1- .. _ ref_plotting_data_on_specific_placements :
1+ .. _ ref_plotting_data_on_geometry_elements :
22
3- ====================================
4- Plotting data on specific placements
5- ====================================
3+ ==============================
4+ Plot data on geometry elements
5+ ==============================
66
77.. |DpfPlotter | replace :: :class: `DpfPlotter<ansys.dpf.core.plotter.DpfPlotter> `
88.. |add_mesh | replace :: :func: `add_mesh()<ansys.dpf.core.plotter.DpfPlotter.add_mesh> `
@@ -15,198 +15,14 @@ Plotting data on specific placements
1515.. |Plane | replace :: :class: `Plane <ansys.dpf.core.geometry.Plane> `
1616.. |mapping | replace :: :class: `mapping <ansys.dpf.core.operators.mapping.on_coordinates.on_coordinates> `
1717
18- This tutorial shows how to plot data on specific placements of a mesh:
19-
20- - :ref: `plot_specific_path `
21- - :ref: `plot_geometry_elements `
22-
23- .. _plot_specific_path :
24-
25- Plot data on a specific path
26- ----------------------------
27-
28- This part shows how to get a result mapped over a specific path and how to plot it.
29-
30- Define the data
31- ^^^^^^^^^^^^^^^
32-
33- We will download a simple simulation result file available in our `Examples ` package:
34-
35- .. code-block :: python
36-
37- # Import the ``ansys.dpf.core`` module, including examples files and the operators subpackage
38- from ansys.dpf import core as dpf
39- from ansys.dpf.core import examples
40- from ansys.dpf.core import operators as ops
41- # Define the result file
42- result_file = examples.find_static_rst()
43-
44- The results will be mapped over a defined path of coordinates. So, start by creating
45- a |Model | with the result file and extract the |MeshedRegion | from it:
46-
47- .. code-block :: python
48-
49- # Create the model
50- my_model = dpf.Model(data_sources = result_file)
51- my_meshed_region = my_model.metadata.meshed_region
52-
53- Define the path
54- ^^^^^^^^^^^^^^^
55-
56- The path coordinates have to be in the space domain of the mesh. You can verify the
57- range of coordinates values by checking the nodes coordinates.
58-
59- Get the nodes coordinates with the mesh operator
60- :class: `nodes_coordinates<ansys.dpf.core.operators.mesh.node_coordinates.node_coordinates> `:
61-
62- .. code-block :: python
63-
64- # Get the mesh nodes coordinates
65- nodes_coords = ops.mesh.node_coordinates(mesh = my_meshed_region).eval()
66-
67- Get the maximum values of the coordinates, so you know the space domain limits.
68-
69- .. code-block :: python
70-
71- # Get the maximum and minimum values of the mesh nodes coordinates
72- max_coords = ops.min_max.min_max(field = nodes_coords).eval(pin = 1 )
73- min_coords = ops.min_max.min_max(field = nodes_coords).eval(pin = 0 )
74- # Print the space domain limits
75- print (" Max coordinates:" , max_coords.data, ' \n ' )
76- print (" Min coordinates:" ,min_coords.data)
77-
78- .. rst-class :: sphx-glr-script-out
79-
80- .. jupyter-execute ::
81- :hide-code:
82-
83- from ansys.dpf import core as dpf
84- from ansys.dpf.core import examples
85- from ansys.dpf.core import operators as ops
86- result_file = examples.find_static_rst()
87- my_model = dpf.Model(data_sources=result_file)
88- my_meshed_region = my_model.metadata.meshed_region
89- nodes_coords = ops.mesh.node_coordinates(mesh=my_meshed_region).eval()
90- max_coords = ops.min_max.min_max(field=nodes_coords).eval(pin=1)
91- min_coords = ops.min_max.min_max(field=nodes_coords).eval(pin=0)
92- print("Max coordinates:", max_coords.data, '\n ')
93- print("Min coordinates:",min_coords.data)
94-
95-
96- Create the path based on a set of coordinates. Here we choose the paths origin coordinates,
97- number of points in the path and the distance between each coordinate.
98-
99- .. code-block :: python
100-
101- # Initial coordinates
102- initial_coords = [0.024 , 0.03 , 0.003 ]
103- # Number of points in the path
104- n_points = 51
105- # Distance between each coordinate
106- delta = 0.001
107-
108- # Create the paths coordinates field
109- path_coords = dpf.fields_factory.create_3d_vector_field(n_points)
110- path_coords.scoping.ids = list (range (0 , n_points))
111-
112- Make a loop to define the paths coordinates field. Here we make a path that only moves along the y-axis.
113-
114- .. code-block :: python
115-
116- # For each iteration we add a new set of coordinates based on the predefined distance between each coordinate
117- for i in range (0 , n_points):
118- initial_coords[1 ] += delta
119- path_coords.append(data = initial_coords, scopingid = 0 )
120-
121- Extract the result
122- ^^^^^^^^^^^^^^^^^^
123-
124- Extract the result from the model. Here we get the equivalent stress result
125-
126- .. code-block :: python
127-
128- # Get the stress result
129- my_stress = my_model.results.stress().eqv().eval()
130-
131- Map the result to the path
132- ^^^^^^^^^^^^^^^^^^^^^^^^^^
133-
134- Compute the mapped data using the |mapping | operator. The stress results are defined in a ``ElementalNodal `` location.
135- So, each entity has a coordinate in the mesh and a correspondent stress data.
136-
137- The |mapping | operator retrieves the results of the entities located in the given coordinates.
138- If the given coordinates don't match with any entity coordinate, the operator interpolates the results inside
139- elements with shape functions.
140-
141- .. code-block :: python
142-
143- # Map the path coordinates with the stress results
144- mapped_stress = ops.mapping.on_coordinates(fields_container = my_stress,
145- coordinates = path_coords,
146- create_support = True ,
147- mesh = my_meshed_region
148- ).eval()
149-
150- Plot the result on the path
151- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
152-
153- Create the plotter and add fields and meshes. For more information about
154- plotting data on a mesh check the tutorial: :ref: `ref_plotting_data_on_the_mesh `
155-
156- First, define the |DpfPlotter | object [2 ]_, then add |MeshedRegion |
157- to it using the |add_mesh | method and add the field using the |add_field | method.
158-
159- To display the figure built by the plotter object use the |show_figure | method.
160-
161- .. code-block :: python
162-
163- # Declare the DpfPlotter object
164- my_plotter = dpf.plotter.DpfPlotter()
165- # Add the MeshedRegion to the DpfPlotter object
166- # We use custom style for the mesh so we can visualise the path (that is inside the mesh)
167- my_plotter.add_mesh(meshed_region = my_meshed_region,style = " surface" , show_edges = True , color = " w" , opacity = 0.3 )
168- # Add the Field to the DpfPlotter object
169- my_plotter.add_field(field = mapped_stress[0 ])
170- # Display the plot
171- my_plotter.show_figure()
172-
173- .. rst-class :: sphx-glr-script-out
174-
175- .. jupyter-execute ::
176- :hide-code:
177-
178- initial_coords = [0.024, 0.03, 0.003]
179- n_points = 51
180- delta = 0.001
181- path_coords = dpf.fields_factory.create_3d_vector_field(n_points)
182- path_coords.scoping.ids = list(range(0, n_points))
183- for i in range(0, n_points):
184- initial_coords[1] += delta
185- path_coords.append(data=initial_coords, scopingid=0)
186- my_stress = my_model.results.stress().eqv().eval()
187- mapped_stress = ops.mapping.on_coordinates(fields_container=my_stress,
188- coordinates=path_coords,
189- create_support=True,
190- mesh=my_meshed_region
191- ).eval()
192- my_plotter = dpf.plotter.DpfPlotter()
193- my_plotter.add_mesh(meshed_region=my_meshed_region,style="surface", show_edges=True, color="w", opacity=0.3)
194- my_plotter.add_field(field=mapped_stress[0])
195- my_plotter.show_figure()
196-
197- .. _plot_geometry_elements :
198-
199- Plot data on geometry elements
200- ------------------------------
201-
202- This part shows how to get a result mapped over different geometric objects:
18+ This tutorials shows how to get a result mapped over different geometric objects:
20319
20420- Points _
20521- Line _
20622- Plane _
20723
20824Define the data
209- ^^^^^^^^^^^^^^^
25+ ---------------
21026
21127We will download a simple simulation result file available in our `Examples ` package:
21228
@@ -250,12 +66,14 @@ plot method [1]_:
25066 ]
25167
25268 Points
253- ^^^^^^
69+ ------
25470
25571Create points
256- ~~~~~~~~~~~~~
72+ ^^^^^^^^^^^^^
25773
258- Create |Points | by defining their coordinates. Once again they have to be in the space domain of the mesh.
74+ Create |Points | by defining their coordinates. They have to be in the space
75+ domain of the mesh. You can verify the range of coordinates values by checking
76+ the nodes coordinates.
25977
26078Get the nodes coordinates with the mesh operator
26179:class: `nodes_coordinates<ansys.dpf.core.operators.mesh.node_coordinates.node_coordinates> `:
@@ -332,7 +150,7 @@ You can do it by hand or by calculating this combinations :
332150 )
333151
334152 Check the points on the mesh with a plot
335- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
336154
337155You can plot the |Points | together with the mesh:
338156
@@ -364,7 +182,7 @@ You can plot the |Points| together with the mesh:
364182 my_points.plot(mesh=my_meshed_region, cpos=camera_position)
365183
366184Map displacement field to the points
367- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
368186
369187Compute the mapped data using the |mapping | operator. The displacement results are defined in a ``Nodal `` location.
370188So, each node has a coordinate in the mesh and a correspondent displacement data.
@@ -383,7 +201,7 @@ elements with shape functions.
383201 ).eval()[0 ]
384202
385203 Plot displacement field on the points
386- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
204+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
387205
388206Create the plotter and add fields and meshes. For more information about
389207plotting data on a mesh check the tutorial: :ref: `ref_plotting_data_on_the_mesh `
@@ -421,10 +239,10 @@ To display the figure built by the plotter object use the |show_figure| method.
421239 my_plotter.show_figure(show_axes=True, cpos=camera_position)
422240
423241Line
424- ^^^^
242+ ----
425243
426244Create the line
427- ~~~~~~~~~~~~~~~
245+ ^^^^^^^^^^^^^^^
428246
429247Create a |Line | passing through the mesh diagonal. To create a |Line |
430248you need pass as arguments: the coordinates of the starting and ending points
@@ -440,7 +258,7 @@ Check the `Create points`_ section to understand how we defined the points coord
440258 )
441259
442260 Check the line on the mesh with a plot
443- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
444262
445263You can plot the |Line | together with the mesh:
446264
@@ -460,7 +278,7 @@ You can plot the |Line| together with the mesh:
460278 my_line.plot(mesh=my_meshed_region, cpos=camera_position)
461279
462280Map displacement field to the line
463- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
464282
465283Compute the mapped data using the |mapping | operator. The displacement results are defined in a ``Nodal `` location.
466284So, each node has a coordinate in the mesh and a correspondent displacement data.
@@ -479,7 +297,7 @@ elements with shape functions.
479297 ).eval()[0 ]
480298
481299 Plot displacement field on the line
482- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
300+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
483301
484302Plot displacement field on the |Line | and display mesh in background.
485303Create the plotter and add fields and meshes. For more information about
@@ -518,10 +336,10 @@ To display the figure built by the plotter object use the |show_figure| method.
518336 my_plotter.show_figure(show_axes=True, cpos=camera_position)
519337
520338Plane
521- ^^^^^
339+ -----
522340
523341Create the plane
524- ~~~~~~~~~~~~~~~~
342+ ^^^^^^^^^^^^^^^^
525343
526344Create a vertical |Plane | passing through the mesh mid point. To create a |Plane |
527345you need pass as arguments: the coordinates of the center point, the vector of the normal direction to the plane,
@@ -542,7 +360,7 @@ Check the `Create points`_ section to understand how we defined the mesh space c
542360 )
543361
544362 Check the plane on the mesh with a plot
545- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
363+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
546364
547365You can plot the |Plane | together with the mesh:
548366
@@ -566,7 +384,7 @@ You can plot the |Plane| together with the mesh:
566384 my_plane.plot(mesh=my_meshed_region, cpos=camera_position)
567385
568386Map displacement field to the plane
569- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
387+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
570388
571389Compute the mapped data using the |mapping | operator. The displacement results are defined in a ``Nodal `` location.
572390So, each node has a coordinate in the mesh and a correspondent displacement data.
@@ -585,7 +403,7 @@ elements with shape functions.
585403 ).eval()[0 ]
586404
587405 Plot displacement field on the plane
588- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
406+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
589407
590408Plot displacement field on the |Plane | and display mesh in background.
591409Create the plotter and add fields and meshes. For more information about
@@ -636,4 +454,4 @@ parameter (the argument must be supported by the installed PyVista version).
636454The default |DpfPlotter | object settings display the mesh with edges and lighting
637455enabled. Nevertheless, as we use the `PyVista <https://github.com/pyvista/pyvista >`_
638456library to create the plot you can use additional PyVista arguments for the |DpfPlotter |
639- object and |add_field | method (available at: :func: `pyvista.plot `).
457+ object and |add_field | method (available at: :func: `pyvista.plot `).
0 commit comments