OpenWAM
TCCCompresor.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 <cmath>
32 #ifdef __BORLANDC__
33 #include <vcl.h>
34 #endif
35 
36 #include "TCCCompresor.h"
37 #include "TCompTubDep.h"
38 #include "TCompTubos.h"
39 #include "TCompresorDep.h"
40 #include "TCCEntradaCompresor.h"
41 
42 #include "TTubo.h"
43 #include "TDeposito.h"
44 #include "TCompresor.h"
45 
46 // ---------------------------------------------------------------------------
47 // ---------------------------------------------------------------------------
48 TCCCompresor::TCCCompresor(nmTypeBC TipoCC, int numCC, nmTipoCalculoEspecies SpeciesModel, int numeroespecies,
49  nmCalculoGamma GammaCalculation, bool ThereIsEGR) :
50  TCondicionContorno(TipoCC, numCC, SpeciesModel, numeroespecies, GammaCalculation, ThereIsEGR) {
51 
52  FTuboExtremo = NULL;
53  FTiempoActual = 0;
54  FNumeroTubo = NULL;
55 
56 }
57 // ---------------------------------------------------------------------------
58 // ---------------------------------------------------------------------------
59 
60 TCCCompresor::~TCCCompresor() {
61 
62  if(FNumeroTubo != NULL)
63  delete[] FNumeroTubo;
64  if(FTuboExtremo != NULL)
65  delete[] FTuboExtremo;
66 
67 }
68 
69 // ---------------------------------------------------------------------------
70 // ---------------------------------------------------------------------------
71 
72 void TCCCompresor::LeeNumeroCompresor(const char *FileWAM, fpos_t &filepos) {
73  try {
74 
75  FILE *fich = fopen(FileWAM, "r");
76  fsetpos(fich, &filepos);
77 
78  fscanf(fich, "%d ", &FNumeroCompresor);
79 
80  fgetpos(fich, &filepos);
81  fclose(fich);
82 
83  } catch(exception & N) {
84  std::cout << "ERROR: TCCCompresor::LeeCompresor en la condicion de contorno: " << FNumeroCC << std::endl;
85  std::cout << "Tipo de error: " << N.what() << std::endl;
86  throw Exception(N.what());
87  }
88 }
89 
90 // ---------------------------------------------------------------------------
91 // ---------------------------------------------------------------------------
92 
93 void TCCCompresor::AsignacionDatos(TCompresor **Compressor, TDeposito **Plenum, const char *FileWAM, fpos_t &filepos,
94  int NumberOfPipes, TTubo **Pipe, TCondicionContorno **BC, int numCC, double AmbientTemperature, double AmbientPressure,
95  double *AtmosphericComposition) {
96  try {
97  int i = 0;
98  bool haytubo = false;
99  int tipoentrada = 0;
100 
101  FTamb = AmbientTemperature;
102  FPamb = AmbientPressure;
103  FCompresor = Compressor[FNumeroCompresor - 1];
104  FFraccionMasicaEspecie = new double[FNumeroEspecies - FIntEGR];
105 
106  if(FCompresor->getModeloCompresor() == nmCompOriginal) {
107  // Posee un tubo y un deposito. Hay que asignarselos a la BC.
108 
109  FTuboExtremo = new stTuboExtremo[1];
110  FTuboExtremo[0].Pipe = NULL;
111 
112  while(FNumeroTubosCC < 1 && i < NumberOfPipes) {
113  if(Pipe[i]->getNodoIzq() == FNumeroCC) {
114  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
115  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmLeft;
116  FNumeroTubosCC++;
117  }
118  if(Pipe[i]->getNodoDer() == FNumeroCC) {
119  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
120  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmRight;
121  FNumeroTubosCC++;
122  }
123  i++;
124  }
125  FILE *fich = fopen(FileWAM, "r");
126  fsetpos(fich, &filepos);
127 
128  fscanf(fich, "%d ", &tipoentrada);
129 
130  fgetpos(fich, &filepos);
131  fclose(fich);
132 
133  switch(tipoentrada) {
134  case 0:
135  FEntradaCompresor = nmAtmosphere;
136  break;
137  case 1:
138  FEntradaCompresor = nmPipe;
139  break;
140  case 2:
141  FEntradaCompresor = nmPlenum;
142  break;
143  }
144 
145  if(FEntradaCompresor == nmPlenum) {
146 
147  FILE *fich = fopen(FileWAM, "r");
148  fsetpos(fich, &filepos);
149 
150  fscanf(fich, "%d ", &FNumeroDeposito);
151 
152  fgetpos(fich, &filepos);
153  fclose(fich);
154 
155  FDeposito = Plenum[FNumeroDeposito - 1];
156  dynamic_cast<TCompTubDep*>(FCompresor)->BusquedaEntradaSalida(FEntradaCompresor, FTamb, FNumeroCC, BC,
157  AtmosphericComposition);
158 
159  } else if(FEntradaCompresor == nmPipe) {
160  for(int i = 0; i < numCC; i++) {
161  if(BC[i]->getTipoCC() == nmEntradaCompre) {
162  if(dynamic_cast<TCCEntradaCompresor*>(BC[i])->getNumeroCompresor() == FNumeroCompresor) {
163  haytubo = true;
164  FTuboRotor = BC[i]->GetTuboExtremo(0).Pipe;
165  FExtremoTuboRotor = BC[i]->GetTuboExtremo(0).TipoExtremo;
166  }
167  }
168  }
169  if(haytubo) {
170  dynamic_cast<TCompTubDep*>(FCompresor)->BusquedaEntradaSalida(FEntradaCompresor, AmbientTemperature, FNumeroCC, BC,
171  AtmosphericComposition);
172  } else {
173  printf("ERROR: El compresor %d no tiene una BC tipo EntradaCompresor a su entrada.\n ", FNumeroCompresor);
174  }
175  } else if(FEntradaCompresor == nmAtmosphere) {
176  dynamic_cast<TCompTubDep*>(FCompresor)->BusquedaEntradaSalida(FEntradaCompresor, AmbientTemperature, FNumeroCC, BC,
177  AtmosphericComposition);
178  }
179 
180  } else if(FCompresor->getModeloCompresor() == nmCompPipes) {
181  // Posee dos tubos. Hay que asignarselos a la BC.
182 
183  FTuboExtremo = new stTuboExtremo[2];
184  FNumeroTubo = new int[2];
185  for(int j = 0; j < 2; j++) {
186  FTuboExtremo[j].Pipe = NULL;
187  }
188 
189  while(FNumeroTubosCC < 2 && i < NumberOfPipes) {
190  if(Pipe[i]->getNodoIzq() == FNumeroCC) {
191  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
192  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmLeft;
193  FNumeroTubo[FNumeroTubosCC] = i;
194  FNumeroTubosCC++;
195  }
196  if(Pipe[i]->getNodoDer() == FNumeroCC) {
197  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
198  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmRight;
199  FNumeroTubo[FNumeroTubosCC] = i;
200  FNumeroTubosCC++;
201  }
202  i++;
203  }
204  dynamic_cast<TCompTubos*>(FCompresor)->RelacionTubos(BC, FNumeroCC);
205 
206  } else if(FCompresor->getModeloCompresor() == nmCompPlenums) {
207  // Posee dos depositos. Hay que asignarselos a la BC.
208 
209  FILE *fich = fopen(FileWAM, "r");
210  fsetpos(fich, &filepos);
211 
212  fscanf(fich, "%d ", &FNumeroDepositoRot);
213  fscanf(fich, "%d ", &FNumeroDepositoEst);
214 
215  fgetpos(fich, &filepos);
216  fclose(fich);
217 
218  FDepositoRot = Plenum[FNumeroDepositoRot - 1];
219  FDepositoEst = Plenum[FNumeroDepositoEst - 1];
220 
221  dynamic_cast<TCompresorDep*>(FCompresor)->RelacionDepositoCompresor(FDepositoRot, FDepositoEst);
222 
223  }
224 
225  } catch(exception & N) {
226  std::cout << "ERROR: TCCCompresor::AsignaCompresor en la condicion de contorno: " << FNumeroCC << std::endl;
227  std::cout << "Tipo de error: " << N.what() << std::endl;
228  throw Exception(N.what());
229  }
230 }
231 
232 // ---------------------------------------------------------------------------
233 // ---------------------------------------------------------------------------
234 
235 void TCCCompresor::ObtencionValoresInstantaneos(double Theta, double tiempoactual) {
236  try {
237 
238  FTheta = Theta;
239  FTiempoActual = tiempoactual;
240 
241  } catch(exception & N) {
242  std::cout << "ERROR: TCCCompresor::ObtencionValoresInstantaneos en la condicion de contorno: " << FNumeroCC <<
243  std::endl;
244  std::cout << "Tipo de error: " << N.what() << std::endl;
245  throw Exception(N.what());
246  }
247 }
248 
249 // ---------------------------------------------------------------------------
250 // ---------------------------------------------------------------------------
251 
252 void TCCCompresor::CalculaCondicionContorno(double Time) {
253  try {
254  double TrabajoInsTurbina = 0.; /* para que compile.inacabado. */
255  int TuboCalculado = 0;
256 
257  if(FCompresor->getModeloCompresor() == nmCompOriginal) {
258  TuboCalculado = 0; // Es la posicion del tubo a calcular en el vector estructura FTuboExtremo.
259  // Para este modelo de compresor no hace falta,pero si en el de 2 tubos. Como comparten
260  // funcion virtual, la llamada de la misma ha de ser igual. Por eso lo anado.
261  dynamic_cast<TCompTubDep*>(FCompresor)->DatosEntradaCompresor(FTamb, FPamb, this);
262  FCompresor->CondicionCompresor(FTheta, FTuboExtremo, FTiempoActual, TuboCalculado);
263  FCompresor->AcumulaMedias(FTiempoActual);
264  }
265  if(FCompresor->getModeloCompresor() == nmCompPlenums) {
266  FCompresor->CalculaGasto(TrabajoInsTurbina, FTiempoActual); /* Falta Acabar!!!!! */
267  FCompresor->AcumulaMedias(FTiempoActual);
268  }
269  if(FCompresor->getModeloCompresor() == nmCompPipes) {
270  // Identificacion del tubo que se esta calculando en el instante current. Solo han de variar sus propiedades.
271  if(FTuboActual == 10000) {
272  TuboCalculado = FTuboActual;
273  } else {
274  for(int i = 0; i < FNumeroTubosCC; i++) {
275  if(FNumeroTubo[i] == FTuboActual) {
276  TuboCalculado = i; // Es la posicion del tubo calculado en el vector estructura FTuboExtremo.
277  }
278  }
279  }
280  FCompresor->CondicionCompresor(FTheta, FTuboExtremo, FTiempoActual, TuboCalculado);
281  FCompresor->AcumulaMedias(FTiempoActual);
282  }
283 
284  // Transporte de especies quimicas. (Paso de informacion del objeto Compressor al objeto BC Compressor
285  for(int i = 0; i < FNumeroEspecies - FIntEGR; i++) {
286  FFraccionMasicaEspecie[i] = FCompresor->GetFraccionMasicaEspecie(i);
287  }
288 
289  } catch(exception & N) {
290  std::cout << "ERROR: TCCCompresor::CalculaCondicionesContorno en la condicion de contorno: " << FNumeroCC << std::endl;
291  std::cout << "Tipo de error: " << N.what() << std::endl;
292  throw Exception(N.what());
293  }
294 }
295 
296 // ---------------------------------------------------------------------------
297 // ---------------------------------------------------------------------------
298 
299 void TCCCompresor::TuboCalculandose(int TuboActual) {
300  try {
301  FTuboActual = TuboActual;
302  } catch(exception & N) {
303  std::cout << "ERROR: TCCUnionEntreTubos::TuboCalculandose en la condicion de contorno: " << FNumeroCC << std::endl;
304  std::cout << "Tipo de error: " << N.what() << std::endl;
305  throw Exception(N.what());
306  }
307 }
308 
309 void TCCCompresor::ReadCompressorData(const char *FileWAM, fpos_t &filepos, TCompresor **Compressor) {
310 
311  int tipoentrada = 0;
312 
313  if(Compressor[FNumeroCompresor - 1]->getModeloCompresor() == nmCompOriginal) {
314  FILE *fich = fopen(FileWAM, "r");
315  fsetpos(fich, &filepos);
316 
317  fscanf(fich, "%d ", &tipoentrada);
318 
319  switch(tipoentrada) {
320  case 0:
321  FEntradaCompresor = nmAtmosphere;
322  break;
323  case 1:
324  FEntradaCompresor = nmPipe;
325  break;
326  case 2:
327  FEntradaCompresor = nmPlenum;
328  fscanf(fich, "%d ", &FNumeroDeposito);
329  break;
330  }
331  fgetpos(fich, &filepos);
332  fclose(fich);
333  } else if(Compressor[FNumeroCompresor - 1]->getModeloCompresor() == nmCompPlenums) {
334  // Posee dos depositos. Hay que asignarselos a la BC.
335 
336  FILE *fich = fopen(FileWAM, "r");
337  fsetpos(fich, &filepos);
338 
339  fscanf(fich, "%d ", &FNumeroDepositoRot);
340  fscanf(fich, "%d ", &FNumeroDepositoEst);
341 
342  fgetpos(fich, &filepos);
343  fclose(fich);
344  }
345 }
346 
347 void TCCCompresor::AsignData(TDeposito **Plenum, int NumberOfPipes, TTubo **Pipe, TCondicionContorno **BC, int numCC,
348  double *AtmosphericComposition, TCompresor **Compressor, double AmbientTemperature, double AmbientPressure) {
349  try {
350  int i = 0;
351  bool haytubo = false;
352 
353  FTamb = AmbientTemperature;
354  FPamb = AmbientPressure;
355  FCompresor = Compressor[FNumeroCompresor - 1];
356  FFraccionMasicaEspecie = new double[FNumeroEspecies - FIntEGR];
357 
358  if(FCompresor->getModeloCompresor() == nmCompOriginal) {
359  // Posee un tubo y un deposito. Hay que asignarselos a la BC.
360 
361  FTuboExtremo = new stTuboExtremo[1];
362  FTuboExtremo[0].Pipe = NULL;
363 
364  while(FNumeroTubosCC < 1 && i < NumberOfPipes) {
365  if(Pipe[i]->getNodoIzq() == FNumeroCC) {
366  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
367  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmLeft;
368  FNumeroTubosCC++;
369  }
370  if(Pipe[i]->getNodoDer() == FNumeroCC) {
371  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
372  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmRight;
373  FNumeroTubosCC++;
374  }
375  i++;
376  }
377 
378  if(FEntradaCompresor == nmPlenum) {
379 
380  FDeposito = Plenum[FNumeroDeposito - 1];
381  dynamic_cast<TCompTubDep*>(FCompresor)->BusquedaEntradaSalida(FEntradaCompresor, FTamb, FNumeroCC, BC,
382  AtmosphericComposition);
383 
384  } else if(FEntradaCompresor == nmPipe) {
385  for(int i = 0; i < numCC; i++) {
386  if(BC[i]->getTipoCC() == nmEntradaCompre) {
387  if(dynamic_cast<TCCEntradaCompresor*>(BC[i])->getNumeroCompresor() == FNumeroCompresor) {
388  haytubo = true;
389  FTuboRotor = BC[i]->GetTuboExtremo(0).Pipe;
390  FExtremoTuboRotor = BC[i]->GetTuboExtremo(0).TipoExtremo;
391  }
392  }
393  }
394  if(haytubo) {
395  dynamic_cast<TCompTubDep*>(FCompresor)->BusquedaEntradaSalida(FEntradaCompresor, FTamb, FNumeroCC, BC,
396  AtmosphericComposition);
397  } else {
398  printf("ERROR: El compresor %d no tiene una BC tipo EntradaCompresor a su entrada.\n ", FNumeroCompresor);
399  }
400  } else if(FEntradaCompresor == nmAtmosphere) {
401  dynamic_cast<TCompTubDep*>(FCompresor)->BusquedaEntradaSalida(FEntradaCompresor, FTamb, FNumeroCC, BC,
402  AtmosphericComposition);
403  }
404 
405  } else if(FCompresor->getModeloCompresor() == nmCompPipes) {
406  // Posee dos tubos. Hay que asignarselos a la BC.
407 
408  FTuboExtremo = new stTuboExtremo[2];
409  FNumeroTubo = new int[2];
410  for(int j = 0; j < 2; j++) {
411  FTuboExtremo[j].Pipe = NULL;
412  }
413 
414  while(FNumeroTubosCC < 2 && i < NumberOfPipes) {
415  if(Pipe[i]->getNodoIzq() == FNumeroCC) {
416  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
417  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmLeft;
418  FNumeroTubo[FNumeroTubosCC] = i;
419  FNumeroTubosCC++;
420  }
421  if(Pipe[i]->getNodoDer() == FNumeroCC) {
422  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
423  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmRight;
424  FNumeroTubo[FNumeroTubosCC] = i;
425  FNumeroTubosCC++;
426  }
427  i++;
428  }
429  // dynamic_cast<TCompTubos*>(FCompresor)->RelacionTubos(BC, FNumeroCC);
430  dynamic_cast<TCompTubos*>(FCompresor)->AsignPipes(BC, FNumeroCC);
431 
432  } else if(FCompresor->getModeloCompresor() == nmCompPlenums) {
433 
434  FDepositoRot = Plenum[FNumeroDepositoRot - 1];
435  FDepositoEst = Plenum[FNumeroDepositoEst - 1];
436 
437  dynamic_cast<TCompresorDep*>(FCompresor)->RelacionDepositoCompresor(FDepositoRot, FDepositoEst);
438 
439  }
440 
441  } catch(exception & N) {
442  std::cout << "ERROR: TCCCompresor::AsignaCompresor en la condicion de contorno: " << FNumeroCC << std::endl;
443  std::cout << "Tipo de error: " << N.what() << std::endl;
444  throw Exception(N.what());
445  }
446 }
447 
448 // ---------------------------------------------------------------------------
449 // ---------------------------------------------------------------------------
450 #pragma package(smart_init)
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
stTuboExtremo
Definition: Globales.h:730
TCompTubDep
Definition: TCompTubDep.h:40
TCompresor
Definition: TCompresor.h:47
TCondicionContorno
Definition: TCondicionContorno.h:54
TCompresorDep
Definition: TCompresorDep.h:37
TDeposito
Definition: TDeposito.h:44
Exception
Custom exception class.
Definition: Exception.hpp:39
TCompTubos
Definition: TCompTubos.h:79
TCCEntradaCompresor
Definition: TCCEntradaCompresor.h:41
TTubo.h