TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Loi_Etat_GP_base.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 <Fluide_Dilatable_base.h>
17#include <Champ_Fonc_Tabule.h>
18#include <Loi_Etat_GP_base.h>
19#include <Champ_Uniforme.h>
20#include <Domaine_VF.h>
21#include <Motcle.h>
22
23Implemente_base_sans_constructeur(Loi_Etat_GP_base,"Loi_Etat_Gaz_Parfait_base",Loi_Etat_base);
24// XD loi_etat_gaz_parfait_base loi_etat_base loi_etat_gaz_parfait_base INHERITS_BRACE Basic class for perfect gases
25// XD_CONT state laws used with a dilatable fluid.
26
28
30{
31 os <<que_suis_je()<< finl;
32 return os;
33}
34
36{
37 return is;
38}
39
40/*! @brief Returns the type of fluid associated.
41 *
42 * @return The fluid type name ("Gaz_Parfait").
43 */
45{
46 return "Gaz_Parfait";
47}
48
49/*! @brief Associates the fluid with the state law.
50 *
51 * @param fl The dilatable fluid to associate.
52 */
58
59/*! @brief Initialises the state law by computing Pth.
60 *
61 */
63{
64 const DoubleTab& tab_Temp = le_fluide->inco_chaleur().valeurs();
65 const DoubleTab& tab_rho = le_fluide->masse_volumique().valeurs();
66 int ntot=tab_Temp.size_totale();
67 tab_rho_n=tab_Temp;
68 for (int i=0 ; i<ntot ; i++)
69 tab_rho_n(i) = tab_rho(i,0);
70 remplir_T();
71}
72
73/*! @brief Fills the temperature array: T = temp + 273.15.
74 *
75 */
77{
78 const DoubleTab& tab_Temp = le_fluide->inco_chaleur().valeurs();
79 temperature_->valeurs() = tab_Temp;
80}
81
82/*! @brief Computes Cp. Does nothing: Cp is constant.
83 *
84 */
86{
87 /* Do nothing */
88}
89
90/*! @brief Computes the thermal conductivity.
91 *
92 */
94{
95 const Champ_Don_base& mu = le_fluide->viscosite_dynamique();
96 const DoubleTab& tab_mu = mu.valeurs();
97 Champ_Don_base& lambda = le_fluide->conductivite();
98 DoubleTab& tab_lambda =lambda.valeurs();
99 //The conductivity is either a uniform field or computed from the dynamic viscosity and Pr
100 if (sub_type(Champ_Fonc_Tabule,lambda))
101 {
102 lambda.mettre_a_jour(temperature_->temps());
103 return;
104 }
105
106
107
108 if (!sub_type(Champ_Uniforme,lambda))
109 {
110 if (sub_type(Champ_Uniforme,mu))
111 {
112 double mu0 = tab_mu(0,0);
113 tab_lambda *= (mu0 * Cp_ / Pr_);
114 }
115 else
116 {
117 tab_lambda = tab_mu;
118 tab_lambda *= Cp_ / Pr_;
119 }
120 }
121 else
122 {
123 if (sub_type(Champ_Uniforme,mu))
124 {
125 tab_lambda(0,0) = mu.valeurs()(0,0) * Cp_ / Pr_;
126 }
127 else
128 {
129 Cerr << finl ;
130 Cerr << "If lambda is of type Champ_Uniform, mu must also be of type Champ_Uniforme !"<< finl;
131 Cerr << "If needed, you can use a Champ_Fonc_Fonction or a Champ_Fonc_Tabule with a constant for mu."<< finl ;
132 Cerr << finl ;
134 }
135 }
136 tab_lambda.echange_espace_virtuel();
137}
138
139/*! @brief Computes the thermal diffusivity.
140 *
141 */
143{
144 const Champ_Don_base& champ_lambda = le_fluide->conductivite();
145 const DoubleTab& tab_lambda = champ_lambda.valeurs();
146 Champ_Don_base& champ_alpha = le_fluide->diffusivite();
147 DoubleTab& tab_alpha = le_fluide->diffusivite().valeurs();
148 const DoubleTab& tab_rho = le_fluide->masse_volumique().valeurs();
149
150 int isVDF=0;
151 if (champ_alpha.que_suis_je()=="Champ_Fonc_P0_VDF") isVDF = 1;
152 int n=tab_alpha.size();
153 bool lambda_uniforme = sub_type(Champ_Uniforme,champ_lambda);
154 if (isVDF)
155 {
156 ToDo_Kokkos("critical");
157 for (int i=0 ; i<n ; i++)
158 tab_alpha(i,0) = (lambda_uniforme ? tab_lambda(0,0) : tab_lambda(i,0)) / (tab_rho(i,0) * Cp_);
159 }
160 else
161 {
162 const IntTab& tab_elem_faces = ref_cast(Domaine_VF,le_fluide->vitesse().domaine_dis_base()).elem_faces();
163 int nfe = tab_elem_faces.line_size();
164 double Cp = Cp_;
165 CIntTabView elem_faces = tab_elem_faces.view_ro();
166 CDoubleTabView lambda = tab_lambda.view_ro();
167 CDoubleTabView rho = tab_rho.view_ro();
168 DoubleTabView alpha = tab_alpha.view_wo();
169 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), n, KOKKOS_LAMBDA(
170 const int i)
171 {
172 double rhoelem=0;
173 for (int face=0; face<nfe; face++) rhoelem += rho(elem_faces(i,face),0);
174 rhoelem /= nfe;
175 alpha(i,0) = (lambda_uniforme ? lambda(0,0) : lambda(i,0))/ ( rhoelem * Cp );
176 });
177 end_gpu_timer(__KERNEL_NAME__);
178 }
179 tab_alpha.echange_espace_virtuel();
180}
181
182/*! @brief Computes the thermodynamic pressure from temperature and density.
183 *
184 * @param T Temperature.
185 * @param rho Density.
186 * @return Thermodynamic pressure Pth = rho * R * T.
187 */
188double Loi_Etat_GP_base::inverser_Pth(double T, double rho)
189{
190 return rho * R_ * T;
191}
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 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 state law class for ideal gases, defining a dilatable fluid with the equation of state: Pth = rh...
void initialiser() override
Initialises the state law by computing Pth.
const Nom type_fluide() const override
Returns the type of fluid associated.
void calculer_lambda() override
Computes the thermal conductivity.
void remplir_T() override
Fills the temperature array: T = temp + 273.15.
void calculer_Cp() override
Computes Cp. Does nothing: Cp is constant.
void associer_fluide(const Fluide_Dilatable_base &) override
Associates the fluid with the state law.
double inverser_Pth(double, double) override
Computes the thermodynamic pressure from temperature and density.
void calculer_alpha() override
Computes the thermal diffusivity.
Base class for the state law hierarchy defining a dilatable fluid.
DoubleTab tab_rho_n
virtual void associer_fluide(const Fluide_Dilatable_base &)
Associates the fluid with the state law.
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
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
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 >, View< _TYPE_, _SHAPE_ > > view_wo()
Definition TRUSTTab.h:276
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
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
int line_size() const
Definition TRUSTVect.tpp:67
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")