TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Op_Conv_EF_Stab_PolyMAC_CDO_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 <Op_Conv_EF_Stab_PolyMAC_CDO_Face.h>
17#include <Discretisation_base.h>
18#include <Dirichlet_homogene.h>
19#include <Champ_Face_PolyMAC_CDO.h>
20#include <Domaine_Cl_PolyMAC_family.h>
21#include <Schema_Temps_base.h>
22#include <Domaine_PolyMAC_CDO.h>
23#include <Probleme_base.h>
24#include <Matrix_tools.h>
25#include <Array_tools.h>
26#include <TRUSTLists.h>
27#include <Dirichlet.h>
28#include <Param.h>
29#include <cmath>
30
31Implemente_instanciable( Op_Conv_EF_Stab_PolyMAC_CDO_Face, "Op_Conv_EF_Stab_PolyMAC_CDO_Face", Op_Conv_PolyMAC_CDO_base );
32Implemente_instanciable( Op_Conv_Amont_PolyMAC_CDO_Face, "Op_Conv_Amont_PolyMAC_CDO_Face", Op_Conv_EF_Stab_PolyMAC_CDO_Face );
33Implemente_instanciable( Op_Conv_Centre_PolyMAC_CDO_Face, "Op_Conv_Centre_PolyMAC_CDO_Face", Op_Conv_EF_Stab_PolyMAC_CDO_Face );
34
35// XD Op_Conv_EF_Stab_PolyMAC_CDO_Face interprete Op_Conv_EF_Stab_PolyMAC_CDO_Face BRACE Class
36// XD_CONT Op_Conv_EF_Stab_PolyMAC_CDO_Face_PolyMAC_CDO
37
41
43{
45 Param param(que_suis_je());
46 param.ajouter("alpha", &alpha_); // XD_ADD_P double
47 // XD_CONT parametre ajustant la stabilisation de 0 (schema centre) a 1 (schema amont)
48 param.lire_avec_accolades_depuis(is);
49 return is;
50}
51
53{
54 alpha_ = 1.0;
56}
57
59{
60 alpha_ = 0.0;
62}
63
65{
66
67 double dt = 1e10;
68 const Domaine_Poly_base& domaine = le_dom_poly_.valeur();
69 const DoubleVect& fs = domaine.face_surfaces(), &pf = equation().milieu().porosite_face(), &ve = domaine.volumes(), &pe = equation().milieu().porosite_elem();
70 const DoubleTab& vit = vitesse_->valeurs();
71 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins();
72 const int N = vit.line_size();
73 DoubleTrav flux(N); //somme des flux pf * |f| * vf, volume minimal des mailles d'elements/faces affectes par ce flux
74
75 for (int e = 0; e < domaine.nb_elem(); e++)
76 {
77 // Calcul du volume effectif de l'element
78 const double vol = pe(e) * ve(e);
79 flux = 0.;
80
81 // Parcourt des faces associees a l'element
82 for (int i = 0; i < e_f.dimension(1); i++)
83 {
84 int f = e_f(e, i);
85 if (f < 0) continue; // face in-existante
86
87 for (int n = 0; n < N; n++)
88 {
89 // Ajout du flux entrant pour la composante n : Seuls les flux entrants comptent
90 double flux_f = pf(f) * fs(f) * std::max((e == f_e(f, 1) ? 1 : -1) * vit(f, n), 0.);
91 flux(n) += flux_f;
92 }
93 }
94
95 // Calcul du pas de temps pour chaque composante n
96 for (int n = 0; n < N; n++)
97 if (std::abs(flux(n)) > 1e-12)
98 dt = std::min(dt, vol / flux(n));
99 }
100
101 return Process::mp_min(dt);
102}
103
105{
107
108 /* au cas ou... */
109 const Domaine_PolyMAC_CDO& domaine = le_dom_poly_.valeur();
110 if (domaine.domaine().nb_joints() && domaine.domaine().joint(0).epaisseur() < 2)
111 {
112 Cerr << "Op_Conv_EF_Stab_PolyMAC_CDO_Face : largeur de joint insuffisante (minimum 2)!" << finl;
114 }
115 porosite_f.ref(mon_equation->milieu().porosite_face());
116 porosite_e.ref(mon_equation->milieu().porosite_elem());
117}
118
120{
122 {
124 return;
125 }
126
127 const Domaine_PolyMAC_CDO& domaine = le_dom_poly_.valeur();
128 const Champ_Face_PolyMAC_CDO& ch = ref_cast(Champ_Face_PolyMAC_CDO, equation().inconnue());
129 const IntTab& e_f = domaine.elem_faces(), &f_e = domaine.face_voisins(), &equiv = domaine.equiv();
130 int i, j, k, l, e, eb, f, fb, fd, fc;
131
132 ch.fcl();
133
134 Stencil stencil(0, 2);
135
136 for (f = 0; f < domaine.nb_faces_tot(); f++)
137 if (f_e(f, 0) >= 0 && (f_e(f, 1) >= 0 || ch.fcl()(f, 0) == 1 || ch.fcl()(f, 0) == 3))
138 {
139 for (i = 0; i < 2; i++)
140 if ((e = f_e(f, i)) >= 0)
141 {
142 for (k = 0; k < e_f.dimension(1) && (fb = e_f(e, k)) >= 0; k++)
143 if (fb < domaine.nb_faces() && ch.fcl()(fb, 0) < 2) //partie "faces"
144 {
145 if ((fc = equiv(f, i, k)) >= 0 || f_e(f, 1) < 0)
146 for (j = 0; j < 2; j++) //equivalence : face fd -> face fb
147 {
148 fd = (j == i ? fb : fc); //element/face sources
149 if (fd >= 0) stencil.append_line(fb,fd);
150 }
151 else for (j = 0; j < 2; j++) //pas d'equivalence : n_f * operateur aux elements
152 {
153 for (eb = f_e(f, j), l = 0; l < e_f.dimension(1) && (fc = e_f(eb, l)) >= 0; l++)
154 stencil.append_line(fb,fc);
155 }
156 }
157 }
158 }
159
160 // Tri et suppression des doublons
161 tableau_trier_retirer_doublons(stencil);
162
163 // Allocation de la matrice
164 int taille = domaine.nb_faces_tot() + (dimension < 3 ? domaine.domaine().nb_som_tot() : domaine.domaine().nb_aretes_tot());
165 Matrix_tools::allocate_morse_matrix(taille, taille, stencil, mat);
166}
167
168// ajoute la contribution de la convection au second membre resu
169// renvoie resu
170
171DoubleTab& Op_Conv_EF_Stab_PolyMAC_CDO_Face::ajouter(const DoubleTab& inco, DoubleTab& secmem) const
172{
174 return Operateur_base::ajouter(inco, secmem);
175
176 const Domaine_PolyMAC_CDO& domaine = le_dom_poly_.valeur();
177 const Champ_Face_PolyMAC_CDO& ch = ref_cast(Champ_Face_PolyMAC_CDO, equation().inconnue());
178 const Conds_lim& cls = la_zcl_poly_->les_conditions_limites();
179
180 const IntTab& f_e = domaine.face_voisins(), &e_f = domaine.elem_faces(), &equiv = domaine.equiv();
181 const DoubleTab& xp = domaine.xp(), &xv = domaine.xv(), &vfd = domaine.volumes_entrelaces_dir(), &vit = vitesse_->valeurs();
182 const DoubleVect& fs = domaine.face_surfaces(), &ve = domaine.volumes(), &pf = porosite_f, &pe = porosite_e;
183 const DoubleTab& nf = domaine.face_normales();
184
185 int i, j, k, l, e, eb, f, fb, fc, fd, m, n, N = inco.line_size(), d, D = dimension, comp = !incompressible_;
186 double mult;
187
188 assert(N == 1);
189 DoubleTrav dfac(2, N, N);
190 double sum_dfac[2];
191 const int nb_faces_tot = domaine.nb_faces_tot();
192 const int nb_faces = domaine.nb_faces();
193 int nb_face_elem = e_f.dimension(1);
194 for (f = 0; f < nb_faces_tot; f++)
195 {
196 const int elem0 = f_e(f, 0);
197 const int elem1 = f_e(f, 1);
198 if (elem0 >= 0 && (elem1 >= 0 || ch.fcl()(f, 0) == 1 || ch.fcl()(f, 0) == 3))
199 {
200 //masse : diagonale + masse ajoutee si correlation
201 const double inv_masse = 1.0 / (std::fabs(vit[f]) > 1e-10 ? inco(f) / vit[f] : 1.0);
202 for (i = 0, dfac = 0; i < 2; i++)
203 {
204 //contribution a dfac
205 for (eb = f_e(f, i), n = 0; n < N; n++)
206 {
207 for (m = 0; m < N; m++)
208 dfac(ch.fcl()(f, 0) == 1 ? 0 : i, n, m) += fs(f) * inco[f] * pe(eb >= 0 ? eb : elem0)
209 * (1. + (vit[f] * (i ? -1 : 1) >= 0 ? 1. : vit[f] ? -1.
210 : 0.) *
211 alpha_) * 0.5;
212 }
213 sum_dfac[i] = 0;
214 for (n = 0; n < N; n++)
215 for (m = 0; m < N; m++)
216 sum_dfac[i] += dfac(i, n, m);
217 }
218 for (i = 0; i < 2; i++)
219 if ((e = f_e(f, i)) >= 0)
220 {
221 double inv_ve = 1.0 / ve(e);
222 for (k = 0; k < nb_face_elem && (fb = e_f(e, k)) >= 0; k++)
223 if (fb < nb_faces && ch.fcl()(fb, 0) < 2) //partie "faces"
224 {
225 if ((fc = equiv(f, i, k)) >= 0 || elem1 < 0)
226 for (j = 0; j < 2; j++) //equivalence : face fd -> face fb
227 {
228 eb = f_e(f, j), fd = (j == i ? fb : fc); //element/face sources
229 mult = (fd < 0 || domaine.dot(&nf(fb, 0), &nf(fd, 0)) > 0 ? 1 : -1) *
230 (fd >= 0 ? pf(fd) / pe(eb) : 1); //multiplicateur pour passer de vf a ve
231 for (n = 0; n < N; n++)
232 for (m = 0; m < N; m++)
233 if (dfac(j, n, m))
234 {
235 double fac = (e == elem0 ? 1 : -1) * vfd(fb, e != f_e(fb, 0)) *
236 dfac(j, n, m) * inv_ve;
237 if (fd >= 0)
238 secmem[fb] -= fac * mult * vit[fd]; //autre face calculee
239 else
240 {
241 const Cond_lim_base& my_cl = cls[ch.fcl()(f, 1)].valeur();
242 if (sub_type(Dirichlet, my_cl)) // sinon : paroi -> pas de contrib
243 for (d = 0; d < D; d++) //CL de Dirichlet
244 secmem[fb] -= fac * nf(fb, d) / fs(fb) *
245 ref_cast(Dirichlet, my_cl).val_imp(
246 ch.fcl()(f, 2), N * d + m) * inv_masse;
247 }
248 if (comp) secmem[fb] += fac * vit[fb]; //partie v div(alpha rho v)
249 }
250 }
251 else
252 {
253 for (j = 0; j < 2; j++) //pas d'equivalence : n_f * operateur aux elements
254 {
255 for (eb = f_e(f, j), l = 0; l < nb_face_elem && (fc = e_f(eb, l)) >= 0; l++)
256 {
257 double num =
258 (e == f_e(fb, 0) ? 1 : -1) * (e == elem0 ? 1 : -1) * fs(fc) * fs(fb) *
259 domaine.dot(&xv(fc, 0), &xv(fb, 0), &xp(eb, 0), &xp(e, 0)) *
260 (eb == f_e(fc, 0) ? 1 : -1);
261 double den = ve(eb) * ve(e);
262 if (std::fabs(num) > 1e-9 * den)
263 {
264 double num_den = num / den;
265 secmem[fb] -= sum_dfac[j] * num_den * vit[fc];
266 }
267 }
268 if (comp)
269 for (l = 0; l < nb_face_elem && (fc = e_f(e, l)) >= 0; l++)
270 {
271 double num = (e == f_e(fb, 0) ? 1 : -1) * (e == elem0 ? 1 : -1) * fs(fc) *
272 fs(fb) *
273 domaine.dot(&xv(fc, 0), &xv(fb, 0), &xp(e, 0), &xp(e, 0)) *
274 (e == f_e(fc, 0) ? 1 : -1);
275 double den = ve(e) * ve(e);
276 if (std::fabs(num) > 1e-9 * den)
277 {
278 double num_den = num / den;
279 secmem[fb] += sum_dfac[j] * num_den * vit[fc];
280 }
281 }
282 }
283 }
284 }
285 }
286 }
287 }
288
289 return secmem;
290}
291
292/*! @brief on assemble la matrice.
293 *
294 */
295inline void Op_Conv_EF_Stab_PolyMAC_CDO_Face::contribuer_a_avec(const DoubleTab& inco, Matrice_Morse& matrice) const
296{
298 {
300 return;
301 }
302
303 const Domaine_PolyMAC_CDO& domaine = le_dom_poly_.valeur();
304 const Champ_Face_PolyMAC_CDO& ch = ref_cast(Champ_Face_PolyMAC_CDO, equation().inconnue());
305 const IntTab& f_e = domaine.face_voisins(), &e_f = domaine.elem_faces(), &equiv = domaine.equiv();
306 const DoubleTab& xp = domaine.xp(), &xv = domaine.xv(), &vfd = domaine.volumes_entrelaces_dir(), &vit = vitesse_->valeurs();
307 const DoubleVect& fs = domaine.face_surfaces(), &ve = domaine.volumes(), &pf = porosite_f, &pe = porosite_e;
308 const DoubleTab& nf = domaine.face_normales();
309
310 int i, j, k, l, e, eb, f, fb, fc, fd, m, n, N = inco.line_size(), comp = !incompressible_;
311 double mult;
312
313 assert(N == 1);
314 DoubleTrav dfac(2, N, N), masse(N, N);
315 for (f = 0; f < domaine.nb_faces_tot(); f++)
316 if (f_e(f, 0) >= 0 && (f_e(f, 1) >= 0 || ch.fcl()(f, 0) == 1 || ch.fcl()(f, 0) == 3))
317 {
318 for (i = 0, dfac = 0; i < 2; i++)
319 {
320 //masse : diagonale + masse ajoutee si correlation
321 masse(0, 0) = std::fabs(vit[f]) > 1e-10 ? inco(f) / vit[f] : 1.0;
322 //contribution a dfac
323 for (eb = f_e(f, i), n = 0; n < N; n++)
324 for (m = 0; m < N; m++)
325 dfac( ch.fcl()(f, 0) == 1 ? 0 : i, n, m) += fs(f) * inco[f] * pe(eb >= 0 ? eb : f_e(f, 0))
326 * (1. + (vit[f] * (i ? -1 : 1) >= 0 ? 1. : vit[f] ? -1. : 0.) * alpha_) / 2;
327 }
328 for (i = 0; i < 2; i++)
329 if ((e = f_e(f, i)) >= 0)
330 {
331 for (k = 0; k < e_f.dimension(1) && (fb = e_f(e, k)) >= 0; k++)
332 if (fb < domaine.nb_faces() && ch.fcl()(fb, 0) < 2) //partie "faces"
333 {
334 if ((fc = equiv(f, i, k)) >= 0 || f_e(f, 1) < 0)
335 for (j = 0; j < 2; j++) //equivalence : face fd -> face fb
336 {
337 eb = f_e(f, j), fd = (j == i ? fb : fc); //element/face sources
338 mult = (fd < 0 || domaine.dot(&nf(fb, 0), &nf(fd, 0)) > 0 ? 1 : -1) * (fd >= 0 ? pf(fd) / pe(eb) : 1); //multiplicateur pour passer de vf a ve
339 for (n = 0; n < N; n++)
340 for (m = 0; m < N; m++)
341 if (dfac(j, n, m))
342 {
343 double fac = (e == f_e(f, 0) ? 1 : -1) * vfd(fb, e != f_e(fb, 0)) * dfac(j, n, m) / ve(e);
344 if (fd >= 0) matrice(fb,fd) += fac * mult; //autre face calculee
345 if (comp) matrice(fb,fb) -= fac; //partie v div(alpha rho v)
346 }
347 }
348 else for (j = 0; j < 2; j++) //pas d'equivalence : n_f * operateur aux elements
349 {
350 for (eb = f_e(f, j), l = 0; l < e_f.dimension(1) && (fc = e_f(eb, l)) >= 0; l++)
351 {
352 double num = (e == f_e(fb, 0) ? 1 : -1) * (e == f_e(f, 0) ? 1 : -1) * fs(fc) * fs(fb) * domaine.dot(&xv(fc, 0), &xv(fb, 0), &xp(eb, 0), &xp(e, 0)) * (eb == f_e(fc, 0) ? 1 : -1);
353 double den = ve(eb) * ve(e);
354 if (std::fabs(num) > 1e-9 * den)
355 {
356 double num_den = num/den;
357 for (n = 0; n < N; n++)
358 for (m = 0; m < N; m++)
359 if (dfac(j, n, m))
360 {
361 double fac = dfac(j, n, m) * num_den;
362 matrice(fb,fc) += fac;
363 }
364 }
365 }
366 if (comp)
367 for (l = 0; l < e_f.dimension(1) && (fc = e_f(e, l)) >= 0; l++)
368 {
369 double num = (e == f_e(fb, 0) ? 1 : -1) * (e == f_e(f, 0) ? 1 : -1) * fs(fc) * fs(fb) * domaine.dot(&xv(fc, 0), &xv(fb, 0), &xp(e, 0), &xp(e, 0)) * (e == f_e(fc, 0) ? 1 : -1);
370 double den = ve(e) * ve(e);
371 if (std::fabs(num) > 1e-9 * den)
372 {
373 double num_den = num/den;
374 for (n = 0; n < N; n++)
375 for (m = 0; m < N; m++)
376 if (dfac(j, n, m))
377 {
378 double fac = dfac(j, n, m) * num_den;
379 matrice(fb,fc) -= fac;
380 }
381 }
382 }
383 }
384 }
385 }
386 }
387}
388
390{
391 if (flag == 0)
392 {
393 Cerr << "Compressible form of operator \"" << que_suis_je() << "\" :" << finl;
394 Cerr << "Discretization of \u2207(inco \u2297 v) - v \u2207.(inco)" << finl;
395 }
396 incompressible_ = flag;
397}
const IntTab & fcl() const
classe Cond_lim_base Classe de base pour la hierarchie des classes qui representent les differentes c...
classe Conds_lim Cette classe represente un vecteur de conditions aux limites.
Definition Conds_lim.h:32
classe Dirichlet Cette classe est la classe de base de la hierarchie des conditions aux limites de ty...
Definition Dirichlet.h:31
class Domaine_Poly_base
virtual const DoubleVect & face_surfaces() const
Definition Domaine_VF.h:51
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
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
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
DoubleVect & porosite_face()
Definition Milieu_base.h:62
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
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
void completer() override
Associe l'operateur au domaine_dis, le domaine_Cl_dis, et a l'inconnue de son equation.
void dimensionner(Matrice_Morse &mat) const override
DOES NOTHING - to override in derived classes.
DoubleTab & ajouter(const DoubleTab &inco, DoubleTab &resu) const override
void contribuer_a_avec(const DoubleTab &, Matrice_Morse &) const override
on assemble la matrice.
double calculer_dt_stab() const override
Calcul dt_stab.
void completer() override
Associe l'operateur au domaine_dis, le domaine_Cl_dis, et a l'inconnue de son equation.
virtual void contribuer_a_avec(const DoubleTab &, Matrice_Morse &) const
DOES NOTHING - to override in derived classes.
virtual int has_interface_blocs() const
virtual void dimensionner(Matrice_Morse &) const
DOES NOTHING - to override in derived classes.
virtual DoubleTab & ajouter(const DoubleTab &, DoubleTab &) const
static double mp_min(double)
Definition Process.cpp:386
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
void append_line(_TYPE_)
Definition TRUSTTab.tpp:213
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
int line_size() const
Definition TRUSTVect.tpp:67