PyAnsys to trace node path

Mike.Thompson
Mike.Thompson Member, Employee Posts: 338
25 Answers 100 Comments 25 Likes First Anniversary
✭✭✭✭
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: 50
    10 Comments First Answer 5 Likes First Anniversary
    ✭✭✭✭
    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):

    mapdl.post1()
    mapdl.set(1)
    mesh_undeformed = mapdl.mesh.grid
    mapdl.upcoord(1)
    mesh_deformed = mapdl.mesh.grid
    norm_disp = mapdl.post_processing.nodal_displacement('NORM')
    mapdl.upcoord(-1)
    

    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:

    mapdl.finish()
    mapdl.post26()
    
    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.queries.nz(node))
    
    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, mapdl.queries.nz(node))
    
    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')
    pl.set_background('w')
    pl.show()
    

    Results in this image:

    Is this what you had in mind?
    Mike

Answers