PyAnsys to trace node path

Mike.Thompson Member, Employee Posts: 290
First Anniversary First Comment 5 Likes Ansys Employee
edited February 2 in Structures

What can I use in PyAnsys to trace multiple 3D node paths along a transient result? I want the paths to display with a 3D viewer on top of the deformed mesh and be able to configure the color, weight etc… of the given paths.
FYI, I know how to get the 3D points, I just need to know how to create the visual.

Best Answer

  • Mike Rife
    Mike Rife Member, Employee Posts: 38
    First Answer 5 Likes First Anniversary First Comment
    Answer ✓

    Hi @Mike.Thompson Well since you tagged PyMAPDL here is a method. I have a 24x.5x1 cantilever beam meshed with solid elements with a pressure applied and run as large deflection so it really bends down. Oh and run in 10 substeps saving results at every sub step.

    In post1 let's capture the undeformed mesh, the deformed mesh, and some result (here USUM):

    mesh_undeformed = mapdl.mesh.grid
    mesh_deformed = mapdl.mesh.grid
    norm_disp = mapdl.post_processing.nodal_displacement('NORM')

    Now we can use the time history post processor post26 to get the x, y, z displacement values of some node to variables (MAPDL variables). Also create variables of the x/y/z location of the node. Then add these together. Now vget them to a (MAPDL) parameter, flatten them, and insert the x/y/z locations (since the time history data starts at the first solved substep). Then stack them together into one numpyt array:

    node = mapdl.queries.node(24, 0, 0)
    mapdl.nsol(2, node, 'u', 'x')
    mapdl.nsol(3, node, 'u', 'y')
    mapdl.nsol(4, node, 'u', 'z')
    mapdl.filldata(5, 1, '', '', mapdl.queries.nx(node))
    mapdl.filldata(6, 1, '', '', mapdl.queries.ny(node))
    mapdl.filldata(7, 1, '', '',
    mapdl.add(2, 2, 5)
    mapdl.add(3, 3, 6)
    mapdl.add(4, 4, 7)
    mapdl.vget("NX1", 2)
    mapdl.vget("NY1", 3)
    mapdl.vget("NZ1", 4)
    NX1 = mapdl.parameters["NX1"]
    NY1 = mapdl.parameters["NY1"]
    NZ1 = mapdl.parameters["NZ1"]
    NX1 = NX1.flatten()
    NY1 = NY1.flatten()
    NZ1 = NZ1.flatten()
    NX1 = np.insert(NX1, 0, mapdl.queries.nx(node))
    NY1 = np.insert(NY1, 0, mapdl.queries.ny(node))
    NZ1 = np.insert(NZ1, 0,
    points = np.column_stack((NX1, NY1, NZ1))

    Now a PyVista plotter can be instantiated (not sure if that is the right term...?) the two meshes and the multiline added. The line is the trace of the path in space the node makes:

    scalars_mesh = mesh_undeformed["ansys_material_type"]
    pl = pv.Plotter()
    pl.add_mesh(mesh_undeformed, show_edges=True, opacity=.15, scalars=scalars_mesh)
    pl.add_mesh(mesh_deformed, scalars=norm_disp)
    line_path = pv.MultipleLines(points=points)
    pl.add_mesh(line_path, color='red')

    Results in this image:

    Is this what you had in mind?