OpenWAM
TCompresor.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 #include <iostream>
31 #ifdef __BORLANDC__
32 #include <vcl.h>
33 #endif
34 //#include <cmath>
35 
36 #include "TCompresor.h"
37 
38 //---------------------------------------------------------------------------
39 //---------------------------------------------------------------------------
40 
41 TCompresor::TCompresor(int i, nmTipoCalculoEspecies SpeciesModel, int numeroespecies, nmCalculoGamma GammaCalculation,
42  bool ThereIsEGR) {
43  FNumeroCompresor = i + 1;
44  FMedias.GraficaMedias = false;
45  FMedias.GraficaTrabajo = false;
46  FMedias.GraficaRendimiento = false;
47  FMedias.GraficaRelacionCompresion = false;
48  FMedias.GraficaGasto = false;
49  FMedias.GraficaGastoCorregido = false;
50  FMedias.GraficaRegimenCorregido = false;
51  FInstant.GraficaInstantaneas = false;
52  FInstant.GraficaPotencia = false;
53  FInstant.GraficaRendimiento = false;
54  FInstant.GraficaRelacionCompresion = false;
55  FInstant.GraficaGasto = false;
56  FInstant.GraficaGastoCorregido = false;
57  FInstant.GraficaRegimenCorregido = false;
58  FInstant.GraficaGamma = false;
59  FTiempo0 = 0.;
60  Mapa = NULL;
61  Mapa2T = NULL;
62  FBombeo = true;
63  FTrabajoPaso = 0.;
64  FDeltaTPaso = 0.;
65 
66  FCalculoEspecies = SpeciesModel;
67  FNumeroEspecies = numeroespecies;
68  FCalculoGamma = GammaCalculation;
69  FFraccionMasicaEspecie = NULL;
70 
71  FHayEGR = ThereIsEGR;
72  if(FHayEGR)
73  FIntEGR = 0;
74  else
75  FIntEGR = 1;
76 
77  FIsAcoustic = false;
78 }
79 
80 //---------------------------------------------------------------------------
81 //---------------------------------------------------------------------------
82 
83 TCompresor::~TCompresor() {
84  if(Mapa != NULL)
85  delete Mapa;
86  if(Mapa2T != NULL)
87  delete Mapa2T;
88  if(FFraccionMasicaEspecie != NULL)
89  delete[] FFraccionMasicaEspecie;
90 }
91 
92 //---------------------------------------------------------------------------
93 //---------------------------------------------------------------------------
94 
95 void TCompresor::InterpolaValoresMapa(double rtc) {
96  try {
97  FRegimen = rtc;
98 
99  if(FModeloCompresor == nmCompPipes) {
100  Mapa2T->InterpolaMapa(FRegimen, FTemperatura10);
101  } else {
102  Mapa->InterpolaMapa(FRegimen, FTemperatura10);
103  }
104 
105  } catch(exception &N) {
106  std::cout << "ERROR: InterpolaValoresMapa en el compresor: " << FNumeroCompresor << std::endl;
107  std::cout << "Tipo de error: " << N.what() << std::endl;
108  throw Exception("ERROR: InterpolaValoresMapa en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
109  }
110 }
111 
112 //---------------------------------------------------------------------------
113 //---------------------------------------------------------------------------
114 
115 void TCompresor::AcumulaMedias(double Tiempo) {
116  double DeltaT = 0.;
117  try {
118  DeltaT = Tiempo - FMedias.Tiempo0;
119  FMedias.TiempoSUM += DeltaT;
120  FMedias.RelacionCompresionSUM += FRelacionCompresion * DeltaT;
121  FMedias.GastoSUM += FGastoCompresor * DeltaT;
122  FMedias.RendimientoSUM += FRendimiento * DeltaT;
123  FMedias.GastoCorregidoSUM += FGastoCorregido * DeltaT;
124  FMedias.RegimenCorregidoSUM += FRegimenCorregido * DeltaT;
125  FMedias.TrabajoSUM += FPotencia * DeltaT;
126  FMedias.Tiempo0 = Tiempo;
127  } catch(exception &N) {
128  std::cout << "ERROR: AcumulaMedias en el compresor: " << FNumeroCompresor << std::endl;
129  std::cout << "Tipo de error: " << N.what() << std::endl;
130  throw Exception("ERROR: AcumulaMedias en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
131  }
132 }
133 
134 //---------------------------------------------------------------------------
135 //---------------------------------------------------------------------------
136 
137 void TCompresor::IniciaMedias() {
138 
139  try {
140  FMedias.TiempoSUM = 0.;
141  FMedias.RelacionCompresionSUM = 0.;
142  FMedias.GastoSUM = 0.;
143  FMedias.RendimientoSUM = 0.;
144  FMedias.GastoCorregidoSUM = 0.;
145  FMedias.RegimenCorregidoSUM = 0.;
146  FMedias.TrabajoSUM = 0.;
147  FMedias.Tiempo0 = 0.;
148 
149  } catch(exception &N) {
150  std::cout << "ERROR: IniciaMedias en el compresor: " << FNumeroCompresor << std::endl;
151  std::cout << "Tipo de error: " << N.what() << std::endl;
152  throw Exception("ERROR: IniciaMedias en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
153  }
154 }
155 
156 //---------------------------------------------------------------------------
157 //---------------------------------------------------------------------------
158 
159 void TCompresor::CalculoPotenciaPaso() {
160  try {
161 
162  FPotenciaPaso = FTrabajoPaso / FDeltaTPaso;
163  FTrabajoPaso = 0.;
164  FDeltaTPaso = 0.;
165 
166  } catch(exception &N) {
167  std::cout << "ERROR: TCompresor::CalculoPotenciaPaso en el compresor: " << FNumeroCompresor << std::endl;
168  std::cout << "Tipo de error: " << N.what() << std::endl;
169  throw Exception("ERROR: TCompresor::CalculoPotenciaPaso en el compresor: " + std::to_string(
170  FNumeroCompresor) + N.what());
171  }
172 }
173 //---------------------------------------------------------------------------
174 //---------------------------------------------------------------------------
175 
176 void TCompresor::CalculaMedias() {
177 
178  try {
179  FMedias.RelacionCompresion = FMedias.RelacionCompresionSUM / FMedias.TiempoSUM;
180  FMedias.Massflow = FMedias.GastoSUM / FMedias.TiempoSUM;
181  FMedias.Rendimiento = FMedias.RendimientoSUM / FMedias.TiempoSUM;
182  FMedias.Trabajo = FMedias.TrabajoSUM;
183  FMedias.GastoCorregido = FMedias.GastoCorregidoSUM / FMedias.TiempoSUM;
184  FMedias.RegimenCorregido = FMedias.RegimenCorregidoSUM / FMedias.TiempoSUM;
185 
186  FMedias.TiempoSUM = 0.;
187  FMedias.RelacionCompresionSUM = 0.;
188  FMedias.GastoSUM = 0.;
189  FMedias.RendimientoSUM = 0.;
190  FMedias.TrabajoSUM = 0.;
191  FMedias.GastoCorregidoSUM = 0.;
192  FMedias.RegimenCorregidoSUM = 0.;
193 
194  } catch(exception &N) {
195  std::cout << "ERROR: CalculaMedias en el compresor: " << FNumeroCompresor << std::endl;
196  std::cout << "Tipo de error: " << N.what() << std::endl;
197  throw Exception("ERROR: CalculaMedias en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
198  }
199 }
200 
201 //---------------------------------------------------------------------------
202 //---------------------------------------------------------------------------
203 
204 void TCompresor::CalculaInstantaneos() {
205  try {
206  FInstant.RelacionCompresion = FRelacionCompresion;
207  FInstant.Massflow = FGastoCompresor;
208  FInstant.Rendimiento = FRendimiento;
209  FInstant.Potencia = FPotencia;
210  FInstant.GastoCorregido = FGastoCorregido;
211  FInstant.RegimenCorregido = FRegimenCorregido;
212  FInstant.Gamma = FGamma;
213  } catch(exception &N) {
214  std::cout << "ERROR: CalculaInstantaneos en el compresor: " << FNumeroCompresor << std::endl;
215  std::cout << "Tipo de error: " << N.what() << std::endl;
216  throw Exception("ERROR: CalculaInstantaneos en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
217  }
218 }
219 
220 //---------------------------------------------------------------------------
221 //---------------------------------------------------------------------------
222 
223 void TCompresor::LeeDatosGraficasMedias(const char *FileWAM, fpos_t &filepos) {
224  int NMagnitudes = 0, Magnitud = 0;
225  try {
226  FILE *fich = fopen(FileWAM, "r");
227  fsetpos(fich, &filepos);
228 
229  FMedias.GraficaMedias = true;
230  fscanf(fich, "%d", &NMagnitudes);
231  for(int i = 0; i < NMagnitudes; i++) {
232  fscanf(fich, "%d", &Magnitud);
233  switch(Magnitud) {
234  case 0:
235  FMedias.GraficaTrabajo = true;
236  break;
237  case 1:
238  FMedias.GraficaRendimiento = true;
239  break;
240  case 2:
241  FMedias.GraficaRelacionCompresion = true;
242  break;
243  case 3:
244  FMedias.GraficaGasto = true;
245  break;
246  case 4:
247  FMedias.GraficaGastoCorregido = true;
248  break;
249  case 5:
250  FMedias.GraficaRegimenCorregido = true;
251  break;
252  }
253  }
254  fgetpos(fich, &filepos);
255  fclose(fich);
256  } catch(exception &N) {
257  std::cout << "ERROR: LeeDatosGraficasMedias en el compresor: " << FNumeroCompresor << std::endl;
258  std::cout << "Tipo de error: " << N.what() << std::endl;
259  throw Exception("ERROR: LeeDatosGraficasMedias en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
260  }
261 }
262 
263 //---------------------------------------------------------------------------
264 //---------------------------------------------------------------------------
265 
266 void TCompresor::CabeceraGraficasMedias(stringstream& medoutput) {
267  try {
268 //FILE *fich=fopen(FileSALIDA,"a");
269  std::string Label;
270  if(FMedias.GraficaMedias) {
271  if(FMedias.GraficaTrabajo) {
272  Label = "\t" + PutLabel(28) + std::to_string(FNumeroCompresor) + PutLabel(907);
273  medoutput << Label.c_str();
274  }
275  if(FMedias.GraficaRendimiento) {
276  Label = "\t" + PutLabel(22) + std::to_string(FNumeroCompresor) + PutLabel(901);
277  medoutput << Label.c_str();
278  }
279  if(FMedias.GraficaRelacionCompresion) {
280  Label = "\t" + PutLabel(23) + std::to_string(FNumeroCompresor) + PutLabel(901);
281  medoutput << Label.c_str();
282  }
283  if(FMedias.GraficaGasto) {
284  Label = "\t" + PutLabel(24) + std::to_string(FNumeroCompresor) + PutLabel(904);
285  medoutput << Label.c_str();
286  }
287  if(FMedias.GraficaGastoCorregido) {
288  Label = "\t" + PutLabel(25) + std::to_string(FNumeroCompresor) + PutLabel(905);
289  medoutput << Label.c_str();
290  }
291  if(FMedias.GraficaRegimenCorregido) {
292  Label = "\t" + PutLabel(26) + std::to_string(FNumeroCompresor) + PutLabel(906);
293  medoutput << Label.c_str();
294  }
295  }
296 //fclose(fich);
297  } catch(exception &N) {
298  std::cout << "ERROR: CabeceraGraficasMedias en el compresor: " << FNumeroCompresor << std::endl;
299  std::cout << "Tipo de error: " << N.what() << std::endl;
300  throw Exception("ERROR: CabeceraGraficasMedias en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
301  }
302 }
303 
304 //---------------------------------------------------------------------------
305 //---------------------------------------------------------------------------
306 
307 void TCompresor::ImprimeGraficasMedias(stringstream& medoutput) {
308  try {
309 //FILE *fich=fopen(FileSALIDA,"a");
310  if(FMedias.GraficaMedias) {
311  if(FMedias.GraficaTrabajo)
312  medoutput << "\t" << FMedias.Trabajo;
313  if(FMedias.GraficaRendimiento)
314  medoutput << "\t" << FMedias.Rendimiento;
315  if(FMedias.GraficaRelacionCompresion)
316  medoutput << "\t" << FMedias.RelacionCompresion;
317  if(FMedias.GraficaGasto)
318  medoutput << "\t" << FMedias.Massflow;
319  if(FMedias.GraficaGastoCorregido)
320  medoutput << "\t" << FMedias.GastoCorregido;
321  if(FMedias.GraficaRegimenCorregido)
322  medoutput << "\t" << FMedias.RegimenCorregido;
323  }
324 //fclose(fich);
325  } catch(exception &N) {
326  std::cout << "ERROR: ImprimeGraficasMedias en el compresor: " << FNumeroCompresor << std::endl;
327  std::cout << "Tipo de error: " << N.what() << std::endl;
328  throw Exception("ERROR: ImprimeGraficasMedias en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
329  }
330 }
331 
332 //---------------------------------------------------------------------------
333 //---------------------------------------------------------------------------
334 
335 void TCompresor::LeeDatosGraficasInstantaneas(const char *FileWAM, fpos_t &filepos) {
336  int NMagnitudes = 0, Magnitud = 0;
337  try {
338  FILE *fich = fopen(FileWAM, "r");
339  fsetpos(fich, &filepos);
340 
341  FInstant.GraficaInstantaneas = true;
342  fscanf(fich, "%d", &NMagnitudes);
343  for(int i = 0; i < NMagnitudes; i++) {
344  fscanf(fich, "%d", &Magnitud);
345  switch(Magnitud) {
346  case 0:
347  FInstant.GraficaRelacionCompresion = true;
348  break;
349  case 1:
350  FInstant.GraficaRendimiento = true;
351  break;
352  case 2:
353  FInstant.GraficaPotencia = true;
354  break;
355  case 3:
356  FInstant.GraficaGasto = true;
357  break;
358  case 4:
359  FInstant.GraficaGastoCorregido = true;
360  break;
361  case 5:
362  FInstant.GraficaRegimenCorregido = true;
363  break;
364  case 6:
365  FInstant.GraficaGamma = true;
366  break;
367  }
368  }
369  fgetpos(fich, &filepos);
370  fclose(fich);
371  } catch(exception &N) {
372  std::cout << "ERROR: LeeDatosGraficasMedias en el compresor: " << FNumeroCompresor << std::endl;
373  std::cout << "Tipo de error: " << N.what() << std::endl;
374  throw Exception("ERROR: LeeDatosGraficasMedias en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
375  }
376 }
377 
378 //---------------------------------------------------------------------------
379 //---------------------------------------------------------------------------
380 
381 void TCompresor::CabeceraGraficasInstantaneas(stringstream& insoutput) {
382  try {
383 //FILE *fich=fopen(FileSALIDA,"a");
384  std::string Label;
385 
386  if(FInstant.GraficaInstantaneas) {
387  if(FInstant.GraficaPotencia) {
388  Label = "\t" + PutLabel(21) + std::to_string(FNumeroCompresor) + PutLabel(903);
389  insoutput << Label.c_str();
390  }
391  if(FInstant.GraficaRendimiento) {
392  Label = "\t" + PutLabel(22) + std::to_string(FNumeroCompresor) + PutLabel(901);
393  insoutput << Label.c_str();
394  }
395  if(FInstant.GraficaRelacionCompresion) {
396  Label = "\t" + PutLabel(23) + std::to_string(FNumeroCompresor) + PutLabel(901);
397  insoutput << Label.c_str();
398  }
399  if(FInstant.GraficaGasto) {
400  Label = "\t" + PutLabel(24) + std::to_string(FNumeroCompresor) + PutLabel(904);
401  insoutput << Label.c_str();
402  }
403  if(FInstant.GraficaGastoCorregido) {
404  Label = "\t" + PutLabel(25) + std::to_string(FNumeroCompresor) + PutLabel(905);
405  insoutput << Label.c_str();
406  }
407  if(FInstant.GraficaRegimenCorregido) {
408  Label = "\t" + PutLabel(26) + std::to_string(FNumeroCompresor) + PutLabel(906);
409  insoutput << Label.c_str();
410  }
411  if(FInstant.GraficaGamma) {
412  Label = "\t" + PutLabel(27) + std::to_string(FNumeroCompresor) + PutLabel(901);
413  insoutput << Label.c_str();
414  }
415  }
416 //fclose(fich);
417  } catch(exception &N) {
418  std::cout << "ERROR: CabeceraGraficasInstantaneas en el compresor: " << FNumeroCompresor << std::endl;
419  std::cout << "Tipo de error: " << N.what() << std::endl;
420  throw Exception("ERROR: CabeceraGraficasInstantaneas en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
421  }
422 }
423 
424 //---------------------------------------------------------------------------
425 //---------------------------------------------------------------------------
426 
427 void TCompresor::ImprimeGraficasInstantaneas(stringstream& insoutput) {
428  try {
429 //FILE *fich=fopen(FileSALIDA,"a");
430  if(FInstant.GraficaInstantaneas) {
431  if(FInstant.GraficaPotencia)
432  insoutput << "\t" << FInstant.Potencia;
433  if(FInstant.GraficaRendimiento)
434  insoutput << "\t" << FInstant.Rendimiento;
435  if(FInstant.GraficaRelacionCompresion)
436  insoutput << "\t" << FInstant.RelacionCompresion;
437  if(FInstant.GraficaGasto)
438  insoutput << "\t" << FInstant.Massflow;
439  if(FInstant.GraficaGastoCorregido)
440  insoutput << "\t" << FInstant.GastoCorregido;
441  if(FInstant.GraficaRegimenCorregido)
442  insoutput << "\t" << FInstant.RegimenCorregido;
443  if(FInstant.GraficaGamma)
444  insoutput << "\t" << FInstant.Gamma;
445  }
446 //fclose(fich);
447  } catch(exception &N) {
448  std::cout << "ERROR: ImprimeGraficasInstantaneas en el compresor: " << FNumeroCompresor << std::endl;
449  std::cout << "Tipo de error: " << N.what() << std::endl;
450  throw Exception("ERROR: ImprimeGraficasInstantaneas en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
451  }
452 }
453 
454 //---------------------------------------------------------------------------
455 //---------------------------------------------------------------------------
456 
457 double TCompresor::GetASonidoComp() {
458  try {
459  if(FModeloCompresor == nmCompPipes) {
460  printf("ERROR:El compresor de tubos no puede estar unido a un deposito\n");
461  return 0;
462  } else
463  return FASonidoSalida;
464  } catch(exception &N) {
465  std::cout << "ERROR: TCompresor::GetASonidoComp en el compresor: " << FNumeroCompresor << std::endl;
466  std::cout << "Tipo de error: " << N.what() << std::endl;
467  throw Exception("ERROR: ImprimeGraficasInstantaneas en el compresor: " + std::to_string(FNumeroCompresor) + N.what());
468  }
469 }
470 
471 //---------------------------------------------------------------------------
472 //---------------------------------------------------------------------------
473 
474 double TCompresor::GetFraccionMasicaEspecie(int i) {
475  try {
476  return FFraccionMasicaEspecie[i];
477  } catch(exception &N) {
478  std::cout << "ERROR: TCompresor::GetFraccionMasicaEspecie en el compresor: " << FNumeroCompresor << std::endl;
479  std::cout << "Tipo de error: " << N.what() << std::endl;
480  throw Exception(N.what());
481  }
482 }
483 
484 //---------------------------------------------------------------------------
485 //---------------------------------------------------------------------------
486 
487 void TCompresor::AsignAcousticElements(TTubo **Pipe, TDeposito **Volume) {
488  if(FIsAcoustic) {
489  FAcComp->AsignInPipe(Pipe);
490  FAcComp->AsignOutPipe(Pipe);
491  FAcComp->AsignVolute(Pipe);
492  FAcComp->AsignRotorVol(Volume);
493  FAcComp->AsignStatorVol(Volume);
494  }
495 }
496 
497 #pragma package(smart_init)
498 
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
TDeposito
Definition: TDeposito.h:44
PutLabel
std::string PutLabel(int idx)
Returns an integer.
Definition: labels.cpp:475
Exception
Custom exception class.
Definition: Exception.hpp:39