TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Masse_PolyMAC_MPFA_Face.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 <Linear_algebra_tools_impl.h>
17#include <Op_Grad_PolyMAC_MPFA_Face.h>
18#include <Masse_PolyMAC_MPFA_Face.h>
19#include <Champ_Face_PolyMAC_MPFA.h>
20#include <Masse_ajoutee_base.h>
21#include <Domaine_PolyMAC_MPFA.h>
22#include <Domaine_Cl_PolyMAC_family.h>
23#include <Option_PolyMAC_family.h>
24#include <Champ_Uniforme.h>
25#include <Pb_Multiphase.h>
26#include <Equation_base.h>
27#include <Matrix_tools.h>
28#include <Array_tools.h>
29#include <Dirichlet.h>
30#include <Matrice33.h>
31#include <Vecteur3.h>
32#include <TRUSTTab.h>
33#include <Piso.h>
34#include <Dirichlet_homogene.h>
35#include <Symetrie.h>
36#include <Debog.h>
37
38Implemente_instanciable(Masse_PolyMAC_MPFA_Face, "Masse_PolyMAC_MPFA_Face", Masse_PolyMAC_HFV_Face);
39
40Sortie& Masse_PolyMAC_MPFA_Face::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
41
43
52
53DoubleTab& Masse_PolyMAC_MPFA_Face::appliquer_impl(DoubleTab& sm) const
54{
55 const Domaine_PolyMAC_MPFA& domaine = ref_cast(Domaine_PolyMAC_MPFA, le_dom_PolyMAC_CDO.valeur());
56 int e, nf_tot = domaine.nb_faces_tot(), d, D = dimension, n, N = equation().inconnue().valeurs().line_size();
57 const DoubleTab *a_r = sub_type(QDM_Multiphase, equation()) ? &ref_cast(Pb_Multiphase, equation().probleme()).equation_masse().champ_conserve().passe() : nullptr;
58 const DoubleVect& pe = equation().milieu().porosite_elem(), &ve = domaine.volumes();
59
60 if (polymac_flica5)
61 {
62 const IntTab& f_e = domaine.face_voisins();
63 const DoubleVect& pf = equation().milieu().porosite_face(), &vf = domaine.volumes_entrelaces();
64 const DoubleTab& vfd = domaine.volumes_entrelaces_dir();
65 int i, f;
66 double fac;
67
68 //velocities at faces
69 for (f = 0; f < domaine.nb_faces(); f++)
70 for (n = 0; n < N; n++)
71 {
72 for (fac = 0, i = 0; i < 2 && (e = f_e(f, i)) >= 0; i++) fac += vfd(f, i) / vf(f) * (a_r ? (*a_r)(e, n) : 1);
73 sm(f, n) /= pf(f) * vf(f) * fac; //computed velocity
74 }
75
76 //velocities at elements
77 if (sm.dimension_tot(0) > N * nf_tot)
78 for (e = 0; e < domaine.nb_elem(); e++)
79 for (d = 0; d < D; d++)
80 for (n = 0; n < N; n++)
81 sm(nf_tot + D * e + d, n) /= pe(e) * ve(e) * (a_r ? (*a_r)(e, n) : 1);
82 }
83 else
84 {
85 //velocities at faces
87
88 //velocities at elements
89 if (sm.dimension_tot(0) > nf_tot)
90 for (e = 0; e < domaine.nb_elem(); e++)
91 for (d = 0; d < D; d++)
92 for (n = 0; n < N; n++)
93 {
94 if ( (a_r ? (*a_r)(e, n) : 1) > 1e-10) sm(nf_tot + D * e + d, n) /= pe(e) * ve(e) * (a_r ? (*a_r)(e, n) : 1);
95 else sm(nf_tot + D * e + d, n) = 0; //case of evanescence
96 }
97 }
98
100 return sm;
101}
102
103void Masse_PolyMAC_MPFA_Face::dimensionner_blocs(matrices_t matrices, const tabs_t& semi_impl) const
104{
105 const std::string& nom_inc = equation().inconnue().le_nom().getString();
106 if (!matrices.count(nom_inc)) return; //nothing to do
107 Matrice_Morse& mat = *matrices.at(nom_inc), mat2;
108 const DoubleTab& inco = equation().inconnue().valeurs();
109 const Pb_Multiphase *pbm = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr;
110 const Masse_ajoutee_base *corr = pbm && pbm->has_correlation("masse_ajoutee") ? &ref_cast(Masse_ajoutee_base, pbm->get_correlation("masse_ajoutee")) : nullptr;
111
112 Stencil sten(0, 2);
113
114 // faces
115 Solveur_Masse_Face_proto::dimensionner_blocs_proto(matrices, semi_impl, false /* dont allocate */, sten);
116
117 // elems
118 int i, e, nf_tot = le_dom_PolyMAC_CDO->nb_faces_tot(), m, n, N = inco.line_size(), d, D = dimension;
119 for (e = 0, i = N * nf_tot; e < le_dom_PolyMAC_CDO->nb_elem_tot(); e++)
120 for (d = 0; d < D; d++)
121 for (n = 0; n < N; n++, i++) //all elements (for Op_Grad_PolyMAC_MPFA_Face)
122 if (corr)
123 for (m = 0; m < N; m++) sten.append_line(i, N * (nf_tot + D * e + d) + m);
124 else sten.append_line(i, i);
125
127 mat.nb_colonnes() ? mat += mat2 : mat = mat2;
128}
129
130// XXX : to check whether Solveur_Masse_Face_proto::ajouter_blocs_proto can be used ...
131void Masse_PolyMAC_MPFA_Face::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, double dt, const tabs_t& semi_impl, int resoudre_en_increments) const
132{
133 const DoubleTab& inco = equation().inconnue().valeurs(), &passe = equation().inconnue().passe();
134 Matrice_Morse *mat = matrices[equation().inconnue().le_nom().getString()]; //facultatif
135 const Domaine_PolyMAC_MPFA& domaine = ref_cast(Domaine_PolyMAC_MPFA, le_dom_PolyMAC_CDO.valeur());
136 const Conds_lim& cls = le_dom_Cl_PolyMAC_CDO->les_conditions_limites();
137 const IntTab& f_e = domaine.face_voisins(), &fcl = ref_cast(Champ_Face_PolyMAC_MPFA, equation().inconnue()).fcl();
138 const DoubleVect& pf = equation().milieu().porosite_face(), &pe = equation().milieu().porosite_elem(), &vf = domaine.volumes_entrelaces(), &ve = domaine.volumes(), &fs = domaine.face_surfaces();
139 const Pb_Multiphase *pbm = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()) : nullptr;
140 const DoubleTab& nf = domaine.face_normales(), *rho = pbm ? &equation().milieu().masse_volumique().passe() : nullptr,
141 *alpha = pbm ? &pbm->equation_masse().inconnue().passe() : nullptr, *a_r = pbm ? &pbm->equation_masse().champ_conserve().passe() : nullptr, &vfd = domaine.volumes_entrelaces_dir();
142 const Masse_ajoutee_base *corr = pbm && pbm->has_correlation("masse_ajoutee") ? &ref_cast(Masse_ajoutee_base, pbm->get_correlation("masse_ajoutee")) : nullptr;
143 int i, e, f, nf_tot = domaine.nb_faces_tot(), m, n, N = inco.line_size(), d, D = dimension, cR = rho ? (*rho).dimension_tot(0) == 1 : 0;
144 const DoubleTab *coeff_t = has_coefficient_temporel_ ? &equation().get_champ(name_of_coefficient_temporel_).valeurs() : nullptr;
145
146 if (polymac_flica5) resoudre_en_increments = 1;
147
148 /* faces: if BCs, no multiplication by alpha * rho in multiphase */
149 DoubleTrav masse(N, N), masse_e(N, N); //alpha * rho mass, contribution
150 for (f = 0; f < domaine.nb_faces(); f++) //real faces
151 {
152 const double fac_ale = domaine.domaine().deformable() ? domaine.domaine().old_volumes_entrelaces()(f) / vf(f) : 1.0;
153 if (!pbm || fcl(f, 0) >= 2)
154 for (masse = 0, n = 0; n < N; n++) masse(n, n) = coeff_t ? (*coeff_t)[f] : 1.0; //not Pb_Multiphase or BC -> no alpha * rho
155 else for (masse = 0, i = 0; i < 2 && (e = f_e(f, i)) >= 0; i++)
156 {
157 for (masse_e = 0, n = 0; n < N; n++) masse_e(n, n) = (*a_r)(e, n); //diagonal part
158 if (corr) corr->ajouter(&(*alpha)(e, 0), &(*rho)(!cR * e, 0), masse_e); //added mass part
159 for (n = 0; n < N; n++)
160 for (m = 0; m < N; m++) masse(n, m) += vfd(f, i) / vf(f) * masse_e(n, m); //contribution to the face alpha * rho
161 }
162 for (n = 0; n < N; n++)
163 {
164 double fac = pf(f) * vf(f) / dt;
165 for (m = 0; m < N; m++) secmem(f, n) -= fac * resoudre_en_increments * masse(n, m) * inco(f, m);
166 if (fcl(f, 0) < 2)
167 for (m = 0; m < N; m++) secmem(f, n) += fac * masse(n, m) * fac_ale * passe(f, m);
168 else if (fcl(f, 0) == 3 && sub_type(Dirichlet, cls[fcl(f, 1)].valeur()))
169 for (d = 0; d < D; d++)
170 secmem(f, n) += fac * masse(n, n) * ref_cast(Dirichlet, cls[fcl(f, 1)].valeur()).val_imp(fcl(f, 2), N * d + n) * nf(f, d) / fs(f);
171 if (mat)
172 for (m = 0; m < N; m++)
173 if (masse(n, m)) (*mat)(N * f + n, N * f + m) += fac * masse(n, m);
174 }
175 }
176
177 for (e = 0, i = nf_tot; e < domaine.nb_elem_tot(); e++) //all elements (for Op_Grad_PolyMAC_MPFA_Face)
178 {
179 const double fac_ale = domaine.domaine().deformable() ? domaine.domaine().old_volumes()(e) / ve(e) : 1.0;
180 for (masse = 0, n = 0; n < N; n++) masse(n, n) = a_r ? (*a_r)(e, n) : 1; //diagonal part
181 if (corr) corr->ajouter(&(*alpha)(e, 0), &(*rho)(!cR * e, 0), masse); //added mass part
182 for (d = 0; d < D; d++, i++)
183 for (n = 0; n < N; n++)
184 {
185 double fac = pe(e) * ve(e) / dt;
186 if (polymac_flica5)
187 for (m = 0; m < N; m++)
188 secmem(i, n) -= fac * masse(n, m) * (resoudre_en_increments * inco(i, m) - passe(i, m));
189 else
190 for (m = 0; m < N; m++)
191 {
192 double ma = a_r ? masse(n, m) : (coeff_t ? (*coeff_t)[(i - nf_tot)/dimension] : 1.0);
193 secmem(i, n) -= fac * ma * (resoudre_en_increments * inco(i, m) - fac_ale * passe(i, m));
194 }
195 if (mat)
196 for (m = 0; m < N; m++)
197 {
198 double ma = polymac_flica5 ? masse(n, m) : (a_r ? masse(n, m) : (coeff_t ? (*coeff_t)[(i - nf_tot)/dimension] : 1.0));
199 if (ma) (*mat)(N * i + n, N * i + m) += fac * ma;
200 }
201 }
202 }
203 i++;
204}
205
206//brings the element part back in consistency with the face part
207DoubleTab& Masse_PolyMAC_MPFA_Face::corriger_solution(DoubleTab& x, const DoubleTab& y, int incr) const
208{
209 const Champ_Face_PolyMAC_MPFA& ch = ref_cast(Champ_Face_PolyMAC_MPFA, equation().inconnue());
211 return x;
212}
: class Champ_Face_PolyMAC_MPFA
void update_ve(DoubleTab &val) const
Interpolates face-based velocity to element centers using a first-order method.
void update_ve2(DoubleTab &val, int incr=0) const
Applies the second-order interpolation from face velocities to element centers.
DoubleTab & passe(int i=1) override
Returns field values at instant t-i.
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 Conds_lim This class represents a vector of boundary conditions.
Definition Conds_lim.h:32
Dirichlet This class is the base class of the hierarchy of Dirichlet-type boundary conditions.
Definition Dirichlet.h:31
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Equation_base The role of an equation is the calculation of one or more fields....
virtual const Milieu_base & milieu() const =0
Champ_Inc_base & champ_conserve() const
virtual const Champ_Inc_base & inconnue() const =0
const Champ_base & get_champ(const Motcle &nom) const override
const Nom & le_nom() const override
Returns the name of the field.
DoubleTab & appliquer_impl(DoubleTab &) const override
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, double dt, const tabs_t &semi_impl, int resoudre_en_increments) const override
DoubleTab & corriger_solution(DoubleTab &x, const DoubleTab &y, int incr=0) const override
void dimensionner_blocs(matrices_t matrices, const tabs_t &semi_impl) const override
Added-mass correlation of the form: alpha_k rho_k Dv_k / Dt -> alpha_k rho_k Dv_k / Dt + sum_l ma(k,...
virtual void ajouter(const double *alpha, const double *rho, DoubleTab &a_r) const =0
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
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
Returns the mass density of the medium (const version).
DoubleVect & porosite_face()
Definition Milieu_base.h:62
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 const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Objet_U.cpp:317
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()
int has_correlation(std::string nom_correlation) const
const Correlation_base & get_correlation(std::string nom_correlation) const
Carries the terms of the momentum equation for multiphase flow without turbulence modelling.
void associer_masse_proto(const Solveur_Masse_base &, const Domaine_VF &)
void dimensionner_blocs_proto(matrices_t matrices, const tabs_t &semi_impl, const bool allocate, Stencil &) const
DoubleTab & appliquer_impl_proto(DoubleTab &) const
Base class for output streams.
Definition Sortie.h:52
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
int line_size() const
Definition TRUSTVect.tpp:67
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")