TrioCFD 1.9.9_beta
TrioCFD documentation
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 parameter adjusting stabilization from 0 (centered scheme) to 1 (upwind scheme)
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); //sum of fluxes pf * |f| * vf, minimum volume of elements/faces affected by this flux
74
75 for (int e = 0; e < domaine.nb_elem(); e++)
76 {
77 // Compute the effective volume of the element
78 const double vol = pe(e) * ve(e);
79 flux = 0.;
80
81 // Loop over faces associated with the 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; // non-existent face
86
87 for (int n = 0; n < N; n++)
88 {
89 // Add incoming flux for component n: only incoming fluxes count
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 // Compute the time step for each component 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 /* just in case... */
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) //"faces" part
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++) //no equivalence: n_f * element operator
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 // Sort and remove duplicates
161 tableau_trier_retirer_doublons(stencil);
162
163 // Allocate the matrix
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// adds the convection contribution to the right-hand side resu
169// returns 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 //mass: diagonal + added mass if 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) //"faces" part
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); //multiplier to convert from vf to 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]; //other computed face
239 else
240 {
241 const Cond_lim_base& my_cl = cls[ch.fcl()(f, 1)].valeur();
242 if (sub_type(Dirichlet, my_cl)) // otherwise: wall -> no contribution
243 for (d = 0; d < D; d++) //Dirichlet BC
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]; //v div(alpha rho v) part
249 }
250 }
251 else
252 {
253 for (j = 0; j < 2; j++) //no equivalence: n_f * element operator
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 Assemble the matrix.
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 //mass: diagonal + added mass if 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) //"faces" part
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); //multiplier to convert from vf to 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; //other computed face
345 if (comp) matrice(fb,fb) -= fac; //v div(alpha rho v) part
346 }
347 }
348 else for (j = 0; j < 2; j++) //no equivalence: n_f * element operator
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
class Cond_lim_base Base class for the hierarchy of classes that represent the different boundary con...
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 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
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
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
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
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
void completer() override
Associates the operator with the domaine_dis, the domaine_Cl_dis, and the unknown of its 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
Assemble the matrix.
double calculer_dt_stab() const override
Computes dt_stab.
void completer() override
Associates the operator with the domaine_dis, the domaine_Cl_dis, and the unknown of its 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:391
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
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