TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Loi_Etat_rhoT_GR_QC.cpp
1/****************************************************************************
2* Copyright (c) 2022, 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 <Loi_Etat_rhoT_GR_QC.h>
17#include <Motcle.h>
18#include <Fluide_Quasi_Compressible.h>
19#include <Champ_Uniforme.h>
20
21Implemente_instanciable(Loi_Etat_rhoT_GR_QC,"Loi_Etat_rhoT_Gaz_Reel_QC",Loi_Etat_GR_base);
22// XD rhoT_gaz_reel_QC loi_etat_gaz_reel_base rhoT_gaz_reel_QC NO_BRACE Class for real gas state law used with a
23// XD_CONT quasi-compressible fluid.
24// XD attr bloc bloc_lecture bloc REQ Description.
25
26
28{
29 os <<que_suis_je()<< finl;
30 return os;
31}
32
34{
35 double PolyRho_lu=-1, PolyT_lu=-1, MMole_lu=-1, Pr_lu=-1;
36
37 Motcle accferme="}";
38 Motcle accouverte="{";
39
40 Motcle motlu;
41 is >> motlu;
42 Cerr<<"Lecture de la loi d'etat Gaz Reel rhoT"<<finl;
43 if (motlu != accouverte)
44 {
45 Cerr<<" On attendait "<<accouverte<<" au lieu de "<<motlu<<finl;
46 abort();
47 }
48 Motcles les_mots(4);
49 {
50 les_mots[0] = "Prandtl";
51 les_mots[1] = "masse_molaire";
52 les_mots[2] = "Poly_rho";
53 les_mots[3] = "Poly_T";
54 // les_mots[4] = "Cp"; //pour debuggage
55 }
56 is >> motlu;
57 while(motlu != accferme )
58 {
59 int rang=les_mots.search(motlu);
60 switch(rang)
61 {
62 case 0 :
63 {
64 is>>Pr_;
65 Pr_lu=1;
66 break;
67 }
68 case 1 :
69 {
70 is>>MMole_;
71 MMole_lu=1;
72 break;
73 }
74 case 2 :
75 {
76 int i,j,im,jm;
77 is>>im;
78 is>>jm;
79 PolyRho_.resize(im,jm);
80 for (i=0 ; i<im ; i++)
81 for (j=0 ; j<jm ; j++)
82 is>>PolyRho_(i,j);
83 PolyRho_lu=1;
84 break;
85 }
86 case 3 :
87 {
88 int i,j,im,jm;
89 is>>im;
90 is>>jm;
91 PolyT_.resize(im,jm);
92 for (i=0 ; i<im ; i++)
93 for (j=0 ; j<jm ; j++)
94 is>>PolyT_(i,j);
95 PolyT_lu=1;
96 break;
97 }
98 case 4 :
99 {
100 is>>Cp_;
101 PolyRho_lu=1;
102 PolyT_lu=1;
103 MMole_lu=1;
104 if (Cp_<0)
105 {
106 Cp_ = -Cp_;
107 debug=1;
108 }
109 else
110 debug=0;
111 R = Cp_ *(1.-1./1.4);
112 Cerr<<"Debogage Gaz Reel : Cp="<<Cp_<<" R="<<R<<finl;
113 break;
114 }
115 default :
116 {
117 Cerr<<"Une loi d'etat "<<que_suis_je()<<" n'a pas la propriete "<<motlu<<finl;
118 Cerr<<"On attendait un mot dans :"<<finl<<les_mots<<finl;
119 abort();
120 }
121 }
122 is >> motlu;
123 }
124
125 if (Pr_lu==-1)
126 {
127 Cerr<<"ERREUR : on attendait la definition du nombre de Prandtl (Prandtl pr)"<<finl;
128 abort();
129 }
130 if (PolyRho_lu==-1)
131 {
132 Cerr<<"ERREUR : on attendait la definition du polynome de la masse volumique (Poly_Rho nb_coeff1 nb_coeff2 a00 a01 a02 ...)"<<finl;
133 abort();
134 }
135 else
136 {
137 int i,j;
138 Cerr<<"Polynome de rho :"<<finl;
139 for (i=0 ; i<PolyRho_.dimension(0) ; i++)
140 {
141 for (j=0 ; j<PolyRho_.dimension(1) ; j++)
142 {
143 Cerr<<" f("<<i<<","<<j<<")= "<<PolyRho_(i,j);
144 }
145 Cerr<<finl;
146 }
147 }
148 if (PolyT_lu==-1)
149 {
150 Cerr<<"ERREUR : on attendait la definition du polynome de la temperature (Poly_T nb_coeff1 nb_coeff2 a00 a01 a02 ...)"<<finl;
151 abort();
152 }
153 else
154 {
155 int i,j;
156 Cerr<<"Polynome de T :"<<finl;
157 for (i=0 ; i<PolyT_.dimension(0) ; i++)
158 {
159 for (j=0 ; j<PolyT_.dimension(1) ; j++)
160 {
161 Cerr<<" f("<<i<<","<<j<<")= "<<PolyT_(i,j);
162 }
163 Cerr<<finl;
164 }
165 }
166 if (MMole_lu==-1)
167 {
168 Cerr<<"ERREUR : on attendait la definition de la masse molaire (masse_molaire m)"<<finl;
169 abort();
170 }
171 return is;
172}
173
174/*! @brief Calcule la masse volumique ponctuelle
175 *
176 * @param (double P) pression
177 * @param (double h) enthalpie
178 * @return (double) masse volumique correspondante
179 */
180double Loi_Etat_rhoT_GR_QC::calculer_masse_volumique(double P, double h) const
181{
182 double res = 0;
183 if (R==-1)
184 {
185 double H = h;
186 int i,j;
187 for (i=0 ; i<PolyRho_.dimension(0) ; i++)
188 for (j=0 ; j<PolyRho_.line_size() ; j++)
189 res += PolyRho_(i,j) *pow(P,j) *pow(H,i);
190 }
191 else
192 {
193 //debuggage
194 res = P*Cp_/(R*h);
195 }
196 return res;
197}
198
199/*! @brief Calcule la temperature ponctuelle
200 *
201 * @param (double P) pression
202 * @param (double h) enthalpie
203 * @return (double) masse volumique correspondante
204 */
206{
207 double res = 0;
208 if (R==-1)
209 {
210 int i,j;
211 double H = h;
212 for (i=0 ; i<PolyT_.dimension(0) ; i++)
213 for (j=0 ; j<PolyT_.line_size() ; j++)
214 res += PolyT_(i,j) *pow(P,i) *pow(H,j);
215 }
216 else
217 {
218 //debuggage
219 res = h/Cp_;
220 }
221 return res;
222}
223
224/*! @brief Cas gaz Reel : doit recalculer l'enthalpie a partir de la pression et la temperature
225 *
226 */
227double Loi_Etat_rhoT_GR_QC::calculer_H(double Pth_, double T_) const
228{
229 double res=0;
230 if (R==-1)
231 {
232 //il faut resoudre c0-T_ + c1.H + c2.H^2 +...=0
233 int i,j, it,max_iter = 1000;
234 double eps = 1.e-6;
235 DoubleVect coef(PolyT_.line_size());
236 coef = 0;
237
238 for (i=0 ; i<PolyT_.dimension(0) ; i++)
239 for (j=0 ; j<PolyT_.line_size() ; j++)
240 coef(j) += PolyT_(i,j) * pow(Pth_,i);
241
242 coef(0) -= T_;
243 double dH, H = -coef(0)/coef(1), num=coef(0), den=0;
244 for (j=1 ; j<PolyT_.line_size() ; j++)
245 {
246 num += coef(j) * pow(H,j);
247 den += j*coef(j) * pow(H,j-1);
248 }
249 dH = num/den;
250 H -= dH;
251
252 it=0;
253 while (dH/H>eps && it<max_iter)
254 {
255 num=coef(0);
256 den=0;
257 for (j=1 ; j<PolyT_.line_size() ; j++)
258 {
259 num += coef(j) * pow(H,j);
260 den += j*coef(j) * pow(H,j-1);
261 }
262 dH = num / den;
263 H -= dH;
264 it++;
265 }
266
267 if (dH/H>eps)
268 {
269 Cerr<<"PB Loi_Etat_rhoT_GR_QC::calculer_H: resolution Newton impossible "<<finl;
270 Cerr<<"Pth= "<<Pth_<<" t="<<T_<<" H="<<H<<finl;
271 abort();
272 }
273 res = H;
274 }
275 else
276 {
277 //debuggage
278 res = Cp_*T_;
279 }
280 return res;
281}
282
283double Loi_Etat_rhoT_GR_QC::Drho_DP(double P, double h) const
284{
285 double res = 0;
286 if (R==-1)
287 {
288 int i,j;
289 double H =h;
290 for (i=1 ; i<PolyRho_.dimension(0) ; i++)
291 for (j=0 ; j<PolyRho_.line_size() ; j++)
292 res += i* PolyRho_(i,j) *pow(P,i-1) *pow(H,j);
293 }
294 else
295 {
296 //debuggage
297 res = 1/(R*h/Cp_);
298 }
299 return res;
300}
301
302//correspond a Drho_DH en fait
303double Loi_Etat_rhoT_GR_QC::Drho_DT(double P, double h) const
304{
305 double res = 0;
306 if (R==-1)
307 {
308 int i,j;
309 double H = h;
310 for (i=1 ; i<PolyRho_.dimension(0) ; i++)
311 for (j=0 ; j<PolyRho_.line_size() ; j++)
312 res += i* PolyRho_(i,j) *pow(P,j) *pow(H,i-1);
313 }
314 else
315 {
316 //debuggage
317 res = -P*Cp_/(R*h*h);
318 }
319 return res;
320}
321
322double Loi_Etat_rhoT_GR_QC::DT_DH(double P, double h) const
323{
324 double res = 0;
325 if (R==-1)
326 {
327 int i,j;
328 double H = h;
329 for (i=0 ; i<PolyT_.dimension(0) ; i++)
330 for (j=1 ; j<PolyT_.line_size() ; j++)
331 res += j* PolyT_(i,j) *pow(P,i) *pow(H,j-1);
332 }
333 else
334 {
335 //debuggage
336 res = Cp_-R;
337 }
338 return res;
339}
340
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
classe Loi_Etat_GR_base Cette classe represente la loi d'etat base pour les gaz reels.
void calculer_masse_volumique() override
Recalcule la masse volumique.
classe Loi_Etat_rhoT_GR_QC Cette classe represente la loi d'etat pour les gaz reels.
double Drho_DP(double, double) const override
double Drho_DT(double, double) const override
double calculer_temperature(double, double) override
Calcule la temperature ponctuelle.
double calculer_H(double, double) const override
Cas gaz Reel : doit recalculer l'enthalpie a partir de la pression et la temperature.
double DT_DH(double, double) const override
void calculer_masse_volumique() override
Recalcule la masse volumique.
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
static void abort()
Routine de sortie de Trio-U sur une erreur abort().
Definition Process.cpp:570
Classe de base des flux de sortie.
Definition Sortie.h:52