OpenWAM
TCCExtremoInyeccion.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 "TCCExtremoInyeccion.h"
32 //#include <cmath>
33 #include <iostream>
34 #include "TTubo.h"
35 
36 //---------------------------------------------------------------------------
37 //---------------------------------------------------------------------------
38 
39 TCCExtremoInyeccion::TCCExtremoInyeccion(nmTypeBC TipoCC, int numCC, nmTipoCalculoEspecies SpeciesModel,
40  int numeroespecies, nmCalculoGamma GammaCalculation, bool ThereIsEGR) :
41  TCondicionContorno(TipoCC, numCC, SpeciesModel, numeroespecies, GammaCalculation, ThereIsEGR) {
42 
43  FTuboExtremo = NULL;
44  FComposicion = NULL;
45  FVelocity = 0;
46  FSonido = 1;
47  FPressure = 0;
48 
49 }
50 
51 //---------------------------------------------------------------------------
52 //---------------------------------------------------------------------------
53 
54 TCCExtremoInyeccion::~TCCExtremoInyeccion() {
55 
56  delete[] FTuboExtremo;
57  if(FComposicion != NULL)
58  delete[] FComposicion;
59 
60 }
61 
62 //---------------------------------------------------------------------------
63 //---------------------------------------------------------------------------
64 
65 void TCCExtremoInyeccion::ReadBoundaryData(const char *FileWAM, fpos_t &filepos, int NumberOfPipes, TTubo **Pipe,
66  int nDPF, TDPF **DPF) {
67  try {
68  int i = 0;
69  double fracciontotal = 0.;
70 
71  FTuboExtremo = new stTuboExtremo[1];
72  FTuboExtremo[0].Pipe = NULL;
73 
74  while(FNumeroTubosCC < 1 && i < NumberOfPipes) {
75  if(Pipe[i]->getNodoIzq() == FNumeroCC) {
76  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
77  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmLeft;
78  FNodoFin = 0;
79  FIndiceCC = 0;
80  FCC = &(FTuboExtremo[FNumeroTubosCC].Beta);
81  FCD = &(FTuboExtremo[FNumeroTubosCC].Landa);
82  FSeccion = __geom::Circle_area(Pipe[i]->GetDiametro(FNodoFin));
83  FNumeroTubosCC++;
84  }
85  if(Pipe[i]->getNodoDer() == FNumeroCC) {
86  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
87  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmRight;
88  FNodoFin = Pipe[i]->getNin() - 1;
89  FIndiceCC = 1;
90  FCC = &(FTuboExtremo[FNumeroTubosCC].Landa);
91  FCD = &(FTuboExtremo[FNumeroTubosCC].Beta);
92  FSeccion = __geom::Circle_area(Pipe[i]->GetDiametro(FNodoFin));
93  FNumeroTubosCC++;
94  }
95  i++;
96  }
97 
98  FILE *fich = fopen(FileWAM, "r");
99  fsetpos(fich, &filepos);
100 
101  fscanf(fich, "%lf %lf %lf ", &FGastoIny, &FTemperaturaIny, &FInicioIny);
102  fscanf(fich, "%lf ", &FDuracionIny);
103 
104 // Inicializacion del transporte de especies quimicas.
105  FFraccionMasicaEspecie = new double[FNumeroEspecies - FIntEGR];
106  FComposicion = new double[FNumeroEspecies - FIntEGR];
107  for(int i = 0; i < FNumeroEspecies - 1; i++) {
108  fscanf(fich, "%lf ", &FComposicion[i]);
109  FFraccionMasicaEspecie[i] = FTuboExtremo[0].Pipe->GetFraccionMasicaInicial(i);
110  fracciontotal += FComposicion[i];
111  }
112  if(FHayEGR) {
113  FFraccionMasicaEspecie[FNumeroEspecies - 1] = FTuboExtremo[0].Pipe->GetFraccionMasicaInicial(FNumeroEspecies - 1);
114  if(FCalculoEspecies == nmCalculoCompleto) {
115  if(FComposicion[0] > 0.2)
116  FComposicion[FNumeroEspecies - 1] = 0.;
117  else
118  FComposicion[FNumeroEspecies - 1] = 1.;
119  } else {
120  if(FComposicion[0] > 0.5)
121  FComposicion[FNumeroEspecies - 1] = 1.;
122  else
123  FComposicion[FNumeroEspecies - 1] = 0.;
124  }
125  }
126  if(fracciontotal != 1.) {
127  std::cout <<
128  "ERROR: La fraccion masica total no puede ser distinta de 1. Repasa la lectura en la condicion de contorno " <<
129  FNumeroCC << std::endl;
130  throw Exception(" ");
131  }
132 
133  fgetpos(fich, &filepos);
134  fclose(fich);
135 
136  }
137 
138  catch(exception &N) {
139  std::cout << "ERROR: TCCExtremoInyeccion::LeeExtremoInyeccion en la condicion de contorno: " << FNumeroCC << std::endl;
140  std::cout << "Tipo de error: " << N.what() << std::endl;
141  throw Exception(N.what());
142  }
143 }
144 
145 //---------------------------------------------------------------------------
146 //---------------------------------------------------------------------------
147 
148 void TCCExtremoInyeccion::ObtencionValoresInstantaneos(double Theta) {
149  try {
150  double ang0 = 0.;
151 
152  FTheta = Theta;
153 
154  ang0 = FTheta - FInicioIny;
155  FAngap = ang0 - floor(ang0 / 360.) * 360.;
156 
157  } catch(exception &N) {
158  std::cout << "ERROR: TCCExtremoInyeccion::ObtencionValoresInstantaneos en la condicion de contorno: " << FNumeroCC <<
159  std::endl;
160  std::cout << "Tipo de error: " << N.what() << std::endl;
161  throw Exception(N.what());
162  }
163 }
164 
165 //---------------------------------------------------------------------------
166 //---------------------------------------------------------------------------
167 
168 void TCCExtremoInyeccion::CalculaCondicionContorno(double Time) {
169  try {
170  double FraccionMasicaAcum = 0.;
171 
172  FGamma = FTuboExtremo[0].Pipe->GetGamma(FNodoFin);
173  FRMezcla = FTuboExtremo[0].Pipe->GetRMezcla(FNodoFin);
174 
175  FGamma3 = __Gamma::G3(FGamma);
176  FGamma5 = __Gamma::G5(FGamma);
177 
178  if(FAngap < FDuracionIny && FTheta > 720.) {
179  FSonido = sqrt(FGamma * FRMezcla * __units::degCToK(FTemperaturaIny)) / __cons::ARef;
180  FVelocity = (FSonido - *FCC) / FGamma3;
181  FPressure = __units::PaToBar(FGastoIny * FRMezcla * __units::degCToK(FTemperaturaIny) /
182  (FVelocity * __cons::ARef * FSeccion)); // Cociente entre presion y la presion de referencia(1e5);
183  if(FPressure < 0.0) {
184  printf("ERROR: TCCExtremoInyeccion::CalculaCondicionContorno Velocity negativa en inyector %lf,Theta= %lf\n en la condicion de contorno: %d",
185  FVelocity * __cons::ARef, FTheta,
186  FNumeroCC);
187  printf(" TCCExtremoInyeccion::CalculaCondicionContorno Presion negativa en inyector %lf\n", FPressure);
188  throw Exception("");
189  }
190  *FCD = FSonido + FGamma3 * FVelocity;
191  FTuboExtremo[0].Entropia = FSonido / pow(FPressure, FGamma5);
192 
193  //Transporte de especies quimicas.
194  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
195  FFraccionMasicaEspecie[j] = FComposicion[j];
196  }
197 
198  } else {
199  // No hay inyeccion,se comporta como un extremo cerrado.
200  *FCD = *FCC;
201 
202  //Transporte de especies quimicas.
203  for(int j = 0; j < FNumeroEspecies - 2; j++) {
204  FFraccionMasicaEspecie[j] = FTuboExtremo[0].Pipe->GetFraccionMasicaCC(FIndiceCC, j);
205  FraccionMasicaAcum += FFraccionMasicaEspecie[j];
206  }
207  FFraccionMasicaEspecie[FNumeroEspecies - 2] = 1. - FraccionMasicaAcum;
208  if(FHayEGR)
209  FFraccionMasicaEspecie[FNumeroEspecies - 1] = FTuboExtremo[0].Pipe->GetFraccionMasicaCC(FIndiceCC, FNumeroEspecies - 1);
210  }
211 
212  } catch(exception &N) {
213  std::cout << "ERROR: TCCExtremoInyeccion::CalculaCondicionContorno en la condicion de contorno: " << FNumeroCC <<
214  std::endl;
215  std::cout << "Tipo de error: " << N.what() << std::endl;
216  throw Exception(N.what());
217  }
218 }
219 
220 //---------------------------------------------------------------------------
221 //---------------------------------------------------------------------------
222 
223 //void TCCExtremoInyeccion::PutIniIny(double valor)
224 //{
225 //try
226 //{
227 //
228 //FInicioIny=valor;
229 //
230 //}
231 //catch(Exception &N)
232 //{
233 //std::cout << "ERROR: TCCExtremoInyeccion::PutIniIny en la condicion de contorno: " << FNumeroCC << std::endl;
234 //std::cout << "Tipo de error: " << N.what() << std::endl;
235 //throw Exception(N.what());
236 //}
237 //}
238 
239 //---------------------------------------------------------------------------
240 //---------------------------------------------------------------------------
241 
242 //void TCCExtremoInyeccion::PutDuracionIny(double valor)
243 //{
244 //try
245 //{
246 //
247 //FDuracionIny=valor;
248 //
249 //}
250 //catch(Exception &N)
251 //{
252 //std::cout << "ERROR: TCCExtremoInyeccion::PutDuracionIny en la condicion de contorno: " << FNumeroCC << std::endl;
253 //std::cout << "Tipo de error: " << N.what() << std::endl;
254 //throw Exception(N.what());
255 //}
256 //}
257 
258 //---------------------------------------------------------------------------
259 //---------------------------------------------------------------------------
260 
261 #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::GetFraccionMasicaCC
double GetFraccionMasicaCC(int j, int i)
Definition: TTubo.h:953
TTubo::GetFraccionMasicaInicial
double GetFraccionMasicaInicial(int i) const
Gets the initial mass fraction of species i.
Definition: TTubo.cpp:5440
TCondicionContorno
Definition: TCondicionContorno.h:54
Exception
Custom exception class.
Definition: Exception.hpp:39
TTubo.h
TTubo::GetRMezcla
double GetRMezcla(int i) const
Gets the gas constant of the mixture at a given cell.
Definition: TTubo.cpp:5476