TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Frottement_interfacial_PolyMAC_MPFA.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 <Frottement_interfacial_PolyMAC_MPFA.h>
17#include <Frottement_interfacial_base.h>
18#include <Champ_Face_PolyMAC_MPFA.h>
19#include <Milieu_composite.h>
20#include <Pb_Multiphase.h>
21
22Implemente_instanciable(Frottement_interfacial_PolyMAC_MPFA, "Frottement_interfacial_Face_PolyMAC_MPFA", Source_Frottement_interfacial_base);
23
26
28{
29 const DoubleTab& inco = ref_cast(Champ_Face_base, equation().inconnue()).valeurs();
30 const Domaine_VF& domaine = ref_cast(Domaine_VF, equation().domaine_dis());
31 int i, j, e, k, l, N = inco.line_size(), d, db, D = dimension, nf_tot = domaine.nb_faces_tot();
32
33 /* elements */
34 for (e = 0, i = nf_tot; e < domaine.nb_elem_tot(); e++)
35 for (d = 0; d < D; d++, i++)
36 for (db = 0, j = nf_tot + D * e; db < D; db++, j++)
37 for (k = 0; k < N; k++)
38 for (l = 0; l < N; l++) stencil.append_line(N * i + k, N * j + l);
39}
40
41void Frottement_interfacial_PolyMAC_MPFA::ajouter_blocs(matrices_t matrices, DoubleTab& secmem, const tabs_t& semi_impl) const
42{
43 const Pb_Multiphase& pbm = ref_cast(Pb_Multiphase, equation().probleme());
44 const bool res_en_T = pbm.resolution_en_T();
45 if (!res_en_T) Process::exit("Frottement_interfacial_PolyMAC_MPFA::ajouter_blocs NOT YET PORTED TO ENTHALPY EQUATION ! TODO FIXME !!");
46
47 const Champ_Face_PolyMAC_MPFA& ch = ref_cast(Champ_Face_PolyMAC_MPFA, equation().inconnue());
48 Matrice_Morse *mat = matrices.count(ch.le_nom().getString()) ? matrices.at(ch.le_nom().getString()) : nullptr;
49 const Domaine_PolyMAC_MPFA& domaine = ref_cast(Domaine_PolyMAC_MPFA, equation().domaine_dis());
50 const IntTab& f_e = domaine.face_voisins(), &fcl = ch.fcl();
51 const DoubleVect& pe = equation().milieu().porosite_elem(), &pf = equation().milieu().porosite_face(), &ve = domaine.volumes(), &vf = domaine.volumes_entrelaces(), &dh_e = equation().milieu().diametre_hydraulique_elem();
52 const DoubleTab& inco = ch.valeurs(), &pvit = ch.passe(), &vfd = domaine.volumes_entrelaces_dir(),
53 &alpha = pbm.equation_masse().inconnue().passe(),
54 &press = ref_cast(QDM_Multiphase, equation()).pression().passe(),
55 &temp = pbm.equation_energie().inconnue().passe(),
56 &rho = equation().milieu().masse_volumique().passe(),
57 &mu = ref_cast(Fluide_base, equation().milieu()).viscosite_dynamique().passe();
58 const Milieu_composite& milc = ref_cast(Milieu_composite, equation().milieu());
59
60 DoubleTab const * d_bulles = (equation().probleme().has_champ("diametre_bulles")) ? &equation().probleme().get_champ("diametre_bulles").valeurs() : nullptr ;
61
62 int e, f, c, i, j, k, l, n, N = inco.line_size(), Np = press.line_size(), d, D = dimension, nf_tot = domaine.nb_faces_tot(),
63 cR = (rho.dimension_tot(0) == 1), cM = (mu.dimension_tot(0) == 1);
64 DoubleTrav a_l(N), p_l(N), T_l(N), rho_l(N), mu_l(N), sigma_l(N*(N-1)/2), dv(N, N), ddv(N, N, 4), d_bulles_l(N), coeff(N, N, 2); //arguments for coeff
65 double ddv_c[4] = {0., 0., 0., 0. };
66 double dh;
67 const Frottement_interfacial_base& correlation_fi = ref_cast(Frottement_interfacial_base, correlation_.valeur());
68
69
70 // And for the span methods of the Saturation class
71 const int ne_tot = domaine.nb_elem_tot(), nb_max_sat = N * (N-1) /2; // yes !! arithmetic series !!
72 DoubleTrav Sigma_tab(ne_tot,nb_max_sat);
73
74 // fill the arrays ...
75 for (k = 0; k < N; k++)
76 for (l = k + 1; l < N; l++)
77 {
78 if (milc.has_saturation(k, l))
79 {
80 const Saturation_base& z_sat = milc.get_saturation(k, l);
81 const int ind_trav = (k*(N-1)-(k-1)*(k)/2) + (l-k-1); // yes !! upper triangular matrix !
82 // retrieve sigma ...
83 const DoubleTab& sig = z_sat.get_sigma_tab();
84 // fill in the good case
85 for (int ii = 0; ii < ne_tot; ii++) Sigma_tab(ii, ind_trav) = sig(ii);
86 }
87 else if (milc.has_interface(k, l))
88 {
89 Interface_base& sat = milc.get_interface(k,l);
90 const int ind_trav = (k*(N-1)-(k-1)*(k)/2) + (l-k-1); // yes !! upper triangular matrix !
91 const DoubleTab& sig = sat.get_sigma_tab();
92 for (int ii = 0; ii < ne_tot; ii++) Sigma_tab(ii, ind_trav) = sig(ii);
93 }
94 }
95
96 /* faces */
97 for (f = 0; f < domaine.nb_faces(); f++)
98 if (fcl(f, 0) < 2)
99 {
100 for (a_l = 0, p_l = 0, T_l = 0, rho_l = 0, mu_l = 0, dh = 0, sigma_l = 0, dv = dv_min, ddv = 0, d_bulles_l=0, c = 0; c < 2 && (e = f_e(f, c)) >= 0; c++)
101 for (n = 0; n < N; n++)
102 {
103 a_l(n) += vfd(f, c) / vf(f) * alpha(e, n);
104 p_l(n) += vfd(f, c) / vf(f) * press(e, n * (Np > 1));
105 T_l(n) += vfd(f, c) / vf(f) * temp(e, n); // FIXME SI res_en_T
106 rho_l(n) += vfd(f, c) / vf(f) * rho(!cR * e, n);
107 mu_l(n) += vfd(f, c) / vf(f) * mu(!cM * e, n);
108 for (k = n+1; k < N; k++)
109 {
110 const int ind_trav = (n*(N-1)-(n-1)*(n)/2) + (k-n-1);
111 sigma_l(ind_trav) += vfd(f, c) / vf(f) * Sigma_tab(e, ind_trav);
112 }
113 dh += vfd(f, c) / vf(f) * alpha(e, n) * dh_e(e);
114 for (k = 0; k < N; k++)
115 {
116 double dv_c = ch.v_norm(pvit, pvit, e, f, k, n, nullptr, &ddv_c[0]);
117 if (dv_c > dv(k, n))
118 for (dv(k, n) = dv_c, i = 0; i < 4; i++) ddv(k, n, i) = ddv_c[i];
119 }
120 d_bulles_l(n) += (d_bulles) ? vfd(f, c) / vf(f) * (*d_bulles)(e,n) : 0;
121 }
122
123 correlation_fi.coefficient(a_l, p_l, T_l, rho_l, mu_l, sigma_l, dh, dv, d_bulles_l, coeff);
124 for (k = 0; k < N; k++)
125 for (l = 0; l < N; l++)
126 for (j = 0; j < 2; j++)
127 coeff(k, l, j) *= 1 + (a_l(k) > 1e-8 ? std::pow(a_l(k) / a_res_, -exp_res) : 0) + (a_l(l) > 1e-8 ? std::pow(a_l(l) / a_res_, -exp_res) : 0);
128
129 /* contributions : we take the max between the two sides */
130 for (k = 0; k < N; k++)
131 for (l = 0; l < N; l++)
132 if (k != l)
133 {
134 double fac = beta_ * pf(f) * vf(f);
135 /* we try to implicitize coeff without slowing convergence by doing a Taylor expansion around pvit (in the direction of interest only) */
136 secmem(f, k) -= fac * (coeff(k, l, 0) * (inco(f, k) - inco(f, l)) + coeff(k, l, 1) * ddv(k, l, 3) * (pvit(f, k) - pvit(f, l)) * ((inco(f, k) - inco(f, l)) - (pvit(f, k) - pvit(f, l))));
137 if (mat)
138 for (j = 0; j < 2; j++) (*mat)(N * f + k, N * f + (j ? l : k)) += fac * (j ? -1 : 1) * (coeff(k, l, 0) + coeff(k, l, 1) * ddv(k, l, 3) * (pvit(f, k) - pvit(f, l)));
139 }
140 }
141
142 /* elements */
143 for (e = 0; e < domaine.nb_elem_tot(); e++)
144 {
145 /* coefficient arguments */
146 for (n = 0; n < N; n++)
147 {
148 a_l(n) = alpha(e, n);
149 p_l(n) = press(e, n * (Np > 1));
150 T_l(n) = temp(e, n); // FIXME SI res_en_T
151 rho_l(n) = rho(!cR * e, n);
152 mu_l(n) = mu(!cM * e, n);
153 for (k = n+1; k < N; k++)
154 {
155 const int ind_trav = (n*(N-1)-(n-1)*(n)/2) + (k-n-1);
156 sigma_l(ind_trav) = Sigma_tab(e, ind_trav);
157 }
158 d_bulles_l(n) = (d_bulles) ? (*d_bulles)(e,n) : 0;
159
160 for (k = 0; k < N; k++) dv(k, n) = std::max(ch.v_norm(pvit, pvit, e, -1, k, n, nullptr, &ddv(k, n, 0)), dv_min);
161
162 }
163
164 correlation_fi.coefficient(a_l, p_l, T_l, rho_l, mu_l, sigma_l, dh_e(e), dv, d_bulles_l, coeff);
165
166 for (k = 0; k < N; k++)
167 for (l = 0; l < N; l++)
168 {
169 coeff(k, l, 1) *= (dv(k, l) > dv_min); //no derivative if dv < dv_min
170 for (j = 0; j < 2; j++)
171 coeff(k, l, j) *= 1 + (a_l(k) > 1e-8 ? std::pow(a_l(k) / a_res_, -exp_res) : 0) + (a_l(l) > 1e-8 ? std::pow(a_l(l) / a_res_, -exp_res) : 0);
172 }
173
174 for (d = 0, i = nf_tot + D * e; d < D; d++, i++)
175 for (k = 0; k < N; k++)
176 for (l = 0; l < N; l++)
177 if (k != l)
178 {
179 double fac = beta_ * pe(e) * ve(e);
180 /* we try to implicitize coeff without slowing convergence by doing a Taylor expansion around pvit (in the direction of interest only) */
181 secmem(i, k) -= fac * (coeff(k, l, 0) * (inco(i, k) - inco(i, l)) + coeff(k, l, 1) * ddv(k, l, d) * (pvit(i, k) - pvit(i, l)) * ((inco(i, k) - inco(i, l)) - (pvit(i, k) - pvit(i, l))));
182 if (mat)
183 for (j = 0; j < 2; j++) (*mat)(N * i + k, N * i + (j ? l : k)) += fac * (j ? -1 : 1) * (coeff(k, l, 0) + coeff(k, l, 1) * ddv(k, l, d) * (pvit(i, k) - pvit(i, l)));
184 }
185 }
186}
: class Champ_Face_PolyMAC_MPFA
double v_norm(const DoubleTab &val, const DoubleTab &val_f, int e, int f, int k, int l, double *v_ext, double *dnv) const
const IntTab & fcl() const
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 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
virtual const Champ_Inc_base & inconnue() const =0
Probleme_base & probleme()
Returns the problem associated with the equation.
const Nom & le_nom() const override
Returns the name of the field.
Base class for an incompressible fluid and its properties:
Definition Fluide_base.h:36
void ajouter_blocs(matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={}) const override
Frottement_interfacial_base class: utility for interfacial friction operators taking the form.
virtual void coefficient(const DoubleTab &alpha, const DoubleTab &p, const DoubleTab &T, const DoubleTab &rho, const DoubleTab &mu, const DoubleTab &sigma, double Dh, const DoubleTab &ndv, const DoubleTab &d_bulles, DoubleTab &coeff) const =0
DoubleTab & get_sigma_tab()
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
DoubleVect & porosite_elem()
Definition Milieu_base.h:58
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
DoubleVect & porosite_face()
Definition Milieu_base.h:62
Composite medium representing a multiphase fluid and its properties:
bool has_interface(int k, int l) const
bool has_saturation(int k, int l) const
Interface_base & get_interface(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
const std::string & getString() const
Definition Nom.h:92
static int dimension
Definition Objet_U.h:94
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 bool resolution_en_T() const
virtual Equation_base & equation_energie()
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
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.
Base class for output streams.
Definition Sortie.h:52
Interfacial friction source term of the form:
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
int line_size() const
Definition TRUSTVect.tpp:67