TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Perte_Charge_VDF_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 <Multiplicateur_diphasique_base.h>
17#include <Fluide_Incompressible.h>
18#include <Perte_Charge_VDF_base.h>
19#include <Schema_Temps_base.h>
20#include <Milieu_composite.h>
21#include <Champ_Uniforme.h>
22#include <QDM_Multiphase.h>
23#include <Champ_Face_VDF.h>
24#include <Domaine_Cl_VDF.h>
25#include <Equation_base.h>
26#include <Pb_Multiphase.h>
27#include <Probleme_base.h>
28#include <Sous_Domaine.h>
29#include <Domaine_VDF.h>
30#include <Param.h>
31
32Implemente_base(Perte_Charge_VDF_base, "Perte_Charge_VDF_base", Perte_Charge_Gen);
33
34Sortie& Perte_Charge_VDF_base::printOn(Sortie& s) const { return s << que_suis_je() << finl; }
35
37
38void Perte_Charge_VDF_base::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
39{
40 const Domaine_VDF& domaine = ref_cast(Domaine_VDF, equation().domaine_dis());
41 const Pb_Multiphase *pbm = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr;
42 const Champ_Face_VDF& ch = ref_cast(Champ_Face_VDF, equation().inconnue());
43 const Champ_Don_base& dh = diam_hydr;
44
45 const DoubleTab& xp = domaine.xp(),&xv = domaine.xv(),
46 &vit = la_vitesse->valeurs(),
47 &pvit = la_vitesse->passe(),
48 &nu = le_fluide->viscosite_cinematique().valeurs(),
49 &vfd = domaine.volumes_entrelaces_dir(),
50 &mu = le_fluide->viscosite_dynamique().valeurs(),
51 &rho = le_fluide->masse_volumique().passe(),
52 *alp = pbm ? &pbm->equation_masse().inconnue().passe() : nullptr;
53
54 const DoubleVect& pe = le_fluide->porosite_elem(),& pf = le_fluide->porosite_face(),
55 &fs = domaine.face_surfaces(), &ve = domaine.volumes();
56
57 const Multiplicateur_diphasique_base *fmult = pbm && pbm->has_correlation("multiplicateur_diphasique") ?
58 &ref_cast(Multiplicateur_diphasique_base, pbm->get_correlation("multiplicateur_diphasique")) : nullptr;
59
60 const Sous_Domaine *pssz = sous_domaine ? &le_sous_domaine.valeur() : nullptr;
61
62 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins(), &fcl = ch.fcl();
63
64 Matrice_Morse *mat = matrices.count(ch.le_nom().getString()) ? matrices.at(ch.le_nom().getString()) : nullptr;
65
66 const int D = dimension, cN = nu.dimension(0) == 1, cM = mu.dimension(0) == 1,
67 cR = rho.dimension(0) == 1, C_dh = sub_type(Champ_Uniforme, diam_hydr.valeur()),
68 N = vit.line_size();
69
70 double t = equation().schema_temps().temps_courant(), v_min = 0.1;
71 DoubleTrav pos(D), v(N, D), vm(D), v_ph(D), dir(D), nv(N), Cf(N), Cf_t(N), Fk(N), G(N), mult(N, 2), Sigma_tab;
72
73 for (int n = 0; n < N; n++)
74 mult(n, 0) = 1, mult(n, 1) = 0; //default value of mult
75
76 if (fmult) //if multiplier -> compute sigma
77 {
78 const Milieu_composite& milc = ref_cast(Milieu_composite, equation().milieu());
79 // For the span methods of the Saturation class
80 const int ne_tot = domaine.nb_elem_tot(), nb_max_sat = N * (N-1) /2; // yes!! arithmetic sequence!!
81 Sigma_tab.resize(ne_tot, nb_max_sat);
82 for (int k = 0; k < N; k++)
83 for (int l = k + 1; l < N; l++)
84 if (milc.has_saturation(k, l))
85 {
86 const Saturation_base& z_sat = milc.get_saturation(k, l);
87 const int ind_trav = (k*(N-1)-(k-1)*(k)/2) + (l-k-1); // Yes! upper triangular matrix!
88 // retrieve Tsat and sigma ...
89 const DoubleTab& sig = z_sat.get_sigma_tab();
90
91 // fill in the good case
92 for (int ii = 0; ii < ne_tot; ii++)
93 Sigma_tab(ii, ind_trav) = sig(ii);
94 }
95 }
96
97 /* contribution de chaque element ou on applique la perte de charge */
98 for (int i = 0; i < (pssz ? pssz->nb_elem_tot() : domaine.nb_elem_tot()); i++)
99 {
100 int e = pssz ? (*pssz)[i] : i;
101 for (int d = 0; d < D; d++)
102 pos(d) = xp(e, d);
103
104 /* vecteur vitesse en e */
105 double dh_e = C_dh ? dh.valeurs()(0, 0) : dh.valeur_a_compo(pos, 0);
106
107 v = 0.;
108 for (int j = 0; j < e_f.dimension(1); j++)
109 {
110 const int f = e_f(e, j);
111 for (int d = 0; d < D; d++)
112 for (int n = 0; n < N; n++)
113 v(n, d) += fs(f) * pf(f) / (ve(e) * pe(e)) * (xv(f, d) - xp(e, d)) * (e == f_e(f, 0) ? 1 : -1) * pvit(f, n);
114 }
115
116
117 /* norme de v (avec seuil), debit surfacique par phase et total */
118 double Gm = 0.;
119 for (int n = 0; n < N; Gm += G(n), n++)
120 {
121 nv(n) = std::max(v_min, sqrt(domaine.dot(&v(n, 0), &v(n, 0))));
122 G(n) = (alp ? (*alp)(e, n) : 1) * rho(!cR * e, n) * nv(n);
123 }
124
125 double arm = 0.;
126 for (int n = 0; n < N; n++)
127 {
128 arm += (alp ? (*alp)(e, n) : 1) * rho(!cR * e, n);
129
130 for (int d = 0; d < D; d++)
131 vm(d) += (alp ? (*alp)(e, n) : 1) * rho(!cR * e, n) * v(n, d);
132 }
133
134 for (int d = 0; d < D; d++)
135 vm(d) /= arm;
136
137 double nvm = std::max(v_min, sqrt(domaine.dot(&vm(0), &vm(0))));
138 double C_iso, C_dir, v_dir;
139
140 /* coefficients de frottements par composante : Cf(n) (phase seule), Cf_t(n) (le debit total dans cette phase) */
141 for (int n = 0; n < N; n++)
142 {
143 double Re = dh_e * std::max(G(n), 1e-10) / mu(!cM * e, n),
144 Re_m = dh_e * Gm / mu(!cM * e, n);
145
146 for (int d = 0; d < D; d++)
147 v_ph(d) = v(n, d);
148
149 /* phase seule */
150 coeffs_perte_charge(v_ph, pos, t, nv(n), dh_e, nu(!cN * e, n), Re, C_iso, C_dir, v_dir, dir);
151
152 Cf(n) = (C_iso + (C_dir - C_iso) * (nv(n) > 1e-8 ? std::pow(domaine.dot(&v(n, 0), &dir(0)), 2) / (nv(n) * nv(n)) : 0)) * 2 * dh_e / std::max(nv(n), 1e-10);
153
154 /* tout le melange dans la phase */
155 coeffs_perte_charge(vm, pos, t, nvm, dh_e, nu(!cN * e, n), Re_m, C_iso, C_dir, v_dir, dir);
156
157 Cf_t(n) = (C_iso + (C_dir - C_iso) * (nvm > 1e-8 ? std::pow(domaine.dot(&vm(0), &dir(0)), 2) / (nvm * nvm) : 0)) * 2 * dh_e / std::max(nvm, 1e-10);
158
159 Fk(n) = Cf(n) * G(n) * G(n) / rho(!cR * e, n) / 2.0 / dh_e; //force
160 }
161 double Fm = Cf_t(0) * Gm * Gm / rho(!cR * e, 0) / 2.0 / dh_e; //wall "mixture" force (total flow rate, but physical properties of the liquid)
162
163 /* appel du multiplicateur diphasique (si il existe) */
164 if (fmult)
165 fmult->coefficient(&(*alp)(e, 0), &rho(!cR * e, 0), &nv(0), &Cf_t(0), &mu(!cM * e, 0), dh_e, Sigma_tab(e,0), &Fk(0), Fm, mult);
166
167 /* contributions aux faces de e */
168 for (int j = 0; j < e_f.dimension(1); j++)
169 {
170 const int f = e_f(e, j);
171
172 if (f < domaine.nb_faces() && (fcl(f, 0) < 2))
173 for (int n = 0; n < N; n++)
174 {
175 int e1 = f_e(f, 0);
176 if (e1 < 0) e1 = f_e(f, 1);
177
178 double fac = pf(f) * vfd(f, e != e1) * 0.5 / dh_e;
179 double fac_n = fac * mult(n, 0) * Cf(n) * nv(n);
180 double fac_m = fac * mult(n, 1) * Cf_t(n) * Gm / rho(!cR * e, n);
181
182 for (int m = 0; m < N; m++)
183 secmem(f, n) -= ((m == n) * fac_n + fac_m) * (alp ? (*alp)(e, m) : 1) * (pbm ? rho(!cR * e, m) : 1) * vit(f, m);
184
185 if (mat)
186 for (int m = 0; m < N; m++)
187 (*mat)(N * f + n, N * f + m) += ((m == n) * fac_n + fac_m) * (alp ? (*alp)(e, m) : 1) * (pbm ? rho(!cR * e, m) : 1);
188 }
189 }
190 }
191}
class Champ_Don_base base class of Given Fields (not calculated)
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
class Champ_Face_VDF
const IntTab & fcl() const
DoubleTab & passe(int i=1) override
Returns field values at instant t-i.
Champ_Uniforme Represents a field that is constant in space and time.
virtual double valeur_a_compo(const DoubleVect &position, int ncomp) const
Computes the point value of the component "compo" of the field at the point with coordinates pos.
class Domaine_VDF
Definition Domaine_VDF.h:61
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual const Champ_Inc_base & inconnue() const =0
Schema_Temps_base & schema_temps()
Returns the time scheme associated with the equation.
const Nom & le_nom() const override
Returns the name of the field.
DoubleTab & get_sigma_tab()
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
Composite medium representing a multiphase fluid and its properties:
bool has_saturation(int k, int l) const
Saturation_base & get_saturation(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
Two-phase multiplier correlations of the form:
virtual void coefficient(const double *alpha, const double *rho, const double *v, const double *f, const double *mu, const double Dh, const double gamma, const double *Fk, const double Fm, DoubleTab &coeff) const =0
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
Multiphase thermohydraulics problem of type "3*N equations":
virtual Equation_base & equation_masse()
virtual void coeffs_perte_charge(const DoubleVect &u, const DoubleVect &pos, double t, double norme_u, double dh, double nu, double reynolds, double &coeff_ortho, double &coeff_long, double &u_l, DoubleVect &v_valeur) const =0
Called for each face by ajouter().
bool sous_domaine
Is the term limited to a sub-domain?
Factorizes the functionalities of several pressure drop terms in VEF, velocity at faces.
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
int has_correlation(std::string nom_correlation) const
const Correlation_base & get_correlation(std::string nom_correlation) const
double temps_courant() const
Returns the current time.
Base class for output streams.
Definition Sortie.h:52
int_t nb_elem_tot() const
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133