OpenWAM
SolverCompresor.h
1 /*--------------------------------------------------------------------------------*\
2 ==========================|
3  \\ /\ /\ // O pen | OpenWAM: The Open Source 1D Gas-Dynamic Code
4  \\ | X | // W ave |
5  \\ \/_\/ // A ction | CMT-Motores Termicos / Universidad Politecnica Valencia
6  \\/ \// M odel |
7  ----------------------------------------------------------------------------------
8  License
9 
10  This file is part of OpenWAM.
11 
12  OpenWAM is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  OpenWAM is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with OpenWAM. If not, see <http://www.gnu.org/licenses/>.
24 
25 
26  \*--------------------------------------------------------------------------------*/
27 
28 //---------------------------------------------------------------------------
29 #ifndef SolverCompresorH
30 #define SolverCompresorH
31 //---------------------------------------------------------------------------
32 
33 //#include "roots.h"
34 #include "Constantes.h"
35 
37 
38  Doub Massflow;
39  Doub SecOut;
40  Doub TempTotOut;
41  Doub PresTotOut;
42  Doub CpMezcla;
43  Doub RMezcla;
44  Doub Gam;
45 
46  Doub RhoOut;
47  Doub TempOut;
48  Doub PresOut;
49  Doub VOut;
50 
51  stCompSolverVOut(Doub gas, Doub sout, Doub ttout, Doub ptout, Doub cpm, Doub rm, Doub g) {
52  Massflow = gas;
53  SecOut = sout;
54  TempTotOut = ttout;
55  PresTotOut = ptout;
56  CpMezcla = cpm;
57  RMezcla = rm;
58  Gam = g;
59  }
60  Doub operator()(const Doub AOut) {
61 // RhoOut=abs(Massflow/SecOut * VOut);
62 // TempOut=TempTotOut-pow(VOut,2)/2./CpMezcla;
63 // PresOut=RhoOut*TempOut*RMezcla;
64 // return PresTotOut-PresOut*pow(TempTotOut/TempOut,Gam/(Gam-1));
65 
66  TempOut = AOut * AOut / Gam / RMezcla;
67  VOut = sqrt((TempTotOut - TempOut) * 2 * CpMezcla);
68  PresOut = PresTotOut / pow(TempTotOut / TempOut, Gam / (Gam - 1));
69  return Massflow - PresOut / RMezcla / TempOut * VOut * SecOut;
70  }
71 };
72 
74 
75  Doub CarIn;
76  Doub CarOut;
77  Doub AaIn;
78  Doub Gam;
79  Doub RMezcla;
80  Doub CpMezcla;
81  Doub SecIn;
82  Doub SecOut;
83  Doub RelComp;
84  Doub CoefPres;
85  Doub VOut;
86  Int_ Sig;
87  Int_ SentFlow;
88  Bool Direct;
89 
90  Doub Gam1;
91  Doub Gam4;
92  Doub PresIn;
93  Doub TempIn;
94  Doub TempOut;
95  Doub RhoIn;
96  Doub VIn;
97  Doub AOut;
98  Doub TempTotIn;
99  Doub TempTotInAnt;
100  Doub TempTotOut;
101  Doub PresTotIn;
102  Doub PresTotOut;
103  Doub Massflow;
104 
105  stCompSolverVIn(Doub cari, Doub caro, Doub aai, Doub g, Doub rm, Doub cpm, Doub sin, Doub sout, Doub rc, Doub cpre,
106  Int_ s, Int_ sf, Doub ttinant, Doub ttoutant, Bool dir, Bool firt) {
107  CarIn = cari;
108  CarOut = caro;
109  AaIn = aai;
110  Sig = s;
111  Gam = g;
112  Gam1 = Gam - 1;
113  Gam4 = 2 * Gam / Gam1;
114  RMezcla = rm;
115  CpMezcla = cpm;
116  SentFlow = sf;
117  RelComp = rc;
118  CoefPres = cpre;
119  Direct = dir;
120  TempTotInAnt = ttinant;
121  SecIn = sin;
122  SecOut = sout;
123  }
124  Doub operator()(const Doub AIn) {
125 
126 // AIn=__cons::ARef*CarIn-(double)Sig*0.5*Gam1*VIn;
127 // PresIn=1e5*pow(AaIn/AIn,-Gam4);
128 // TempIn=pow(AIn,2.)/Gam/RMezcla;
129 // RhoIn=PresIn/(RMezcla*TempIn);
130 // TempTotIn=TempIn+pow(VIn,2.)/2./CpMezcla;
131 // PresTotIn=PresIn*pow(TempTotIn/TempIn,Gam/Gam1);
132 //
133 // Massflow=SentFlow*SecIn*RhoIn*VIn;
134 //
135 // PresTotOut=PresTotIn*pow(RelComp,SentFlow);
136 //
137 // if(Direct){
138 // TempTotOut=TempTotIn*(1+CoefPres);
139 // }else{
140 // TempTotOut=TempTotInAnt;
141 // }
142 // Doub VOutMin=0.;
143 // Doub VOutMax=(double)Sig*2*__cons::ARef*CarOut/(3-Gam);
144 //
145 // Doub VMax1=-sqrt(2*CpMezcla*TempTotOut);
146 // if(VOutMax < VMax1){
147 // VOutMax=VMax1;
148 // }
149 //
150 // VMax1=sqrt(2*RMezcla*Gam*TempTotOut/(Gam+1));
151 // if(VOutMax < VMax1){
152 // VOutMax=VMax1;
153 // }
154 
155  PresIn = __units::BarToPa(pow(AaIn / AIn, -Gam4));
156  TempIn = pow2(AIn) / Gam / RMezcla;
157  VIn = 2 * (__cons::ARef * CarIn - AIn) / Gam1;
158  RhoIn = PresIn / (RMezcla * TempIn);
159  TempTotIn = TempIn + pow2(VIn) / 2. / CpMezcla;
160  PresTotIn = PresIn * pow(TempTotIn / TempIn, Gam / Gam1);
161 
162  Massflow = SentFlow * SecIn * RhoIn * VIn;
163 
164  PresTotOut = PresTotIn * pow(RelComp, SentFlow);
165 
166  if(Direct) {
167  TempTotOut = TempTotIn * (1 + CoefPres);
168  } else {
169  TempTotOut = TempTotInAnt;
170  }
171 
172  Doub AOutMin = CarOut * __cons::ARef;
173  Doub AOutMax = 2 * CarOut * __cons::ARef / (3 - Gam);
174 
175  Doub lim = sqrt(Gam * RMezcla * TempTotOut);
176  if(AOutMax > lim)
177  AOutMax = lim;
178  if(AOutMin < lim) {
179 
180  stCompSolverVOut FunAout(Massflow, SecOut, TempTotOut, PresTotOut, CpMezcla, RMezcla, Gam);
181 
182  AOut = rtbis(FunAout, AOutMin, AOutMax, 1e-10);
183 
184  VOut = FunAout.VOut;
185  } else {
186  return 1.;
187  }
188 
189  //AOut=sqrt(Gam * RMezcla*TempOut);
190  return CarOut * __cons::ARef - (AOut - (double) Sig * VOut * Gam1 / 2) / __cons::ARef;
191 
192  }
193 };
194 
195 #endif
Constantes.h
stCompSolverVIn
Definition: SolverCompresor.h:73
pow2
T pow2(T x)
Returns x to the power of 2.
Definition: Math_wam.h:88
stCompSolverVOut
Definition: SolverCompresor.h:36