TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Q1_EF.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 <Champ_Q1_EF.h>
17#include <Domaine_EF.h>
18#include <Domaine.h>
19#include <Equation_base.h>
20#include <distances_EF.h>
21#include <Dirichlet_paroi_fixe.h>
22#include <Dirichlet_paroi_defilante.h>
23#include <Equation_base.h>
24#include <Fluide_base.h>
25#include <Champ_Uniforme.h>
26#include <Modele_turbulence_hyd_base.h>
27#include <Debog.h>
28
29Implemente_instanciable(Champ_Q1_EF,"Champ_Q1_EF",Champ_Inc_Q1_base);
30
31Sortie& Champ_Q1_EF::printOn(Sortie& s) const { return s << que_suis_je() << " " << le_nom(); }
32
34{
35 lire_donnees(s) ;
36 return s ;
37}
38
40{
41 return ref_cast(Domaine_EF, le_dom_VF.valeur());
42}
43
44int Champ_Q1_EF::imprime(Sortie& os, int ncomp) const
45{
46 const Domaine_dis_base& domaine_dis = domaine_dis_base();
47 const Domaine& domaine = domaine_dis.domaine();
48 const DoubleTab& coord = domaine.coord_sommets();
49 const int nb_som = domaine.nb_som();
50 const DoubleTab& val = valeurs();
51 int som;
52 os << nb_som << finl;
53 for (som = 0; som < nb_som; som++)
54 {
55 if (dimension == 3)
56 os << coord(som, 0) << " " << coord(som, 1) << " " << coord(som, 2) << " ";
57 if (dimension == 2)
58 os << coord(som, 0) << " " << coord(som, 1) << " ";
59 if (nb_compo_ == 1)
60 os << val(som) << finl;
61 else
62 os << val(som, ncomp) << finl;
63 }
64 os << finl;
65 Cout << "Champ_Q1_EF::imprime FIN >>>>>>>>>> " << finl;
66 return 1;
67}
68
69void Champ_Q1_EF::gradient(DoubleTab& gradient_elem)
70{
71 // Compute the velocity gradient for the vorticity computation
72 // Order-1 gradient (mean value within an element)
73 // Order 1 gradient (mean value within an element)
74 const Domaine_EF& domaine_EF_ = domaine_EF();
75 const DoubleTab& vitesse = equation().inconnue().valeurs();
76 const IntTab& elems = domaine_EF_.domaine().les_elems();
77 int nb_som_elem = domaine_EF_.domaine().nb_som_elem();
78 int nb_elems = domaine_EF_.domaine().nb_elem_tot();
79 const DoubleVect& volume_thilde = domaine_EF_.volumes_thilde();
80 const DoubleTab& Bij_thilde = domaine_EF_.Bij_thilde();
81
82 assert(gradient_elem.dimension_tot(0) == nb_elems);
83 assert(gradient_elem.dimension(1) == dimension); // line
84 assert(gradient_elem.dimension(2) == dimension); // column
85
86 operator_egal(gradient_elem, 0.); // Real space only
87
88 for (int num_elem = 0; num_elem < nb_elems; num_elem++)
89 {
90 for (int a = 0; a < dimension; a++) // component number 1
91 {
92 for (int b = 0; b < dimension; b++) // component number 2
93 {
94 for (int j = 0; j < nb_som_elem; j++)
95 {
96 int s = elems(num_elem, j);
97 gradient_elem(num_elem, a, b) += vitesse(s, a) * Bij_thilde(num_elem, j, b);
98 }
99 gradient_elem(num_elem, a, b) /= volume_thilde(num_elem);
100 }
101 }
102 }
103}
104
105void Champ_Q1_EF::cal_rot_ordre1(DoubleTab& vorticite)
106{
107 const Domaine_EF& domaine_EF_ = domaine_EF();
108 int nb_elems = domaine_EF_.domaine().nb_elem_tot();
109
110 DoubleTab gradient_elem(0, dimension, dimension);
111 // the array is initialized in the gradient() method:
112 domaine_EF_.domaine().creer_tableau_elements(gradient_elem, RESIZE_OPTIONS::NOCOPY_NOINIT);
113 gradient(gradient_elem);
114 Debog::verifier("apres calcul gradient", gradient_elem);
115 int num_elem;
116 switch(dimension)
117 {
118 case 2:
119 {
120 for (num_elem = 0; num_elem < nb_elems; num_elem++)
121 {
122 vorticite(num_elem) = gradient_elem(num_elem, 1, 0) - gradient_elem(num_elem, 0, 1);
123 }
124 }
125 break;
126 case 3:
127 {
128 for (num_elem = 0; num_elem < nb_elems; num_elem++)
129 {
130 vorticite(num_elem, 0) = gradient_elem(num_elem, 2, 1) - gradient_elem(num_elem, 1, 2);
131 vorticite(num_elem, 1) = gradient_elem(num_elem, 0, 2) - gradient_elem(num_elem, 2, 0);
132 vorticite(num_elem, 2) = gradient_elem(num_elem, 1, 0) - gradient_elem(num_elem, 0, 1);
133 }
134 }
135 }
136 Debog::verifier("apres calcul vort", vorticite);
137 return;
138}
139
140void Champ_Q1_EF::calcul_y_plus(const Domaine_Cl_EF& domaine_Cl_EF, DoubleTab& y_plus)
141{
142 // Initialize the y_plus field with a negative value,
143 // so that when visualizing the field near the wall,
144 // one only needs to remove the negative values and only
145 // the wall values remain.
146
147 int ndeb, nfin, elem, l_unif;
148 double norm_tau, u_etoile, norm_v = 0, dist, d_visco = 0, visco = 1.;
149 y_plus = -1.;
150
151 const Domaine_EF& domaine_EF = ref_cast(Domaine_EF, le_dom_VF.valeur());
152 const IntTab& face_voisins = domaine_EF.face_voisins();
153 int nsom = domaine_EF.nb_som_face();
154 int nsom_elem = domaine_EF.domaine().nb_som_elem();
155 int nb_nodes_free = nsom_elem - nsom;
156 const IntTab& elems=domaine_EF.domaine().les_elems() ;
157 const Equation_base& eqn_hydr = equation();
158 const DoubleTab& vitesse = eqn_hydr.inconnue().valeurs();
159 const Fluide_base& le_fluide = ref_cast(Fluide_base, eqn_hydr.milieu());
160 const Champ_Don_base& ch_visco_cin = le_fluide.viscosite_cinematique();
161 const DoubleTab& tab_visco = ch_visco_cin.valeurs();
162
163 if (sub_type(Champ_Uniforme, ch_visco_cin))
164 {
165 visco = tab_visco(0, 0);
166 l_unif = 1;
167 }
168 else
169 l_unif = 0;
170
171 DoubleTab yplus_faces(1, 1); // will contain yplus values if available
172 int yplus_already_computed = 0; // flag
173
174 const RefObjU& modele_turbulence = eqn_hydr.get_modele(TURBULENCE);
175 if (modele_turbulence && sub_type(Modele_turbulence_hyd_base, modele_turbulence.valeur()))
176 {
177 const Modele_turbulence_hyd_base& mod_turb = ref_cast(Modele_turbulence_hyd_base, modele_turbulence.valeur());
178 const Turbulence_paroi_base& loipar = mod_turb.loi_paroi();
179 if (loipar.use_shear())
180 {
181 yplus_faces.resize(domaine_EF.nb_faces_tot());
182 yplus_faces.ref(loipar.tab_d_plus());
183 yplus_already_computed = 1;
184 }
185 }
186
187 ArrOfDouble vit(dimension);
188 ArrOfDouble val(dimension);
189 ArrOfDouble vit_face(dimension);
190 ArrOfInt nodes_face(nsom);
191
192 for (int n_bord = 0; n_bord < domaine_EF.nb_front_Cl(); n_bord++)
193 {
194 const Cond_lim& la_cl = domaine_Cl_EF.les_conditions_limites(n_bord);
195
196 if (sub_type(Dirichlet_paroi_fixe, la_cl.valeur()))
197 {
198 const Front_VF& le_bord = ref_cast(Front_VF, la_cl->frontiere_dis());
199 // Loop on real faces
200 ndeb = 0;
201 nfin = le_bord.nb_faces_tot();
202
203 for (int ind_face = ndeb; ind_face < nfin; ind_face++)
204 {
205
206 int num_face=le_bord.num_face(ind_face);
207 if (face_voisins(num_face, 0) != -1)
208 elem = face_voisins(num_face, 0);
209 else
210 elem = face_voisins(num_face, 1);
211
212 if (yplus_already_computed)
213 {
214 // y+ is only defined on faces so we take the face value to put in the element
215 y_plus(elem) = yplus_faces(num_face);
216 }
217 else
218 {
219 vit_face=0.;
220 nodes_face=0;
221 for(int jsom=0; jsom<nsom; jsom++)
222 {
223 int num_som = domaine_EF.face_sommets(num_face, jsom);
224 nodes_face[jsom] = num_som;
225 for(int comp=0; comp<dimension; comp++) vit_face[comp]+=vitesse(num_som,comp)/nsom;
226 }
227 vit=0.;
228 // Loop on nodes: average velocity of nodes not belonging to the BC face
229 for (int i=0; i<nsom_elem; i++)
230 {
231 int node=elems(elem,i);
232 int IOK = 1;
233 for(int jsom=0; jsom<nsom; jsom++)
234 if (nodes_face[jsom] == node) IOK=0;
235 // Le noeud contribue
236 if (IOK)
237 for (int j=0; j<dimension; j++)
238 vit[j]+=(vitesse(node,j)-vit_face[j])/nb_nodes_free; // subtracts any possible sliding velocity
239 }
240 norm_v = norm_vit_lp(vit,num_face,domaine_EF,val);
241 dist = distance_face_elem(num_face,elem,domaine_EF);
242 dist *= 2.;
243 if (l_unif)
244 d_visco = visco;
245 else
246 d_visco = tab_visco[elem];
247
248 // PQ : 01/10/03 : corrections with respect to the initial version
249 norm_tau = d_visco * norm_v / dist;
250
251 u_etoile = sqrt(norm_tau);
252 y_plus(elem) = dist * u_etoile / d_visco;
253
254 } // else yplus already computed
255 } // loop on faces
256 } // End fixed wall
257 } // End loop over boundaries
258}
class Champ_Don_base base class of Given Fields (not calculated)
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
const Domaine & domaine() const
int lire_donnees(Entree &)
Reads the field values from an input stream.
const Domaine_dis_base & domaine_dis_base() const override
DoubleTab & valeurs() override
Returns the array of field values at the current time.
int imprime(Sortie &, int) const override
const Domaine_EF & domaine_EF() const
void calcul_y_plus(const Domaine_Cl_EF &, DoubleTab &)
void gradient(DoubleTab &)
void cal_rot_ordre1(DoubleTab &)
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
static void verifier(const char *const msg, double)
Definition Debog.cpp:21
Dirichlet_paroi_fixe Represents a fixed wall in a Navier-Stokes type equation.
int nb_som_elem() const
Returns the number of vertices of the geometric elements that make up the domain.
Definition Domaine.h:474
int_t nb_elem_tot() const
Definition Domaine.h:132
virtual void creer_tableau_elements(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
Creates a parallel array of values at elements.
Definition Domaine.cpp:850
IntTab_t & les_elems()
Definition Domaine.h:129
const Cond_lim & les_conditions_limites(int) const
Returns the i-th boundary condition.
class Domaine_EF
Definition Domaine_EF.h:56
const DoubleTab & Bij_thilde() const
Definition Domaine_EF.h:90
const DoubleVect & volumes_thilde() const
Definition Domaine_EF.h:82
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
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 RefObjU & get_modele(Type_modele type) const
virtual const Champ_Inc_base & inconnue() const =0
const Nom & le_nom() const override
Returns the name of the field.
int nb_compo_
Definition Field_base.h:95
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_tot() const
Definition Front_VF.h:58
int num_face(const int) const
Definition Front_VF.h:68
Base class for the turbulence model hierarchy for Navier-Stokes equations.
const Turbulence_paroi_base & loi_paroi() const
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
Base class for output streams.
Definition Sortie.h:52
virtual void ref(const TRUSTTab &)
Definition TRUSTTab.tpp:308
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
const Objet_U & valeur() const
Definition TRUST_Ref.h:134
Base class for the hierarchy of wall-law models computing turbulent quantities near walls....
const DoubleVect & tab_d_plus() const
virtual bool use_shear() const