OpenWAM
TCCPreVble.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 "TCCPreVble.h"
32 // #include <cmath>
33 #include <iostream>
34 
35 #include "TTubo.h"
36 #include "TEntradaPulso.h"
37 
38 // ---------------------------------------------------------------------------
39 // ---------------------------------------------------------------------------
40 
41 TCCPreVble::TCCPreVble(nmTypeBC TipoCC, int numCC, nmTipoCalculoEspecies SpeciesModel, int numeroespecies,
42  nmCalculoGamma GammaCalculation, bool ThereIsEGR) :
43  TCondicionContorno(TipoCC, numCC, SpeciesModel, numeroespecies, GammaCalculation, ThereIsEGR) {
44 
45  FTuboExtremo = NULL;
46  FPulso = NULL;
47  FComposicion = NULL;
48 
49 }
50 
51 // ---------------------------------------------------------------------------
52 // ---------------------------------------------------------------------------
53 
54 TCCPreVble::~TCCPreVble() {
55 
56  delete[] FTuboExtremo;
57 
58  if(FPulso != NULL)
59  delete FPulso;
60 
61  if(FComposicion != NULL)
62  delete[] FComposicion;
63 
64 }
65 
66 // ---------------------------------------------------------------------------
67 // ---------------------------------------------------------------------------
68 
69 void TCCPreVble::ReadBoundaryData(const char *FileWAM, fpos_t &filepos, int NumberOfPipes, TTubo **Pipe, int nDPF,
70  TDPF **DPF) {
71  try {
72  int i = 0;
73  double fracciontotal = 0.;
74 
75  FTuboExtremo = new stTuboExtremo[1];
76  FTuboExtremo[0].Pipe = NULL;
77 
78  FTiempo = 0;
79  FPref = 1;
80 
81  while(FNumeroTubosCC < 1 && i < NumberOfPipes) {
82  if(Pipe[i]->getNodoIzq() == FNumeroCC) {
83  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
84  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmLeft;
85  FCC = &(FTuboExtremo[FNumeroTubosCC].Beta);
86  FCD = &(FTuboExtremo[FNumeroTubosCC].Landa);
87  FNodoFin = 0;
88  FIndiceCC = 0;
89  FNumeroTubosCC++;
90  }
91  if(Pipe[i]->getNodoDer() == FNumeroCC) {
92  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
93  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmRight;
94  FCC = &(FTuboExtremo[FNumeroTubosCC].Landa);
95  FCD = &(FTuboExtremo[FNumeroTubosCC].Beta);
96  FNodoFin = FTuboExtremo[FNumeroTubosCC].Pipe->getNin() - 1;
97  FIndiceCC = 1;
98  FNumeroTubosCC++;
99  }
100  i++;
101  }
102 
103  FILE *fich = fopen(FileWAM, "r");
104  fsetpos(fich, &filepos);
105 
106  FPulso = new TEntradaPulso();
107  FPulso->LeeEntradaPulso(fich);
108 
109  // Inicializacion del transporte de especies quimicas.
110  FFraccionMasicaEspecie = new double[FNumeroEspecies - FIntEGR];
111  FComposicion = new double[FNumeroEspecies - FIntEGR];
112  for(int i = 0; i < FNumeroEspecies - 1; i++) {
113  fscanf(fich, "%lf ", &FComposicion[i]);
114  FFraccionMasicaEspecie[i] = FTuboExtremo[0].Pipe->GetFraccionMasicaInicial(i);
115  fracciontotal += FComposicion[i];
116  }
117  if(FHayEGR) {
118  FFraccionMasicaEspecie[FNumeroEspecies - 1] = FTuboExtremo[0].Pipe->GetFraccionMasicaInicial(FNumeroEspecies - 1);
119  if(FCalculoEspecies == nmCalculoCompleto) {
120  if(FComposicion[0] > 0.2)
121  FComposicion[FNumeroEspecies - 1] = 0.;
122  else
123  FComposicion[FNumeroEspecies - 1] = 1.;
124  } else {
125  if(FComposicion[0] > 0.5)
126  FComposicion[FNumeroEspecies - 1] = 1.;
127  else
128  FComposicion[FNumeroEspecies - 1] = 0.;
129  }
130  }
131 
132  if(fracciontotal != 1.) {
133  std::cout <<
134  "ERROR: La fraccion masica total no puede ser distinta de 1. Repasa la lectura en la condicion de contorno " <<
135  FNumeroCC << std::endl;
136  throw Exception(" ");
137  }
138 
139  fgetpos(fich, &filepos);
140  fclose(fich);
141 
142  }
143 
144  catch(exception & N) {
145  std::cout << "ERROR: TCCPreVble::LecturaPulso en la condicion de contorno: " << FNumeroCC << std::endl;
146  std::cout << "Tipo de error: " << N.what() << std::endl;
147  throw Exception(N.what());
148  }
149 }
150 
151 // ---------------------------------------------------------------------------
152 // ---------------------------------------------------------------------------
153 
154 void TCCPreVble::CalculaCondicionContorno(double Time) {
155  try {
156  double Pressure, Temp, Ason, FraccionMasicaAcum = 0.;
157 
158  FGamma = FTuboExtremo[0].Pipe->GetGamma(FNodoFin);
159  double Gamma3 = (FGamma - 1) / 2;
160  double R = FTuboExtremo[0].Pipe->GetRMezcla(FNodoFin);
161 
162  FTiempo = FTuboExtremo[0].Pipe->getTime1();
163  FPulso->BusquedaInstante(FTiempo);
164 
165  Pressure = FPulso->InterpolaPresion();
166  Temp = FPulso->InterpolaEntropia();
167 
168  double rel_CCon_entropia = *FCC / FTuboExtremo[0].Entropia;
169  double yyy = pow(Pressure / FPref, __Gamma::G5(FGamma));
170 
171  if(rel_CCon_entropia / yyy < 1.0) {
172 
173  Ason = sqrt(FGamma * R * __units::degCToK(Temp)) / __cons::ARef;
174  double AA = Ason / pow(Pressure, __Gamma::G5(FGamma));
175  double U = (*FCC - Ason * FTuboExtremo[0].Entropia / AA) / Gamma3;
176  *FCC = Ason + Gamma3 * U;
177  *FCD = Ason - Gamma3 * U;
178  FTuboExtremo[0].Entropia = Ason / pow(Pressure, __Gamma::G5(FGamma));
179  } else {
180  Ason = FTuboExtremo[0].Entropia * pow(Pressure, __Gamma::G5(FGamma));
181  *FCD = 2 * Ason - *FCC;
182  }
183 
184  // *FCD=(2.0*pow((1+Pressure)/FPref,__Gamma::G5(FGamma))-1.0)*Entropia;
185  // *FCC=Entropia;
186  // FTuboExtremo[0].Entropia=Entropia;
187 
188  // Transporte de Especies Quimicas
189  if(*FCC > *FCD) { // Flujo saliente del tubo
190  for(int j = 0; j < FNumeroEspecies - 2; j++) {
191  FFraccionMasicaEspecie[j] = FTuboExtremo[0].Pipe->GetFraccionMasicaCC(FIndiceCC, j);
192  FraccionMasicaAcum += FFraccionMasicaEspecie[j];
193  }
194  FFraccionMasicaEspecie[FNumeroEspecies - 2] = 1. - FraccionMasicaAcum;
195  if(FHayEGR)
196  FFraccionMasicaEspecie[FNumeroEspecies - 1] = FTuboExtremo[0].Pipe->GetFraccionMasicaCC(FIndiceCC, FNumeroEspecies - 1);
197  } else if(*FCD > *FCC) { // Flujo entrante al tubo
198  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
199  FFraccionMasicaEspecie[j] = FComposicion[j];
200  }
201  }
202  /* La ultima opcion es que *FCC=*FCD. En este caso el flujo esta parado y la fraccion masica
203  de las especies permanece constante en dicho instante */
204 
205  } catch(exception & N) {
206  std::cout << "ERROR: TCCPreVble::CalculaCondicionesContorno en la condicion de contorno: " << FNumeroCC << std::endl;
207  std::cout << "Tipo de error: " << N.what() << std::endl;
208  throw Exception(N.what());
209  }
210 }
211 
212 // ---------------------------------------------------------------------------
213 // ---------------------------------------------------------------------------
214 
215 #pragma package(smart_init)
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
TTubo::getTime1
double getTime1() const
Gets the time at the following time-step.
Definition: TTubo.cpp:5492
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
TEntradaPulso
Definition: TEntradaPulso.h:42