7.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-2021 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 "fvm_nodal.h"
41 #include "fvm_writer.h"
42 
43 #include "cs_base.h"
44 #include "cs_field.h"
45 #include "cs_math.h"
46 #include "cs_mesh_location.h"
47 
48 /*----------------------------------------------------------------------------*/
49 
51 
52 /*============================================================================
53  * Macro definitions
54  *============================================================================*/
55 
56 /*============================================================================
57  * Local type definitions
58  *============================================================================*/
59 
60 /*=============================================================================
61  * Global variables
62  *============================================================================*/
63 
66 extern const int *cs_glob_bc_type;
67 
71 extern const int *cs_glob_bc_face_zone;
72 
73 /*============================================================================
74  * Public function prototypes
75  *============================================================================*/
76 
77 /*----------------------------------------------------------------------------
78  * Handling of boundary condition definition errors and associated output.
79  *
80  * This function checks for errors, and simply returns if no error is
81  * encountered. In case of error, it outputs helpful information so as to
82  * make it easier to locate the matching faces.
83  *
84  * For each boundary face, bc_type defines the boundary condition type.
85  * As a convention here, zero values correspond to undefined types,
86  * positive values to defined types (with no error), and negative values
87  * to defined types with inconsistent or incompatible values, the
88  * absolute value indicating the original boundary condition type.
89  *
90  * An optional label may be used if the error is related to another
91  * attribute than the boundary type, for appropriate error reporting.
92  *
93  * parameters:
94  * bc_flag <-- array of BC type ids
95  * type_name <-- name of attribute in error, or NULL
96  *----------------------------------------------------------------------------*/
97 
98 void
99 cs_boundary_conditions_error(const int *bc_type,
100  const char *type_name);
101 
102 /*----------------------------------------------------------------------------
103  * Locate shifted boundary face coordinates on possibly filtered
104  * cells or boundary faces for later interpolation.
105  *
106  * parameters:
107  * location_type <-- matching values location (CS_MESH_LOCATION_CELLS
108  * or CS_MESH_LOCATION_BOUNDARY_FACES)
109  * n_location_elts <-- number of selected location elements
110  * n_faces <-- number of selected boundary faces
111  * location_elts <-- list of selected location elements (0 to n-1),
112  * or NULL if no indirection is needed
113  * faces <-- list of selected boundary faces (0 to n-1),
114  * or NULL if no indirection is needed
115  * coord_shift <-- array of coordinates shift relative to selected
116  * boundary faces
117  * coord_stride <-- access stride in coord_shift: 0 for uniform
118  * shift, 1 for "per face" shift.
119  * tolerance <-- relative tolerance for point location.
120  *
121  * returns:
122  * associated locator structure
123  *----------------------------------------------------------------------------*/
124 
125 ple_locator_t *
127  cs_lnum_t n_location_elts,
128  cs_lnum_t n_faces,
129  const cs_lnum_t *location_elts,
130  const cs_lnum_t *faces,
131  cs_real_3_t *coord_shift,
132  int coord_stride,
133  double tolerance);
134 
135 /*----------------------------------------------------------------------------
136  * Set mapped boundary conditions for a given field and mapping locator.
137  *
138  * parameters:
139  * field <-- field whose boundary conditions are set
140  * locator <-- associated mapping locator, as returned
141  * by cs_boundary_conditions_map().
142  * location_type <-- matching values location (CS_MESH_LOCATION_CELLS or
143  * CS_MESH_LOCATION_BOUNDARY_FACES)
144  * normalize <-- normalization option:
145  * 0: values are simply mapped
146  * 1: values are mapped, then multiplied
147  * by a constant factor so that their
148  * surface integral on selected faces
149  * is preserved (relative to the
150  * input values)
151  * 2: as 1, but with a boundary-defined
152  * weight, defined by balance_w
153  * 3: as 1, but with a cell-defined
154  * weight, defined by balance_w
155  * interpolate <-- interpolation option:
156  * 0: values are simply based on matching
157  * cell or face center values
158  * 1: values are based on matching cell
159  * or face center values, corrected
160  * by gradient interpolation
161  * n_faces <-- number of selected boundary faces
162  * faces <-- list of selected boundary faces (0 to n-1),
163  * or NULL if no indirection is needed
164  * balance_w <-- optional balance weight, or NULL
165  * nvar <-- number of variables requiring BC's
166  * rcodcl <-> boundary condition values
167  *----------------------------------------------------------------------------*/
168 
169 void
171  ple_locator_t *locator,
172  cs_mesh_location_type_t location_type,
173  int normalize,
174  int interpolate,
175  cs_lnum_t n_faces,
176  const cs_lnum_t *faces,
177  cs_real_t *balance_w,
178  int nvar,
179  cs_real_t rcodcl[]);
180 
181 /*----------------------------------------------------------------------------*/
205 /*----------------------------------------------------------------------------*/
206 
207 int
208 cs_boundary_conditions_add_map(int bc_location_id,
209  int source_location_id,
210  cs_real_t coord_shift[3],
211  double tolerance);
212 
213 /*----------------------------------------------------------------------------
214  * Create the boundary conditions face type and face zone arrays
215  *----------------------------------------------------------------------------*/
216 
217 void
219 
220 /*----------------------------------------------------------------------------
221  * Free the boundary conditions face type and face zone arrays.
222  *
223  * This also frees boundary condition mappings which may have been defined.
224  *----------------------------------------------------------------------------*/
225 
226 void
228 
229 /*----------------------------------------------------------------------------*/
240 /*----------------------------------------------------------------------------*/
241 
242 inline static void
243 cs_boundary_conditions_set_neumann_scalar(cs_real_t *a,
244  cs_real_t *af,
245  cs_real_t *b,
246  cs_real_t *bf,
247  cs_real_t qimp,
248  cs_real_t hint)
249 {
250  /* Gradient BCs */
251  *a = -qimp/hint;
252  *b = 1.;
253 
254  /* Flux BCs */
255  *af = qimp;
256  *bf = 0.;
257 }
258 
259 /*----------------------------------------------------------------------------*/
272 /*----------------------------------------------------------------------------*/
273 
274 inline static void
275 cs_boundary_conditions_set_dirichlet_scalar(cs_real_t *a,
276  cs_real_t *af,
277  cs_real_t *b,
278  cs_real_t *bf,
279  cs_real_t pimp,
280  cs_real_t hint,
281  cs_real_t hext)
282 {
283  if (hext < 0.) {
284 
285  /* Gradient BCs */
286  *a = pimp;
287  *b = 0.;
288 
289  /* Flux BCs */
290  *af = -hint*pimp;
291  *bf = hint;
292 
293  }
294  else {
295 
296  /* Gradient BCs */
297  *a = hext*pimp/(hint + hext);
298  *b = hint /(hint + hext);
299 
300  /* Flux BCs */
301  cs_real_t heq = hint*hext/(hint + hext);
302  *af = -heq*pimp;
303  *bf = heq;
304 
305  }
306 }
307 
308 /*----------------------------------------------------------------------------*/
321 /*----------------------------------------------------------------------------*/
322 
323 inline static void
324 cs_boundary_conditions_set_dirichlet_vector(cs_real_3_t a,
325  cs_real_3_t af,
326  cs_real_33_t b,
327  cs_real_33_t bf,
328  cs_real_3_t pimpv,
329  cs_real_t hint,
330  cs_real_3_t hextv)
331 {
332  for (int isou = 0 ; isou < 3; isou++) {
333  if (fabs(hextv[isou]) > 0.5*cs_math_infinite_r) {
334 
335  /* Gradient BCs */
336  a[isou] = pimpv[isou];
337  for (int jsou = 0 ; jsou < 3 ; jsou++)
338  b[isou][jsou] = 0.;
339 
340  /* Flux BCs */
341  af[isou] = -hint*pimpv[isou];
342  for (int jsou = 0; jsou < 3; jsou++) {
343  if (jsou == isou)
344  bf[isou][jsou] = hint;
345  else
346  bf[isou][jsou] = 0.;
347  }
348  } else {
349 
350  cs_real_t heq = hint*hextv[isou]/(hint + hextv[isou]);
351 
352  /* Gradient BCs */
353  a[isou] = hextv[isou]*pimpv[isou]/(hint + hextv[isou]);
354  for (int jsou = 0 ; jsou < 3 ; jsou++) {
355  if (jsou == isou)
356  b[isou][jsou] = hint/(hint + hextv[isou]);
357  else
358  b[isou][jsou] = 0.;
359  }
360 
361  /* Flux BCs */
362  af[isou] = -heq*pimpv[isou];
363  for (int jsou = 0 ; jsou < 3 ; jsou++) {
364  if (jsou == isou)
365  bf[isou][jsou] = heq;
366  else
367  bf[isou][jsou] = 0.;
368  }
369  }
370  }
371 }
372 
373 /*----------------------------------------------------------------------------*/
386 /*----------------------------------------------------------------------------*/
387 
388 void
390  cs_real_t *cofaf,
391  cs_real_t *coefb,
392  cs_real_t *cofbf,
393  cs_real_t pimp,
394  cs_real_t cfl,
395  cs_real_t hint);
396 
397 /*----------------------------------------------------------------------------*/
411 /*----------------------------------------------------------------------------*/
412 
413 inline static void
414 cs_boundary_conditions_set_dirichlet_vector_aniso(cs_real_3_t a,
415  cs_real_3_t af,
416  cs_real_33_t b,
417  cs_real_33_t bf,
418  cs_real_3_t pimpv,
419  cs_real_6_t hintt,
420  cs_real_3_t hextv)
421 {
422  for (int isou = 0 ; isou < 3 ; isou++) {
423  if (fabs(hextv[isou]) > 0.5*cs_math_infinite_r) {
424 
425  /* Gradient BCs */
426  a[isou] = pimpv[isou];
427  for (int jsou = 0 ; jsou < 3 ; jsou++)
428  b[isou][jsou] = 0.;
429 
430  } else {
431 
432  cs_exit(1);
433 
434  }
435  }
436 
437  /* Flux BCs */
438  cs_math_sym_33_3_product(hintt, pimpv, af);
439  for (int isou = 0 ; isou < 3 ; isou++)
440  af[isou] = -af[isou];
441 
442  bf[0][0] = hintt[0];
443  bf[1][1] = hintt[1];
444  bf[2][2] = hintt[2];
445  bf[0][1] = hintt[3];
446  bf[1][0] = hintt[3];
447  bf[1][2] = hintt[4];
448  bf[2][1] = hintt[4];
449  bf[0][2] = hintt[5];
450  bf[2][0] = hintt[5];
451 }
452 
453 /*----------------------------------------------------------------------------*/
462 /*----------------------------------------------------------------------------*/
463 
464 void
466  int itypfb[],
467  int icodcl[],
468  double rcodcl[]);
469 
470 /*----------------------------------------------------------------------------*/
483 /*----------------------------------------------------------------------------*/
484 
485 void
487  int itypfb[],
488  int icodcl[],
489  double rcodcl[]);
490 
491 /*----------------------------------------------------------------------------*/
492 
494 
495 #endif /* __CS_BOUNDARY_CONDITIONS_H__ */
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:322
Field descriptor.
Definition: cs_field.h:125
cs_mesh_location_type_t
Definition: cs_mesh_location.h:60
void cs_boundary_conditions_free(void)
Free the boundary conditions face type and face zone arrays.
Definition: cs_boundary_conditions.c:1182
#define BEGIN_C_DECLS
Definition: cs_defs.h:495
void cs_exit(int status)
Definition: cs_base.c:1404
void cs_boundary_conditions_create(void)
Create the legacy boundary conditions face type and face zone arrays.
Definition: cs_boundary_conditions.c:1142
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, int nvar, cs_real_t rcodcl[])
Set mapped boundary conditions for a given field and mapping locator.
Definition: cs_boundary_conditions.c:897
const int * cs_glob_bc_face_zone
double cs_real_t
Floating-point value.
Definition: cs_defs.h:307
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:1209
double precision, save a
Definition: cs_fuel_incl.f90:146
void cs_boundary_conditions_compute(int nvar, int itypfb[], int icodcl[], double rcodcl[])
Update per variable boundary condition codes.
Definition: cs_boundary_conditions.c:1238
integer, dimension(:), pointer, save itypfb
Definition: pointe.f90:100
integer, save nvar
number of solved variables (must be lower than nvarmx)
Definition: dimens.f90:42
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:320
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:301
#define END_C_DECLS
Definition: cs_defs.h:496
double precision, dimension(nozppm), save qimp
Definition: coincl.f90:108
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:327
void cs_boundary_conditions_complete(int nvar, int itypfb[], int icodcl[], double rcodcl[])
Automatic adjustments for boundary condition codes.
Definition: cs_boundary_conditions.c:1368
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:675
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:1109
double precision hext
Definition: cs_tagmr.f90:100
const cs_real_t cs_math_infinite_r
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:729
const int * cs_glob_bc_type
double precision, save b
Definition: cs_fuel_incl.f90:146