Note
Go to the end to download the full example code.
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.
Perform required imports#
This example uses a supplied file that you can
get using the examples
module.
from ansys.dpf import post
from ansys.dpf.post import examples
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.
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)
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
Extract displacement data#
displacement = simulation.displacement(all_sets=True)
print(displacement)
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
... ... ... ... ...
Compute the maximum displacement for each component at each time-step#
# 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)
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
Compute the minimum displacement for each component at each time-step#
# 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)
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
Total running time of the script: (0 minutes 0.233 seconds)