My Project
programmer's 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:

"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]);
}
cs_balance_by_zone_compute
void cs_balance_by_zone_compute(const char *scalar_name, cs_lnum_t n_cells_sel, const cs_lnum_t cell_sel_ids[], cs_real_t balance[CS_BALANCE_N_TERMS])
Compute the different terms of the balance of a given scalar, on a volume zone defined by selected ce...
Definition: cs_balance_by_zone.c:710
cs_balance_by_zone
void cs_balance_by_zone(const char *selection_crit, const char *scalar_name)
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
cs_selector_get_cell_list
void cs_selector_get_cell_list(const char *criteria, cs_lnum_t *n_cells, cs_lnum_t cell_list[])
Fill a list of cells verifying a given selection criteria.
Definition: cs_selector.c:369
cs_balance_term_t
cs_balance_term_t
Definition: cs_balance_by_zone.h:49
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:302
cs_surface_balance
void cs_surface_balance(const char *selection_crit, const char *scalar_name, const cs_real_t normal[3])
Compute the surface balance of a given scalar.
Definition: cs_balance_by_zone.c:2209
cs_balance_p_term_t
cs_balance_p_term_t
Definition: cs_balance_by_zone.h:83
CS_BALANCE_MASS_IN
Definition: cs_balance_by_zone.h:56
BFT_MALLOC
#define BFT_MALLOC(_ptr, _ni, _type)
Allocate memory for _ni elements of type _type.
Definition: bft_mem.h:62
BFT_FREE
#define BFT_FREE(_ptr)
Free allocated memory.
Definition: bft_mem.h:101
cs_pressure_drop_by_zone
void cs_pressure_drop_by_zone(const char *selection_crit)
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
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_pressure_drop_by_zone_compute
void cs_pressure_drop_by_zone_compute(cs_lnum_t n_cells_sel, const cs_lnum_t cell_sel_ids[], cs_real_t balance[CS_BALANCE_P_N_TERMS])
Computes one term of the head loss balance (pressure drop) on a on a volume zone defined by selected ...
Definition: cs_balance_by_zone.c:1572
CS_BALANCE_MASS_OUT
Definition: cs_balance_by_zone.h:57
CS_BALANCE_P_RHOU_IN
Definition: cs_balance_by_zone.h:93
CS_BALANCE_P_RHOU_OUT
Definition: cs_balance_by_zone.h:94
bft_printf
int bft_printf(const char *const format,...)
Replacement for printf() with modifiable behavior.
Definition: bft_printf.c:140
CS_BALANCE_P_N_TERMS
Definition: cs_balance_by_zone.h:98