.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01-Detailed-Examples/06-compute-min-max.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_examples_01-Detailed-Examples_06-compute-min-max.py: .. _ref_compute_statistics_example: Compute minimum and maximum of a DataFrame ========================================== In this example, transient mechanical displacement data is used to show how to compute the min or max of a given DataFrame. .. GENERATED FROM PYTHON SOURCE LINES 11-15 Perform required imports ------------------------ This example uses a supplied file that you can get using the ``examples`` module. .. GENERATED FROM PYTHON SOURCE LINES 15-19 .. code-block:: Python from ansys.dpf import post from ansys.dpf.post import examples .. GENERATED FROM PYTHON SOURCE LINES 20-26 Get ``Simulation`` object ------------------------- Get the ``Simulation`` object that allows access to the result. The ``Simulation`` object must be instantiated with the path for the result file. For example, ``"C:/Users/user/my_result.rst"`` on Windows or ``"/home/user/my_result.rst"`` on Linux. .. GENERATED FROM PYTHON SOURCE LINES 26-37 .. code-block:: Python example_path = examples.download_crankshaft() # to automatically detect the simulation type, use: simulation = post.load_simulation(example_path) # to enable auto-completion, use the equivalent: simulation = post.StaticMechanicalSimulation(example_path) # print the simulation to get an overview of what's available print(simulation) .. rst-class:: sphx-glr-script-out .. code-block:: none Static Mechanical Simulation. Data Sources ------------------------------ /opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/crankshaft/crankshaft.rst DPF Model ------------------------------ Static analysis Unit system: MKS: m, kg, N, s, V, A, degC Physics Type: Mechanical Available results: - displacement: Nodal Displacement - velocity: Nodal Velocity - acceleration: Nodal Acceleration - reaction_force: Nodal Force - stress: ElementalNodal Stress - elemental_volume: Elemental Volume - stiffness_matrix_energy: Elemental Energy-stiffness matrix - artificial_hourglass_energy: Elemental Hourglass Energy - thermal_dissipation_energy: Elemental thermal dissipation energy - kinetic_energy: Elemental Kinetic Energy - co_energy: Elemental co-energy - incremental_energy: Elemental incremental energy - elastic_strain: ElementalNodal Strain - element_euler_angles: ElementalNodal Element Euler Angles - structural_temperature: ElementalNodal Structural temperature ------------------------------ DPF Meshed Region: 69762 nodes 39315 elements Unit: m With solid (3D) elements ------------------------------ DPF Time/Freq Support: Number of sets: 3 Cumulative Time (s) LoadStep Substep 1 1.000000 1 1 2 2.000000 1 2 3 3.000000 1 3 .. GENERATED FROM PYTHON SOURCE LINES 38-40 Extract displacement data ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python displacement = simulation.displacement(all_sets=True) print(displacement) .. rst-class:: sphx-glr-script-out .. code-block:: none results U (m) set_ids 1 2 3 node_ids components 4872 X 5.6781e-06 -5.9469e-06 -3.4137e-05 Y 5.1667e-04 1.0318e-03 1.5417e-03 Z -3.2535e-06 -4.1346e-06 -2.6398e-06 9005 X -2.6323e-06 -2.1432e-05 -5.5625e-05 Y 4.8445e-04 9.6717e-04 1.4448e-03 Z -4.9795e-07 1.2790e-06 5.3134e-06 ... ... ... ... ... .. GENERATED FROM PYTHON SOURCE LINES 45-47 Compute the maximum displacement for each component at each time-step --------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 47-65 .. code-block:: Python # The default axis is the MeshIndex maximum_over_mesh = displacement.max() print(maximum_over_mesh) # is equivalent to maximum_over_mesh = displacement.max(axis="node_ids") print(maximum_over_mesh) # Compute the maximum displacement for each node and component across time # ------------------------------------------------------------------------ maximum_over_time = displacement.max(axis="set_ids") print(maximum_over_time) # Compute the maximum displacement overall # ---------------------------------------- maximum_overall = maximum_over_time.max() print(maximum_overall) .. rst-class:: sphx-glr-script-out .. code-block:: none results U (m) set_ids 1 2 3 components X 7.3303e-04 1.4495e-03 2.1441e-03 Y 1.3962e-03 2.7884e-03 4.1656e-03 Z 2.1567e-04 4.3321e-04 6.5135e-04 results U (m) set_ids 1 2 3 components X 7.3303e-04 1.4495e-03 2.1441e-03 Y 1.3962e-03 2.7884e-03 4.1656e-03 Z 2.1567e-04 4.3321e-04 6.5135e-04 results U (m) node_ids components 4872 X 5.6781e-06 Y 1.5417e-03 Z -2.6398e-06 9005 X -2.6323e-06 Y 1.4448e-03 Z 5.3134e-06 ... ... ... results U (m) components X 2.1441e-03 Y 4.1656e-03 Z 6.5135e-04 .. GENERATED FROM PYTHON SOURCE LINES 66-68 Compute the minimum displacement for each component at each time-step --------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 68-85 .. code-block:: Python # The default axis is the MeshIndex minimum_over_mesh = displacement.min() print(minimum_over_mesh) # is equivalent to minimum_over_mesh = displacement.min(axis="node_ids") print(minimum_over_mesh) # Compute the minimum displacement for each node and component across time # ------------------------------------------------------------------------ minimum_over_time = displacement.min(axis="set_ids") print(minimum_over_time) # Compute the minimum displacement overall # ---------------------------------------- minimum_overall = minimum_over_time.min() print(minimum_overall) .. rst-class:: sphx-glr-script-out .. code-block:: none results U (m) set_ids 1 2 3 components X -7.4732e-04 -1.5081e-03 -2.2755e-03 Y -4.0138e-04 -8.0316e-04 -1.2014e-03 Z -2.1555e-04 -4.3299e-04 -6.5101e-04 results U (m) set_ids 1 2 3 components X -7.4732e-04 -1.5081e-03 -2.2755e-03 Y -4.0138e-04 -8.0316e-04 -1.2014e-03 Z -2.1555e-04 -4.3299e-04 -6.5101e-04 results U (m) node_ids components 4872 X -3.4137e-05 Y 5.1667e-04 Z -4.1346e-06 9005 X -5.5625e-05 Y 4.8445e-04 Z -4.9795e-07 ... ... ... results U (m) components X -2.2755e-03 Y -1.2014e-03 Z -6.5101e-04 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.238 seconds) .. _sphx_glr_download_examples_01-Detailed-Examples_06-compute-min-max.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 06-compute-min-max.ipynb <06-compute-min-max.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 06-compute-min-max.py <06-compute-min-max.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_