@@ -19,7 +19,7 @@ Define the data
19
19
In this tutorial we will download a simulation result file available
20
20
in our ``Examples `` package:
21
21
22
- .. code-block :: python
22
+ .. jupyter-execute ::
23
23
24
24
# Import the ``ansys.dpf.core `` module, including examples files and operators subpackage
25
25
from ansys.dpf import core as dpf
@@ -33,32 +33,20 @@ metadata, by opening a DataSources or a Streams, and to instanciate results prov
33
33
34
34
Printing the model displays the available results.
35
35
36
- .. code-block :: python
36
+ .. jupyter-execute ::
37
37
38
38
# Create the model
39
39
my_model = dpf.Model(data_sources=result_file)
40
40
# Print the model
41
41
print(my_model)
42
42
43
- .. rst-class :: sphx-glr-script-out
44
-
45
- .. jupyter-execute ::
46
- :hide-code:
47
-
48
- from ansys.dpf import core as dpf
49
- from ansys.dpf.core import examples
50
- from ansys.dpf.core import operators as ops
51
- result_file = examples.find_multishells_rst()
52
- my_model = dpf.Model(data_sources=result_file)
53
- print(my_model)
54
-
55
43
56
44
To deform the mesh we need a result with a homogeneous unit dimension, a distance unit.
57
45
Thus, to deform the mesh we need the displacement result.
58
46
59
47
Extract the displacements results from the model:
60
48
61
- .. code-block :: python
49
+ .. jupyter-execute ::
62
50
63
51
# Get the displacement results
64
52
my_disp_result = my_model.results.displacement
@@ -71,7 +59,7 @@ to work with the XX stress tensor component result.
71
59
Fot more information about extracting results from a result file check
72
60
the :ref: `ref_tutorials_import_data ` tutorials section.
73
61
74
- .. code-block :: python
62
+ .. jupyter-execute ::
75
63
76
64
# Extract the stress result
77
65
my_stress = my_model.results.stress()
@@ -80,7 +68,7 @@ As the stress result is in a ``ElementalNodal`` location we have to change it.
80
68
Here we define the new location with a input of the
81
69
:class: `stress() <ansys.dpf.core.operators.result.stress.stress> ` operator.
82
70
83
- .. code-block :: python
71
+ .. jupyter-execute ::
84
72
85
73
# Define the desired location as an input of the results operator
86
74
my_stress.inputs.requested_location(dpf.locations.nodal)
@@ -91,7 +79,7 @@ To get the results only for the XX stress component we have to use
91
79
the :func: `select_component() <ansys.dpf.core.fields_container.FieldsContainer.select_component> `
92
80
method:
93
81
94
- .. code-block :: python
82
+ .. jupyter-execute ::
95
83
96
84
# Define the component to get.
97
85
# The stress tensor has 6 components per elementary data (symmetrical tensor XX,YY,ZZ,XY,YZ,XZ).
@@ -107,7 +95,7 @@ The geometry can be defined by a |MeshedRegion| or by a |MeshesContainer|.
107
95
108
96
Define the |MeshedRegion | from the |Model |:
109
97
110
- .. code-block :: python
98
+ .. jupyter-execute ::
111
99
112
100
# Define the meshed region
113
101
my_meshed_region = my_model.metadata.meshed_region
@@ -117,7 +105,7 @@ There are different ways to obtain a |MeshesContainer|.
117
105
Here we get a |MeshesContainer | by using the :class: `split_mesh <ansys.dpf.core.operators.mesh.split_mesh.split_mesh> `
118
106
operator. It splits the mesh by material by default:
119
107
120
- .. code-block :: python
108
+ .. jupyter-execute ::
121
109
122
110
# Define the meshed region
123
111
my_meshes = ops.mesh.split_mesh(mesh=my_meshed_region).eval()
@@ -129,7 +117,7 @@ or a :class:`FieldsContainer<ansys.dpf.core.field.Field>`.
129
117
The procedures are the same for a |MeshedRegion | and a |MeshesContainer |. For this reason we will show only
130
118
one plot for the |MeshesContainer |
131
119
132
- .. code-block :: python
120
+ .. jupyter-execute ::
133
121
134
122
# Define the plot formating
135
123
my_scale_factor = 0.001
@@ -165,112 +153,36 @@ one plot for the |MeshesContainer|
165
153
text="e",
166
154
window_size=my_window_size)
167
155
168
- .. rst-class :: sphx-glr-script-out
169
-
170
- .. jupyter-execute ::
171
- :hide-code:
172
-
173
- my_meshed_region = my_model.metadata.meshed_region
174
- my_meshes = ops.mesh.split_mesh(mesh=my_meshed_region).eval()
175
- my_disp_result = my_model.results.displacement
176
- my_stress = my_model.results.stress()
177
- my_stress.inputs.requested_location(dpf.locations.nodal)
178
- fc_stress = my_stress.eval()
179
- my_disp_result = my_model.results.displacement
180
- my_stress = my_model.results.stress()
181
- my_scale_factor = 0.001
182
- my_window_size=[350,350]
183
- my_meshed_region.plot( deform_by=my_disp_result,
184
- scale_factor=my_scale_factor,
185
- text="a",
186
- window_size=my_window_size)
187
- my_disp_op = my_disp_result()
188
- my_meshed_region.plot( deform_by=my_disp_op,
189
- scale_factor=my_scale_factor,
190
- text="b",
191
- window_size=my_window_size)
192
- my_disp_fc = my_disp_result.eval()
193
- my_meshed_region.plot( deform_by=my_disp_fc,
194
- scale_factor=my_scale_factor,
195
- text="c",
196
- font_size=5,
197
- window_size=my_window_size)
198
- my_disp_field = my_disp_fc[0]
199
- my_meshed_region.plot( deform_by=my_disp_field,
200
- scale_factor=my_scale_factor,
201
- text="d",
202
- window_size=my_window_size)
203
- my_meshes.plot( deform_by=my_disp_field,
204
- scale_factor=my_scale_factor,
205
- text="e",
206
- window_size=my_window_size)
207
-
208
156
Plot data on the deformed geometry
209
157
----------------------------------
210
158
211
159
Plot the data on its mesh support
212
160
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
213
161
214
- Plotting the data in DPF means plotting the |Field | or | FieldsContainer | that contains the data.
162
+ Plotting the data in DPF means plotting the |Field | that contains the data.
215
163
216
164
Plot the stress results on the deformed geometry:
217
165
218
- .. code-block :: python
166
+ .. jupyter-execute ::
219
167
220
168
# Define the stress field
221
169
stress_field = fc_stress[0]
222
- # Plot the results on a deformed geometry. The data is in a:
223
- # a) Field
224
- stress_field.plot( deform_by = my_disp_field,
225
- scale_factor = my_scale_factor)
226
-
227
- .. rst-class :: sphx-glr-script-out
228
-
229
- .. jupyter-execute ::
230
- :hide-code:
231
-
232
- stress_field = fc_stress[0]
170
+ # Plot the results on a deformed geometry. The data is in a Field
233
171
stress_field.plot( deform_by=my_disp_field,
234
172
scale_factor=my_scale_factor)
235
173
236
174
Plot the mesh and add the stress data on top of that
237
175
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
238
176
239
- The data to be plotted in a |MeshedRegion | can be in a |Field | or in a | FieldsContainer |
177
+ The data to be plotted in a |MeshedRegion | can be in a |Field |.
240
178
241
- .. code-block :: python
179
+ .. jupyter-execute ::
242
180
243
181
# Plot the MeshedRegion and the stress in a Field
244
- my_meshed_region.plot( field_or_fields_container = stress_field
245
- deform_by = my_disp_field,
246
- scale_factor = my_scale_factor)
247
-
248
- .. rst-class :: sphx-glr-script-out
249
-
250
- .. jupyter-execute ::
251
- :hide-code:
252
-
253
182
my_meshed_region.plot( field_or_fields_container=stress_field,
254
183
deform_by=my_disp_field,
255
184
scale_factor=my_scale_factor)
256
185
257
- The data to be plotted in a |MeshesContainer | must be in a |FieldsContainer |
258
-
259
- .. code-block :: python
260
-
261
- # Plot the MeshesContainer and the stress in a FieldsContainer
262
- my_meshes.plot( fields_container = fc_stress
263
- deform_by = my_disp_field,
264
- scale_factor = my_scale_factor)
265
-
266
- .. rst-class :: sphx-glr-script-out
267
-
268
- .. jupyter-execute ::
269
- :hide-code:
270
-
271
- my_meshed_region.plot( field_or_fields_container=stress_field,
272
- deform_by=my_disp_field,
273
- scale_factor=my_scale_factor)
274
186
275
187
.. rubric :: Footnotes
276
188
0 commit comments