1
- .. _ ref_plotting_data_on_specific_placements :
1
+ .. _ ref_plotting_data_on_geometry_elements :
2
2
3
- ====================================
4
- Plotting data on specific placements
5
- ====================================
3
+ ==============================
4
+ Plot data on geometry elements
5
+ ==============================
6
6
7
7
.. |DpfPlotter | replace :: :class: `DpfPlotter<ansys.dpf.core.plotter.DpfPlotter> `
8
8
.. |add_mesh | replace :: :func: `add_mesh()<ansys.dpf.core.plotter.DpfPlotter.add_mesh> `
@@ -15,198 +15,14 @@ Plotting data on specific placements
15
15
.. |Plane | replace :: :class: `Plane <ansys.dpf.core.geometry.Plane> `
16
16
.. |mapping | replace :: :class: `mapping <ansys.dpf.core.operators.mapping.on_coordinates.on_coordinates> `
17
17
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:
203
19
204
20
- Points _
205
21
- Line _
206
22
- Plane _
207
23
208
24
Define the data
209
- ^^^^^^^^^^^^^^^
25
+ ---------------
210
26
211
27
We will download a simple simulation result file available in our `Examples ` package:
212
28
@@ -250,12 +66,14 @@ plot method [1]_:
250
66
]
251
67
252
68
Points
253
- ^^^^^^
69
+ ------
254
70
255
71
Create points
256
- ~~~~~~~~~~~~~
72
+ ^^^^^^^^^^^^^
257
73
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.
259
77
260
78
Get the nodes coordinates with the mesh operator
261
79
: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 :
332
150
)
333
151
334
152
Check the points on the mesh with a plot
335
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
336
154
337
155
You can plot the |Points | together with the mesh:
338
156
@@ -364,7 +182,7 @@ You can plot the |Points| together with the mesh:
364
182
my_points.plot(mesh=my_meshed_region, cpos=camera_position)
365
183
366
184
Map displacement field to the points
367
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
185
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
368
186
369
187
Compute the mapped data using the |mapping | operator. The displacement results are defined in a ``Nodal `` location.
370
188
So, each node has a coordinate in the mesh and a correspondent displacement data.
@@ -383,7 +201,7 @@ elements with shape functions.
383
201
).eval()[0 ]
384
202
385
203
Plot displacement field on the points
386
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
204
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
387
205
388
206
Create the plotter and add fields and meshes. For more information about
389
207
plotting 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.
421
239
my_plotter.show_figure(show_axes=True, cpos=camera_position)
422
240
423
241
Line
424
- ^^^^
242
+ ----
425
243
426
244
Create the line
427
- ~~~~~~~~~~~~~~~
245
+ ^^^^^^^^^^^^^^^
428
246
429
247
Create a |Line | passing through the mesh diagonal. To create a |Line |
430
248
you 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
440
258
)
441
259
442
260
Check the line on the mesh with a plot
443
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
444
262
445
263
You can plot the |Line | together with the mesh:
446
264
@@ -460,7 +278,7 @@ You can plot the |Line| together with the mesh:
460
278
my_line.plot(mesh=my_meshed_region, cpos=camera_position)
461
279
462
280
Map displacement field to the line
463
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
464
282
465
283
Compute the mapped data using the |mapping | operator. The displacement results are defined in a ``Nodal `` location.
466
284
So, each node has a coordinate in the mesh and a correspondent displacement data.
@@ -479,7 +297,7 @@ elements with shape functions.
479
297
).eval()[0 ]
480
298
481
299
Plot displacement field on the line
482
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
300
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
483
301
484
302
Plot displacement field on the |Line | and display mesh in background.
485
303
Create 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.
518
336
my_plotter.show_figure(show_axes=True, cpos=camera_position)
519
337
520
338
Plane
521
- ^^^^^
339
+ -----
522
340
523
341
Create the plane
524
- ~~~~~~~~~~~~~~~~
342
+ ^^^^^^^^^^^^^^^^
525
343
526
344
Create a vertical |Plane | passing through the mesh mid point. To create a |Plane |
527
345
you 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
542
360
)
543
361
544
362
Check the plane on the mesh with a plot
545
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
363
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
546
364
547
365
You can plot the |Plane | together with the mesh:
548
366
@@ -566,7 +384,7 @@ You can plot the |Plane| together with the mesh:
566
384
my_plane.plot(mesh=my_meshed_region, cpos=camera_position)
567
385
568
386
Map displacement field to the plane
569
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
387
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
570
388
571
389
Compute the mapped data using the |mapping | operator. The displacement results are defined in a ``Nodal `` location.
572
390
So, each node has a coordinate in the mesh and a correspondent displacement data.
@@ -585,7 +403,7 @@ elements with shape functions.
585
403
).eval()[0 ]
586
404
587
405
Plot displacement field on the plane
588
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
406
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
589
407
590
408
Plot displacement field on the |Plane | and display mesh in background.
591
409
Create 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).
636
454
The default |DpfPlotter | object settings display the mesh with edges and lighting
637
455
enabled. Nevertheless, as we use the `PyVista <https://github.com/pyvista/pyvista >`_
638
456
library 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