Note
Go to the end to download the full example code.
Get data from a static simulation#
This example shows how to get data from a previously stored static simulation. The available results can be listed to see what results can be retrieved.
Perform required imports#
Perform required imports. This example uses a supplied file that you can
get by importing the DPF examples
package.
from ansys.dpf import post
from ansys.dpf.post import examples
Get Solution
object#
Get the Solution
object that allows access to the result. The Solution
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.
simulation = post.load_simulation(examples.static_rst)
print(simulation)
Static Mechanical Simulation.
Data Sources
------------------------------
DPF DataSources:
Result files:
result key: rst and path: /opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/ansys/dpf/core/examples/result_files/static.rst
Secondary files:
DPF Model
------------------------------
Static analysis
Unit system: MKS: m, kg, N, s, V, A, degC
Physics Type: Mechanical
Available results:
- displacement: Nodal Displacement
- 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:
81 nodes
8 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
Get and plot displacements#
displacement = simulation.displacement()
Print information
print(displacement._fc)
DPF displacement(s)Fields Container
with 1 field(s)
defined on labels: time
with:
- field 0 {time: 1} with Nodal location, 3 components and 81 entities.
Plot displacements
displacement._fc[0].plot()

Get and plot stresses#
Get the “XY” stress component averaged on nodes.
stress = simulation.stress_nodal(components="XY")
Print information.
print(stress._fc)
DPF stress(s)Fields Container
with 1 field(s)
defined on labels: time
with:
- field 0 {time: 1} with Nodal location, 1 components and 81 entities.
Plot available stresses.
stress._fc[0].plot()

Get stresses at only five nodes#
Get stresses at only the first five nodes using their IDs.
stress_nodes = simulation.stress_nodal(node_ids=range(1, 6))
Print information.
print(stress_nodes._fc)
DPF stress(s)Fields Container
with 1 field(s)
defined on labels: time
with:
- field 0 {time: 1} with Nodal location, 6 components and 5 entities.
Plot stresses.
stress_nodes._fc[0].plot()

Get stresses in a named selection#
Get the name of the first named selection in the simulation.
Print information.
print(stress_named_sel._fc)
DPF stress(s)Fields Container
with 1 field(s)
defined on labels: time
with:
- field 0 {time: 1} with Nodal location, 6 components and 21 entities.
Plot stresses.
stress_named_sel._fc[0].plot()

Get stresses in a few elements#
Get stresses only for a few elements selected by their IDs.
stress_elements = simulation.stress_nodal(element_ids=[1, 2, 3])
Print information.
print(stress_elements._fc)
DPF stress(s)Fields Container
with 1 field(s)
defined on labels: time
with:
- field 0 {time: 1} with Nodal location, 6 components and 44 entities.
Plot stresses.
stress_elements._fc[0].plot()

Get elemental streses and raw stresses#
Get elemental stresses and print information.
stress_elements = simulation.stress_elemental()
print(stress_elements._fc)
DPF stress(s)Fields Container
with 1 field(s)
defined on labels: time
with:
- field 0 {time: 1} with Elemental location, 6 components and 8 entities.
Get raw stresses (ElementalNodal) and print information.
stress_raw = simulation.stress()
print(stress_raw._fc)
DPF stress(s)Fields Container
with 1 field(s)
defined on labels: time
with:
- field 0 {time: 1} with ElementalNodal location, 6 components and 8 entities.
Total running time of the script: (0 minutes 3.432 seconds)