OpenWAM
TVenturi.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 "TVenturi.h"
32 
33 #include "TCCDeposito.h"
34 #include "TTubo.h"
35 #include "TTipoValvula.h"
36 
37 // ---------------------------------------------------------------------------
38 // ---------------------------------------------------------------------------
39 
40 TVenturi::TVenturi(int i, nmTipoCalculoEspecies SpeciesModel, int numeroespecies, nmCalculoGamma GammaCalculation,
41  bool ThereIsEGR) :
42  TDepVolCteBase(i, nmVenturi, SpeciesModel, numeroespecies, GammaCalculation, ThereIsEGR) {
43 
44  asgNumeroVenturi = false;
45 
46  FResInstantVenturi.PresionEntrada = false;
47  FResInstantVenturi.PresionGarganta = false;
48  FResInstantVenturi.MachEntrada = false;
49  FResInstantVenturi.MachGarganta = false;
50  FResInstantVenturi.VelEntrada = false;
51  FResInstantVenturi.VelLateral = false;
52  FResInstantVenturi.GastoEntrada = false;
53  FResInstantVenturi.GastoLateral = false;
54 
55  FResMediosVenturi.PresionEntrada = false;
56  FResMediosVenturi.PresionGarganta = false;
57  FResMediosVenturi.MachEntrada = false;
58  FResMediosVenturi.MachGarganta = false;
59  FResMediosVenturi.VelEntrada = false;
60  FResMediosVenturi.VelLateral = false;
61  FResMediosVenturi.GastoEntrada = false;
62  FResMediosVenturi.GastoLateral = false;
63 
64  FResMediosVenturi.Tiempo0 = 0.;
65  FResMediosVenturi.TiempoSUM = 0.;
66  FResMediosVenturi.PresionEntradaSUM = 0.;
67  FResMediosVenturi.PresionGargantaSUM = 0.;
68  FResMediosVenturi.MachEntradaSUM = 0.;
69  FResMediosVenturi.MachGargantaSUM = 0.;
70  FResMediosVenturi.VelEntradaSUM = 0.;
71  FResMediosVenturi.VelLateralSUM = 0.;
72  FResMediosVenturi.GastoEntradaSUM = 0.;
73  FResMediosVenturi.GastoLateralSUM = 0.;
74 
75 }
76 
77 // ---------------------------------------------------------------------------
78 // ---------------------------------------------------------------------------
79 
80 TVenturi::~TVenturi() {
81 }
82 
83 // ---------------------------------------------------------------------------
84 // ---------------------------------------------------------------------------
85 
86 void TVenturi::LeeDatosVenturi(const char *FileWAM, fpos_t &filepos) {
87  try {
88  int numid = 0; // dato para Wamer
89  FILE *fich = fopen(FileWAM, "r");
90  fsetpos(fich, &filepos);
91 
92  fscanf(fich, "%d ", &numid); /* DATO PARA WAMER */
93  fscanf(fich, "%d %d %d ", &FNodoEntrada, &FNodoSalida, &FNodoLateral);
94  fscanf(fich, "%lf %lf %lf ", &FRelacionSecciones, &FRendimientoVenturi, &FPerdidasCalor);
95 
96  fgetpos(fich, &filepos);
97  fclose(fich);
98 
99  } catch(exception & N) {
100  std::cout << "ERROR: TVenturi::LeeDatosVenturi en el deposito: " << FNumeroDeposito << std::endl;
101  // std::cout << "Tipo de error: " << N.what() << std::endl;
102  throw Exception(N.what());
103  }
104 }
105 
106 // ---------------------------------------------------------------------------
107 // ---------------------------------------------------------------------------
108 
109 void TVenturi::ActualizaPropiedades(double TimeCalculo) {
110 
111  double H = 0.; // Entalpia de entrada
112  double Energia = 0.;
113  double MasaEntrante, FraccionMasicaAcum = 0.;
114  double DeltaT = 0.;
115  double g = 0., v = 0., a = 0., m = 0.;
116  int SignoFlujo = 1;
117 
118  try {
119  FMasa0 = FMasa;
120  MasaEntrante = 0.;
121  H = 0.;
122  DeltaT = TimeCalculo - FTime;
123 
124  if(FCalculoEspecies == nmCalculoCompleto) {
125 
126  FRMezcla = CalculoCompletoRMezcla(FFraccionMasicaEspecie[0], FFraccionMasicaEspecie[1], FFraccionMasicaEspecie[2], 0,
127  FCalculoGamma, nmMEP);
128  FCpMezcla = CalculoCompletoCpMezcla(FFraccionMasicaEspecie[0], FFraccionMasicaEspecie[1], FFraccionMasicaEspecie[2], 0,
129  __units::degCToK(FTemperature), FCalculoGamma, nmMEP);
130  FGamma = CalculoCompletoGamma(FRMezcla, FCpMezcla, FCalculoGamma);
131 
132  } else if(FCalculoEspecies == nmCalculoSimple) {
133 
134  FRMezcla = CalculoSimpleRMezcla(FFraccionMasicaEspecie[0], FFraccionMasicaEspecie[1], FCalculoGamma, nmMEP);
135  FCvMezcla = CalculoSimpleCvMezcla(__units::degCToK(FTemperature), FFraccionMasicaEspecie[0], FFraccionMasicaEspecie[1],
136  FCalculoGamma, nmMEP);
137  FGamma = CalculoSimpleGamma(FRMezcla, FCvMezcla, FCalculoGamma);
138 
139  }
140 
141  FGamma1 = __Gamma::G1(FGamma);
142  FGamma2 = __Gamma::G2(FGamma);
143  FGamma3 = __Gamma::G3(FGamma);
144  FGamma5 = __Gamma::G5(FGamma);
145  FGamma6 = __Gamma::G6(FGamma);
146 
147  bool Converge = false;
148  bool FirstStep = true;
149  double H0 = 0.;
150  double Asonido0 = FAsonido;
151  double Asonido1 = FAsonido;
152  double Error = 0.;
153  double Diff = 0.;
154 
155  while(!Converge) {
156  H = 0.;
157  for(int i = 0; i < FNumeroUniones; i++) {
158  if(dynamic_cast<TCCDeposito*>(FCCDeposito[i])->getSentidoFlujo() == nmEntrante) {
159  SignoFlujo = 1;
160  } else if(dynamic_cast<TCCDeposito*>(FCCDeposito[i])->getSentidoFlujo() == nmSaliente) {
161  SignoFlujo = -1;
162  }
163  g = (double) - dynamic_cast<TCCDeposito*>(FCCDeposito[i])->getMassflow();
164  v = (double) SignoFlujo * dynamic_cast<TCCDeposito*>(FCCDeposito[i])->getVelocity();
165  a = dynamic_cast<TCCDeposito*>(FCCDeposito[i])->getSpeedSound();
166  m = g * DeltaT * FCCDeposito[i]->GetTuboExtremo(0).Pipe->getNumeroConductos();
167  if(FirstStep) {
168  MasaEntrante += m;
169  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
170  FMasaEspecie[j] += FCCDeposito[i]->GetFraccionMasicaEspecie(j) * m;
171  }
172  }
173  if(v > 0) {
174  H += EntalpiaEntrada(a, v, m, Asonido1, FMasa, FCCDeposito[i]->getGamma());
175  }
176 
177  }
178  if(FirstStep) {
179  FMasa = FMasa0 + MasaEntrante;
180  for(int j = 0; j < FNumeroEspecies - 2; j++) {
181  FFraccionMasicaEspecie[j] = FMasaEspecie[j] / FMasa;
182  FraccionMasicaAcum += FFraccionMasicaEspecie[j];
183  }
184  FFraccionMasicaEspecie[FNumeroEspecies - 2] = 1. - FraccionMasicaAcum;
185  if(FHayEGR)
186  FFraccionMasicaEspecie[FNumeroEspecies - 1] = FMasaEspecie[FNumeroEspecies - 1] / FMasa;
187  H0 = H;
188  FirstStep = false;
189  }
190 
191  Energia = pow(FMasa / FMasa0 * exp((H + H0) / 2), FGamma1);
192  Asonido1 = FAsonido * sqrt(Energia);
193  Error = (Diff = Asonido1 - Asonido0, fabs(Diff)) / Asonido1;
194  if(Error > 1e-6) {
195  Asonido0 = Asonido1;
196  } else {
197  FAsonido = Asonido1;
198  Converge = true;
199  }
200  }
201  FTemperature = __units::KTodegC(pow2(FAsonido * __cons::ARef) / (FGamma * FRMezcla));
202  FPressure = __units::PaToBar(pow2(__cons::ARef * FAsonido) / FGamma / FVolumen * FMasa);
203  FPresionIsen = pow(FPressure / FPresRef, FGamma5);
204  FTime = TimeCalculo;
205  } catch(exception & N) {
206  std::cout << "ERROR: TVenturi::ActualizaPropiedades en el venturi: " << FNumeroVenturi << std::endl;
207  std::cout << "Tipo de error: " << N.what() << std::endl;
208  throw Exception(N.what());
209  }
210 }
211 
212 // ---------------------------------------------------------------------------
213 // ---------------------------------------------------------------------------
214 
215 void TVenturi::AsignaEntradaSalidaLateralCC() {
216  try {
217 
218  if(FTipoDeposito == nmVenturi) {
219  for(int i = 0; i < FNumeroUniones; i++) {
220  if(FCCDeposito[i]->getNumeroCC() == FNodoEntrada) {
221  FCCEntrada = FCCDeposito[i];
222  } else if(FCCDeposito[i]->getNumeroCC() == FNodoSalida) {
223  FCCSalida = FCCDeposito[i];
224  } else if(FCCDeposito[i]->getNumeroCC() == FNodoLateral) {
225  FCCLateral = FCCDeposito[i];
226  }
227  }
228  }
229 
230  } catch(exception & N) {
231  std::cout << "ERROR: TVenturi::AsignaEntradaSalidaLateralCC en el venturi " << FNumeroVenturi << std::endl;
232  std::cout << "Tipo de error: " << N.what() << std::endl;
233  throw Exception(N.what());
234  }
235 }
236 
237 // ---------------------------------------------------------------------------
238 // ---------------------------------------------------------------------------
239 
240 void TVenturi::CalculaVenturi() {
241 
242  // El venturi se considera simetrico, es decir, el fluido puede entrar tanto por el
243  // ramal de entrada como por el ramal de salida.
244 
245  try {
246  double Velocity = 0., Speedsound = 0.;
247  double Converge = 0., VelGarganta0 = 0., VelGarganta1 = 0.;
248  double Mach0 = 0., Mach1 = 0.;
249  double CSup = 0.;
250  double TempGarganta = 0., TempEntrada = 0.;
251  int SentidoEntrada = 0, SentidoSalida = 0;
252 
253  TempEntrada = __units::degCToK(FTemperature);
254 
255  if(dynamic_cast<TCCDeposito*>(FCCEntrada)->getSentidoFlujo() == nmEntrante) {
256  SentidoEntrada = 1;
257  } else if(dynamic_cast<TCCDeposito*>(FCCEntrada)->getSentidoFlujo() == nmSaliente) {
258  SentidoEntrada = -1;
259  }
260 
261  Velocity = SentidoEntrada * dynamic_cast<TCCDeposito*>(FCCEntrada)->getVelocity();
262  Speedsound = dynamic_cast<TCCDeposito*>(FCCEntrada)->getSpeedSound();
263 
264  if(Velocity > 0.0) {
265  if(Speedsound > 0)
266  dynamic_cast<TCCDeposito*>(FCCEntrada)->putMachVenturi(Velocity / Speedsound);
267  dynamic_cast<TCCDeposito*>(FCCSalida)->putMachVenturi(0.);
268 // if(Speedsound > 0) dynamic_cast<TCCDeposito *>(FCCEntrada)->getValvula()->getCRecuperacion() = Velocity / Speedsound;
269 // dynamic_cast<TCCDeposito *>(FCCSalida)->getValvula()->getCRecuperacion() = 0.;
270  } else {
271  if(dynamic_cast<TCCDeposito*>(FCCSalida)->getSentidoFlujo() == nmEntrante) {
272  SentidoSalida = 1;
273  } else if(dynamic_cast<TCCDeposito*>(FCCSalida)->getSentidoFlujo() == nmSaliente) {
274  SentidoSalida = -1;
275  }
276  Velocity = SentidoSalida * dynamic_cast<TCCDeposito*>(FCCSalida)->getVelocity();
277  Speedsound = dynamic_cast<TCCDeposito*>(FCCSalida)->getSpeedSound();
278  dynamic_cast<TCCDeposito*>(FCCEntrada)->putMachVenturi(0.);
279  if(Speedsound > 0)
280  dynamic_cast<TCCDeposito*>(FCCSalida)->putMachVenturi(Velocity / Speedsound);
281 // dynamic_cast<TCCDeposito *>(FCCEntrada)->getValvula()->getCRecuperacion() = 0.;
282 // if(Speedsound > 0) dynamic_cast<TCCDeposito *>(FCCSalida)->getValvula()->getCRecuperacion() = Velocity / Speedsound;
283  }
284 
285  Mach0 = Velocity / FAsonido;
286  Mach1 = Mach0 * FRelacionSecciones;
287 
288  FCpMezcla = FGamma * FRMezcla / FGamma1;
289 
290  TempGarganta = TempEntrada - pow((FRelacionSecciones - 1.) * Velocity * __cons::ARef, 2.) / (2. * FCpMezcla);
291 
292  Converge = 0.;
293  VelGarganta0 = Velocity;
294  VelGarganta1 = Velocity;
295 
296  if(Velocity > 0. && FRelacionSecciones > 0.) {
297  while(Converge < 0.99999 || Converge > 1.00001) {
298  if(Mach1 > 0.99999999) {
299  Mach1 = 1.;
300  printf("N. de Mach en el venturi situado en el deposito %d = 1. ", FNumeroDeposito);
301  printf("Velocity = %g (m/s) \t", VelGarganta1 * __cons::ARef);
302  printf("Temperature = %g (degC)\n", TempGarganta);
303  } else if(Mach1 == 1.) {
304  VelGarganta1 = sqrt(((1. + FGamma1 / 2. * pow2(Mach0)) / (FGamma2 * pow2(Mach0) / 2.) * pow2(Velocity)));
305  } else {
306  VelGarganta1 = FRelacionSecciones * Velocity * pow(TempEntrada / TempGarganta, FGamma6);
307  }
308 
309  TempGarganta = TempEntrada - (pow2(VelGarganta1 * __cons::ARef) - pow2(Velocity * __cons::ARef)) / (2. * FCpMezcla);
310 
311  Mach1 = VelGarganta1 * __cons::ARef / sqrt(FGamma * FRMezcla * TempGarganta);
312  Converge = VelGarganta1 / VelGarganta0;
313  VelGarganta0 = VelGarganta1;
314  }
315  VelGarganta0 = sqrt((FRendimientoVenturi * pow2(VelGarganta0) - FPerdidasCalor * 2.));
316 // dynamic_cast<TCCDeposito *>(FCCLateral)->getValvula()->getCRecuperacion() = (VelGarganta0 * __cons::ARef)/pow(FGamma*FRMezcla*TempGarganta,0.5);
317  dynamic_cast<TCCDeposito*>(FCCLateral)->putMachVenturi((VelGarganta0 * __cons::ARef) / pow(
318  FGamma * FRMezcla * TempGarganta, 0.5));
319  } else {
320 // dynamic_cast<TCCDeposito *>(FCCLateral)->getValvula()->getCRecuperacion() = 0.;
321  dynamic_cast<TCCDeposito*>(FCCLateral)->putMachVenturi(0.);
322  }
323 
324  } catch(exception & N) {
325  std::cout << "ERROR: TVenturi::CalculaVenturi en el venturi: " << FNumeroVenturi << std::endl;
326  std::cout << "Tipo de error: " << N.what() << std::endl;
327  throw Exception(N.what());
328  }
329 }
330 
331 // ---------------------------------------------------------------------------
332 // ---------------------------------------------------------------------------
333 
334 //void TVenturi::PutNumeroVenturi(int NumeroVenturi) {
335 // try {
336 // if (!asgNumeroVenturi) {
337 // FNumeroVenturi = NumeroVenturi;
338 // asgNumeroVenturi = true;
339 // }
340 // else {
341 // std::cout << "ERROR: Este Venturi ya tiene numero asignado" << std::endl;
342 // throw Exception("");
343 // }
344 // }
345 // catch(Exception & N) {
346 // std::cout << "ERROR: TVenturi::PutNumeroVenturi en la Venturi " << FNumeroVenturi << std::endl;
347 // std::cout << "Tipo de error: " << N.what() << std::endl;
348 // throw Exception(N.what());
349 // }
350 //}
351 
352 // ---------------------------------------------------------------------------
353 // ---------------------------------------------------------------------------
354 
355 void TVenturi::LeeResultadosInstantVenturi(const char *FileWAM, fpos_t &filepos) {
356 
357  int nvars = 0, var = 0;
358 
359  try {
360  FILE *fich = fopen(FileWAM, "r");
361  fsetpos(fich, &filepos);
362 
363  fscanf(fich, "%d ", &nvars);
364  for(int i = 0; i < nvars; ++i) {
365  fscanf(fich, "%d ", &var);
366  switch(var) {
367  case 0:
368  FResInstantVenturi.PresionEntrada = true;
369  break;
370  case 1:
371  FResInstantVenturi.PresionGarganta = true;
372  break;
373  case 2:
374  FResInstantVenturi.MachEntrada = true;
375  break;
376  case 3:
377  FResInstantVenturi.MachGarganta = true;
378  break;
379  case 4:
380  FResInstantVenturi.VelEntrada = true;
381  break;
382  case 5:
383  FResInstantVenturi.VelLateral = true;
384  break;
385  case 6:
386  FResInstantVenturi.GastoEntrada = true;
387  break;
388  case 7:
389  FResInstantVenturi.GastoLateral = true;
390  break;
391  default:
392  std::cout << "Resultados instantaneos en venturi " << FNumeroVenturi << " no implementados " << std::endl;
393  }
394  }
395 
396  fgetpos(fich, &filepos);
397  fclose(fich);
398  } catch(exception & N) {
399  std::cout << "ERROR: TVenturi::LeeResultadosInstantVenturi en el venturi: " << FNumeroVenturi << std::endl;
400  std::cout << "Tipo de error: " << N.what() << std::endl;
401  throw Exception(N.what());
402  }
403 }
404 
405 // ---------------------------------------------------------------------------
406 // ---------------------------------------------------------------------------
407 
408 void TVenturi::CabeceraResultadosInstantVenturi(stringstream& insoutput) {
409  try {
410  // FILE *fich=fopen(FileSALIDA,"a");
411  std::string Label;
412 
413  if(FResInstantVenturi.PresionEntrada) {
414  Label = "\t" + PutLabel(521) + std::to_string(FNumeroVenturi) + PutLabel(908);
415  insoutput << Label.c_str();
416  }
417  if(FResInstantVenturi.PresionGarganta) {
418  Label = "\t" + PutLabel(522) + std::to_string(FNumeroVenturi) + PutLabel(908);
419  insoutput << Label.c_str();
420  }
421  if(FResInstantVenturi.MachEntrada) {
422  Label = "\t" + PutLabel(523) + std::to_string(FNumeroVenturi) + PutLabel(901);
423  insoutput << Label.c_str();
424  }
425  if(FResInstantVenturi.MachGarganta) {
426  Label = "\t" + PutLabel(524) + std::to_string(FNumeroVenturi) + PutLabel(901);
427  insoutput << Label.c_str();
428  }
429  if(FResInstantVenturi.VelEntrada) {
430  Label = "\t" + PutLabel(525) + std::to_string(FNumeroVenturi) + PutLabel(909);
431  insoutput << Label.c_str();
432  }
433  if(FResInstantVenturi.VelLateral) {
434  Label = "\t" + PutLabel(526) + std::to_string(FNumeroVenturi) + PutLabel(909);
435  insoutput << Label.c_str();
436  }
437  if(FResInstantVenturi.GastoEntrada) {
438  Label = "\t" + PutLabel(527) + std::to_string(FNumeroVenturi) + PutLabel(904);
439  insoutput << Label.c_str();
440  }
441  if(FResInstantVenturi.GastoLateral) {
442  Label = "\t" + PutLabel(528) + std::to_string(FNumeroVenturi) + PutLabel(904);
443  insoutput << Label.c_str();
444  }
445 
446  // fclose(fich);
447  } catch(exception & N) {
448  std::cout << "ERROR: TVenturi::CabeceraResultadosInstantVenturi en el venturi: " << FNumeroVenturi << std::endl;
449  std::cout << "Tipo de error: " << N.what() << std::endl;
450  throw Exception(N.what());
451  }
452 }
453 
454 // ---------------------------------------------------------------------------
455 // ---------------------------------------------------------------------------
456 
457 void TVenturi::ImprimeResultadosInstantVenturi(stringstream& insoutput) {
458  try {
459  // FILE *fich=fopen(FileSALIDA,"a");
460 
461  if(FResInstantVenturi.PresionEntrada)
462  insoutput << "\t" << FResInstantVenturi.PresionEntradaINS;
463  if(FResInstantVenturi.PresionGarganta)
464  insoutput << "\t" << FResInstantVenturi.PresionGargantaINS;
465  if(FResInstantVenturi.MachEntrada)
466  insoutput << "\t" << FResInstantVenturi.MachEntradaINS;
467  if(FResInstantVenturi.MachGarganta)
468  insoutput << "\t" << FResInstantVenturi.MachGargantaINS;
469  if(FResInstantVenturi.VelEntrada)
470  insoutput << "\t" << FResInstantVenturi.VelEntradaINS;
471  if(FResInstantVenturi.VelLateral)
472  insoutput << "\t" << FResInstantVenturi.VelLateralINS;
473  if(FResInstantVenturi.GastoEntrada)
474  insoutput << "\t" << FResInstantVenturi.GastoEntradaINS;
475  if(FResInstantVenturi.GastoLateral)
476  insoutput << "\t" << FResInstantVenturi.GastoLateralINS;
477 
478  // fclose(fich);
479  } catch(exception & N) {
480  std::cout << "ERROR: TVenturi::ImprimeResultadosInstantVenturi en el venturi: " << FNumeroVenturi << std::endl;
481  std::cout << "Tipo de error: " << N.what() << std::endl;
482  throw Exception(N.what());
483  }
484 }
485 
486 // ---------------------------------------------------------------------------
487 // ---------------------------------------------------------------------------
488 
489 void TVenturi::CalculaResultadosVenturi() {
490  try {
491  int SentidoEntrada = 0, SentidoLateral = 0, SentidoSalida = 0;
492  if(FResInstantVenturi.PresionEntrada) {
493  FResInstantVenturi.PresionEntradaINS = FPressure;
494  }
495  if(FResInstantVenturi.PresionGarganta) {
496  FResInstantVenturi.PresionGargantaINS = FPressure / pow(1 + FGamma1 / 2 * pow2(dynamic_cast<TCCDeposito*>
497  (FCCLateral)->getMachVenturi()), FGamma / FGamma1);
498  }
499  if(FResInstantVenturi.MachEntrada) {
500  if(dynamic_cast<TCCDeposito*>(FCCEntrada)->getMachVenturi() != 0) {
501  FResInstantVenturi.MachEntradaINS = fabs(dynamic_cast<TCCDeposito*>(FCCEntrada)->getMachVenturi());
502  } else {
503  FResInstantVenturi.MachEntradaINS = -fabs(dynamic_cast<TCCDeposito*>(FCCSalida)->getMachVenturi());
504  }
505  }
506  if(FResInstantVenturi.MachGarganta) {
507  FResInstantVenturi.MachGargantaINS = fabs(dynamic_cast<TCCDeposito*>(FCCLateral)->getMachVenturi());
508  }
509  if(FResInstantVenturi.VelEntrada) {
510  if(dynamic_cast<TCCDeposito*>(FCCEntrada)->getMachVenturi() != 0) {
511  if(dynamic_cast<TCCDeposito*>(FCCEntrada)->getSentidoFlujo() == nmEntrante) {
512  SentidoEntrada = 1;
513  } else if(dynamic_cast<TCCDeposito*>(FCCEntrada)->getSentidoFlujo() == nmSaliente) {
514  SentidoEntrada = -1;
515  }
516  FResInstantVenturi.VelEntradaINS = SentidoEntrada * __cons::ARef * dynamic_cast<TCCDeposito*>
517  (FCCEntrada)->getVelocity();
518  } else {
519  if(dynamic_cast<TCCDeposito*>(FCCSalida)->getSentidoFlujo() == nmEntrante) {
520  SentidoSalida = 1;
521  } else if(dynamic_cast<TCCDeposito*>(FCCSalida)->getSentidoFlujo() == nmSaliente) {
522  SentidoSalida = -1;
523  }
524  FResInstantVenturi.VelEntradaINS = SentidoSalida * __cons::ARef * dynamic_cast<TCCDeposito*>(FCCSalida)->getVelocity();
525  }
526  }
527 
528  if(FResInstantVenturi.VelLateral) {
529  if(dynamic_cast<TCCDeposito*>(FCCLateral)->getSentidoFlujo() == nmEntrante) {
530  SentidoLateral = 1;
531  } else if(dynamic_cast<TCCDeposito*>(FCCLateral)->getSentidoFlujo() == nmSaliente) {
532  SentidoLateral = -1;
533  }
534  FResInstantVenturi.VelLateralINS = SentidoLateral * __cons::ARef * dynamic_cast<TCCDeposito*>
535  (FCCLateral)->getVelocity();
536  }
537  if(FResInstantVenturi.GastoEntrada) {
538  if(dynamic_cast<TCCDeposito*>(FCCEntrada)->getMachVenturi() != 0) {
539  FResInstantVenturi.GastoEntradaINS = -dynamic_cast<TCCDeposito*>(FCCEntrada)->getMassflow();
540  } else {
541  FResInstantVenturi.GastoEntradaINS = -dynamic_cast<TCCDeposito*>(FCCSalida)->getMassflow();
542  }
543  }
544  if(FResInstantVenturi.GastoLateral) {
545  FResInstantVenturi.GastoLateralINS = -dynamic_cast<TCCDeposito*>(FCCLateral)->getMassflow();
546  }
547 
548  } catch(exception & N) {
549  std::cout << "ERROR: TVenturi::CalculaResultadosVenturi en el venturi: " << FNumeroVenturi << std::endl;
550  std::cout << "Tipo de error: " << N.what() << std::endl;
551  throw Exception(N.what());
552  }
553 }
554 
555 // ---------------------------------------------------------------------------
556 // ---------------------------------------------------------------------------
557 
558 void TVenturi::ReadAverageResultsVenturi(const char *FileWAM, fpos_t &filepos) {
559  int nvars = 0, var = 0;
560 
561  try {
562  FILE *fich = fopen(FileWAM, "r");
563  fsetpos(fich, &filepos);
564 
565  fscanf(fich, "%d ", &nvars);
566  for(int i = 0; i < nvars; ++i) {
567  fscanf(fich, "%d ", &var);
568  switch(var) {
569  case 0:
570  FResMediosVenturi.PresionEntrada = true;
571  break;
572  case 1:
573  FResMediosVenturi.PresionGarganta = true;
574  break;
575  case 2:
576  FResMediosVenturi.MachEntrada = true;
577  break;
578  case 3:
579  FResMediosVenturi.MachGarganta = true;
580  break;
581  case 4:
582  FResMediosVenturi.VelEntrada = true;
583  break;
584  case 5:
585  FResMediosVenturi.VelLateral = true;
586  break;
587  case 6:
588  FResMediosVenturi.GastoEntrada = true;
589  break;
590  case 7:
591  FResMediosVenturi.GastoLateral = true;
592  break;
593  default:
594  std::cout << "Resultados medios en venturi " << FNumeroVenturi << " no implementados " << std::endl;
595  }
596  }
597  fgetpos(fich, &filepos);
598  fclose(fich);
599  } catch(exception & N) {
600  std::cout << "ERROR: TVenturi::ReadAverageResultsVenturi en el venturi: " << FNumeroVenturi << std::endl;
601  std::cout << "Tipo de error: " << N.what() << std::endl;
602  throw Exception(N.what());
603  }
604 }
605 
606 // ---------------------------------------------------------------------------
607 // ---------------------------------------------------------------------------
608 
609 void TVenturi::HeaderAverageResultsVenturi(stringstream& medoutput) {
610  try {
611  // FILE *fich=fopen(FileSALIDA,"a");
612  std::string Label;
613 
614  if(FResMediosVenturi.PresionEntrada) {
615  Label = "\t" + PutLabel(521) + std::to_string(FNumeroVenturi) + PutLabel(908);
616  medoutput << Label.c_str();
617  }
618  if(FResMediosVenturi.PresionGarganta) {
619  Label = "\t" + PutLabel(522) + std::to_string(FNumeroVenturi) + PutLabel(908);
620  medoutput << Label.c_str();
621  }
622  if(FResMediosVenturi.MachEntrada) {
623  Label = "\t" + PutLabel(523) + std::to_string(FNumeroVenturi) + PutLabel(901);
624  medoutput << Label.c_str();
625  }
626  if(FResMediosVenturi.MachGarganta) {
627  Label = "\t" + PutLabel(524) + std::to_string(FNumeroVenturi) + PutLabel(901);
628  medoutput << Label.c_str();
629  }
630  if(FResMediosVenturi.VelEntrada) {
631  Label = "\t" + PutLabel(525) + std::to_string(FNumeroVenturi) + PutLabel(909);
632  medoutput << Label.c_str();
633  }
634  if(FResMediosVenturi.VelLateral) {
635  Label = "\t" + PutLabel(526) + std::to_string(FNumeroVenturi) + PutLabel(909);
636  medoutput << Label.c_str();
637  }
638  if(FResMediosVenturi.GastoEntrada) {
639  Label = "\t" + PutLabel(527) + std::to_string(FNumeroVenturi) + PutLabel(904);
640  medoutput << Label.c_str();
641  }
642  if(FResMediosVenturi.GastoLateral) {
643  Label = "\t" + PutLabel(528) + std::to_string(FNumeroVenturi) + PutLabel(904);
644  medoutput << Label.c_str();
645  }
646 
647  // fclose(fich);
648  } catch(exception & N) {
649  std::cout << "ERROR: TVenturi::HeaderAverageResultsVenturi en el venturi: " << FNumeroVenturi << std::endl;
650  std::cout << "Tipo de error: " << N.what() << std::endl;
651  throw Exception(N.what());
652  }
653 }
654 
655 // ---------------------------------------------------------------------------
656 // ---------------------------------------------------------------------------
657 
658 void TVenturi::AcumulaResultadosMediosVenturi(double Actual) {
659  try {
660  int SentidoEntrada = 0, SentidoLateral = 0;
661  double Delta = Actual - FResMediosVenturi.Tiempo0;
662 
663  if(FResMediosVenturi.PresionEntrada) {
664  FResMediosVenturi.PresionEntradaSUM += FPressure * Delta;
665  }
666  if(FResMediosVenturi.PresionGarganta) {
667  FResMediosVenturi.PresionGargantaSUM += (FPressure / pow(1 + FGamma1 / 2 * pow(dynamic_cast<TCCDeposito*>
668  (FCCLateral)->getMachVenturi(), 2.), FGamma / FGamma1)) * Delta;
669  }
670  if(FResMediosVenturi.MachEntrada) {
671  FResMediosVenturi.MachEntradaSUM += fabs(dynamic_cast<TCCDeposito*>(FCCEntrada)->getMachVenturi()) * Delta;
672  }
673  if(FResMediosVenturi.MachGarganta) {
674  FResMediosVenturi.MachGargantaSUM += fabs(dynamic_cast<TCCDeposito*>(FCCLateral)->getMachVenturi()) * Delta;
675  }
676  if(FResMediosVenturi.VelEntrada) {
677  if(dynamic_cast<TCCDeposito*>(FCCEntrada)->getSentidoFlujo() == nmEntrante) {
678  SentidoEntrada = 1;
679  } else if(dynamic_cast<TCCDeposito*>(FCCEntrada)->getSentidoFlujo() == nmSaliente) {
680  SentidoEntrada = -1;
681  }
682  FResMediosVenturi.VelEntradaSUM += SentidoEntrada * __cons::ARef * Delta * dynamic_cast<TCCDeposito*>
683  (FCCEntrada)->getVelocity();
684  }
685  if(FResMediosVenturi.VelLateral) {
686  if(dynamic_cast<TCCDeposito*>(FCCLateral)->getSentidoFlujo() == nmEntrante) {
687  SentidoLateral = 1;
688  } else if(dynamic_cast<TCCDeposito*>(FCCLateral)->getSentidoFlujo() == nmSaliente) {
689  SentidoLateral = -1;
690  }
691  FResMediosVenturi.VelLateralSUM += SentidoLateral * __cons::ARef * Delta * dynamic_cast<TCCDeposito*>
692  (FCCLateral)->getVelocity();
693 
694  }
695  if(FResMediosVenturi.GastoEntrada) {
696  FResMediosVenturi.GastoEntradaSUM += -Delta * dynamic_cast<TCCDeposito*>(FCCEntrada)->getMassflow();
697  }
698  if(FResMediosVenturi.GastoLateral) {
699  FResMediosVenturi.GastoLateralSUM += -Delta * dynamic_cast<TCCDeposito*>(FCCLateral)->getMassflow();
700  }
701 
702  FResMediosVenturi.TiempoSUM += Delta;
703  FResMediosVenturi.Tiempo0 = Actual;
704  } catch(exception & N) {
705  std::cout << "ERROR: TVenturi::AcumulaResultadosMediosVenturi en el venturi: " << FNumeroVenturi << std::endl;
706  std::cout << "Tipo de error: " << N.what() << std::endl;
707  throw Exception(N.what());
708  }
709 }
710 
711 // ---------------------------------------------------------------------------
712 // ---------------------------------------------------------------------------
713 
714 void TVenturi::ResultadosMediosVenturi() {
715  try {
716  if(FResMediosVenturi.PresionEntrada) {
717  FResMediosVenturi.PresionEntradaMED = FResMediosVenturi.PresionEntradaSUM / FResMediosVenturi.TiempoSUM;
718  FResMediosVenturi.PresionEntradaSUM = 0.;
719  }
720  if(FResMediosVenturi.PresionGarganta) {
721  FResMediosVenturi.PresionGargantaMED = FResMediosVenturi.PresionGargantaSUM / FResMediosVenturi.TiempoSUM;
722  FResMediosVenturi.PresionGargantaSUM = 0.;
723  }
724  if(FResMediosVenturi.MachEntrada) {
725  FResMediosVenturi.MachEntradaMED = FResMediosVenturi.MachEntradaSUM / FResMediosVenturi.TiempoSUM;
726  FResMediosVenturi.MachEntradaSUM = 0.;
727  }
728  if(FResMediosVenturi.MachGarganta) {
729  FResMediosVenturi.MachGargantaMED = FResMediosVenturi.MachGargantaSUM / FResMediosVenturi.TiempoSUM;
730  FResMediosVenturi.MachGargantaSUM = 0.;
731  }
732  if(FResMediosVenturi.VelEntrada) {
733  FResMediosVenturi.VelEntradaMED = FResMediosVenturi.VelEntradaSUM / FResMediosVenturi.TiempoSUM;
734  FResMediosVenturi.VelEntradaSUM = 0.;
735  }
736  if(FResMediosVenturi.VelLateral) {
737  FResMediosVenturi.VelLateralMED = FResMediosVenturi.VelLateralSUM / FResMediosVenturi.TiempoSUM;
738  FResMediosVenturi.VelLateralSUM = 0.;
739  }
740  if(FResMediosVenturi.GastoEntrada) {
741  FResMediosVenturi.GastoEntradaMED = FResMediosVenturi.GastoEntradaSUM / FResMediosVenturi.TiempoSUM;
742  FResMediosVenturi.GastoEntradaSUM = 0.;
743  }
744  if(FResMediosVenturi.GastoLateral) {
745  FResMediosVenturi.GastoLateralMED = FResMediosVenturi.GastoLateralSUM / FResMediosVenturi.TiempoSUM;
746  FResMediosVenturi.GastoLateralSUM = 0.;
747  }
748  FResMediosVenturi.TiempoSUM = 0;
749  } catch(exception & N) {
750  std::cout << "ERROR: TVenturi::ResultadosMediosVenturi en el venturi: " << FNumeroVenturi << std::endl;
751  std::cout << "Tipo de error: " << N.what() << std::endl;
752  throw Exception(N.what());
753  }
754 }
755 
756 // ---------------------------------------------------------------------------
757 // ---------------------------------------------------------------------------
758 
759 void TVenturi::ImprimeResultadosMediosVenturi(stringstream& medoutput) {
760  try {
761  // FILE *fich=fopen(FileSALIDA,"a");
762 
763  if(FResMediosVenturi.PresionEntrada)
764  medoutput << "\t" << FResMediosVenturi.PresionEntradaMED;
765  if(FResMediosVenturi.PresionGarganta)
766  medoutput << "\t" << FResMediosVenturi.PresionGargantaMED;
767  if(FResMediosVenturi.MachEntrada)
768  medoutput << "\t" << FResMediosVenturi.MachEntradaMED;
769  if(FResMediosVenturi.MachGarganta)
770  medoutput << "\t" << FResMediosVenturi.MachGargantaMED;
771  if(FResMediosVenturi.VelEntrada)
772  medoutput << "\t" << FResMediosVenturi.VelEntradaMED;
773  if(FResMediosVenturi.VelLateral)
774  medoutput << "\t" << FResMediosVenturi.VelLateralMED;
775  if(FResMediosVenturi.GastoEntrada)
776  medoutput << "\t" << FResMediosVenturi.GastoEntradaMED;
777  if(FResMediosVenturi.GastoLateral)
778  medoutput << "\t" << FResMediosVenturi.GastoLateralMED;
779 
780  // fclose(fich);
781  } catch(exception & N) {
782  std::cout << "ERROR: TVenturi::ImprimeResultadosMediosVenturi en el venturi: " << FNumeroVenturi << std::endl;
783  std::cout << "Tipo de error: " << N.what() << std::endl;
784  throw Exception(N.what());
785  }
786 }
787 
788 void TVenturi::UpdateProperties0DModel(double TimeCalculo) {
789  ActualizaPropiedades(TimeCalculo);
790 
791  CalculaVenturi();
792 
793  AcumulaResultadosMediosVenturi(TimeCalculo);
794 
795  AcumulaResultadosMedios(TimeCalculo);
796 
797 }
798 
799 // ---------------------------------------------------------------------------
800 // ---------------------------------------------------------------------------
801 
802 #pragma package(smart_init)
TDepVolCteBase
Definition: TDepVolCteBase.h:33
PutLabel
std::string PutLabel(int idx)
Returns an integer.
Definition: labels.cpp:475
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