ANSYS DPF Overview of the POST API

This tutorial shows quickly how to use the DPF-POST API. For more details, you can read the detailed tutorials in the examples gallery.

Start ansys.post module

Here we load the post module.

from ansys.dpf import post

Prepare a solution object

We will first get the solution object that allows to access the result. It must be instantiated with the result filepath like "C:/Users/user/my_result.rst" or on Linux "/home/user/my_result.rst"

In this example, we use a built-in example included with this module, which you can get by importing the examples module from ansys.dpf.post

from ansys.dpf.post import examples
solution = post.load_solution(examples.multishells_rst)

Get the mesh and the time_freq_support

The mesh is the support of the model. The time freq support is the time/frequence representation of the model.

mesh = solution.mesh
time_freq_support = solution.time_freq_support

Get a result object from the solution object

The result can be: stress, plastic_strain, elastic_strain, temperature, displacement).

post.print_available_keywords()
stress = solution.stress(location=post.locations.nodal, time_scoping=[1])

# both the location and time_scoping are available in the definition of
# the stress result
stress.definition.location
stress.definition.time_scoping

print(stress)

Out:

element_scoping: list, int or dpf.core.Scoping
grouping: str. Use post.grouping.(...) as helper.
location: str. Use post.locations.(...) as helper.
mapdl_grouping: int. Write 186 to get mapdl_elements solid_186.
named_selection: str. Name of named_selection.
node_scoping: list, int or dpf.core.Scoping
set: int
time: float
time_scoping: list, int or dpf.core.Scoping

Stress Tensor object.

Object properties:
 - location   : Nodal
 - time_scoping : [1]

Compute data

Here is shown how to get a subresult such as SX, the stress tensor in the XX direction.

SX subresult

sx = stress.xx
sx.num_fields
sx_field = sx[0]
sx_data = sx.get_data_at_field(0)
print('Length of the data:', len(sx_data))
print()
print('Maximum Stress Field:\n', sx.max)
print()
print('Maximum data at stress field:', sx.max_data)
print('Maximum SX at Field 0:', sx.get_max_data_at_field(0))

Out:

Length of the data: 6854

Maximum Stress Field:
 DPF stress_1.s0 Field
  Location: Nodal
  Unit: Pa
  2 entities
  Data:1 components and 2 elementary data


Maximum data at stress field: [6.67615284e+11 1.53671424e+13]
Maximum SX at Field 0: 667615283882.6666

Stress tensor result Here we get the minimum and maximum stresses at a field for all directions, including ‘XX’, ‘XY, ‘XZ’, ‘XY’, ‘YZ’, and ‘XZ’.

s = stress.tensor
s_field = s[0]
s_data = sx.get_data_at_field(0)
print('Length of the data:', len(s_data))
print()
print('Maximum Stress Field:\n', s.max)
print()
print('Maximum data at stress field:', s.max_data)
print('Maximum Stress Tensors at Field 0:\n', s.get_max_data_at_field(0))

print('Minimum Stress Field:\n', s.min)
print()
print('Minimum data at stress field:', s.min_data)
print('Minimum Stress Tensors at Field 0:\n', s.get_min_data_at_field(0))

Out:

Length of the data: 6854

Maximum Stress Field:
 DPF stress_1.s Field
  Location: Nodal
  Unit: Pa
  2 entities
  Data:6 components and 2 elementary data


Maximum data at stress field: [[6.67615284e+11 8.74460905e+11 4.95394439e+11 6.01889079e+11
  1.10325826e+11 1.85580244e+11]
 [1.53671424e+13 4.21781549e+08 3.78202198e+12 2.07950475e+11
  1.57995981e+11 1.09972131e+12]]
Maximum Stress Tensors at Field 0:
 [6.67615284e+11 8.74460905e+11 4.95394439e+11 6.01889079e+11
 1.10325826e+11 1.85580244e+11]
Minimum Stress Field:
 DPF stress_1.s Field
  Location: Nodal
  Unit: Pa
  2 entities
  Data:6 components and 2 elementary data


Minimum data at stress field: [[-5.77907764e+11 -7.35604867e+11 -2.41200931e+11 -2.98145939e+11
  -2.42143056e+11 -3.09138563e+11]
 [-1.49601458e+13 -2.63695614e+08 -3.77945626e+12 -3.35432675e+11
  -1.57190152e+11 -9.66123233e+11]]
Minimum Stress Tensors at Field 0:
 [-5.77907764e+11 -7.35604867e+11 -2.41200931e+11 -2.98145939e+11
 -2.42143056e+11 -3.09138563e+11]

Display a result

Use <subresult>.plot_contour() to plot a result.

s.plot_contour()
00 overview example

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

Gallery generated by Sphinx-Gallery