TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Op_Evanescence_Homogene_Face_base.cpp
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#include <Op_Evanescence_Homogene_Face_base.h>
17#include <Viscosite_turbulente_base.h>
18#include <Vitesse_relative_base.h>
19#include <Gravite_Multiphase.h>
20#include <Milieu_composite.h>
21#include <Champ_Face_base.h>
22#include <Champ_Uniforme.h>
23#include <Pb_Multiphase.h>
24#include <Matrix_tools.h>
25#include <Domaine_VF.h>
26#include <Param.h>
27#include <SETS.h>
28
29Implemente_base(Op_Evanescence_Homogene_Face_base,"Op_Evanescence_Homogene_Face_base",Operateur_Evanescence_base);
30
32
34{
35 Param param(que_suis_je());
36 param.ajouter("alpha_res", &alpha_res_, Param::REQUIRED);
37 param.ajouter("alpha_res_min", &alpha_res_min_);
38 param.lire_avec_accolades_depuis(is);
39
40 Pb_Multiphase& pbm = ref_cast(Pb_Multiphase, equation().probleme());
41 if (pbm.has_correlation("Vitesse_relative") && !pbm.has_correlation("gravite")) Process::exit(que_suis_je() + " : you must define a multiphase gravity field if you want a drift flux!!");
42 if (pbm.has_correlation("Vitesse_relative") && ref_cast(Vitesse_relative_base, pbm.get_correlation("Vitesse_relative")).needs_vort()) pbm.creer_champ("vorticite");
43
44 return is;
45}
46
47void Op_Evanescence_Homogene_Face_base::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
48{
49 const Champ_Face_base& ch = ref_cast(Champ_Face_base, equation().inconnue());
50 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
51 const DoubleTab& inco = ch.valeurs();
52 const IntTab& fcl = ch.fcl();
53
54 /* we must be able to add / subtract equations between components */
55 int i, f, n, N = inco.line_size();
56 if (N == 1) return; //no evanescence in single-phase flow!
57 for (auto &&n_m : matrices)
58 if (n_m.second->nb_colonnes())
59 {
60 Stencil sten(0, 2);
61
62
63 std::set<int> idx;
64 Matrice_Morse& mat = *n_m.second, mat2;
65 /* face equations: only those computed */
66 for (f = 0; f < domaine.nb_faces(); f++, idx.clear())
67 if (fcl(f, 0) < 2)
68 {
69 for (i = N * f, n = 0; n < N; n++, i++)
70 for (auto j = mat.get_tab1()(i) - 1; j < mat.get_tab1()(i + 1) - 1; j++)
71 idx.insert(mat.get_tab2()(j) - 1);
72 for (i = N * f, n = 0; n < N; n++, i++)
73 for (auto &&c : idx)
74 if (c >= 0)
75 sten.append_line(i, c);
76 }
77 else if (n_m.first == ch.le_nom().getString()) /* CLs a valeur imposee : diagonale */
78 for (n = 0, i = N * f; n < N; n++, i++) sten.append_line(i, i);
79
80 /* equations aux elements si aux */
81 dimensionner_blocs_aux(idx, sten, mat);
82
84 mat = mat2; //to force the ordering of coefficients in the matrix (speeds up row-by-row operations)
85 }
86}
87
88void Op_Evanescence_Homogene_Face_base::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
89{
90
91 const Pb_Multiphase& pbm = ref_cast(Pb_Multiphase, equation().probleme());
92 const bool reso_en_T = pbm.resolution_en_T();
93 const Milieu_composite& milc = ref_cast(Milieu_composite, equation().milieu());
94 const Champ_Face_base& ch = ref_cast(Champ_Face_base, equation().inconnue());
95 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
96 const IntTab& f_e = domaine.face_voisins(), &fcl = ch.fcl();
97 const DoubleTab& inco = ch.valeurs(), &vfd = domaine.volumes_entrelaces_dir(),
98 &alpha = ref_cast(Pb_Multiphase, equation().probleme()).equation_masse().inconnue().passe(),
99 &rho = equation().milieu().masse_volumique().passe(),
100 &temp_ou_enth = ref_cast(Pb_Multiphase, equation().probleme()).equation_energie().inconnue().passe(),
101 &press = ref_cast(QDM_Multiphase, ref_cast(Pb_Multiphase, equation().probleme()).equation_qdm()).pression().passe(),
102 &mu = ref_cast(Milieu_composite, equation().milieu()).viscosite_dynamique().passe(),
103 *d_bulles = (equation().probleme().has_champ("diametre_bulles")) ? &equation().probleme().get_champ("diametre_bulles").valeurs() : nullptr,
104 *k_turb = (equation().probleme().has_champ("k")) ? &equation().probleme().get_champ("k").passe() : nullptr,
105 *gravity = (equation().probleme().has_champ("gravite")) ? &equation().probleme().get_champ("gravite").valeurs() : nullptr ;
106
107 const DoubleVect& vf = domaine.volumes_entrelaces(), &dh_e = milc.diametre_hydraulique_elem();
108 int e, f, k, l, n, m, N = inco.line_size(), Nk = (k_turb) ? (*k_turb).line_size() : 0, d, D = dimension, cR = (rho.dimension_tot(0) == 1), cM = (mu.dimension_tot(0) == 1), Np = press.line_size(),
109 iter = sub_type(SETS, equation().schema_temps()) ? 0 * ref_cast(SETS, equation().schema_temps()).iteration_ : 0;
110
111 if (N == 1) return; //no evanescence in single-phase flow!
112
113 double a_eps = alpha_res_, a_eps_min = alpha_res_min_, a_m, a_max; //threshold for triggering evanescence treatment
114
115 /* search for evanescent phases and treatment of right-hand sides */
116 IntTrav maj(inco.dimension_tot(0)); //maj(i): dominant phase for row i
117 DoubleTrav coeff(inco.dimension_tot(0), inco.line_size(), 2); //coeff(i, n, 0/1): coefficient to apply to the existing equation / to the eq. "inco = v_maj"
118 Matrice_Morse& mat_diag = *matrices.at(ch.le_nom().getString());
119
120 DoubleTab dvr_face(domaine.nb_faces(), N, N, N); // Derivative of vr(n,k) at f with respect to phase l; for now always along d2=d
121 // Carried along because someone separated the matrix loop from the right-hand-side loop
122
123 /* compute the drift velocity: retrieve the required intermediate quantities */
126 out.vr.resize(N, N, D), out.dvr.resize(N, N, D, N*D);
127 const Vitesse_relative_base* correlation_vd = pbm.has_correlation("vitesse_relative") ? &ref_cast(Vitesse_relative_base, pbm.get_correlation("vitesse_relative")) : nullptr;
128 DoubleTab gradAlpha, vort, nut;
129 const int is_turb = ref_cast(Operateur_Diff_base, ref_cast(QDM_Multiphase, pbm.equation_qdm()).operateur_diff().l_op_base()).is_turb();
130 if (correlation_vd)
131 {
132 in.alpha.resize(N), in.rho.resize(N), in.mu.resize(N), in.d_bulles.resize(N), in.k.resize(N), in.nut.resize(N), in.v.resize(D, N), in.sigma.resize(N*(N-1)/2), in.g.resize(D);
133 if (correlation_vd->needs_grad_alpha())
134 {
135 gradAlpha.resize(domaine.nb_faces(), D, N);
136 calc_grad_alpha_faces(gradAlpha);
137 in.gradAlpha.resize(D, N);
138 }
139 if (correlation_vd->needs_vort())
140 {
141 vort.resize(domaine.nb_faces(), D, N);
142 calc_vort_faces(vort);
143 in.vort.resize(D, N);
144 }
145 if (is_turb)
146 {
147 nut.resize(domaine.nb_elem_tot(), N);
148 ref_cast(Viscosite_turbulente_base, (*ref_cast(Operateur_Diff_base, equation().operateur(0).l_op_base()).correlation_viscosite_turbulente())).eddy_viscosity(nut); //filled by the correlation
149 }
150 }
151
152 for (f = 0; f < domaine.nb_faces(); f++)
153 if (fcl(f, 0) < 2)
154 {
155 /* dominant phase: with interpolated alpha by default, with upwind alpha for SETS / ICE iterations */
156 for (a_max = 0, k = -1, n = 0; n < N; n++)
157 {
158 if (iter) a_m = alpha(f_e(f, f_e(f, 1) >= 0 && inco(f, n) < 0), n);
159 else
160 {
161 int i;
162 for (a_m = 0, i = 0; i < 2; i++)
163 if ((e = f_e(f, i)) >= 0)
164 a_m += vfd(f, i) / vf(f) * alpha(e, n);
165 }
166 if (a_m > a_max) k = n, a_max = a_m;
167 }
168 if (k >= 0) maj(f) = k;
169 else abort();
170
171 if (correlation_vd)
172 {
173 for (n = 0; n < N; n++)
174 for (d = 0; d < D; d++) in.v(d, n) = inco(f, n) * domaine.face_normales(f, d) / domaine.face_surfaces(f);
175 int i;
176 for (in.alpha = 0, in.rho = 0, in.mu = 0, in.d_bulles = 0, in.k = 0, in.nut = 0, in.dh = 0, in.g = 0, i = 0; i < 2 && (e = f_e(f, i)) >= 0; i++)
177 {
178 in.dh += vfd(f, i) / vf(f) * dh_e(e); // should not be in the loop on N below.
179 for (n = 0; n < N; n++)
180 {
181 in.alpha(n) += vfd(f, i) / vf(f) * alpha(e, n);
182 in.rho(n) += vfd(f, i) / vf(f) * rho(!cR * e, n);
183 in.mu(n) += vfd(f, i) / vf(f) * mu(!cM * e, n);
184 in.d_bulles(n)+=vfd(f, i) / vf(f) *((d_bulles) ? (*d_bulles)(e, n) : -1.) ;
185 for (m = n+1; m < N; m++)
186 if (milc.has_interface(n, m))
187 {
188 const int ind_trav = (n*(N-1)-(n-1)*(n)/2) + (m-n-1); // upper triangular matrix indexing!
189 Interface_base& sat = milc.get_interface(n, m);
190 in.sigma(ind_trav) = reso_en_T ? sat.sigma(temp_ou_enth(e, n), press(e, n * (Np > 1))) : sat.sigma_h(temp_ou_enth(e, n), press(e, n * (Np > 1)));
191 }
192 }
193 for (n = 0; n < Nk; n++) in.k(n) += vfd(f, i) / vf(f) *((k_turb) ? (*k_turb)(e, n) : -1.), in.nut(n) += vfd(f, i) / vf(f) *((is_turb) ? nut(e, n) : -1.) ;
194 for (d = 0; d < D; d++) in.g(d) += vfd(f, i) / vf(f) * (*gravity)(e,d);
195 if (correlation_vd->needs_grad_alpha())
196 for (n = 0; n < N; n++)
197 for (d = 0; d < D; d++) in.gradAlpha(d, n) = gradAlpha(f, d, n);
198 if (correlation_vd->needs_vort())
199 for (n = 0; n < N; n++)
200 for (d = 0; d < D; d++) in.vort(d, n) = vort(f, d, n);
201 }
202 correlation_vd->vitesse_relative(in, out);
203 }
204
205 /* evanescent phases: with upwind alpha. The dominant phase cannot be evanescent! */
206 for (n = 0; n < N; n++)
207 {
208 if (iter) a_m = alpha(f_e(f, f_e(f, 1) >= 0 && inco(f, n) < 0), n);
209 else
210 {
211 int i;
212 for (a_m = 0, i = 0; i < 2; i++)
213 if ((e = f_e(f, i)) >= 0)
214 a_m += vfd(f, i) / vf(f) * alpha(e, n);
215 }
216 if (n != k && a_m < a_eps)
217 {
218 coeff(f, n, 1) = mat_diag(N * f + k, N * f + k) * (coeff(f, n, 0) = std::min(std::max((a_eps - a_m) / (a_eps - a_eps_min), 0.), 1.));
219 DoubleTab vr_face(N, N);
220 for (d = 0; d < D; ++d)
221 {
222 vr_face(n, k) += out.vr(n, k, d) * domaine.face_normales(f, d) / domaine.face_surfaces(f);
223 for (l=0 ; l<N ; l++) dvr_face(f, n, k,l) += out.dvr(n, k, d, l*D+d) * domaine.face_normales(f, d) / domaine.face_surfaces(f);
224 }
225 double flux = coeff(f, n, 0) * secmem(f, n) + coeff(f, n, 1) * (inco(f, n) - inco(f, k) - vr_face(n, k));
226 secmem(f, k) += flux, secmem(f, n) -= flux;
227 }
228 }
229 }
230
231 /* lignes de matrices */
232 for (auto &&n_m : matrices)
233 if (n_m.second->nb_colonnes())
234 {
235 int diag = (n_m.first == ch.le_nom().getString()); //are we on the diagonal block?
236 Matrice_Morse& mat = *n_m.second;
237 /* faces */
238 for (f = 0; f < domaine.nb_faces(); f++)
239 if (fcl(f, 0) < 2)
240 for (n = 0; n < N; n++)
241 if (coeff(f, n, 0))
242 {
243 k = maj(f);
244 for (auto i = mat.get_tab1()(N * f + n) - 1, j = mat.get_tab1()(N * f + k) - 1; i < mat.get_tab1()(N * f + n + 1) - 1; i++, j++)
245 {
246 assert(mat.get_tab2()(i) == mat.get_tab2()(j));
247 int c = diag * mat.get_tab2()(i) - 1; //column index (shared by both rows thanks to dimensionner_blocs())
248 mat.get_set_coeff()(j) += coeff(f, n, 0) * mat.get_set_coeff()(i) - coeff(f, n, 1) * ((c == N * f + n) - (c == N * f + k));
249 mat.get_set_coeff()(i) += -coeff(f, n, 0) * mat.get_set_coeff()(i) + coeff(f, n, 1) * ((c == N * f + n) - (c == N * f + k));
250
251 mat.get_set_coeff()(j) += - coeff(f, n, 1) * ( - dvr_face(f, n, k, n)*(c == N * f + n) - dvr_face(f, n, k, n)*(c == N * f + k));
252 mat.get_set_coeff()(i) += + coeff(f, n, 1) * ( - dvr_face(f, n, k, n)*(c == N * f + n) - dvr_face(f, n, k, k)*(c == N * f + k));
253 }
254 }
255 }
256
257 // if auxiliary variables:
258 ajouter_blocs_aux(maj, coeff, matrices, secmem);
259}
260
262{
263 vort = 0;
264 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
265 const IntTab& f_e = domaine.face_voisins();
266 const DoubleVect& vf = domaine.volumes_entrelaces(), &fs = domaine.face_surfaces();
267 const DoubleTab& n_f = domaine.face_normales(), &vfd = domaine.volumes_entrelaces_dir();
268 const DoubleTab& vorticite = equation().probleme().get_champ("vorticite").passe(),
269 &grad_v = equation().probleme().get_champ("gradient_vitesse").passe();
270
271 const int D = dimension, N = vort.dimension_tot(2), nf = domaine.nb_faces(), nf_tot = domaine.nb_faces_tot();
272 int c, e, f, n, d, d2, n_l = 0;
273 DoubleTrav grad_l(D, D), scal_grad(D);
274
275 for (f = 0; f < nf; f++)
276 for (c = 0; c < 2; c++)
277 {
278 e = f_e(f, c);
279
280 if (e < 0)
281 continue;
282
283 if (D == 2)
284 {
285 for (n = 0; n < N; n++)
286 for (d = 0; d < D; d++)
287 vort(f, d, n) += vorticite(e, n) * vfd(f, c) / vf(f);
288 }
289 else
290 {
291 for (n = 0; n < N; n++)
292 for (d = 0; d < D; d++)
293 vort(f, d, n) += vorticite(e, N * d + n) * vfd(f, c) / vf(f);
294 }
295 }
296
297 if (D == 3)
298 for (f = 0; f < nf; f++)
299 {
300 grad_l = 0; // we fill grad_l so that grad_l(d, d2) = du_d/dx_d2 by averaging between both elements
301 for (d = 0; d < D; d++)
302 for (d2 = 0; d2 < D; d2++)
303 for (c = 0; c < 2 && (e = f_e(f, c)) >= 0; c++)
304 grad_l(d, d2) += vfd(f, c) / vf(f) * grad_v(nf_tot + D * e + d2, n_l * D + d);
305 //We replace the n_l components by the one calculated without interpolation to elements
306 scal_grad = 0; // scal_grad(d) = grad(u_d).n_f
307 for (d = 0; d < D; d++)
308 for (d2 = 0; d2 < D; d2++)
309 scal_grad(d) += grad_l(d, d2) * n_f(f, d2) / fs(f);
310 for (d = 0; d < D; d++)
311 for (d2 = 0; d2 < D; d2++)
312 grad_l(d, d2) += (grad_v(f, n_l * D + d) - scal_grad(d)) * n_f(f, d2) / fs(f);
313 // We calculate the local vorticity using this local gradient
314 vort(f, 0, n_l) = grad_l(2, 1) - grad_l(1, 2); // dUz/dy - dUy/dz
315 vort(f, 1, n_l) = grad_l(0, 2) - grad_l(2, 0); // dUx/dz - dUz/dx
316 vort(f, 2, n_l) = grad_l(1, 0) - grad_l(0, 1); // dUy/dx - dUx/dy
317 }
318}
const IntTab & fcl() const
DoubleTab & valeurs() override
Returns the array of field values at the current time.
virtual DoubleTab & valeurs()=0
virtual DoubleTab & passe(int i=1)
Definition Champ_Proto.h:50
class Domaine_VF
Definition Domaine_VF.h:44
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const Milieu_base & milieu() const =0
Probleme_base & probleme()
Returns the problem associated with the equation.
const Nom & le_nom() const override
Returns the name of the field.
double sigma_h(const double h, const double P) const
double sigma(const double T, const double P) const
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
const auto & get_tab2() const
const auto & get_tab1() const
auto & get_set_coeff()
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
int nb_lignes() const override
Return local number of lines (=size on the current proc).
static void allocate_morse_matrix(const int nb_lines, const int nb_columns, const Stencil &stencil, Matrice_Morse &matrix, const bool &attach_stencil_to_matrix=false)
virtual const Champ_base & masse_volumique() const
Returns the mass density of the medium (const version).
DoubleTab & diametre_hydraulique_elem()
Definition Milieu_base.h:70
Composite medium representing a multiphase fluid and its properties:
bool has_interface(int k, int l) const
Interface_base & get_interface(int k, int l) const
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
const std::string & getString() const
Definition Nom.h:92
static int dimension
Definition Objet_U.h:94
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Manages evanescence in a face-based equation (-> QDM).
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
virtual void dimensionner_blocs_aux(std::set< int > &, Stencil &, Matrice_Morse &) const
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl={}) const override
virtual void ajouter_blocs_aux(IntTrav &, DoubleTrav, matrices_t, DoubleTab &) const
virtual void calc_grad_alpha_faces(DoubleTab &) const
Operateur_Diff_base This class is the base of the hierarchy of operators representing.
Generic base class in the operator hierarchy for evanescence management terms.
@ REQUIRED
Definition Param.h:115
Multiphase thermohydraulics problem of type "3*N equations":
virtual bool resolution_en_T() const
virtual Equation_base & equation_qdm()
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
void creer_champ(const Motcle &motlu) override
const Champ_base & get_champ(const Motcle &nom) const override
int has_correlation(std::string nom_correlation) const
const Correlation_base & get_correlation(std::string nom_correlation) const
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Carries the terms of the momentum equation for multiphase flow without turbulence modelling.
SETS scheme (semi-implicit + stabilisation steps, TRACE-style).
Definition SETS.h:35
Base class for output streams.
Definition Sortie.h:52
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
int line_size() const
Definition TRUSTVect.tpp:67
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91
Turbulent viscosity correlations describing the Reynolds stress tensor R_{ij} = - <u'_i u'_j>.
Relative velocity correlations of the form ur = (v_k - v_l).
virtual bool needs_grad_alpha() const
virtual bool needs_vort() const
virtual void vitesse_relative(const input_t &input, output_t &output) const =0