TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Paroi_negligeable_VEF.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 <Paroi_negligeable_VEF.h>
17#include <Dirichlet_paroi_fixe.h>
18#include <Modele_turbulence_hyd_base.h>
19#include <Operateur_base.h>
20#include <Champ_Uniforme.h>
21#include <distances_VEF.h>
22#include <Milieu_base.h>
23#include <Fluide_base.h>
24#include <Champ_P1NC.h>
25#include <TRUSTTrav.h>
26#include <Operateur.h>
27
28Implemente_instanciable(Paroi_negligeable_VEF, "negligeable_VEF", Paroi_hyd_base_VEF);
29
31{
32 return s << que_suis_je() << " " << le_nom();
33}
34
36{
37 return s;
38}
39
41{
43
44 // Size the elem_paroi array
45 int num_cl, fac, i;
46 const Conds_lim& les_cl = le_dom_Cl_dis_->les_conditions_limites();
47 // const IntTab& elem_faces = le_dom_VEF->elem_faces();
48 const IntTab& face_voisins = le_dom_dis_->face_voisins();
49
50 DoubleTrav Verif_elem_double(le_dom_dis_->nb_elem());
52 Verif_elem_double = 0;
53 elem_paroi.resize(le_dom_dis_->nb_faces_bord());
54 elem_paroi_double.resize(le_dom_dis_->nb_faces_bord());
55
56 for (num_cl = 0; num_cl < les_cl.size(); num_cl++)
57 {
58 const Cond_lim& la_cl = les_cl[num_cl];
59 const Front_VF& la_front_dis = ref_cast(Front_VF, la_cl->frontiere_dis());
60 int ndeb = la_front_dis.num_premiere_face();
61 int nfin = ndeb + la_front_dis.nb_faces();
62 int num1, verif;
63
64 if (sub_type(Dirichlet_paroi_fixe, la_cl.valeur()))
65 {
66 for (fac = ndeb; fac < nfin; fac++)
67 {
68 num1 = face_voisins(fac, 0);
69 if (num1 == -1)
70 num1 = face_voisins(fac, 1);
71 if (Verif_elem_double[num1] == 0)
72 {
75 Verif_elem_double[num1]++;
77 }
78 else
79 {
80 verif = 0;
81 for (i = 0; i < compteur_elem_paroi; i++)
82 {
83 if (elem_paroi[i] == num1)
84 {
85 elem_paroi_double[fac] = i;
86 verif++;
87 }
88 }
89 if (verif == 0)
90 {
91 Cerr << "There is a serious problem in the determination of elem_paroi_double" << finl;
92 }
93 }
94 }
95 }
96 }
97 elem_paroi.resize(compteur_elem_paroi); // We have all elements touching the wall by one face
98 // PBL: do we have duplicates???? -> No, because of Verif_elem_double!!
99 return 1;
100}
101
102int Paroi_negligeable_VEF::calculer_hyd_BiK(DoubleTab& tab_k, DoubleTab& tab_eps)
103{
104 return calculer_hyd(tab_k); // the value in argument is not used anyway
105}
106
107int Paroi_negligeable_VEF::calculer_hyd(DoubleTab& tab_k_eps)
108{
109
110 const Equation_base& eqn_hydr = mon_modele_turb_hyd->equation();
111 if (sub_type(Fluide_base, eqn_hydr.milieu()))
112 {
113
114 int ndeb, nfin, elem, l_unif;
115 double norm_tau, u_etoile, norm_v = 0, dist = 0, val1, val2, val3, d_visco, visco = 1.;
116 IntVect num(dimension);
117
118 const Domaine_VEF& domaine_VEF = ref_cast(Domaine_VEF, le_dom_dis_.valeur());
119 const IntTab& face_voisins = domaine_VEF.face_voisins();
120 const IntTab& elem_faces = domaine_VEF.elem_faces();
121 const Fluide_base& le_fluide = ref_cast(Fluide_base, eqn_hydr.milieu());
122 const Champ_Don_base& ch_visco_cin = le_fluide.viscosite_cinematique();
123 const DoubleTab& tab_visco = ch_visco_cin.valeurs();
124 const DoubleTab& vit = eqn_hydr.inconnue().valeurs();
125
126 if (sub_type(Champ_Uniforme, ch_visco_cin))
127 {
128 if (tab_visco(0, 0) > DMINFLOAT)
129 visco = tab_visco(0, 0);
130 else
131 visco = DMINFLOAT;
132 l_unif = 1;
133 }
134 else
135 l_unif = 0;
136 if ((!l_unif) && (tab_visco.local_min_vect() < DMINFLOAT))
137 {
138 Cerr << "In Paroi_negligeable_VEF::calculer_hyd : visco = " << tab_visco.local_min_vect() << " <= 0 ? " << finl;
139 exit();
140 }
141
142 for (int n_bord = 0; n_bord < domaine_VEF.nb_front_Cl(); n_bord++)
143 {
144 const Cond_lim& la_cl = le_dom_Cl_dis_->les_conditions_limites(n_bord);
145
146 if (sub_type(Dirichlet_paroi_fixe, la_cl.valeur()))
147 {
148 const Front_VF& le_bord = ref_cast(Front_VF, la_cl->frontiere_dis());
149 ndeb = le_bord.num_premiere_face();
150 nfin = ndeb + le_bord.nb_faces();
151 ToDo_Kokkos("To avoid an expensive copy D2H of array velocity.");
152 for (int num_face = ndeb; num_face < nfin; num_face++)
153 {
154 elem = face_voisins(num_face, 0);
155 if (dimension == 2)
156 {
157
158 num[0] = elem_faces(elem, 0);
159 num[1] = elem_faces(elem, 1);
160
161 if (num[0] == num_face)
162 num[0] = elem_faces(elem, 2);
163 else if (num[1] == num_face)
164 num[1] = elem_faces(elem, 2);
165
166 dist = distance_2D(num_face, elem, domaine_VEF);
167 dist *= 3. / 2.; // to convert to wall distance / midpoint of num[0]-num[1]
168 //norm_v=norm_2D_vit1_lp(vit,num_face,num[0],num[1],domaine_VEF,val1,val2);
169 norm_v = norm_2D_vit1(vit, num[0], num[1], num_face, domaine_VEF, val1, val2);
170
171 } // dim 2
172 else if (dimension == 3)
173 {
174
175 num[0] = elem_faces(elem, 0);
176 num[1] = elem_faces(elem, 1);
177 num[2] = elem_faces(elem, 2);
178
179 if (num[0] == num_face)
180 num[0] = elem_faces(elem, 3);
181 else if (num[1] == num_face)
182 num[1] = elem_faces(elem, 3);
183 else if (num[2] == num_face)
184 num[2] = elem_faces(elem, 3);
185
186 dist = distance_3D(num_face, elem, domaine_VEF);
187 dist *= 4. / 3.; // to convert to wall distance / midpoint of num[0]-num[1]-num[2]
188 //norm_v=norm_3D_vit1_lp(vit, num_face, num[0], num[1], num[2], domaine_VEF, val1, val2, val3);
189 norm_v = norm_3D_vit1(vit, num_face, num[0], num[1], num[2], domaine_VEF, val1, val2, val3);
190
191 } // dim 3
192
193 if (l_unif)
194 d_visco = visco;
195 else
196 d_visco = tab_visco[elem];
197
198 norm_tau = d_visco * norm_v / dist;
199 u_etoile = sqrt(norm_tau);
200 tab_u_star_(num_face) = u_etoile;
201
202 } // loop on faces
203
204 } // End of fixed wall
205
206 } // End of loop over boundaries
207
208 }
209
210 return 1;
211}
212
213// This is the one we are interested in!!!
214int Paroi_negligeable_VEF::calculer_hyd(DoubleTab& tab_nu_t, DoubleTab& tab_k)
215{
216 const Equation_base& eqn_hydr = mon_modele_turb_hyd->equation();
217 if (sub_type(Fluide_base, eqn_hydr.milieu()))
218 {
219 const Domaine_VEF& domaine_VEF = ref_cast(Domaine_VEF, le_dom_dis_.valeur());
220 const Fluide_base& le_fluide = ref_cast(Fluide_base, eqn_hydr.milieu());
221 const Champ_Don_base& ch_visco_cin = le_fluide.viscosite_cinematique();
222 const DoubleTab& tab_visco = ch_visco_cin.valeurs();
223
224 double visco0;
225 bool l_unif;
226 if (sub_type(Champ_Uniforme, ch_visco_cin))
227 {
228 if (tab_visco(0, 0) > DMINFLOAT)
229 visco0 = tab_visco(0, 0);
230 else
231 visco0 = DMINFLOAT;
232 l_unif = true;
233 }
234 else
235 {
236 visco0 = -1;
237 l_unif = false;
238 }
239 if ((!l_unif) && (tab_visco.local_min_vect() < DMINFLOAT))
240 {
241 Cerr << "In Paroi_negligeable_VEF::calculer_hyd : visco = " << tab_visco.local_min_vect() << " <= 0 ? " << finl;
242 exit();
243 }
244
245 for (int n_bord = 0; n_bord < domaine_VEF.nb_front_Cl(); n_bord++)
246 {
247 const Cond_lim& la_cl = le_dom_Cl_dis_->les_conditions_limites(n_bord);
248 if (sub_type(Dirichlet_paroi_fixe, la_cl.valeur()))
249 {
250 const Front_VF& le_bord = ref_cast(Front_VF, la_cl->frontiere_dis());
251 int ndeb = le_bord.num_premiere_face();
252 int nfin = ndeb + le_bord.nb_faces();
253 int dim = Objet_U::dimension;
254 int nfac = domaine_VEF.domaine().nb_faces_elem();
255 CDoubleTabView xp = domaine_VEF.xp().view_ro();
256 CDoubleTabView xv = domaine_VEF.xv().view_ro();
257 CDoubleTabView face_normale = domaine_VEF.face_normales().view_ro();
258 CIntTabView elem_faces = domaine_VEF.elem_faces().view_ro();
259 CIntTabView face_voisins = domaine_VEF.face_voisins().view_ro();
260 CDoubleTabView vit = eqn_hydr.inconnue().valeurs().view_ro();
261 CDoubleArrView visco = static_cast<const DoubleVect&>(tab_visco).view_ro();
262 DoubleArrView tab_u_star = tab_u_star_.view_rw();
263 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), Kokkos::RangePolicy<>(ndeb, nfin), KOKKOS_LAMBDA (const int num_face)
264 {
265 int num[3];
266 double val[3];
267 int elem = face_voisins(num_face, 0);
268 int fac = 0;
269 for (int i = 0; i < dim; i++)
270 {
271 if (elem_faces(elem, fac) == num_face) fac++;
272 num[i] = elem_faces(elem, fac);
273 fac++;
274 }
275 double dist = distance(dim, num_face, elem, xp, xv, face_normale);
276 dist *= (dim + 1.) / dim; // to convert to wall distance / midpoint of num[0]-num[1]
277 double norm_v = norm_vit1(dim, vit, num_face, nfac, num, face_normale, val);
278 double d_visco = l_unif ? visco0 : visco[elem];
279 double norm_tau = d_visco * norm_v / dist;
280 double u_etoile = sqrt(norm_tau);
281 tab_u_star(num_face) = u_etoile;
282 }); // loop on faces
283 end_gpu_timer(__KERNEL_NAME__);
284 } // End of fixed wall
285 } // End of loop over boundaries
286 }
287 return 1;
288}
289
294
296{
297 return false;
298}
class Champ_Don_base base class of Given Fields (not calculated)
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
DoubleTab & valeurs() override
Returns the array of field values at the current time.
Champ_Uniforme Represents a field that is constant in space and time.
class Cond_lim Generic class used to represent any class
Definition Cond_lim.h:31
class Conds_lim This class represents a vector of boundary conditions.
Definition Conds_lim.h:32
Dirichlet_paroi_fixe Represents a fixed wall in a Navier-Stokes type equation.
int nb_faces_elem(int=0) const
Returns the number of faces of type i of the geometric elements that make up the domain.
Definition Domaine.h:484
class Domaine_VEF
Definition Domaine_VEF.h:53
virtual double face_normales(int face, int comp) const
Definition Domaine_VF.h:47
double xv(int num_face, int k) const
Definition Domaine_VF.h:76
int elem_faces(int i, int j) const
Returns the index of the i-th face of element num_elem; the face numbering convention is.
Definition Domaine_VF.h:542
double xp(int num_elem, int k) const
Definition Domaine_VF.h:77
int face_voisins(int num_face, int i) const
Returns the neighbouring element of num_face in direction i.
Definition Domaine_VF.h:418
int nb_front_Cl() const
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Equation_base The role of an equation is the calculation of one or more fields....
virtual const Milieu_base & milieu() const =0
virtual const Champ_Inc_base & inconnue() const =0
Base class for an incompressible fluid and its properties:
Definition Fluide_base.h:36
const Champ_Don_base & viscosite_cinematique() const
Definition Fluide_base.h:56
class Front_VF
Definition Front_VF.h:36
int nb_faces() const
Definition Front_VF.h:53
int num_premiere_face() const
Definition Front_VF.h:63
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 const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Objet_U.cpp:317
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
CLASS: Paroi_hyd_base_VEF.
int calculer_hyd_BiK(DoubleTab &, DoubleTab &) override
int calculer_hyd(DoubleTab &) override
bool use_shear() const override
virtual int calculer_scal(Champ_Fonc_base &)
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
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, ConstView< _TYPE_, _SHAPE_ > > view_ro() const
Definition TRUSTTab.h:261
_TYPE_ local_min_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const
Definition TRUSTVect.h:155
const DoubleVect & tab_u_star() const