9.0
general documentation
Loading...
Searching...
No Matches
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
63#define CS_MAX_BC_PM_ZONE_NUM 2000
64
66#define CS_MAX_BC_TYPE 200
67
68/*============================================================================
69 * Local type definitions
70 *============================================================================*/
71
72/*=============================================================================
73 * Global variables
74 *============================================================================*/
75
77
78extern const int *cs_glob_bc_type;
79
85
86/*----------------------------------------------------------------------------*/
87
99
100typedef struct {
101
103 int *izfppp;
104
106 int *iautom;
107
109
111
112/*============================================================================
113 * Public function prototypes
114 *============================================================================*/
115
116/*----------------------------------------------------------------------------
117 * Define automatic turbulence values for open boundaries.
118 *----------------------------------------------------------------------------*/
119
120void
122
123/*----------------------------------------------------------------------------
124 * Handling of boundary condition definition errors and associated output.
125 *
126 * This function checks for errors, and simply returns if no error is
127 * encountered. In case of error, it outputs helpful information so as to
128 * make it easier to locate the matching faces.
129 *
130 * For each boundary face, bc_type defines the boundary condition type.
131 * As a convention here, zero values correspond to undefined types,
132 * positive values to defined types (with no error), and negative values
133 * to defined types with inconsistent or incompatible values, the
134 * absolute value indicating the original boundary condition type.
135 *
136 * An optional label may be used if the error is related to another
137 * attribute than the boundary type, for appropriate error reporting.
138 *
139 * parameters:
140 * bc_flag <-- array of BC type ids
141 * type_name <-- name of attribute in error, or NULL
142 *----------------------------------------------------------------------------*/
143
144void
145cs_boundary_conditions_error(const int *bc_type,
146 const char *type_name);
147
148/*----------------------------------------------------------------------------
149 * Locate shifted boundary face coordinates on possibly filtered
150 * cells or boundary faces for later interpolation.
151 *
152 * parameters:
153 * location_type <-- matching values location (CS_MESH_LOCATION_CELLS
154 * or CS_MESH_LOCATION_BOUNDARY_FACES)
155 * n_location_elts <-- number of selected location elements
156 * n_faces <-- number of selected boundary faces
157 * location_elts <-- list of selected location elements (0 to n-1),
158 * or NULL if no indirection is needed
159 * faces <-- list of selected boundary faces (0 to n-1),
160 * or NULL if no indirection is needed
161 * coord_shift <-- array of coordinates shift relative to selected
162 * boundary faces
163 * coord_stride <-- access stride in coord_shift: 0 for uniform
164 * shift, 1 for "per face" shift.
165 * tolerance <-- relative tolerance for point location.
166 *
167 * returns:
168 * associated locator structure
169 *----------------------------------------------------------------------------*/
170
171ple_locator_t *
173 cs_lnum_t n_location_elts,
174 cs_lnum_t n_faces,
175 const cs_lnum_t *location_elts,
176 const cs_lnum_t *faces,
177 cs_real_3_t *coord_shift,
178 int coord_stride,
179 double tolerance);
180
181/*----------------------------------------------------------------------------
182 * Set mapped boundary conditions for a given field and mapping locator.
183 *
184 * parameters:
185 * field <-- field whose boundary conditions are set
186 * locator <-- associated mapping locator, as returned
187 * by cs_boundary_conditions_map().
188 * location_type <-- matching values location (CS_MESH_LOCATION_CELLS or
189 * CS_MESH_LOCATION_BOUNDARY_FACES)
190 * normalize <-- normalization option:
191 * 0: values are simply mapped
192 * 1: values are mapped, then multiplied
193 * by a constant factor so that their
194 * surface integral on selected faces
195 * is preserved (relative to the
196 * input values)
197 * 2: as 1, but with a boundary-defined
198 * weight, defined by balance_w
199 * 3: as 1, but with a cell-defined
200 * weight, defined by balance_w
201 * interpolate <-- interpolation option:
202 * 0: values are simply based on matching
203 * cell or face center values
204 * 1: values are based on matching cell
205 * or face center values, corrected
206 * by gradient interpolation
207 * n_faces <-- number of selected boundary faces
208 * faces <-- list of selected boundary faces (0 to n-1),
209 * or NULL if no indirection is needed
210 * balance_w <-- optional balance weight, or NULL
211 *----------------------------------------------------------------------------*/
212
213void
215 ple_locator_t *locator,
216 cs_mesh_location_type_t location_type,
217 int normalize,
218 int interpolate,
219 cs_lnum_t n_faces,
220 const cs_lnum_t *faces,
221 cs_real_t *balance_w);
222
223/*----------------------------------------------------------------------------*/
247/*----------------------------------------------------------------------------*/
248
249int
250cs_boundary_conditions_add_map(int bc_location_id,
251 int source_location_id,
252 cs_real_t coord_shift[3],
253 double tolerance);
254
255/*----------------------------------------------------------------------------*/
259/*----------------------------------------------------------------------------*/
260
261void
263
264/*----------------------------------------------------------------------------
265 * Create the boundary conditions face type and face zone arrays
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:2243
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:2719
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:2826
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:3183
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:3019
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:2887
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:2980
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:3113
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:1992
void cs_boundary_conditions_complete(int bc_type[])
Automatic adjustments for boundary condition codes.
Definition cs_boundary_conditions.cpp:2580
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:1840
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:2769
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:2187
int * cs_boundary_conditions_get_bc_type(void)
Return pointer to boundary conditions BC type array.
Definition cs_boundary_conditions.cpp:2387
void cs_boundary_conditions_create_legacy_zone_data(void)
Create the legacy boundary conditions zone data arrays.
Definition cs_boundary_conditions.cpp:2220
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:2934
void cs_boundary_conditions_free(void)
Free the boundary conditions face type and face zone arrays.
Definition cs_boundary_conditions.cpp:2295
void cs_boundary_conditions_compute(int bc_type[])
Update per variable boundary condition codes.
Definition cs_boundary_conditions.cpp:2401
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:2691
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:1786
int cs_boundary_conditions_get_legacy_zone_num(const cs_zone_t *z)
Definition cs_boundary_conditions.cpp:2744
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:3348
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:2794
void cs_boundary_conditions_reset(void)
Prepare (reset) condition coefficients for all variable fields.
Definition cs_boundary_conditions.cpp:2337
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:3326
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:3267
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:2848
#define BEGIN_C_DECLS
Definition cs_defs.h:542
double cs_real_t
Floating-point value.
Definition cs_defs.h:342
#define END_C_DECLS
Definition cs_defs.h:543
int cs_lnum_t
local mesh entity id
Definition cs_defs.h:335
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition cs_defs.h:359
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:100
int * iautom
Definition cs_boundary_conditions.h:106
int * izfppp
Definition cs_boundary_conditions.h:103
Field descriptor.
Definition cs_field.h:158
Definition cs_time_control.h:96
Definition cs_zone.h:55