TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Loi_Etat_GR_base.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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_Quasi_Compressible.h>
17#include <Loi_Etat_GR_base.h>
18#include <Champ_Uniforme.h>
19#include <Motcle.h>
20
21Implemente_base_sans_constructeur(Loi_Etat_GR_base,"Loi_Etat_Gaz_Reel_base",Loi_Etat_base);
22// XD loi_etat_gaz_reel_base loi_etat_base loi_etat_gaz_reel_base INHERITS_BRACE Basic class for real gases state laws
23// XD_CONT used with a dilatable fluid.
24
26
28{
29 os <<que_suis_je()<< finl;
30 return os;
31}
32
34{
35 return is;
36}
37
38/*! @brief Returns the type of fluid associated.
39 *
40 * @return The fluid type name ("Gaz_Reel").
41 */
43{
44 return "Gaz_Reel";
45}
46
47/*! @brief Initialises the state law by computing Pth.
48 *
49 */
51{
52 le_fluide->inco_chaleur().nommer("enthalpie");
53
54 const DoubleTab& tab_H = le_fluide->inco_chaleur().valeurs();
55 const DoubleTab& tab_rho = le_fluide->masse_volumique().valeurs();
56 int i, n = tab_H.dimension(0);
57 DoubleTab& tab_T = temperature_->valeurs();
58 tab_TempC.resize(n);
59 double Pth = le_fluide->pression_th();
60 for (i=0 ; i<n ; i++)
61 {
62 tab_rho_n(i) = tab_rho(i,0);
63 tab_TempC(i) = calculer_temperature(Pth,tab_H(i,0));
64 tab_T(i) = tab_TempC(i);
65 }
66 tab_Cp.ref(le_fluide->capacite_calorifique().valeurs());
68}
69
70/*! @brief Initialises the enthalpy unknown.
71 *
72 */
74{
75 /*
76 * XXX XXX XXX
77 * The heat unknown inco_chaleur is first filled with the initial temperature.
78 * It must be converted to enthalpy;
79 * the data are the density and the temperature,
80 * so enthalpy and pressure must be computed.
81 */
82
83 DoubleTab& tab_TH = le_fluide->inco_chaleur().valeurs();
84 double Pth = le_fluide->pression_th();
85 DoubleTab& tab_rho = le_fluide->masse_volumique().valeurs();
86 tab_rho_n=tab_rho;
87 tab_rho_np1=tab_rho;
88 int som,n = tab_TH.dimension(0);
89 if (le_fluide->inco_chaleur().le_nom() == "enthalpie")
90 {
91 for (som=0 ; som<n ; som++)
92 tab_rho_np1(som) = tab_rho(som,0) = tab_rho_n(som) = calculer_masse_volumique(Pth,tab_TH(som,0));
93 }
94 else
95 {
96 for (som=0 ; som<n ; som++)
97 {
98 tab_TH(som,0) = calculer_H(Pth,tab_TH(som,0));
99 tab_rho_np1(som) = tab_rho(som,0) = tab_rho_n(som) = calculer_masse_volumique(Pth,tab_TH(som,0));
100 }
101 }
102 Cerr<<"FIN Loi_Etat_GR_base::initialiser_H Pth = "<<Pth<<" H = "<<tab_TH(0,0)<<finl;
103}
104
105/*! @brief Fills the temperature array from the enthalpy unknown.
106 *
107 */
109{
110 const DoubleTab& tab_H = le_fluide->inco_chaleur().valeurs();
111 int i, n = tab_TempC.dimension(0);
112 DoubleTab& tab_T = temperature_->valeurs();
113 double Pth = le_fluide->pression_th();
114 for (i=0 ; i<n ; i++)
115 {
116 tab_TempC(i) = calculer_temperature(Pth,tab_H(i,0));
117 tab_T(i,0) = tab_TempC(i);
118 }
119}
120
121/*! @brief Computes Cp as a function of physical quantities P and h.
122 * Cp = dh/dT = de/dT - 1/rho^2 * drho/dT
123 *
124 * @param P Pressure.
125 * @param h Enthalpy.
126 * @return Computed Cp value.
127 */
128double Loi_Etat_GR_base::Cp_calc(double P, double h) const
129{
130 double res;
131 if (R==-1) res = 1./(DT_DH(P,h));
132 else res = Cp_;
133
134 return res;
135}
136
137/*! @brief Computes Cp using the PolyCp_ polynomial.
138 *
139 */
141{
142 double Pth = le_fluide->pression_th();
143 const DoubleTab& tab_h = le_fluide->inco_chaleur().valeurs();
144 for (int i=0; i<tab_Cp.size(); i++) tab_Cp(i) = Cp_calc(Pth,tab_h(i,0));
145}
146
147/*! @brief Computes the conductivity divided by Cp: equivalent to k*dT/dh for using enthalpy in the diffusion operator.
148 *
149 */
151{
152 const Champ_Don_base& mu = le_fluide->viscosite_dynamique();
153 const DoubleTab& tab_mu = mu.valeurs();
154 Champ_Don_base& lambda = le_fluide->conductivite();
155 DoubleTab& tab_lambda = lambda.valeurs();
156
157 int i, n=tab_lambda.size();
158 if (!sub_type(Champ_Uniforme,lambda))
159 {
160 if (sub_type(Champ_Uniforme,mu))
161 {
162 for (i=0 ; i<n ; i++) tab_lambda(i,0) = tab_mu(0,0) * tab_Cp(i) / Pr_;
163 }
164 else
165 {
166 for (i=0 ; i<n ; i++) tab_lambda(i,0) = tab_mu(i,0) * tab_Cp(i) / Pr_;
167 }
168 }
169}
170
171double Loi_Etat_GR_base::De_DP(double P, double T) const
172{
173 double res = 0;
174 Cerr<<"Loi_Etat_GR_base::De_DP non accede normalement"<<finl;
175 abort();
176 return res;
177}
178double Loi_Etat_GR_base::De_DT(double P, double T) const
179{
180 double res = 0;
181 Cerr<<"Loi_Etat_GR_base::De_DP non accede normalement"<<finl;
182 abort();
183 return res;
184}
185
186/*! @brief Computes the thermodynamic pressure from enthalpy and density by Newton iteration.
187 *
188 * @param H Enthalpy.
189 * @param rho Density.
190 * @return Thermodynamic pressure Pth.
191 */
192double Loi_Etat_GR_base::inverser_Pth(double H, double rho)
193{
194 double P = le_fluide->pression_th();
195 double acc = (calculer_masse_volumique(P,H) - rho) / Drho_DP(P,H);
196 int i=0;
197 while (std::fabs(acc)>1e-8 && i<1000)
198 {
199 P = P-acc;
200 acc = (calculer_masse_volumique(P,H) - rho) / Drho_DP(P,H);
201 i++;
202 }
203 if (std::fabs(acc)>1e-8)
204 {
205 Cerr<<"Problem in the pressure inversion: nb_iter="<<i<<finl;
206 Cerr<<" Pth="<<P<<" H="<<H<<" rho="<<rho<<finl;
207 abort();
208 }
209 return P;
210}
211
class Champ_Don_base base class of Given Fields (not calculated)
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
Champ_Uniforme Represents a field that is constant in space and time.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Base state law class for real gases, defining a dilatable fluid with the equations of state: rho = rh...
void calculer_Cp() override
Computes Cp using the PolyCp_ polynomial.
void initialiser_inco_ch() override
Initialises the enthalpy unknown.
double De_DT(double, double) const override
virtual double calculer_temperature(double, double)=0
double De_DP(double, double) const override
void calculer_lambda() override
Computes the conductivity divided by Cp: equivalent to k*dT/dh for using enthalpy in the diffusion op...
void calculer_masse_volumique() override
Recomputes the density (masse volumique).
double calculer_H(double, double) const override=0
For ideal gases: does nothing. For real gases: must recompute enthalpy from pressure and temperature.
double inverser_Pth(double, double) override
Computes the thermodynamic pressure from enthalpy and density by Newton iteration.
double Cp_calc(double, double) const
Computes Cp as a function of physical quantities P and h. Cp = dh/dT = de/dT - 1/rho^2 * drho/dT.
void remplir_T() override
Fills the temperature array from the enthalpy unknown.
const Nom type_fluide() const override
Returns the type of fluid associated.
void initialiser() override
Initialises the state law by computing Pth.
virtual double DT_DH(double, double) const =0
double Drho_DP(double, double) const override=0
Base class for the state law hierarchy defining a dilatable fluid.
DoubleTab tab_rho_np1
DoubleTab tab_rho_n
virtual void calculer_masse_volumique()
Recomputes the density (masse volumique).
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
virtual void nommer(const Nom &)
Assigns a name to the Objet_U. Virtual method to override.
Definition Objet_U.cpp:327
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 abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
Base class for output streams.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45