OpenWAM
TControlFuel.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 "TControlFuel.h"
32 
33 //---------------------------------------------------------------------------
34 //---------------------------------------------------------------------------
35 
36 TControlFuel::TControlFuel() {
37  FVector_Ma_mapa = NULL;
38  FVector_Regimen_mapa = NULL;
39  FMapa_Limitador_Humos = NULL;
40 }
41 
42 //---------------------------------------------------------------------------
43 //---------------------------------------------------------------------------
44 
45 TControlFuel::~TControlFuel() {
46 
47  if(FVector_Ma_mapa != NULL)
48  delete FVector_Ma_mapa;
49  if(FVector_Regimen_mapa != NULL)
50  delete FVector_Regimen_mapa;
51 
52  if(FMapa_Limitador_Humos != NULL) {
53  for(int i = 0; i < FNumeroDatos_Ma; i++) {
54  delete FMapa_Limitador_Humos[i];
55  }
56  delete[] FMapa_Limitador_Humos;
57  }
58 
59 }
60 
61 //---------------------------------------------------------------------------
62 //---------------------------------------------------------------------------
63 
64 void TControlFuel::LeeDatosEntrada(char *Ruta, FILE *fich) {
65  char *FileFuel;
66  char *DatosFuel;
67 
68  try {
69 
70  for(int i = 0; i <= (int) strlen(Ruta); i++) {
71  DatosFuel[i] = Ruta[i];
72  }
73 
74  fscanf(fich, "%s ", &FileFuel);
75  strcat(DatosFuel, FileFuel);
76 
77  FichFuel = fopen(DatosFuel, "r");
78  if((FichFuel = fopen(DatosFuel, "r")) == NULL) {
79  std::cout << "ERROR: Fichero de fuel no cargado";
80  } else {
81  fscanf(FichFuel, "%d %d ", &FNumeroDatos_Regimen, &FNumeroDatos_Ma);
82  FVector_Ma_mapa = new double[FNumeroDatos_Ma];
83  FVector_Regimen_mapa = new double[FNumeroDatos_Regimen];
84  FMapa_Limitador_Humos = new double*[FNumeroDatos_Ma];
85  for(int i = 0; i < FNumeroDatos_Ma; i++) {
86  FMapa_Limitador_Humos[i] = new double[FNumeroDatos_Regimen];
87  }
88 
89  for(int i = 0; i < FNumeroDatos_Regimen; i++) {
90  fscanf(FichFuel, "%lf ", &FVector_Regimen_mapa[i]);
91  }
92 
93  for(int i = 0; i < FNumeroDatos_Ma; i++) {
94  fscanf(FichFuel, "%lf ", &FVector_Ma_mapa[i]);
95  }
96 
97  for(int i = 0; i < FNumeroDatos_Ma; i++) {
98  for(int j = 0; j < FNumeroDatos_Regimen; j++) {
99  fscanf(FichFuel, "%lf ", &FMapa_Limitador_Humos[i][j]);
100  }
101  }
102 
103  fclose(FichFuel);
104  }
105 
106  } catch(exception &N) {
107  std::cout << "ERROR: LeeDatosEntrada Fuel (DLL)" << std::endl;
108  std::cout << "Tipo de error: " << N.what() << std::endl;
109  throw Exception(N.what());
110  }
111 }
112 
113 //---------------------------------------------------------------------------
114 //---------------------------------------------------------------------------
115 /*
116  double TControlFuel::CalculaFuel(double TiempoActual)
117  {
118  try{
119  int j=0, jmax=FNumeroDatos-1;
120  double FuelAct, deltaT, t;
121  while(TiempoActual>FTiempo[j] && j<jmax){
122  j++;
123  }
124  if(j==jmax){
125  FuelAct=FFuel[jmax];
126  }else{
127  deltaT= FTiempo[j]-FTiempo[j-1];
128  t=TiempoActual-FTiempo[j-1];
129  FuelAct=xit_(FFuel[j-1],FFuel[j],deltaT,t);
130  }
131  return FuelAct;
132  }
133  catch(Exception &N)
134  {
135  std::cout << "ERROR: CalculaFuel" << std::endl;
136  std::cout << "Tipo de error: " << N.what() << std::endl;
137  throw Exception(N.what());
138  }
139 
140  }
141 
142  */
143 
144 //---------------------------------------------------------------------------
145 //---------------------------------------------------------------------------
146 double TControlFuel::xit_(double vizq, double vder, double axid, double xif) {
147  try {
148  double xx = 0., yy = 0.;
149  double ret_val = 0.;
150 
151  xx = vder - vizq;
152  if(axid != 0.) {
153  yy = xx / axid * xif;
154  ret_val = vizq + yy;
155  } else {
156  printf("ERROR: valores entrada xit\n");
157  throw Exception("");
158  }
159  return ret_val;
160  } catch(exception &N) {
161  std::cout << "ERROR: xit_" << std::endl;
162  std::cout << "Tipo de error: " << N.what() << std::endl;
163  throw Exception(N.what());
164  }
165 }
166 
167 //---------------------------------------------------------------------------
168 //---------------------------------------------------------------------------
169 
170 double TControlFuel::CalculaFuel(double MasaPorAdmision, double Regimen, double TiempoActual) {
171  try {
172  /* Estrategia de inyeccion de combustible en transitorio de carga. */
173  double MasaAire = 0., FuelMin = 0., FuelMax = 0., FuelLimitador = 0.;
174 
175  FuelMin = 4.32E-06; // en (kg/cc)
176  FuelMax = 5.86E-05; // en (kg/cc)
177 
178 // MasaPorAdmision ha de expresarse en mg
179 
180  if(TiempoActual < 10. * 120. / Regimen) {
181  FuelAct = FuelMin;
182  FFuelDeseado = FuelMin;
183  }
184 
185  if(TiempoActual > 10. * 120. / Regimen) {
186  FuelAct = FuelMax;
187  FFuelDeseado = FuelMax;
188  /* Calculo de combustible dado por el limitador de humos (kg/cc para WAM)*/
189  FuelLimitador = Interpolacion_bidimensional(Regimen, MasaPorAdmision, FVector_Ma_mapa, FVector_Regimen_mapa,
190  FMapa_Limitador_Humos, FNumeroDatos_Regimen, FNumeroDatos_Ma) / 1e6;
191 
192  if(FuelLimitador < FuelAct) {
193  FuelAct = FuelLimitador;
194  }
195  }
196 
197  return FuelAct;
198 
199  } catch(exception &N) {
200  std::cout << "ERROR: TControlFuel::CalculaFuel" << std::endl;
201  std::cout << "Tipo de error: " << N.what() << std::endl;
202  throw Exception(N.what());
203  }
204 }
205 
206 //---------------------------------------------------------------------------
207 //---------------------------------------------------------------------------
208 //
209 //double TControlFuel::CalculaFuel()
210 //{
211 //try
212 //{
213 //
215 //return FuelAct;
216 //
217 //}
218 //catch(Exception &N)
219 //{
220 //std::cout << "ERROR: TControlFuel::CalculaFuel" << std::endl;
221 //std::cout << "Tipo de error: " << N.what() << std::endl;
222 //throw Exception(N.what());
223 //}
224 //}
225 //
226 //---------------------------------------------------------------------------
227 //---------------------------------------------------------------------------
228 
229 void TControlFuel::IniciaFuel(double mfuel) {
230  try {
231 
232  FuelAct = mfuel;
233 
234  } catch(exception &N) {
235  std::cout << "ERROR: TControlFuel::IniciaFuel" << std::endl;
236  std::cout << "Tipo de error: " << N.what() << std::endl;
237  throw Exception(N.what());
238  }
239 }
240 
241 //---------------------------------------------------------------------------
242 //---------------------------------------------------------------------------
243 
244 #pragma package(smart_init)
245 
Exception
Custom exception class.
Definition: Exception.hpp:39
TControlFuel::IniciaFuel
void IniciaFuel(double mfuel)
Definition: TControlFuel.cpp:229