TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Coalescence_bulles_1groupe_PolyMAC_MPFA.cpp
1/****************************************************************************
2* Copyright (c) 2021, 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 <Coalescence_bulles_1groupe_PolyMAC_MPFA.h>
17#include <Pb_Multiphase.h>
18#include <Champ_Elem_PolyMAC_MPFA.h>
19#include <Milieu_composite.h>
20#include <Op_Diff_Turbulent_PolyMAC_MPFA_Face.h>
21#include <Viscosite_turbulente_base.h>
22#include <Matrix_tools.h>
23#include <Array_tools.h>
24#include <Coalescence_bulles_1groupe_base.h>
25#include <Domaine_PolyMAC_MPFA.h>
26#include <Champ_Face_base.h>
27#include <math.h>
28
29Implemente_instanciable(Coalescence_bulles_1groupe_PolyMAC_MPFA, "Coalescence_bulles_1groupe_elem_PolyMAC_MPFA", Source_base);
30
31
33{
34 return os;
35}
36
38{
39 Param param(que_suis_je());
40 param.ajouter("beta_k", &beta_k_);
41 param.lire_avec_accolades_depuis(is);
42
43
44 const Pb_Multiphase *pbm = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr;
45
46 if (!pbm || pbm->nb_phases() == 1)
47 Process::exit(que_suis_je() + " : not needed for single-phase flow!");
48
49 for (int n = 0; n < pbm->nb_phases(); n++) //recherche de n_l, n_g : phase {liquide,gaz}_continu en priorite
50 if (pbm->nom_phase(n).debute_par("liquide")
51 && (n_l < 0 || pbm->nom_phase(n).finit_par("continu")))
52 n_l = n;
53
54 if (n_l < 0)
55 Process::exit(que_suis_je() + " : liquid phase not found!");
56
57 if (pbm->has_correlation("Coalescence_bulles_1groupe")) correlation_ = pbm->get_correlation("Coalescence_bulles_1groupe"); //correlation fournie par le bloc correlation
58 else Correlation_base::typer_lire_correlation(correlation_, *pbm, "Coalescence_bulles_1groupe", is); //sinon -> on la lit
59
60 return is;
61}
62
63void Coalescence_bulles_1groupe_PolyMAC_MPFA::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
64{
65 const Domaine_PolyMAC_MPFA& domaine = ref_cast(Domaine_PolyMAC_MPFA, equation().domaine_dis());
66 const int ne = domaine.nb_elem(), ne_tot = domaine.nb_elem_tot(), N = equation().inconnue().valeurs().line_size();
67
68 for (auto &&n_m : matrices)
69 if (n_m.first == "alpha" || n_m.first == "k" || n_m.first == "tau" || n_m.first == "omega")
70 {
71 Matrice_Morse& mat = *n_m.second;
72 Matrice_Morse mat2;
73 const DoubleTab& dep = equation().probleme().get_champ(n_m.first.c_str()).valeurs();
74 const int nc = dep.dimension_tot(0);
75 const int M = dep.line_size();
76 Stencil sten(0, 2);
77
78 if (n_m.first == "alpha")
79 for (int e = 0; e < ne; e++)
80 for (int n = 0; n < N; n++)
81 sten.append_line(N * e + n, N * e + n);
82
83 if (n_m.first == "k" || n_m.first == "tau" || n_m.first == "omega") // N <= M
84 for (int e = 0; e < ne; e++)
85 for (int n = 0; n < N; n++)
86 for (int k = 0; k < M; k++)
87 sten.append_line(N * e + n, M * e + k);
88
89 Matrix_tools::allocate_morse_matrix(N * ne_tot, M * nc, sten, mat2);
90 mat.nb_colonnes() ? mat += mat2 : mat = mat2;
91 }
92}
93
94void Coalescence_bulles_1groupe_PolyMAC_MPFA::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
95{
96 const Pb_Multiphase& pbm = ref_cast(Pb_Multiphase, equation().probleme());
97 const Domaine_PolyMAC_MPFA& domaine = ref_cast(Domaine_PolyMAC_MPFA, equation().domaine_dis());
98 const DoubleVect& pe = equation().milieu().porosite_elem(), &ve = domaine.volumes();
99
100 const DoubleTab& inco = equation().inconnue().valeurs();
101 const DoubleTab& d_bulles_p = equation().probleme().get_champ("diametre_bulles").passe();
102 const DoubleTab& alpha = pbm.equation_masse().inconnue().valeurs();
103 const DoubleTab& press_p = ref_cast(QDM_Multiphase,pbm.equation_qdm()).pression().passe();
104 const DoubleTab& temp_p = pbm.equation_energie().inconnue().passe();
105 const DoubleTab& rho_p = equation().milieu().masse_volumique().passe();
106 const DoubleTab& nu_p = equation().probleme().get_champ("viscosite_cinematique").passe();
107 const DoubleTab *tab_k_p = equation().probleme().has_champ("k") ? &equation().probleme().get_champ("k").passe() : nullptr;
108 const DoubleTab *tab_k = equation().probleme().has_champ("k") ? &equation().probleme().get_champ("k").valeurs() : nullptr;
109 const DoubleTab *tau = equation().probleme().has_champ("tau") ? &equation().probleme().get_champ("tau").valeurs() : nullptr;
110 const DoubleTab *omega = equation().probleme().has_champ("omega") ? &equation().probleme().get_champ("omega").valeurs() : nullptr ;
111
112 const Milieu_composite& milc = ref_cast(Milieu_composite, equation().milieu());
113 const int N = pbm.nb_phases();
114 const int Nk = (tab_k) ? (*tab_k).line_size() : -1;
115 const int Np = equation().probleme().get_champ("pression").valeurs().line_size();
116
117 // Models use epsilon but with omega and tau we induce new variations of tau/omega and k
118 std::string Type_diss = "other"; // omega, tau or other dissipation
119 if (tau)
120 Type_diss = "tau";
121 else if (omega)
122 Type_diss = "omega";
123
124 DoubleTrav epsilon(alpha);
125 const Op_Diff_Turbulent_PolyMAC_MPFA_Face& op_diff = ref_cast(Op_Diff_Turbulent_PolyMAC_MPFA_Face, equation().probleme().equation(0).operateur(0).l_op_base());
126 const Viscosite_turbulente_base& visc_turb = ref_cast(Viscosite_turbulente_base, op_diff.correlation());
127 visc_turb.eps(epsilon); // Epsilon is in the past
128 double limiter = visc_turb.limiteur();
129 double dh = 0;
130
131 Matrice_Morse *Ma = matrices.count("alpha") ? matrices.at("alpha") : nullptr;
132 Matrice_Morse *Mk = matrices.count("k") ? matrices.at("k") : nullptr;
133 Matrice_Morse *Mtau = matrices.count("tau") ? matrices.at("tau") : nullptr;
134 Matrice_Morse *Momega = matrices.count("omega") ? matrices.at("omega") : nullptr;
135 Matrice_Morse *Mai = matrices.count("interfacial_area") ? matrices.at("interfacial_area") : nullptr;
136
137 const int cR = (rho_p.dimension_tot(0) == 1), cM = (nu_p.dimension_tot(0) == 1);
138 const int D = dimension;
139 DoubleTrav a_l(N), p_l(N), T_l(N), rho_l(N), nu_l(N), sigma_l(N,N), dv(N, N), d_bulles_l(N), eps_l(Nk), k_l(Nk), coeff(N, N); //arguments pour coeff
140 const Coalescence_bulles_1groupe_base& correlation_coal = ref_cast(Coalescence_bulles_1groupe_base, correlation_.valeur());
141
142 // fill velocity at elem tab
143 DoubleTab pvit_elem(0, N * D);
144 domaine.domaine().creer_tableau_elements(pvit_elem);
145 const Champ_Face_base& ch_vit = ref_cast(Champ_Face_base,ref_cast(Pb_Multiphase, equation().probleme()).equation_qdm().inconnue());
146 ch_vit.get_elem_vector_field(pvit_elem);
147
148 const double fac_sec = 1.e4 ; // numerical security
149 const double alpha_min = 1.e-3 ; // to avoid numerical problems
150
151 /* elements */
152 for (int e = 0; e < domaine.nb_elem(); e++)
153 {
154 for (int n = 0; n < N; n++)
155 {
156 a_l(n) = alpha(e, n); // to further implicit the source term
157 p_l(n) = press_p(e, n * (Np > 1));
158 T_l(n) = temp_p(e, n);
159 rho_l(n) = rho_p(!cR * e, n);
160 nu_l(n) = nu_p(!cM * e, n);
161
162 for (int k = 0; k < N; k++)
163 if(milc.has_interface(n, k))
164 {
165 Interface_base& sat = milc.get_interface(n, k);
166 sigma_l(n, k) = sat.sigma(temp_p(e, n), press_p(e, n * (Np > 1)));
167 }
168 d_bulles_l(n) = d_bulles_p(e, n);
169 }
170
171 for (int n = 0; n < Nk; n++)
172 {
173 eps_l(n) = epsilon(e, n) ;
174 k_l(n) = (tab_k_p) ? (*tab_k_p)(e, n) : 0;
175 }
176
177 dv = 0;
178 for (int d = 0; d < D; d++)
179 for (int n = 0; n < N; n++)
180 for (int k = 0 ; k < N ; k++)
181 dv(n, k) += (pvit_elem(e, N * d + n) - ((n != k) ? pvit_elem(e, N * d + k) : 0)) * (pvit_elem(e, N * d + n) - ((n != k) ? pvit_elem(e, N * d + k) : 0)); // nv(n,n) = ||v(n)||, nv(n, k!=n) = ||v(n)-v(k)||
182
183 for (int n = 0; n < N; n++)
184 for (int k = 0 ; k < N ; k++)
185 dv(n, k) = sqrt(dv(n, k));
186
187 // Get correlations-------------------------------------------------------------------------------------------------------------------------------------------------------
188 correlation_coal.coefficient(a_l, p_l, T_l, rho_l, nu_l, sigma_l, dh, dv, d_bulles_l, eps_l, k_l, coeff); // Semi-Explicit coeff : alpha is implicit
189
190 for (int k = 0 ; k < N ; k++)
191 {
192 double eps_valeurs {0};
193 if (Type_diss == "tau")
194 eps_valeurs = beta_k_ * ((*tab_k)(e, n_l)>1.e-8
195 ? (*tab_k)(e, n_l)*(*tab_k)(e, n_l)/ std::max((*tab_k)(e, n_l) * (*tau)(e, n_l), limiter * nu_p(e, n_l)) : 0);
196 else if (Type_diss == "omega")
197 eps_valeurs = beta_k_ * ((*tab_k)(e, n_l)*(*omega)(e, n_l)) ;
198 else
199 eps_valeurs = epsilon(e, n_l);
200
201 // Recuring functions for source terms
202
203 const double cbrt_6 = std::cbrt(6.);
204 const double factor_tmp = M_PI/(3*cbrt_6*cbrt_6*cbrt_6*cbrt_6*cbrt_6);
205 const double fac = (alpha(e, k)>alpha_min) ? pe(e) * ve(e) * factor_tmp * coeff(k, n_l) : 0. ;
206 const double dalpha_fac = (alpha(e, k)>alpha_min) ? pe(e) * ve(e) * factor_tmp * coeff(n_l, k) : 0. ;
207
208 const double ai = std::max(inco(e, k), 0.) ; //security inco negative
209 const double cbrt_ai = std::cbrt(ai);
210 const double ai_5_over3 = cbrt_ai*cbrt_ai*cbrt_ai*cbrt_ai*cbrt_ai ;
211
212 const double alpha_1_over3 = std::cbrt(alpha(e, k)) ;
213 const double eps_1_over3 = std::cbrt(eps_valeurs) ;
214
215 // Fill the matrix
216 secmem(e , k) += (fac > 0. ) ? fac * alpha_1_over3 * ai_5_over3 * eps_1_over3 : 0. ; // (alpha, ai, epsilon) implicit dependance
217
218 if (Ma)
219 (*Ma)(N * e + k , N * e + k) -= (fac > 0. )
220 ? fac * 1./3. / std::min(alpha_1_over3 * alpha_1_over3,fac_sec) * ai_5_over3 * eps_1_over3 + dalpha_fac * alpha_1_over3 * ai_5_over3 * eps_1_over3
221 : 0. ;
222
223 if (Mai)
224 (*Mai)(N * e + k , N * e + k) -= (fac > 0. )
225 ? fac * alpha_1_over3 * 5./3. * std::cbrt(ai) * std::cbrt(ai) * eps_1_over3
226 : 0. ;
227
228 if (Type_diss == "tau")//-------------------------------------------------------------------------------------------------------------------------------------------
229 {
230 if ((*tab_k)(e, n_l) * (*tau)(e, n_l) > limiter * nu_p(e, n_l)) // derivative according to k due to epsilon
231 {
232 if (Mk)
233 (*Mk)(N * e + k, Nk * e + n_l) -= (fac > 0. )
234 ? fac * alpha_1_over3 * ai_5_over3 * 1./3. * std::cbrt(beta_k_) / std::min(std::cbrt((*tab_k)(e, n_l)) * std::cbrt((*tab_k)(e, n_l)), fac_sec) / std::min(std::cbrt((*tau)(e, n_l)),fac_sec)
235 : 0.;
236
237 if (Mtau)
238 (*Mtau)(N * e + k, Nk * e + n_l) -= (fac > 0. )
239 ? fac * alpha_1_over3 * ai_5_over3 *-1./3. * std::cbrt(beta_k_) * std::cbrt((*tab_k)(e, n_l)) / std::min(std::cbrt((*tau)(e, n_l)) * std::cbrt((*tau)(e, n_l)) * std::cbrt((*tau)(e, n_l)) * std::cbrt((*tau)(e, n_l)), fac_sec)
240 : 0.;
241 }
242 else
243 {
244 if (Mk)
245 (*Mk)(N * e + k, Nk * e + n_l) -= (fac > 0. )
246 ? fac * alpha_1_over3 * ai_5_over3 * 1./3. * std::cbrt(beta_k_) / std::min(std::cbrt((*tab_k)(e, n_l)),fac_sec) / std::min(std::cbrt(limiter * nu_p(e, n_l)), fac_sec)
247 : 0. ;
248 }
249 }
250
251 if (Type_diss == "omega")
252 {
253 if (Momega)
254 (*Momega)(N * e + k , Nk * e + n_l) -= (fac > 0. )
255 ? fac * alpha_1_over3 * ai_5_over3 * 1./3. * std::cbrt(beta_k_) * std::cbrt((*tab_k)(e, n_l)) / std::min(std::cbrt((*omega)(e, n_l)) * std::cbrt((*omega)(e, n_l)),fac_sec)
256 : 0.;
257
258 if (Mk)
259 (*Mk)(N * e + k , Nk * e + n_l) -= (fac > 0. )
260 ? fac * alpha_1_over3 * ai_5_over3 * 1./3. * std::cbrt(beta_k_) / std::min(std::cbrt((*tab_k)(e, n_l)) * std::cbrt((*tab_k)(e, n_l)), fac_sec) * std::cbrt((*omega)(e, n_l))
261 : 0.;
262 }
263 }
264 }
265}
virtual DoubleTab & get_elem_vector_field(DoubleTab &, bool passe=false) const
DoubleTab & passe(int i=1) override
Renvoie les valeurs du champs a l'instant t-i.
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
virtual DoubleTab & valeurs()=0
virtual DoubleTab & passe(int i=1)
Definition Champ_Proto.h:50
classe Coalescence_bulles_1groupe_PolyMAC_MPFA
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl={}) const override
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
virtual void coefficient(const DoubleTab &alpha, const DoubleTab &p, const DoubleTab &T, const DoubleTab &rho, const DoubleTab &nu, const DoubleTab &sigma, double Dh, const DoubleTab &ndv, const DoubleTab &d_bulles, const DoubleTab &eps, const DoubleTab &k_turb, DoubleTab &coeff) const =0
static void typer_lire_correlation(OWN_PTR(Correlation_base)&, const Probleme_base &, const Nom &, Entree &)
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
virtual const Champ_Inc_base & inconnue() const =0
Probleme_base & probleme()
Renvoie le probleme associe a l'equation.
double sigma(const double T, const double P) const
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
int nb_colonnes() const override
Return local number of columns (=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)
DoubleVect & porosite_elem()
Definition Milieu_base.h:58
virtual const Champ_base & masse_volumique() const
Renvoie la masse volumique du milieu.
Classe Milieu_composite Cette classe represente un fluide reel ainsi que.
bool has_interface(int k, int l) const
Interface_base & get_interface(int k, int l) const
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
virtual int debute_par(const char *const n) const
Definition Nom.cpp:319
static int dimension
Definition Objet_U.h:99
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
: class Op_Diff_Turbulent_PolyMAC_MPFA_Face
const Correlation_base & correlation() const
classe Pb_Multiphase Cette classe represente un probleme de thermohydraulique multiphase de type "3*N...
virtual Equation_base & equation_qdm()
virtual Equation_base & equation_energie()
const Nom & nom_phase(int i) const
int nb_phases() const
virtual Equation_base & equation_masse()
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const 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 exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
classe QDM_Multiphase Cette classe porte les termes de l'equation de la dynamique
Classe de base des flux de sortie.
Definition Sortie.h:52
classe Source_base Un objet Source_base est un terme apparaissant au second membre d'une
Definition Source_base.h:42
_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
classe Viscosite_turbulente_base correlations de viscosite turbulente decrivant le tenseur de Reynold...
virtual void eps(DoubleTab &eps) const =0