9.1
general documentation
cs_boundary_conditions.h
Go to the documentation of this file.
1#ifndef __CS_BOUNDARY_CONDITIONS_H__
2#define __CS_BOUNDARY_CONDITIONS_H__
3
4/*============================================================================
5 * Boundary condition handling.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*----------------------------------------------------------------------------
31 * Standard C library headers
32 *----------------------------------------------------------------------------*/
33
34/*----------------------------------------------------------------------------
35 * Local headers
36 *----------------------------------------------------------------------------*/
37
38#include <ple_locator.h>
39
40#include "base/cs_base.h"
41#include "base/cs_field.h"
42#include "base/cs_function.h"
43#include "base/cs_math.h"
46#include "base/cs_zone.h"
47
48/*----------------------------------------------------------------------------*/
49
51
52/*============================================================================
53 * Macro definitions
54 *============================================================================*/
55
57#define CS_MAX_BC_TYPE 200
58
59/*============================================================================
60 * Local type definitions
61 *============================================================================*/
62
63/*=============================================================================
64 * Global variables
65 *============================================================================*/
66
69extern const int *cs_glob_bc_type;
70
77/*----------------------------------------------------------------------------*/
78
91typedef struct {
92
94 int *izfppp;
95
97 int *iautom;
98
100
102
103/*============================================================================
104 * Public function prototypes
105 *============================================================================*/
106
107/*----------------------------------------------------------------------------
108 * Define automatic turbulence values for open boundaries.
109 *----------------------------------------------------------------------------*/
110
111void
113
114/*----------------------------------------------------------------------------
115 * Handling of boundary condition definition errors and associated output.
116 *
117 * This function checks for errors, and simply returns if no error is
118 * encountered. In case of error, it outputs helpful information so as to
119 * make it easier to locate the matching faces.
120 *
121 * For each boundary face, bc_type defines the boundary condition type.
122 * As a convention here, zero values correspond to undefined types,
123 * positive values to defined types (with no error), and negative values
124 * to defined types with inconsistent or incompatible values, the
125 * absolute value indicating the original boundary condition type.
126 *
127 * An optional label may be used if the error is related to another
128 * attribute than the boundary type, for appropriate error reporting.
129 *
130 * parameters:
131 * bc_flag <-- array of BC type ids
132 * type_name <-- name of attribute in error, or NULL
133 *----------------------------------------------------------------------------*/
134
135void
136cs_boundary_conditions_error(const int *bc_type,
137 const char *type_name);
138
139/*----------------------------------------------------------------------------
140 * Locate shifted boundary face coordinates on possibly filtered
141 * cells or boundary faces for later interpolation.
142 *
143 * parameters:
144 * location_type <-- matching values location (CS_MESH_LOCATION_CELLS
145 * or CS_MESH_LOCATION_BOUNDARY_FACES)
146 * n_location_elts <-- number of selected location elements
147 * n_faces <-- number of selected boundary faces
148 * location_elts <-- list of selected location elements (0 to n-1),
149 * or NULL if no indirection is needed
150 * faces <-- list of selected boundary faces (0 to n-1),
151 * or NULL if no indirection is needed
152 * coord_shift <-- array of coordinates shift relative to selected
153 * boundary faces
154 * coord_stride <-- access stride in coord_shift: 0 for uniform
155 * shift, 1 for "per face" shift.
156 * tolerance <-- relative tolerance for point location.
157 *
158 * returns:
159 * associated locator structure
160 *----------------------------------------------------------------------------*/
161
162ple_locator_t *
164 cs_lnum_t n_location_elts,
165 cs_lnum_t n_faces,
166 const cs_lnum_t *location_elts,
167 const cs_lnum_t *faces,
168 cs_real_3_t *coord_shift,
169 int coord_stride,
170 double tolerance);
171
172/*----------------------------------------------------------------------------
173 * Set mapped boundary conditions for a given field and mapping locator.
174 *
175 * parameters:
176 * field <-- field whose boundary conditions are set
177 * locator <-- associated mapping locator, as returned
178 * by cs_boundary_conditions_map().
179 * location_type <-- matching values location (CS_MESH_LOCATION_CELLS or
180 * CS_MESH_LOCATION_BOUNDARY_FACES)
181 * normalize <-- normalization option:
182 * 0: values are simply mapped
183 * 1: values are mapped, then multiplied
184 * by a constant factor so that their
185 * surface integral on selected faces
186 * is preserved (relative to the
187 * input values)
188 * 2: as 1, but with a boundary-defined
189 * weight, defined by balance_w
190 * 3: as 1, but with a cell-defined
191 * weight, defined by balance_w
192 * interpolate <-- interpolation option:
193 * 0: values are simply based on matching
194 * cell or face center values
195 * 1: values are based on matching cell
196 * or face center values, corrected
197 * by gradient interpolation
198 * n_faces <-- number of selected boundary faces
199 * faces <-- list of selected boundary faces (0 to n-1),
200 * or NULL if no indirection is needed
201 * balance_w <-- optional balance weight, or NULL
202 *----------------------------------------------------------------------------*/
203
204void
206 ple_locator_t *locator,
207 cs_mesh_location_type_t location_type,
208 int normalize,
209 int interpolate,
210 cs_lnum_t n_faces,
211 const cs_lnum_t *faces,
212 cs_real_t *balance_w);
213
214/*----------------------------------------------------------------------------*/
238/*----------------------------------------------------------------------------*/
239
240int
241cs_boundary_conditions_add_map(int bc_location_id,
242 int source_location_id,
243 cs_real_t coord_shift[3],
244 double tolerance);
245
246/*----------------------------------------------------------------------------*/
250/*----------------------------------------------------------------------------*/
251
252void
254
255/*----------------------------------------------------------------------------
256 * Create the boundary conditions face type and face zone arrays
257 *----------------------------------------------------------------------------*/
258
259void
261
262/*----------------------------------------------------------------------------*/
263/*
264 * \brief Update the legacy boundary conditions face type and face zone arrays.
265 */
266/*----------------------------------------------------------------------------*/
267
268void
270
271/*----------------------------------------------------------------------------
272 * Free the boundary conditions face type and face zone arrays.
273 *
274 * This also frees boundary condition mappings which may have been defined.
275 *----------------------------------------------------------------------------*/
276
277void
279
280/*----------------------------------------------------------------------------*/
284/*----------------------------------------------------------------------------*/
285
286void
288
289/*----------------------------------------------------------------------------*/
290/*
291 * \brief Return pointer to boundary conditions BC type array.
292 */
293/*----------------------------------------------------------------------------*/
294
295int *
297
298/*----------------------------------------------------------------------------*/
304/*----------------------------------------------------------------------------*/
305
306void
307cs_boundary_conditions_compute(int bc_type[]);
308
309/*----------------------------------------------------------------------------*/
319/*----------------------------------------------------------------------------*/
320
321void
323
324/*----------------------------------------------------------------------------*/
325/*
326 * \brief Return pointer to model inlet structure associated with a given
327 * open (inlet/outlet) boundary.
328 *
329 * The returned pointer is of type void * as it should be cast to the
330 * appropriate (model-dependent) type.
331
332 * If no matching parent open boundary has been created yet, it is created.
333 *
334 * \param[in] zone pointer to associated zone
335 *
336 * \return: pointer to structure associated with zone
337 */
338/*----------------------------------------------------------------------------*/
339
340void *
342
343/*----------------------------------------------------------------------------*/
358/*----------------------------------------------------------------------------*/
359
360void *
362
363/*----------------------------------------------------------------------------*/
364/*
365 * \brief Return legacy zone number related to a given zone, if available.
366 *
367 * \param[in] z pointer to associated zone
368 *
369 * \return number associated with legacy zone, or 0 if unavailable.
370 */
371/*----------------------------------------------------------------------------*/
372
373int
375
376/*----------------------------------------------------------------------------*/
386/*----------------------------------------------------------------------------*/
387
388cs_real_t *
390
391/*----------------------------------------------------------------------------*/
392/*
393 * \brief Assign pointer to model inlet structure associated with a given
394 * open (inlet/outlet) boundary.
395 *
396 * The returned pointer is of type void * as it should be cast to the
397 * appropriate (model-dependent) type.
398
399 * If no matching parent open boundary has been created yet, it is created.
400 *
401 * \param[in] zone pointer to associated zone
402 * \param[in] s_ptr pointer to associated structure
403 * \param[in] s_del destructor for associated structure, or NULL
404 */
405/*----------------------------------------------------------------------------*/
406
407void
409 void *s_ptr,
410 void *s_del);
411
412/*----------------------------------------------------------------------------*/
413/*
414 * \brief Acess the time control structure of an inlet.
415 *
416 * This allows modifying that structure, for example updating the inlet
417 * velocity values only in a certain time range, and avoiding
418 * uneeded recomputations outside that range.
419 *
420 * \param[in] zone pointer to associated zone
421 */
422/*----------------------------------------------------------------------------*/
423
426
427/*----------------------------------------------------------------------------*/
428/*
429 * \brief Assign a constant velocity to an open (inlet/outlet) boundary.
430 *
431 * This function may also be used to define the flow direction if called
432 * before one of the \c cs_boundary_conditions_open_set_mass_flow_rate
433 * or \c cs_boundary_conditions_open_set_volume_flow_rate functions.
434 *
435 * \param[in] z pointer to associated zone
436 * \param[in] u associated velocity value
437 */
438/*----------------------------------------------------------------------------*/
439
440void
442 const cs_real_t u[3]);
443
444/*----------------------------------------------------------------------------*/
445/*
446 * \brief Assign a constant velocity normal to an inlet.
447 *
448 * \param[in] z pointer to associated zone
449 * \param[in] u_norm associated constant normal
450 */
451/*----------------------------------------------------------------------------*/
452
453void
455 cs_real_t u_norm);
456
457/*----------------------------------------------------------------------------*/
472/*----------------------------------------------------------------------------*/
473
474void
477 void *input);
478
479/*----------------------------------------------------------------------------*/
480/*
481 * \brief Return the volume flow rate to an inlet or outlet.
482 *
483 * The flow direction may be specified by also calling
484 * \ref cs_boundary_conditions_open_set_velocity_by_value,
485 * or \ref cs_boundary_conditions_open_set_velocity_by_func.
486 * In that case, the velocity vector is rescaled so as to obtain the required
487 * volume flow rate.
488 *
489 * \param[in] z pointer to associated zone
490 *
491 * \return volume flow rate associated with open boundary
492 */
493/*----------------------------------------------------------------------------*/
494
497
498/*----------------------------------------------------------------------------*/
499/*
500 * \brief Assign a constant mass flow rate to an inlet or outlet.
501 *
502 * By default, the flow direction is considered normal to the boundary.
503 * The flow direction may be specified by calling
504 * \ref cs_boundary_conditions_open_set_velocity_by_value,
505 * or \ref cs_boundary_conditions_open_set_velocity_by_func
506 * for the appropriate zone before calling this function.
507 * In that case, the velocity vector is rescaled so as to obtain the required
508 * mass flow rate.
509 *
510 * \param[in] z pointer to associated zone
511 * \param[in] q associated constant mass flow rate
512 */
513/*----------------------------------------------------------------------------*/
514
515void
517 cs_real_t q);
518
519/*----------------------------------------------------------------------------*/
520/*
521 * \brief Assign a mass flow rate to an inlet or outlet based on
522 * provided function.
523 *
524 * The flow direction may be specified by also calling
525 * \ref cs_boundary_conditions_open_set_velocity_by_value,
526 * \ref cs_boundary_conditions_open_set_velocity_by_normal_value,
527 * or \ref cs_boundary_conditions_open_set_velocity_by_func.
528 * In that case, the velocity vector is rescaled so as to obtain the required
529 * mass flow rate.
530 *
531 * Since the flow rate is a global value, the provided function should
532 * be associated with the CS_MESH_LOCATION_NONE location.
533 *
534 * Note also that during updates, this function will be called before
535 * the velocity vector update, so in complex cases where flow rate computation
536 * would require feedback from the velocity at this boundary, the user
537 * must be aware that values from the previous time step or update will
538 * be used, handle this in another manner.
539 *
540 * Reminder: if the input pointer is non-null, it must point to valid data
541 * when the selection function is called, so either:
542 * - that value or structure should not be temporary (i.e. local);
543 * - when a single integer identifier is needed, the input pointer can be
544 * set to that value instead of an actual address;
545 *
546 * \param[in] z pointer to associated zone
547 * \param[in] func associated scalar (mass flow rate) evaluation function
548 * \param[in] input optional function evaluation input, or NULL
549 */
550/*----------------------------------------------------------------------------*/
551
552void
554 (const cs_zone_t *z,
556 void *input);
557
558/*----------------------------------------------------------------------------*/
559/*
560 * \brief Assign a constant volume flow rate to an inlet or outlet.
561 *
562 * The flow direction may be specified by also calling
563 * \ref cs_boundary_conditions_open_set_velocity_by_value,
564 * or \ref cs_boundary_conditions_open_set_velocity_by_func.
565 * In that case, the velocity vector is rescaled so as to obtain the required
566 * volume flow rate.
567 *
568 * \param[in] z pointer to associated zone
569 * \param[in] q associated constant volume flow rate
570 */
571/*----------------------------------------------------------------------------*/
572
573void
575 cs_real_t q);
576
577/*----------------------------------------------------------------------------*/
578/*
579 * \brief Assign a volume flow rate to an inlet or outlet based on
580 * provided function.
581 *
582 * The flow direction may be specified by also calling
583 * \ref cs_boundary_conditions_open_set_velocity_by_value,
584 * \ref cs_boundary_conditions_open_set_velocity_by_normal_value,
585 * or \ref cs_boundary_conditions_open_set_velocity_by_func.
586 * In that case, the velocity vector is rescaled so as to obtain the required
587 * volume flow rate.
588 *
589 * Since the flow rate is a global value, the provided function should
590 * be associated with the CS_MESH_LOCATION_NONE location.
591 *
592 * Note also that during updates, this function will be called before
593 * the velocity vector update, so in complex cases where flow rate computation
594 * would require feedback from the velocity at this boundary, the user
595 * must be aware that values from the previous time step or update will
596 * be used, handle this in another manner.
597 *
598 * Reminder: if the input pointer is non-null, it must point to valid data
599 * when the selection function is called, so either:
600 * - that value or structure should not be temporary (i.e. local);
601 * - when a single integer identifier is needed, the input pointer can be
602 * set to that value instead of an actual address;
603 *
604 * \param[in] z pointer to associated zone
605 * \param[in] func associated scalar (volume flow rate) evaluation function
606 * \param[in] input optional function evaluation input, or NULL
607 */
608/*----------------------------------------------------------------------------*/
609
610void
612 (const cs_zone_t *z,
614 void *input);
615
616/*----------------------------------------------------------------------------*/
617/*
618 * \brief Base the inlet turbulence values on a a circular duct with smooth
619 * wall (see ref cs_turbulence_bc_ke_hyd_diam).
620 *
621 * \param[in] zone pointer to associated zone
622 * \param[in] hd associated hydraulic diameter
623 */
624/*----------------------------------------------------------------------------*/
625
626void
628 cs_real_t hd);
629
630/*----------------------------------------------------------------------------*/
631/*
632 * \brief Base the inlet turbulence values on a a circular duct with smooth
633 * wall (see ref cs_turbulence_bc_ke_hyd_diam).
634 *
635 * \param[in] zone pointer to associated zone
636 * \param[in] ti associated turbulence intensity
637 */
638/*----------------------------------------------------------------------------*/
639
640void
642 cs_real_t ti);
643
644/*----------------------------------------------------------------------------*/
645
647
648#endif /* __CS_BOUNDARY_CONDITIONS_H__ */
void cs_boundary_conditions_create(void)
Create the legacy boundary conditions face type and face zone arrays.
Definition: cs_boundary_conditions.cpp:2186
void * cs_boundary_conditions_get_model_inlet_try(const cs_zone_t *zone)
Return pointer to model inlet structure associated with a given boundary zone, if associated,...
Definition: cs_boundary_conditions.cpp:2722
cs_time_control_t * cs_boundary_conditions_open_get_time_control(const cs_zone_t *zone)
Acess the time control structure of an open (inlet/outlet) boundary.
Definition: cs_boundary_conditions.cpp:2829
void cs_boundary_conditions_open_turb(void)
void cs_boundary_conditions_open_set_volume_flow_rate_by_value(const cs_zone_t *z, cs_real_t q)
Assign a constant volume flow rate to an inlet or outlet.
Definition: cs_boundary_conditions.cpp:3186
void cs_boundary_conditions_open_set_mass_flow_rate_by_value(const cs_zone_t *z, cs_real_t q)
Assign a constant mass flow rate to an inlet or outlet.
Definition: cs_boundary_conditions.cpp:3022
void cs_boundary_conditions_open_set_velocity_by_normal_value(const cs_zone_t *z, cs_real_t u_norm)
Assign a constant velocity normal to an inlet.
Definition: cs_boundary_conditions.cpp:2890
cs_boundary_condition_pm_info_t * cs_glob_bc_pm_info
const int * cs_glob_bc_type
cs_real_t cs_boundary_conditions_open_get_mass_flow_rate(const cs_zone_t *z)
Return the volume flow rate to an inlet or outlet.
Definition: cs_boundary_conditions.cpp:2983
void cs_boundary_conditions_open_set_mass_flow_rate_by_func(const cs_zone_t *z, cs_eval_at_location_t *func, void *input)
Assign a mass flow rate to an inlet or outlet based on provided function.
Definition: cs_boundary_conditions.cpp:3116
void cs_boundary_conditions_ibm_create(cs_lnum_t n_ib_cells)
Update the legacy boundary conditions face type and face zone arrays.
Definition: cs_boundary_conditions.cpp:2236
void cs_boundary_conditions_mapped_set(const cs_field_t *f, ple_locator_t *locator, cs_mesh_location_type_t location_type, int normalize, int interpolate, cs_lnum_t n_faces, const cs_lnum_t *faces, cs_real_t *balance_w)
Set mapped boundary conditions for a given field and mapping locator.
Definition: cs_boundary_conditions.cpp:1935
void cs_boundary_conditions_complete(int bc_type[])
Automatic adjustments for boundary condition codes.
Definition: cs_boundary_conditions.cpp:2582
ple_locator_t * cs_boundary_conditions_map(cs_mesh_location_type_t location_type, cs_lnum_t n_location_elts, cs_lnum_t n_faces, const cs_lnum_t *location_elts, const cs_lnum_t *faces, cs_real_3_t *coord_shift, int coord_stride, double tolerance)
Locate shifted boundary face coordinates on possibly filtered cells or boundary faces for later inter...
Definition: cs_boundary_conditions.cpp:1783
cs_real_t * cs_boundary_conditions_get_b_head_loss(bool alloc_if_null)
Return pointer to boundary head losses array.
Definition: cs_boundary_conditions.cpp:2772
int cs_boundary_conditions_add_map(int bc_location_id, int source_location_id, cs_real_t coord_shift[3], double tolerance)
Add location of locate shifted boundary face coordinates on cells or boundary faces for automatic int...
Definition: cs_boundary_conditions.cpp:2130
int * cs_boundary_conditions_get_bc_type(void)
Return pointer to boundary conditions BC type array.
Definition: cs_boundary_conditions.cpp:2388
void cs_boundary_conditions_create_legacy_zone_data(void)
Create the legacy boundary conditions zone data arrays.
Definition: cs_boundary_conditions.cpp:2163
void cs_boundary_conditions_open_set_velocity_by_func(const cs_zone_t *z, cs_eval_at_location_t *func, void *input)
Assign a normal velocity to an inlet using a provided function.
Definition: cs_boundary_conditions.cpp:2937
void cs_boundary_conditions_free(void)
Free the boundary conditions face type and face zone arrays.
Definition: cs_boundary_conditions.cpp:2281
void cs_boundary_conditions_compute(int bc_type[])
Update per variable boundary condition codes.
Definition: cs_boundary_conditions.cpp:2402
void * cs_boundary_conditions_get_model_inlet(const cs_zone_t *zone)
Return pointer to model inlet structure associated with a given open (inlet/outlet) boundary.
Definition: cs_boundary_conditions.cpp:2694
void cs_boundary_conditions_error(const int *bc_type, const char *type_name)
Handling of boundary condition definition errors and associated output.
Definition: cs_boundary_conditions.cpp:1729
int cs_boundary_conditions_get_legacy_zone_num(const cs_zone_t *z)
Definition: cs_boundary_conditions.cpp:2747
void cs_boundary_conditions_inlet_set_turbulence_intensity(const cs_zone_t *zone, cs_real_t ti)
Base the inlet turbulence values on a a circular duct with smooth wall (see ref cs_turbulence_bc_ke_h...
Definition: cs_boundary_conditions.cpp:3351
void cs_boundary_conditions_assign_model_inlet(const cs_zone_t *zone, void *s_ptr, void *s_del)
Assign pointer to model inlet structure associated with a given open (inlet/outlet) boundary.
Definition: cs_boundary_conditions.cpp:2797
void cs_boundary_conditions_reset(void)
Prepare (reset) condition coefficients for all variable fields.
Definition: cs_boundary_conditions.cpp:2323
void cs_boundary_conditions_inlet_set_turbulence_hyd_diam(const cs_zone_t *zone, cs_real_t hd)
Base the inlet turbulence values on a a circular duct with smooth wall (see ref cs_turbulence_bc_ke_h...
Definition: cs_boundary_conditions.cpp:3329
void cs_boundary_conditions_open_set_volume_flow_rate_by_func(const cs_zone_t *z, cs_eval_at_location_t *func, void *input)
Assign a volume flow rate to an inlet or outlet based on provided function.
Definition: cs_boundary_conditions.cpp:3270
void cs_boundary_conditions_open_set_velocity_by_value(const cs_zone_t *z, const cs_real_t u[3])
Assign a constant velocity to an open (inlet/outlet) boundary.
Definition: cs_boundary_conditions.cpp:2851
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:374
#define END_C_DECLS
Definition: cs_defs.h:555
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
void() cs_eval_at_location_t(int location_id, cs_lnum_t n_elts, const cs_lnum_t *elt_ids, void *input, void *vals)
Function pointer for evaluation of local function values.
Definition: cs_function.h:112
cs_mesh_location_type_t
Definition: cs_mesh_location.h:60
Definition: cs_boundary_conditions.h:91
int * iautom
Definition: cs_boundary_conditions.h:97
int * izfppp
Definition: cs_boundary_conditions.h:94
Field descriptor.
Definition: cs_field.h:156
Definition: cs_time_control.h:96
Definition: cs_zone.h:55