PyAnsys to trace node path

Mike.Thompson
Mike.Thompson Member, Employee Posts: 241
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.

Answers

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 183
    First Answer First Comment 5 Likes First Anniversary

    I am not sure that I understand. Do you want to start with straight lines superimposed on an undeformed mesh and then watch how the lines deform as the mesh deforms with time?

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 241
    First Anniversary First Comment 5 Likes Ansys Employee

    @Landon Mitchell Kanner ,
    No. The node starts at a point and at each time step will be at a new point in space. I want to trace a spline through those points in space. I believe we have this kind of capability in Mechanical at least in RBD, but I want to know how to do it with PyAnsys tools.

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 183
    First Answer First Comment 5 Likes First Anniversary

    Have you looked at PyVista or VTK, which PyVista is built on?

  • Mike Rife
    Mike Rife Member, Employee Posts: 25
    5 Likes First Anniversary First Comment Ansys Employee

    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