Basic DPF-Core Usage

This example shows how to open an example result file and do some basic post-processing.

If you have ANSYS 2021R1 installed, getting running DPF is quite easy as ansys.dpf.core takes care of launching all the services required to start post-processing ANSYS files.

First, import the DPF-Core module as dpf_core and also import the included examples file.

from ansys.dpf import core as dpf
from ansys.dpf.core import examples

Next, open an example and then print out the model object. The Model class helps to organize access methods for the result by keeping track of the operators and data sources used by the result file.

Printing the model displays: - Analysis type - Available results - Size of the mesh - Number of results

Also, note that the first time you create a DPF object, Python will automatically attempt to start the server in the background. If you wish to connect to an existing server (either local or remote), use dpf.connect_to_server()

model = dpf.Model(examples.simple_bar)
print(model)

Out:

DPF Model
------------------------------
DPF Result Info
  Analysis: static
  Physics Type: mecanic
  Unit system: MKS: m, kg, N, s, V, A, degC
  Available results:
    U Displacement :nodal displacements
    ENF Element nodal Forces :element nodal forces
    ENG_VOL Volume :element volume
    ENG_SE Energy-stiffness matrix :element energy associated with the stiffness matrix
    ENG_AHO Hourglass Energy :artificial hourglass energy
    ENG_TH thermal dissipation energy :thermal dissipation energy
    ENG_KE Kinetic Energy :kinetic energy
    ENG_CO co-energy :co-energy (magnetics)
    ENG_INC incremental energy :incremental energy (magnetics)
    BFE Temperature :element structural nodal temperatures
------------------------------
DPF  Meshed Region:
  3751 nodes
  3000 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

Model Metadata

Specific metadata can be extracted from the model by referencing the metadata property of the model. For example, just the result_info can be printed with:

metadata = model.metadata
print(metadata.result_info)

Out:

DPF Result Info
  Analysis: static
  Physics Type: mecanic
  Unit system: MKS: m, kg, N, s, V, A, degC
  Available results:
    U Displacement :nodal displacements
    ENF Element nodal Forces :element nodal forces
    ENG_VOL Volume :element volume
    ENG_SE Energy-stiffness matrix :element energy associated with the stiffness matrix
    ENG_AHO Hourglass Energy :artificial hourglass energy
    ENG_TH thermal dissipation energy :thermal dissipation energy
    ENG_KE Kinetic Energy :kinetic energy
    ENG_CO co-energy :co-energy (magnetics)
    ENG_INC incremental energy :incremental energy (magnetics)
    BFE Temperature :element structural nodal temperatures

The mesh region can be printed with

print(metadata.meshed_region)

Out:

DPF  Meshed Region:
  3751 nodes
  3000 elements
  Unit: m
  With solid (3D) elements

and the time or frequency of the results can be printed with:

print(metadata.time_freq_support)

Out:

DPF  Time/Freq Support:
  Number of sets: 1
Cumulative     Time (s)       LoadStep       Substep
1              1.000000       1              1

Extracting Displacement Results

All results of the model can be accessed through the results property, which returns the Results class. This class contains the DPF result operators available to a specific result file, which are listed when printing the object with print(results)

Here, we connect the 'U' operator with the data_sources, which takes place automatically when running results.displacement(). By default, this is connected to the first result set, which for this static result is the only result.

results = model.results
displacements = results.displacement()
fields = displacements.outputs.fields_container()

# finally, extract the data of the displacement field
disp = fields[0].data
disp

Out:

array([[-1.22753781e-08, -1.20861254e-06, -5.02681396e-06],
       [-9.46666013e-09, -1.19379712e-06, -4.64249826e-06],
       [-1.22188426e-08, -1.19494216e-06, -4.63117832e-06],
       ...,
       [-1.35911608e-08,  1.52559428e-06, -4.29246409e-06],
       [-1.91212290e-08,  1.52577102e-06, -4.28782940e-06],
       [-2.69632909e-08,  1.52485289e-06, -4.27831232e-06]])
model.metadata.meshed_region.plot(fields)
00 basic example

Out:

[(4.199214280684376, 5.199214280684376, 4.199214280684376),
 (0.5, 1.5, 0.5),
 (0.0, 0.0, 1.0)]

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

Gallery generated by Sphinx-Gallery