TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Coloc_Operator_tools.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Coloc_Operator_tools_included
17#define Coloc_Operator_tools_included
18
19#include <algorithm>
20#include <cmath>
21
22inline void compute_hll_bounds(const DoubleTab& vit_n, const DoubleTab& c, const int f, const int el, const int er, const int nb_phases, double& Sm, double& Sp)
23{
24 Sm = 0.;
25 Sp = 0.;
26 for (int n = 0; n < nb_phases; n++)
27 {
28 const double un_l = vit_n(f, n);
29 const double un_r = vit_n(f, n + nb_phases);
30 const double c_l = c(el, n), c_r = c(er, n);
31 const double Sm_k = std::min(un_l - c_l, un_r - c_r);
32 const double Sp_k = std::max(un_l + c_l, un_r + c_r);
33
34 Sm = std::min(Sm, std::min(0.0, Sm_k));
35 Sp = std::max(Sp, std::max(0.0, Sp_k));
36 }
37}
38
39inline double compute_rusanov_speed(const DoubleTab& vit_n, const DoubleTab& c, const int f, const int el, const int er, const int n, const int nb_phases)
40{
41 const double un_l = vit_n(f, n);
42 const double un_r = vit_n(f, n + nb_phases);
43 const double c_l = c(el, n), c_r = c(er, n);
44 double s = std::max(fabs(un_l - c_l), fabs(un_l + c_l));
45
46 s = std::max(s, std::max(fabs(un_r - c_r), fabs(un_r + c_r)));
47 return s;
48}
49
50inline void compute_non_conservative_hll_left_bounds(const DoubleTab& vit_n, const DoubleTab& c, const int f, const int el, const int er,
51 const int m, const int n, const int nb_phases, double& Sm, double& Sp, double& un)
52{
53 int k = m; // index pressure
54 double un_l = vit_n(f, k);
55 double un_r = vit_n(f, k + nb_phases);
56 double c_l = c(el, k);
57 double c_r = c(er, k);
58 const double Sm1 = std::min(un_l - c_l, un_r - c_r);
59 const double Sp1 = std::max(un_l + c_l, un_r + c_r);
60
61 k = n; // index velocity
62 un_l = vit_n(f, k);
63 un_r = vit_n(f, k + nb_phases);
64 c_l = c(el, k);
65 c_r = c(er, k);
66 const double Sm2 = std::min(un_l - c_l, un_r - c_r);
67 const double Sp2 = std::max(un_l + c_l, un_r + c_r);
68
69 Sm = std::min(0.0, std::min(Sm1, Sm2));
70 Sp = std::max(0.0, std::max(Sp1, Sp2));
71 un = un_l;
72}
73
74inline void compute_non_conservative_hll_right_bounds(const DoubleTab& vit_n, const DoubleTab& c, const int f, const int el, const int er,
75 const int m, const int n, const int nb_phases, double& Sm, double& Sp, double& un)
76{
77 int k = m; // index pressure
78 double un_r = -vit_n(f, k);
79 double un_l = -vit_n(f, k + nb_phases);
80 double c_l = c(er, k);
81 double c_r = c(el, k);
82 const double Sm1 = std::min(un_l - c_l, un_r - c_r);
83 const double Sp1 = std::max(un_l + c_l, un_r + c_r);
84
85 k = n; // index velocity
86 un_r = -vit_n(f, k);
87 un_l = -vit_n(f, k + nb_phases);
88 c_l = c(er, k);
89 c_r = c(el, k);
90 const double Sm2 = std::min(un_l - c_l, un_r - c_r);
91 const double Sp2 = std::max(un_l + c_l, un_r + c_r);
92
93 Sm = std::min(0.0, std::min(Sm1, Sm2));
94 Sp = std::max(0.0, std::max(Sp1, Sp2));
95 un = un_l;
96}
97
98#endif /*Coloc_Operator_tools_included*/