.. _UserDefinedPostprocessing:
User Defined Postprocessing via :code:`userDefinedFields`
=========================================================
In Flow360, users can specify custom expressions to calculate outputs based on some solver variables. These variables can be used in the :code:`outputFields` of :ref:`volumeOutput`, :ref:`surfaceOutput`, :ref:`sliceOutput`, :ref:`isoSurfaceOutput` and :ref:`monitorOutput`.
We will illustrate how to use this feature using several example.
.. note::
We provide a complete list of available functions and some guidelines in our :ref:`knowledge base`.
.. _UDFTotPressure:
Custom Output Variable
--------------------------------------------------------------------------
In this example, we compute the total pressure coefficient for the entire domain of an :ref:`om6Wing` simulation. For the definition of the total pressure coefficient please see :ref:`here`.
First we need to define the expression for total pressure coefficient.
.. literalinclude:: Files/totalPressureCoefficientUserDefinedFields.json
:linenos:
A statement-by-statement breakdown of the above expression is shown in following table:
.. _UserDefinedFields_:
.. table::
:widths: 40 50
+---------------------------------------------------+-------------------------------------------------------------------+
| Expression | Explanation |
+===================================================+===================================================================+
| :code:`double gamma = 1.40;....` | A declaration of local variables that can be used \ |
| | in subsequent expression. |
+---------------------------------------------------+-------------------------------------------------------------------+
| :code:`double Mach = sqrt(primit....`\ | Still a declaration. But the Mach number is calculated locally \ |
| | even though it is a valid option for :code:`outputFields`. \|
| | This is an example that not all the pre-defined output variables \|
| | are available to be used in the expression. |
+---------------------------------------------------+-------------------------------------------------------------------+
| :code:`TotalPressureCoeff = (gamma*pri....`\ | This assigns the final result to the total pressure coefficient.\ |
| | Note that the output variable name in the expression \ |
| | (:code:`TotalPressureCoeff`) is exactly \ |
| | the same as its :code:`name` entry in the JSON. \ |
+---------------------------------------------------+-------------------------------------------------------------------+
Then we need to add :code:`TotalPressureCoeff` in one of the outputs. Here we use :ref:`volumeOutput`.
.. literalinclude:: Files/totalPressureCoefficientInVolumeOutputs.json
:linenos:
.. _UDFSurfIntegral:
Custom surface integral
--------------------------------------------------------------------------
In Flow360 we have added a new type of monitor which is called surface-integral monitor in addition to the probe monitor which monitor quantities at a set of given coordinates. The surface-integral monitor will try to compute the surface integral of the given variable on given patches. Here we show an example of calculating the pressure force on a no-slip wall as an example.
.. literalinclude:: Files/pressureForceUserDefinedFields.json
:linenos:
Note that the :code:`nodeNormals` is a vector whose direction is the normal of the given patch at each node and the magnitude is the area associated with the node. Therefore the right hand side of the :code:`PressureForce` corresponds to the red part of the following equation for pressure force:
.. math::
:label: def_pressureForce
\overrightarrow{\mathbf{f_p}} = \int {\color{Red} \left(p - p_{ref}\right )d\overrightarrow{\mathbf{A}}}
where the :math:`\overrightarrow{\mathbf{f_p}}` is the pressure force, :math:`p_{ref}` is the free steam pressure. Surface integrals for scalar outputs should use :code:`magnitude(nodeNormals)` instead to include the area (:math:`dA`) in integral. Otherwise the result will be a summation of the value over the nodes instead of surface area integral.
And in the :code:`monitorOutput` section, we have:
.. literalinclude:: Files/pressureForceMonitorOutput.json
:linenos:
which means that we want :code:`PressureForce` integral computed on patch :code:`wing1` and patch :code:`wing2` as a whole.