8.0
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-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 
53 /*============================================================================
54  * Local type definitions
55  *============================================================================*/
56 
57 /*=============================================================================
58  * Global variables
59  *============================================================================*/
60 
63 extern const int *cs_glob_bc_type;
64 
68 extern const int *cs_glob_bc_face_zone;
69 
70 /*============================================================================
71  * Public function prototypes
72  *============================================================================*/
73 
74 /*----------------------------------------------------------------------------
75  * Handling of boundary condition definition errors and associated output.
76  *
77  * This function checks for errors, and simply returns if no error is
78  * encountered. In case of error, it outputs helpful information so as to
79  * make it easier to locate the matching faces.
80  *
81  * For each boundary face, bc_type defines the boundary condition type.
82  * As a convention here, zero values correspond to undefined types,
83  * positive values to defined types (with no error), and negative values
84  * to defined types with inconsistent or incompatible values, the
85  * absolute value indicating the original boundary condition type.
86  *
87  * An optional label may be used if the error is related to another
88  * attribute than the boundary type, for appropriate error reporting.
89  *
90  * parameters:
91  * bc_flag <-- array of BC type ids
92  * type_name <-- name of attribute in error, or NULL
93  *----------------------------------------------------------------------------*/
94 
95 void
96 cs_boundary_conditions_error(const int *bc_type,
97  const char *type_name);
98 
99 /*----------------------------------------------------------------------------
100  * Locate shifted boundary face coordinates on possibly filtered
101  * cells or boundary faces for later interpolation.
102  *
103  * parameters:
104  * location_type <-- matching values location (CS_MESH_LOCATION_CELLS
105  * or CS_MESH_LOCATION_BOUNDARY_FACES)
106  * n_location_elts <-- number of selected location elements
107  * n_faces <-- number of selected boundary faces
108  * location_elts <-- list of selected location elements (0 to n-1),
109  * or NULL if no indirection is needed
110  * faces <-- list of selected boundary faces (0 to n-1),
111  * or NULL if no indirection is needed
112  * coord_shift <-- array of coordinates shift relative to selected
113  * boundary faces
114  * coord_stride <-- access stride in coord_shift: 0 for uniform
115  * shift, 1 for "per face" shift.
116  * tolerance <-- relative tolerance for point location.
117  *
118  * returns:
119  * associated locator structure
120  *----------------------------------------------------------------------------*/
121 
122 ple_locator_t *
124  cs_lnum_t n_location_elts,
125  cs_lnum_t n_faces,
126  const cs_lnum_t *location_elts,
127  const cs_lnum_t *faces,
128  cs_real_3_t *coord_shift,
129  int coord_stride,
130  double tolerance);
131 
132 /*----------------------------------------------------------------------------
133  * Set mapped boundary conditions for a given field and mapping locator.
134  *
135  * parameters:
136  * field <-- field whose boundary conditions are set
137  * locator <-- associated mapping locator, as returned
138  * by cs_boundary_conditions_map().
139  * location_type <-- matching values location (CS_MESH_LOCATION_CELLS or
140  * CS_MESH_LOCATION_BOUNDARY_FACES)
141  * normalize <-- normalization option:
142  * 0: values are simply mapped
143  * 1: values are mapped, then multiplied
144  * by a constant factor so that their
145  * surface integral on selected faces
146  * is preserved (relative to the
147  * input values)
148  * 2: as 1, but with a boundary-defined
149  * weight, defined by balance_w
150  * 3: as 1, but with a cell-defined
151  * weight, defined by balance_w
152  * interpolate <-- interpolation option:
153  * 0: values are simply based on matching
154  * cell or face center values
155  * 1: values are based on matching cell
156  * or face center values, corrected
157  * by gradient interpolation
158  * n_faces <-- number of selected boundary faces
159  * faces <-- list of selected boundary faces (0 to n-1),
160  * or NULL if no indirection is needed
161  * balance_w <-- optional balance weight, or NULL
162  *----------------------------------------------------------------------------*/
163 
164 void
166  ple_locator_t *locator,
167  cs_mesh_location_type_t location_type,
168  int normalize,
169  int interpolate,
170  cs_lnum_t n_faces,
171  const cs_lnum_t *faces,
172  cs_real_t *balance_w);
173 
174 /*----------------------------------------------------------------------------*/
198 /*----------------------------------------------------------------------------*/
199 
200 int
201 cs_boundary_conditions_add_map(int bc_location_id,
202  int source_location_id,
203  cs_real_t coord_shift[3],
204  double tolerance);
205 
206 /*----------------------------------------------------------------------------
207  * Create the boundary conditions face type and face zone arrays
208  *----------------------------------------------------------------------------*/
209 
210 void
212 
213 /*----------------------------------------------------------------------------
214  * Free the boundary conditions face type and face zone arrays.
215  *
216  * This also frees boundary condition mappings which may have been defined.
217  *----------------------------------------------------------------------------*/
218 
219 void
221 
222 /*----------------------------------------------------------------------------*/
233 /*----------------------------------------------------------------------------*/
234 
235 inline static void
237  cs_real_t *af,
238  cs_real_t *b,
239  cs_real_t *bf,
240  cs_real_t qimp,
241  cs_real_t hint)
242 {
243  /* Gradient BCs */
244  *a = -qimp/hint;
245  *b = 1.;
246 
247  /* Flux BCs */
248  *af = qimp;
249  *bf = 0.;
250 }
251 
252 /*----------------------------------------------------------------------------*/
263 /*----------------------------------------------------------------------------*/
264 
265 inline static void
267  cs_real_t af[3],
268  cs_real_t b[3][3],
269  cs_real_t bf[3][3],
270  const cs_real_t qimpv[3],
271  cs_real_t hint)
272 {
273  /* Gradient BCs */
274 
275  for (size_t i = 0; i < 3; i++) {
276  a[i] = -qimpv[i] / fmax(hint, 1.e-300);
277  }
278 
279  b[0][0] = 1., b[0][1] = 0., b[0][2] = 0.;
280  b[1][0] = 0., b[1][1] = 1., b[1][2] = 0.;
281  b[2][0] = 0., b[2][1] = 0., b[2][2] = 1.;
282 
283  /* Flux BCs */
284 
285  for (size_t i = 0; i < 3; i++) {
286  af[i] = qimpv[i];
287 
288  for (size_t j = 0; j < 3; j++)
289  bf[i][j] = 0;
290  }
291 }
292 
293 /*----------------------------------------------------------------------------*/
306 /*----------------------------------------------------------------------------*/
307 
308 inline static void
310  cs_real_t *af,
311  cs_real_t *b,
312  cs_real_t *bf,
313  cs_real_t pimp,
314  cs_real_t hint,
315  cs_real_t hext)
316 {
317  if (hext < 0.) {
318 
319  /* Gradient BCs */
320  *a = pimp;
321  *b = 0.;
322 
323  /* Flux BCs */
324  *af = -hint*pimp;
325  *bf = hint;
326 
327  }
328  else {
329 
330  /* Gradient BCs */
331  *a = hext*pimp/(hint + hext);
332  *b = hint /(hint + hext);
333 
334  /* Flux BCs */
335  cs_real_t heq = hint*hext/(hint + hext);
336  *af = -heq*pimp;
337  *bf = heq;
338 
339  }
340 }
341 
342 /*----------------------------------------------------------------------------*/
355 /*----------------------------------------------------------------------------*/
356 
357 inline static void
359  cs_real_3_t af,
360  cs_real_33_t b,
361  cs_real_33_t bf,
362  cs_real_3_t pimpv,
363  cs_real_t hint,
364  cs_real_3_t hextv)
365 {
366  for (int isou = 0; isou < 3; isou++) {
367  if (fabs(hextv[isou]) > 0.5*cs_math_infinite_r) {
368 
369  /* Gradient BCs */
370  a[isou] = pimpv[isou];
371  for (int jsou = 0; jsou < 3; jsou++)
372  b[isou][jsou] = 0.;
373 
374  /* Flux BCs */
375  af[isou] = -hint*pimpv[isou];
376  for (int jsou = 0; jsou < 3; jsou++) {
377  if (jsou == isou)
378  bf[isou][jsou] = hint;
379  else
380  bf[isou][jsou] = 0.;
381  }
382  } else {
383 
384  cs_real_t heq = hint*hextv[isou]/(hint + hextv[isou]);
385 
386  /* Gradient BCs */
387  a[isou] = hextv[isou]*pimpv[isou]/(hint + hextv[isou]);
388  for (int jsou = 0; jsou < 3; jsou++) {
389  if (jsou == isou)
390  b[isou][jsou] = hint/(hint + hextv[isou]);
391  else
392  b[isou][jsou] = 0.;
393  }
394 
395  /* Flux BCs */
396  af[isou] = -heq*pimpv[isou];
397  for (int jsou = 0; jsou < 3; jsou++) {
398  if (jsou == isou)
399  bf[isou][jsou] = heq;
400  else
401  bf[isou][jsou] = 0.;
402  }
403  }
404  }
405 }
406 
407 /*----------------------------------------------------------------------------*/
420 /*----------------------------------------------------------------------------*/
421 
422 void
424  cs_real_t *cofaf,
425  cs_real_t *coefb,
426  cs_real_t *cofbf,
427  cs_real_t pimp,
428  cs_real_t cfl,
429  cs_real_t hint);
430 
431 /*----------------------------------------------------------------------------*/
445 /*----------------------------------------------------------------------------*/
446 
447 inline static void
449  cs_real_3_t af,
450  cs_real_33_t b,
451  cs_real_33_t bf,
452  cs_real_3_t pimpv,
453  cs_real_6_t hintt,
454  cs_real_3_t hextv)
455 {
456  /* Gradient BCs */
457  for (int isou = 0; isou < 3; isou++) {
458  if (fabs(hextv[isou]) > 0.5*cs_math_infinite_r) {
459  a[isou] = pimpv[isou];
460  for (int jsou = 0; jsou < 3; jsou++)
461  b[isou][jsou] = 0.;
462  }
463  else {
464  /* FIXME: at least log error message */
465  cs_exit(1);
466  }
467  }
468 
469  /* Flux BCs */
470  cs_math_sym_33_3_product(hintt, pimpv, af);
471  for (int isou = 0; isou < 3; isou++)
472  af[isou] = -af[isou];
473 
474  bf[0][0] = hintt[0];
475  bf[1][1] = hintt[1];
476  bf[2][2] = hintt[2];
477  bf[0][1] = hintt[3];
478  bf[1][0] = hintt[3];
479  bf[1][2] = hintt[4];
480  bf[2][1] = hintt[4];
481  bf[0][2] = hintt[5];
482  bf[2][0] = hintt[5];
483 }
484 
485 /*----------------------------------------------------------------------------*/
489 /*----------------------------------------------------------------------------*/
490 
491 void
493 
494 /*----------------------------------------------------------------------------*/
500 /*----------------------------------------------------------------------------*/
501 
502 void
504 
505 /*----------------------------------------------------------------------------*/
515 /*----------------------------------------------------------------------------*/
516 
517 void
519 
520 /*----------------------------------------------------------------------------*/
521 
523 
524 #endif /* __CS_BOUNDARY_CONDITIONS_H__ */
void cs_exit(int status)
Definition: cs_base.c:1505
void cs_boundary_conditions_create(void)
Create the legacy boundary conditions face type and face zone arrays.
Definition: cs_boundary_conditions.c:1255
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:236
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:309
const int * cs_glob_bc_type
const int * cs_glob_bc_face_zone
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:1027
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:358
void cs_boundary_conditions_complete(int itypfb[])
Automatic adjustments for boundary condition codes.
Definition: cs_boundary_conditions.c:1567
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:875
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:1322
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:1222
void cs_boundary_conditions_free(void)
Free the boundary conditions face type and face zone arrays.
Definition: cs_boundary_conditions.c:1295
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:821
void cs_boundary_conditions_reset(void)
Prepare (reset) condition coefficients for all variable fields.
Definition: cs_boundary_conditions.c:1346
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:448
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:266
void cs_boundary_conditions_compute(int itypfb[])
Update per variable boundary condition codes.
Definition: cs_boundary_conditions.c:1391
#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_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:332
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
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:341
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
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
integer, dimension(:), pointer, save itypfb
boundary condition type at the boundary face ifac (see cs_user_boundary_conditions)
Definition: pointe.f90:100
double precision, save fmax
Definition: coincl.f90:182
double precision, dimension(nozppm), save qimp
Definition: coincl.f90:157
double precision, save a
Definition: cs_fuel_incl.f90:148
double precision, save b
Definition: cs_fuel_incl.f90:148
Field descriptor.
Definition: cs_field.h:130