.. _non_dim_coeff_userGuide:

.. currentmodule:: flow360

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

Besides the :ref:`non-dimensional output fields <non_dim_output_userGuide>`, there are also many **coefficients** commonly used in the computational fluid dynamics community,
e.g. lift coefficient (:math:`C_L`), drag coefficient (:math:`C_D`), etc. 
Flow360 also exports the above coefficients as :ref:`tabulated data <tabulated_data_userGuide_workflowsInterfaces>`. 

.. attention::

   The reference velocity for the force and moment coefficients is :math:`U_\text{ref}`, which is the reference velocity set in the operating condition and can be accessed through :code:`case.params.reference_velocity`. 
   
   **It is important to note that** :math:`U_\text{ref}` **used here is different from the** :ref:`reference velocity scaling <reference_velocity_scaling>` :math:`U_\text{scale}` **used for nondimensionalizing other variables** (such as velocity fields, heat flux, angular speeds).
   
   **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 :ref:`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 :ref:`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 :ref:`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

   density = case.params.operating_condition.thermal_state.density
   A_ref = case.params.reference_geometry.area
   U_ref = case.params.reference_velocity
   moment_length = case.params.reference_geometry.moment_length

   # 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 * moment_length[1]


.. seealso::

   - :ref:`python_api_calculate_dimensional_forces` — A comprehensive Python snippet for converting force and moment coefficients to dimensional values.

