Variable presets and data transformation#

Section author: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ)

ogstools.variables provides classes (Scalar, Vector, Matrix) which encapsulate unit handling and data transformation for simplified processing of mesh data. There are also several predefined variables.

import ogstools as ogs
from ogstools import examples

ogs.variables.get_dataframe()
data_name data_unit output_unit output_name type
preset
heatflowrate HeatFlowRate HeatFlowRate Scalar
massflowrate MassFlowRate MassFlowRate Scalar
material_id MaterialIDs MaterialIDs Scalar
nodal_forces NodalForces NodalForces Vector
... ... ... ... ... ...
fluid_pressure_crit sigma Pa MPa fluid_pressure_criterion Scalar
stress sigma Pa MPa stress Matrix
temperature temperature K °C temperature Scalar
velocity velocity m/s m/s darcy_velocity Vector

18 rows × 5 columns



Scalar, Vector and Matrix inherit from the class Variable with its transform() function. This function converts the argument from data_unit to output_unit and applies a function if specified. In this case we convert from K to °C:

ogs.variables.temperature.transform(273.15, strip_unit=False)
0.0 °C


You can also create your own variables by creating a Scalar, Vector or Matrix variable. The following doesn’t do any unit conversion.

custom_temperature = ogs.variables.Scalar(
    data_name="temperature", data_unit="K", output_unit="K"
)
custom_temperature.transform(273.15, strip_unit=False)
273.15 K


Or use existing presets as a template and replace some parameters:

custom_temperature = ogs.variables.temperature.replace(output_unit="°F")
custom_temperature.transform(273.15, strip_unit=False)
31.999999999999936 °F


Components of Vector variables and Matrix variables can be accessed with bracket indexing. Vector variables should be of length 2 or 3 corresponding to the dimension. Matrix variables likewise should be of length 4 [xx, yy, zz, xy] or 6 [xx, yy, zz, xy, yz, xz].

ogs.variables.displacement[1].transform([0.01, 0.02, 0.03], strip_unit=False)
0.02 m


ogs.variables.strain["xx"].transform(
    [0.01, 0.02, 0.03, 0.04, 0.05, 0.06], strip_unit=False
)
1.0 %


Magnitude of a 2D displacement vector:

ogs.variables.displacement.magnitude.transform([0.03, 0.04], strip_unit=False)
0.05 m


We suggest specifying the variables and their transformations once. These can be reused in different kind of post processing. When plotting with ogstools.plot we can use these presets to simplify the task of processing the data (e.g. calculate the von Mises stress):

fig = ogs.plot.contourf(
    examples.load_mesh_mechanics_2D(), ogs.variables.stress.von_Mises
)
plot variables

Have a look at Plotting the data for more examples.

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