TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Modele_turbulence_scal_Prandtl.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 <Pb_Thermohydraulique_Turbulent_QC.h>
17#include <Modele_turbulence_scal_Prandtl.h>
18#include <Modifier_pour_fluide_dilatable.h>
19#include <Champ_Uniforme.h>
20#include <Domaine_VF.h>
21#include <Parser_U.h>
22#include <ParserView.h>
23#include <Motcle.h>
24#include <Param.h>
25
26Implemente_instanciable(Modele_turbulence_scal_Prandtl, "Modele_turbulence_scal_Prandtl", Modele_turbulence_scal_diffturb_base);
27// XD prandtl modele_turbulence_scal_base prandtl INHERITS_BRACE The Prandtl model. For the scalar equations, only the
28// XD_CONT model based on Reynolds analogy is available. If K_Epsilon was selected in the hydraulic equation, Prandtl
29// XD_CONT must be selected for the convection-diffusion temperature equation coupled to the hydraulic equation and
30// XD_CONT Schmidt for the concentration equations.
31
33
35{
37 // if a function was read, initialize the Parser
38 if (definition_fonction_ != Nom())
39 {
40 fonction_.setNbVar(2);
41 fonction_.addVar("alpha");
42 fonction_.addVar("nu_t");
44 fonction_.parseString();
45 }
46
47 if (LePrdt_fct_ != Nom())
48 {
49 fonction1_.setNbVar(3);
50 fonction1_.addVar("x");
51 fonction1_.addVar("y");
52 fonction1_.addVar("z");
53 fonction1_.setString(LePrdt_fct_);
54 fonction1_.parseString();
55 }
56 else
57 Cerr << "The default value of the turbulent Prandtl number is " << LePrdt_ << finl;
58
59 Cerr << "The expression for the turbulent Prandtl number is " << LePrdt_fct_ << finl;
60 return is;
61}
62
64{
65 param.ajouter("Prdt", &LePrdt_fct_); // XD_ADD_P chaine
66 // XD_CONT Keyword to modify the constant (Prdt) of Prandtl model : Alphat=Nut/Prdt Default value is 0.9
67 param.ajouter("Prandt_turbulent_fonction_nu_t_alpha", &definition_fonction_); // XD_ADD_P chaine
68 // XD_CONT Optional keyword to specify turbulent diffusivity (by default, alpha_t=nu_t/Prt) with another formulae, for
69 // XD_CONT example: alpha_t=nu_t2/(0,7*alpha+0,85*nu_tt) with the string nu_t*nu_t/(0,7*alpha+0,85*nu_t) where alpha
70 // XD_CONT is the thermal diffusivity.
72}
73
74/*! @brief Computes the turbulent diffusivity and applies the wall law.
75 *
76 * @param Unused time parameter.
77 */
79{
81 const Milieu_base& mil = equation().probleme().milieu();
83 loipar_->calculer_scal(diffusivite_turbulente_);
84
85 const Probleme_base& mon_pb = mon_equation_->probleme();
86 DoubleTab& lambda_t = conductivite_turbulente_->valeurs();
87 lambda_t = diffusivite_turbulente_->valeurs();
88 const bool uniforme = sub_type(Champ_Uniforme, mon_pb.milieu().capacite_calorifique());
89 const DoubleTab& tab_Cp = mon_pb.milieu().capacite_calorifique().valeurs();
90 const DoubleTab& tab_rho = mon_pb.milieu().masse_volumique().valeurs();
91 if (sub_type(Pb_Thermohydraulique_Turbulent_QC, mon_pb))
92 {
93 CDoubleArrView Cp = static_cast<const DoubleVect&>(tab_Cp).view_ro();
94 DoubleArrView lambda = static_cast<DoubleVect&>(lambda_t).view_rw();
95 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), lambda_t.size(),
96 KOKKOS_LAMBDA(
97 const int i)
98 {
99 lambda(i) *= Cp(uniforme ? 0 : i);
100 });
101 end_gpu_timer(__KERNEL_NAME__);
102 if (equation().probleme().is_dilatable())
103 multiplier_par_rho_si_dilatable(lambda_t, mil);
104 }
105 else
106 lambda_t *= mon_equation_->domaine_dis().nb_elem() > 0 ? tab_rho(0, 0) * tab_Cp(0, 0) : 1.0;
107 lambda_t.echange_espace_virtuel();
108 diffusivite_turbulente_->valeurs().echange_espace_virtuel();
109}
110
111/*! @brief Computes the turbulent diffusivity.
112 *
113 * turbulent_diffusivity = turbulent_viscosity / turbulent_Prandtl_number
114 *
115 * @return The newly computed turbulent diffusivity field.
116 * @throws If diffusivite_turbulente and viscosite_turbulente fields do not have the same number of nodal values.
117 */
119{
120 DoubleTab& tab_alpha_t = diffusivite_turbulente_->valeurs();
121 const DoubleTab& tab_nu_t = la_viscosite_turbulente_->valeurs();
122 double temps = la_viscosite_turbulente_->temps();
123
124
125 int n = tab_alpha_t.size();
126 if (tab_nu_t.size() != n)
127 {
128 Cerr << "The DoubleTab arrays of diffusivite_turbulente and viscosite_turbulente fields" << finl;
129 Cerr << "must have the same number of nodal values" << finl;
130 exit();
131 }
132
133 if (definition_fonction_ != Nom())
134 {
135 // modif VB to use the equation approaching Yakhot: LePrdt = 0.7/Pe-t + 0.85
136 // Pe-t is a turbulent Peclet number defined by Pr*(nut/nu)
137 // giving alpha_t = nut * nut / ( 0.7 alpha + 0.85 nut )
138
139 const Milieu_base& milieu = mon_equation_->milieu();
140 const Champ_Don_base& alpha = milieu.diffusivite();
141 if (!milieu.has_diffusivite())
142 {
143 // GF if this condition is blocking, we could improve by
144 // attempting to create a parser without the variable alpha; if successful, alpha exists, is constant, and equals 1.
145 Cerr << "Error in Modele_turbulence_scal_prandtl, the Prandt_turbulent_fonction_nu_t_alpha option is only available for media with a defined diffusivity" << finl;
146 exit();
147 }
148 double d_alpha = 0.;
149 const bool is_alpha_unif = sub_type(Champ_Uniforme, alpha);
150 if (is_alpha_unif)
151 d_alpha = alpha.valeurs()(0, 0);
152
153 ParserView parser(fonction_);
154 parser.parseString();
155 CDoubleArrView alpha_vals;
156 if (!is_alpha_unif) alpha_vals = static_cast<const ArrOfDouble&>(alpha.valeurs()).view_ro();
157 CDoubleArrView nu_t = static_cast<const DoubleVect&>(tab_nu_t).view_ro();
158 DoubleArrView alpha_t = static_cast<DoubleVect&>(tab_alpha_t).view_rw();
159 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), Kokkos::RangePolicy<>(0, n), KOKKOS_LAMBDA(const int i)
160 {
161 double alpha_val = is_alpha_unif ? d_alpha : alpha_vals(i);
162 int threadId = parser.acquire();
163 parser.setVar(0, alpha_val, threadId);
164 parser.setVar(1, nu_t[i], threadId);
165 alpha_t[i] = parser.eval(threadId);
166 parser.release(threadId);
167 });
168 end_gpu_timer(__KERNEL_NAME__);
169 }
170 else
171 {
172 if (LePrdt_fct_ != Nom())
173 {
174 const int nb_dim = dimension;
175 ParserView parser(fonction1_);
176 parser.parseString();
177 CDoubleTabView xp = ref_cast(Domaine_VF,mon_equation_->domaine_dis()).xp().view_ro();
178 CDoubleArrView nu_t = static_cast<const DoubleVect&>(tab_nu_t).view_ro();
179 DoubleArrView alpha_t = static_cast<DoubleVect&>(tab_alpha_t).view_rw();
180 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), Kokkos::RangePolicy<>(0, n), KOKKOS_LAMBDA(const int i)
181 {
182 double x = xp(i, 0);
183 double y = xp(i, 1);
184 double z = nb_dim == 3 ? xp(i, 2) : 0.;
185 int threadId = parser.acquire();
186 parser.setVar(0, x, threadId);
187 parser.setVar(1, y, threadId);
188 parser.setVar(2, z, threadId);
189 double NbPrandtlCell = parser.eval(threadId);
190 parser.release(threadId);
191 alpha_t[i] = nu_t[i] / NbPrandtlCell;
192 });
193 end_gpu_timer(__KERNEL_NAME__);
194 }
195 else
196 {
197 double inv_LePrdt = 1./LePrdt_;
198 // ToDo Kokkos: implement operator_mutiply(u,v,alpha);
199 // if u = v * alpha is a regular pattern in the code...
200 CDoubleArrView nu_t = static_cast<const DoubleVect&>(tab_nu_t).view_ro();
201 DoubleArrView alpha_t = static_cast<DoubleVect&>(tab_alpha_t).view_rw();
202 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__),
203 Kokkos::RangePolicy<>(0, n), KOKKOS_LAMBDA(
204 const int i)
205 {
206 alpha_t[i] = nu_t[i] * inv_LePrdt;
207 });
208 end_gpu_timer(__KERNEL_NAME__);
209 }
210 }
211
212 diffusivite_turbulente_->changer_temps(temps);
213
214 if (equation().probleme().is_dilatable())
215 diviser_par_rho_si_dilatable(diffusivite_turbulente_->valeurs(), equation().probleme().milieu());
216 return diffusivite_turbulente_.valeur();
217}
218
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
virtual DoubleTab & valeurs()=0
Champ_Uniforme Represents a field that is constant in space and time.
class Domaine_VF
Definition Domaine_VF.h:44
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Probleme_base & probleme()
Returns the problem associated with the equation.
Milieu_base This class is the base of the (physical) medium hierarchy.
Definition Milieu_base.h:50
virtual const Champ_Don_base & capacite_calorifique() const
Returns the heat capacity of the medium (const version).
virtual const Champ_Don_base & diffusivite() const
Returns the diffusivity of the medium (const version).
virtual const Champ_base & masse_volumique() const
Returns the mass density of the medium (const version).
bool has_diffusivite() const
Definition Milieu_base.h:95
Scalar turbulence model using the turbulent Prandtl number to compute turbulent diffusivity:
virtual public_for_cuda Champ_Fonc_base & calculer_diffusivite_turbulente()
Computes the turbulent diffusivity.
void mettre_a_jour(double) override
Computes the turbulent diffusivity and applies the wall law.
Convection_Diffusion_std & equation()
virtual void set_param(Param &) const override
int loi_paroi_non_nulle() const
Returns whether a wall law is set (const version).
Base class for scalar turbulence models that compute turbulent diffusivity as:
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
static int dimension
Definition Objet_U.h:94
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
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
KOKKOS_INLINE_FUNCTION int acquire() const
Definition ParserView.h:77
KOKKOS_INLINE_FUNCTION void setVar(int i, double val, int threadId) const
Definition ParserView.h:64
void parseString() override
Definition ParserView.h:52
KOKKOS_INLINE_FUNCTION void release(int threadId) const
Definition ParserView.h:79
KOKKOS_INLINE_FUNCTION double eval(int threadId) const
Definition ParserView.h:69
Turbulent thermohydraulics problem for a quasi-compressible fluid.
class Probleme_base It is a Probleme_U that is not a coupling.
virtual const Milieu_base & milieu() const
Returns the physical medium associated with the problem (const version).
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
_SIZE_ size() const
Definition TRUSTVect.tpp:45
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")