TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Loi_Etat_base.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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 <Fluide_Dilatable_base.h>
17#include <Schema_Temps_base.h>
18#include <Champ_Fonc_Tabule.h>
19#include <Champ_Uniforme.h>
20#include <Loi_Etat_base.h>
21#include <Probleme_base.h>
22#include <Domaine_VF.h>
23#include <Debog.h>
24#include <kokkos++.h>
25#include <TRUSTArray_kokkos.tpp>
26
27Implemente_base_sans_constructeur(Loi_Etat_base,"Loi_Etat_base",Objet_U);
28// XD loi_etat_base objet_u loi_etat_base INHERITS_BRACE Basic class for state laws used with a dilatable fluid.
29
31
33{
34 return os << que_suis_je() << finl;
35}
36
38{
39 return is;
40}
41
42/*! @brief Associates the fluid with the state law.
43 *
44 * @param fl The dilatable fluid to associate.
45 */
47{
48 le_fluide = fl;
49}
50
51/*! @brief Associates the problem with the state law.
52 *
53 * @param pb The problem to associate.
54 */
56{
57 le_prob_ = pb;
58}
59
60/*! @brief Returns the temperature field.
61 *
62 * @return The temperature field (const reference).
63 */
65{
66 return temperature_.valeur();
67}
68
70{
71 return temperature_.valeur();
72}
73
74/*! @brief Initialises the heat equation unknown; sets rho arrays and updates density.
75 *
76 */
78{
79 DoubleTab& tab_rho = le_fluide->masse_volumique().valeurs();
80 tab_rho_n=tab_rho;
81 tab_rho_np1=tab_rho;
83 double t = le_prob_->schema_temps().temps_courant();
85 tab_rho.echange_espace_virtuel();
86 tab_rho_np1.echange_espace_virtuel();
87}
88
89/*! @brief Prepares the fluid for computation by filling temperature and computing density.
90 *
91 */
93{
94 remplir_T();
96 double t = le_prob_->schema_temps().temps_courant();
98}
99
100/*! @brief Updates the state law and the density field.
101 *
102 * @param temps The current simulation time.
103 */
105{
106 //filling rho with rho(n+1)
107 DoubleTab& tab_rho = le_fluide->masse_volumique().valeurs();
109 tab_rho = tab_rho_np1;
110 le_fluide->masse_volumique().mettre_a_jour(temps);
111}
112
113/*! @brief Computes the dynamic viscosity.
114 *
115 */
117{
118 Champ_Don_base& mu = le_fluide->viscosite_dynamique();
119 if (!sub_type(Champ_Uniforme,mu))
120 {
121 // E. Saikali : Why not Champ_fonc_xyz for mu ???
122 if (sub_type(Champ_Fonc_Tabule,mu) || sub_type(Champ_Don_base,mu))
123 mu.mettre_a_jour(temperature_->temps());
124 else
125 {
126 Cerr<<"The viscosity field mu of type "<<mu.que_suis_je()<<" is not recognized.";
128 }
129 }
130}
131
132/*! @brief Computes the thermal conductivity.
133 *
134 */
136{
137 const Champ_Don_base& mu = le_fluide->viscosite_dynamique();
138 const DoubleTab& tab_Cp = le_fluide->capacite_calorifique().valeurs();
139 const DoubleTab& tab_mu = mu.valeurs();
140 Champ_Don_base& lambda = le_fluide->conductivite();
141 DoubleTab& tab_lambda = lambda.valeurs();
142 ToDo_Kokkos("critical");
143 int i, n = tab_lambda.size();
144 // The conductivity is either a uniform field or computed from the dynamic viscosity and Pr
145 if (!sub_type(Champ_Uniforme,lambda))
146 {
147 if (sub_type(Champ_Uniforme,mu))
148 {
149 double mu0 = tab_mu(0,0);
150 for (i=0 ; i<n ; i++) tab_lambda(i,0) = mu0 * tab_Cp(i,0) / Pr_;
151 }
152 else
153 {
154 for (i=0 ; i<n ; i++) tab_lambda(i,0) = tab_mu(i,0) * tab_Cp(i,0) / Pr_;
155 }
156 }
157 tab_lambda.echange_espace_virtuel();
158}
159
160/*! @brief Computes the kinematic viscosity.
161 *
162 */
164{
165 const Champ_Don_base& viscosite_dynamique = le_fluide->viscosite_dynamique();
166 bool uniforme = sub_type(Champ_Uniforme,viscosite_dynamique);
167 const DoubleTab& tab_rho = le_fluide->masse_volumique().valeurs();
168 const DoubleTab& tab_mu = viscosite_dynamique.valeurs();
169 Champ_Don_base& viscosite_cinematique = le_fluide->viscosite_cinematique();
170 DoubleTab& tab_nu = viscosite_cinematique.valeurs();
171 int n = tab_nu.size();
172
173 if (viscosite_cinematique.que_suis_je()=="Champ_Fonc_P0_VDF")
174 {
175 // VDF
176 for (int i=0 ; i<n ; i++)
177 tab_nu(i,0) = tab_mu(uniforme ? 0 : i,0) / tab_rho(i,0);
178 }
179 else // VEF
180 {
181 const IntTab& ef = ref_cast(Domaine_VF,le_fluide->vitesse().domaine_dis_base()).elem_faces();
182 int nfe = ef.line_size();
183 CIntTabView elem_faces = ef.view_ro();
184 CDoubleArrView rho = static_cast<const DoubleVect&>(tab_rho).view_ro();
185 CDoubleArrView mu = static_cast<const DoubleVect&>(tab_mu).view_ro();
186 DoubleArrView nu = static_cast<DoubleVect&>(tab_nu).view_rw();
187 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), n, KOKKOS_LAMBDA(const int i)
188 {
189 double rhoelem = 0;
190 for (int face = 0; face < nfe; face++)
191 rhoelem += rho(elem_faces(i, face));
192 rhoelem /= nfe;
193 nu(i) = mu(uniforme ? 0 : i) / rhoelem;
194 });
195 end_gpu_timer(__KERNEL_NAME__);
196 }
197 tab_nu.echange_espace_virtuel();
198 Debog::verifier("Loi_Etat_base::calculer_nu tab_nu",tab_nu);
199}
200
201/*! @brief Computes the thermal diffusivity.
202 *
203 */
205{
206 DoubleTab& tab_alpha = le_fluide->diffusivite().valeurs();
207 const Champ_Don_base& conductivite = le_fluide->conductivite();
208 bool uniforme = sub_type(Champ_Uniforme,conductivite);
209 int n = tab_alpha.size();
210 CDoubleArrView lambda = static_cast<const DoubleVect&>(conductivite.valeurs()).view_ro();
211 CDoubleArrView Cp = static_cast<const DoubleVect&>(le_fluide->capacite_calorifique().valeurs()).view_ro();
212 CDoubleArrView rho = static_cast<const DoubleVect&>(le_fluide->masse_volumique().valeurs()).view_ro();
213 DoubleArrView alpha = static_cast<DoubleVect&>(tab_alpha).view_rw();
214 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), n, KOKKOS_LAMBDA(const int i)
215 {
216 alpha(i) = lambda(uniforme ? 0 : i) / (rho(i) * Cp(i));
217 });
218 end_gpu_timer(__KERNEL_NAME__);
219 tab_alpha.echange_espace_virtuel();
220 Debog::verifier("Loi_Etat_base::calculer_alpha alpha",tab_alpha);
221}
222
223
224/*! @brief Does nothing; overloaded in Loi_Etat_Melange_GP.
225 *
226 */
228{
229 /* Do nothing : overloaded later */
230}
231
232/*! @brief Does nothing; overloaded in Loi_Etat_Melange_Binaire.
233 *
234 */
236{
237 /* Do nothing : overloaded later */
238}
239
240/*! @brief Recomputes the density (masse volumique).
241 *
242 */
244{
245 DoubleTab& tab_rho = le_fluide->masse_volumique().valeurs();
246 compute_tab_rho(tab_rho); // May be overloaded for device
247 tab_rho.echange_espace_virtuel();
248 tab_rho_np1.echange_espace_virtuel();
249 le_fluide->calculer_rho_face(tab_rho_np1);
250}
251
252// Host version
253void Loi_Etat_base::compute_tab_rho(DoubleTab& tab_rho)
254{
255 int n=tab_rho.size();
256 double Pth = le_fluide->pression_th();
257 const DoubleTab& tab_ICh = le_fluide->inco_chaleur().valeurs();
258 ToDo_Kokkos("Implement a ::compute_tab_rho() on device");
259 for (int som = 0; som < n; som++)
260 {
261 tab_rho_np1(som) = calculer_masse_volumique(Pth, tab_ICh(som, 0));
262 tab_rho(som, 0) = 0.5 * (tab_rho_n(som) + tab_rho_np1(som));
263 }
264}
265/*! @brief For ideal gases: does nothing. For real gases: must recompute enthalpy from pressure and temperature.
266 *
267 * @param Pth_ Thermodynamic pressure.
268 * @param T_ Temperature.
269 * @return The computed enthalpy (or temperature unchanged for ideal gases).
270 */
271double Loi_Etat_base::calculer_H(double Pth_, double T_) const
272{
273 return T_;
274}
275
276double Loi_Etat_base::Drho_DP(double,double) const
277{
278 Cerr<<"Drho_DP must be implemented in the derived class "<<que_suis_je()<<" to be used"<<finl;
279 abort();
280 return 0;
281}
282double Loi_Etat_base::Drho_DT(double,double) const
283{
284 Cerr<<"Drho_DT must be implemented in the derived class "<<que_suis_je()<<" to be used"<<finl;
285 abort();
286 return 0;
287}
288double Loi_Etat_base::De_DP(double,double) const
289{
290 Cerr<<"De_DP must be implemented in the derived class "<<que_suis_je()<<" to be used"<<finl;
291 abort();
292 return 0;
293}
294double Loi_Etat_base::De_DT(double,double) const
295{
296 Cerr<<"De_DT must be implemented in the derived class "<<que_suis_je()<<" to be used"<<finl;
297 abort();
298 return 0;
299}
300
301bool Loi_Etat_base::has_champ(const Motcle& nom, OBS_PTR(Champ_base)& ref_champ) const
302{
303 return champs_compris_.has_champ(nom, ref_champ);
304}
305bool Loi_Etat_base::has_champ(const Motcle& nom) const
306{
307 return champs_compris_.has_champ(nom);
308}
309
311{
312 return champs_compris_.get_champ(nom);
313}
314
316{
317 if (opt==DESCRIPTION)
318 Cerr<<"Loi_Etat_base : "<<champs_compris_.liste_noms_compris()<<finl;
319 else
320 nom.add(champs_compris_.liste_noms_compris());
321}
322
class Champ_Don_base base class of Given Fields (not calculated)
void mettre_a_jour(double temps) override
Time update.
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
Class Champ_Fonc_Tabule Derived class of Champ_Fonc_base representing.
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
bool has_champ(const Motcle &nom, OBS_PTR(FIELD_TYPE)&ref_champ) const
static void verifier(const char *const msg, double)
Definition Debog.cpp:21
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
Base class for a dilatable fluid, inheriting from Fluide_base.
Base class for the state law hierarchy defining a dilatable fluid.
void assoscier_probleme(const Probleme_base &pb)
Associates the problem with the state law.
virtual void initialiser_inco_ch()
Initialises the heat equation unknown; sets rho arrays and updates density.
virtual double De_DP(double, double) const
DoubleTab tab_rho_np1
void mettre_a_jour(double)
Updates the state law and the density field.
const Champ_base & get_champ(const Motcle &nom) const override
virtual void abortTimeStep()
virtual double De_DT(double, double) const
DoubleTab tab_rho_n
Champ_Don_base & ch_temperature()
virtual void remplir_T()=0
virtual void compute_tab_rho(DoubleTab &)
virtual void associer_fluide(const Fluide_Dilatable_base &)
Associates the fluid with the state law.
virtual void calculer_masse_volumique()
Recomputes the density (masse volumique).
virtual double Drho_DT(double, double) const
virtual void preparer_calcul()
Prepares the fluid for computation by filling temperature and computing density.
virtual void calculer_alpha()
Computes the thermal diffusivity.
virtual double calculer_H(double, double) const
For ideal gases: does nothing. For real gases: must recompute enthalpy from pressure and temperature.
virtual double Drho_DP(double, double) const
void get_noms_champs_postraitables(Noms &nom, Option opt=NONE) const override
virtual void calculer_lambda()
Computes the thermal conductivity.
virtual void calculer_mu()
Computes the dynamic viscosity.
void calculer_nu()
Computes the kinematic viscosity.
virtual void calculer_nu_sur_Sc()
Does nothing; overloaded in Loi_Etat_Melange_Binaire.
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
virtual void calculer_mu_sur_Sc()
Does nothing; overloaded in Loi_Etat_Melange_GP.
A character string (Nom) in uppercase.
Definition Motcle.h:26
An array of character strings (VECT(Nom)).
Definition Noms.h:26
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
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
class Probleme_base It is a Probleme_U that is not a coupling.
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
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
_SIZE_ size() const
Definition TRUSTVect.tpp:45
int line_size() const
Definition TRUSTVect.tpp:67
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")