Display results as vectors #2464
-
Hello, in APDL there is a command called plvect to display vectors with element centroids as the origin for the vectors. How can I do this in pymapdl if the x,y, and z values for the vectors are saved as numpy array? I was thinking that maybe i can get the locations of the element centroid but not sure how. Once i have that maybe i could use the command plotter.add_arrows() to display the vectors. Do anyone have a better suggestion? Thanks in advance! Arun |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @arun-maniam ! You could accomplish that using pyvista: import pyvista as pv
grid = mapdl.mesh._grid
mapdl.post1()
mapdl.set("last") # Important! Otherwise the element values are zero.
centers = np.array(grid.cell_centers().points)
scalars = mapdl.post_processing.element_displacement("NORM") # Just for plotting
direction = np.array(mapdl.post_processing.element_displacement("ALL"))
size_arrow_respect_full_model = 10 # th times smaller
arrow_size = np.mean(centers.max(axis=0) - centers.min(axis=0))/size_arrow_respect_full_model
magnitude = arrow_size/direction.max()
pl = pv.Plotter()
# pl.add_mesh(grid, opacity=0.5, color='grey') # In case you want to plot the cylinder too
pl.add_points(centers,scalars=scalars, cmap="bwr")
pl.add_arrows(centers, direction, magnitude, cmap="bwr", show_scalar_bar=False)
pl.show() ModelDetails
from ansys.mapdl.core import launch_mapdl mapdl = launch_mapdl(start_instance=False) define cylinder and mesh parameterstorque = 100 Define higher-order SOLID186Define surface effect elements SURF154 to apply torqueas a tangential pressuremapdl.prep7() Aluminum properties (or something)mapdl.mp("ex", 1, 10e6) Simple cylinderfor i in range(4): mapdl.nummrg("kp") mesh cylindermapdl.lsel("s", "loc", "x", 0) mapdl.slashsolu() # Using Slash instead of / due to duplicate SOLU command Apply tangential pressuremapdl.esel("s", "type", "", 2) Constrain bottom of cylinder/rodmapdl.asel("s", "loc", "z", 0) mapdl.d("all", "all") |
Beta Was this translation helpful? Give feedback.
Hello @arun-maniam !
You could accomplish that using pyvista: