Scope results over custom time domains#

The Result class, which are instances created by the Model, give access to helpers for requesting results on specific mesh and time scopings. With these helpers, working on a temporal subset of the model is straightforward. In this example, different ways to choose the temporal subset to evaluate a result are exposed. This example can be extended to frequency subsets.

# Import necessary modules
from ansys.dpf import core as dpf
from ansys.dpf.core import examples

Create a model object to establish a connection with an example result file:

model = dpf.Model(examples.download_transient_result())
print(model)
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
     -  elemental_summable_miscellaneous_data: Elemental Elemental Summable Miscellaneous Data
     -  element_nodal_forces: ElementalNodal Element nodal Forces
     -  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
     -  thermal_strain: ElementalNodal Thermal Strains
     -  thermal_strains_eqv: ElementalNodal Thermal Strains eqv
     -  swelling_strains: ElementalNodal Swelling Strains
     -  element_euler_angles: ElementalNodal Element Euler Angles
     -  structural_temperature: ElementalNodal Structural temperature
------------------------------
DPF  Meshed Region:
  3820 nodes
  789 elements
  Unit: m
  With solid (3D) elements, shell (2D) elements, shell (3D) elements
------------------------------
DPF  Time/Freq Support:
  Number of sets: 35
Cumulative     Time (s)       LoadStep       Substep
1              0.000000       1              1
2              0.019975       1              2
3              0.039975       1              3
4              0.059975       1              4
5              0.079975       1              5
6              0.099975       1              6
7              0.119975       1              7
8              0.139975       1              8
9              0.159975       1              9
10             0.179975       1              10
11             0.199975       1              11
12             0.218975       1              12
13             0.238975       1              13
14             0.258975       1              14
15             0.278975       1              15
16             0.298975       1              16
17             0.318975       1              17
18             0.338975       1              18
19             0.358975       1              19
20             0.378975       1              20
21             0.398975       1              21
22             0.417975       1              22
23             0.437975       1              23
24             0.457975       1              24
25             0.477975       1              25
26             0.497975       1              26
27             0.517975       1              27
28             0.537550       1              28
29             0.557253       1              29
30             0.577118       1              30
31             0.597021       1              31
32             0.616946       1              32
33             0.636833       1              33
34             0.656735       1              34
35             0.676628       1              35

Request specific time sets#

If specific time sets are of interest, looking into the TimeFreqSupport and connect a given time_scoping accordingly to the cumulative indexes can be useful.

print(model.metadata.time_freq_support)

time_sets = [1, 3, 10]
disp = model.results.displacement.on_time_scoping(time_sets).eval()

print(disp)

# Or using a scoping
time_sets_scoping = dpf.time_freq_scoping_factory.scoping_by_sets([1, 3, 10])
disp = model.results.displacement.on_time_scoping(time_sets_scoping).eval()

print(disp)
DPF  Time/Freq Support:
  Number of sets: 35
Cumulative     Time (s)       LoadStep       Substep
1              0.000000       1              1
2              0.019975       1              2
3              0.039975       1              3
4              0.059975       1              4
5              0.079975       1              5
6              0.099975       1              6
7              0.119975       1              7
8              0.139975       1              8
9              0.159975       1              9
10             0.179975       1              10
11             0.199975       1              11
12             0.218975       1              12
13             0.238975       1              13
14             0.258975       1              14
15             0.278975       1              15
16             0.298975       1              16
17             0.318975       1              17
18             0.338975       1              18
19             0.358975       1              19
20             0.378975       1              20
21             0.398975       1              21
22             0.417975       1              22
23             0.437975       1              23
24             0.457975       1              24
25             0.477975       1              25
26             0.497975       1              26
27             0.517975       1              27
28             0.537550       1              28
29             0.557253       1              29
30             0.577118       1              30
31             0.597021       1              31
32             0.616946       1              32
33             0.636833       1              33
34             0.656735       1              34
35             0.676628       1              35

DPF displacement(s)Fields Container
  with 3 field(s)
  defined on labels: time

  with:
  - field 0 {time:  1} with Nodal location, 3 components and 3820 entities.
  - field 1 {time:  3} with Nodal location, 3 components and 3820 entities.
  - field 2 {time:  10} with Nodal location, 3 components and 3820 entities.

DPF displacement(s)Fields Container
  with 3 field(s)
  defined on labels: time

  with:
  - field 0 {time:  1} with Nodal location, 3 components and 3820 entities.
  - field 1 {time:  3} with Nodal location, 3 components and 3820 entities.
  - field 2 {time:  10} with Nodal location, 3 components and 3820 entities.

