TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Loi_Etat_rhoT_GP_QC.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 <Loi_Etat_rhoT_GP_QC.h>
18#include <TRUSTTab.h>
19#include <Param.h>
20#include <ParserView.h>
21
22Implemente_instanciable_sans_constructeur( Loi_Etat_rhoT_GP_QC, "Loi_Etat_rhoT_Gaz_Parfait_QC", Loi_Etat_GP_base ) ;
23// XD rhoT_gaz_parfait_QC loi_etat_gaz_parfait_base rhoT_gaz_parfait_QC INHERITS_BRACE Class for perfect gas used with a
24// XD_CONT quasi-compressible fluid where the state equation is defined as rho = f(T).
25
27
29{
31 return os;
32}
33
35{
36 Nom expression_;
37
38 Param param(que_suis_je());
39 param.ajouter("Cp",&Cp_,Param::REQUIRED);// XD_ADD_P double
40 // XD_CONT Specific heat at constant pressure of the gas Cp.
41 param.ajouter("Prandtl",&Pr_); // XD_ADD_P double
42 // XD_CONT Prandtl number of the gas Pr=mu*Cp/lambda
43 param.ajouter("rho_xyz",&rho_xyz_); // XD_ADD_P field_base
44 // XD_CONT Defined with a Champ_Fonc_xyz to define a constant rho with time (space dependent)
45 param.ajouter("rho_t",&expression_); // XD_ADD_P chaine
46 // XD_CONT Expression of T used to calculate rho. This can lead to a variable rho, both in space and in time.
47 param.ajouter("Tmin_for_exit",&Tmin_for_exit_); // XD_ADD_P double
48 // XD_CONT If temperature goes below Tmin_for_exit (default value -1000), computation will stop.
49 param.lire_avec_accolades(is);
50
51 if (expression_ == "??" && !rho_xyz_)
52 {
53 Cerr << "Error in Loi_Etat_rhoT_GP_QC::readOn !" << finl;
54 Cerr << "The closure equation of rho is not read in your data file !" << finl;
55 Cerr << "Either use rho_t followed by an expression of T," << finl;
56 Cerr << "or use rho_xyz followed by a Champ_Fonc_xyz !" << finl;
58 }
59
60 if (expression_ != "??")
61 {
62 is_exp_ = true;
63 Cerr << "Parsing the expression " << expression_ << finl;
64 parser_.setNbVar(1);
65 parser_.setString(expression_);
66 parser_.addVar("T");
67 parser_.parseString();
68 }
69 else
70 assert(rho_xyz_->que_suis_je() == "Champ_Fonc_xyz" );
71
72 return is;
73}
74
75// Method used to initialize rho from a Champ_Fonc_xyz
76// In this case the DoubleTab rho_ is initialized and remains constant with time
78{
79 int isVDF = 0;
80 if (le_fluide->masse_volumique().que_suis_je()=="Champ_Fonc_P0_VDF") isVDF = 1;
81 // We know that mu is always stored on elems
82 int nb_elems = le_fluide->viscosite_dynamique().valeurs().size();
83 // The OWN_PTR(Champ_Don_base) rho_xyz_ is evaluated on elements
84 assert (rho_xyz_->valeurs().size() == nb_elems);
85
86 if (isVDF)
87 {
88 // Disc VDF => rho_ & rho_xyz_ on elems => we do nothing
89 rho_.resize(nb_elems, 1);
90 DoubleTab& fld = rho_xyz_->valeurs();
91 for (int i=0; i<nb_elems; i++) rho_(i,0)=fld(i,0);
92 }
93 else
94 {
95 // Disc VEF => rho on faces ...
96 int nb_faces = le_fluide->masse_volumique().valeurs().size(); // rho on faces in VEF
97 rho_.resize(nb_faces, 1);
98
99 Champ_base& ch_rho = le_fluide->masse_volumique();
100 ch_rho.affecter_(rho_xyz_);
101 DoubleTab& fld = ch_rho.valeurs();
102 for (int i = 0; i < nb_faces; i++) rho_(i,0)= fld(i,0);
103 }
104}
105
107{
108 // required here for xyz !
109 if ( !is_exp_ ) initialiser_rho();
111}
112
113// Override
114double Loi_Etat_rhoT_GP_QC::calculer_masse_volumique(double P, double T) const
115{
116 /* Not useful for this state law */
117 return -3000.;
118}
119
120// Overload
121double Loi_Etat_rhoT_GP_QC::calculer_masse_volumique(double P, double T, int ind) const
122{
123 if (inf_ou_egal(T,Tmin_for_exit_))
124 {
125 Cerr << finl << "Error, we find a temperature of " << T << " !" << finl;
126 Cerr << "Either your calculation has diverged or you don't define" << finl;
127 Cerr << "temperature in Kelvin somewhere in your data file." << finl;
128 Cerr << "It is mandatory for Quasi compressible model." << finl;
129 Cerr << "Check your data file." << finl;
131 }
132 if (is_exp_)
133 {
134 parser_.setVar(0,T);
135 return parser_.eval();
136 }
137 else
138 {
139 // Initialized from Champ_Fonc_xyz
140 // dont change, return what is saved in rho_
141 return rho_(ind,0);
142 }
143}
144
145double Loi_Etat_rhoT_GP_QC::inverser_Pth(double T, double rho)
146{
147 abort();
148 throw;
149}
150
151/*! @brief Recalcule la masse volumique
152 *
153 */
155{
156 const DoubleTab& tab_ICh = le_fluide->inco_chaleur().valeurs();
157 DoubleTab& tab_rho = le_fluide->masse_volumique().valeurs();
158 int n=tab_rho.size();
159 if (is_exp_)
160 {
161 ParserView parser(parser_);
162 parser.parseString();
163 CDoubleTabView ICh = tab_ICh.view_ro();
164 CDoubleArrView rho_n = static_cast<const DoubleVect&>(tab_rho_n).view_ro();
165 DoubleArrView rho_np1 = static_cast<DoubleVect&>(tab_rho_np1).view_wo();
166 DoubleTabView rho = tab_rho.view_wo();
167 double eps = std::numeric_limits<double>::epsilon();
168 double Tmin_for_exit = Tmin_for_exit_ ;
169 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), n, KOKKOS_LAMBDA(const int i)
170 {
171 double T = ICh(i, 0);
172 if (Kokkos::abs(T) < eps)
173 {
174 T = 0.0;
175 }
176 if (T<=Tmin_for_exit) Process::Kokkos_exit("Dumb temperature in Loi_Etat_rhoT_GP_QC::calculer_masse_volumique !");
177 int threadId = parser.acquire();
178 parser.setVar(0, T, threadId);
179 rho_np1(i) = parser.eval(threadId);
180 parser.release(threadId);
181 rho(i, 0) = 0.5 * (rho_n(i) + rho_np1(i));
182 });
183 end_gpu_timer(__KERNEL_NAME__);
184 }
185 else
186 {
187 CDoubleTabView rho = rho_.view_ro();
188 CDoubleArrView rho_n = static_cast<const DoubleVect&>(tab_rho_n).view_ro();
189 DoubleArrView rho_np1 = static_cast<DoubleVect&>(tab_rho_np1).view_wo();
190 DoubleTabView masse_volumique = tab_rho.view_rw();
191 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__), n, KOKKOS_LAMBDA(const int i)
192 {
193 rho_np1(i) = rho(i,0);
194 masse_volumique(i, 0) = 0.5 * (rho_n(i) + rho_np1(i));
195 });
196 end_gpu_timer(__KERNEL_NAME__);
197 }
198 tab_rho.echange_espace_virtuel();
199 tab_rho_np1.echange_espace_virtuel();
200 le_fluide->calculer_rho_face(tab_rho_np1);
201}
virtual DoubleTab & valeurs()=0
classe Champ_base Cette classe est la base de la hierarchie des champs.
Definition Champ_base.h:43
virtual Champ_base & affecter_(const Champ_base &)=0
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Loi_Etat_GP_base Cette classe represente la loi d'etat base pour les gaz parfaits.
virtual void initialiser_inco_ch()
Initialise l'inconnue de l'equation de chaleur : ne fai rien.
const DoubleTab & rho_n() const
DoubleTab tab_rho_np1
DoubleTab tab_rho_n
const DoubleTab & rho_np1() const
: class Loi_Etat_rhoT_GP_QC
void calculer_masse_volumique() override
Recalcule la masse volumique.
double inverser_Pth(double T, double rho) override
Calcule la pression avec la temperature et la masse volumique.
void initialiser_inco_ch() override
Initialise l'inconnue de l'equation de chaleur : ne fai rien.
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
@ REQUIRED
Definition Param.h:115
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
static KOKKOS_INLINE_FUNCTION void Kokkos_exit(const char *)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.h:173
static void abort()
Routine de sortie de Trio-U sur une erreur abort().
Definition Process.cpp:570
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
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
std::enable_if_t< is_default_exec_space< EXEC_SPACE >, View< _TYPE_, _SHAPE_ > > view_rw()
Definition TRUSTTab.h:291
_SIZE_ size() const
Definition TRUSTVect.tpp:45
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")