OpenWAM
TCCPulso.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 "TCCPulso.h"
32 //#include <cmath>
33 #include <iostream>
34 
35 #include "TTubo.h"
36 #include "TEntradaPulso.h"
37 
38 //---------------------------------------------------------------------------
39 //---------------------------------------------------------------------------
40 
41 TCCPulso::TCCPulso(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 TCCPulso::~TCCPulso() {
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 TCCPulso::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: TCCPulso::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 TCCPulso::CalculaCondicionContorno(double Time) {
155  try {
156  double Pressure, Entropia, FraccionMasicaAcum = 0.;
157 
158  FGamma = FTuboExtremo[0].Pipe->GetGamma(FNodoFin);
159 
160  FTiempo = FTuboExtremo[0].Pipe->getTime1();
161  FPulso->BusquedaInstante(FTiempo);
162 
163  Pressure = FPulso->InterpolaPresion();
164  Entropia = FPulso->InterpolaEntropia();
165 
166  *FCD = (2.0 * pow((1 + Pressure) / FPref, __Gamma::G5(FGamma)) - 1.0) * Entropia;
167  *FCC = Entropia;
168  FTuboExtremo[0].Entropia = Entropia;
169 
170 // Transporte de Especies Quimicas
171  if(*FCC > *FCD) { // Flujo saliente del tubo
172  for(int j = 0; j < FNumeroEspecies - 2; j++) {
173  FFraccionMasicaEspecie[j] = FTuboExtremo[0].Pipe->GetFraccionMasicaCC(FIndiceCC, j);
174  FraccionMasicaAcum += FFraccionMasicaEspecie[j];
175  }
176  FFraccionMasicaEspecie[FNumeroEspecies - 2] = 1. - FraccionMasicaAcum;
177  if(FHayEGR)
178  FFraccionMasicaEspecie[FNumeroEspecies - 1] = FTuboExtremo[0].Pipe->GetFraccionMasicaCC(FIndiceCC, FNumeroEspecies - 1);
179  } else if(*FCD > *FCC) { // Flujo entrante al tubo
180  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
181  FFraccionMasicaEspecie[j] = FComposicion[j];
182  }
183  }
184  /* La ultima opcion es que *FCC=*FCD. En este caso el flujo esta parado y la fraccion masica
185  de las especies permanece constante en dicho instante */
186 
187  } catch(exception &N) {
188  std::cout << "ERROR: TCCPulso::CalculaCondicionesContorno en la condicion de contorno: " << FNumeroCC << std::endl;
189  std::cout << "Tipo de error: " << N.what() << std::endl;
190  throw Exception(N.what());
191  }
192 }
193 
194 //---------------------------------------------------------------------------
195 //---------------------------------------------------------------------------
196 
197 #pragma package(smart_init)
198 
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
TEntradaPulso
Definition: TEntradaPulso.h:42