9.0
general documentation
Loading...
Searching...
No Matches
cs_boundary_conditions_set_coeffs.h
Go to the documentation of this file.
1#ifndef __CS_BOUNDARY_CONDITIONS_SET_COEFFS_H__
2#define __CS_BOUNDARY_CONDITIONS_SET_COEFFS_H__
3
4/*============================================================================
5 * Translation of the boundary conditions given by the user in a form
6 * that fits the solver.
7 *============================================================================*/
8
9/*
10 This file is part of code_saturne, a general-purpose CFD tool.
11
12 Copyright (C) 1998-2025 EDF S.A.
13
14 This program is free software; you can redistribute it and/or modify it under
15 the terms of the GNU General Public License as published by the Free Software
16 Foundation; either version 2 of the License, or (at your option) any later
17 version.
18
19 This program is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 details.
23
24 You should have received a copy of the GNU General Public License along with
25 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
26 Street, Fifth Floor, Boston, MA 02110-1301, USA.
27*/
28
29/*----------------------------------------------------------------------------*/
30
31/*----------------------------------------------------------------------------
32 * Local headers
33 *----------------------------------------------------------------------------*/
34
35#include "base/cs_defs.h"
36
37#include "bft/bft_error.h"
38#include "base/cs_field.h"
39#include "base/cs_math.h"
41
42#ifdef __cplusplus
43#include "base/cs_dispatch.h"
44#endif
45
46/*----------------------------------------------------------------------------*/
47
49
50/*=============================================================================
51 * Public function prototypes
52 *============================================================================*/
53
54/*----------------------------------------------------------------------------*/
55/*
56 * \brief Translation of the boundary conditions given by the user
57 * in a form that fits to the solver.
58 *
59 * The values at a boundary face \f$ \fib \f$ stored in the face center
60 * \f$ \centf \f$ of the variable \f$ P \f$ and its diffusive flux \f$ Q \f$
61 * are written as:
62 * \f[
63 * P_{\face} = A_P^g + B_P^g P_{\centi}
64 * \f]
65 * and
66 * \f[
67 * Q_{\face} = A_P^f + B_P^f P_{\centi}
68 * \f]
69 * where \f$ P_\centi \f$ is the value of the variable \f$ P \f$ at the
70 * neighboring cell.
71 *
72 * \warning
73 * - If we consider an increment of a variable, the boundary conditions
74 * read:
75 * \f[
76 * \delta P_{\face} = B_P^g \delta P_{\centi}
77 * \f]
78 * and
79 * \f[
80 * \delta Q_{\face} = -B_P^f \delta P_{\centi}
81 * \f]
82 *
83 * - For a vector field such as the velocity \f$ \vect{u} \f$ the boundary
84 * conditions may read:
85 * \f[
86 * \vect{u}_{\face} = \vect{A}_u^g + \tens{B}_u^g \vect{u}_{\centi}
87 * \f]
88 * and
89 * \f[
90 * \vect{Q}_{\face} = \vect{A}_u^f + \tens{B}_u^f \vect{u}_{\centi}
91 * \f]
92 * where \f$ \tens{B}_u^g \f$ and \f$ \tens{B}_u^f \f$ are 3x3 tensor matrix
93 * which coupled velocity components next to a boundary.
94 *
95 * Please refer to the
96 * <a href="../../theory.pdf#boundary"><b>boundary conditions</b></a> section
97 * of the theory guide for more informations, as well as the
98 * <a href="../../theory.pdf#condli"><b>condli</b></a> section.
99 *
100 * \param[in] nvar total number of variables
101 * \param[in] iterns iteration number on Navier-Stokes equations
102 * \param[in] isvhb id of field whose exchange coeffient should be
103 * saved at the walls, or -1.
104 * \param[in] itrale ALE iteration number
105 * \param[in] italim for ALE
106 * \param[in] itrfin Last velocity-pressure sub-iteration indicator
107 * \param[in] ineefl for ALE
108 * \param[in] itrfup Update after velocity-pressure sub-iterations
109 * \param[in,out] isostd indicator for standard outlet
110 * and reference face index
111 * \param[in] dt time step (per cell)
112 * \param[out] visvdr dynamic viscosity after V. Driest damping in
113 * boundary cells
114 * \param[out] hbord exchange coefficient at boundary
115 * \param[out] theipb value of thermal scalar at \f$ \centip \f$
116 * of boundary cells
117 * \param[in] nftcdt Global indicator of condensation source terms
118 * (ie. sum on the processors of nfbpcd) cells
119 * associated to the face with condensation
120 * phenomenon
121 */
122/*----------------------------------------------------------------------------*/
123
124void
126 int iterns,
127 int isvhb,
128 int itrale,
129 int italim,
130 int itrfin,
131 int ineefl,
132 int itrfup,
133 int isostd[],
134 cs_real_t visvdr[],
135 cs_real_t hbord[],
136 cs_real_t theipb[],
137 int nftcdt);
138
139/*----------------------------------------------------------------------------*/
143/*----------------------------------------------------------------------------*/
144
145void
147
148/*----------------------------------------------------------------------------*/
157/*----------------------------------------------------------------------------*/
158
159inline static void
161 cs_field_bc_coeffs_t *bc_coeffs,
162 cs_real_t qimp,
163 cs_real_t hint)
164{
165 cs_real_t *a = bc_coeffs->a;
166 cs_real_t *b = bc_coeffs->b;
167 cs_real_t *af = bc_coeffs->af;
168 cs_real_t *bf = bc_coeffs->bf;
169
170 /* Gradient BCs */
171 a[f_id] = -qimp/cs_math_fmax(hint, 1.e-300);
172 b[f_id] = 1.;
173
174 /* Flux BCs */
175 af[f_id] = qimp;
176 bf[f_id] = 0.;
177}
178
179/*----------------------------------------------------------------------------*/
186/*----------------------------------------------------------------------------*/
187
188inline static void
190 cs_field_bc_coeffs_t *bc_coeffs)
191{
192 cs_real_t *a = bc_coeffs->a;
193 cs_real_t *b = bc_coeffs->b;
194 cs_real_t *af = bc_coeffs->af;
195 cs_real_t *bf = bc_coeffs->bf;
196
197 /* Gradient BCs */
198 a[f_id] = 0.;
199 b[f_id] = 1.;
200
201 /* Flux BCs */
202 af[f_id] = 0.;
203 bf[f_id] = 0.;
204}
205
206/*----------------------------------------------------------------------------*/
215/*----------------------------------------------------------------------------*/
216
217inline static void
219 cs_field_bc_coeffs_t *bc_coeffs,
220 const cs_real_t qimpv[3],
221 cs_real_t hint)
222{
223 cs_real_3_t *a = (cs_real_3_t *)bc_coeffs->a;
224 cs_real_33_t *b = (cs_real_33_t *)bc_coeffs->b;
225 cs_real_3_t *af = (cs_real_3_t *)bc_coeffs->af;
226 cs_real_33_t *bf = (cs_real_33_t *)bc_coeffs->bf;
227
228 /* Gradient BCs */
229
230 for (size_t i = 0; i < 3; i++) {
231 a[f_id][i] = -qimpv[i] / fmax(hint, 1.e-300);
232 }
233
234 b[f_id][0][0] = 1., b[f_id][0][1] = 0., b[f_id][0][2] = 0.;
235 b[f_id][1][0] = 0., b[f_id][1][1] = 1., b[f_id][1][2] = 0.;
236 b[f_id][2][0] = 0., b[f_id][2][1] = 0., b[f_id][2][2] = 1.;
237
238 /* Flux BCs */
239
240 for (size_t i = 0; i < 3; i++) {
241 af[f_id][i] = qimpv[i];
242
243 for (size_t j = 0; j < 3; j++)
244 bf[f_id][i][j] = 0.;
245 }
246}
247
248/*----------------------------------------------------------------------------*/
257/*----------------------------------------------------------------------------*/
258
259inline static void
261 cs_field_bc_coeffs_t *bc_coeffs,
262 const cs_real_t qimpv[3],
263 const cs_real_t hint[6])
264{
265 cs_real_3_t *a = (cs_real_3_t *)bc_coeffs->a;
266 cs_real_33_t *b = (cs_real_33_t *)bc_coeffs->b;
267 cs_real_3_t *af = (cs_real_3_t *)bc_coeffs->af;
268 cs_real_33_t *bf = (cs_real_33_t *)bc_coeffs->bf;
269
270 cs_real_t m[6] = {0., 0., 0., 0., 0., 0.};
271 m[0] = hint[1]*hint[2] - hint[4]*hint[4];
272 m[1] = hint[0]*hint[2] - hint[5]*hint[5];
273 m[2] = hint[0]*hint[1] - hint[3]*hint[3];
274 m[3] = hint[4]*hint[5] - hint[3]*hint[2];
275 m[4] = hint[3]*hint[5] - hint[0]*hint[4];
276 m[5] = hint[3]*hint[4] - hint[1]*hint[5];
277
278 cs_real_t invdet = 1./(hint[0]*m[0] + hint[3]*m[3] + hint[5]*m[5]);
279
280 cs_real_t invh[6] = {0., 0., 0., 0., 0., 0.};
281 invh[0] = m[0] * invdet;
282 invh[1] = m[1] * invdet;
283 invh[2] = m[2] * invdet;
284 invh[3] = m[3] * invdet;
285 invh[4] = m[4] * invdet;
286 invh[5] = m[5] * invdet;
287
288 /* Gradient BCs */
289 cs_math_sym_33_3_product(invh, qimpv, a[f_id]);
290 for (int isou = 0; isou < 3; isou++)
291 a[f_id][isou] = -a[f_id][isou];
292
293 b[f_id][0][0] = 1.0, b[f_id][0][1] = 0.0, b[f_id][0][2] = 0.0;
294 b[f_id][1][0] = 0.0, b[f_id][1][1] = 1.0, b[f_id][1][2] = 0.0;
295 b[f_id][2][0] = 0.0, b[f_id][2][1] = 0.0, b[f_id][2][2] = 1.0;
296
297 for (int isou = 0; isou < 3; isou++) {
298
299 /* Flux BCs */
300 af[f_id][isou] = qimpv[isou];
301 for (int jsou = 0; jsou < 3; jsou++)
302 bf[f_id][isou][jsou] = 0.0;
303 }
304}
305
306/*----------------------------------------------------------------------------*/
314/*----------------------------------------------------------------------------*/
315
316inline static void
318 cs_real_t af[6],
319 cs_real_t b[6][6],
320 cs_real_t bf[6][6],
321 const cs_real_t qimpts[6],
322 cs_real_t hint)
323{
324 for (int isou = 0; isou < 6; isou++) {
325
326 /* Gradient BC */
327 a[isou] = -qimpts[isou]/cs_math_fmax(hint, 1.e-300);
328 for (int jsou = 0; jsou < 6; jsou++) {
329 if (jsou == isou)
330 b[isou][jsou] = 1.0;
331 else
332 b[isou][jsou] = 0.0;
333 }
334
335 /* Flux BCs */
336 af[isou] = qimpts[isou];
337 for (int jsou = 0; jsou < 6; jsou++)
338 bf[isou][jsou] = 0.0;
339 }
340}
341
342/*----------------------------------------------------------------------------*/
353/*----------------------------------------------------------------------------*/
354
355inline static void
357 cs_field_bc_coeffs_t *bc_coeffs,
358 cs_real_t pimp,
359 cs_real_t hint,
360 cs_real_t hext)
361{
362 cs_real_t *a = bc_coeffs->a;
363 cs_real_t *b = bc_coeffs->b;
364 cs_real_t *af = bc_coeffs->af;
365 cs_real_t *bf = bc_coeffs->bf;
366
367 //if (fabs(hext) > cs_math_infinite_r*0.5) {
368 if (hext < 0.) {
369
370 /* Gradient BCs */
371 a[f_id] = pimp;
372 b[f_id] = 0.;
373
374 /* Flux BCs */
375 af[f_id] = -hint*pimp;
376 bf[f_id] = hint;
377
378 }
379 else {
380
381 /* Gradient BCs */
382 a[f_id] = hext*pimp/(hint + hext);
383 b[f_id] = hint /(hint + hext);
384
385 /* Flux BCs */
386 cs_real_t heq = hint*hext/(hint + hext);
387 af[f_id] = -heq*pimp;
388 bf[f_id] = heq;
389
390 }
391}
392
393/*----------------------------------------------------------------------------*/
404/*----------------------------------------------------------------------------*/
405
406inline static void
408 cs_field_bc_coeffs_t *bc_coeffs,
409 const cs_real_t pimpv[3],
410 cs_real_t hint,
411 const cs_real_t hextv[3])
412{
413
414 cs_real_3_t *a = (cs_real_3_t *)bc_coeffs->a;
415 cs_real_33_t *b = (cs_real_33_t *)bc_coeffs->b;
416 cs_real_3_t *af = (cs_real_3_t *)bc_coeffs->af;
417 cs_real_33_t *bf = (cs_real_33_t *)bc_coeffs->bf;
418
419 for (int isou = 0; isou < 3; isou++) {
420 if (fabs(hextv[isou]) > 0.5*cs_math_infinite_r) {
421
422 /* Gradient BCs */
423 a[f_id][isou] = pimpv[isou];
424 for (int jsou = 0; jsou < 3; jsou++)
425 b[f_id][isou][jsou] = 0.;
426
427 /* Flux BCs */
428 af[f_id][isou] = -hint*pimpv[isou];
429
430 bf[f_id][0][0] = hint, bf[f_id][0][1] = 0., bf[f_id][0][2] = 0.;
431 bf[f_id][1][0] = 0., bf[f_id][1][1] = hint, bf[f_id][1][2] = 0.;
432 bf[f_id][2][0] = 0., bf[f_id][2][1] = 0., bf[f_id][2][2] = hint;
433
434 }
435 else {
436
437 const cs_real_t val = hint/(hint + hextv[isou]);
438 const cs_real_t heq = hextv[isou]*val;
439
440 /* Gradient BCs */
441 a[f_id][isou] = hextv[isou]*pimpv[isou]/(hint + hextv[isou]);
442
443 b[f_id][0][0] = val, b[f_id][0][1] = 0., b[f_id][0][2] = 0.;
444 b[f_id][1][0] = 0., b[f_id][1][1] = val, b[f_id][1][2] = 0.;
445 b[f_id][2][0] = 0., b[f_id][2][1] = 0., b[f_id][2][2] = val;
446
447 /* Flux BCs */
448 af[f_id][isou] = -heq*pimpv[isou];
449
450 bf[f_id][0][0] = heq, bf[f_id][0][1] = 0., bf[f_id][0][2] = 0.;
451 bf[f_id][1][0] = 0., bf[f_id][1][1] = heq, bf[f_id][1][2] = 0.;
452 bf[f_id][2][0] = 0., bf[f_id][2][1] = 0., bf[f_id][2][2] = heq;
453
454 }
455 }
456}
457
458/*----------------------------------------------------------------------------*/
459/*
460 * \brief Set convective oulet BC for a scalar for a given face.
461 *
462 * \param[in] f_id face id
463 * \param[out] bc_coeffs boundary conditions structure
464 * \param[in] pimp flux value to impose
465 * \param[in] cfl local Courant number used to convect
466 * \param[in] hint internal exchange coefficient
467 */
468/*----------------------------------------------------------------------------*/
469
470void
472 (cs_lnum_t f_id,
473 cs_field_bc_coeffs_t *bc_coeffs,
474 cs_real_t pimp,
475 cs_real_t cfl,
476 cs_real_t hint);
477
478/*----------------------------------------------------------------------------*/
490/*----------------------------------------------------------------------------*/
491
492inline static void
494(cs_lnum_t f_id,
495 cs_field_bc_coeffs_t *bc_coeffs,
496 const cs_real_t pimpv[3],
497 const cs_real_t hintt[6],
498 const cs_real_t hextv[3])
499{
500
501 cs_real_3_t *a = (cs_real_3_t *)bc_coeffs->a;
502 cs_real_33_t *b = (cs_real_33_t *)bc_coeffs->b;
503 cs_real_3_t *af = (cs_real_3_t *)bc_coeffs->af;
504 cs_real_33_t *bf = (cs_real_33_t *)bc_coeffs->bf;
505
506 /* Gradient BCs */
507 for (int isou = 0; isou < 3; isou++) {
508 if (fabs(hextv[isou]) > 0.5*cs_math_infinite_r) {
509 a[f_id][isou] = pimpv[isou];
510 for (int jsou = 0; jsou < 3; jsou++)
511 b[f_id][isou][jsou] = 0.;
512 }
513 else {
514 /* FIXME: at least log error message */
515 bft_error(__FILE__, __LINE__, 0,
516 _(" %s: hextv not set for component %d."),
517 __func__, isou);
518 }
519 }
520
521 /* Flux BCs */
522 cs_math_sym_33_3_product(hintt, pimpv, af[f_id]);
523 for (int isou = 0; isou < 3; isou++)
524 af[f_id][isou] = -af[f_id][isou];
525
526 bf[f_id][0][0] = hintt[0];
527 bf[f_id][1][1] = hintt[1];
528 bf[f_id][2][2] = hintt[2];
529 bf[f_id][0][1] = hintt[3];
530 bf[f_id][1][0] = hintt[3];
531 bf[f_id][1][2] = hintt[4];
532 bf[f_id][2][1] = hintt[4];
533 bf[f_id][0][2] = hintt[5];
534 bf[f_id][2][0] = hintt[5];
535}
536
537/*----------------------------------------------------------------------------*/
547/*----------------------------------------------------------------------------*/
548
549inline static void
551 cs_real_t af[6],
552 cs_real_t b[6][6],
553 cs_real_t bf[6][6],
554 const cs_real_t pimpts[6],
555 cs_real_t hint,
556 const cs_real_t hextts[6])
557{
558 for (int isou = 0; isou < 6; isou++) {
559
560 if (fabs(hextts[isou]) > 0.5*cs_math_infinite_r) {
561 /* Gradient BCs */
562 a[isou] = pimpts[isou];
563 for (int jsou = 0; jsou < 6; jsou++)
564 b[isou][jsou] = 0.;
565
566 /* Flux BCs */
567 af[isou] = -hint * pimpts[isou];
568 for (int jsou = 0; jsou < 6; jsou++) {
569 if (jsou == isou)
570 bf[isou][jsou] = hint;
571 else
572 bf[isou][jsou] = 0.;
573 }
574 }
575
576 else {
577
578 const cs_real_t heq = hint * hextts[isou] / (hint + hextts[isou]);
579
580 /* Gradient BCs */
581 a[isou] = hextts[isou] * pimpts[isou] / (hint + hextts[isou]);
582 for (int jsou = 0; jsou < 6; jsou++) {
583 if (jsou == isou)
584 b[isou][jsou] = hint / (hint + hextts[isou]);
585 else
586 b[isou][jsou] = 0.;
587 }
588
589 /* Flux BCs */
590 af[isou] = -heq * pimpts[isou];
591 for (int jsou = 0; jsou < 6; jsou++) {
592 if (jsou == isou)
593 bf[isou][jsou] = heq;
594 else
595 bf[isou][jsou] = 0.;
596 }
597 }
598 }
599}
600
601/*----------------------------------------------------------------------------*/
612/*----------------------------------------------------------------------------*/
613
614inline static void
616 (cs_lnum_t f_id,
617 cs_field_bc_coeffs_t *bc_coeffs,
618 const cs_real_t pimpv[3],
619 const cs_real_t qimpv[3],
620 cs_real_t hint,
621 const cs_nreal_t normal[3])
622{
623 cs_real_3_t *a = (cs_real_3_t *)bc_coeffs->a;
624 cs_real_33_t *b = (cs_real_33_t *)bc_coeffs->b;
625 cs_real_3_t *af = (cs_real_3_t *)bc_coeffs->af;
626 cs_real_33_t *bf = (cs_real_33_t *)bc_coeffs->bf;
627
628 for (int isou = 0; isou < 3; isou++) {
629
630 /* Gradient BCs */
631 a[f_id][isou] = - qimpv[isou]/cs_math_fmax(hint, 1.e-300);
632 /* "[1 -n(x)n] Qimp / hint" is divided into two */
633 for (int jsou = 0; jsou < 3; jsou++) {
634
635 a[f_id][isou] = a[f_id][isou] + normal[isou]*normal[jsou]
636 * (pimpv[jsou] + qimpv[jsou] / cs_math_fmax(hint, 1.e-300));
637
638 if (jsou == isou)
639 b[f_id][isou][jsou] = 1.0 - normal[isou] * normal[jsou];
640 else
641 b[f_id][isou][jsou] = - normal[isou] * normal[jsou];
642 }
643
644 /* Flux BCs */
645 af[f_id][isou] = qimpv[isou];
646 /* "[1 -n(x)n] Qimp" is divided into two */
647 for (int jsou = 0; jsou < 3; jsou++){
648
649 af[f_id][isou] = af[f_id][isou] - normal[isou]*normal[jsou]
650 * (hint * pimpv[jsou] + qimpv[jsou]);
651
652 bf[f_id][isou][jsou] = hint * normal[isou] * normal[jsou];
653 }
654 }
655}
656
657/*----------------------------------------------------------------------------*/
669/*----------------------------------------------------------------------------*/
670
671void
673 (cs_lnum_t f_id,
674 cs_field_bc_coeffs_t *bc_coeffs,
675 const cs_real_t pimpv[3],
676 const cs_real_t qimpv[3],
677 const cs_real_t hint[6],
678 const cs_nreal_t normal[3]);
679
680/*----------------------------------------------------------------------------*/
692/*----------------------------------------------------------------------------*/
693
694inline static void
696 (cs_lnum_t f_id,
697 cs_field_bc_coeffs_t *bc_coeffs,
698 const cs_real_t pimpv[3],
699 const cs_real_t qimpv[3],
700 cs_real_t hint,
701 const cs_nreal_t normal[3])
702{
703 cs_real_3_t *a = (cs_real_3_t *)bc_coeffs->a;
704 cs_real_33_t *b = (cs_real_33_t *)bc_coeffs->b;
705 cs_real_3_t *af = (cs_real_3_t *)bc_coeffs->af;
706 cs_real_33_t *bf = (cs_real_33_t *)bc_coeffs->bf;
707
708 for (int isou = 0; isou < 3; isou++) {
709
710 /* Gradient BC*/
711 /* "[1 -n(x)n] Pimp" is divided into two */
712 a[f_id][isou] = pimpv[isou];
713 for (int jsou = 0; jsou < 3; jsou++) {
714
715 a[f_id][isou] = a[f_id][isou] - normal[isou]*normal[jsou]
716 * (pimpv[jsou] + qimpv[jsou] / cs_math_fmax(hint, 1.e-300));
717
718 b[f_id][isou][jsou] = normal[isou] * normal[jsou];
719 }
720
721 /* Flux BC */
722 /* "[1 -n(x)n] Pimp" is divided into two */
723 af[f_id][isou] = -hint*pimpv[isou];
724 for (int jsou = 0; jsou < 3; jsou++) {
725
726 af[f_id][isou] = af[f_id][isou] + normal[isou]*normal[jsou]
727 * (qimpv[jsou] + pimpv[jsou] * hint);
728
729 if (jsou == isou)
730 bf[f_id][isou][jsou] = hint * (1.0 - normal[isou] * normal[jsou]);
731 else
732 bf[f_id][isou][jsou] = - hint * normal[isou] * normal[jsou];
733 }
734 }
735}
736
737/*----------------------------------------------------------------------------*/
750/*----------------------------------------------------------------------------*/
751
752void
754 (cs_lnum_t f_id,
755 cs_field_bc_coeffs_t *bc_coeffs,
756 const cs_real_t pimpv[3],
757 const cs_real_t qimpv[3],
758 const cs_real_t hint[6],
759 const cs_nreal_t normal[3]);
760
761/*----------------------------------------------------------------------------*/
771/*----------------------------------------------------------------------------*/
772
773inline static void
775 (cs_lnum_t f_id,
776 cs_field_bc_coeffs_t *bc_coeffs,
777 const cs_real_t pimpv[3],
778 const cs_real_t cflv[3],
779 cs_real_t hint)
780{
781 cs_real_3_t *a = (cs_real_3_t *)bc_coeffs->a;
782 cs_real_33_t *b = (cs_real_33_t *)bc_coeffs->b;
783 cs_real_3_t *af = (cs_real_3_t *)bc_coeffs->af;
784 cs_real_33_t *bf = (cs_real_33_t *)bc_coeffs->bf;
785
786 for (int isou = 0; isou < 3; isou++) {
787
788 /* Gradient BCs */
789 for (int jsou = 0; jsou < 3; jsou ++) {
790 if (jsou == isou)
791 b[f_id][isou][jsou] = cflv[isou] / (1.0 + cflv[isou]);
792 else
793 b[f_id][isou][jsou] = 0.0;
794 }
795 a[f_id][isou] = pimpv[isou] * (1.0 - b[f_id][isou][isou]);
796
797 /* Flux BCs */
798 af[f_id][isou] = -hint * a[f_id][isou];
799 for (int jsou = 0; jsou < 3; jsou++) {
800 if (jsou == isou)
801 bf[f_id][isou][jsou] = hint * (1.0 - b[f_id][isou][jsou]);
802 else
803 bf[f_id][isou][jsou] = 0.0;
804 }
805 }
806}
807
808/*----------------------------------------------------------------------------*/
818/*----------------------------------------------------------------------------*/
819
820inline static void
822 cs_real_t af[6],
823 cs_real_t b[6][6],
824 cs_real_t bf[6][6],
825 const cs_real_t pimpts[6],
826 const cs_real_t cflts[6],
827 cs_real_t hint)
828{
829 for (int isou = 0; isou < 6; isou++) {
830
831 /* Gradient BCs */
832 for (int jsou = 0; jsou < 6; jsou++) {
833 if (jsou == isou)
834 b[isou][jsou] = cflts[isou] / (1.0 + cflts[isou]);
835 else
836 b[isou][jsou] = 0.0;
837 }
838 a[isou] = (1.0 - b[isou][isou]) * pimpts[isou];
839
840 /* Flux BCs */
841 af[isou] = -hint*a[isou];
842 for (int jsou = 0; jsou < 6; jsou++) {
843 if (jsou == isou)
844 bf[isou][jsou] = hint * (1.0 - b[isou][jsou]);
845 else
846 bf[isou][jsou] = 0.0;
847 }
848 }
849}
850
851/*----------------------------------------------------------------------------*/
861/*----------------------------------------------------------------------------*/
862
863inline static void
865(cs_lnum_t f_id,
866 cs_field_bc_coeffs_t *bc_coeffs,
867 const cs_real_t pimpv[3],
868 const cs_real_t cflv[3],
869 const cs_real_t hintt[6])
870{
871
872 cs_real_3_t *a = (cs_real_3_t *)bc_coeffs->a;
873 cs_real_33_t *b = (cs_real_33_t *)bc_coeffs->b;
874 cs_real_3_t *af = (cs_real_3_t *)bc_coeffs->af;
875 cs_real_33_t *bf = (cs_real_33_t *)bc_coeffs->bf;
876
877 for(int isou = 0; isou < 3; isou++) {
878
879 /* Gradient BCs */
880 for (int jsou = 0; jsou < 3; jsou++) {
881 if (jsou == isou)
882 b[f_id][isou][jsou] = cflv[isou]/(1.0+cflv[isou]);
883 else
884 b[f_id][isou][jsou] = 0.0;
885 }
886 a[f_id][isou] = (1.0-b[f_id][isou][isou])*pimpv[isou];
887
888 }
889
890 /* Flux BCs */
891 cs_math_sym_33_3_product(hintt, a[f_id], af[f_id]);
892 for (int isou = 0; isou < 3; isou++)
893 af[f_id][isou] = -af[f_id][isou];
894
895 bf[f_id][0][0] = hintt[0]*(1.0 - b[f_id][0][0]);
896 bf[f_id][1][1] = hintt[1]*(1.0 - b[f_id][1][1]);
897 bf[f_id][2][2] = hintt[2]*(1.0 - b[f_id][2][2]);
898 bf[f_id][0][1] = hintt[3]*(1.0 - b[f_id][0][0]);
899 bf[f_id][1][0] = hintt[3]*(1.0 - b[f_id][0][0]);
900 bf[f_id][1][2] = hintt[4]*(1.0 - b[f_id][1][1]);
901 bf[f_id][2][1] = hintt[4]*(1.0 - b[f_id][1][1]);
902 bf[f_id][0][2] = hintt[5]*(1.0 - b[f_id][2][2]);
903 bf[f_id][2][0] = hintt[5]*(1.0 - b[f_id][2][2]);
904}
905
906/*----------------------------------------------------------------------------*/
916/*----------------------------------------------------------------------------*/
917
918inline static void
920 (cs_lnum_t f_id,
921 cs_field_bc_coeffs_t *bc_coeffs,
922 cs_real_t pinf,
923 cs_real_t ratio,
924 cs_real_t hint)
925{
926 cs_real_t *a = bc_coeffs->a;
927 cs_real_t *b = bc_coeffs->b;
928 cs_real_t *af = bc_coeffs->af;
929 cs_real_t *bf = bc_coeffs->bf;
930
931 /* Gradient BCs */
932 b[f_id] = ratio;
933 a[f_id] = pinf;
934
935 /* Flux BCs */
936 af[f_id] = -hint * a[f_id];
937 bf[f_id] = hint * (1. - b[f_id]);
938}
939
940/*----------------------------------------------------------------------------*/
949/*----------------------------------------------------------------------------*/
950
951inline static void
953 (cs_lnum_t f_id,
954 cs_field_bc_coeffs_t *bc_coeffs,
955 cs_real_t dimp,
956 cs_real_t hint)
957
958{
959 cs_real_t *af = bc_coeffs->af;
960 cs_real_t *bf = bc_coeffs->bf;
961
962 /* Gradient BCs */
964 bc_coeffs,
965 dimp,
966 hint);
967
968 /* Flux BCs */
969 af[f_id] = 0.;
970 bf[f_id] = 0.;
971}
972
973/*----------------------------------------------------------------------------*/
984/*----------------------------------------------------------------------------*/
985
986inline static void
988 (cs_lnum_t f_id,
989 cs_field_bc_coeffs_t *bc_coeffs,
990 cs_real_t pinf,
991 cs_real_t ratio,
992 cs_real_t dimp)
993{
994 cs_real_t *a = bc_coeffs->a;
995 cs_real_t *b = bc_coeffs->b;
996 cs_real_t *af = bc_coeffs->af;
997 cs_real_t *bf = bc_coeffs->bf;
998
999 /* Gradient BCs */
1000 b[f_id] = ratio;
1001 a[f_id] = pinf;
1002
1003 /* Flux BCs */
1004 af[f_id] = dimp;
1005 bf[f_id] = 0.;
1006}
1007
1008/*----------------------------------------------------------------------------*/
1017/*----------------------------------------------------------------------------*/
1018
1019inline static void
1021 cs_field_bc_coeffs_t *bc_coeffs,
1022 cs_real_t hext,
1023 cs_real_t dimp)
1024{
1025 cs_real_t *a = bc_coeffs->a;
1026 cs_real_t *b = bc_coeffs->b;
1027 cs_real_t *af = bc_coeffs->af;
1028 cs_real_t *bf = bc_coeffs->bf;
1029
1030 /* Gradients BCs */
1031 a[f_id] = 0.;
1032 b[f_id] = 1.;
1033
1034 /* Flux BCs */
1035 af[f_id] = dimp;
1036 bf[f_id] = hext;
1037}
1038
1039/*----------------------------------------------------------------------------*/
1049/*----------------------------------------------------------------------------*/
1050
1051inline static void
1053 (cs_lnum_t f_id,
1054 cs_field_bc_coeffs_t *bc_coeffs,
1055 cs_real_t pimp,
1056 cs_real_t dimp)
1057{
1058 cs_real_t *a = bc_coeffs->a;
1059 cs_real_t *b = bc_coeffs->b;
1060 cs_real_t *af = bc_coeffs->af;
1061 cs_real_t *bf = bc_coeffs->bf;
1062
1063 /* Gradients BC */
1064 a[f_id] = pimp;
1065 b[f_id] = 0.;
1066
1067 /* Flux BCs */
1068 af[f_id] = dimp;
1069 bf[f_id] = 0.;
1070}
1071
1072/*----------------------------------------------------------------------------*/
1082/*----------------------------------------------------------------------------*/
1083
1084inline static void
1086 (cs_lnum_t f_id,
1087 cs_field_bc_coeffs_t *bc_coeffs,
1088 const cs_real_t pimpv[3],
1089 const cs_real_t qimpv[3])
1090{
1091 cs_real_3_t *a = (cs_real_3_t *)bc_coeffs->a;
1092 cs_real_33_t *b = (cs_real_33_t *)bc_coeffs->b;
1093 cs_real_3_t *af = (cs_real_3_t *)bc_coeffs->af;
1094 cs_real_33_t *bf = (cs_real_33_t *)bc_coeffs->bf;
1095
1096 for (int isou = 0; isou < 3; isou++) {
1097
1098 /* Gradient BCs */
1099 a[f_id][isou] = pimpv[isou];
1100 for (int jsou = 0; jsou < 3; jsou++)
1101 b[f_id][isou][jsou] = 0.0;
1102
1103 /* Flux BCs */
1104 af[f_id][isou] = qimpv[isou];
1105 for (int jsou = 0; jsou < 3; jsou++)
1106 bf[f_id][isou][jsou] = 0.0;
1107 }
1108}
1109
1110/*----------------------------------------------------------------------------*/
1120/*----------------------------------------------------------------------------*/
1121
1122inline static void
1124 (cs_real_t a[6],
1125 cs_real_t af[6],
1126 cs_real_t b[6][6],
1127 cs_real_t bf[6][6],
1128 const cs_real_t pimpts[6],
1129 const cs_real_t qimpts[6])
1130{
1131 for (int isou = 0; isou < 6; isou++) {
1132
1133 /* BS test on hextv ? if (abs(hextv[isou]) > cs_math_infinite_r * 0.5) */
1134
1135 /* Gradient BCs */
1136 a[isou] = pimpts[isou];
1137 for (int jsou = 0; jsou < 6; jsou++)
1138 b[isou][jsou] = 0.0;
1139
1140 /* Flux BCs */
1141 af[isou] = qimpts[isou];
1142 for (int jsou = 0; jsou < 6; jsou++)
1143 bf[isou][jsou] = 0.0;
1144 }
1145}
1146
1147/*----------------------------------------------------------------------------*/
1148
1150
1151#ifdef __cplusplus
1152
1153/*============================================================================
1154 * Public C++ function definitions
1155 *============================================================================*/
1156
1157/*----------------------------------------------------------------------------*/
1158/*
1159 * \brief Update face value for gradient and diffusion when solving
1160 * in increment.
1161 *
1162 * \param[in] ctx reference to dispatch context
1163 * \param[in] f pointer to field
1164 * \param[in] bc_coeffs boundary condition structure for the variable
1165 * \param[in] inc 0 if an increment, 1 otherwise
1166 * \param[in] halo_type halo type (extended or not)
1167 * \param[in] var variable values at cell centers
1168 * \param[in,out] var_ip boundary variable values at I' position
1169 * \param[in,out] var_f face values for the gradient computation
1170 * \param[in,out] var_f_lim face values for the gradient computation
1171 * (with limiter)
1172 * \param[in,out] var_f_d face values for the diffusion computation
1173 * \param[in,out] var_f_d_lim face values for the diffusion computation
1174 * (with limiter)
1175 */
1176/*----------------------------------------------------------------------------*/
1177
1178template <cs_lnum_t stride>
1179void
1181 (cs_dispatch_context &ctx,
1182 cs_field_t *f,
1183 const cs_field_bc_coeffs_t *bc_coeffs,
1184 const int inc,
1185 const cs_equation_param_t *eqp,
1186 const cs_real_t pvar[][stride],
1187 cs_real_t val_ip[][stride],
1188 cs_real_t val_f[][stride],
1189 cs_real_t val_f_lim[][stride],
1190 cs_real_t val_f_d[][stride],
1191 cs_real_t val_f_d_lim[][stride]);
1192
1193/*----------------------------------------------------------------------------*/
1194/*
1195 * \brief Update boundary coefficient face values for gradient and diffusion
1196 * when solving for a given field.
1197 *
1198 * \param[in] ctx reference to dispatch context
1199 * \param[in, out] f pointer to field
1200 * \param[in] pvar variable values at cell centers
1201 */
1202/*----------------------------------------------------------------------------*/
1203
1204template <cs_lnum_t stride>
1205void
1207 (cs_dispatch_context &ctx,
1208 cs_field_t *f,
1209 const cs_real_t pvar[][stride]);
1210
1211/*----------------------------------------------------------------------------*/
1221/*----------------------------------------------------------------------------*/
1222
1223void
1225 (cs_field_bc_coeffs_t *bc_coeffs,
1226 cs_lnum_t n_b_faces,
1227 cs_lnum_t dim,
1228 cs_alloc_mode_t amode,
1229 bool limiter);
1230
1231#endif /* cplusplus */
1232
1233/*----------------------------------------------------------------------------*/
1234
1235#endif /* __CS_BOUNDARY_CONDITIONS_SET_COEFFS_H__ */
void bft_error(const char *const file_name, const int line_num, const int sys_error_code, const char *const format,...)
Calls the error handler (set by bft_error_handler_set() or default).
Definition bft_error.cpp:193
void cs_boundary_conditions_ensure_bc_coeff_face_values_allocated(cs_field_bc_coeffs_t *bc_coeffs, cs_lnum_t n_b_faces, cs_lnum_t dim, cs_alloc_mode_t amode, bool limiter)
Allocate BC coefficients face values if needed.
Definition cs_boundary_conditions_set_coeffs.cpp:4485
void cs_boundary_conditions_update_bc_coeff_face_values(cs_dispatch_context &ctx, cs_field_t *f, const cs_field_bc_coeffs_t *bc_coeffs, const int inc, const cs_equation_param_t *eqp, const cs_real_t pvar[][stride], cs_real_t val_ip[][stride], cs_real_t val_f[][stride], cs_real_t val_f_lim[][stride], cs_real_t val_f_d[][stride], cs_real_t val_f_d_lim[][stride])
Update face value for gradient and diffusion when solving in increments.
Definition cs_boundary_conditions_set_coeffs.cpp:4138
void cs_boundary_conditions_set_generalized_sym_vector_aniso(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t pimpv[3], const cs_real_t qimpv[3], const cs_real_t hint[6], const cs_nreal_t normal[3])
Set generalized BC for an anisotropic symmetric vector for a given face.
Definition cs_boundary_conditions_set_coeffs.cpp:3956
static void cs_boundary_conditions_set_dirichlet_vector(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t pimpv[3], cs_real_t hint, const cs_real_t hextv[3])
Set Dirichlet BC for a vector for a given face.
Definition cs_boundary_conditions_set_coeffs.h:407
static void cs_boundary_conditions_set_neumann_scalar_hmg(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs)
Set homogeneous Neumann BC for a scalar for a given face.
Definition cs_boundary_conditions_set_coeffs.h:189
static void cs_boundary_conditions_set_affine_function_conv_neumann_diff_scalar(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, cs_real_t pinf, cs_real_t ratio, cs_real_t dimp)
Set Neumann BC for the convection operator, imposed flux for diffusion.
Definition cs_boundary_conditions_set_coeffs.h:988
static void cs_boundary_conditions_set_dirichlet_conv_neumann_diff_scalar(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, cs_real_t pimp, cs_real_t dimp)
Imposed value for the convection operator, imposed flux for diffusion, for a scalar.
Definition cs_boundary_conditions_set_coeffs.h:1053
static void cs_boundary_conditions_set_dirichlet_scalar(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, 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_set_coeffs.h:356
static void cs_boundary_conditions_set_dirichlet_conv_neumann_diff_vector(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t pimpv[3], const cs_real_t qimpv[3])
Imposed value for the convection operator, imposed flux for diffusion, for a vector.
Definition cs_boundary_conditions_set_coeffs.h:1086
static void cs_boundary_conditions_set_convective_outlet_tensor(cs_real_t a[6], cs_real_t af[6], cs_real_t b[6][6], cs_real_t bf[6][6], const cs_real_t pimpts[6], const cs_real_t cflts[6], cs_real_t hint)
Set convective outlet BC for a tensor for a given face.
Definition cs_boundary_conditions_set_coeffs.h:821
void cs_boundary_conditions_set_convective_outlet_scalar(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, cs_real_t pimp, cs_real_t cfl, cs_real_t hint)
Set convective oulet boundary condition for a scalar.
Definition cs_boundary_conditions_set_coeffs.cpp:3920
static void cs_boundary_conditions_set_neumann_vector(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t qimpv[3], cs_real_t hint)
Set Neumann BC for a scalar for a given face.
Definition cs_boundary_conditions_set_coeffs.h:218
void cs_boundary_conditions_set_coeffs_init(void)
Initialization of boundary condition arrays.
Definition cs_boundary_conditions_set_coeffs.cpp:3768
static void cs_boundary_conditions_set_neumann_vector_aniso(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t qimpv[3], const cs_real_t hint[6])
Set neumann BC for an anisotropic vector for a given face.
Definition cs_boundary_conditions_set_coeffs.h:260
static void cs_boundary_conditions_set_dirichlet_conv_neumann_diff_tensor(cs_real_t a[6], cs_real_t af[6], cs_real_t b[6][6], cs_real_t bf[6][6], const cs_real_t pimpts[6], const cs_real_t qimpts[6])
Imposed value for the convection operator, imposed flux for diffusion, for a tensor.
Definition cs_boundary_conditions_set_coeffs.h:1124
static void cs_boundary_conditions_set_affine_function_scalar(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, cs_real_t pinf, cs_real_t ratio, cs_real_t hint)
Set BC for an affine scalar function for a given face.
Definition cs_boundary_conditions_set_coeffs.h:920
static void cs_boundary_conditions_set_convective_outlet_vector_aniso(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t pimpv[3], const cs_real_t cflv[3], const cs_real_t hintt[6])
Set convective outlet BC for an anisotropic vector for a given face.
Definition cs_boundary_conditions_set_coeffs.h:865
void cs_boundary_conditions_set_coeffs(int nvar, int iterns, int isvhb, int itrale, int italim, int itrfin, int ineefl, int itrfup, int isostd[], cs_real_t visvdr[], cs_real_t hbord[], cs_real_t theipb[], int nftcdt)
Translation of the boundary conditions given by the user in a form that fits to the solver.
Definition cs_boundary_conditions_set_coeffs.cpp:866
static void cs_boundary_conditions_set_dirichlet_vector_aniso(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t pimpv[3], const cs_real_t hintt[6], const cs_real_t hextv[3])
Set Dirichlet BC for a vector for a given face with left anisotropic diffusion.
Definition cs_boundary_conditions_set_coeffs.h:494
static void cs_boundary_conditions_set_generalized_dirichlet_vector(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t pimpv[3], const cs_real_t qimpv[3], cs_real_t hint, const cs_nreal_t normal[3])
Set generalized Dirichlet BC for a vector for a given face.
Definition cs_boundary_conditions_set_coeffs.h:696
static void cs_boundary_conditions_set_generalized_sym_vector(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t pimpv[3], const cs_real_t qimpv[3], cs_real_t hint, const cs_nreal_t normal[3])
Set generalized BC for a symmetric vector for a given face.
Definition cs_boundary_conditions_set_coeffs.h:616
static void cs_boundary_conditions_set_convective_outlet_vector(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t pimpv[3], const cs_real_t cflv[3], cs_real_t hint)
Set convective outlet BC for a vector for a given face.
Definition cs_boundary_conditions_set_coeffs.h:775
static void cs_boundary_conditions_set_neumann_conv_h_neumann_diff_scalar(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, cs_real_t dimp, cs_real_t hint)
Set Neumann BC for the convection operator, zero flux for diffusion.
Definition cs_boundary_conditions_set_coeffs.h:953
static void cs_boundary_conditions_set_total_flux(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, cs_real_t hext, cs_real_t dimp)
Set total flux as a Robin condition.
Definition cs_boundary_conditions_set_coeffs.h:1020
static void cs_boundary_conditions_set_dirichlet_tensor(cs_real_t a[6], cs_real_t af[6], cs_real_t b[6][6], cs_real_t bf[6][6], const cs_real_t pimpts[6], cs_real_t hint, const cs_real_t hextts[6])
Set Dirichlet BC for a tensor for a given face.
Definition cs_boundary_conditions_set_coeffs.h:550
static void cs_boundary_conditions_set_neumann_tensor(cs_real_t a[6], cs_real_t af[6], cs_real_t b[6][6], cs_real_t bf[6][6], const cs_real_t qimpts[6], cs_real_t hint)
Set Neumann boundary conditions for a tensor for a given face.
Definition cs_boundary_conditions_set_coeffs.h:317
static void cs_boundary_conditions_set_neumann_scalar(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, cs_real_t qimp, cs_real_t hint)
Set Neumann BC for a scalar for a given face.
Definition cs_boundary_conditions_set_coeffs.h:160
void cs_boundary_conditions_set_generalized_dirichlet_vector_aniso(cs_lnum_t f_id, cs_field_bc_coeffs_t *bc_coeffs, const cs_real_t pimpv[3], const cs_real_t qimpv[3], const cs_real_t hint[6], const cs_nreal_t normal[3])
Set generalized Dirichlet BC for an anisotropic vector for a given face.
Definition cs_boundary_conditions_set_coeffs.cpp:4039
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition cs_defs.h:368
#define BEGIN_C_DECLS
Definition cs_defs.h:542
#define _(String)
Definition cs_defs.h:67
double cs_real_t
Floating-point value.
Definition cs_defs.h:342
#define END_C_DECLS
Definition cs_defs.h:543
double cs_nreal_t
Definition cs_defs.h:346
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
const cs_real_t cs_math_infinite_r
static CS_F_HOST_DEVICE void cs_math_sym_33_3_product(const cs_real_t m[6], const cs_real_t v[3], cs_real_t *restrict mv)
Compute the product of a symmetric matrix of 3x3 real values by a vector of 3 real values....
Definition cs_math.h:983
static CS_F_HOST_DEVICE cs_real_t cs_math_fmax(cs_real_t x, cs_real_t y)
Compute the max value of two real values.
Definition cs_math.h:503
cs_alloc_mode_t
Definition cs_mem.h:50
Set of parameters to handle an unsteady convection-diffusion-reaction equation with term sources.
Definition cs_equation_param.h:193
Field boundary condition descriptor (for variables)
Definition cs_field.h:121
cs_real_t * b
Definition cs_field.h:131
cs_real_t * a
Definition cs_field.h:130
cs_real_t * bf
Definition cs_field.h:133
cs_real_t * af
Definition cs_field.h:132
Field descriptor.
Definition cs_field.h:158