8.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-2023 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 "cs_base.h"
41#include "cs_field.h"
42#include "cs_math.h"
43#include "cs_mesh_location.h"
44
45/*----------------------------------------------------------------------------*/
46
48
49/*============================================================================
50 * Macro definitions
51 *============================================================================*/
52
60#define CS_MAX_BC_PM_ZONE_NUM 2000
61
62/*============================================================================
63 * Local type definitions
64 *============================================================================*/
65
66/*=============================================================================
67 * Global variables
68 *============================================================================*/
69
71
72extern const int *cs_glob_bc_type;
73
79
80/*----------------------------------------------------------------------------*/
81
93
130
132
133/*============================================================================
134 * Public function prototypes
135 *============================================================================*/
136
137/*----------------------------------------------------------------------------
138 * Handling of boundary condition definition errors and associated output.
139 *
140 * This function checks for errors, and simply returns if no error is
141 * encountered. In case of error, it outputs helpful information so as to
142 * make it easier to locate the matching faces.
143 *
144 * For each boundary face, bc_type defines the boundary condition type.
145 * As a convention here, zero values correspond to undefined types,
146 * positive values to defined types (with no error), and negative values
147 * to defined types with inconsistent or incompatible values, the
148 * absolute value indicating the original boundary condition type.
149 *
150 * An optional label may be used if the error is related to another
151 * attribute than the boundary type, for appropriate error reporting.
152 *
153 * parameters:
154 * bc_flag <-- array of BC type ids
155 * type_name <-- name of attribute in error, or NULL
156 *----------------------------------------------------------------------------*/
157
158void
159cs_boundary_conditions_error(const int *bc_type,
160 const char *type_name);
161
162/*----------------------------------------------------------------------------
163 * Locate shifted boundary face coordinates on possibly filtered
164 * cells or boundary faces for later interpolation.
165 *
166 * parameters:
167 * location_type <-- matching values location (CS_MESH_LOCATION_CELLS
168 * or CS_MESH_LOCATION_BOUNDARY_FACES)
169 * n_location_elts <-- number of selected location elements
170 * n_faces <-- number of selected boundary faces
171 * location_elts <-- list of selected location elements (0 to n-1),
172 * or NULL if no indirection is needed
173 * faces <-- list of selected boundary faces (0 to n-1),
174 * or NULL if no indirection is needed
175 * coord_shift <-- array of coordinates shift relative to selected
176 * boundary faces
177 * coord_stride <-- access stride in coord_shift: 0 for uniform
178 * shift, 1 for "per face" shift.
179 * tolerance <-- relative tolerance for point location.
180 *
181 * returns:
182 * associated locator structure
183 *----------------------------------------------------------------------------*/
184
185ple_locator_t *
187 cs_lnum_t n_location_elts,
188 cs_lnum_t n_faces,
189 const cs_lnum_t *location_elts,
190 const cs_lnum_t *faces,
191 cs_real_3_t *coord_shift,
192 int coord_stride,
193 double tolerance);
194
195/*----------------------------------------------------------------------------
196 * Set mapped boundary conditions for a given field and mapping locator.
197 *
198 * parameters:
199 * field <-- field whose boundary conditions are set
200 * locator <-- associated mapping locator, as returned
201 * by cs_boundary_conditions_map().
202 * location_type <-- matching values location (CS_MESH_LOCATION_CELLS or
203 * CS_MESH_LOCATION_BOUNDARY_FACES)
204 * normalize <-- normalization option:
205 * 0: values are simply mapped
206 * 1: values are mapped, then multiplied
207 * by a constant factor so that their
208 * surface integral on selected faces
209 * is preserved (relative to the
210 * input values)
211 * 2: as 1, but with a boundary-defined
212 * weight, defined by balance_w
213 * 3: as 1, but with a cell-defined
214 * weight, defined by balance_w
215 * interpolate <-- interpolation option:
216 * 0: values are simply based on matching
217 * cell or face center values
218 * 1: values are based on matching cell
219 * or face center values, corrected
220 * by gradient interpolation
221 * n_faces <-- number of selected boundary faces
222 * faces <-- list of selected boundary faces (0 to n-1),
223 * or NULL if no indirection is needed
224 * balance_w <-- optional balance weight, or NULL
225 *----------------------------------------------------------------------------*/
226
227void
229 ple_locator_t *locator,
230 cs_mesh_location_type_t location_type,
231 int normalize,
232 int interpolate,
233 cs_lnum_t n_faces,
234 const cs_lnum_t *faces,
235 cs_real_t *balance_w);
236
237/*----------------------------------------------------------------------------*/
261/*----------------------------------------------------------------------------*/
262
263int
264cs_boundary_conditions_add_map(int bc_location_id,
265 int source_location_id,
266 cs_real_t coord_shift[3],
267 double tolerance);
268
269/*----------------------------------------------------------------------------
270 * Create the boundary conditions face type and face zone arrays
271 *----------------------------------------------------------------------------*/
272
273void
275
276/*----------------------------------------------------------------------------
277 * Free the boundary conditions face type and face zone arrays.
278 *
279 * This also frees boundary condition mappings which may have been defined.
280 *----------------------------------------------------------------------------*/
281
282void
284
285/*----------------------------------------------------------------------------*/
296/*----------------------------------------------------------------------------*/
297
298inline static void
300 cs_real_t *af,
301 cs_real_t *b,
302 cs_real_t *bf,
303 cs_real_t qimp,
304 cs_real_t hint)
305{
306 /* Gradient BCs */
307 *a = -qimp/hint;
308 *b = 1.;
309
310 /* Flux BCs */
311 *af = qimp;
312 *bf = 0.;
313}
314
315/*----------------------------------------------------------------------------*/
326/*----------------------------------------------------------------------------*/
327
328inline static void
330 cs_real_t af[3],
331 cs_real_t b[3][3],
332 cs_real_t bf[3][3],
333 const cs_real_t qimpv[3],
334 cs_real_t hint)
335{
336 /* Gradient BCs */
337
338 for (size_t i = 0; i < 3; i++) {
339 a[i] = -qimpv[i] / fmax(hint, 1.e-300);
340 }
341
342 b[0][0] = 1., b[0][1] = 0., b[0][2] = 0.;
343 b[1][0] = 0., b[1][1] = 1., b[1][2] = 0.;
344 b[2][0] = 0., b[2][1] = 0., b[2][2] = 1.;
345
346 /* Flux BCs */
347
348 for (size_t i = 0; i < 3; i++) {
349 af[i] = qimpv[i];
350
351 for (size_t j = 0; j < 3; j++)
352 bf[i][j] = 0;
353 }
354}
355
356/*----------------------------------------------------------------------------*/
369/*----------------------------------------------------------------------------*/
370
371inline static void
373 cs_real_t *af,
374 cs_real_t *b,
375 cs_real_t *bf,
376 cs_real_t pimp,
377 cs_real_t hint,
378 cs_real_t hext)
379{
380 if (hext < 0.) {
381
382 /* Gradient BCs */
383 *a = pimp;
384 *b = 0.;
385
386 /* Flux BCs */
387 *af = -hint*pimp;
388 *bf = hint;
389
390 }
391 else {
392
393 /* Gradient BCs */
394 *a = hext*pimp/(hint + hext);
395 *b = hint /(hint + hext);
396
397 /* Flux BCs */
398 cs_real_t heq = hint*hext/(hint + hext);
399 *af = -heq*pimp;
400 *bf = heq;
401
402 }
403}
404
405/*----------------------------------------------------------------------------*/
418/*----------------------------------------------------------------------------*/
419
420inline static void
422 cs_real_3_t af,
423 cs_real_33_t b,
424 cs_real_33_t bf,
425 cs_real_3_t pimpv,
426 cs_real_t hint,
427 cs_real_3_t hextv)
428{
429 for (int isou = 0; isou < 3; isou++) {
430 if (fabs(hextv[isou]) > 0.5*cs_math_infinite_r) {
431
432 /* Gradient BCs */
433 a[isou] = pimpv[isou];
434 for (int jsou = 0; jsou < 3; jsou++)
435 b[isou][jsou] = 0.;
436
437 /* Flux BCs */
438 af[isou] = -hint*pimpv[isou];
439 for (int jsou = 0; jsou < 3; jsou++) {
440 if (jsou == isou)
441 bf[isou][jsou] = hint;
442 else
443 bf[isou][jsou] = 0.;
444 }
445 } else {
446
447 cs_real_t heq = hint*hextv[isou]/(hint + hextv[isou]);
448
449 /* Gradient BCs */
450 a[isou] = hextv[isou]*pimpv[isou]/(hint + hextv[isou]);
451 for (int jsou = 0; jsou < 3; jsou++) {
452 if (jsou == isou)
453 b[isou][jsou] = hint/(hint + hextv[isou]);
454 else
455 b[isou][jsou] = 0.;
456 }
457
458 /* Flux BCs */
459 af[isou] = -heq*pimpv[isou];
460 for (int jsou = 0; jsou < 3; jsou++) {
461 if (jsou == isou)
462 bf[isou][jsou] = heq;
463 else
464 bf[isou][jsou] = 0.;
465 }
466 }
467 }
468}
469
470/*----------------------------------------------------------------------------*/
483/*----------------------------------------------------------------------------*/
484
485void
487 cs_real_t *cofaf,
488 cs_real_t *coefb,
489 cs_real_t *cofbf,
490 cs_real_t pimp,
491 cs_real_t cfl,
492 cs_real_t hint);
493
494/*----------------------------------------------------------------------------*/
508/*----------------------------------------------------------------------------*/
509
510inline static void
512 cs_real_3_t af,
513 cs_real_33_t b,
514 cs_real_33_t bf,
515 cs_real_3_t pimpv,
516 cs_real_6_t hintt,
517 cs_real_3_t hextv)
518{
519 /* Gradient BCs */
520 for (int isou = 0; isou < 3; isou++) {
521 if (fabs(hextv[isou]) > 0.5*cs_math_infinite_r) {
522 a[isou] = pimpv[isou];
523 for (int jsou = 0; jsou < 3; jsou++)
524 b[isou][jsou] = 0.;
525 }
526 else {
527 /* FIXME: at least log error message */
528 cs_exit(1);
529 }
530 }
531
532 /* Flux BCs */
533 cs_math_sym_33_3_product(hintt, pimpv, af);
534 for (int isou = 0; isou < 3; isou++)
535 af[isou] = -af[isou];
536
537 bf[0][0] = hintt[0];
538 bf[1][1] = hintt[1];
539 bf[2][2] = hintt[2];
540 bf[0][1] = hintt[3];
541 bf[1][0] = hintt[3];
542 bf[1][2] = hintt[4];
543 bf[2][1] = hintt[4];
544 bf[0][2] = hintt[5];
545 bf[2][0] = hintt[5];
546}
547
548/*----------------------------------------------------------------------------*/
552/*----------------------------------------------------------------------------*/
553
554void
556
557/*----------------------------------------------------------------------------*/
563/*----------------------------------------------------------------------------*/
564
565void
567
568/*----------------------------------------------------------------------------*/
578/*----------------------------------------------------------------------------*/
579
580void
582
583/*----------------------------------------------------------------------------*/
584
586
587#endif /* __CS_BOUNDARY_CONDITIONS_H__ */
void cs_exit(int status)
Definition cs_base.c:1504
void cs_boundary_conditions_create(void)
Create the legacy boundary conditions face type and face zone arrays.
Definition cs_boundary_conditions.c:1300
static void cs_boundary_conditions_set_neumann_scalar(cs_real_t *a, cs_real_t *af, cs_real_t *b, cs_real_t *bf, cs_real_t qimp, cs_real_t hint)
Set Neumann BC for a scalar for a given face.
Definition cs_boundary_conditions.h:299
static void cs_boundary_conditions_set_dirichlet_scalar(cs_real_t *a, cs_real_t *af, cs_real_t *b, cs_real_t *bf, cs_real_t pimp, cs_real_t hint, cs_real_t hext)
Set Dirichlet BC for a scalar for a given face.
Definition cs_boundary_conditions.h:372
cs_boundary_condition_pm_info_t * cs_glob_bc_pm_info
const int * cs_glob_bc_type
#define CS_MAX_BC_PM_ZONE_NUM
Definition cs_boundary_conditions.h:60
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.c:1072
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.c:920
static void cs_boundary_conditions_set_dirichlet_vector(cs_real_3_t a, cs_real_3_t af, cs_real_33_t b, cs_real_33_t bf, cs_real_3_t pimpv, cs_real_t hint, cs_real_3_t hextv)
Set Dirichlet BC for a vector for a given face.
Definition cs_boundary_conditions.h:421
void cs_boundary_conditions_complete(int itypfb[])
Automatic adjustments for boundary condition codes.
Definition cs_boundary_conditions.c:1625
void cs_boundary_conditions_set_convective_outlet_scalar(cs_real_t *coefa, cs_real_t *cofaf, cs_real_t *coefb, cs_real_t *cofbf, cs_real_t pimp, cs_real_t cfl, cs_real_t hint)
Set convective oulet boundary condition for a scalar.
Definition cs_boundary_conditions.c:1380
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.c:1267
void cs_boundary_conditions_free(void)
Free the boundary conditions face type and face zone arrays.
Definition cs_boundary_conditions.c:1350
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.c:866
void cs_boundary_conditions_reset(void)
Prepare (reset) condition coefficients for all variable fields.
Definition cs_boundary_conditions.c:1404
static void cs_boundary_conditions_set_dirichlet_vector_aniso(cs_real_3_t a, cs_real_3_t af, cs_real_33_t b, cs_real_33_t bf, cs_real_3_t pimpv, cs_real_6_t hintt, cs_real_3_t hextv)
Set Dirichlet BC for a vector for a given face with left anisotropic diffusion.
Definition cs_boundary_conditions.h:511
static void cs_boundary_conditions_set_neumann_vector(cs_real_t a[3], cs_real_t af[3], cs_real_t b[3][3], cs_real_t bf[3][3], const cs_real_t qimpv[3], cs_real_t hint)
Set Neumann BC for a scalar for a given face.
Definition cs_boundary_conditions.h:329
void cs_boundary_conditions_compute(int itypfb[])
Update per variable boundary condition codes.
Definition cs_boundary_conditions.c:1449
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition cs_defs.h:341
#define BEGIN_C_DECLS
Definition cs_defs.h:509
double cs_real_t
Floating-point value.
Definition cs_defs.h:319
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition cs_defs.h:334
#define END_C_DECLS
Definition cs_defs.h:510
int cs_lnum_t
local mesh entity id
Definition cs_defs.h:313
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition cs_defs.h:332
static void cs_math_sym_33_3_product(const cs_real_t m[6], const cs_real_t v[3], cs_real_t mv[restrict 3])
Compute the product of a symmetric matrix of 3x3 real values by a vector of 3 real values....
Definition cs_math.h:639
const cs_real_t cs_math_infinite_r
cs_mesh_location_type_t
Definition cs_mesh_location.h:60
Definition cs_boundary_conditions.h:94
double qimp[CS_MAX_BC_PM_ZONE_NUM+1]
Definition cs_boundary_conditions.h:121
int iqimp[CS_MAX_BC_PM_ZONE_NUM+1]
Definition cs_boundary_conditions.h:106
double dh[CS_MAX_BC_PM_ZONE_NUM+1]
Definition cs_boundary_conditions.h:124
double xintur[CS_MAX_BC_PM_ZONE_NUM+1]
Definition cs_boundary_conditions.h:127
int * izfppp
Definition cs_boundary_conditions.h:98
int icalke[CS_MAX_BC_PM_ZONE_NUM+1]
Definition cs_boundary_conditions.h:113
Field descriptor.
Definition cs_field.h:130