This is an example of cs_user_extra_operations which performs scalar balances on specified zones.
body
The algorithm implemented in the subroutine balance_by_zone adds up contributions of fluxes on the boundary of the sub-domain defined by the user. The different contributions are classified according to their nature (inlet, outlet, wall, symmetry...) if they are boundary faces of the whole domain or according to the sign of the mass flux if they are boundary faces of the sub-domain but internal faces of the whole domain.
To ensure calculations have physical meaning, it is best to use a spatially uniform time step (idtvar = 0 or 1).
The balance at time step n over a subdomain of boundary is equal to:
The first term is negative if the amount of scalar in the volume has increased (it is 0 in a steady regime).
The terms of convection and diffusion (at internal or boundary faces) are positive if the amount of scalar in the volume has increased.
In a steady regime, a positive balance thus indicates a scalar gain.
Example 1
This example computes energy balance relative to temperature. We assume that we want to compute balances (convective and diffusive) at the boundaries of the calculation domain.
The scalar considered is the temperature, nevertheless it is multiplied by the specific heat at each cell so that the computed balance is on energy, hence in Joules.
Compute and log the different terms of the balance of a given scalar, on a volumic zone defined by se...
Definition cs_balance_by_zone.c:1494
Example 2
This example computes the balance relative to a scalar named "scalar1". We assume that we want to compute balances (convective and diffusive) on a box defined by two diagonally opposite points (the extrema in terms of coordinates).
The box criterion can be used as follows: box[ , , , , , ].
Instead of simply logging the various balance terms, it is possible to access them using the lower level functions, and the cs_balance_term_t components of the computed balance.
The following exemple shows how to access for example the mass flow components of the scalar balance:
Computes one term of the head loss balance (pressure drop) on a volumic zone defined by the criterion...
Definition cs_balance_by_zone.c:2119
Specific terms of a head balance
Instead of simply logging the various balance terms, it is possible to access them using the lower level functions, and the cs_balance_p_term_t components of the computed balance.
The following exemple shows how to access for example the mass flow components of the pressure drop computation: