TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Op_Conv_EF.h
1/****************************************************************************
2* Copyright (c) 2024, 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#ifndef Op_Conv_EF_included
17#define Op_Conv_EF_included
18
19#include <TRUSTTabs_forward.h>
20#include <Op_Conv_EF_base.h>
21#include <Champ_Uniforme.h>
22#include <Probleme_base.h>
23#include <Op_Diff_EF.h>
24#include <Motcle.h>
25#include <Entree.h>
26#include <Debog.h>
27
28enum class AJOUTE_COND { GEN , D3_81 , D3_82 , D2_41 , D2_42 };
29
30/*! @brief class Op_Conv_EF Cette classe represente l'operateur de convection associe a une equation de
31 *
32 * transport d'un scalaire.
33 * La discretisation est EF
34 * Le champ convecte est scalaire ou vecteur de type Champ_P1NC
35 * Le schema de convection est du type Decentre ou Centre
36 *
37 */
39{
40 Declare_instanciable(Op_Conv_EF);
41public:
42
43 DoubleTab& ajouter(const DoubleTab& , DoubleTab& ) const override;
44 DoubleTab& ajouter_a_la_diffusion(const DoubleTab& , DoubleTab& ) const;
45
46 double calculer_dt_stab() const override ;
47
48 //virtual void remplir_fluent() const;
49 // Methodes pour l implicite.
50 inline void dimensionner(Matrice_Morse& matrice) const override { Op_EF_base::dimensionner(le_dom_EF.valeur(),la_zcl_EF.valeur(), matrice); }
51 inline void modifier_pour_Cl(Matrice_Morse& matrice, DoubleTab& secmem) const override { Op_EF_base::modifier_pour_Cl(le_dom_EF.valeur(),la_zcl_EF.valeur(), matrice, secmem); }
52 inline void contribuer_a_avec(const DoubleTab& inco, Matrice_Morse& matrice) const override { ajouter_contribution(inco, matrice); }
53 inline void contribuer_au_second_membre(DoubleTab& resu) const override { contribue_au_second_membre(resu); }
54 void contribue_au_second_membre(DoubleTab& ) const;
55 void ajouter_contribution_sous_cond(const DoubleTab& transporte, Matrice_Morse& matrice,int btd_impl,int hourglass_impl,int centre_impl ) const;
56 void ajouter_contribution(const DoubleTab&, Matrice_Morse& ) const;
57 void ajouter_contribution_a_la_diffusion(const DoubleTab&, Matrice_Morse& ) const;
58 void contribue_au_second_membre_a_la_diffusion(DoubleTab& resu) const;
59
60 DoubleTab& ajouter_sous_cond(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
61 virtual double coefficient_btd() const;
62 void completer() override;
63 double get_btd() const { return btd_; }
64 const Champ_base& get_champ(const Motcle& nom) const override;
65 bool has_champ(const Motcle& nom, OBS_PTR(Champ_base) &ref_champ) const override;
66 bool has_champ(const Motcle& nom) const override;
67
68protected:
69 double hourglass;
70 int hourglass_impl_,btd_impl_,centre_impl_; // flag pour savoir si les termes sont implicites
72 double f_lu_;
76
77 // pour supg
78 mutable double max_ue_=1e-8,min_dx_=1e37;// comme G2
80
81// optimisation
82 DoubleTab& ajouter_sous_cond_gen(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
83 DoubleTab& ajouter_sous_cond_dim3_nbn8_nbdim1(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
84 DoubleTab& ajouter_sous_cond_dim3_nbn8_nbdim2(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
85 DoubleTab& ajouter_sous_cond_dim2_nbn4_nbdim1(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
86 DoubleTab& ajouter_sous_cond_dim2_nbn4_nbdim2(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
87 double btd_=-1.;
88
89 template <AJOUTE_COND _COND_>
90 DoubleTab& ajouter_sous_cond_template(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
91};
92
94{
95 Declare_instanciable(Op_Conv_BTD_EF);
96 double coefficient_btd() const override;
97 void completer() override;
98protected:
99 double facteur_=-100.;
100};
101
102template <AJOUTE_COND _COND_>
103DoubleTab& Op_Conv_EF::ajouter_sous_cond_template(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const
104{
105 static constexpr bool IS_GEN = (_COND_ == AJOUTE_COND::GEN), IS_D3_81 = (_COND_ == AJOUTE_COND::D3_81), IS_D3_82 = (_COND_ == AJOUTE_COND::D3_82),
106 IS_D2_41 = (_COND_ == AJOUTE_COND::D2_41), IS_D2_42 = (_COND_ == AJOUTE_COND::D2_42);
107
108 const Domaine_EF& domaine_ef = ref_cast(Domaine_EF, le_dom_EF.valeur());
109 const int nb_som_elem = (IS_D3_81 || IS_D3_82) ? 8 : ( (IS_D2_41 || IS_D2_42) ? 4 : domaine_ef.domaine().nb_som_elem() /* IS_GEN */);
110
111 if ((btd_impl == 1) && (hourglass_impl == 1) && (centre_impl == 1))
112 return resu;
113
114
115 const Champ_Inc_base& la_vitesse = vitesse_.valeur();
116 const DoubleTab& G = la_vitesse.valeurs();
117
118 int transport_rhou = 0;
119 if (vitesse_->le_nom() == "rho_u") transport_rhou = 1;
120
121 const DoubleTab& rho_elem = (transport_rhou == 1 ? equation().probleme().get_champ("masse_volumique_melange").valeurs() : equation().probleme().get_champ("masse_volumique").valeurs());
122 int is_not_rho_unif = (rho_elem.size() == 1 ? 0 : 1);
123
124 Debog::verifier("conv vitesse", G);
125 Debog::verifier("conv rho", rho_elem);
126 Debog::verifier("conv transporte", transporte);
127
128 const int nb_comp0 = resu.line_size(), nb_elem_tot = domaine_ef.domaine().nb_elem_tot();
129 const DoubleVect& volumes_thilde = domaine_ef.volumes_thilde(), & volumes = domaine_ef.volumes();
130 const DoubleTab& IPhi_thilde = domaine_ef.IPhi_thilde(), & bij = domaine_ef.Bij();
131
132 const IntTab& elems = domaine_ef.domaine().les_elems();
133 double f = coefficient_btd();
134
135 int mcoef3d[8] = { 1, -1, -1, 1, -1, 1, 1, -1 };
136 int sommetoppose[8] = { 7, 6, 5, 4, 3, 2, 1, 0 };
137
138 DoubleTab transp_loc(nb_som_elem, nb_comp0);
139 // A DEPLACER !!!!!
140 const DoubleTab& lambda = ref_cast(Operateur_Diff_base,equation().operateur(0).l_op_base()).diffusivite().valeurs();
141 int is_not_lambda_unif = 1;
142 if (lambda.size() == 1)
143 is_not_lambda_unif = 0;
144
145 const int const_dimension = (IS_D3_81 || IS_D3_82) ? 3 : ( (IS_D2_41 || IS_D2_42) ? 2 : Objet_U::dimension /* IS_GEN */);
146 const int nb_comp = IS_D3_82 ? 3 : ((IS_D3_81 || IS_D2_41) ? 1 : ( IS_D2_42 ? 2 : nb_comp0 /* IS_GEN */));
147 const int dim_fois_nbn = (IS_D3_81 || IS_D3_82) ? 24 : ( (IS_D2_41 || IS_D2_42) ? 8 : -100 /* IS_GEN, inutile */);
148
149 if (nb_comp0 != nb_comp)
150 abort();
151
152 ArrOfDouble G_e(const_dimension);
153 ArrOfDouble pr(nb_comp),ge_bij(nb_som_elem);
154
155 const double *bij_ptr = bij.addr();
156 const double *transp_loc_ptr = transp_loc.addr();
157 const double *transporte_ptr = transporte.addr();
158 double *resu_ptr = resu.addr();
159
160#define bij_(elem,i,j) (IS_GEN ? bij(elem,i,j) : bij_ptr[elem*dim_fois_nbn+i*const_dimension+j])
161#define transp_loc_(som,a) (IS_GEN ? transp_loc(som,a) :transp_loc_ptr[som*nb_comp+a])
162#define transporte_(som,a) (IS_GEN ? transporte(som,a) : transporte_ptr[som*nb_comp+a])
163#define resu_(som,a) (IS_GEN ? resu(som,a) : resu_ptr[som*nb_comp+a])
164
165 double inv_nb_som_elem = 1. / nb_som_elem;
166 for (int elem = 0; elem < nb_elem_tot; elem++)
167 if (elem_contribue(elem))
168 {
169 G_e = 0;
170 for (int i1 = 0; i1 < nb_som_elem; i1++)
171 {
172 int glob = elems(elem, i1);
173 for (int b = 0; b < const_dimension; b++)
174 G_e[b] += G(glob, b);
175 for (int a = 0; a < nb_comp; a++)
176 transp_loc(i1, a) = transporte_(glob, a);
177 }
178 G_e *= inv_nb_som_elem;
179
180 double vol_elem = volumes(elem);
181 double inv_vol_elem = 1. / vol_elem;
182 double pond2 = volumes_thilde(elem) * inv_vol_elem * inv_vol_elem;
183
184 if (transport_rhou)
185 pond2 /= (is_not_rho_unif ? rho_elem(elem) : rho_elem(0, 0));
186 double fpond2 = f * pond2;
187
188 if ((hourglass) && (nb_som_elem == 8) && (hourglass_impl == 0))
189 {
190 double pond3 = f * dotproduct_array(G_e, G_e);
191 if (transport_rhou)
192 pond3 /= (is_not_rho_unif ? rho_elem(elem) : rho_elem(0, 0));
193 if (is_not_lambda_unif)
194 pond3 += lambda(elem);
195 else
196 pond3 += lambda(0, 0);
197 pond3 *= volumes_thilde(elem) * inv_vol_elem * pow(vol_elem, 0.3333333333333333);
198 pond3 *= hourglass;
199
200 for (int a = 0; a < nb_comp; a++)
201 {
202 double coef2d = 0.042 * pond3;
203 double coef3d = coef2d * 0.5;
204
205 double t0 = -coef2d * (transp_loc_(0,a)+transp_loc_(1,a)+transp_loc_(2,a)+transp_loc_(3,a)
206 +transp_loc_(4,a)+transp_loc_(5,a)+transp_loc_(6,a)+transp_loc_(7,a));
207
208 double t3d = 0;
209 for (int i = 0; i < 8; i++)
210 t3d += mcoef3d[i] * transp_loc_(i, a);
211 t3d *= coef3d;
212 double t3db = coef3d * (transp_loc_(0,a)-transp_loc_(1,a)+transp_loc_(3,a)-transp_loc_(2,a)
213 -transp_loc_(4,a)+transp_loc_(5,a)-transp_loc_(7,a)+transp_loc_(6,a));
214 if (!est_egal(t3d, t3db, 1e-6))
215 assert(0);
216
217 for (int i = 0; i < 8; i++)
218 resu_(elems(elem,i),a)-=mcoef3d[i]*t3d+t0+coef2d*4.*(transp_loc_(i,a)+transp_loc_(sommetoppose[i],a));
219 }
220 }
221
222 {
223 for (int yy = 0; yy < nb_som_elem; yy++)
224 ge_bij[yy] = 0;
225 if ((centre_impl == 0) || (btd_impl == 0))
226 {
227 for (int i1 = 0; i1 < nb_som_elem; i1++)
228 {
229 double cb = 0;
230 for (int b = 0; b < const_dimension; b++)
231 cb += G_e[b] * bij_(elem, i1, b);
232 ge_bij[i1] = cb;
233 }
234 for (int i1 = 0; i1 < nb_som_elem; i1++)
235 {
236 double pond = 0;
237 if (centre_impl == 0)
238 pond = IPhi_thilde(elem, i1) * inv_vol_elem;
239 int glob = elems(elem, i1);
240 //pr=0;
241 for (int yy = 0; yy < nb_comp; yy++)
242 pr[yy] = 0;
243
244 double cbbtd = pond;
245 if ((btd_impl == 0) && (type_op == amont))
246 cbbtd += ge_bij[i1] * (fpond2);
247 for (int i2 = 0; i2 < nb_som_elem; i2++)
248 {
249 const double cbi2 = ge_bij[i2];
250 double coef = cbbtd * cbi2;
251 for (int a = 0; a < nb_comp; a++)
252 pr[a] -= coef * transp_loc_(i2, a);
253 }
254 for (int a = 0; a < nb_comp; a++)
255 resu_(glob,a)+=pr[a];
256 }
257 }
258 }
259 }
260
261 fluent_.echange_espace_virtuel();
262 return resu;
263
264#undef bij_
265#undef transp_loc_
266#undef transporte_
267#undef resu_
268}
269
270#endif
Classe Champ_Inc_base.
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
virtual DoubleTab & valeurs()=0
classe Champ_Uniforme Represente un champ constant dans l'espace et dans le temps.
classe Champ_base Cette classe est la base de la hierarchie des champs.
Definition Champ_base.h:43
static void verifier(const char *const msg, double)
Definition Debog.cpp:21
int_t nb_elem_tot() const
Definition Domaine.h:132
IntTab_t & les_elems()
Definition Domaine.h:129
class Domaine_EF
Definition Domaine_EF.h:59
const DoubleTab & IPhi_thilde() const
Definition Domaine_EF.h:95
const DoubleTab & Bij() const
Definition Domaine_EF.h:92
const DoubleVect & volumes_thilde() const
Definition Domaine_EF.h:85
double volumes(int i) const
Definition Domaine_VF.h:113
const Domaine & domaine() const
Probleme_base & probleme()
Renvoie le probleme associe a l'equation.
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
const Equation_base & equation() const
Renvoie la reference sur l'equation pointe par MorEqn::mon_equation.
Definition MorEqn.h:62
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
static int dimension
Definition Objet_U.h:99
double facteur_
Definition Op_Conv_EF.h:99
class Op_Conv_EF_base
OBS_PTR(Domaine_EF) le_dom_EF
class Op_Conv_EF Cette classe represente l'operateur de convection associe a une equation de
Definition Op_Conv_EF.h:39
void contribue_au_second_membre(DoubleTab &) const
int centre_impl_
Definition Op_Conv_EF.h:70
DoubleTab & ajouter_sous_cond_dim3_nbn8_nbdim1(const DoubleTab &transporte, DoubleTab &resu, int btd_impl, int hourglass_impl, int centre_impl) const
double hourglass
Definition Op_Conv_EF.h:69
int hourglass_hors_conv_
Definition Op_Conv_EF.h:71
int calcul_dt_stab_
Definition Op_Conv_EF.h:74
DoubleTab & ajouter_sous_cond_gen(const DoubleTab &transporte, DoubleTab &resu, int btd_impl, int hourglass_impl, int centre_impl) const
DoubleTab & ajouter_sous_cond_template(const DoubleTab &transporte, DoubleTab &resu, int btd_impl, int hourglass_impl, int centre_impl) const
Definition Op_Conv_EF.h:103
double f_lu_
Definition Op_Conv_EF.h:72
double calculer_dt_stab() const override
Calcul dt_stab.
Champ_Uniforme coefficient_correcteur_supg_
Definition Op_Conv_EF.h:79
void modifier_pour_Cl(Matrice_Morse &matrice, DoubleTab &secmem) const override
DOES NOTHING - to override in derived classes.
Definition Op_Conv_EF.h:51
void contribue_au_second_membre_a_la_diffusion(DoubleTab &resu) const
virtual double coefficient_btd() const
double get_btd() const
Definition Op_Conv_EF.h:63
double min_dx_
Definition Op_Conv_EF.h:78
DoubleTab & ajouter_a_la_diffusion(const DoubleTab &, DoubleTab &) const
void dimensionner(Matrice_Morse &matrice) const override
DOES NOTHING - to override in derived classes.
Definition Op_Conv_EF.h:50
const Champ_base & get_champ(const Motcle &nom) const override
void ajouter_contribution_a_la_diffusion(const DoubleTab &, Matrice_Morse &) const
DoubleTab & ajouter_sous_cond_dim3_nbn8_nbdim2(const DoubleTab &transporte, DoubleTab &resu, int btd_impl, int hourglass_impl, int centre_impl) const
DoubleTab & ajouter(const DoubleTab &, DoubleTab &) const override
int btd_hors_conv_
Definition Op_Conv_EF.h:71
void ajouter_contribution(const DoubleTab &, Matrice_Morse &) const
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
double btd_
Definition Op_Conv_EF.h:87
DoubleTab & ajouter_sous_cond(const DoubleTab &transporte, DoubleTab &resu, int btd_impl, int hourglass_impl, int centre_impl) const
int btd_impl_
Definition Op_Conv_EF.h:70
DoubleTab & ajouter_sous_cond_dim2_nbn4_nbdim2(const DoubleTab &transporte, DoubleTab &resu, int btd_impl, int hourglass_impl, int centre_impl) const
void contribuer_a_avec(const DoubleTab &inco, Matrice_Morse &matrice) const override
DOES NOTHING - to override in derived classes.
Definition Op_Conv_EF.h:52
void ajouter_contribution_sous_cond(const DoubleTab &transporte, Matrice_Morse &matrice, int btd_impl, int hourglass_impl, int centre_impl) const
DoubleTab & ajouter_sous_cond_dim2_nbn4_nbdim1(const DoubleTab &transporte, DoubleTab &resu, int btd_impl, int hourglass_impl, int centre_impl) const
void completer() override
Associe l'operateur au domaine_dis, le domaine_Cl_dis, et a l'inconnue de son equation.
int hourglass_impl_
Definition Op_Conv_EF.h:70
void contribuer_au_second_membre(DoubleTab &resu) const override
DOES NOTHING - to override in derived classes.
Definition Op_Conv_EF.h:53
double max_ue_
Definition Op_Conv_EF.h:78
type_operateur type_op
Definition Op_Conv_EF.h:75
void dimensionner(const Domaine_EF &, const Domaine_Cl_EF &, Matrice_Morse &) const
Dimensionnement de la matrice qui devra recevoir les coefficients provenant de la convection,...
int elem_contribue(const int elem) const
void modifier_pour_Cl(const Domaine_EF &, const Domaine_Cl_EF &, Matrice_Morse &, DoubleTab &) const
Modification des coef de la matrice et du second membre pour les conditions de Dirichlet.
classe Operateur_Diff_base Cette classe est la base de la hierarchie des operateurs representant
const Champ_base & get_champ(const Motcle &nom) const override
static void abort()
Routine de sortie de Trio-U sur une erreur abort().
Definition Process.cpp:570
_TYPE_ * addr()
_SIZE_ size() const
Definition TRUSTVect.tpp:45
int line_size() const
Definition TRUSTVect.tpp:67