7.0
general documentation
Scalar and head loss balance by zone

Scalar balance by zone

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 $ \Omega $ of boundary $ \partial \Omega $ is equal to:

\[ \begin{array}{r c l} Balance^n &=& \displaystyle \sum_{\Omega_i \in \Omega} \norm{\vol{\celli}} \rho_\celli \left(\varia_\celli^{n-1} -\varia_\celli^n \right) \\ &+& \displaystyle \sum_{\Omega_i \in \Omega} \sum_{\face \in \Face{\celli}} \Delta t_\celli \varia_\celli^n \left(\rho \vect{u}\right)_\face^n \cdot \vect{S}_{\iface} \\ &-& \displaystyle \sum_{\face \in \partial \Omega} \Delta t_\celli \varia_\face^n \left(\rho \vect{u}\right)_\face^n \cdot \vect{S}_{\iface} \\ &+& \displaystyle \sum_{\face \in \partial \Omega} \Delta t_\celli K_\face \grad_\face \varia^n \cdot \vect{S}_{\iface} \\ &-& \displaystyle \sum_{\fib \in \partial \Omega} \Delta t_\celli \dot{m}_\ib \left(A_\ib^g + B_\ib^g \varia_\celli^n \right) \\ &+& \displaystyle \sum_{\fib \in \partial \Omega} \Delta t_\celli \norm{\vect{S}_\ib} \left(A_\ib^f + B_\ib^f \varia_\celli^n \right) \end{array} \]

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.

Here is the corresponding code:

cs_balance_by_zone("all[]", "temperature");

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[ $ x_{min}$, $ y_{min}$, $ z_{min}$, $ x_{max}$, $ y_{max}$, $ z_{max}$].

Here is the corresponding code:

cs_balance_by_zone("box[-0.5, 1.3, 0.0, 1.0, 1.9, 1.0]",
"scalar1");

Scalar balance through a surface

This example computes the balance relative to a scalar named "scalar1". Here is the corresponding code:

cs_real_t normal[3] = {0., 0., 1.,};
cs_surface_balance("selection_criterion", "scalar1", normal);

Specific terms of a scalar balance

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:

const char criteria[] = "zone_group";
cs_lnum_t n_selected_cells = 0;
cs_lnum_t *selected_cells = NULL;
BFT_MALLOC(selected_cells, domain->mesh->n_cells, cs_lnum_t);
&n_selected_cells,
selected_cells);
n_selected_cells,
selected_cells,
balance);
BFT_FREE(selected_cells);
bft_printf("inlet mass flow (scalar 1): %g\n"
"outlet mass flow (scalar 1): %g\n",
balance[mass_in_idx],
balance[mass_out_idx]);

Head loss balance by zone

This example computes the head balance for a volume zone. Here is the corresponding code:

cs_pressure_drop_by_zone("zone_group");

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:

{
const char criteria[] = "zone_group";
cs_lnum_t n_selected_cells = 0;
cs_lnum_t *selected_cells = NULL;
BFT_MALLOC(selected_cells, domain->mesh->n_cells, cs_lnum_t);
&n_selected_cells,
selected_cells);
selected_cells,
balance);
BFT_FREE(selected_cells);
bft_printf("inlet mass flow (rho.u): %g\n"
"outlet mass flow (rho.u): %g\n",
balance[rhou_in_idx],
balance[rhou_out_idx]);
}