OpenWAM
TCCEntradaCompresor.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 "TCCEntradaCompresor.h"
32 //#include <cmath>
33 #include <iostream>
34 #include "TCompresor.h"
35 #include "TTubo.h"
36 
37 //---------------------------------------------------------------------------
38 //---------------------------------------------------------------------------
39 
40 TCCEntradaCompresor::TCCEntradaCompresor(nmTypeBC TipoCC, int numCC, nmTipoCalculoEspecies SpeciesModel,
41  int numeroespecies, nmCalculoGamma GammaCalculation, bool ThereIsEGR) :
42  TCondicionContorno(TipoCC, numCC, SpeciesModel, numeroespecies, GammaCalculation, ThereIsEGR) {
43 
44  FTuboExtremo = NULL;
45  FVelocity = 0;
46  FSonido = 1;
47  FPressure = 0;
48  FGasto = 0;
49 
50 }
51 
52 //---------------------------------------------------------------------------
53 //---------------------------------------------------------------------------
54 
55 TCCEntradaCompresor::~TCCEntradaCompresor() {
56 
57  delete[] FTuboExtremo;
58 
59 }
60 
61 //---------------------------------------------------------------------------
62 //---------------------------------------------------------------------------
63 
64 void TCCEntradaCompresor::ReadBoundaryData(const char *FileWAM, fpos_t &filepos, int NumberOfPipes, TTubo **Pipe,
65  int nDPF, TDPF **DPF) {
66  try {
67  int i = 0;
68 
69  FTuboExtremo = new stTuboExtremo[1];
70  FTuboExtremo[0].Pipe = NULL;
71 
72  while(FNumeroTubosCC < 1 && i < NumberOfPipes) {
73  if(Pipe[i]->getNodoIzq() == FNumeroCC) {
74  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
75  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmLeft;
76  FNodoFin = 0;
77  FCC = &(FTuboExtremo[FNumeroTubosCC].Beta);
78  FCD = &(FTuboExtremo[FNumeroTubosCC].Landa);
79  FSeccionTubo = __geom::Circle_area(Pipe[i]->GetDiametro(FNodoFin));
80  FPressure = Pipe[i]->GetPresion(FNodoFin);
81  FNumeroTubosCC++;
82  }
83  if(Pipe[i]->getNodoDer() == FNumeroCC) {
84  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
85  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmRight;
86  FNodoFin = Pipe[i]->getNin() - 1;
87  FCC = &(FTuboExtremo[FNumeroTubosCC].Landa);
88  FCD = &(FTuboExtremo[FNumeroTubosCC].Beta);
89  FSeccionTubo = __geom::Circle_area(Pipe[i]->GetDiametro(FNodoFin));
90  FPressure = Pipe[i]->GetPresion(FNodoFin);
91  FNumeroTubosCC++;
92  }
93  i++;
94  }
95 
96  FILE *fich = fopen(FileWAM, "r");
97  fsetpos(fich, &filepos);
98 
99  fscanf(fich, "%d ", &FNumeroCompresor);
100 
101  fgetpos(fich, &filepos);
102  fclose(fich);
103 
104 // Inicializacion del transporte de especies quimicas.
105  FFraccionMasicaEspecie = new double[FNumeroEspecies - FIntEGR];
106  for(int i = 0; i < FNumeroEspecies - FIntEGR; i++) {
107  FFraccionMasicaEspecie[i] = FTuboExtremo[0].Pipe->GetFraccionMasicaInicial(i);
108  }
109 
110  } catch(exception &N) {
111  std::cout << "ERROR: TCCEntradaCompresor::AsignaTubos en la condicion de contorno: " << FNumeroCC << std::endl;
112  std::cout << "Tipo de error: " << N.what() << std::endl;
113  throw Exception(N.what());
114  }
115 }
116 //---------------------------------------------------------------------------
117 //---------------------------------------------------------------------------
118 
119 void TCCEntradaCompresor::AsignaCompresor(TCompresor **Compressor) {
120  try {
121 
122  FCompresor = Compressor[FNumeroCompresor - 1];
123 
124  } catch(exception &N) {
125  std::cout << "ERROR: TCCEntradaCompresor::AsignaCompresor en la condicion de contorno: " << FNumeroCC << std::endl;
126  std::cout << "Tipo de error: " << N.what() << std::endl;
127  throw Exception(N.what());
128  }
129 }
130 
131 //---------------------------------------------------------------------------
132 //---------------------------------------------------------------------------
133 
134 void TCCEntradaCompresor::CalculaCondicionContorno(double Time) {
135  try {
136  double cte1 = 0., cte2 = 0., ctea = 0., numerador = 0., denominador = 0., presionact = 0.;
137  int contador = 0;
138  double error = 1e5;
139 
140  FGamma = FTuboExtremo[0].Pipe->GetGamma(FNodoFin);
141  FGamma1 = __Gamma::G1(FGamma);
142  FGamma3 = __Gamma::G3(FGamma);
143  FGamma5 = __Gamma::G5(FGamma);
144 
145  FGasto = FCompresor->getMassflow();
146  cte1 = FTuboExtremo[0].Entropia;
147  cte2 = FGamma1 * pow2(FTuboExtremo[0].Entropia) * FGasto * __cons::ARef / (2 * FGamma * FSeccionTubo * 1e5);
148  ctea = FGamma1 / FGamma;
149 
150  while(error > 1e-5 && contador < 800) {
151  contador++;
152  numerador = cte1 * pow(FPressure, FGamma5) + cte2 * pow(FPressure, ctea - 1) - *FCC;
153  denominador = cte1 * FGamma5 * pow(FPressure, FGamma5 - 1) + cte2 * (ctea - 1) * pow(FPressure, ctea - 2);
154  presionact = FPressure - numerador / denominador;
155  error = fabs(FPressure - presionact);
156  FPressure = presionact;
157  }
158  if(contador > 799) {
159  printf("ERROR: TCCEntradaCompresor::CalculaCondicionContorno, no converge en entrada compresor en la condicion de contorno: %d\n",
160  FNumeroCC);
161  throw Exception("ERROR: TCCEntradaCompresor::CalculaCondicionContorno no converge en entrada compresor");
162  }
163 
164 // Calculo de velocidad,velocidad del sonido y caracteristica reflejada.
165  FSonido = FTuboExtremo[0].Entropia * pow(FPressure, FGamma5);
166  FVelocity = (*FCC - FSonido) / FGamma3;
167  *FCD = FSonido - FGamma3 * FVelocity;
168 
169 // Segun este modelo de compresor,el flujo solo puede entrar en el compresor. Asi que la composicion
170 // sera la determinada por la linea de corriente que llega del tubo. Esta sera la composicion del fluido
171 // en el compresor. Se actualiza directamente en el compresor.
172 
173  } catch(exception &N) {
174  std::cout << "ERROR: TCCEntradaCompresor::CalculaCondicionContorno en la condicion de contorno: " << FNumeroCC <<
175  std::endl;
176  std::cout << "Tipo de error: " << N.what() << std::endl;
177  throw Exception(N.what());
178  }
179 }
180 
181 //---------------------------------------------------------------------------
182 //---------------------------------------------------------------------------
183 
184 #pragma package(smart_init)
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
TTubo::GetGamma
double GetGamma(int i) const
Gets the specific heat capacities ratio at a given cell.
Definition: TTubo.cpp:5444
stTuboExtremo
Definition: Globales.h:730
TDPF
Definition: TDPF.h:45
TTubo::GetFraccionMasicaInicial
double GetFraccionMasicaInicial(int i) const
Gets the initial mass fraction of species i.
Definition: TTubo.cpp:5440
TTubo::GetPresion
double GetPresion(int i) const
Gets the fluid pressure.
Definition: TTubo.cpp:5468
TCompresor
Definition: TCompresor.h:47
TCondicionContorno
Definition: TCondicionContorno.h:54
Exception
Custom exception class.
Definition: Exception.hpp:39
TTubo.h
pow2
T pow2(T x)
Returns x to the power of 2.
Definition: Math_wam.h:88