Extract stress/strain invariants - Static Simulation#

In this script a static simulation is used as an example to show how to extract tensor’s invariants.

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 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()
simulation = post.load_simulation(example_path)

# for no autocompletion, this line is equivalent to:
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.8.16/x64/lib/python3.8/site-packages/ansys/dpf/core/examples/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
     -  structural_temperature: ElementalNodal 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 elemental nodal stress and strain#

stress = simulation.stress(all_sets=True)
print(stress)

strain = simulation.elastic_strain(all_sets=True)
print(strain)
                results           S
                set_ids           1           2           3
element_ids  components
      18357      XX (1)  2.7979e+06  4.3949e+06  4.6183e+06
                 YY (1)  8.6092e+06  2.8565e+07  5.9405e+07
                 ZZ (1) -1.0166e+07 -2.6681e+06  2.2825e+07
                 XY (1)  5.9477e+05  7.8847e+05 -3.5088e+05
                 YZ (1) -1.9866e+08 -3.9727e+08 -5.9452e+08
                 XZ (1) -6.6205e+06 -4.0082e+06  7.6945e+06
        ...


                results        EPEL
                set_ids           1           2           3
element_ids  components
      18357      XX (1)  1.6326e-05 -1.6871e-05 -1.0025e-04
                 YY (1)  5.4098e-05  1.4024e-04  2.5586e-04
                 ZZ (1) -6.7943e-05 -6.2781e-05  1.8092e-05
                 XY (1)  7.7320e-06  1.0250e-05 -4.5614e-06
                 YZ (1) -2.5826e-03 -5.1645e-03 -7.7287e-03
                 XZ (1) -8.6066e-05 -5.2106e-05  1.0003e-04
        ...

Compute principal invariant averaged and unaveraged on stress and strain#

princ_stress_1 = simulation.stress_principal(components=[1])
print(princ_stress_1)

nodal_princ_stress_2 = simulation.stress_principal_nodal(components=[2])
print(nodal_princ_stress_2)
nodal_princ_stress_2.plot()

nodal_princ_strain_2 = simulation.elastic_strain_principal_nodal(components=[2])
print(nodal_princ_strain_2)
nodal_princ_strain_2.plot()
  • 04 invariants
  • 04 invariants
                results           S
                set_ids           3
element_ids  components
      18357       1 (1)  6.3596e+08
      18357       1 (2)  5.3499e+08
      18357       1 (3)  6.6581e+08
      18357       1 (4)  4.2794e+08
      18357   1 (1) (1)  3.6762e+08
      18357   1 (1) (2)  2.3020e+08
        ...


                results           S
                set_ids           3
   node_ids  components
       4872           2 -1.4818e+06
       9005              3.1627e+05
       9373              4.0889e+07
       9372             -3.2059e+07
       4876              1.9911e+07
       9781             -1.1439e+08
        ...


                results        EPEL
                set_ids           3
   node_ids  components
       4872           2 -1.2351e-04
       9005             -1.2034e-04
       9373             -1.4734e-04
       9372              1.8417e-05
       4876              6.4584e-04
       9781              7.0507e-05
        ...

Compute Von Mises eqv averaged and unaveraged on stress and strain#

stress_eqv = simulation.stress_eqv_von_mises(set_ids=[1])
print(stress_eqv)

nodal_stress_eqv = simulation.stress_eqv_von_mises_nodal(set_ids=[1])
nodal_stress_eqv.plot()

nodal_strain_eqv = simulation.elastic_strain_eqv_von_mises_nodal(set_ids=[1])
nodal_strain_eqv.plot()
  • 04 invariants
  • 04 invariants
    results           S
    set_ids           1
element_ids
      18357 (1)  3.4469e+08
      18357 (2)  2.8529e+08
      18357 (3)  3.1625e+08
      18357 (4)  2.8731e+08
      18357 (1)  3.3939e+08
      18357 (2)  2.7271e+08
        ...

Total running time of the script: ( 0 minutes 7.739 seconds)

Gallery generated by Sphinx-Gallery