OpenWAM
TOpenWAM.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 #ifndef TOpenWAMH
29 #define TOpenWAMH
30 
31 #ifdef __BORLANDC__
32 #include <vcl.h>
33 #endif
34 #include <cstdio>
35 #include <cstdlib>
36 #include <cstring>
37 #include <string>
38 #include <regex>
39 #include <fstream>
40 #pragma hdrstop
41 #include "Globales.h"
42 
43 #include "TTimeControl.h"
44 
45 // ENGINE BLOCK AND CYLINDERS
46 #include "TBloqueMotor.h"
47 #include "TCilindro4T.h"
48 
49 // COMPRESSOR
50 #include "TCompresorDep.h"
51 #include "TCompTubDep.h"
52 #include "TCompTubos.h"
53 
54 // EXTERNAL CALCULATIONS
55 #include "TCalculoExtern.h"
56 #include "TRemansoMatlab.h"
57 #include "TCoefDescarga.h"
58 #include "TControlFuel.h"
59 
60 // VALVES
61 #include "TCDExterno.h"
62 #include "TEstatorTurbina.h"
63 #include "TRotorTurbina.h"
64 #include "TWasteGate.h"
65 #include "TValvulaContr.h"
66 #include "TDiscoRotativo.h"
67 #include "TLumbrera.h"
68 #include "TCDFijo.h"
69 #include "TValvula4T.h"
70 #include "TLamina.h"
71 #include "TMariposa.h"
72 
73 // PIPES
74 #include "TTubo.h"
75 
76 // PLENUMS
77 #include "TDepVolVariable.h"
78 #include "TDepVolCte.h"
79 #include "TTurbinaSimple.h"
80 #include "TTurbinaTwin.h"
81 #include "TVenturi.h"
82 #include "TUnionDireccional.h"
83 
84 // BOUNDARY CONDITIONS
85 #include "TCCDescargaExtremoAbierto.h"
86 #include "TCCExtremoAnecoico.h"
87 #include "TCCExtremoCerrado.h"
88 #include "TCCPulso.h"
89 #include "TCCCilindro.h"
90 #include "TCCUnionEntreTubos.h"
91 #include "TCCPerdidadePresion.h"
92 #include "TCCDeposito.h"
93 #include "TCCRamificacion.h"
94 #include "TCCExtremoInyeccion.h"
95 #include "TCCEntradaCompresor.h"
96 #include "TCCUnionEntreDepositos.h"
97 #include "TCCCompresorVolumetrico.h"
98 #include "TCCCompresor.h"
99 #include "TCCPreVble.h"
100 #include "TCFDConnection.h"
101 #include "TCCExternalConnection.h"
102 #include "TCCExternalConnectionVol.h"
103 
104 // TURBOCHARGER AXIS
105 #include "TEjeTurbogrupo.h"
106 
107 // DIESEL PARTICULATE FILTER
108 #ifdef ParticulateFilter
109 #include "TDPF.h"
110 #include "TCanalDPF.h"
111 #endif
112 
113 // CONCENTRIC 1D ELEMENTS
114 #ifdef ConcentricElement
115 #include "TConcentricoTubos.h"
116 #include "TConcentricoDPF.h"
117 #endif
118 
119 // CONTROL DEVICES
120 #include "TSensor.h"
121 #include "TPIDController.h"
122 #include "TTable1D.h"
123 #include "TDecisor.h"
124 #include "TGain.h"
125 
126 // OUTPUT RESULTS
127 #include "TOutputResults.h"
128 #define completo 1
129 
130 /* ! \def gestorcom
131  Allow the communication with WAMer
132  */
133 
134 #include <sys/timeb.h>
135 
136 #ifdef __BORLANDC__
137 #define gestorcom true
138 #define graphicalout true
139 #else
140 //#define gestorcom 0
141 //#define graphicalout 0
142 #endif
143 
144 #ifdef gestorcom
145 #include "TCGestorWAM.h"
146 #endif
147 
148 class TOpenWAM {
149  private:
150 
151 #ifdef gestorcom
152 
153  TCGestorWAM *GestorWAM;
154 #endif
155 
156  std::string tzstr;
157  struct timeb begining, final, current;
158 
159  stRun Run;
160 
161  stDatosTGV *DatosTGV;
162  std::string fileinput;
163 
164  FILE *FileInput;
165  // !< Pointers to input and output files.
166  FILE *fc; // !< Pointers to input and output files.
167 
168  //char fileinput[8];
169 
170  TBloqueMotor** Engine;
171  TCompresor** Compressor;
172  TCalculoExtern* EXTERN;
173  TEjeTurbogrupo** Axis;
174 
175  // ! ARRAY OF TYPES OF VALVES
176  TTipoValvula** TypeOfValve;
177 
178  // ! POINTERS ARRAY TO VALVES TYPE TURBINE STATOR
179  TEstatorTurbina*** StatorTurbine;
180  // ! POINTERS ARRAY TO VALVES TYPE TURBINE ROTOR
181  TRotorTurbina** RotorTurbine;
182  // ! POINTERS ARRAY TO EXTERNAL CONNECTIONS
183  TTipoValvula** CCCalcExtern;
184  TTipoValvula** BCButerflyValve;
185 
186  // ! ARRAY OF PIPES
187  TTubo** Pipe;
188 
189  // ! ARRAY OF CONCENTRIC ELEMENTS
190 #ifdef ConcentricElement
191  TConcentrico** Concentric;
192 #endif
193 
194  // ! ARRAY OF DPFs
195 #ifdef ParticulateFilter
196  TDPF** DPF;
197 #endif
198 
199  // ! ARRAYS OF PLENUMS
200  TDeposito** Plenum;
201  TTurbina** Turbine;
202  TVenturi** Venturi;
203 
204  // ! ARRAYS OF BOUNDARY CONDITIONS
205  TCondicionContorno** BC;
206  TCondicionContorno** BCIntakeValve;
207  TCondicionContorno** BCExhaustValve;
208  TCondicionContorno** BCReedValve;
209  TCondicionContorno** BCWasteGate;
210 
211  TCCExternalConnection** BCExtConnection;
212  TCCExternalConnectionVol** BCExtConnectionVol;
213 
214  TCCCompresorVolumetrico** VolumetricCompressor;
215  TCCDescargaExtremoAbierto** MatlabDischarge;
216  TCCExtremoInyeccion** InjectionEnd;
217  TCCPerdidadePresion **PerdidaPresion;
218 
219  // !OUTPUT OBJECT
220  TOutputResults* Output;
221 
222  // ! CONTROL PARAMETERS
223  bool FirstIteration;
224  int JStepMax;
225  int JStepMaxDPF;
226  int JCurrent;
227  int JCurrentDPF;
228  double TimeEndStep;
229  double DeltaTPlenums;
230  bool Independent;
231  bool Is_EndStep;
232  bool PipeStepMax;
233  bool DPFStepMax;
234  bool TimeMinPipe;
235  bool TimeMinDPF;
236 
237  double CrankAngle;
238  double AcumulatedTime;
239  double Theta;
240  double Theta0;
241 
242  // ! SPECIES MODEL PARAMETERS
243 
244  stEspecies* SpeciesName;
245  int SpeciesNumber;
246 
247  nmTipoCalculoEspecies SpeciesModel;
248 
249  double* AtmosphericComposition;
250 
251  nmTipoCombustible FuelType;
252  nmCalculoGamma GammaCalculation;
253 
254  // ! GENERAL PARAMETERS
255  nmTipoMotor EngineType;
256 
257  nmTipoModelado SimulationType;
258  bool ThereIsEGR;
259  bool ThereIsFuel;
260  int OpenWAMVersion;
261  int Steps;
262  int Increment;
263  float Percentage;
264  double ThetaIni;
265  double ene;
266  double agincr;
267  double thmax;
268  double grmax;
269  double SimulationDuration;
270  int CyclesWithoutThemalInertia;
271  double AmbientPressure;
272  double AmbientTemperature;
273  bool ConvergenceFirstTime;
274 
275  // ! DOES THE ENGINE BLOCK EXIST?
276  bool EngineBlock;
277 
278  // ! NUMBER OF PIPES
279  int NumberOfPipes;
280 
281  // ! NUMBER OF CONCENTRIC ELEMENTS
282  int NumberOfConcentrics;
283 
284  // ! NUMBER OF DIESEL PARTICULATE FILTERS
285  int NumberOfDPF;
286 
287  // ! VALVES PARAMETERS
288  int NumberOfValves;
289  int NumberOfReedValves;
290  int NumberOfWasteGates;
291  int NumberOfExternalCalculatedValves;
292 
293  // ! CONNECTIONS PARAMETERS
294  int NumberOfConnections;
295  int NumberOfVolumetricCompressors;
296  int NumberOfExhaustValves;
297  int NumberOfIntakeValves;
298  int NumberOfCompressorsConnections;
299  int NumberOfInjectionEnds;
300  int NumberOfConectionsBetweenPlenums;
301  int NumberOfButerflyValves;
302 
303  // ! NUMBER OF PLENUMS
304  int NumberOfPlenums;
305 
306  // ! NUMBER OF VENTURIS
307  int NumberOfVenturis;
308 
309  // ! NUMBER OF DIRECTIONAL JUNCIONS
310  int NumberOfDirectionalJunctions;
311 
312  // ! PARAMETER FOR THE CONTROL UNIT
313  int NumberOfSensors;
314 
315  TSensor **Sensor;
316 
317  int NumberOfControllers;
318 
319  TController **Controller;
320 
321  // ! EXTERNAL CALCULATION PARAMETERS
322  bool ThereIsDLL;
323  int controlvalv;
324  int nematlab;
325 
326  // ! TURBINE PARAMETERS
327  int NumberOfTurbines;
328  int CountVGT;
329 
330  // ! NUMBER OF TURBOCHARGER AXIS
331  int NumberOfAxis;
332 
333  // ! NUMBER OF COMPRESSORS
334  int NumberOfCompressors;
335 
336  // ! NUMBER OF PRESSURE LOSSES
337  int NumTCCPerdidaPresion;
338 
339  int fi_num_threads;
340 
349  void InitFlowIndependentNumThreads();
350 
351  void CleanLabelsX();
352 
353  void CleanLabels();
354 
355  void ReadGeneralData();
356 
357  void ReadEngine();
358 
359  void ReadPipes();
360 
361  void ReadDPF();
362 
363  void ReadConcentric();
364 
365  void ReadValves();
366 
367  void ReadPlenums();
368 
369  void ReadCompressors();
370 
371  void ReadConnections();
372 
373  void ReadTurbochargerAxis();
374 
375  void ReadSensors();
376 
377  void ReadControllers();
378 
379  void ReadOutput(char* FileName);
380 
381  void ReadDataDLL();
382 
383  void RunningControl();
384 
385  void InitializeRunningAngles();
386 
387  void AllocateVGTData();
388 
389  void CalculateNewHeatPositions();
390 
391  void CalculateDistance(int NodoOrigen, int NodoFin, double Longitud, int NumberOfPlenums, int NumberOfPipes,
392  int NumberOfConnections, TTubo **Pipe, TCondicionContorno **BC);
393 
394  int SelectPipe(TTubo **Pipe, int NumberOfPipes, int nodo1, int nodo2);
395 
396  void MethodStability();
397 
398  void SearchMinimumTimeStep();
399 
400  void StudyInflowOutflowMass();
401 
402  void SearchMinimumTime(int LNumDepInicial, double* LTMinimo, TDeposito **LPlenum);
403 
404  void SearchMinimumTimeGroup(double *LTMinimo, int LNumDeposito, TDeposito **LPlenum);
405 
406  void FixTimeStep();
407 
408  void FixTimeStepExternal(double deltat);
409 
410  void RecalculateStability();
411 
412  void SolveAdjacentElements(int PipeEnd, double TiempoActual);
413 
414  void SolveBranch(int NumDeposito, double TiempoActual);
415 
416  void UpdateEngine();
417 
418  void SolveRoadLoadModel();
419 
420  void RecalculateStabilitySolver();
421 
422  void UpdateTurbocharger();
423 
424  void comunica_wam_dll();
425 
426  void ModificacionControlEjecucion();
427 
428  void Actuadores();
429 
430  public:
431 
432  TOpenWAM();
433 
434  ~TOpenWAM();
435 
436  void ReadInputData(char* FileName);
437 
438  void InitializeParameters();
439 
440  void ConnectFlowElements();
441 
442  void ConnectControlElements();
443 
444  void InitialHeatTransferParameters();
445 
446  void DetermineTimeStepIndependent();
447 
448  void DetermineTimeStepCommon();
449 
450  void DetermineTimeStep(double t);
451 
452  void InitializeOutput();
453 
454  void CalculateFlowIndependent();
455 
456  void CalculateFlowCommon();
457 
458  void ManageOutput();
459 
460  bool CalculationEnd();
461 
462  void Progress();
463 
464  void ProgressBegin();
465 
466  void ProgressEnd();
467 
468  void NewEngineCycle();
469 
470  void GeneralOutput();
471 
472  bool IsIndependent() {
473  return Independent;
474  }
475  ;
476 
477  void UpdateExternalBoundary(int i, double U0, double U1, double T0, double T1, double P0, double P1, double t);
478 
479  void UpdateExternalBoundary(int i, double U0, double T0, double P0, double t);
480 
481  void InitiateExternalBoundary(int i, double D0, double D1, double dX);
482 
483  void InitiateExternalBoundary(int i, double D0, double dX);
484 
485  void LoadNewData(int i, double* p, double* T, double* u);
486 
487  bool GetIs_EndStep();
488 
489 };
490 // ---------------------------------------------------------------------------
491 #endif
stEspecies
Definition: Globales.h:297
TRotorTurbina
Definition: TRotorTurbina.h:48
TEjeTurbogrupo
Definition: TEjeTurbogrupo.h:47
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
TCCDescargaExtremoAbierto
Definition: TCCDescargaExtremoAbierto.h:43
TController
Definition: TController.h:37
TTurbina
Definition: TTurbina.h:41
TCCExtremoInyeccion
Definition: TCCExtremoInyeccion.h:37
TCCExternalConnection
Definition: TCCExternalConnection.h:9
TTipoValvula
Definition: TTipoValvula.h:53
TOpenWAM
Definition: TOpenWAM.h:148
TCCCompresorVolumetrico
Definition: TCCCompresorVolumetrico.h:37
TDPF
Definition: TDPF.h:45
TCalculoExtern
Definition: TCalculoExtern.h:190
TCompresor
Definition: TCompresor.h:47
TCondicionContorno
Definition: TCondicionContorno.h:54
TDeposito
Definition: TDeposito.h:44
stDatosTGV
Definition: Globales.h:336
TVenturi
Definition: TVenturi.h:33
TTubo.h
TBloqueMotor
Definition: TBloqueMotor.h:43
TEstatorTurbina
Definition: TEstatorTurbina.h:47
stRun
Definition: Globales.h:354
TSensor
Definition: TSensor.h:42
TCCPerdidadePresion
Definition: TCCPerdidadePresion.h:44
TConcentrico
Definition: TConcentrico.h:45
TCCExternalConnectionVol
Definition: TCCExternalConnectionVol.h:9
TCGestorWAM
Definition: TCGestorWAM.h:42
TOutputResults
Definition: TOutputResults.h:34