Skip to content

Commit 706b595

Browse files
use only the jupyter sphinx extension
1 parent 50dc469 commit 706b595

6 files changed

+74
-491
lines changed

doc/source/user_guide/tutorials/plot/plotting_a_graph.rst

+12-61
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Define the data
3131

3232
We will download a simple simulation result file available in our `Examples` package:
3333

34-
.. code-block:: python
34+
.. jupyter-execute::
3535

3636
# Import the ``ansys.dpf.core`` module, including examples files, the operators subpackage, the geometry module and the matplotlib
3737
from ansys.dpf import core as dpf
@@ -45,15 +45,15 @@ We will download a simple simulation result file available in our `Examples` pac
4545
The results will be mapped over a defined path of coordinates. So, start by creating
4646
a |Model| with the result file and extract the |MeshedRegion| from it:
4747

48-
.. code-block:: python
48+
.. jupyter-execute::
4949

5050
# Create the model
5151
my_model = dpf.Model(data_sources=result_file)
5252
my_meshed_region = my_model.metadata.meshed_region
5353

5454
We choose to plot the displacement results field. Extract the displacements results from the model:
5555

56-
.. code-block:: python
56+
.. jupyter-execute::
5757

5858
# Get the displacement results
5959
my_disp = my_model.results.displacement.eval()
@@ -63,7 +63,7 @@ Create the line
6363

6464
Create a |Line| passing through the mesh diagonal.
6565

66-
.. code-block:: python
66+
.. jupyter-execute::
6767

