OpenWAM
TCalculoExtern.h
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 #ifndef TCalculoExternH
30 #define TCalculoExternH
31 #define maxnd 80 /*n. maximo de nodos que llegan a depositos*/
32 
33 // #include "engine.h"
34 #include "Constantes.h"
35 #include "Globales.h"
36 
37 #include <string.h>
38 #include <cstdio>
39 #include <iostream>
40 #ifdef __BORLANDC__
41 #include <vcl.h>
42 #endif
43 //#include <cmath>
44 #include <fstream>
45 
46 // class TMatlab;
47 class TTubo;
48 class TDeposito;
49 class TCCDeposito;
50 class TCondicionContorno;
51 class TTGV;
52 class TControlFuel;
53 class TEGRV;
54 class TRegimenMotor;
55 class Tfql;
56 class TEjeTurbogrupo;
57 class TTurbina;
58 class TVenturi;
59 class TBloqueMotor;
60 class TRemansoMatlab;
61 class TCoefDescarga;
64 class TControlInyeccion;
65 class TControlK;
66 
67 enum nmTipoSenTubo {
68  nmPrTubo = 0, nmVelTubo = 1, nmTempTubo = 2, nmGastoTubo = 3, nmN2Tubo = 4, nmO2Tubo = 5, nmCO2Tubo = 6, nmH2OTubo = 7, nmHCTubo = 8, nmSootTubo = 9, nmNOxTubo = 10, nmCOTubo = 11, nmAireFrTubo = 12, nmGasQuemadoTubo = 13, nmEGRTubo = 14, nmCombustibleTubo = 15
69 };
70 
71 enum nmTipoSenDep {
72  nmPrDep = 0, nmTempDep = 1, nmN2Dep = 2, nmO2Dep = 3, nmCO2Dep = 4, nmH2ODep = 5, nmHCDep = 6, nmSootDep = 7, nmNOxDep = 8, nmCODep = 9, nmAireFrDep = 10, nmGasQuemadoDep = 11, nmEGRDep = 12, nmCombustibleDep = 13
73 };
74 
75 enum nmTipoSenTG {
76  nmRTCTG = 0
77 };
78 
79 enum nmTipoSenTurbina {
80  nmRelaci1 = 0, nmRelaci2 = 1
81 };
82 
83 enum nmTipoSenCil {
84  nmPrCil = 0, nmTempCil = 1, nmMfCil = 2, nmAFRCil = 3
85 };
86 
87 enum nmTipoSenVent {
88  nmPrEntVent = 0, nmPrGarVent = 1, nmVelEntVent = 2, nmVelLatVent = 3, nmGastoEntVent = 4, nmGastoLatVent = 5
89 };
90 
91 enum nmTipoSenMotor {
92  nmAngulo = 0, nmReg = 1, nmTiempo = 2
93 };
94 
95 enum nmTipoSenUED {
96  nmGasto = 0
97 };
98 
99 struct stSensorTubos {
100  int tubo;
101  int nodos;
102  double deltax;
103  double distancia;
104  double ctetiempo;
105  double ganancia;
106  double valact;
107  double valant;
108  double valreal;
109  double valrealant;
110  nmTipoSenTubo tipo;
111 };
112 
113 struct stSensorDep {
114  int deposito;
115  double ctetiempo;
116  double ganancia;
117  double valact;
118  double valant;
119  double valreal;
120  double valrealant;
121  nmTipoSenDep tipo;
122 };
123 
124 struct stSensorTG {
125  int turbogrupo;
126  double ctetiempo;
127  double ganancia;
128  double valact;
129  double valant;
130  double valreal;
131  double valrealant;
132  nmTipoSenTG tipo;
133 };
134 
136  int turbina;
137  double ctetiempo;
138  double ganancia;
139  double valact;
140  double valant;
141  double valreal;
142  double valrealant;
143  nmTipoSenTurbina tipo;
144 };
145 
146 struct stSensorCil {
147  int cilindro;
148  double ctetiempo;
149  double ganancia;
150  double valact;
151  double valant;
152  double valreal;
153  double valrealant;
154  nmTipoSenCil tipo;
155 };
156 
157 struct stSensorVent {
158  int venturi;
159  double ctetiempo;
160  double ganancia;
161  double valact;
162  double valant;
163  double valreal;
164  double valrealant;
165  nmTipoSenVent tipo;
166 };
167 
169  int motor;
170  double ctetiempo;
171  double ganancia;
172  double valact;
173  double valant;
174  double valreal;
175  double valrealant;
176  nmTipoSenMotor tipo;
177 };
178 
179 struct stSensorUED {
180  int CCUED;
181  double ctetiempo;
182  double ganancia;
183  double valact;
184  double valant;
185  double valreal;
186  double valrealant;
187  nmTipoSenUED tipo;
188 };
189 
191  private:
192  // Variables
193  int FNumeroInMat; // Numero de entradas a matlab
194  int FNumeroOutMat; // Numero de salidas de matlab
195 
196  int FNInputsdll; // Numero de entradas de la dll
197  int FNOutputsdll; // Numero de salidas de la dll
198 
199  int FNSensTubos; // Numero de sensores en tubos
200  int FNSensDepositos; // Numero de sensores en depositos
201  int FNSensTurbogrupo; // Numero de sensores en turbogrupos
202  int FNSensTurbina; // Numero de sensores en turbina
203  int FNSensMotor; // Numero de sensores en el motor
204  int FNSensVenturis; // Numero de sensores en venturis
205  int FNSensCilindros; // Numero de sensores en cilindros
206  int FNSensUED; // Numero de sensores en uniones entre depositos
207 
208  double *FInputs; // Vector de comunicacion WAM -> DLL
209  double *FOutputs; // Vector de comunicacion DLL -> WAM
210  double *FEntrada; // Vector de comunicacion DLL -> Matlab
211  double *FSalida; // Vector de comunicacion Matlab -> DLL
212  // TMatlab *ECU; // Objeto TMatlab para la programacion de la ECU
213  TTGV **FTGV; // Objeto para el calculo de la TGV
214  TControlFuel *FFuel; // Objeto para el calculo del Fuel
215  TEGRV *FEGRV; // Objeto para el calculo de la valvula de EGR.
216  TRegimenMotor *FRegimen; // Objeto para el calculo del Regimen del motor.
217  Tfql *Ffql; // Objeto para el calculo de las Leyes de Liberacion de Calor.
218  TRemansoMatlab **FRemansoMatlab; // Objeto para el calculo de la presion y temperatura en un deposito de remanso.
219  TCoefDescarga **FCoefDescarga; // Objeto para el calculo del coeficiente de descarga de una union a deposito/cilindro
221  *FAjusteTransCalorCil; // Objeto para el calculo de los coeficientes de ajuste de transmision de calor en admision y escape
222  TFraccionMasicaCilindro *FFraccionMasicaCilindro; // Objeto para imponer la fraccion masica a la apertura del cilindro.
224  *FControlInyeccion; // Objeto para determinar el numero de inyecciones, la presion de inyeccion y la duracion y masa inyectada en cada inyeccion.
225  TControlK **FControlK; // Objeto para calcular la variacion de K con el Re en cada CC de Perdida de Presion
226  char *FRutaTrabajo;
227 
228  // Indice que indica la posicion de cada especie en el vector de fraccion masica.
229  int FIndiceTuboN2, FIndiceTuboO2, FIndiceTuboCO2, FIndiceTuboH2O, FIndiceTuboHC, FIndiceTuboSoot, FIndiceTuboNOx,
230  FIndiceTuboCO, FIndiceTuboAireFresco, FIndiceTuboGasQuemado, FIndiceTuboEGR,
231  FIndiceTuboComb;
232  int FIndiceDepN2, FIndiceDepO2, FIndiceDepCO2, FIndiceDepH2O, FIndiceDepHC, FIndiceDepSoot, FIndiceDepNOx, FIndiceDepCO,
233  FIndiceDepAireFresco, FIndiceDepGasQuemado, FIndiceDepEGR, FIndiceDepComb;
234 
235  bool Fhayecu, Fcontroliny, Fcontrolmfcomb, Fmodcomb, Fajustbaraba, FFraccionMasicaEspeciesCil;
236  bool FCalculoK;
237  int Fngrafmat;
238  double Ftmuestreoecu, FTiempo, FTiempomuestreo, FTiempoSum;
239 
240  int Fntact;
241 
242  int Fnematlab; // N. de depositos de remanso matlab
243  int Fnumunion; // N. de uniones controladas
244 
245  // Variables para la determinacion de la correlacion utilizada en las turbinas.
246  double CoefCorrCd[2], CoefCorrRend[2];
247  // N. de turbinas.
248  int Fcontadortgv;
249  int FNumPerdidasPresion;
250 
251  /* Analisis Convergencia de la Ejecucion */
252  bool FConvergencia;
253  bool FPrimeraVez;
254 
255  double *FParametros; // Parametros para interpolacion dFQL
256 
257  double FMasaFuel;
258  double FMasaFuelDeseado;
259  double FFuelIni;
260  double FCDEGRIni;
261  double FCDEstatorIni;
262  double FCDRotorIni;
263  double FRendimientoIni;
264  double FTiempoPrevio;
265 
266  nmCalculoGamma FCalculoGamma;
267 
268  stSensorTubos *FSensorTubo;
269  stSensorDep *FSensorDep;
270  stSensorTG *FSensorTG;
271  stSensorTurbina *FSensorTurbina;
272  stSensorCil *FSensorCil;
273  stSensorVent *FSensorVent;
274  stSensorMotor *FSensorMotor;
275  stSensorUED *FSensorUED;
276 
277  // Variable para salida de resultados medios/instantaneos
278 
279  double PosicionTurbina;
280  double PosicionTurbinaSUM;
281  double SensorGastoAdmision;
282  double SensorGastoAdmisionSUM;
283  double SensorP2;
284  double SensorP2SUM;
285  double SensorP3;
286  double SensorP3SUM;
287  double SensorP4;
288  double SensorP4SUM;
289  double SensorRegimenTurbo;
290  double SensorRegimenTurboSUM;
291  double SensorRelCinematica;
292  double SensorRelCinematicaSUM;
293 
294  void PutInputdll(int i, double valor);
295 
296  TControlFuel* GetFuel();
297 
298  public:
299  // ---------------------------------------------------------------------------
300  // Recuerda que aqui se encuentran las llamadas entre wam y la dll, siempre
301  // que cambies algo aqui deberas recompilar el wam y modificar las llamadas
302  // ---------------------------------------------------------------------------
303  // Variables
304  bool getajustbaraba() {
305  return Fajustbaraba;
306  }
307  ;
308 
309  // Funciones
310  double GetOutput_dll(int i);
311 
312  bool getcontrolmfcomb() {
313  return Fcontrolmfcomb;
314  }
315  ;
316 
317  int getngrafmat() {
318  return Fngrafmat;
319  }
320  ;
321 
322  bool getmodcomb() {
323  return Fmodcomb;
324  }
325  ;
326 
327  bool getcontroliny() {
328  return Fcontroliny;
329  }
330  ;
331 
332  bool getFraccionMasicaEspeciesCil() {
333  return FFraccionMasicaEspeciesCil;
334  }
335  ;
336 
337  bool getControlK() {
338  return FCalculoK;
339  }
340  ;
341 
342  TRemansoMatlab* GetTRemansoMatlab(int i);
343 
344  TCoefDescarga* GetTCoefDescarga(int i);
345 
346  TControlFuel* getFuel() {
347  return GetFuel();
348  }
349  ;
350 
351  bool getConvergencia() {
352  return FConvergencia;
353  }
354  ;
355 
356  // Funciones
357  TCalculoExtern();
358 
359  ~TCalculoExtern();
360 
361  void LlamadaECU(double DeltaT, TBloqueMotor **Engine);
362 
363  void FinECU();
364 
365  // void LeeFicherosDLL(FILE *fich,int controlvalv,int nematlab,
366  // int ncilin,int nunmat,int CountVGT);
367 
368  void LeeFicherosDLL(const char *FileWAM, fpos_t &filepos, int controlvalv, int nematlab, int ncilin, int nunmat,
369  int CountVGT, int numespecies, int NumeroPerdidasPresion);
370 
371  // Funciones para la lectura de sensores
372  void Lee_Sens_Tubos(const char *FileWAM, fpos_t &filepos, TTubo **Pipe, nmTipoCalculoEspecies SpeciesModel,
373  bool ThereIsEGR, bool HayCombustible);
374 
375  void Lee_Sens_Dep(const char *FileWAM, fpos_t &filepos, TDeposito **Plenum, nmTipoCalculoEspecies SpeciesModel,
376  bool ThereIsEGR, bool HayCombustible);
377 
378  void Lee_Sens_TG(const char *FileWAM, fpos_t &filepos, TEjeTurbogrupo **Axis);
379 
380  void Lee_Sens_Turbina(const char *FileWAM, fpos_t &filepos, TTurbina **Turbine);
381 
382  void Lee_Sens_Cil(const char *FileWAM, fpos_t &filepos, TBloqueMotor **Engine);
383 
384  void Lee_Sens_Vent(const char *FileWAM, fpos_t &filepos, TVenturi **Venturi);
385 
386  void Lee_Sens_Motor(const char *FileWAM, fpos_t &filepos, double CrankAngle, double ene, double AcumulatedTime);
387 
388  void Lee_Sens_UED(const char *FileWAM, fpos_t &filepos, TCondicionContorno **BC);
389 
390  void Lectura_Datos_Adicionales(const char *FileWAM, fpos_t &filepos);
391 
392  void IniciaEntradaDLL();
393 
394  // Funciones para el calculo de sensores
395  void Calculo_Sensores_Tubos(TTubo **Pipe, double deltaT);
396 
397  void Calculo_Sensores_Deposito(TDeposito **Plenum, double deltaT);
398 
399  void Calculo_Sensores_TG(double deltaT, TEjeTurbogrupo **Axis);
400 
401  void Calculo_Sensores_Turbina(double deltaT, TTurbina **Turbine);
402 
403  void Calculo_Sensores_Cilindro(double deltaT, TBloqueMotor **Engine);
404 
405  void Calculo_Sensores_Venturi(double deltaT, TVenturi **Venturi);
406 
407  void Calculo_Sensores_Motor(double deltaT, TBloqueMotor **Engine, double AcumulatedTime);
408 
409  void Calculo_Sensores_UED(double deltaT, TCondicionContorno **BC);
410 
411  // Funcion de interpolacion
412  double xit_(double vizq, double vder, double axid, double xif);
413 
414  // Funciones para graficar
415  void InicializaMedias();
416 
417  void AcumulaMedias(double DeltaT);
418 
419  void CalculaMedias();
420 
421  void ImprimeCabeceraMedias(stringstream& medoutput);
422 
423  void ImprimeGraficosMedias(stringstream& medoutput);
424 
425  void ImprimeCabeceraInstantaneas(stringstream& insoutput);
426 
427  void ImprimeGraficosInstantaneas(stringstream& insoutput);
428 
429  void ObtenerRutaTrabajo(const char *origin);
430 
431 };
432 
433 // ---------------------------------------------------------------------------
434 #endif
435 
stSensorCil
Definition: TCalculoExtern.h:146
TEjeTurbogrupo
Definition: TEjeTurbogrupo.h:47
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
stSensorDep
Definition: TCalculoExtern.h:113
TEGRV
Definition: TEGRV.h:46
TControlFuel
Definition: TControlFuel.h:42
TControlInyeccion
Definition: TControlInyeccion.h:42
Constantes.h
TTurbina
Definition: TTurbina.h:41
TControlK
Definition: TControlK.h:44
TCalculoExtern
Definition: TCalculoExtern.h:190
TAjusteTransCalorCil
Definition: TAjusteTransCalorCil.h:44
TCondicionContorno
Definition: TCondicionContorno.h:54
TDeposito
Definition: TDeposito.h:44
TCoefDescarga
Definition: TCoefDescarga.h:42
stSensorTubos
Definition: TCalculoExtern.h:99
stSensorMotor
Definition: TCalculoExtern.h:168
TTGV
Definition: TTGV.h:40
TFraccionMasicaCilindro
Definition: TFraccionMasicaCilindro.h:40
TRegimenMotor
Definition: TRegimenMotor.h:39
TVenturi
Definition: TVenturi.h:33
TBloqueMotor
Definition: TBloqueMotor.h:43
TCCDeposito
Definition: TCCDeposito.h:40
TRemansoMatlab
Definition: TRemansoMatlab.h:43
stSensorVent
Definition: TCalculoExtern.h:157
stSensorTurbina
Definition: TCalculoExtern.h:135
stSensorTG
Definition: TCalculoExtern.h:124
stSensorUED
Definition: TCalculoExtern.h:179
Tfql
Definition: Tfql.h:51