.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials\post_processing_basics\main_steps.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_post_processing_basics_main_steps.py: .. _ref_tutorials_main_steps: Postprocessing main steps ========================= There are four main steps to transform simulation data into output data that can be used to visualize and analyze simulation results: 1. Import and open results files 2. Access and extract results 3. Transform available data 4. Visualize the data .. GENERATED FROM PYTHON SOURCE LINES 39-43 1- Import and open results files --------------------------------- First, import the DPF-Core module as ``dpf`` and import the included examples file. .. GENERATED FROM PYTHON SOURCE LINES 43-51 .. code-block:: Python # Import the ansys.dpf.core module as ``dpf`` from ansys.dpf import core as dpf # Import the examples module # Import the operators module from ansys.dpf.core import examples, operators as ops .. GENERATED FROM PYTHON SOURCE LINES 52-55 :class:`DataSources ` is a class that manages paths to their files. Use this object to declare data inputs for DPF and define their locations. .. GENERATED FROM PYTHON SOURCE LINES 55-59 .. code-block:: Python # Define the DataSources object my_data_sources = dpf.DataSources(result_path=examples.find_simple_bar()) .. GENERATED FROM PYTHON SOURCE LINES 60-72 The :class:`Model ` class creates and evaluates common readers for the files it is given, such as a mesh provider, a result info provider, and a streams provider. It provides dynamically built methods to extract the results available in the files, as well as many shortcuts to facilitate exploration of the available data. Printing the model displays: - Analysis type - Available results - Size of the mesh - Number of results .. GENERATED FROM PYTHON SOURCE LINES 72-77 .. code-block:: Python # Define the Model object my_model = dpf.Model(data_sources=my_data_sources) print(my_model) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Model ------------------------------ Static analysis Unit system: MKS: m, kg, N, s, V, A, degC Physics Type: Mechanical Available results: - node_orientations: Nodal Node Euler Angles - displacement: Nodal Displacement - element_nodal_forces: ElementalNodal Element nodal Forces - elemental_volume: Elemental Volume - stiffness_matrix_energy: Elemental Energy-stiffness matrix - artificial_hourglass_energy: Elemental Hourglass Energy - kinetic_energy: Elemental Kinetic Energy - co_energy: Elemental co-energy - incremental_energy: Elemental incremental energy - thermal_dissipation_energy: Elemental thermal dissipation energy - element_orientations: ElementalNodal Element Euler Angles - structural_temperature: ElementalNodal Structural temperature ------------------------------ DPF Meshed Region: 3751 nodes 3000 elements Unit: m With solid (3D) elements ------------------------------ DPF Time/Freq Support: Number of sets: 1 Cumulative Time (s) LoadStep Substep 1 1.000000 1 1 .. GENERATED FROM PYTHON SOURCE LINES 78-83 2- Access and extract results ----------------------------- We see in the model that a displacement result is available. You can access this result by: .. GENERATED FROM PYTHON SOURCE LINES 83-88 .. code-block:: Python # Define the displacement results through the model property `results` my_displacements = my_model.results.displacement.eval() print(my_displacements) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF displacement(s)Fields Container with 1 field(s) defined on labels: time with: - field 0 {time: 1} with Nodal location, 3 components and 3751 entities. .. GENERATED FROM PYTHON SOURCE LINES 89-90 The displacement data can be extracted by: .. GENERATED FROM PYTHON SOURCE LINES 90-95 .. code-block:: Python # Extract the data of the displacement field my_displacements_0 = my_displacements[0].data print(my_displacements_0) .. rst-class:: sphx-glr-script-out .. code-block:: none [[-1.22753781e-08 -1.20861254e-06 -5.02681396e-06] [-9.46666013e-09 -1.19379712e-06 -4.64249826e-06] [-1.22188426e-08 -1.19494216e-06 -4.63117832e-06] ... [-1.35911608e-08 1.52559428e-06 -4.29246409e-06] [-1.91212290e-08 1.52577102e-06 -4.28782940e-06] [-2.69632909e-08 1.52485289e-06 -4.27831232e-06]] .. GENERATED FROM PYTHON SOURCE LINES 96-104 3- Transform available data --------------------------- Several transformations can be made with the data. They can be a single operation, by using only one operator, or they can represent a succession of operations, by defining a workflow with chained operators. Here we start by computing the displacements norm. .. GENERATED FROM PYTHON SOURCE LINES 104-109 .. code-block:: Python # Define the norm operator (here for a fields container) for the displacement my_norm = ops.math.norm_fc(fields_container=my_displacements).eval() print(my_norm[0].data) .. rst-class:: sphx-glr-script-out .. code-block:: none [5.17008254e-06 4.79354058e-06 4.78287034e-06 ... 4.55553187e-06 4.55124420e-06 4.54201053e-06] .. GENERATED FROM PYTHON SOURCE LINES 110-111 Then we compute the maximum values of the normalised displacement. .. GENERATED FROM PYTHON SOURCE LINES 111-116 .. code-block:: Python # Define the maximum operator and chain it to the norm operator my_max = ops.min_max.min_max_fc(fields_container=my_norm).outputs.field_max() print(my_max) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF displacement_1.s Field Location: Nodal Unit: m 1 entities Data: 1 components and 1 elementary data IDs data(m) ------------ ---------- 0 2.523683e-05 .. GENERATED FROM PYTHON SOURCE LINES 117-121 4- Visualize the data ---------------------- Plot the transformed displacement results. .. GENERATED FROM PYTHON SOURCE LINES 121-124 .. code-block:: Python # Define the support of the plot (here we plot the displacement over the mesh) my_model.metadata.meshed_region.plot(field_or_fields_container=my_displacements) .. image-sg:: /tutorials/post_processing_basics/images/sphx_glr_main_steps_001.png :alt: main steps :srcset: /tutorials/post_processing_basics/images/sphx_glr_main_steps_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (None, ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.417 seconds) .. _sphx_glr_download_tutorials_post_processing_basics_main_steps.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: main_steps.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: main_steps.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: main_steps.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_