TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Perte_Charge_PolyMAC_HFV.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 <Perte_Charge_PolyMAC_HFV.h>
18#include <Fluide_Incompressible.h>
19#include <Domaine_Cl_PolyMAC_family.h>
20#include <Domaine_PolyMAC_MPFA.h>
21#include <Champ_Face_PolyMAC_CDO.h>
22#include <Schema_Temps_base.h>
23#include <Milieu_composite.h>
24#include <Champ_Uniforme.h>
25#include <QDM_Multiphase.h>
26#include <Pb_Multiphase.h>
27#include <Probleme_base.h>
28#include <Equation_base.h>
29#include <Sous_Domaine.h>
30#include <Param.h>
31
32Implemente_base(Perte_Charge_PolyMAC_HFV, "Perte_Charge_PolyMAC_HFV", Perte_Charge_PolyMAC_CDO);
33
34Sortie& Perte_Charge_PolyMAC_HFV::printOn(Sortie& s) const { return s << que_suis_je() << finl; }
35
37
38void Perte_Charge_PolyMAC_HFV::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
39{
40 assert(has_interface_blocs());
41
42 const Domaine_Poly_base& domaine = ref_cast(Domaine_Poly_base, equation().domaine_dis());
43 const Pb_Multiphase *pbm = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr;
44 const Champ_Face_PolyMAC_CDO& ch = ref_cast(Champ_Face_PolyMAC_CDO, equation().inconnue());
45 const Champ_Don_base& dh = diam_hydr;
46
47 const DoubleTab& xp = domaine.xp(), &xv = domaine.xv(), &vit = la_vitesse->valeurs(), &pvit = la_vitesse->passe(),
48 &nu = le_fluide->viscosite_cinematique().valeurs(), &vfd = domaine.volumes_entrelaces_dir(),
49 &mu = le_fluide->viscosite_dynamique().valeurs(), &rho = le_fluide->masse_volumique().passe(),
50 *alp = pbm ? &pbm->equation_masse().inconnue().passe() : nullptr;
51
52 const DoubleVect& pe = le_fluide->porosite_elem(), &pf = le_fluide->porosite_face(), &fs = domaine.face_surfaces(), &ve = domaine.volumes();
53 const Multiplicateur_diphasique_base *fmult = pbm && pbm->has_correlation("multiplicateur_diphasique") ?
54 &ref_cast(Multiplicateur_diphasique_base, pbm->get_correlation("multiplicateur_diphasique")) : nullptr;
55
56 const Sous_Domaine *pssz = sous_domaine ? &le_sous_domaine.valeur() : nullptr;
57 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins(), &fcl = ch.fcl();
58 Matrice_Morse *mat = matrices.count(ch.le_nom().getString()) ? matrices.at(ch.le_nom().getString()) : nullptr;
59
60 int i, j, k, f, d, D = dimension, cN = nu.dimension(0) == 1, cM = mu.dimension(0) == 1, cR = rho.dimension(0) == 1,
61 C_dh = sub_type(Champ_Uniforme, diam_hydr.valeur()), m, n, N = vit.line_size(),
62 poly_v2 = sub_type(Domaine_PolyMAC_MPFA, domaine), nf_tot = domaine.nb_faces_tot();
63
64 double t = equation().schema_temps().temps_courant(), v_min = 0.1, Gm, Fm, nvm, arm, C_dir, C_iso, v_dir;
65 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;
66
67 for (n = 0; n < N; n++)
68 mult(n, 0) = 1, mult(n, 1) = 0; //default value of mult
69 if (fmult) //if multiplier -> compute sigma
70 {
71 const Milieu_composite& milc = ref_cast(Milieu_composite, equation().milieu());
72 // For the span methods of the Saturation class
73 const int ne_tot = domaine.nb_elem_tot(), nb_max_sat = N * (N-1) /2; // arithmetic series !
74 Sigma_tab.resize(ne_tot, nb_max_sat);
75 for (k = 0; k < N; k++)
76 for (int l = k + 1; l < N; l++)
77 if (milc.has_saturation(k, l))
78 {
79 const Saturation_base& z_sat = milc.get_saturation(k, l);
80 const int ind_trav = (k*(N-1)-(k-1)*(k)/2) + (l-k-1); // upper triangular matrix !
81 // retrieve Tsat and sigma ...
82 const DoubleTab& sig = z_sat.get_sigma_tab();
83
84 // fill in the good case
85 for (int ii = 0; ii < ne_tot; ii++)
86 Sigma_tab(ii, ind_trav) = sig(ii);
87 }
88 }
89
90 /* contribution of each element where the pressure drop is applied */
91 for (i = 0; i < (pssz ? pssz->nb_elem_tot() : domaine.nb_elem_tot()); i++)
92 {
93 int e = pssz ? (*pssz)[i] : i;
94 for (d = 0; d < D; d++)
95 pos(d) = xp(e, d);
96
97 /* velocity vector at element e */
98 double dh_e = C_dh ? dh.valeurs()(0, 0) : dh.valeur_a_compo(pos, 0);
99 if (poly_v2)
100 for (d = 0; d < D; d++)
101 for (n = 0; n < N; n++)
102 v(n, d) = pvit(nf_tot + D * e + d, n); //velocity via auxiliary variable
103 else
104 for (v = 0, j = 0; j < e_f.dimension(1) && (f = e_f(e, j)) >= 0; j++)
105 for (n = 0; n < N; n++)
106 for (d = 0; d < D; d++) /* PolyMAC_HFV V1: velocity to reconstruct */
107 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);
108
109 /* norm of v (with threshold), mass flux per phase and total */
110 for (n = 0, Gm = 0; n < N; Gm += G(n), n++)
111 nv(n) = std::max(v_min, sqrt(domaine.dot(&v(n, 0), &v(n, 0)))), G(n) = (alp ? (*alp)(e, n) : 1) * rho(!cR * e, n) * nv(n);
112 for (arm = 0, n = 0; n < N; n++)
113 for (arm += (alp ? (*alp)(e, n) : 1) * rho(!cR * e, n), d = 0; d < D; d++)
114 vm(d) += (alp ? (*alp)(e, n) : 1) * rho(!cR * e, n) * v(n, d);
115 for (d = 0; d < D; d++)
116 vm(d) /= arm;
117 nvm = std::max(v_min, sqrt(domaine.dot(&vm(0), &vm(0))));
118
119 /* friction coefficients per component: Cf(n) (single phase), Cf_t(n) (total flow rate in this phase) */
120 for (n = 0; n < N; n++)
121 {
122 double Re = dh_e * std::max(G(n), 1e-10) / mu(!cM * e, n), Re_m = dh_e * Gm / mu(!cM * e, n);
123 for (d = 0; d < D; d++)
124 v_ph(d) = v(n, d);
125 /* single phase */
126 coeffs_perte_charge(v_ph, pos, t, nv(n), dh_e, nu(!cN * e, n), Re, C_iso, C_dir, v_dir, dir);
127 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);
128 /* entire mixture in the phase */
129 coeffs_perte_charge(vm, pos, t, nvm, dh_e, nu(!cN * e, n), Re_m, C_iso, C_dir, v_dir, dir);
130 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);
131 Fk(n) = Cf(n) * G(n) * G(n) / rho(!cR * e, n) / 2.0 / dh_e; //force
132 }
133 Fm = Cf_t(0) * Gm * Gm / rho(!cR * e, 0) / 2.0 / dh_e; //wall force "mixture" (total flow rate, but physical properties of the liquid)
134
135 /* call the two-phase multiplier (if it exists) */
136 if (fmult) 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);
137
138 /* contributions to the faces of element e */
139 for (j = 0; j < e_f.dimension(1) && (f = e_f(e, j)) >= 0; j++)
140 if (f < domaine.nb_faces() && (!poly_v2 || fcl(f, 0) < 2)) /* contribution to Dirichlet faces in Poly V1 */
141 for (n = 0; n < N; n++)
142 {
143 double fac = pf(f) * vfd(f, e != f_e(f, 0)) * 0.5 / dh_e, fac_n = fac * mult(n, 0) * Cf(n) * nv(n), fac_m = fac * mult(n, 1) * Cf_t(n) * Gm / rho(!cR * e, n);
144 for (m = 0; m < N; m++)
145 secmem(f, n) -= ((m == n) * fac_n + fac_m) * (alp ? (*alp)(e, m) : 1) * (pbm ? rho(!cR * e, m) : 1) * vit(f, m);
146 if (mat)
147 for (m = 0; m < N; m++)
148 (*mat)(N * f + n, N * f + m) += ((m == n) * fac_n + fac_m) * (alp ? (*alp)(e, m) : 1) * (pbm ? rho(!cR * e, m) : 1);
149 }
150
151 if (poly_v2)
152 for (d = 0, k = nf_tot + D * e; d < D; d++, k++)
153 for (n = 0; n < N; n++) /* PolyMAC_HFV V2: contributions to element equations */
154 {
155 double fac = pe(e) * ve(e) * 0.5 / dh_e, fac_n = fac * mult(n, 0) * Cf(n) * nv(n), fac_m = fac * mult(n, 1) * Cf_t(n) * Gm / rho(!cR * e, n);
156 for (m = 0; m < N; m++)
157 secmem(k, n) -= ((m == n) * fac_n + fac_m) * (alp ? (*alp)(e, m) : 1) * (pbm ? rho(!cR * e, m) : 1) * vit(k, m);
158 if (mat)
159 for (m = 0; m < N; m++)
160 (*mat)(N * k + n, N * k + m) += ((m == n) * fac_n + fac_m) * (alp ? (*alp)(e, m) : 1) * (pbm ? rho(!cR * e, m) : 1);
161 }
162 }
163}
class Champ_Don_base base class of Given Fields (not calculated)
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
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_Poly_base
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?
Factorises the features of several pressure drop classes in VEF, face velocity.
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
int has_interface_blocs() 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