
.. _non_dim_coeff:

.. currentmodule:: flow360

Force and Moment Coefficients
==============================

Besides the :ref:`non-dimensional output fields <non_dim_output>`, there are also many **coefficients** commonly used in the computational fluid dynamics community,
e.g. pressure coefficient (:math:`C_p`), skin friction coefficient (:math:`C_f`), lift coefficient (:math:`C_L`), drag coefficient (:math:`C_D`), etc. 
Flow360 also exports the above coefficients found in :py:class:`VolumeOutput`, :py:class:`SurfaceOutput`, :py:class:`SliceOutput`. 

.. attention::

   It should be noted that the reference velocity :math:`U_\text{ref}` used to calculate the :math:`C_p, C_f, C_D, C_L` can be set via :py:attr:`AerospaceCondition.velocity_magnitude` or :py:attr:`AerospaceCondition.reference_velocity_magnitude` by users. It is not the same as the reference velocity (:math:`C_\infty`) used for the non-dimensional outputs in :numref:`tab_non_dim_output`. 

   **In particular, we want to emphasize that the non-dimensionalization of force and moment for** :ref:`BET Disk <betDiskLoadingNote>` **,** :ref:`Actuator Disk <ADoutput>` **and** :ref:`Porous Media <pmoutput>` **are different from the coefficients shown in this page.**

The force coefficients and moment coefficients exported by Flow360 are listed in :numref:`tab_non_dim_coeff`.
These coefficients can be obtained from :code:`total_forces_v2.csv`, :code:`surface_forces_v2.csv` files on WebUI. They can also be fetched by the :code:`case.results.total_forces` and :code:`case.results.surface_forces` Python API calls.

.. _tab_non_dim_coeff:
.. csv-table:: Force coefficients and moment coefficients exported by Flow360
   :file: Tables/nonDimCoefficients.csv
   :widths: 10,50
   :header-rows: 1
   :delim: @

.. _note_ref_value:
.. note::
 
   In the above table, all reference values can be accessed through Python API as shown in the :ref:`Reference Variable Table <table_ref_value>`.

The typical output options in the WebUI and various csv files are outlined in :numref:`tab_ForcesMoments`. The conventions assume z-axis upwards, y-axis spanwise (+ towards starboard side) and x-axis in the axial direction (+ in the freestream direction) for the global axes, as shown in :numref:`axis_conventions`.

.. _axis_conventions:
.. figure:: Figures/AxisConventions.png
   :align: center
   :scale: 80%

   Axis conventions demonstrated using the CRM geometry


.. _tab_ForcesMoments:
.. csv-table:: Force and Moment output conventions.
   :file: Tables/force_moments.csv
   :widths: 20, 60
   :align: center
   :header-rows: 1
   :delim: @


Example: Lift Force and Pitching Moment
----------------------------------------

.. code-block:: python
   :linenos:

   # The output values are averaged over the last 10% steps
   total_forces = case.results.total_forces.averages

   length_unit = project.length_unit
   density = case.params.operating_condition.thermal_state.density
   A_ref = case.params.reference_geometry.area

   # If reference_velocity_magnitude is provided
   # when defining operating_condition, use
   # U_ref = case.params.operating_condition.reference_velocity_magnitude
   U_ref = case.params.operating_condition.velocity_magnitude

   # Compute Lift Force
   CL = total_forces["CL"]
   Lift = CL * 0.5 * density * U_ref**2 * A_ref

   # Compute Pitching Moment
   CMy = total_forces["CMy"] 
   Pitching_Moment = CMy * 0.5 * density * U_ref**2 * A_ref * length_unit
