TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Transport_K_ou_Eps_base.cpp
1/****************************************************************************
2* Copyright (c) 2019, 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 <Transport_K_ou_Eps_base.h>
17#include <Discret_Thyd.h>
18#include <Probleme_base.h>
19#include <Schema_Temps_base.h>
20#include <Domaine_VF.h>
21#include <Param.h>
22#include <Debog.h>
23#include <communications.h>
24#include <Champ_Inc_P0_base.h>
25#include <Transport_2eq_base.h>
26
27Implemente_base(Transport_K_ou_Eps_base,"Transport_K_ou_Eps_base",Transport_2eq_base);
28
29
30// XD Transport_K_ou_Eps_base Transport_2eq_base Transport_K_ou_Eps_base BRACE Base class of the transport equations for
31// XD_CONT the uncoupled resolution version RANS models
32
33/*! @brief
34 *
35 * @param (Sortie& is) un flot de sortie
36 * @return (Sortie&) le flot de sortie modifie
37 */
39{
40 return is << que_suis_je() << "\n";
41
42}
43
44/*! @brief Simple appel a Equation_base::readOn(Entree&)
45 *
46 * @param (Entree& is) un flot d'entree
47 * @return (Entree&) le flot d'entree modifie
48 */
50{
52 return is;
53}
54
59
61{
62 if (sub_type(Discret_Thyd,discretisation()))
63 {
64 Cerr << "K,Eps transport equation ("<< que_suis_je() <<") discretization" << finl;
65 Cerr << "K_or_Eps field discretization" << finl;
66 Noms noms(1);
67 Noms unit(1);
68
69 if ( transporte_K_ )
70 {
71 Cerr << "K field discretization" << finl;
72 noms[0]="K";
73 }
74 else
75 {
76 Cerr << "Epsilon field discretization" << finl;
77 noms[0]="Eps";
78 }
79
80 unit[0]="m2/s2";
81
82 discretisation().discretiser_champ("temperature",domaine_dis(),multi_scalaire,noms,unit,1,schema_temps().nb_valeurs_temporelles(),schema_temps().temps_courant(),le_champ_);
83
84 if ( transporte_K_ )
85 le_champ_->nommer("K");
86 else
87 le_champ_->nommer("Eps");
88
89 champs_compris_.ajoute_champ(le_champ_);
90
93
95 }
96 else
97 {
98 Cerr<<" Transport_K_ou_Eps_base::discretiser "<<finl;
99 Cerr<<"Discretization "<<discretisation().que_suis_je()<<" not recognized."<<finl;
101 }
102 creer_champ( "residu" );
103}
104
105/*! @brief Controle le champ inconnue K-epsilon en forcant a zero les valeurs du champ
106 *
107 * inferieurs a 1.e-10.
108 *
109 * @return (int) renvoie toujours 1
110 */
112{
113 DoubleTab& K_ou_Eps = le_champ_->valeurs();
114 int size=K_ou_Eps.dimension(0);
115 if (size<0)
116 {
117 if (sub_type(Champ_Inc_P0_base, le_champ_.valeur()))
118 size = le_champ_->equation().domaine_dis().domaine().nb_elem();
119 else
120 {
121 Cerr << "Unsupported K_ou_Eps field in Transport_K_ou_Eps_base::controler_variable()" << finl;
122 Process::exit(-1);
123 }
124 }
125 //int size_tot=mp_sum(size);
126 // On estime pour eviter un mp_sum toujours couteux:
127 int size_tot = size * Process::nproc();
128 ArrOfInt neg(2);
129 neg=0;
130 int control=1;
131 int lquiet = modele_turbulence().get_lquiet();
132 // On interdit K-Eps negatif pour le K-Eps seulement
133 // Les autres modeles (2 couches, Launder, ne sont pas assez valides)
134
135 const Domaine_VF& domaine_vf = ref_cast(Domaine_VF,domaine_dis());
136
137 double Le_MIN = modele_turbulence().get_EPS_MIN();
138
139 double LeEPS_MAX = modele_turbulence().get_EPS_MAX();
140
141 if ( transporte_K_ )
142 {
143 Le_MIN = modele_turbulence().get_K_MIN();
144 }
145
146 const IntTab& face_voisins = domaine_vf.face_voisins();
147 const IntTab& elem_faces = domaine_vf.elem_faces();
148 // PL on ne fixe au seuil minimum que si negatifs
149 // car la loi de paroi peut fixer a des valeurs tres petites
150 // et le rapport K*K/eps est coherent
151 // Changement: 13/12/07: en cas de valeurs negatives pour k OU eps
152 // on fixe k ET eps a une valeur moyenne des 2 elements voisins
153 Nom position;
154 Debog::verifier("Transport_K_ou_Eps_base::controler_variable before",K_ou_Eps);
155 for (int n=0; n<size; n++)
156 {
157 double& var = K_ou_Eps(n);
158 if (var < 0)
159 {
160 neg[0] += ( var<0 ? 1 : 0);
161
162 position="x=";
163 position+=(Nom)domaine_vf.xv(n,0);
164 position+=" y=";
165 position+=(Nom)domaine_vf.xv(n,1);
166 if (dimension==3)
167 {
168 position+=" z=";
169 position+=(Nom)domaine_vf.xv(n,2);
170 }
171 // On impose une valeur plus physique (moyenne des elements voisins)
172 var = 0;
173 int nvar = 0;
174 int nb_faces_elem = elem_faces.line_size();
175 if (size==face_voisins.dimension(0))
176 {
177 // K or Eps on faces (eg:VEF)
178 for (int i=0; i<2; i++)
179 {
180 int elem = face_voisins(n,i);
181 if (elem!=-1)
182 for (int j=0; j<nb_faces_elem; j++)
183 if (j != n)
184 {
185 double& var_face = K_ou_Eps(elem_faces(elem,j));
186 if (var_face > Le_MIN)
187 {
188 var += var_face;
189 nvar++;
190 }
191 }
192 }
193 }
194 else
195 {
196 // K-Eps on cells (eg:VDF)
197 position="x=";
198 position+=(Nom)domaine_vf.xp(n,0);
199 position+=" y=";
200 position+=(Nom)domaine_vf.xp(n,1);
201 if (dimension==3)
202 {
203 position+=" z=";
204 position+=(Nom)domaine_vf.xp(n,2);
205 }
206 nvar = 0; // var -> var_min
207
208 }
209 if (nvar!=0) var /= nvar;
210 else var = Le_MIN;
211 if (schema_temps().limpr() && !lquiet)
212 {
213 // Warnings printed:
214 Cerr << (control ? "***Warning***: " : "***Error***: ");
215 Cerr << "k or eps forced to " << var << " on node " << n << " : " << position << finl;
216 }
217 }
218 else if ( ( var > LeEPS_MAX ) and ( ! transporte_K_ ) )
219 {
220 neg[1] += 1;
221
222 if (size==face_voisins.dimension(0))
223 {
224 // K-Eps on faces (eg:VEF)
225
226 position="x=";
227 position+=(Nom)domaine_vf.xv(n,0);
228 position+=" y=";
229 position+=(Nom)domaine_vf.xv(n,1);
230 if (dimension==3)
231 {
232 position+=" z=";
233 position+=(Nom)domaine_vf.xv(n,2);
234 }
235 }
236 else
237 {
238 // K-Eps on cells (eg:VDF)
239 position="x=";
240 position+=(Nom)domaine_vf.xp(n,0);
241 position+=" y=";
242 position+=(Nom)domaine_vf.xp(n,1);
243 if (dimension==3)
244 {
245 position+=" z=";
246 position+=(Nom)domaine_vf.xp(n,2);
247 }
248 }
249
250 var = LeEPS_MAX;
251 if (schema_temps().limpr() && !lquiet)
252 {
253 // Warnings printed:
254 Cerr << (control ? "***Warning***: " : "***Error***: ");
255
256 Cerr << "eps forced to " << var << " on node " << n << " : " << position << finl;
257 }
258 }
259 }
260
261 K_ou_Eps.echange_espace_virtuel();
262 if (schema_temps().limpr())
263 {
265 if (neg[0] )
266 {
268 {
269 const double time = le_champ_->temps();
270 Cerr << "Values forced for k or eps because:" << finl;
271 if (neg[0])
272 Cerr << "Negative values found for k or eps on " << neg[0] << "/" << size_tot << " nodes at time " << time
273 << finl;
274 // Warning if more than 0.01% of nodes are values fixed
275 double ratio_var = 100. * neg[0] / size_tot;
276 if ( ( ratio_var > 0.01 ) && !lquiet)
277 {
278 Cerr << "It is possible your initial and/or boundary conditions on k or eps are wrong." << finl;
279 Cerr << "Check the initial and boundary values for k and eps by using:" << finl;
280 Cerr << "k~" << (dimension == 2 ? "" : "3/2*") << "(t*U)^2 (t turbulence rate, U mean velocity) ";
281 Cerr
282 << "and eps~Cmu^0.75 k^1.5/l with l turbulent length scale and Cmu a k-eps model parameter whose value is typically given as 0.09."
283 << finl;
284 Cerr << "See explanations here: http://www.esi-cfd.com/esi-users/turb_parameters/" << finl;
285 Cerr
286 << "Remark : by giving the velocity field (u) and the hydraulic diameter (d), by using boundary_field_uniform_keps_from_ud and field_uniform_keps_from_ud, "
287 << finl;
288 Cerr
289 << "respectively for boudnaries and initial conditions, TRUST will determine automatically values for k and eps."
290 << finl;
291 if (probleme().is_dilatable() == 1)
292 {
293 Cerr
294 << "Please, don't forget (sorry for this TRUST syntax weakness) that when using Quasi-Compressible module"
295 << finl;
296 Cerr
297 << "the unknowns for which you define initial and boundary conditions are rho*k and rho*eps."
298 << finl;
299 }
300 }
301 }
302 if (!control && !lquiet)
303 {
304 // On quitte en postraitant pour trouver les noeuds
305 // qui posent probleme
306 Cerr << "The problem is postprocessed in order to find the nodes where K or Eps values go below 0."
307 << finl;
308 probleme().postraiter(1);
310 };
311 }
312 if ( neg[1] )
313 {
315 {
316 const double time = le_champ_->temps();
317 Cerr << "Values forced for eps because:" << finl;
318 Cerr << "Maximum values found for eps on " << neg[1] << "/" << size_tot << " nodes at time " << time
319 << finl;
320 }
321 }
322 }
323 Debog::verifier("Transport_K_ou_Eps_base::controler_variable after",K_ou_Eps);
324 return 1;
325}
326
327/*! @brief on remet eps et K positifs
328 *
329 */
334
335bool Transport_K_ou_Eps_base::has_champ(const Motcle& nom, OBS_PTR(Champ_base)& ref_champ) const
336{
337 if (nom == "residu")
338 {
339 ref_champ = Transport_K_ou_Eps_base::get_champ(nom);
340 return true;
341 }
342
343 if (Equation_base::has_champ(nom, ref_champ))
344 return true;
345
346 return false; /* rien trouve */
347}
348
350{
351 if (nom == "residu")
352 return true;
353
355 return true;
356
357 return false; /* rien trouve */
358}
359
361{
362 if (nom == "residu")
363 {
364 double temps_init = schema_temps().temps_init();
365 Champ_Fonc_base& ch = ref_cast_non_const(Champ_Fonc_base, residu_.valeur());
366 if (((ch.temps() != le_champ_->temps()) || (ch.temps() == temps_init)))
367 ch.mettre_a_jour(le_champ_->temps());
368
369 return champs_compris_.get_champ(nom);
370 }
371
372 OBS_PTR(Champ_base) ref_champ;
373
374 if (Equation_base::has_champ(nom, ref_champ))
375 return ref_champ;
376
377 throw std::runtime_error(std::string("Field ") + nom.getString() + std::string(" not found !"));
378}
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
void mettre_a_jour(double temps) override
Time update of the field.
: class Champ_Inc_P0_base
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
double temps() const
Returns the time of the field.
static void verifier(const char *const msg, double)
Definition Debog.cpp:21
class Discret_Thyd This class is the base class representing a discretization
void discretiser_champ(const Motcle &directive, const Domaine_dis_base &z, const Nom &nom, const Nom &unite, int nb_comp, int nb_pas_dt, double temps, OWN_PTR(Champ_Inc_base)&champ, const Nom &sous_type=NOM_VIDE) const
class Domaine_VF
Definition Domaine_VF.h:44
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
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void set_calculate_time_derivative(int i)
const Discretisation_base & discretisation() const
Returns the discretization associated with the equation.
int calculate_time_derivative() const
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
Probleme_base & probleme()
Returns the problem associated with the equation.
int limpr() const
Ask the time scheme if an output is needed.
void creer_champ(const Motcle &motlu) override
Schema_Temps_base & schema_temps()
Returns the time scheme associated with the equation.
virtual void discretiser()
Discretizes the equation.
Champs_compris champs_compris_
Domaine_dis_base & domaine_dis()
Returns the discretized domain associated with the equation.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
const std::string & getString() const
Definition Nom.h:92
An array of character strings (VECT(Nom)).
Definition Noms.h:26
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
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
int postraiter(int force=1) override
If force=1, performs post-processing regardless of the post-processing frequencies.
static void mp_sum_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:194
static int nproc()
Returns the number of processors in the current group. See Comm_Group::nproc() and PE_Groups::current...
Definition Process.cpp:102
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82
double temps_init() const
Returns the initial time.
Base class for output streams.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
int line_size() const
Definition TRUSTVect.tpp:67
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")
Classe Transport_2eq_base Classe de base pour les equations.
void set_param(Param &) const override
const Modele_turbulence_hyd_2_eq_base & modele_turbulence() const
Renvoie le modele de turbulence associe a l'equation.
OBS_PTR(Milieu_base) le_fluide
Classe de base pour l'equation de transport des modeles k_Epsilon dans une approche ou K et Epsilon s...
void discretiser() override
Discretizes the equation.
void valider_iteration() override
on remet eps et K positifs
const Champ_base & get_champ(const Motcle &nom) const override
void set_param(Param &param) const override
virtual int controler_variable()
Controle le champ inconnue K-epsilon en forcant a zero les valeurs du champ.
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override