Equivalent to:

disp_op = model.results.displacement()
disp_op.inputs.time_scoping(time_sets)
disp = disp_op.outputs.fields_container()

Equivalent to:

disp = model.results.displacement(time_scoping=time_sets_scoping).eval()

Request specific time steps#

If specific time steps or load steps are of interest, looking into the TimeFreqSupport and connect a given time_scoping located on steps can be done.

time_steps_scoping = dpf.time_freq_scoping_factory.scoping_by_load_step(1)
disp = model.results.displacement.on_time_scoping(time_steps_scoping).eval()

print(disp)
DPF displacement(s)Fields Container
  with 35 field(s)
  defined on labels: time

  with:
  - field 0 {time:  1} with Nodal location, 3 components and 3820 entities.
  - field 1 {time:  2} with Nodal location, 3 components and 3820 entities.
  - field 2 {time:  3} with Nodal location, 3 components and 3820 entities.
  - field 3 {time:  4} with Nodal location, 3 components and 3820 entities.
  - field 4 {time:  5} with Nodal location, 3 components and 3820 entities.
  - field 5 {time:  6} with Nodal location, 3 components and 3820 entities.
  - field 6 {time:  7} with Nodal location, 3 components and 3820 entities.
  - field 7 {time:  8} with Nodal location, 3 components and 3820 entities.
  - field 8 {time:  9} with Nodal location, 3 components and 3820 entities.
  - field 9 {time:  10} with Nodal location, 3 components and 3820 entities.
  - field 10 {time:  11} with Nodal location, 3 components and 3820 entities.
  - field 11 {time:  12} with Nodal location, 3 components and 3820 entities.
  - field 12 {time:  13} with Nodal location, 3 components and 3820 entities.
  - field 13 {time:  14} with Nodal location, 3 components and 3820 entities.
  - field 14 {time:  15} with Nodal location, 3 components and 3820 entities.
  - field 15 {time:  16} with Nodal location, 3 components and 3820 entities.
  - field 16 {time:  17} with Nodal location, 3 components and 3820 entities.
  - field 17 {time:  18} with Nodal location, 3 components and 3820 entities.
  - field 18 {time:  19} with Nodal location, 3 components and 3820 entities.
  - field 19 {time:  20} with Nodal location, 3 components and 3820 entities.
  - field 20 {time:  21} with Nodal location, 3 components and 3820 entities.
  - field 21 {time:  22} with Nodal location, 3 components and 3820 entities.
  - field 22 {time:  23} with Nodal location, 3 components and 3820 entities.
  - field 23 {time:  24} with Nodal location, 3 components and 3820 entities.
  - field 24 {time:  25} with Nodal location, 3 components and 3820 entities.
  - field 25 {time:  26} with Nodal location, 3 components and 3820 entities.
  - field 26 {time:  27} with Nodal location, 3 components and 3820 entities.
  - field 27 {time:  28} with Nodal location, 3 components and 3820 entities.
  - field 28 {time:  29} with Nodal location, 3 components and 3820 entities.
  - field 29 {time:  30} with Nodal location, 3 components and 3820 entities.
  - field 30 {time:  31} with Nodal location, 3 components and 3820 entities.
  - field 31 {time:  32} with Nodal location, 3 components and 3820 entities.
  - field 32 {time:  33} with Nodal location, 3 components and 3820 entities.
  - field 33 {time:  34} with Nodal location, 3 components and 3820 entities.
  - field 34 {time:  35} with Nodal location, 3 components and 3820 entities.

Equivalent to:

disp_op = model.results.displacement()
disp_op.inputs.time_scoping(time_steps_scoping)
disp = disp_op.outputs.fields_container()

Using helpers#

Evaluate at all times.

disp = model.results.displacement.on_all_time_freqs().eval()

Evaluate at first and last times

disp = model.results.displacement.on_first_time_freq().eval()
print(disp)
disp = model.results.displacement.on_last_time_freq().eval()
print(disp)
DPF displacement(s)Fields Container
  with 1 field(s)
  defined on labels: time

  with:
  - field 0 {time:  1} with Nodal location, 3 components and 3820 entities.

DPF displacement(s)Fields Container
  with 1 field(s)
  defined on labels: time

  with:
  - field 0 {time:  35} with Nodal location, 3 components and 3820 entities.

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

Gallery generated by Sphinx-Gallery