.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_propertylib/plot_propertylib.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_howto_propertylib_plot_propertylib.py: Property Presets ================ .. sectionauthor:: Florian Zill (Helmholtz Centre for Environmental Research GmbH - UFZ) :py:mod:`ogstools.propertylib` provides classes (Scalar, Vector, Matrix) which encapsulate unit handling and data transformation for simplified processing of mesh data. There are several predefined properties stored under the module :py:mod:`ogstools.propertylib.presets`. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: Python from ogstools.meshplotlib import examples, plot from ogstools.propertylib import Scalar, presets presets.get_dataframe() .. raw:: html
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

17 rows × 5 columns



.. GENERATED FROM PYTHON SOURCE LINES 20-24 Scalar, Vector and Matrix inherit from the class Property with its :meth:`~ogstools.propertylib.Property.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: .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: Python presets.temperature.transform(273.15) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.0 .. GENERATED FROM PYTHON SOURCE LINES 29-31 You can also create your own properties by creating a Scalar, Vector or Matrix property. The following doesn't do any unit conversion. .. GENERATED FROM PYTHON SOURCE LINES 33-38 .. code-block:: Python custom_temperature = Scalar( data_name="temperature", data_unit="K", output_unit="K" ) custom_temperature.transform(273.15) .. rst-class:: sphx-glr-script-out .. code-block:: none array(273.15) .. GENERATED FROM PYTHON SOURCE LINES 39-40 Or use existing presets as a template and replace some parameters: .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: Python custom_temperature = presets.temperature.replace(output_unit="°F") custom_temperature.transform(273.15) .. rst-class:: sphx-glr-script-out .. code-block:: none 31.999999999999936 .. GENERATED FROM PYTHON SOURCE LINES 44-49 Components of Vector properties and Matrix properties can be accessed with bracket indexing. :class:`~ogstools.propertylib.vector.Vector` properties should be of length 2 or 3 corresponding to the dimension. :class:`~ogstools.propertylib.matrix.Matrix` properties likewise should be of length 4 [xx, yy, zz, xy] or 6 [xx, yy, zz, xy, yz, xz]. .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: Python presets.displacement[1].transform([0.01, 0.02, 0.03]) .. rst-class:: sphx-glr-script-out .. code-block:: none array(0.02) .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: Python presets.strain["xx"].transform([0.01, 0.02, 0.03, 0.04, 0.05, 0.06]) .. rst-class:: sphx-glr-script-out .. code-block:: none 1.0 .. GENERATED FROM PYTHON SOURCE LINES 57-58 Magnitude of a 2D displacement vector: .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: Python presets.displacement.magnitude.transform([0.03, 0.04]) .. rst-class:: sphx-glr-script-out .. code-block:: none 0.05 .. GENERATED FROM PYTHON SOURCE LINES 63-67 We suggest specifying the properties and their transformations once. These can be reused in different kind of post processing. When plotting with :py:mod:`ogstools.meshplotlib` we can use these presets to simplify the task of processing the data (e.g. calculate the von Mises stress): .. GENERATED FROM PYTHON SOURCE LINES 69-71 .. code-block:: Python fig = plot(examples.mesh_mechanics, presets.stress.von_Mises) .. image-sg:: /auto_examples/howto_propertylib/images/sphx_glr_plot_propertylib_001.png :alt: plot propertylib :srcset: /auto_examples/howto_propertylib/images/sphx_glr_plot_propertylib_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 72-74 Have a look at :ref:`sphx_glr_auto_examples_howto_meshplotlib` for more examples. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.314 seconds) .. _sphx_glr_download_auto_examples_howto_propertylib_plot_propertylib.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_propertylib.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_propertylib.py `