OpenWAM
TEntradaPulso.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 "TEntradaPulso.h"
32 
33 //---------------------------------------------------------------------------
34 //---------------------------------------------------------------------------
35 
36 TEntradaPulso::TEntradaPulso() {
37 
38  FTiempo = NULL;
39  FPresionRelativa = NULL;
40  FNivelEntropia = NULL;
41  FNumeroCiclo = 1;
42 }
43 
44 //---------------------------------------------------------------------------
45 //---------------------------------------------------------------------------
46 
47 TEntradaPulso::~TEntradaPulso() {
48  if(FTiempo != NULL)
49  delete FTiempo;
50  if(FPresionRelativa != NULL)
51  delete FPresionRelativa;
52  if(FNivelEntropia != NULL)
53  delete FNivelEntropia;
54 
55 }
56 
57 //---------------------------------------------------------------------------
58 //---------------------------------------------------------------------------
59 
60 void TEntradaPulso::LeeEntradaPulso(FILE *fich) {
61  try {
62 
63  fscanf(fich, "%d ", &FNumeroDatos);
64  FTiempo = new double[FNumeroDatos];
65  FPresionRelativa = new double[FNumeroDatos];
66  FNivelEntropia = new double[FNumeroDatos];
67  for(int i = 0; i < FNumeroDatos; i++) {
68  fscanf(fich, "%lf %lf %lf ", &FTiempo[i], &FPresionRelativa[i], &FNivelEntropia[i]);
69  }
70  if(FTiempo[0] > 0.0) {
71  std::cout << "WARNING: El primer instante de tiempo deberia ser 0 para evitar problemas" << std::endl;
72  }
73  } catch(exception &N) {
74  stringstream err;
75  std::cout << "ERROR: TEntradaPulso::LeeEntradaPulso " << std::endl;
76  std::cout << "Tipo de error: " << N.what() << std::endl;
77  err << "ERROR: TEntradaPulso::LeeEntradaPulso " << N.what();
78  throw Exception(err.str());
79  }
80 }
81 
82 //---------------------------------------------------------------------------
83 //---------------------------------------------------------------------------
84 
85 void TEntradaPulso::BusquedaInstante(double Tiempo) {
86  try {
87  int i = 0;
88  FTiempoActual = Tiempo - (FNumeroCiclo - 1) * FTiempo[FNumeroDatos - 1];
89 //std::cout << FTiempoActual << "\t" << FNumeroCiclo << "\t" << FNumeroCiclo*FTiempo[FNumeroDatos-1] << std::endl;
90  if(FTiempoActual > FTiempo[FNumeroDatos - 1]) {
91  ++FNumeroCiclo;
92  FTiempoActual = FTiempoActual - FTiempo[FNumeroDatos - 1];
93  std::cout << "INFO: Comienza el ciclo " << FNumeroCiclo << std::endl;
94  std::cout << " Tiempo transcurrido: " << Tiempo << std::endl;
95  }
96  while(Tiempo > FTiempo[i] + (FNumeroCiclo - 1) * FTiempo[FNumeroDatos - 1]) {
97  ++i;
98  }
99  FInstante = i;
100 
101  } catch(exception &N) {
102  stringstream err;
103  std::cout << "ERROR: TEntradaPulso::BusquedaInstante " << std::endl;
104  std::cout << "Tipo de error: " << N.what() << std::endl;
105  err << "ERROR: TEntradaPulso::BusquedaInstante " << N.what();
106  throw Exception(err.str());
107  }
108 }
109 
110 //---------------------------------------------------------------------------
111 //---------------------------------------------------------------------------
112 
113 double TEntradaPulso::InterpolaPresion() {
114  try {
115  double deltat = (FTiempoActual - FTiempo[FInstante - 1]) / (FTiempo[FInstante] - FTiempo[FInstante - 1]);
116  double presion = (1 - deltat) * FPresionRelativa[FInstante - 1] + deltat * FPresionRelativa[FInstante];
117  return presion;
118  } catch(exception &N) {
119  stringstream err;
120  std::cout << "ERROR: TEntradaPulso::InterpolaPresion " << std::endl;
121  std::cout << "Tipo de error: " << N.what() << std::endl;
122  err << "ERROR: TEntradaPulso::InterpolaPresion " << N.what();
123  throw Exception(err.str());
124  }
125 }
126 
127 //---------------------------------------------------------------------------
128 //---------------------------------------------------------------------------
129 
130 double TEntradaPulso::InterpolaEntropia() {
131  try {
132  double deltat = (FTiempoActual - FTiempo[FInstante - 1]) / (FTiempo[FInstante] - FTiempo[FInstante - 1]);
133  double entropia = (1 - deltat) * FNivelEntropia[FInstante - 1] + deltat * FNivelEntropia[FInstante];
134  return entropia;
135  } catch(exception &N) {
136  stringstream err;
137  std::cout << "ERROR: TEntradaPulso::InterpolaEntropia" << std::endl;
138  std::cout << "Tipo de error: " << N.what() << std::endl;
139  err << "ERROR: TEntradaPulso::InterpolaEntropia " << N.what();
140  throw Exception(err.str());
141  }
142 }
143 
144 //---------------------------------------------------------------------------
145 //---------------------------------------------------------------------------
146 
147 #pragma package(smart_init)
Exception
Custom exception class.
Definition: Exception.hpp:39