.. _userDefinedPostProcessingOverview:

User Defined Post Processing
============================

Overview
--------

Flow360 allows users to define custom fields that can be applied on volumes, surfaces, slices and isosurfaces alongside the built-in :ref:`solution fields<postProcessingParameters>`.

These can be classified into three families depending on what entity the user wants to postprocess.

User Variables
--------------

:ref:`User Variables <userVariables>` allows users to define their own postprocessing variables using :ref:`expressions <expressions>`. These variables can then be used to define outputs.

User Defined Surface Integrals
------------------------------

The :ref:`User Variables <userVariables>` functionality also allows users to integrate internal solver variables over a given set of mesh patches.
For example, a pressure force calculation on a given subset of the body can be done with the following user variable.

.. code-block:: python

    import flow360 as fl

    with fl.SI_unit_system:
        thermal_state = fl.ThermalState(temperature=288.15, density=1.225)
        pressure_force_field = fl.UserVariable(name="PressureForce", value=(fl.solution.pressure.in_units("Pa") - thermal_state.pressure) * fl.solution.node_unit_normal)

        fl.SimulationParams(
            outputs=[
                fl.SurfaceIntegralOutput(
                    name="SurfaceIntegralPressureForce",
                    output_fields=[pressure_force_field],
                    surfaces=[vm["rotating/rotors"]]
                )
            ]
        )

One could also look at integrated flow quantities across an inlet or an outlet for example.  

User Defined Monitors
---------------------

Using the :ref:`User Variables <userVariables>` functionality, users can create User Defined Monitors that export a history of the evolution of a given variable during the course of the simulation.

Examples include:

- Monitor the convergence of a force or torque on a control surface as the simulation progresses
- Monitor the evolution of a subset of variables as a function of time in a time accurate simulation
