How can I plot in pydpf-post results on a mesh part linked to a named selection?

Options
Javier Vique
Javier Vique Member, Employee Posts: 78
First Answer First Anniversary Name Dropper 5 Likes

'Extract results on named selections - Modal Simulation' example shows how to plot results on a specific named selection. Results are only shown on that named selection, but the rest of the structure is kept grey. Is there any way to only plot the mesh which is linked to the named selection and not the whole structure?

Tagged:

Best Answer

  • Javier Vique
    Javier Vique Member, Employee Posts: 78
    First Answer First Anniversary Name Dropper 5 Likes
    Answer ✓
    Options

    Having a look at pydpf-post manual, we can see that simulation.plot has only mesh=true or mesh=false, but it does not allow to link to a specific part of the mesh. What it can be done is to use plot contour and its pyvista options, for instance opacity.
    Here the code to plot on BAR_1 named selection from the example commented before:

    from ansys.dpf import post
    from ansys.dpf.post import examples
    
    example_path = examples.download_modal_frame()
    solution = post.load_solution(example_path)
    
    disp = solution.displacement()
    disp_bar_1 = solution.displacement(named_selection='BAR_1')
    dxb1 = disp_bar_1.x
    
    all_elem = solution.mesh.elements.scoping.ids
    elem_ns = solution.mesh.named_selection('BAR_1').ids
    
    opacities = []
    
    for i in all_elem:
        if i in elem_ns:
            opacities.append(1.0)
        else:
            opacities.append(0.0)
    
    pl = dxb1.plot_contour("time", [1], opacity=opacities)
    

    The result got is the following:

    Another option would be using pydpf-core to generate a mesh from scoping and plot the desired result on it.

Answers

  • Nathanvanthof
    Nathanvanthof Member Posts: 4
    First Comment
    Options

    When I copy paste the code I get this:

    Any idea what might be wrong?

  • Javier Vique
    Javier Vique Member, Employee Posts: 78
    First Answer First Anniversary Name Dropper 5 Likes
    edited September 2023
    Options

    Hello @Nathanvanthof ,
    It seems something related to pyvista. An alternative to the workaround that I proposed is to apply a opacity of 0.0 to all the elements with no result, which gives same results for me, as you can see in the screenshot below. These would be the code:

    from ansys.dpf import post
    from ansys.dpf.post import examples
    
    example_path = examples.download_modal_frame()
    solution = post.load_solution(example_path)
    
    disp = solution.displacement()
    disp_on_named_selection = solution.displacement(named_selection='BAR_1')
    dx = disp_on_named_selection.x
    
    all_elem = solution.mesh.elements.scoping.ids
    elem_ns = solution.mesh.named_selection('BAR_1').ids
    
    pl = dx.plot_contour("time", [1], nan_opacity = 0.0)
    

    If you are still having issues, I would play with options given in pyvista.plot and pv.Plotter.add_mesh.
    Regards, Javier.

  • Nathanvanthof
    Nathanvanthof Member Posts: 4
    First Comment
    Options

    This works, thank you so much!