|
| 1 | +.. _ref_tutorials_basic: |
| 2 | + |
| 3 | +================== |
| 4 | +The basic tutorial |
| 5 | +================== |
| 6 | + |
| 7 | +This tutorial guides throughout the basic concepts and features of the PyDPF-Core tool. |
| 8 | +It helps to have a Python interpreter for hands-on experience, but all code examples are |
| 9 | +executed, so the tutorial can be read off-line as well. |
| 10 | + |
| 11 | +For a complete description of all the objects and modules, see the :ref:`API reference <ref_api_section>` section. |
| 12 | + |
| 13 | +This page is divided in two sections: |
| 14 | + |
| 15 | +.. grid:: 1 1 2 2 |
| 16 | + :gutter: 2 |
| 17 | + :padding: 2 |
| 18 | + :margin: 2 |
| 19 | + |
| 20 | + .. grid-item-card:: Overview |
| 21 | + :link: tutorials_overview |
| 22 | + :link-type: ref |
| 23 | + :text-align: center |
| 24 | + |
| 25 | + Learn the different ways to interact with data by calling PyDPF-Core commands and operators. |
| 26 | + |
| 27 | + .. grid-item-card:: Postprocessing main steps |
| 28 | + :link: tutorials_main_steps |
| 29 | + :link-type: ref |
| 30 | + :text-align: center |
| 31 | + |
| 32 | + How to do a basic prost-processing by transforming simulation data into output |
| 33 | + data that can be used to visualize and analyze results |
| 34 | + |
| 35 | +.. _tutorials_overview: |
| 36 | + |
| 37 | +Overview |
| 38 | +-------- |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +.. _tutorials_main_steps: |
| 43 | + |
| 44 | +Postprocessing main steps |
| 45 | +------------------------- |
| 46 | + |
| 47 | +There are five main steps to transform simulation data into output data that can |
| 48 | +be used to visualize and analyze simulation results: |
| 49 | + |
| 50 | +.. grid:: |
| 51 | + :gutter: 2 |
| 52 | + :padding: 2 |
| 53 | + :margin: 2 |
| 54 | + |
| 55 | + .. grid-item-card:: 1 |
| 56 | + :link: tutorials_main_steps_1 |
| 57 | + :link-type: ref |
| 58 | + :text-align: center |
| 59 | + |
| 60 | + Importing and opening results files |
| 61 | + |
| 62 | + .. grid-item-card:: 2 |
| 63 | + :link: tutorials_main_steps_2 |
| 64 | + :link-type: ref |
| 65 | + :text-align: center |
| 66 | + |
| 67 | + Access and extract results |
| 68 | + |
| 69 | + .. grid-item-card:: 3 |
| 70 | + :link: tutorials_main_steps_3 |
| 71 | + :link-type: ref |
| 72 | + :text-align: center |
| 73 | + |
| 74 | + Transform available data |
| 75 | + |
| 76 | + .. grid-item-card:: 4 |
| 77 | + :link: tutorials_main_steps_4 |
| 78 | + :link-type: ref |
| 79 | + :text-align: center |
| 80 | + |
| 81 | + Visualize the data |
| 82 | + |
| 83 | + .. grid-item-card:: 5 |
| 84 | + :link: tutorials_main_steps_5 |
| 85 | + :link-type: ref |
| 86 | + :text-align: center |
| 87 | + |
| 88 | + Extract data |
| 89 | + |
| 90 | +.. _tutorials_main_steps_1: |
| 91 | + |
| 92 | +1- Importing and opening results files |
| 93 | +************************************** |
| 94 | + |
| 95 | +First, import the DPF-Core module as ``dpf`` and import the included examples file |
| 96 | + |
| 97 | +.. code-block:: python |
| 98 | +
|
| 99 | + from ansys.dpf import core as dpf |
| 100 | + from ansys.dpf.core import examples |
| 101 | + from ansys.dpf.core import operators as ops |
| 102 | +
|
| 103 | +`DataSources' is a class that manages paths to their files. Use this object to declare |
| 104 | +data inputs for DPF and define their locations. |
| 105 | + |
| 106 | +.. code-block:: python |
| 107 | + |
| 108 | + # Define the DataSources object |
| 109 | + my_data_sources = dpf.DataSources(result_path=examples.find_simple_bar()) |
| 110 | + |
| 111 | + |
| 112 | +The model is a helper designed to give shortcuts to access the analysis results |
| 113 | +metadata, by opening a DataSources or a Streams, and to instanciate results provider for it. |
| 114 | + |
| 115 | +Printing the model displays: |
| 116 | + |
| 117 | + - Analysis type |
| 118 | + - Available results |
| 119 | + - Size of the mesh |
| 120 | + - Number of results |
| 121 | + |
| 122 | +.. code-block:: python |
| 123 | + |
| 124 | + # Define the Model object |
| 125 | + my_model = dpf.Model(data_sources=my_data_sources) |
| 126 | + print(my_model) |
| 127 | + |
| 128 | +.. rst-class:: sphx-glr-script-out |
| 129 | + |
| 130 | + .. jupyter-execute:: |
| 131 | + :hide-code: |
| 132 | + |
| 133 | + from ansys.dpf import core as dpf |
| 134 | + from ansys.dpf.core import examples |
| 135 | + from ansys.dpf.core import operators as ops |
| 136 | + my_data_sources = dpf.DataSources(result_path=examples.find_simple_bar()) |
| 137 | + my_model = dpf.Model(data_sources=my_data_sources) |
| 138 | + print(my_model) |
| 139 | + |
| 140 | +.. _tutorials_main_steps_2: |
| 141 | + |
| 142 | +2- Access and extract results |
| 143 | +***************************** |
| 144 | + |
| 145 | +We see in the model that a displacement result is available. You can access this result by: |
| 146 | + |
| 147 | +.. code-block:: python |
| 148 | + |
| 149 | + # Define the displacement results through the models property `results` |
| 150 | + my_displacements = my_model.results.displacement.eval() |
| 151 | + print(my_displacements) |
| 152 | + |
| 153 | +.. rst-class:: sphx-glr-script-out |
| 154 | + |
| 155 | + .. jupyter-execute:: |
| 156 | + :hide-code: |
| 157 | + |
| 158 | + my_displacements = my_model.results.displacement.eval() |
| 159 | + print(my_displacements) |
| 160 | + |
| 161 | +The displacement data can be extract by: |
| 162 | + |
| 163 | +.. code-block:: python |
| 164 | +
|
| 165 | + # Extract the data of the displacement field |
| 166 | + my_displacements_0 = my_displacements[0].data |
| 167 | + print(my_displacements_0) |
| 168 | +
|
| 169 | +.. rst-class:: sphx-glr-script-out |
| 170 | + |
| 171 | + .. jupyter-execute:: |
| 172 | + :hide-code: |
| 173 | + |
| 174 | + my_displacements_0 = my_displacements[0].data |
| 175 | + print(my_displacements_0) |
| 176 | + |
| 177 | +.. _tutorials_main_steps_3: |
| 178 | + |
| 179 | +3- Transform available data |
| 180 | +*************************** |
| 181 | + |
| 182 | +Several transformations can be made with the data. They can be a single operation, |
| 183 | +by using only one operator, or they can represent a succession of operations, by defining a |
| 184 | +workflow with chained operators. |
| 185 | + |
| 186 | +Here we star by computing the displacements norm. |
| 187 | + |
| 188 | +.. code-block:: python |
| 189 | +
|
| 190 | + # Define the norm operator (here for a fields container) for the displacement |
| 191 | + my_norm = ops.math.norm_fc(fields_container=my_displacements).eval() |
| 192 | + print(my_norm[0].data) |
| 193 | +
|
| 194 | +.. rst-class:: sphx-glr-script-out |
| 195 | + |
| 196 | + .. jupyter-execute:: |
| 197 | + :hide-code: |
| 198 | + |
| 199 | + my_norm = ops.math.norm_fc(fields_container=my_displacements).eval() |
| 200 | + print(my_norm[0].data) |
| 201 | + |
| 202 | +Then we compute the maximum values of the normalised displacement |
| 203 | + |
| 204 | +.. code-block:: python |
| 205 | +
|
| 206 | + # Define the maximum operator and chain it to the norm operator |
| 207 | + my_max= ops.min_max.min_max_fc(fields_container=my_norm).outputs.field_max() |
| 208 | + print(my_max) |
| 209 | +
|
| 210 | +.. rst-class:: sphx-glr-script-out |
| 211 | + |
| 212 | + .. jupyter-execute:: |
| 213 | + :hide-code: |
| 214 | + |
| 215 | + my_max = ops.min_max.min_max_fc(fields_container=my_norm).outputs.field_max() |
| 216 | + print(my_max) |
| 217 | + |
| 218 | +.. _tutorials_main_steps_4: |
| 219 | + |
| 220 | +4- Visualize the data |
| 221 | +********************* |
| 222 | + |
| 223 | +Plot the transformed displacement results |
| 224 | + |
| 225 | +.. code-block:: python |
| 226 | +
|
| 227 | + # Define the support of the plot (here we plot the displacement over the mesh) |
| 228 | + my_model.metadata.meshed_region.plot(field_or_fields_container=my_displacements) |
| 229 | +
|
| 230 | +.. rst-class:: sphx-glr-script-out |
| 231 | + |
| 232 | + .. jupyter-execute:: |
| 233 | + :hide-code: |
| 234 | + |
| 235 | + my_model.metadata.meshed_region.plot(field_or_fields_container=my_displacements) |
| 236 | + |
| 237 | +.. _tutorials_main_steps_5: |
| 238 | + |
| 239 | +5- Extract the data |
| 240 | +******************* |
| 241 | + |
0 commit comments