PyAnsys to trace node path
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
-
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?
Mike1
Answers
-
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?
0 -
@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.0 -
-
@Mike.Thompson Not sure I've understood fully either, but maybe this helps ? https://dpf.docs.pyansys.com/version/stable/examples/06-plotting/04-plot_on_path.html#sphx-glr-examples-06-plotting-04-plot-on-path-py
0 -
@Mike Rife , thanks for the detailed response. This is what I was hoping for. The only other items would be to make the path tracing graphics more robust in terms of color, weights, visible through the model or hidden behind it, etc....
You set the color = red in the example, and I assume some of the basic options like line weight are also easy to find. Thanks!
0 -
@Mike.Thompson yes there is a "line_width" that can be set. There are quite a few options for the add_mesh.
1