OpenWAM
TDepVolVariable.cpp
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 #pragma hdrstop
30 
31 #include "TDepVolVariable.h"
32 
33 #include "TCCDeposito.h"
34 #include "TCCUnionEntreDepositos.h"
35 #include "TTubo.h"
36 
37 //---------------------------------------------------------------------------
38 //---------------------------------------------------------------------------
39 
40 TDepVolVariable::TDepVolVariable(int i, int ncv, nmTipoCalculoEspecies SpeciesModel, int numeroespecies,
41  nmCalculoGamma GammaCalculation, bool ThereIsEGR) :
42  TDeposito(i, nmDepVolVble, SpeciesModel, numeroespecies, GammaCalculation, ThereIsEGR) {
43 
44  FNumeroCompresorVol = ncv + 1;
45 
46 }
47 
48 //---------------------------------------------------------------------------
49 //---------------------------------------------------------------------------
50 
51 TDepVolVariable::~TDepVolVariable() {
52 }
53 
54 //---------------------------------------------------------------------------
55 //---------------------------------------------------------------------------
56 
57 void TDepVolVariable::LeeDatosDepVolVariable(const char *FileWAM, fpos_t &filepos, bool HayMotor) {
58  try {
59 
60  int ControlRegimen = 0;
61 
62  FILE *fich = fopen(FileWAM, "r");
63  fsetpos(fich, &filepos);
64 
65  fscanf(fich, "%lf %lf %lf ", &FLBiela, &FCarrera, &FDiametro);
66  fscanf(fich, "%lf %lf %lf ", &FRelCompre, &FDesfase, &FDescentramiento);
67 
68  fscanf(fich, "%d ", &ControlRegimen);
69 
70  switch(ControlRegimen) {
71  case 0:
72  FControlRegimen = nmPropio;
73  break;
74  case 1:
75  FControlRegimen = nmMotor;
76  break;
77  }
78  if(FControlRegimen == nmPropio) {
79  fscanf(fich, "%lf ", &FRegimen);
80  FRelacionVelocidades = 1.;
81  } else if(FControlRegimen == nmMotor && HayMotor) {
82  fscanf(fich, "%lf ", &FRelacionVelocidades);
83  } else {
84  std::cout << "ERROR: TDepVolVariable::LeeDatosIniciales Lectura del Control del Regimen erronea " << std::endl;
85  throw Exception(" ");
86  }
87 
88  fgetpos(fich, &filepos);
89  fclose(fich);
90 
91  FVolumenMuerto = __geom::Circle_area(FDiametro) * FCarrera / (FRelCompre - 1.);
92 
93  } catch(exception &N) {
94  std::cout << "ERROR: TDepVolVariable::LeeDatosDepVolVariable en el compresor volumetrico: " << FNumeroCompresor <<
95  std::endl;
96 //std::cout << "Tipo de error: " << N.what() << std::endl;
97  throw Exception(N.what());
98  }
99 }
100 
101 //---------------------------------------------------------------------------
102 //---------------------------------------------------------------------------
103 
104 void TDepVolVariable::ActualizaPropiedades(double TimeCalculo) {
105 
106  double H = 0.; //Entalpia de entrada
107  double Energia = 0.;
108  double MasaEntrante, FraccionMasicaAcum = 0.;
109  double DeltaT = 0., DeltaAngulo = 0.;
110  double g = 0., v = 0., a = 0., m = 0.;
111  int SignoFlujo = 1, SignoFlujoED = 1;
112 
113  try {
114  FMasa0 = FMasa;
115  MasaEntrante = 0.;
116  H = 0.;
117  DeltaT = TimeCalculo - FTime;
118  DeltaAngulo = 360 * FRegimen / 60. * DeltaT;
119  FAngulo += DeltaAngulo;
120  FVolumen0 = FVolumen;
121  FVolumen = CalculaVolumen(FAngulo, FCarrera, FLBiela, FDiametro, FVolumenMuerto);
122 
123  if(FCalculoEspecies == nmCalculoCompleto) {
124 
125  FRMezcla = CalculoCompletoRMezcla(FFraccionMasicaEspecie[0], FFraccionMasicaEspecie[1], FFraccionMasicaEspecie[2], 0,
126  FCalculoGamma, nmMEP);
127  FCpMezcla = CalculoCompletoCpMezcla(FFraccionMasicaEspecie[0], FFraccionMasicaEspecie[1], FFraccionMasicaEspecie[2], 0,
128  __units::degCToK(FTemperature), FCalculoGamma, nmMEP);
129  FGamma = CalculoCompletoGamma(FRMezcla, FCpMezcla, FCalculoGamma);
130 
131  } else if(FCalculoEspecies == nmCalculoSimple) {
132 
133  FRMezcla = CalculoSimpleRMezcla(FFraccionMasicaEspecie[0], FFraccionMasicaEspecie[1], FCalculoGamma, nmMEP);
134  FCvMezcla = CalculoSimpleCvMezcla(__units::degCToK(FTemperature), FFraccionMasicaEspecie[0], FFraccionMasicaEspecie[1],
135  FCalculoGamma, nmMEP);
136  FGamma = CalculoSimpleGamma(FRMezcla, FCvMezcla, FCalculoGamma);
137 
138  }
139 
140  for(int i = 0; i < FNumeroUniones; i++) {
141  if(dynamic_cast<TCCDeposito *>(FCCDeposito[i])->getSentidoFlujo() == nmEntrante) {
142  SignoFlujo = 1;
143  } else if(dynamic_cast<TCCDeposito *>(FCCDeposito[i])->getSentidoFlujo() == nmSaliente) {
144  SignoFlujo = -1;
145  }
146  g = (double) - dynamic_cast<TCCDeposito *>(FCCDeposito[i])->getMassflow();
147  m = g * DeltaT * FCCDeposito[i]->GetTuboExtremo(0).Pipe->getNumeroConductos();
148  v = (double) SignoFlujo * dynamic_cast<TCCDeposito *>(FCCDeposito[i])->getVelocity();
149  a = dynamic_cast<TCCDeposito *>(FCCDeposito[i])->getSpeedSound();
150  MasaEntrante += m;
151  if(v > 0) {
152  H += EntalpiaEntrada(a, v, m, FAsonido, FMasa0, FCCDeposito[i]->getGamma());
153  }
154  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
155  FMasaEspecie[j] += FCCDeposito[i]->GetFraccionMasicaEspecie(j) * m;
156  }
157  }
158  for(int i = 0; i < FNumeroUnionesED; i++) {
159 
160  if(FNumeroDeposito == dynamic_cast<TCCUnionEntreDepositos *>(FCCUnionEntreDep[i])->getNumeroDeposito1()) {
161  SignoFlujoED = dynamic_cast<TCCUnionEntreDepositos *>(FCCUnionEntreDep[i])->getSentidoFlujoED1();
162  } else if(FNumeroDeposito == dynamic_cast<TCCUnionEntreDepositos *>(FCCUnionEntreDep[i])->getNumeroDeposito2()) {
163  SignoFlujoED = dynamic_cast<TCCUnionEntreDepositos *>(FCCUnionEntreDep[i])->getSentidoFlujoED2();
164  } else
165  printf("ERROR:TDepVolVariable::ActualizaPropiedades en el deposito %d, union entre depositos %d\n", FNumeroDeposito, i);
166 
167  g = (double) SignoFlujoED * dynamic_cast<TCCUnionEntreDepositos *>(FCCUnionEntreDep[i])->getMassflow();
168  m = g * DeltaT;
169  a = (double) dynamic_cast<TCCUnionEntreDepositos *>(FCCUnionEntreDep[i])->getSpeedSound();
170  MasaEntrante += m;
171  if(g > 0) {
172  H += EntalpiaEntrada(a, 0, m, FAsonido, FMasa0, FCCUnionEntreDep[i]->getGamma());
173  }
174  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
175  FMasaEspecie[j] += FCCUnionEntreDep[i]->GetFraccionMasicaEspecie(j) * m;
176  }
177  }
178  FMasa = FMasa0 + MasaEntrante;
179  for(int j = 0; j < FNumeroEspecies - 2; j++) {
180  FFraccionMasicaEspecie[j] = FMasaEspecie[j] / FMasa;
181  FraccionMasicaAcum += FFraccionMasicaEspecie[j];
182  }
183  FFraccionMasicaEspecie[FNumeroEspecies - 2] = 1. - FraccionMasicaAcum;
184  if(FHayEGR)
185  FFraccionMasicaEspecie[FNumeroEspecies - 1] = FMasaEspecie[FNumeroEspecies - 1] / FMasa;
186 
187  Energia = pow(FVolumen0 * FMasa / FMasa0 / FVolumen * exp(H), __Gamma::G1(FGamma));
188  FAsonido *= sqrt(Energia);
189  FPressure = __units::PaToBar(pow2(__cons::ARef * FAsonido) * FMasa / (FGamma * FVolumen));
190  FPresionIsen = pow(FPressure / FPresRef, __Gamma::G5(FGamma));
191  FTemperature = __units::KTodegC(pow2(FAsonido * __cons::ARef) / (FGamma * FRMezcla));
192  FTime = TimeCalculo;
193  if(FAngulo > 360.) {
194  FAngulo -= 360.;
195  }
196 
197  } catch(exception &N) {
198  std::cout << "ERROR: TDepVolVariable::ActualizaPropiedades en el compresor volumetrico: " << FNumeroCompresorVol <<
199  std::endl;
200  std::cout << "Tipo de error: " << N.what() << std::endl;
201  throw Exception(N.what());
202  }
203 }
204 
205 //---------------------------------------------------------------------------
206 //---------------------------------------------------------------------------
207 
208 double TDepVolVariable::CalculaVolumen(double CrankAngle, double carrera, double lbiela, double diametro,
209  double vol_muerto) {
210  double c = 0., tt = 0., ttt = 0.;
211  double ret_val = 0.;
212 
213  try {
214 
215  c = __units::DegToRad(CrankAngle);
216  tt = pow2(lbiela);
217  tt -= pow2(carrera * sin(c) / 2.);
218  tt = sqrt(tt);
219  ttt = lbiela + carrera * (1. - cos(c)) / 2. - tt;
220  ret_val = ttt * __geom::Circle_area(diametro);
221  ret_val += vol_muerto;
222  return ret_val;
223 
224  } catch(exception &N) {
225  std::cout << "ERROR: TDepVolVariable::CalculaVolumen en el compresor volumetrico: " << FNumeroCompresorVol << std::endl;
226  std::cout << "Tipo de error: " << N.what() << std::endl;
227  throw Exception(N.what());
228  }
229 }
230 
231 //---------------------------------------------------------------------------
232 //---------------------------------------------------------------------------
233 
234 void TDepVolVariable::IniciaVolumen(double Theta) {
235  try {
236  FAngulo = Theta - FDesfase;
237  FVolumen = CalculaVolumen(FAngulo, FCarrera, FLBiela, FDiametro, FVolumenMuerto);
238  FMasa = FVolumen * FGamma * __units::BarToPa(FPressure) / pow2(FAsonido * __cons::ARef);
239  FVolumen0 = FVolumen;
240  } catch(exception &N) {
241  std::cout << "ERROR: TDepVolVariable::IniciaVolumen en el compresor volumetrico: " << FNumeroCompresorVol << std::endl;
242  std::cout << "Tipo de error: " << N.what() << std::endl;
243  throw Exception(N.what());
244  }
245 }
246 
247 void TDepVolVariable::UpdateProperties0DModel(double TimeCalculo) {
248 
249  ActualizaPropiedades(TimeCalculo);
250 
251  AcumulaResultadosMedios(TimeCalculo);
252 
253 }
254 
255 void TDepVolVariable::UpdateSpeed(double NewSpeed) {
256  FRegimen = NewSpeed * FRelacionVelocidades;
257 }
258 
259 //---------------------------------------------------------------------------
260 //---------------------------------------------------------------------------
261 
262 #pragma package(smart_init)
263 
TCCUnionEntreDepositos
Definition: TCCUnionEntreDepositos.h:41
TDeposito
Definition: TDeposito.h:44
Exception
Custom exception class.
Definition: Exception.hpp:39
TTubo.h
TCCDeposito
Definition: TCCDeposito.h:40
pow2
T pow2(T x)
Returns x to the power of 2.
Definition: Math_wam.h:88