TrioCFD 1.9.9_beta
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 Represents the convection operator associated with a scalar transport equation.
31 *
32 * The discretization is EF.
33 * The convected field is a scalar or vector of type Champ_P1NC.
34 * The convection scheme is of type Upwind or Centered.
35 *
36 */
38{
39 Declare_instanciable(Op_Conv_EF);
40public:
41
42 DoubleTab& ajouter(const DoubleTab& , DoubleTab& ) const override;
43 DoubleTab& ajouter_a_la_diffusion(const DoubleTab& , DoubleTab& ) const;
44
45 double calculer_dt_stab() const override ;
46
47 //virtual void remplir_fluent() const;
48 // Methods for the implicit scheme.
49 inline void dimensionner(Matrice_Morse& matrice) const override { Op_EF_base::dimensionner(le_dom_EF.valeur(),la_zcl_EF.valeur(), matrice); }
50 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); }
51 inline void contribuer_a_avec(const DoubleTab& inco, Matrice_Morse& matrice) const override { ajouter_contribution(inco, matrice); }
52 inline void contribuer_au_second_membre(DoubleTab& resu) const override { contribue_au_second_membre(resu); }
53 void contribue_au_second_membre(DoubleTab& ) const;
54 void ajouter_contribution_sous_cond(const DoubleTab& transporte, Matrice_Morse& matrice,int btd_impl,int hourglass_impl,int centre_impl ) const;
55 void ajouter_contribution(const DoubleTab&, Matrice_Morse& ) const;
56 void ajouter_contribution_a_la_diffusion(const DoubleTab&, Matrice_Morse& ) const;
57 void contribue_au_second_membre_a_la_diffusion(DoubleTab& resu) const;
58
59 DoubleTab& ajouter_sous_cond(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
60 virtual double coefficient_btd() const;
61 void completer() override;
62 double get_btd() const { return btd_; }
63 const Champ_base& get_champ(const Motcle& nom) const override;
64 bool has_champ(const Motcle& nom, OBS_PTR(Champ_base) &ref_champ) const override;
65 bool has_champ(const Motcle& nom) const override;
66
67protected:
68 double hourglass;
69 int hourglass_impl_,btd_impl_,centre_impl_; // flag to indicate whether terms are implicit
71 double f_lu_;
75
76 // for supg
77 mutable double max_ue_=1e-8,min_dx_=1e37;// like G2
79
80// optimisation
81 DoubleTab& ajouter_sous_cond_gen(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
82 DoubleTab& ajouter_sous_cond_dim3_nbn8_nbdim1(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
83 DoubleTab& ajouter_sous_cond_dim3_nbn8_nbdim2(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
84 DoubleTab& ajouter_sous_cond_dim2_nbn4_nbdim1(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
85 DoubleTab& ajouter_sous_cond_dim2_nbn4_nbdim2(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
86 double btd_=-1.;
87
88 template <AJOUTE_COND _COND_>
89 DoubleTab& ajouter_sous_cond_template(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const;
90};
91
93{
94 Declare_instanciable(Op_Conv_BTD_EF);
95 double coefficient_btd() const override;
96 void completer() override;
97protected:
98 double facteur_=-100.;
99};
100
101template <AJOUTE_COND _COND_>
102DoubleTab& Op_Conv_EF::ajouter_sous_cond_template(const DoubleTab& transporte, DoubleTab& resu,int btd_impl,int hourglass_impl,int centre_impl) const
103{
104 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),
105 IS_D2_41 = (_COND_ == AJOUTE_COND::D2_41), IS_D2_42 = (_COND_ == AJOUTE_COND::D2_42);
106
107 const Domaine_EF& domaine_ef = ref_cast(Domaine_EF, le_dom_EF.valeur());
108 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 */);
109
110 if ((btd_impl == 1) && (hourglass_impl == 1) && (centre_impl == 1))
111 return resu;
112
113
114 const Champ_Inc_base& la_vitesse = vitesse_.valeur();
115 const DoubleTab& G = la_vitesse.valeurs();
116
117 int transport_rhou = 0;
118 if (vitesse_->le_nom() == "rho_u") transport_rhou = 1;
119
120 const DoubleTab& rho_elem = (transport_rhou == 1 ? equation().probleme().get_champ("masse_volumique_melange").valeurs() : equation().probleme().get_champ("masse_volumique").valeurs());
121 int is_not_rho_unif = (rho_elem.size() == 1 ? 0 : 1);
122
123 Debog::verifier("conv vitesse", G);
124 Debog::verifier("conv rho", rho_elem);
125 Debog::verifier("conv transporte", transporte);
126
127 const int nb_comp0 = resu.line_size(), nb_elem_tot = domaine_ef.domaine().nb_elem_tot();
128 const DoubleVect& volumes_thilde = domaine_ef.volumes_thilde(), & volumes = domaine_ef.volumes();
129 const DoubleTab& IPhi_thilde = domaine_ef.IPhi_thilde(), & bij = domaine_ef.Bij();
130
131 const IntTab& elems = domaine_ef.domaine().les_elems();
132 double f = coefficient_btd();
133
134 int mcoef3d[8] = { 1, -1, -1, 1, -1, 1, 1, -1 };
135 int sommetoppose[8] = { 7, 6, 5, 4, 3, 2, 1, 0 };
136
137 DoubleTab transp_loc(nb_som_elem, nb_comp0);
138 // A DEPLACER !!!!!
139 const DoubleTab& lambda = ref_cast(Operateur_Diff_base,equation().operateur(0).l_op_base()).diffusivite().valeurs();
140 int is_not_lambda_unif = 1;
141 if (lambda.size() == 1)
142 is_not_lambda_unif = 0;
143
144 const int const_dimension = (IS_D3_81 || IS_D3_82) ? 3 : ( (IS_D2_41 || IS_D2_42) ? 2 : Objet_U::dimension /* IS_GEN */);
145 const int nb_comp = IS_D3_82 ? 3 : ((IS_D3_81 || IS_D2_41) ? 1 : ( IS_D2_42 ? 2 : nb_comp0 /* IS_GEN */));
146 const int dim_fois_nbn = (IS_D3_81 || IS_D3_82) ? 24 : ( (IS_D2_41 || IS_D2_42) ? 8 : -100 /* IS_GEN, inutile */);
147
148 if (nb_comp0 != nb_comp)
149 abort();
150
151 ArrOfDouble G_e(const_dimension);
152 ArrOfDouble pr(nb_comp),ge_bij(nb_som_elem);
153
154 const double *bij_ptr = bij.addr();
155 const double *transp_loc_ptr = transp_loc.addr();
156 const double *transporte_ptr = transporte.addr();
157 double *resu_ptr = resu.addr();
158
159#define bij_(elem,i,j) (IS_GEN ? bij(elem,i,j) : bij_ptr[elem*dim_fois_nbn+i*const_dimension+j])
160#define transp_loc_(som,a) (IS_GEN ? transp_loc(som,a) :transp_loc_ptr[som*nb_comp+a])
161#define transporte_(som,a) (IS_GEN ? transporte(som,a) : transporte_ptr[som*nb_comp+a])
162#define resu_(som,a) (IS_GEN ? resu(som,a) : resu_ptr[som*nb_comp+a])
163
164 double inv_nb_som_elem = 1. / nb_som_elem;
165 for (int elem = 0; elem < nb_elem_tot; elem++)
166 if (elem_contribue(elem))
167 {
168 G_e = 0;
169 for (int i1 = 0; i1 < nb_som_elem; i1++)
170 {
171 int glob = elems(elem, i1);
172 for (int b = 0; b < const_dimension; b++)
173 G_e[b] += G(glob, b);
174 for (int a = 0; a < nb_comp; a++)
175 transp_loc(i1, a) = transporte_(glob, a);
176 }
177 G_e *= inv_nb_som_elem;
178
179 double vol_elem = volumes(elem);
180 double inv_vol_elem = 1. / vol_elem;
181 double pond2 = volumes_thilde(elem) * inv_vol_elem * inv_vol_elem;
182
183 if (transport_rhou)
184 pond2 /= (is_not_rho_unif ? rho_elem(elem) : rho_elem(0, 0));
185 double fpond2 = f * pond2;
186
187 if ((hourglass) && (nb_som_elem == 8) && (hourglass_impl == 0))
188 {
189 double pond3 = f * dotproduct_array(G_e, G_e);
190 if (transport_rhou)
191 pond3 /= (is_not_rho_unif ? rho_elem(elem) : rho_elem(0, 0));
192 if (is_not_lambda_unif)
193 pond3 += lambda(elem);
194 else
195 pond3 += lambda(0, 0);
196 pond3 *= volumes_thilde(elem) * inv_vol_elem * pow(vol_elem, 0.3333333333333333);
197 pond3 *= hourglass;
198
199 for (int a = 0; a < nb_comp; a++)
200 {
201 double coef2d = 0.042 * pond3;
202 double coef3d = coef2d * 0.5;
203
204 double t0 = -coef2d * (transp_loc_(0,a)+transp_loc_(1,a)+transp_loc_(2,a)+transp_loc_(3,a)
205 +transp_loc_(4,a)+transp_loc_(5,a)+transp_loc_(6,a)+transp_loc_(7,a));
206
207 double t3d = 0;
208 for (int i = 0; i < 8; i++)
209 t3d += mcoef3d[i] * transp_loc_(i, a);
210 t3d *= coef3d;
211 double t3db = coef3d * (transp_loc_(0,a)-transp_loc_(1,a)+transp_loc_(3,a)-transp_loc_(2,a)
212 -transp_loc_(4,a)+transp_loc_(5,a)-transp_loc_(7,a)+transp_loc_(6,a));
213 if (!est_egal(t3d, t3db, 1e-6))
214 assert(0);
215
216 for (int i = 0; i < 8; i++)
217 resu_(elems(elem,i),a)-=mcoef3d[i]*t3d+t0+coef2d*4.*(transp_loc_(i,a)+transp_loc_(sommetoppose[i],a));
218 }
219 }
220
221 {
222 for (int yy = 0; yy < nb_som_elem; yy++)
223 ge_bij[yy] = 0;
224 if ((centre_impl == 0) || (btd_impl == 0))
225 {
226 for (int i1 = 0; i1 < nb_som_elem; i1++)
227 {
228 double cb = 0;
229 for (int b = 0; b < const_dimension; b++)
230 cb += G_e[b] * bij_(elem, i1, b);
231 ge_bij[i1] = cb;
232 }
233 for (int i1 = 0; i1 < nb_som_elem; i1++)
234 {
235 double pond = 0;
236 if (centre_impl == 0)
237 pond = IPhi_thilde(elem, i1) * inv_vol_elem;
238 int glob = elems(elem, i1);
239 //pr=0;
240 for (int yy = 0; yy < nb_comp; yy++)
241 pr[yy] = 0;
242
243 double cbbtd = pond;
244 if ((btd_impl == 0) && (type_op == amont))
245 cbbtd += ge_bij[i1] * (fpond2);
246 for (int i2 = 0; i2 < nb_som_elem; i2++)
247 {
248 const double cbi2 = ge_bij[i2];
249 double coef = cbbtd * cbi2;
250 for (int a = 0; a < nb_comp; a++)
251 pr[a] -= coef * transp_loc_(i2, a);
252 }
253 for (int a = 0; a < nb_comp; a++)
254 resu_(glob,a)+=pr[a];
255 }
256 }
257 }
258 }
259
260 fluent_.echange_espace_virtuel();
261 return resu;
262
263#undef bij_
264#undef transp_loc_
265#undef transporte_
266#undef resu_
267}
268
269#endif
Class Champ_Inc_base.
DoubleTab & valeurs() override
Returns the array of field values at the current time.
virtual DoubleTab & valeurs()=0
Champ_Uniforme Represents a field that is constant in space and time.
class Champ_base This class is the base of the fields hierarchy.
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:56
const DoubleTab & IPhi_thilde() const
Definition Domaine_EF.h:92
const DoubleTab & Bij() const
Definition Domaine_EF.h:89
const DoubleVect & volumes_thilde() const
Definition Domaine_EF.h:82
double volumes(int i) const
Definition Domaine_VF.h:113
const Domaine & domaine() const
Probleme_base & probleme()
Returns the problem associated with the equation.
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
A character string (Nom) in uppercase.
Definition Motcle.h:26
static int dimension
Definition Objet_U.h:94
double facteur_
Definition Op_Conv_EF.h:98
class Op_Conv_EF_base
OBS_PTR(Domaine_EF) le_dom_EF
class Op_Conv_EF Represents the convection operator associated with a scalar transport equation.
Definition Op_Conv_EF.h:38
void contribue_au_second_membre(DoubleTab &) const
int centre_impl_
Definition Op_Conv_EF.h:69
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:68
int hourglass_hors_conv_
Definition Op_Conv_EF.h:70
int calcul_dt_stab_
Definition Op_Conv_EF.h:73
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:102
double f_lu_
Definition Op_Conv_EF.h:71
double calculer_dt_stab() const override
Computes dt_stab.
Champ_Uniforme coefficient_correcteur_supg_
Definition Op_Conv_EF.h:78
void modifier_pour_Cl(Matrice_Morse &matrice, DoubleTab &secmem) const override
DOES NOTHING - to override in derived classes.
Definition Op_Conv_EF.h:50
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:62
double min_dx_
Definition Op_Conv_EF.h:77
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:49
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:70
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:86
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:69
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:51
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
Associates the operator with the domaine_dis, the domaine_Cl_dis, and the unknown of its equation.
int hourglass_impl_
Definition Op_Conv_EF.h:69
void contribuer_au_second_membre(DoubleTab &resu) const override
DOES NOTHING - to override in derived classes.
Definition Op_Conv_EF.h:52
double max_ue_
Definition Op_Conv_EF.h:77
type_operateur type_op
Definition Op_Conv_EF.h:74
void dimensionner(const Domaine_EF &, const Domaine_Cl_EF &, Matrice_Morse &) const
Sizes the matrix that will receive the coefficients from the convection and diffusion operators for t...
int elem_contribue(const int elem) const
void modifier_pour_Cl(const Domaine_EF &, const Domaine_Cl_EF &, Matrice_Morse &, DoubleTab &) const
Modification of the matrix coefficients and the right-hand side for Dirichlet conditions.
Operateur_Diff_base This class is the base of the hierarchy of operators representing.
const Champ_base & get_champ(const Motcle &nom) const override
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
_TYPE_ * addr()
_SIZE_ size() const
Definition TRUSTVect.tpp:45
int line_size() const
Definition TRUSTVect.tpp:67