6868
# Create the Line object
6969
my_line = geo.Line(coordinates=[[0.0, 0.06, 0.0], [0.03, 0.03, 0.03]],
@@ -75,7 +75,7 @@ Map displacement field to the line
7575

7676
Compute the mapped displacement data using the |mapping| operator.
7777

78-
.. code-block:: python
78+
.. jupyter-execute::
7979

8080
# Map the line coordinates with the displacement results and get the field
8181
mapped_disp_line = ops.mapping.on_coordinates(fields_container=my_disp,
@@ -92,43 +92,15 @@ Plot a graph of the displacement field along the specified |Line| length using t
9292
To get the |Line| length you can use the |Line| property :func:`path<ansys.dpf.core.geometry.Line.path>`.
9393
It gives the 1D line coordinates, by the number of points the line was discretized.
9494

95-
.. code-block:: python
95+
.. jupyter-execute::
9696

9797
# Define the norm of the displacement field
9898
norm_disp = ops.math.norm(field=mapped_disp_line).eval()
9999
# Define the line points on the its length
100100
line_length_points = my_line.path
101101
# Plot the graph
102-
plt.plot(line_length_points, norm_disp)
103-
# Graph formating
104-
plt.xlabel("Line length"); plt.ylabel("Displacement norm field"); plt.title("Displacement evolution on the line")
105-
plt.show()
106-
107-
.. rst-class:: sphx-glr-script-out
108-
109-
.. jupyter-execute::
110-
:hide-code:
111-
112-
from ansys.dpf import core as dpf
113-
from ansys.dpf.core import examples
114-
from ansys.dpf.core import operators as ops
115-
from ansys.dpf.core import geometry as geo
116-
import matplotlib.pyplot as plt
117-
result_file = examples.find_static_rst()
118-
my_model = dpf.Model(data_sources=result_file)
119-
my_meshed_region = my_model.metadata.meshed_region
120-
my_disp = my_model.results.displacement.eval()
121-
my_line = geo.Line(coordinates=[[0.0, 0.06, 0.0], [0.03, 0.03, 0.03]],
122-
n_points=50
123-
)
124-
mapped_disp_line = ops.mapping.on_coordinates(fields_container=my_disp,
125-
coordinates=my_line.mesh.nodes.coordinates_field,
126-
create_support=True,
127-
mesh=my_meshed_region
128-
).eval()[0]
129-
norm_disp = ops.math.norm(field=mapped_disp_line).eval()
130-
line_length_points = my_line.path
131102
plt.plot(line_length_points, norm_disp.data)
103+
# Graph formating
132104
plt.xlabel("Line length"); plt.ylabel("Displacement norm field"); plt.title("Displacement evolution on the line")
133105
plt.show()
134106

@@ -144,7 +116,7 @@ Define the data
144116
Download the transient result example. This example is not included in DPF-Core
145117
by default to speed up the installation. Downloading this example should take only a few seconds.
146118

147-
.. code-block:: python
119+
.. jupyter-execute::
148120

149121
# Import the ``ansys.dpf.core`` module, including examples files, the operators subpackage and the matplotlib
150122
from ansys.dpf import core as dpf
@@ -157,7 +129,7 @@ by default to speed up the installation. Downloading this example should take on
157129
The results will be mapped over a defined path of coordinates. So, start by creating
158130
a |Model| with the result file and extract the |MeshedRegion| from it:
159131

160-
.. code-block:: python
132+
.. jupyter-execute::
161133

162134
# Create the model
163135
my_model = dpf.Model(data_sources=result_file)
@@ -166,14 +138,14 @@ a |Model| with the result file and extract the |MeshedRegion| from it:
166138
We choose to plot the maximum and minimum displacement results over time.
167139
Extract the displacements results from the model for all the time frequencies:
168140

169-
.. code-block:: python
141+
.. jupyter-execute::
170142

171143
# Get the displacement results
172144
my_disp = my_model.results.displacement.on_all_time_freqs.eval()
173145

174146
Define the minimum and maximum displacements for all results:
175147

176-
.. code-block:: python
148+
.. jupyter-execute::
177149

178150
# Define the min_max operator with the normed displacement
179151
min_max_op = ops.min_max.min_max_fc(fields_container=ops.math.norm_fc(my_disp))
@@ -186,33 +158,12 @@ Plot a graph of the minimum and maximum displacements over time
186158

187159
Plot a graph of the minimum and maximum displacements over time using the matplotlib library.
188160

189-
.. code-block:: python
161+
.. jupyter-execute::
190162

191163
# Define the time frequencies from the model
192164
time_data = my_model.metadata.time_freq_support.time_frequencies.data
193165
# Plot the graph
194166
plt.plot(time_data, max_disp.data, "r", label="Max")
195167
plt.plot(time_data, min_disp.data, "b", label="Min")
196168
# Graph formating
197-
plt.xlabel("Time (s)"); plt.ylabel("Displacement (m)"); plt.legend(); plt.show()
198-
199-
.. rst-class:: sphx-glr-script-out
200-
201-
.. jupyter-execute::
202-
:hide-code:
203-
204-
from ansys.dpf import core as dpf
205-
from ansys.dpf.core import examples
206-
from ansys.dpf.core import operators as ops
207-
import matplotlib.pyplot as plt
208-
result_file = examples.download_transient_result()
209-
my_model = dpf.Model(data_sources=result_file)
210-
my_meshed_region = my_model.metadata.meshed_region
211-
my_disp = my_model.results.displacement.on_all_time_freqs.eval()
212-
min_max_op = ops.min_max.min_max_fc(fields_container=ops.math.norm_fc(my_disp))
213-
max_disp = min_max_op.eval(pin=1)
214-
min_disp = min_max_op.eval(pin=0)
215-
time_data = my_model.metadata.time_freq_support.time_frequencies.data
216-
plt.plot(time_data, max_disp.data, "r", label="Max")
217-
plt.plot(time_data, min_disp.data, "b", label="Min")
218169
plt.xlabel("Time (s)"); plt.ylabel("Displacement (m)"); plt.legend(); plt.show()

doc/source/user_guide/tutorials/plot/plotting_data_on_deformed_mesh.rst

+14-102
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Define the data
1919
In this tutorial we will download a simulation result file available
2020
in our ``Examples`` package:
2121

22-
.. code-block:: python
22+
.. jupyter-execute::
2323

2424
# Import the ``ansys.dpf.core`` module, including examples files and operators subpackage
2525
from ansys.dpf import core as dpf
@@ -33,32 +33,20 @@ metadata, by opening a DataSources or a Streams, and to instanciate results prov
3333

3434
Printing the model displays the available results.
3535

36-
.. code-block:: python
36+
.. jupyter-execute::
3737

3838
# Create the model
3939
my_model = dpf.Model(data_sources=result_file)
4040
# Print the model
4141
print(my_model)
4242

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-
5543

5644
To deform the mesh we need a result with a homogeneous unit dimension, a distance unit.
5745
Thus, to deform the mesh we need the displacement result.
5846

5947
Extract the displacements results from the model:
6048

61-
.. code-block:: python
49+
.. jupyter-execute::
6250

6351
# Get the displacement results
6452
my_disp_result = my_model.results.displacement
@@ -71,7 +59,7 @@ to work with the XX stress tensor component result.
7159
Fot more information about extracting results from a result file check
7260
the :ref:`ref_tutorials_import_data` tutorials section.
7361

74-
.. code-block:: python
62+
.. jupyter-execute::
7563

7664
# Extract the stress result
7765
my_stress = my_model.results.stress()
@@ -80,7 +68,7 @@ As the stress result is in a ``ElementalNodal`` location we have to change it.
8068
Here we define the new location with a input of the
8169
:class:`stress() <ansys.dpf.core.operators.result.stress.stress>` operator.
8270

83-
.. code-block:: python
71+
.. jupyter-execute::
8472

8573
# Define the desired location as an input of the results operator
8674
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
9179
the :func:`select_component() <ansys.dpf.core.fields_container.FieldsContainer.select_component>`
9280
method:
9381

94-
.. code-block:: python
82+
.. jupyter-execute::
9583

9684
# Define the component to get.
9785
# 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|.
10795

10896
Define the |MeshedRegion| from the |Model|:
10997

110-
.. code-block:: python
98+
.. jupyter-execute::
11199

112100
# Define the meshed region
113101
my_meshed_region = my_model.metadata.meshed_region
@@ -117,7 +105,7 @@ There are different ways to obtain a |MeshesContainer|.
117105
Here we get a |MeshesContainer| by using the :class:`split_mesh <ansys.dpf.core.operators.mesh.split_mesh.split_mesh>`
118106
operator. It splits the mesh by material by default:
119107

120-
.. code-block:: python
108+
.. jupyter-execute::
121109

122110
# Define the meshed region
123111
my_meshes = ops.mesh.split_mesh(mesh=my_meshed_region).eval()
@@ -129,7 +117,7 @@ or a :class:`FieldsContainer<ansys.dpf.core.field.Field>`.
129117
The procedures are the same for a |MeshedRegion| and a |MeshesContainer|. For this reason we will show only
130118
one plot for the |MeshesContainer|
131119

132-
.. code-block:: python
120+
.. jupyter-execute::
133121

134122
# Define the plot formating
135123
my_scale_factor = 0.001
@@ -165,112 +153,36 @@ one plot for the |MeshesContainer|
165153
text="e",
166154
window_size=my_window_size)
167155

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-
208156
Plot data on the deformed geometry
209157
----------------------------------
210158

211159
Plot the data on its mesh support
212160
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
213161

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.
215163

216164
Plot the stress results on the deformed geometry:
217165

218-
.. code-block:: python
166+
.. jupyter-execute::
219167

220168
# Define the stress field
221169
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
233171
stress_field.plot( deform_by=my_disp_field,
234172
scale_factor=my_scale_factor)
235173

236174
Plot the mesh and add the stress data on top of that
237175
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
238176

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|.
240178

241-
.. code-block:: python
179+
.. jupyter-execute::
242180

243181
# 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-
253182
my_meshed_region.plot( field_or_fields_container=stress_field,
254183
deform_by=my_disp_field,
255184
scale_factor=my_scale_factor)
256185

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)
274186

275187
.. rubric:: Footnotes
276188

0 commit comments

Comments
 (0)