OpenWAM
TOpenWAM.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 #pragma hdrstop
29 
30 #include "TOpenWAM.h"
31 #ifdef _WIN32
32 #include <Windows.h>
33 #endif
34 #include "Version.h"
35 
36 TOpenWAM::TOpenWAM() {
37 
38 #ifdef gestorcom
39  GestorWAM = NULL;
40  GestorWAM = new TCGestorWAM();
41  GestorWAM->Init();
42 #endif
43  tzstr = "TZ=PST8PDT";
44 
45  DatosTGV = NULL;
46  fc = NULL;
47 
48  Engine = NULL;
49  Compressor = NULL;
50  EXTERN = NULL;
51  Axis = NULL;
52 
53  // ! ARRAY OF TYPES OF VALVES
54  TypeOfValve = NULL;
55 
56  // ! POINTERS ARRAY TO VALVES TYPE TURBINE STATOR
57  StatorTurbine = NULL;
58  // ! POINTERS ARRAY TO VALVES TYPE TURBINE ROTOR
59  RotorTurbine = NULL;
60  // ! POINTERS ARRAY TO EXTERNAL CONNECTIONS
61  CCCalcExtern = NULL;
62  BCButerflyValve = NULL;
63 
64  // ! ARRAY OF PIPES
65  Pipe = NULL;
66 
67  // ! ARRAY OF CONCENTRIC ELEMENTS
68 #ifdef ConcentricElement
69  Concentric = NULL;
70 #endif
71 
72  // ! ARRAY OF DPFs
73 #ifdef ParticulateFilter
74  DPF = NULL;
75 #endif
76 
77  // ! ARRAYS OF PLENUMS
78  Plenum = NULL;
79  Turbine = NULL;
80  Venturi = NULL;
81 
82  // ! ARRAYS OF BOUNDARY CONDITIONS
83  BC = NULL;
84  BCIntakeValve = NULL;
85  BCExhaustValve = NULL;
86  BCReedValve = NULL;
87  BCWasteGate = NULL;
88 
89  VolumetricCompressor = NULL;
90  MatlabDischarge = NULL;
91  InjectionEnd = NULL;
92  PerdidaPresion = NULL;
93 
94  // !OUTPUT OBJECT
95  Output = NULL;
96 
97  CrankAngle = 0.;
98  AcumulatedTime = 0.;
99  Theta = 0.;
100  Theta0 = 0.;
101 
102  // ! SPECIES MODEL PARAMETERS
103 
104  SpeciesName = NULL;
105  SpeciesNumber = 0;
106 
107  AtmosphericComposition = NULL;
108 
109  // ! GENERAL PARAMETERS
110  SimulationType = nmEstacionario;
111  ThereIsEGR = false;
112  ThereIsFuel = false;
113  OpenWAMVersion = 0;
114  Steps = 0;
115  Increment = 0;
116  Percentage = 0;
117  ThetaIni = 0.;
118  ene = 0.;
119  agincr = 0.;
120  thmax = 0.;
121  grmax = 0.;
122  SimulationDuration = 0.;
123  CyclesWithoutThemalInertia = 0;
124  AmbientPressure = 0.;
125  AmbientTemperature = 0.;
126  ConvergenceFirstTime = false;
127 
128  Independent = true;
129  PipeStepMax = false;
130  DPFStepMax = false;
131  TimeMinPipe = false;
132  TimeMinDPF = false;
133 
134  // ! DOES THE ENGINE BLOCK EXIST?
135  EngineBlock = false;
136 
137  // ! NUMBER OF PIPES
138  NumberOfPipes = 0;
139 
140  // ! NUMBER OF CONCENTRIC ELEMENTS
141  NumberOfConcentrics = 0;
142 
143  // ! NUMBER OF DIESEL PARTICULATE FILTERS
144  NumberOfDPF = 0;
145 
146  // ! VALVES PARAMETERS
147  NumberOfValves = 0;
148  NumberOfReedValves = 0;
149  NumberOfWasteGates = 0;
150  NumberOfExternalCalculatedValves = 0;
151 
152  // ! CONNECTIONS PARAMETERS
153  NumberOfConnections = 0;
154  NumberOfVolumetricCompressors = 0;
155  NumberOfExhaustValves = 0;
156  NumberOfIntakeValves = 0;
157  NumberOfCompressorsConnections = 0;
158  NumberOfInjectionEnds = 0;
159  NumberOfConectionsBetweenPlenums = 0;
160  NumberOfButerflyValves = 0;
161 
162  // ! NUMBER OF PLENUMS
163  NumberOfPlenums = 0;
164 
165  // ! NUMBER OF VENTURIS
166  NumberOfVenturis = 0;
167 
168  // ! NUMBER OF DIRECTIONAL JUNCIONS
169  NumberOfDirectionalJunctions = 0;
170 
171  // ! PARAMETER FOR THE CONTROL UNIT
172  NumberOfSensors = 0;
173 
174  Sensor = NULL;
175 
176  NumberOfControllers = 0;
177 
178  Controller = NULL;
179 
180  // ! EXTERNAL CALCULATION PARAMETERS
181  ThereIsDLL = false;
182  controlvalv = 0;
183  nematlab = 0;
184 
185  // ! TURBINE PARAMETERS
186  NumberOfTurbines = 0;
187  CountVGT = 0;
188 
189  // ! NUMBER OF TURBOCHARGER AXIS
190  NumberOfAxis = 0;
191 
192  // ! NUMBER OF COMPRESSORS
193  NumberOfCompressors = 0;
194 
195  Steps = 0;
196  TimeEndStep = 0.;
197 
198  InitFlowIndependentNumThreads();
199 }
200 
201 TOpenWAM::~TOpenWAM() {
202 #ifdef completo
203  if(ThereIsDLL) {
204  EXTERN->FinECU();
205  }
206 #endif
207 
208  printf("INFO: *** CMT : SIMULATION FINISHED CORRECTLY ***\n");
209 
210 #ifdef gestorcom
211  if(GestorWAM != NULL)
212  GestorWAM->ProcesoTranscurrido(100);
213 #endif
214 
215  if(EXTERN != NULL)
216  delete EXTERN;
217 
218  // Liberacion memoria dinamica Depositos.
219  if(NumberOfPlenums > 0 && Plenum != NULL) {
220  for(int i = 0; i < NumberOfPlenums; i++)
221  delete Plenum[i];
222  delete[] Plenum;
223  }
224 
225  if(NumberOfTurbines > 0 && Turbine != NULL)
226  delete[] Turbine;
227 
228  if(NumberOfVenturis > 0 && Venturi != NULL)
229  delete[] Venturi;
230 
231  // Liberacion memoria dinamica Compressor.
232  if(NumberOfCompressors > 0 && Compressor != NULL) {
233  for(int i = 0; i < NumberOfCompressors; i++)
234  delete Compressor[i];
235  delete[] Compressor;
236  }
237 
238  // Liberacion memoria dinamica Tubos.
239  if(NumberOfPipes > 0 && Pipe != NULL) {
240  for(int i = 0; i < NumberOfPipes; i++)
241  delete Pipe[i];
242  delete[] Pipe;
243  }
244 
245  // Liberacion memoria dinamica Concentricos.
246 #ifdef ConcentricElement
247  if(NumberOfConcentrics > 0 && Concentric != NULL) {
248  for(int i = 0; i < NumberOfConcentrics; i++)
249  delete Concentric[i];
250  delete[]Concentric;
251  }
252 #endif
253 
254  // Liberacion memoria dinamica DPFs.
255 #ifdef ParticulateFilter
256  if(NumberOfDPF > 0 && DPF != NULL) {
257  for(int i = 0; i < NumberOfDPF; i++)
258  delete DPF[i];
259  delete[]DPF;
260  }
261 #endif
262 
263  // Liberacion memoria dinamica Condiciones de Contorno.
264  if(NumberOfConnections > 0 && *BC != NULL) {
265  for(int i = 0; i < NumberOfConnections; i++)
266  delete BC[i];
267  delete[] BC;
268  }
269 
270  // Liberacion memoria dinamica Axis de Turbogrupo.
271  if(NumberOfAxis > 0 && Axis != NULL) {
272  for(int i = 0; i < NumberOfAxis; i++)
273  delete Axis[i];
274  delete[] Axis;
275  }
276 
277  // Liberacion memoria dinamica Engine.
278  if(EngineBlock && Engine != NULL) {
279  delete Engine[0];
280  delete[] Engine;
281  }
282 
283  if(NumberOfIntakeValves > 0 && BCIntakeValve != NULL)
284  delete[] BCIntakeValve;
285 
286  if(NumberOfExhaustValves > 0 && BCExhaustValve != NULL)
287  delete[] BCExhaustValve;
288 
289  if(NumberOfWasteGates > 0 && BCWasteGate != NULL)
290  delete[] BCWasteGate;
291 
292  if(NumberOfReedValves > 0 && BCReedValve != NULL)
293  delete[] BCReedValve;
294 
295  if(NumberOfVolumetricCompressors > 0 && VolumetricCompressor != NULL)
296  delete[] VolumetricCompressor;
297 
298  if(nematlab > 0 && MatlabDischarge != NULL)
299  delete[] MatlabDischarge;
300 
301  if(NumberOfInjectionEnds > 0 && InjectionEnd != NULL)
302  delete[] InjectionEnd;
303 
304  if(NumTCCPerdidaPresion > 0 && PerdidaPresion != NULL)
305  delete[] PerdidaPresion;
306 
307  if(SpeciesName != NULL)
308  delete[] SpeciesName;
309 
310  if(AtmosphericComposition != NULL)
311  delete[] AtmosphericComposition;
312 
313  if(DatosTGV != NULL)
314  delete[] DatosTGV;
315 
316  if(TypeOfValve != NULL) {
317  for(int i = 0; i < NumberOfValves; i++) {
318  delete TypeOfValve[i];
319  }
320  delete[] TypeOfValve;
321  }
322 
323  if(StatorTurbine != NULL) {
324  for(int i = 0; i < NumberOfTurbines; i++) {
325  delete[] StatorTurbine[i];
326  }
327  delete[] StatorTurbine;
328  }
329 
330  if(RotorTurbine != NULL)
331  delete[] RotorTurbine;
332 
333  if(CCCalcExtern != NULL)
334  delete[] CCCalcExtern;
335 
336  if(BCButerflyValve != NULL)
337  delete[] BCButerflyValve;
338 
339 #ifdef gestorcom
340  if(GestorWAM != NULL) {
341  GestorWAM->NuevoMensaje("Simulation finished correctly.");
342  GestorWAM->Terminar();
343  delete GestorWAM;
344  }
345 #endif
346 
347 }
348 
349 void TOpenWAM::CleanLabelsX() {
350 
351  FILE *fetmp;
352 
353  //strcpy(fileinput.c_str(), "tmp.wam");
354 
355  fileinput = "tmp.wam";
356 
357  fetmp = fopen(fileinput.c_str(), "w");
358 
359  int cc = 0, cc2 = 0;
360  bool label;
361  char line[800];
362  char linenew[800];
363  while(!feof(FileInput)) {
364  fgets(line, 800, FileInput);
365  cc = 0;
366  cc2 = 0;
367  label = false;
368  while(line[cc] == ' ' || line[cc] == '\t') {
369  cc++;
370  }
371  while(line[cc] != '\n' && cc < 800) {
372  if(label) {
373  if(line[cc] == '>') {
374  label = false;
375  }
376  cc++;
377  } else {
378  if(line[cc] == '<') {
379  label = true;
380  } else {
381  linenew[cc2] = line[cc];
382  cc2++;
383  }
384  cc++;
385  }
386  }
387  linenew[cc2] = '\n';
388  for(int i = cc2 + 1; i < 800; ++i) {
389  linenew[i] = '\0';
390  }
391  if(linenew[0] != '\n') {
392  fputs(linenew, fetmp);
393  }
394  }
395 
396  fclose(fetmp);
397  fclose(FileInput);
398 
399 }
400 
401 void TOpenWAM::CleanLabels() {
402 
403  std::regex labelregex("<.*>");
404  std::regex blregex("^[:s:]*\\r$");
405  std::regex blregex2("^[:s:]*$");
406 
407  ifstream sFileInput;
408  ofstream sFileOutput;
409  string strline, strline_out;
410 
411  sFileInput.open(fileinput.c_str());
412  fileinput.append(".tmp");
413  sFileOutput.open(fileinput.c_str());
414 
415  while(!sFileInput.eof()) {
416  std::getline(sFileInput, strline);
417  strline_out = std::regex_replace(strline, labelregex, "");
418  if(std::regex_match(strline_out, blregex) == false && std::regex_match(strline_out, blregex2) == false) {
419  sFileOutput << strline_out << std::endl;
420  }
421  }
422  sFileInput.close();
423  sFileOutput.close();
424 }
425 
426 void TOpenWAM::ReadInputData(char* FileName) {
427 
428  fpos_t fileposition;
429 
430  FileInput = fopen(FileName, "r");
431  if(FileInput == NULL) {
432  printf("ERROR: The input file do not exist.\n");
433 #ifdef gestorcom
434  if(GestorWAM != NULL) {
435  GestorWAM->NuevoMensaje("The input file do not exist.");
436  GestorWAM->Terminar();
437  delete GestorWAM;
438  }
439 #endif
440  exit(EXIT_FAILURE);
441  }
442 
443 #ifdef _WIN32
444 
445  fclose(FileInput);
446 
447  fileinput = FileName;
448 
449  CleanLabels();
450 
451 #else
452  CleanLabelsX();
453 #endif
454 
455  FileInput = fopen(fileinput.c_str(), "r");
456  if(!FileInput) {
457  std::perror("File opening failed: ");
458  exit(EXIT_FAILURE);
459  }
460 
461 #ifdef gestorcom
462  if(GestorWAM != NULL)
463  GestorWAM->NuevoMensaje("Reading input data.");
464 #endif
465  // -----------------------------------------------------------------------------
466  // -----------------------------------------------------------------------------
467 
468  std::cout << "=======================" << std::endl;
469  std::cout << " OpenWAM " << VERSION_PRINT << std::endl;
470  std::cout << "=======================" << std::endl << std::endl;
471 
472  std::cout << "THE MODEL IS READING THE INPUT DATA" << std::endl << std::endl;
473 
474  // -----------------------------------------------------------------------------
475  // -----------------------------------------------------------------------------
476 
477  fscanf(FileInput, "%d", &OpenWAMVersion);
478  if(OpenWAMVersion != vers) {
479  printf("ERROR: THE WAM VERSION IS NOT CORRECT FOR THESE INPUT DATA\n\n");
480  printf(" OpenWAM version: %d", vers);
481  printf(" File version: %d", OpenWAMVersion);
482  exit(1);
483  }
484  int ind = 0;
485  fscanf(FileInput, "%d ", &ind);
486  ind == 0 ? Independent = false : Independent = true;
487 
488  ReadGeneralData();
489 
490  ReadEngine();
491 
492  ReadPipes();
493 
494 #ifdef ParticulateFilter
495  ReadDPF();
496 #endif
497 
498 #ifdef ConcentricElement
499  ReadConcentric();
500 #endif
501 
502  ReadValves();
503 
504  ReadPlenums();
505 
506  ReadCompressors();
507 
508  ReadConnections();
509 
510  ReadTurbochargerAxis();
511 
512  ReadSensors();
513 
514  ReadControllers();
515 
516  ReadOutput(FileName);
517 
518  fgetpos(FileInput, &fileposition);
519  fclose(FileInput);
520 
521  for(int i = 0; i < NumberOfConnections; i++) {
522  if(BC[i]->getTipoCC() == nmCompresor) {
523  dynamic_cast<TCCCompresor*>(BC[i])->ReadCompressorData(fileinput.c_str(), fileposition, Compressor);
524  }
525  }
526 
527  FileInput = fopen(fileinput.c_str(), "r");
528  fsetpos(FileInput, &fileposition);
529 
530  int dll = 0;
531  fscanf(FileInput, "%d", &dll);
532  dll == 0 ? ThereIsDLL = false : ThereIsDLL = true;
533  if(ThereIsDLL) {
534  EXTERN = new TCalculoExtern();
535 
536  ReadDataDLL();
537  }
538  printf("INFO: The input file data has been readed correctly\n\n");
539 #ifdef gestorcom
540  if(GestorWAM != NULL)
541  GestorWAM->NuevoMensaje("Performing preliminar calculations...");
542 #endif
543 
544  fclose(FileInput);
545  if(remove(fileinput.c_str()) != 0)
546  perror("WARNING: Error deleting file\n");
547  else
548  puts("INFO: File successfully deleted\n");
549 }
550 
551 void TOpenWAM::ReadDataDLL() {
552  try {
553  fpos_t filepos;
554  fgetpos(FileInput, &filepos);
555  fclose(FileInput);
556 
557  if(Engine != NULL) {
558  EXTERN->LeeFicherosDLL(fileinput.c_str(), filepos, controlvalv, nematlab, Engine[0]->getGeometria().NCilin,
559  NumberOfExternalCalculatedValves, CountVGT, SpeciesNumber,
560  NumTCCPerdidaPresion);
561  } else {
562  EXTERN->LeeFicherosDLL(fileinput.c_str(), filepos, controlvalv, nematlab, 0, NumberOfExternalCalculatedValves, CountVGT,
563  SpeciesNumber, NumTCCPerdidaPresion);
564  }
565  if(Pipe != NULL)
566  EXTERN->Lee_Sens_Tubos(fileinput.c_str(), filepos, Pipe, SpeciesModel, ThereIsEGR, ThereIsFuel);
567  if(Plenum != NULL)
568  EXTERN->Lee_Sens_Dep(fileinput.c_str(), filepos, Plenum, SpeciesModel, ThereIsEGR, ThereIsFuel);
569  if(Axis != NULL)
570  EXTERN->Lee_Sens_TG(fileinput.c_str(), filepos, Axis);
571  if(Turbine != NULL)
572  EXTERN->Lee_Sens_Turbina(fileinput.c_str(), filepos, Turbine);
573  if(Engine != NULL)
574  EXTERN->Lee_Sens_Cil(fileinput.c_str(), filepos, Engine);
575  if(Venturi != NULL)
576  EXTERN->Lee_Sens_Vent(fileinput.c_str(), filepos, Venturi);
577  if(Engine != NULL)
578  EXTERN->Lee_Sens_Motor(fileinput.c_str(), filepos, Theta, Engine[0]->getRegimen(), AcumulatedTime);
579  if(NumberOfConectionsBetweenPlenums != 0)
580  EXTERN->Lee_Sens_UED(fileinput.c_str(), filepos, BC);
581  EXTERN->Lectura_Datos_Adicionales(fileinput.c_str(), filepos);
582  EXTERN->IniciaEntradaDLL();
583 
584  FileInput = fopen(fileinput.c_str(), "r");
585  fsetpos(FileInput, &filepos);
586 
587  } catch(exception & N) {
588  stringstream err;
589  std::cout << "ERROR: ReadDataDLL" << std::endl;
590  std::cout << "Tipo de error: " << N.what() << std::endl;
591  err << "ERROR: ReadDataDLL" << N.what();
592  throw Exception(err.str());
593  }
594 }
595 
596 void TOpenWAM::ReadGeneralData() {
597  try {
598 
599  int hayBQ = 0;
600  int tipociclo = 0, tipomod = 0, tipocalculoespecies = 0;
601  double fracciontotal = 0.;
602  int haycombustible, tipocombustible, tipogamma, EGR, IntEGR = 1;
603  stEspecies *DatEsp;
604  double *CompAtmosfera;
605 
606  fscanf(FileInput, "%lf %lf ", &agincr, &SimulationDuration);
607  fscanf(FileInput, "%lf %lf ", &AmbientPressure, &AmbientTemperature);
608  fscanf(FileInput, "%d %d ", &tipocalculoespecies, &tipogamma);
609 
610  switch(tipogamma) {
611  case 0:
612  GammaCalculation = nmGammaConstante;
613  break;
614  case 1:
615  GammaCalculation = nmComposicion;
616  break;
617  case 2:
618  GammaCalculation = nmComposicionTemperatura;
619  break;
620  }
621 
622  fscanf(FileInput, "%d ", &hayBQ);
623 
624  hayBQ == 0 ? EngineBlock = false : EngineBlock = true;
625 
626  if(EngineBlock) {
627  fscanf(FileInput, "%d %d %d", &tipociclo, &tipomod, &EGR);
628  if(tipociclo == 1) {
629  EngineType = nm2T;
630  } else {
631  EngineType = nm4T;
632  }
633  EGR == 0 ? ThereIsEGR = false : ThereIsEGR = true;
634  EGR == 0 ? IntEGR = 1 : IntEGR = 0;
635  switch(tipomod) {
636  case 0:
637  SimulationType = nmEstacionario;
638  break;
639  case 1:
640  SimulationType = nmTransitorioCarga;
641  break;
642  case 2:
643  SimulationType = nmTransitorioRegimen;
644  break;
645  case 3:
646  SimulationType = nmTransitorioRegimenExterno;
647  break;
648  }
649  if(SimulationType != nmEstacionario) {
650  fscanf(FileInput, "%d", &CyclesWithoutThemalInertia);
651  }
652  }
653 
654  switch(tipocalculoespecies) {
655  case 0:
656  SpeciesModel = nmCalculoSimple;
657  break;
658  case 1:
659  SpeciesModel = nmCalculoCompleto;
660  break;
661  }
662 
663  if(SpeciesModel == nmCalculoCompleto) {
664  fscanf(FileInput, "%d ", &haycombustible);
665  haycombustible == 0 ? ThereIsFuel = false : ThereIsFuel = true;
666  if(haycombustible == 1) { // Fuel injection is considered
667  fscanf(FileInput, "%d ", &tipocombustible);
668  switch(tipocombustible) {
669  case 0:
670  FuelType = nmDiesel;
671  break;
672  case 1:
673  FuelType = nmGasolina;
674  break;
675  }
676  SpeciesNumber = 10;
677  } else if(haycombustible == 0) { // Fuel injection is not considered
678  SpeciesNumber = 9;
679  }
680 
681  DatEsp = new stEspecies[SpeciesNumber - IntEGR];
682 
683  // DatEsp[0].Nombre = new char[15];
684  DatEsp[0].Nombre = "O2";
685  DatEsp[0].R = 259.825; // J/kgK
686 
687  // DatEsp[1].Nombre = new char[15];
688  DatEsp[1].Nombre = "CO2";
689  DatEsp[1].R = 188.9207; // J/kgK
690 
691  // DatEsp[2].Nombre = new char[15];
692  DatEsp[2].Nombre = "H2O";
693  DatEsp[2].R = 461.398; // J/kgK
694 
695  // DatEsp[3].Nombre = new char[15];
696  DatEsp[3].Nombre = "HC";
697  DatEsp[3].R = 638.58; // J/kgK
698 
699  // DatEsp[4].Nombre = new char[15];
700  DatEsp[4].Nombre = "Soot";
701  DatEsp[4].R = 692.866; // J/kgK Se asimila al carbono.
702 
703  // DatEsp[5].Nombre = new char[15];
704  DatEsp[5].Nombre = "NOx";
705  DatEsp[5].R = 277.1466; // J/kgK
706 
707  // DatEsp[6].Nombre = new char[15];
708  DatEsp[6].Nombre = "CO";
709  DatEsp[6].R = 296.837; // J/kgK
710 
711  if(haycombustible == 1) {
712  if(FuelType == nmDiesel) {
713  // DatEsp[7].Nombre = new char[15];
714  DatEsp[7].Nombre = "Diesel";
715  DatEsp[7].R = 55.95; // J/kgK
716  } else if(FuelType == nmGasolina) {
717  // DatEsp[7].Nombre = new char[15];
718  DatEsp[7].Nombre = "Gasolina";
719  DatEsp[7].R = 72.425; // J/kgK
720  }
721  // DatEsp[8].Nombre = new char[15];
722  DatEsp[8].Nombre = "N2";
723  DatEsp[8].R = 296.837; // J/kgK
724 
725  if(ThereIsEGR) {
726  // DatEsp[9].Nombre = new char[15];
727  DatEsp[9].Nombre = "EGR";
728  DatEsp[9].R = 287.; // J/kgK
729  }
730  } else {
731  // DatEsp[7].Nombre = new char[15];
732  DatEsp[7].Nombre = "N2";
733  DatEsp[7].R = 296.837; // J/kgK
734 
735  if(ThereIsEGR) {
736  // DatEsp[8].Nombre = new char[15];
737  DatEsp[8].Nombre = "EGR";
738  DatEsp[8].R = 287.; // J/kgK
739  }
740  }
741 
742  } else if(SpeciesModel == nmCalculoSimple) {
743  fscanf(FileInput, "%d ", &haycombustible);
744  if(haycombustible == 1) { // Existe inyeccion de combustible
745  fscanf(FileInput, "%d ", &tipocombustible);
746  switch(tipocombustible) {
747  case 0:
748  FuelType = nmDiesel;
749  break;
750  case 1:
751  FuelType = nmGasolina;
752  break;
753  }
754  SpeciesNumber = 4;
755  } else if(haycombustible == 0) {
756  // No existe inyeccion de combustible
757  SpeciesNumber = 3;
758  }
759  DatEsp = new stEspecies[SpeciesNumber - IntEGR];
760 
761  DatEsp[0].Nombre = new char[15];
762  DatEsp[0].Nombre = "GasesQuemados";
763  DatEsp[0].R = 285.4; // J/kgK
764 
765  if(haycombustible == 1) {
766  if(FuelType == nmDiesel) {
767  // DatEsp[1].Nombre = new char[15];
768  DatEsp[1].Nombre = "Diesel";
769  DatEsp[1].R = 55.95; // J/kgK
770  } else if(FuelType == nmGasolina) {
771  // DatEsp[1].Nombre = new char[15];
772  DatEsp[1].Nombre = "Gasolina";
773  DatEsp[1].R = 72.425; // J/kgK
774  }
775  // DatEsp[2].Nombre = new char[15];
776  DatEsp[2].Nombre = "Aire";
777  DatEsp[2].R = 287.; // J/kgK
778 
779  if(ThereIsEGR) {
780  // DatEsp[3].Nombre = new char[15];
781  DatEsp[3].Nombre = "EGR";
782  DatEsp[3].R = 287.; // J/kgK
783  }
784  } else {
785  // DatEsp[1].Nombre = new char[15];
786  DatEsp[1].Nombre = "Aire";
787  DatEsp[1].R = 287.; // J/kgK.
788 
789  if(ThereIsEGR) {
790  // DatEsp[2].Nombre = new char[15];
791  DatEsp[2].Nombre = "EGR";
792  DatEsp[2].R = 287.; // J/kgK
793  }
794  }
795  }
796  SpeciesName = DatEsp;
797 
798  // A continuacion se lee la composicion del aire atmosferico
799 
800  CompAtmosfera = new double[SpeciesNumber - IntEGR];
801  for(int i = 0; i < SpeciesNumber - 1; i++) {
802  fscanf(FileInput, "%lf ", &CompAtmosfera[i]);
803 
804  fracciontotal += CompAtmosfera[i];
805  }
806  if(ThereIsEGR)
807  CompAtmosfera[SpeciesNumber - 1] = 0.;
808  if(fracciontotal != 1.) {
809  std::cout << "ERROR: The total mass fraction must be equal to 1. Check your input data " << std::endl;
810  throw Exception(" ");
811  }
812 
813  AtmosphericComposition = CompAtmosfera;
814 
815  } catch(exception & N) {
816  std::cout << "ERROR: ReadGeneralData" << std::endl;
817  std::cout << "Tipo de error: " << N.what() << std::endl;
818  throw Exception(N.what());
819  }
820 }
821 
822 void TOpenWAM::ReadEngine()
823 
824 {
825  try {
826  fpos_t filepos;
827 
828  if(EngineBlock) {
829  fgetpos(FileInput, &filepos);
830  fclose(FileInput);
831  Engine = new TBloqueMotor*[1];
832  Engine[0] = new TBloqueMotor(AmbientPressure, AmbientTemperature, SpeciesModel, SpeciesNumber, GammaCalculation,
833  ThereIsEGR);
834  Engine[0]->LeeMotor(fileinput.c_str(), filepos, SimulationType, CyclesWithoutThemalInertia, EngineType,
835  AtmosphericComposition);
836  FileInput = fopen(fileinput.c_str(), "r");
837  fsetpos(FileInput, &filepos);
838  }
839 
840  } catch(exception & N) {
841  std::cout << "ERROR: ReadEngine " << std::endl;
842  std::cout << "Tipo de error: " << N.what() << std::endl;
843  throw Exception(N.what());
844  }
845 }
846 
847 void TOpenWAM::ReadPipes() {
848  try {
849  fpos_t filepos;
850  int tipomallado = 0;
851 
852  fscanf(FileInput, "%d ", &NumberOfPipes);
853  Pipe = new TTubo*[NumberOfPipes];
854  printf("Number of pipes: %d\n", NumberOfPipes);
855  tipomallado = 1;
856 
857  fgetpos(FileInput, &filepos);
858  fclose(FileInput);
859 
860  for(int i = 0; i < NumberOfPipes; i++) {
861  Pipe[i] = new TTubo(SpeciesNumber, i, SimulationDuration, Engine, SpeciesModel, GammaCalculation, ThereIsEGR);
862  Pipe[i]->LeeDatosGeneralesTubo(fileinput.c_str(), filepos);
863  if(EngineBlock) {
864  Pipe[i]->LeeDatosGeometricosTubo(fileinput.c_str(), filepos, Engine[0]->getRegimen(), tipomallado, Engine);
865  } else {
866  Pipe[i]->LeeDatosGeometricosTubo(fileinput.c_str(), filepos, -1., tipomallado, Engine);
867  }
868  cout << "INFO: Pipe n. " << i + 1 << " - N. of cells " << Pipe[i]->getNin() << " - Mesh size = " <<
869  Pipe[i]->getMallado() << " m." << endl;
870 // i + 1, Pipe[i]->getNin(), Pipe[i]->getMallado());
871  }
872 
873  FileInput = fopen(fileinput.c_str(), "r");
874  fsetpos(FileInput, &filepos);
875  } catch(exception & N) {
876  std::cout << "ERROR: ReadPipes" << std::endl;
877  std::cout << "Tipo de error: " << N.what() << std::endl;
878  throw Exception(N.what());
879  }
880 }
881 
882 void TOpenWAM::ReadDPF() {
883  try {
884 #ifdef ParticulateFilter
885  fpos_t filepos;
886 
887  fscanf(FileInput, "%d ", &NumberOfDPF);
888  DPF = new TDPF*[NumberOfDPF];
889  printf("Number of DPF: %d\n", NumberOfDPF);
890 
891  fgetpos(FileInput, &filepos);
892  fclose(FileInput);
893 
894  for(int i = 0; i < NumberOfDPF; i++) {
895  DPF[i] = new TDPF(i + 1, Engine, SpeciesNumber);
896  DPF[i]->LeeDatosDPF(fileinput.c_str(), filepos, SpeciesModel,
897  GammaCalculation, ThereIsEGR, Engine);
898  }
899 
900  FileInput = fopen(fileinput.c_str(), "r");
901  fsetpos(FileInput, &filepos);
902 #endif
903  } catch(exception & N) {
904  std::cout << "ERROR: ReadDPF" << std::endl;
905  std::cout << "Tipo de error: " << N.what() << std::endl;
906  throw Exception(N.what());
907  }
908 }
909 
910 void TOpenWAM::ReadConcentric() {
911  try {
912 #ifdef ConcentricElement
913  fpos_t filepos;
914  int numducts = 0;
915 
916  fscanf(FileInput, "%d ", &NumberOfConcentrics);
917  Concentric = new TConcentrico*[NumberOfConcentrics];
918  printf("Number of concentrics: %d\n", NumberOfConcentrics);
919 
920  for(int i = 0; i < NumberOfConcentrics; i++) {
921  fscanf(FileInput, "%d ", &numducts);
922  fgetpos(FileInput, &filepos);
923  fclose(FileInput);
924  if(numducts == 2) {
925  Concentric[i] = new TConcentricoTubos(i);
926 #ifdef ParticulateFilter
927  Concentric[i]->LeeDatosTuboConcentrico(fileinput.c_str(), filepos,
928  Pipe, DPF);
929 #else
930  Concentric[i]->LeeDatosTuboConcentrico(fileinput.c_str(), filepos,
931  Pipe, NULL);
932 #endif
933  } else if(numducts == 1) {
934  Concentric[i] = new TConcentricoDPF(i);
935 #ifdef ParticulateFilter
936  Concentric[i]->LeeDatosTuboConcentrico(fileinput.c_str(), filepos,
937  Pipe, DPF);
938 #else
939  Concentric[i]->LeeDatosTuboConcentrico(fileinput.c_str(), filepos,
940  Pipe, NULL);
941 #endif
942  }
943  FileInput = fopen(fileinput.c_str(), "r");
944  fsetpos(FileInput, &filepos);
945  }
946 #endif
947  } catch(exception & N) {
948  std::cout << "ERROR: ReadConcentric" << std::endl;
949  std::cout << "Tipo de error: " << N.what() << std::endl;
950  throw Exception(N.what());
951  }
952 }
953 
954 void TOpenWAM::ReadValves() {
955  try {
956  fscanf(FileInput, "%d ", &NumberOfValves);
957  TypeOfValve = new TTipoValvula*[NumberOfValves];
958  int val = 0;
959  int NumTCDFijo = 0;
960  int NumTValvula4T = 0;
961  int NumberOfReedValves = 0;
962  int NumTDiscoRotativo = 0;
963  int NumTLumbrera = 0;
964  int NumTValvulaContr = 0;
965  int NumberOfWasteGates = 0;
966  int NumTEstatorTurbina = 0;
967  int NumTRotorTurbina = 0;
968  int NumTCDExterno = 0;
969  int NumberOfButerflyValves = 0;
970  int tipval = 0;
971  fpos_t filepos;
972 
973  for(int i = 0; i < NumberOfValves; ++i) {
974  fscanf(FileInput, "%d ", &tipval);
975  switch(tipval) {
976  case 0:
977  TypeOfValve[i] = new TCDFijo();
978  val = NumTCDFijo;
979  NumTCDFijo++;
980  break;
981  case 1:
982  TypeOfValve[i] = new TValvula4T();
983  val = NumTValvula4T;
984  NumTValvula4T++;
985  break;
986  case 2:
987  TypeOfValve[i] = new TLamina();
988  val = NumberOfReedValves;
989  NumberOfReedValves++;
990  break;
991  case 3:
992  TypeOfValve[i] = new TDiscoRotativo();
993  val = NumTDiscoRotativo;
994  NumTDiscoRotativo++;
995  break;
996  case 4:
997  TypeOfValve[i] = new TLumbrera(Engine[0]->getGeometria().Biela, Engine[0]->getGeometria().Carrera);
998  val = NumTLumbrera;
999  NumTLumbrera++;
1000  break;
1001  case 5:
1002  TypeOfValve[i] = new TValvulaContr();
1003  val = NumTValvulaContr;
1004  NumTValvulaContr++;
1005  break;
1006  case 6:
1007  TypeOfValve[i] = new TWasteGate();
1008  val = NumberOfWasteGates;
1009  NumberOfWasteGates++;
1010  break;
1011  case 7:
1012  TypeOfValve[i] = new TEstatorTurbina();
1013  val = NumTEstatorTurbina;
1014  NumTEstatorTurbina++;
1015  break;
1016  case 8:
1017  TypeOfValve[i] = new TRotorTurbina();
1018  val = NumTRotorTurbina;
1019  NumTRotorTurbina++;
1020  break;
1021  case 9:
1022  controlvalv = 1;
1023  TypeOfValve[i] = new TCDExterno();
1024  val = NumTCDExterno;
1025  NumTCDExterno++;
1026  break;
1027  case 10:
1028  TypeOfValve[i] = new TMariposa();
1029  val = NumberOfButerflyValves;
1030  NumberOfButerflyValves++;
1031  break;
1032  }
1033  fgetpos(FileInput, &filepos);
1034  fclose(FileInput);
1035  if(!EngineBlock) {
1036  TypeOfValve[i]->LeeDatosIniciales(fileinput.c_str(), filepos, val, EngineBlock, NULL);
1037  } else {
1038  TypeOfValve[i]->LeeDatosIniciales(fileinput.c_str(), filepos, val, EngineBlock, Engine[0]);
1039  }
1040  FileInput = fopen(fileinput.c_str(), "r");
1041  fsetpos(FileInput, &filepos);
1042  }
1043 
1044  } catch(exception & N) {
1045  stringstream err;
1046  std::cout << "ERROR: ReadValves" << std::endl;
1047  std::cout << "Tipo de error: " << N.what() << std::endl;
1048  err << "ERROR: ReadValves" << N.what();
1049  throw Exception(err.str());
1050  }
1051 }
1052 
1053 void TOpenWAM::ReadPlenums() {
1054 
1055  try {
1056  fpos_t filepos;
1057  int tipoDep, ncv = 0;
1058  int numeroturbina = 0, numeroventuri = 0;
1059 
1060  /* PARAMETERS USED BY WAMMER */
1061  int numeroturbinas = 0, numeroventuris = 0, numerounionesdireccionales = 0;
1062 
1063  fscanf(FileInput, "%d ", &NumberOfPlenums);
1064  /* PARAMETERS USED BY WAMMER */
1065  fscanf(FileInput, "%d %d %d", &numeroturbinas, &numeroventuris, &numerounionesdireccionales);
1066 
1067  fgetpos(FileInput, &filepos);
1068  fclose(FileInput);
1069 
1070  NumberOfTurbines = 0;
1071  NumberOfVenturis = 0;
1072  NumberOfDirectionalJunctions = 0;
1073  if(NumberOfPlenums != 0) {
1074  Plenum = new TDeposito*[NumberOfPlenums];
1075  }
1076  if(NumberOfPlenums != 0) {
1077  for(int i = 0; i < NumberOfPlenums; ++i) {
1078  FileInput = fopen(fileinput.c_str(), "r");
1079  fsetpos(FileInput, &filepos);
1080  fscanf(FileInput, "%d ", &tipoDep);
1081  fgetpos(FileInput, &filepos);
1082  fclose(FileInput);
1083  switch(tipoDep) {
1084  case 0:
1085  Plenum[i] = new TDepVolCte(i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1086  Plenum[i]->LeeDatosGeneralesDepositos(fileinput.c_str(), filepos);
1087  break;
1088  case 1:
1089  Plenum[i] = new TDepVolVariable(i, ncv, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1090  Plenum[i]->LeeDatosGeneralesDepositos(fileinput.c_str(), filepos);
1091  dynamic_cast<TDepVolVariable*>(Plenum[i])->LeeDatosDepVolVariable(fileinput.c_str(), filepos, EngineBlock);
1092  ncv++;
1093  break;
1094  case 2:
1095  FileInput = fopen(fileinput.c_str(), "r");
1096  fsetpos(FileInput, &filepos);
1097  fscanf(FileInput, "%d ", &numeroturbina);
1098  Plenum[i] = new TTurbinaSimple(i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1099  dynamic_cast<TTurbina*>(Plenum[i])->PutNumeroTurbina(numeroturbina);
1100  fgetpos(FileInput, &filepos);
1101  fclose(FileInput);
1102  Plenum[i]->LeeDatosGeneralesDepositos(fileinput.c_str(), filepos);
1103  dynamic_cast<TTurbina*>(Plenum[i])->LeeTurbina(fileinput.c_str(), filepos);
1104  dynamic_cast<TTurbina*>(Plenum[i])->IniciaMedias();
1105  NumberOfTurbines = NumberOfTurbines + 1;
1106  break;
1107  case 3:
1108  FileInput = fopen(fileinput.c_str(), "r");
1109  fsetpos(FileInput, &filepos);
1110  fscanf(FileInput, "%d ", &numeroturbina);
1111  Plenum[i] = new TTurbinaTwin(i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1112  dynamic_cast<TTurbina*>(Plenum[i])->PutNumeroTurbina(numeroturbina);
1113  fgetpos(FileInput, &filepos);
1114  fclose(FileInput);
1115  Plenum[i]->LeeDatosGeneralesDepositos(fileinput.c_str(), filepos);
1116  dynamic_cast<TTurbina*>(Plenum[i])->LeeTurbina(fileinput.c_str(), filepos);
1117  dynamic_cast<TTurbina*>(Plenum[i])->IniciaMedias();
1118  NumberOfTurbines = NumberOfTurbines + 1;
1119  break;
1120  case 4:
1121  FileInput = fopen(fileinput.c_str(), "r");
1122  fsetpos(FileInput, &filepos);
1123  fscanf(FileInput, "%d ", &numeroventuri);
1124  Plenum[i] = new TVenturi(i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1125  dynamic_cast<TVenturi*>(Plenum[i])->PutNumeroVenturi(numeroventuri);
1126  fgetpos(FileInput, &filepos);
1127  fclose(FileInput);
1128  NumberOfVenturis = NumberOfVenturis + 1;
1129  Plenum[i]->LeeDatosGeneralesDepositos(fileinput.c_str(), filepos);
1130  dynamic_cast<TVenturi*>(Plenum[i])->LeeDatosVenturi(fileinput.c_str(), filepos);
1131  break;
1132  case 5:
1133  NumberOfDirectionalJunctions = NumberOfDirectionalJunctions + 1;
1134  Plenum[i] = new TUnionDireccional(i, NumberOfDirectionalJunctions, SpeciesModel, SpeciesNumber, GammaCalculation,
1135  ThereIsEGR);
1136  Plenum[i]->LeeDatosGeneralesDepositos(fileinput.c_str(), filepos);
1137  dynamic_cast<TUnionDireccional*>(Plenum[i])->LeeDatosUnionDireccional(fileinput.c_str(), filepos);
1138  break;
1139  }
1140 
1141  }
1142  }
1143  FileInput = fopen(fileinput.c_str(), "r");
1144  fsetpos(FileInput, &filepos);
1145 
1146  if(NumberOfTurbines > 0)
1147  Turbine = new TTurbina*[NumberOfTurbines];
1148  for(int i = 0; i < NumberOfTurbines; i++) {
1149  for(int j = 0; j < NumberOfPlenums; j++) {
1150  if(Plenum[j]->getTipoDeposito() == nmTurbinaSimple || Plenum[j]->getTipoDeposito() == nmTurbinaTwin) {
1151  if(i + 1 == dynamic_cast<TTurbina*>(Plenum[j])->getNumeroTurbina()) {
1152  Turbine[i] = dynamic_cast<TTurbina*>(Plenum[j]);
1153  }
1154  }
1155  }
1156  }
1157  if(NumberOfVenturis > 0)
1158  Venturi = new TVenturi*[NumberOfVenturis];
1159  for(int i = 0; i < NumberOfVenturis; i++) {
1160  for(int j = 0; j < NumberOfPlenums; j++) {
1161  if(Plenum[j]->getTipoDeposito() == nmVenturi) {
1162  if(dynamic_cast<TVenturi*>(Plenum[j])->getNumeroVenturi() == i + 1) {
1163  Venturi[i] = dynamic_cast<TVenturi*>(Plenum[j]);
1164  }
1165  }
1166  }
1167  }
1168  } catch(exception & N) {
1169  std::cout << "ERROR: ReadPlenums " << std::endl;
1170  std::cout << "Tipo de error: " << N.what() << std::endl;
1171  throw Exception(N.what());
1172  }
1173 }
1174 
1175 void TOpenWAM::ReadCompressors() {
1176  try {
1177  fpos_t filepos;
1178  int TipoCompresor = 0;
1179  int haydeposito = 0, numid = 0, numid1 = 0, numid2 = 0;
1180 
1181  fscanf(FileInput, "%d ", &NumberOfCompressors);
1182  Compressor = new TCompresor*[NumberOfCompressors];
1183  fgetpos(FileInput, &filepos);
1184  fclose(FileInput);
1185 
1186  for(int j = 0; j < NumberOfCompressors; j++) {
1187  FileInput = fopen(fileinput.c_str(), "r");
1188  fsetpos(FileInput, &filepos);
1189  fscanf(FileInput, "%d ", &TipoCompresor);
1190  if(TipoCompresor == 0) {
1191  /* Lectura para Wamer */
1192  fscanf(FileInput, "%d ", &haydeposito);
1193  if(haydeposito == 1)
1194  fscanf(FileInput, "%d ", &numid);
1195  }
1196  if(TipoCompresor == 1) {
1197  /* Lectura para Wamer */
1198  fscanf(FileInput, "%d %d", &numid1, &numid2);
1199  }
1200  fgetpos(FileInput, &filepos);
1201  fclose(FileInput);
1202  switch(TipoCompresor) {
1203  case 0: /* Pipe - Deposito */
1204  Compressor[j] = new TCompTubDep(j, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1205  (dynamic_cast<TCompTubDep*>(Compressor[j]))->LeeCompresor(fileinput.c_str(), filepos);
1206  break;
1207  case 1: /* Entre Depositos */
1208  Compressor[j] = new TCompresorDep(j, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1209  (dynamic_cast<TCompresorDep*>(Compressor[j]))->LeeCompresor(fileinput.c_str(), filepos);
1210  break;
1211  case 2: /* Entre Tubos */
1212  Compressor[j] = new TCompTubos(j, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1213  (dynamic_cast<TCompTubos*>(Compressor[j]))->LeeCompresor(fileinput.c_str(), filepos);
1214  break;
1215  }
1216  }
1217  FileInput = fopen(fileinput.c_str(), "r");
1218  fsetpos(FileInput, &filepos);
1219  } catch(exception & N) {
1220  std::cout << "ERROR: ReadCompressors " << std::endl;
1221  std::cout << "Tipo de error: " << N.what() << std::endl;
1222  throw Exception(N.what());
1223  }
1224 }
1225 
1226 void TOpenWAM::ReadConnections() {
1227  try {
1228  fpos_t filepos;
1229  int numerocv = 0, contador = 0;
1230  int NumTCCDescargaExtremoAbierto = 0, NumTCCExtremoCerrado = 0, NumTCCExtremoAnecoico = 0, NumTCCPulso = 0,
1231  NumTCCUnionEntreTubos = 0, NumTCCCilindro = 0, NumTCCDeposito = 0,
1232  NumTCCRamificacion = 0, NumTCCEntradaCompresor = 0, NumTCCPreVble = 0;
1233  NumTCCPerdidaPresion = 0;
1234  int TipoCC = 0;
1235  int numerovalvula = 0, quevalv;
1236  int NumTCCExternalConnection = 0;
1237 
1238  // ! PARAMETERS USED BY WAMer
1239  int numnodosimples, numpulsos, numnododep, numperdpresion, numcomprtornillo, numextremosinyeccion,
1240  numnodoentredepositos, numentradacompresor, numentradapresionestatica;
1241 
1242  fscanf(FileInput, "%d ", &NumberOfConnections);
1243  // ! PARAMETERS USED BY WAMer
1244  fscanf(FileInput, "%d %d %d %d %d %d %d %d %d", &numnodosimples, &numpulsos, &numnododep, &numperdpresion,
1245  &numcomprtornillo, &numextremosinyeccion, &numnodoentredepositos,
1246  &numentradacompresor, &numentradapresionestatica);
1247 
1248  BC = new TCondicionContorno*[NumberOfConnections];
1249  printf("Number of boundary condition: %d\n", NumberOfConnections);
1250  fgetpos(FileInput, &filepos);
1251  fclose(FileInput);
1252  if(NumberOfConnections != 0) {
1253  for(int i = 0; i <= NumberOfConnections - 1; ++i) {
1254  FileInput = fopen(fileinput.c_str(), "r");
1255  fsetpos(FileInput, &filepos);
1256  fscanf(FileInput, "%d ", &TipoCC);
1257  fgetpos(FileInput, &filepos);
1258  fclose(FileInput);
1259  switch(TipoCC) {
1260  case 0:
1261  BC[i] = new TCCDescargaExtremoAbierto(nmOpenEndAtmosphere, i, SpeciesModel, SpeciesNumber, GammaCalculation,
1262  ThereIsEGR);
1263  NumTCCDescargaExtremoAbierto++;
1264 #ifdef ParticulateFilter
1265  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1266  Pipe, NumberOfDPF, DPF);
1267 #else
1268  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1269 #endif
1270  BC[i]->AsignAmbientConditions(AmbientTemperature, AmbientPressure, AtmosphericComposition);
1271  break;
1272  case 1:
1273  BC[i] = new TCCDescargaExtremoAbierto(nmOpenEndReservoir, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1274  NumTCCDescargaExtremoAbierto++;
1275 #ifdef ParticulateFilter
1276  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1277  Pipe, NumberOfDPF, DPF);
1278 #else
1279  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1280 #endif
1281  break;
1282  case 2:
1283  BC[i] = new TCCDescargaExtremoAbierto(nmOpenEndCalcExtern, i, SpeciesModel, SpeciesNumber, GammaCalculation,
1284  ThereIsEGR);
1285  NumTCCDescargaExtremoAbierto++;
1286  nematlab++;
1287 #ifdef ParticulateFilter
1288  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1289  Pipe, NumberOfDPF, DPF);
1290 #else
1291  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1292 #endif
1293  break;
1294  case 3:
1295  BC[i] = new TCCExtremoCerrado(nmClosedEnd, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1296  NumTCCExtremoCerrado++;
1297  BC[i]->AsignaTubos(NumberOfPipes, Pipe);
1298  break;
1299  case 4:
1300  BC[i] = new TCCExtremoAnecoico(nmAnechoicEnd, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1301  NumTCCExtremoAnecoico++;
1302  BC[i]->AsignaTubos(NumberOfPipes, Pipe);
1303  break;
1304  case 5:
1305  BC[i] = new TCCPulso(nmIncidentPressurWave, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1306  NumTCCPulso++;
1307 #ifdef ParticulateFilter
1308  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1309  Pipe, NumberOfDPF, DPF);
1310 #else
1311  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1312 #endif
1313  break;
1314  case 6:
1315  BC[i] = new TCCUnionEntreTubos(nmPipesConnection, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1316  NumTCCUnionEntreTubos++;
1317 #ifdef ParticulateFilter
1318  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1319  Pipe, NumberOfDPF, DPF);
1320 #else
1321  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1322 #endif
1323  break;
1324  case 7:
1325  BC[i] = new TCCCilindro(nmIntakeValve, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1326  NumTCCCilindro++;
1327  NumberOfIntakeValves++;
1328 #ifdef ParticulateFilter
1329  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1330  Pipe, NumberOfDPF, DPF);
1331 #else
1332  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1333 #endif
1334  break;
1335  case 8:
1336  BC[i] = new TCCCilindro(nmExhaustValve, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1337  NumTCCCilindro++;
1338  NumberOfExhaustValves++;
1339 #ifdef ParticulateFilter
1340  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1341  Pipe, NumberOfDPF, DPF);
1342 #else
1343  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1344 #endif
1345  break;
1346  case 9:
1347  BC[i] = new TCCPerdidadePresion(nmLinearPressureLoss, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1348  NumTCCPerdidaPresion++;
1349 #ifdef ParticulateFilter
1350  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1351  Pipe, NumberOfDPF, DPF);
1352 #else
1353  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1354 #endif
1355  break;
1356  case 10:
1357  BC[i] = new TCCPerdidadePresion(nmQuadraticPressureLoss, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1358  NumTCCPerdidaPresion++;
1359 #ifdef ParticulateFilter
1360  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1361  Pipe, NumberOfDPF, DPF);
1362 #else
1363  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1364 #endif
1365  break;
1366  case 11:
1367  BC[i] = new TCCDeposito(nmPipeToPlenumConnection, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1368  NumTCCDeposito++;
1369 #ifdef ParticulateFilter
1370  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1371  Pipe, NumberOfDPF, DPF);
1372 #else
1373  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1374 #endif
1375  break;
1376  case 12:
1377  BC[i] = new TCCRamificacion(nmBranch, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1378  NumTCCRamificacion++;
1379  BC[i]->AsignaTubos(NumberOfPipes, Pipe);
1380  break;
1381  case 13:
1382  FileInput = fopen(fileinput.c_str(), "r");
1383  fsetpos(FileInput, &filepos);
1384  fscanf(FileInput, "%d ", &numerocv);
1385  fgetpos(FileInput, &filepos);
1386  fclose(FileInput);
1387  BC[i] = new TCCCompresorVolumetrico(nmVolumetricCompressor, i, SpeciesModel, SpeciesNumber, GammaCalculation,
1388  ThereIsEGR);
1389  dynamic_cast<TCCCompresorVolumetrico*>(BC[i])->PutNumeroCV(numerocv);
1390  NumberOfVolumetricCompressors++;
1391  dynamic_cast<TCCCompresorVolumetrico*>(BC[i])->LeeCCCompresorVol(fileinput.c_str(), filepos, NumberOfPipes, Pipe,
1392  EngineBlock);
1393  dynamic_cast<TCCCompresorVolumetrico*>(BC[i])->IniciaMedias();
1394  break;
1395  case 14:
1396  BC[i] = new TCCExtremoInyeccion(nmInjectionEnd, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1397  NumberOfInjectionEnds++;
1398 #ifdef ParticulateFilter
1399  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1400  Pipe, NumberOfDPF, DPF);
1401 #else
1402  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1403 #endif
1404  break;
1405  case 15:
1406  BC[i] = new TCCEntradaCompresor(nmEntradaCompre, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1407  NumTCCEntradaCompresor++;
1408 #ifdef ParticulateFilter
1409  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1410  Pipe, NumberOfDPF, DPF);
1411 #else
1412  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1413 #endif
1414  break;
1415  case 16:
1416  BC[i] = new TCCUnionEntreDepositos(nmUnionEntreDepositos, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1417  NumberOfConectionsBetweenPlenums++;
1418  dynamic_cast<TCCUnionEntreDepositos*>(BC[i])->LeeUEDepositos(fileinput.c_str(), filepos, Independent);
1419  break;
1420  case 17:
1421  BC[i] = new TCCCompresor(nmCompresor, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1422  NumberOfCompressorsConnections++;
1423  dynamic_cast<TCCCompresor*>(BC[i])->LeeNumeroCompresor(fileinput.c_str(), filepos);
1424  break;
1425  case 18:
1426  BC[i] = new TCCPreVble(nmPresionVble, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1427  NumTCCPreVble++;
1428 #ifdef ParticulateFilter
1429  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1430  Pipe, NumberOfDPF, DPF);
1431 #else
1432  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1433 #endif
1434  break;
1435  case 19:
1436  BC[i] = new TCFDConnection(nmCFDConnection, i, SpeciesModel, SpeciesNumber, GammaCalculation, ThereIsEGR);
1437 #ifdef ParticulateFilter
1438  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1439  Pipe, NumberOfDPF, DPF);
1440 #else
1441  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1442 #endif
1443  break;
1444  case 20:
1445  BC[i] = new TCCExternalConnectionVol(nmExternalConnection, i, SpeciesModel, SpeciesNumber, GammaCalculation,
1446  ThereIsEGR);
1447  NumTCCExternalConnection++;
1448 #ifdef ParticulateFilter
1449  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes,
1450  Pipe, NumberOfDPF, DPF);
1451 #else
1452  BC[i]->ReadBoundaryData(fileinput.c_str(), filepos, NumberOfPipes, Pipe, NumberOfDPF, NULL);
1453 #endif
1454  break;
1455  }
1456  if(BC[i]->getTipoCC() == nmIntakeValve || BC[i]->getTipoCC() == nmExhaustValve
1457  || BC[i]->getTipoCC() == nmPipeToPlenumConnection || BC[i]->getTipoCC() == nmUnionEntreDepositos) {
1458  FileInput = fopen(fileinput.c_str(), "r");
1459  fsetpos(FileInput, &filepos);
1460  fscanf(FileInput, "%d ", &quevalv);
1461  fgetpos(FileInput, &filepos);
1462  fclose(FileInput);
1463  if(BC[i]->getTipoCC() == nmIntakeValve || BC[i]->getTipoCC() == nmExhaustValve) {
1464  dynamic_cast<TCCCilindro*>(BC[i])->AsignaTipoValvula(TypeOfValve, quevalv, numerovalvula);
1465  } else if(BC[i]->getTipoCC() == nmPipeToPlenumConnection) {
1466  dynamic_cast<TCCDeposito*>(BC[i])->AsignaTipoValvula(TypeOfValve, quevalv, numerovalvula);
1467  if(TypeOfValve[quevalv - 1]->getTypeOfValve() == nmLamina)
1468  NumberOfReedValves++;
1469  if(TypeOfValve[quevalv - 1]->getTypeOfValve() == nmWasteGate)
1470  NumberOfWasteGates++;
1471  if(TypeOfValve[quevalv - 1]->getTypeOfValve() == nmCalcExtern)
1472  NumberOfExternalCalculatedValves++;
1473  if(TypeOfValve[quevalv - 1]->getTypeOfValve() == nmMariposa)
1474  NumberOfButerflyValves++;
1475  } else if(BC[i]->getTipoCC() == nmUnionEntreDepositos) {
1476  dynamic_cast<TCCUnionEntreDepositos*>(BC[i])->AsignaTipoValvula(TypeOfValve, quevalv, numerovalvula);
1477  if(TypeOfValve[quevalv - 1]->getTypeOfValve() == nmLamina)
1478  NumberOfReedValves++;
1479  if(TypeOfValve[quevalv - 1]->getTypeOfValve() == nmWasteGate)
1480  NumberOfWasteGates++;
1481  if(TypeOfValve[quevalv - 1]->getTypeOfValve() == nmCalcExtern)
1482  NumberOfExternalCalculatedValves++;
1483  if(TypeOfValve[quevalv - 1]->getTypeOfValve() == nmMariposa)
1484  NumberOfButerflyValves++;
1485  }
1486  numerovalvula++;
1487  }
1488 
1489  }
1490  }
1491  FileInput = fopen(fileinput.c_str(), "r");
1492  fsetpos(FileInput, &filepos);
1493 
1494  if(NumberOfIntakeValves > 0) {
1495  BCIntakeValve = new TCondicionContorno*[NumberOfIntakeValves];
1496  contador = 0;
1497  for(int j = 0; j < NumberOfConnections; j++) {
1498  if(BC[j]->getTipoCC() == nmIntakeValve) {
1499  BCIntakeValve[contador] = dynamic_cast<TCCCilindro*>(BC[j]);
1500  contador++;
1501  }
1502  }
1503  }
1504 
1505  if(NumberOfExhaustValves > 0) {
1506  BCExhaustValve = new TCondicionContorno*[NumberOfExhaustValves];
1507  contador = 0;
1508  for(int j = 0; j < NumberOfConnections; j++) {
1509  if(BC[j]->getTipoCC() == nmExhaustValve) {
1510  BCExhaustValve[contador] = dynamic_cast<TCCCilindro*>(BC[j]);
1511  contador++;
1512  }
1513  }
1514  }
1515 
1516  if(NumberOfVolumetricCompressors > 0) {
1517  VolumetricCompressor = new TCCCompresorVolumetrico*[NumberOfVolumetricCompressors];
1518  contador = 0;
1519  for(int j = 0; j < NumberOfConnections; j++) {
1520  if(BC[j]->getTipoCC() == nmVolumetricCompressor) {
1521  if(contador + 1 == dynamic_cast<TCCCompresorVolumetrico*>(BC[j])->getNumeroCV()) {
1522  VolumetricCompressor[contador] = dynamic_cast<TCCCompresorVolumetrico*>(BC[j]);
1523  contador++;
1524  }
1525  }
1526  }
1527  }
1528 
1529  if(NumTCCPerdidaPresion > 0) {
1530  PerdidaPresion = new TCCPerdidadePresion*[NumTCCPerdidaPresion];
1531  contador = 0;
1532  for(int j = 0; j < NumberOfConnections; j++) {
1533  if(BC[j]->getTipoCC() == nmLinearPressureLoss || BC[j]->getTipoCC() == nmQuadraticPressureLoss) {
1534  PerdidaPresion[contador] = dynamic_cast<TCCPerdidadePresion*>(BC[j]);
1535  contador++;
1536  }
1537  }
1538  }
1539 
1540  if(nematlab > 0) {
1541  MatlabDischarge = new TCCDescargaExtremoAbierto*[nematlab];
1542  contador = 0;
1543  for(int j = 0; j < NumberOfConnections; j++) {
1544  if(BC[j]->getTipoCC() == nmOpenEndCalcExtern) {
1545  MatlabDischarge[contador] = dynamic_cast<TCCDescargaExtremoAbierto*>(BC[j]);
1546  contador++;
1547  }
1548  }
1549  }
1550 
1551  if(NumberOfInjectionEnds > 0) {
1552  InjectionEnd = new TCCExtremoInyeccion*[NumberOfInjectionEnds];
1553  contador = 0;
1554  for(int j = 0; j < NumberOfConnections; j++) {
1555  if(BC[j]->getTipoCC() == nmInjectionEnd) {
1556  InjectionEnd[contador] = dynamic_cast<TCCExtremoInyeccion*>(BC[j]);
1557  contador++;
1558  }
1559  }
1560  }
1561 
1562  if(NumberOfReedValves > 0) {
1563  BCReedValve = new TCondicionContorno*[NumberOfReedValves];
1564  contador = 0;
1565  for(int j = 0; j < NumberOfConnections; j++) {
1566  if(BC[j]->getTipoCC() == nmPipeToPlenumConnection) {
1567  if(dynamic_cast<TCCDeposito*>(BC[j])->getValvula()->getTypeOfValve() == nmLamina) {
1568  BCReedValve[contador] = dynamic_cast<TCCDeposito*>(BC[j]);
1569  contador++;
1570  }
1571  } else if(BC[j]->getTipoCC() == nmUnionEntreDepositos) {
1572  if(dynamic_cast<TCCUnionEntreDepositos*>(BC[j])->getValvula()->getTypeOfValve() == nmLamina) {
1573  BCReedValve[contador] = dynamic_cast<TCCUnionEntreDepositos*>(BC[j]);
1574  contador++;
1575  }
1576  }
1577  }
1578  }
1579 
1580  if(NumberOfWasteGates > 0) {
1581  BCWasteGate = new TCondicionContorno*[NumberOfWasteGates];
1582  contador = 0;
1583  for(int j = 0; j < NumberOfConnections; j++) {
1584  if(BC[j]->getTipoCC() == nmPipeToPlenumConnection) {
1585  if(dynamic_cast<TCCDeposito*>(BC[j])->getValvula()->getTypeOfValve() == nmWasteGate) {
1586  BCWasteGate[contador] = BC[j];
1587  contador++;
1588  }
1589  } else if(BC[j]->getTipoCC() == nmUnionEntreDepositos) {
1590  if(dynamic_cast<TCCUnionEntreDepositos*>(BC[j])->getValvula()->getTypeOfValve() == nmWasteGate) {
1591  BCWasteGate[contador] = BC[j];
1592  contador++;
1593  }
1594  }
1595  }
1596  }
1597 
1598  if(NumberOfExternalCalculatedValves > 0) {
1599  CCCalcExtern = new TTipoValvula*[NumberOfExternalCalculatedValves];
1600  contador = 0;
1601  for(int j = 0; j < NumberOfConnections; j++) {
1602  if(BC[j]->getTipoCC() == nmPipeToPlenumConnection) {
1603  if(dynamic_cast<TCCDeposito*>(BC[j])->getValvula()->getTypeOfValve() == nmCalcExtern) {
1604  CCCalcExtern[contador] = dynamic_cast<TCCDeposito*>(BC[j])->getValvula();
1605  contador++;
1606  }
1607  } else if(BC[j]->getTipoCC() == nmUnionEntreDepositos) {
1608  if(dynamic_cast<TCCUnionEntreDepositos*>(BC[j])->getValvula()->getTypeOfValve() == nmCalcExtern) {
1609  CCCalcExtern[contador] = dynamic_cast<TCCDeposito*>(BC[j])->getValvula();
1610  contador++;
1611  }
1612  }
1613  }
1614  }
1615 
1616  if(NumberOfButerflyValves > 0) {
1617  BCButerflyValve = new TTipoValvula*[NumberOfButerflyValves];
1618  contador = 0;
1619  for(int j = 0; j < NumberOfConnections; j++) {
1620  if(BC[j]->getTipoCC() == nmPipeToPlenumConnection) {
1621  if(dynamic_cast<TCCDeposito*>(BC[j])->getValvula()->getTypeOfValve() == nmMariposa) {
1622  BCButerflyValve[contador] = dynamic_cast<TCCDeposito*>(BC[j])->getValvula();
1623  contador++;
1624  }
1625  } else if(BC[j]->getTipoCC() == nmUnionEntreDepositos) {
1626  if(dynamic_cast<TCCUnionEntreDepositos*>(BC[j])->getValvula()->getTypeOfValve() == nmMariposa) {
1627  BCButerflyValve[contador] = dynamic_cast<TCCDeposito*>(BC[j])->getValvula();
1628  contador++;
1629  }
1630  }
1631  }
1632  }
1633  if(NumTCCExternalConnection > 0) {
1634  BCExtConnectionVol = new TCCExternalConnectionVol*[NumTCCExternalConnection];
1635  bool *Asigned;
1636  Asigned = new bool[NumTCCExternalConnection];
1637 
1638  for(int i = 0; i < NumTCCExternalConnection; ++i) {
1639  Asigned[i] = false;
1640  }
1641 
1642  for(int i = 0; i < NumberOfConnections; ++i) {
1643  if(BC[i]->getTipoCC() == nmExternalConnection) {
1644  int ID = dynamic_cast<TCCExternalConnectionVol*>(BC[i])->GetID() - 1;
1645  if(Asigned[ID] == true) {
1646  std::cout << "ERROR: There are two external connection with the same ID" << std::endl;
1647  }
1648  Asigned[ID] = true;
1649 
1650  if(ID >= NumTCCExternalConnection) {
1651  std::cout << "ERROR: Wrong ID for the external connection node " << i << std::endl;
1652  }
1653  BCExtConnectionVol[ID] = dynamic_cast<TCCExternalConnectionVol*>(BC[i]);
1654  }
1655  }
1656  }
1657 
1658  } catch(exception & N) {
1659  std::cout << " ERROR : ReadConnections " << std::endl;
1660  std::cout << " Tipo de error : " << N.what() << std::endl;
1661  throw Exception(N.what());
1662  }
1663 }
1664 
1665 void TOpenWAM::ReadTurbochargerAxis() {
1666  try {
1667  fpos_t filepos;
1668 
1669  fscanf(FileInput, " %d ", &NumberOfAxis);
1670  if(NumberOfAxis != 0) {
1671  Axis = new TEjeTurbogrupo*[NumberOfAxis];
1672  }
1673  fgetpos(FileInput, &filepos);
1674  fclose(FileInput);
1675 
1676  if(NumberOfAxis != 0) {
1677  for(int i = 0; i < NumberOfAxis; ++i) {
1678  if(EngineBlock) {
1679  Axis[i] = new TEjeTurbogrupo(i, Engine[0]->getGeometria().NCilin);
1680  } else
1681  Axis[i] = new TEjeTurbogrupo(i, 0);
1682  Axis[i]->ReadTurbochargerAxis(fileinput.c_str(), filepos, Compressor, Turbine);
1683  Axis[i]->IniciaMedias();
1684  }
1685  }
1686 
1687  FileInput = fopen(fileinput.c_str(), "r");
1688  fsetpos(FileInput, &filepos);
1689  } catch(exception & N) {
1690  std::cout << " ERROR : ReadTurbochargerAxis " << std::endl;
1691  std::cout << " Tipo de error : " << N.what() << std::endl;
1692  throw Exception(N.what());
1693  }
1694 }
1695 
1696 void TOpenWAM::ReadSensors() {
1697  fpos_t filepos;
1698 
1699  fscanf(FileInput, " %d ", &NumberOfSensors);
1700 
1701  fgetpos(FileInput, &filepos);
1702  fclose(FileInput);
1703 
1704  if(NumberOfSensors > 0) {
1705  Sensor = new TSensor*[NumberOfSensors];
1706  for(int i = 0; i < NumberOfSensors; i++) {
1707  Sensor[i] = new TSensor(i);
1708  Sensor[i]->ReadSensor(fileinput.c_str(), filepos);
1709  Sensor[i]->IniciaMedias();
1710  }
1711  }
1712  FileInput = fopen(fileinput.c_str(), "r");
1713  fsetpos(FileInput, &filepos);
1714 }
1715 
1716 void TOpenWAM::ReadControllers() {
1717  int ctrl = 0;
1718  fpos_t filepos;
1719 
1720  fscanf(FileInput, " %d ", &NumberOfControllers);
1721  if(NumberOfControllers > 0) {
1722  Controller = new TController*[NumberOfControllers];
1723  for(int i = 0; i < NumberOfControllers; i++) {
1724  fscanf(FileInput, " %d ", &ctrl);
1725  switch(ctrl) {
1726  case 1:
1727  Controller[i] = new TPIDController(i);
1728  break;
1729  case 2:
1730  Controller[i] = new TTable1D(i);
1731  break;
1732  case 3:
1733  Controller[i] = new TDecisor(i);
1734  break;
1735  case 4:
1736  Controller[i] = new TGain(i);
1737  break;
1738  }
1739  fgetpos(FileInput, &filepos);
1740  fclose(FileInput);
1741  Controller[i]->LeeController(fileinput.c_str(), filepos);
1742  Controller[i]->IniciaMedias();
1743  FileInput = fopen(fileinput.c_str(), "r");
1744  fsetpos(FileInput, &filepos);
1745  }
1746  }
1747 }
1748 
1749 void TOpenWAM::ReadOutput(char* FileName) {
1750 
1751  fpos_t filepos;
1752  fgetpos(FileInput, &filepos);
1753  fclose(FileInput);
1754 
1755  Output = new TOutputResults();
1756 
1757  // OUTPUT ->
1758 #ifdef ParticulateFilter
1759  Output->ReadAverageResults(fileinput.c_str(), filepos, Pipe, EngineBlock, Engine,
1760  Plenum, Axis, Compressor, Turbine, BC, DPF, VolumetricCompressor,
1761  Venturi, Sensor, Controller, SimulationDuration, FileName);
1762 
1763  Output->ReadInstantaneousResults(fileinput.c_str(), filepos, Engine, Plenum, Pipe,
1764  Venturi, BC, DPF, Axis, Compressor, Turbine, VolumetricCompressor,
1765  BCWasteGate, NumberOfWasteGates, BCReedValve, NumberOfReedValves,
1766  Sensor, Controller, FileName);
1767 #else
1768  Output->ReadAverageResults(fileinput.c_str(), filepos, Pipe, EngineBlock, Engine, Plenum, Axis, Compressor, Turbine, BC,
1769  NULL, VolumetricCompressor, Venturi, Sensor, Controller,
1770  SimulationDuration, FileName);
1771 
1772  Output->ReadInstantaneousResults(fileinput.c_str(), filepos, Engine, Plenum, Pipe, Venturi, BC, NULL, Axis, Compressor,
1773  Turbine, VolumetricCompressor, BCWasteGate, NumberOfWasteGates, BCReedValve,
1774  NumberOfReedValves, Sensor, Controller, FileName);
1775 #endif
1776 
1777  Output->ReadSpaceTimeResults(fileinput.c_str(), filepos, Pipe, Engine, Plenum);
1778 
1779  FileInput = fopen(FileName, "r");
1780  fsetpos(FileInput, &filepos);
1781 }
1782 
1783 void TOpenWAM::InitializeParameters() {
1784 
1785  RunningControl();
1786 
1787  InitializeRunningAngles();
1788 
1789  CalculateNewHeatPositions();
1790 
1791  for(int j = 0; j < NumberOfPipes; ++j) {
1792  Pipe[j]->IniciaVariablesFundamentalesTubo();
1793  Pipe[j]->InicializaCaracteristicas(BC);
1794  Pipe[j]->IniciaVariablesTransmisionCalor(BC, Engine, AmbientTemperature);
1795  Pipe[j]->CalculaCoeficientePeliculaInterior(BC);
1796  Pipe[j]->EstabilidadMetodoCalculo();
1797  }
1798 #ifdef ParticulateFilter
1799  for(int i = 0; i < NumberOfDPF; i++) {
1800  DPF[i]->IniciaVariablesTransmisionCalor(AmbientTemperature);
1801  for(int j = 0; j < DPF[i]->getNumeroHacesCanales(); j++) {
1802  (DPF[i]->GetCanal(j, 0))->IniciaVariablesFundamentalesCanalDPF();
1803  (DPF[i]->GetCanal(j, 0))->InicializaCaracteristicas(BC);
1804  (DPF[i]->GetCanal(j, 0))->CalculaCoeficientePeliculaInterior();
1805  (DPF[i]->GetCanal(j, 1))->IniciaVariablesFundamentalesCanalDPF();
1806  (DPF[i]->GetCanal(j, 1))->InicializaCaracteristicas(BC);
1807  (DPF[i]->GetCanal(j, 1))->CalculaCoeficientePeliculaInterior();
1808  if(j == DPF[i]->getNumeroHacesCanales() - 1) {
1809  (DPF[i]->GetCanal(j, 0))->CalculaCoeficientePeliculaExterior
1810  (AmbientPressure);
1811  (DPF[i]->GetCanal(j, 1))->CalculaCoeficientePeliculaExterior
1812  (AmbientPressure);
1813  }
1814 #ifdef ConcentricElement
1815  DPF[i]->CalculoResistenciaTC_First_Time(j, Pipe, Concentric);
1816 #else
1817  DPF[i]->CalculoResistenciaTC_First_Time(j, Pipe, NULL);
1818 #endif
1819  }
1820 #ifdef ConcentricElement
1821  DPF[i]->InicializaDPF(NumberOfConcentrics, Concentric);
1822 #else
1823  DPF[i]->InicializaDPF(NumberOfConcentrics, NULL);
1824 #endif
1825  DPF[i]->CalculoEstabilidadDPF();
1826  }
1827 #endif
1828 
1829  FirstIteration = true;
1830 
1831 #ifdef ConcentricElement
1832  for(int i = 0; i < NumberOfConcentrics; i++) {
1833  Concentric[i]->CalculaResistenciasdePared(BC);
1834  }
1835 #endif
1836 
1837  if(!Independent) {
1838  for(int i = 0; i < NumberOfConnections; i++) {
1839  BC[i]->TuboCalculandose(10000);
1840  }
1841  }
1842 
1843  AllocateVGTData();
1844 
1845  for(int i = 0; i < NumberOfPlenums; i++) {
1846  if(Plenum[i]->getTipoDeposito() == nmDepVolVble) {
1847  dynamic_cast<TDepVolVariable*>(Plenum[i])->IniciaVolumen(Theta);
1848  }
1849  }
1850 
1851  if(EngineBlock) {
1852  for(int i = 0; i < NumberOfPlenums; i++) {
1853  if(Plenum[i]->getTipoDeposito() == nmDepVolVble) {
1854  dynamic_cast<TDepVolVariable*>(Plenum[i])->UpdateSpeed(Engine[0]->getRegimen());
1855  }
1856  }
1857 
1858  Engine[0]->IniciaVarCilindro();
1859  Engine[0]->AsignacionTuboRendVol(Pipe);
1860 
1861  if((Engine[0]->getNumTuboRendVol() > NumberOfPipes) || Engine[0]->getNumTuboRendVol() <= 0) {
1862  printf(" ERROR : The intake pipe selectec for calculating \n ");
1863  printf(" the volumetric efficieny is not correct(pipe n. %d)\n ", Engine[0]->getTuboRendVol()->getNumeroTubo());
1864  throw Exception(" ERROR : The pipe selected for calculating the volumetric efficiency is not correct ");
1865  }
1866  if(ThereIsDLL) {
1867  if(EXTERN->getmodcomb()) {
1868  for(int i = 0; i < Engine[0]->getGeometria().NCilin; i++) {
1869  Engine[0]->GetCilindro(i)->PutHayDLL(true);
1870  Engine[0]->GetCilindro(i)->PutModComb(true);
1871  }
1872  } else {
1873  for(int i = 0; i < Engine[0]->getGeometria().NCilin; i++) {
1874  Engine[0]->GetCilindro(i)->PutHayDLL(true);
1875  }
1876  }
1877 
1878  }
1879  for(int i = 0; i < Engine[0]->getGeometria().NCilin; i++) {
1880  Engine[0]->GetCilindro(i)->DefineCombustion();
1881  }
1882  }
1883  for(int i = 0; i < NumberOfCompressors; i++) {
1884  Compressor[i]->Initialize();
1885  }
1886 
1887  for(int i = 0; i < NumberOfAxis; i++) {
1888  Axis[i]->InterpolaValoresMapa();
1889  Axis[i]->InitizlizeHTM(AmbientTemperature);
1890  }
1891 
1892  for(int i = 0; i < NumberOfConnections; i++) {
1893  if(BC[i]->getTipoCC() == nmPipeToPlenumConnection) {
1894  dynamic_cast<TCCDeposito*>(BC[i])->IniciaGamma();
1895  }
1896  if(BC[i]->getTipoCC() == nmPipeToPlenumConnection && EngineBlock) {
1897  TTipoValvula* val = dynamic_cast<TCCDeposito*>(BC[i])->getValvula();
1898  if(val->getTypeOfValve() == nmDiscoRotativo) {
1899  dynamic_cast<TDiscoRotativo*>(val)->PutAngle0(Engine[0]->getTheta());
1900  }
1901  }
1902  }
1903 
1904  ThetaIni = Theta;
1905 }
1906 
1907 void TOpenWAM::RunningControl() {
1908  try {
1909  double regimenficticio = 0.;
1910 
1911  if(!EngineBlock) {
1912  /* No hay motor pero Theta controla el funcionamiento del WAM. DE MOMENTO (pedro,paco) */
1913  Run.CycleDuration = 720;
1914  regimenficticio = 720. / 6 / SimulationDuration;
1915  thmax = 720.;
1916  grmax = 0.;
1917  agincr *= 6. * regimenficticio;
1918 
1919  } else {
1920  Run.CycleDuration = Engine[0]->getAngTotalCiclo();
1921  thmax = SimulationDuration * Engine[0]->getAngTotalCiclo();
1922  grmax = thmax - Engine[0]->getAngTotalCiclo();
1923 
1924  }
1925  } catch(exception & N) {
1926  std::cout << " ERROR : RunningControl " << std::endl;
1927  std::cout << " Tipo de error : " << N.what() << std::endl;
1928  throw Exception(N.what());
1929  }
1930 }
1931 
1932 void TOpenWAM::InitializeRunningAngles() {
1933  try {
1934 
1935  if(!EngineBlock) {
1936  /* Inicio angulos de la ejecucion */
1937  Theta = 0.;
1938  } else {
1939  /* Inicio angulos de la ejecucion */
1940  Engine[0]->IniciaAnguloCalculo();
1941  Theta = Engine[0]->getTheta();
1942  }
1943 
1944  CrankAngle = Theta;
1945  Theta0 = 0.;
1946 
1947  } catch(exception & N) {
1948  std::cout << " ERROR : InitizalizeRunningAngles " << std::endl;
1949  std::cout << " Tipo de error : " << N.what() << std::endl;
1950  throw Exception(N.what());
1951  }
1952 }
1953 
1954 void TOpenWAM::AllocateVGTData() {
1955  try {
1956 
1957  CountVGT = 0;
1958  int tgv = 0;
1959  int entr = 0;
1960 
1961  StatorTurbine = new TEstatorTurbina * *[NumberOfTurbines];
1962  RotorTurbine = new TRotorTurbina*[NumberOfTurbines];
1963  for(int i = 0; i < NumberOfTurbines; i++) {
1964  StatorTurbine[i] = new TEstatorTurbina*[Turbine[i]->getNumeroEntradas()];
1965  for(int j = 0; j < NumberOfConnections; j++) {
1966  if(BC[j]->getTipoCC() == nmPipeToPlenumConnection) {
1967  if(dynamic_cast<TCCDeposito*>(BC[j])->getValvula()->getTypeOfValve() == nmStator) {
1968  if(dynamic_cast<TEstatorTurbina*>(dynamic_cast<TCCDeposito*>(BC[j])->getValvula())->getNumeroTurbina() == i + 1) {
1969  entr = dynamic_cast<TEstatorTurbina*>(dynamic_cast<TCCDeposito*>(BC[j])->getValvula())->getNumeroEntrada() - 1;
1970  StatorTurbine[i][entr] = dynamic_cast<TEstatorTurbina*>(dynamic_cast<TCCDeposito*>(BC[j])->getValvula());
1971  }
1972  } else if(dynamic_cast<TCCDeposito*>(BC[j])->getValvula()->getTypeOfValve() == nmRotor) {
1973  if(dynamic_cast<TRotorTurbina*>(dynamic_cast<TCCDeposito*>(BC[j])->getValvula())->getNumeroTurbina() == i + 1) {
1974  RotorTurbine[i] = dynamic_cast<TRotorTurbina*>(dynamic_cast<TCCDeposito*>(BC[j])->getValvula());
1975  if(RotorTurbine[i]->getTipoRotor() == nmRotVariable) {
1976  CountVGT += 1;
1977  }
1978  }
1979  }
1980  }
1981  }
1982  }
1983  if(CountVGT != 0) {
1984  DatosTGV = new stDatosTGV[CountVGT];
1985  for(int i = 0; i < NumberOfTurbines; i++) {
1986  if(RotorTurbine[i]->getTipoRotor() == nmRotVariable) {
1987  // En su momento asignar al objeto turbina correspondiente el namero de TGV que le corresponde.Falta hacer.26-12-05
1988  DatosTGV[tgv].Entradas = Turbine[i]->getNumeroEntradas();
1989  DatosTGV[tgv].Turbine = i;
1990  DatosTGV[tgv].Estator = new TTipoValvula*[Turbine[i]->getNumeroEntradas()];
1991  DatosTGV[tgv].Rendimiento = new double[Turbine[i]->getNumeroEntradas()];
1992  for(int j = 0; j < Turbine[i]->getNumeroEntradas(); ++j) {
1993  if(Turbine[i]->GetCCEntrada(j)->getTipoCC() == nmPipeToPlenumConnection) {
1994  DatosTGV[tgv].Estator[j] = dynamic_cast<TCCDeposito*>(Turbine[i]->GetCCEntrada(j))->getValvula();
1995  } else if(Turbine[i]->GetCCEntrada(j)->getTipoCC() == nmUnionEntreDepositos) {
1996  DatosTGV[tgv].Estator[j] = dynamic_cast<TCCUnionEntreDepositos*>(Turbine[i]->GetCCEntrada(j))->getValvula();
1997  }
1998  DatosTGV[tgv].Rendimiento[j] = 0;
1999  if(Turbine[i]->GetCCSalida(0)->getTipoCC() == nmPipeToPlenumConnection) {
2000  DatosTGV[tgv].Rotor = dynamic_cast<TCCDeposito*>(Turbine[i]->GetCCSalida(0))->getValvula();
2001  } else
2002  printf(" ERROR : Tubine output %d is not a connection plenum - pipe.", i + 1);
2003  tgv++;
2004  }
2005  Turbine[i]->AllocateDatosTGV(DatosTGV);
2006  }
2007  }
2008  }
2009  } catch(exception & N) {
2010  stringstream err;
2011  std::cout << " ERROR : AllocateVGTData " << std::endl;
2012  std::cout << " Tipo de error : " << N.what() << std::endl;
2013  err << " ERROR : dimensionado_tgvwam " << N.what();
2014  throw Exception(err.str());
2015  }
2016 }
2017 
2018 void TOpenWAM::ConnectFlowElements() {
2019 
2020  if(EngineBlock) {
2021 
2022  for(int i = 0; i < Engine[0]->getGeometria().NCilin; i++) {
2023  dynamic_cast<TCilindro*>(Engine[0]->GetCilindro(i))->AsignacionCC(BC, NumberOfConnections);
2024  }
2025  for(int i = 0; i < NumberOfConnections; i++) {
2026  if(BC[i]->getTipoCC() == nmIntakeValve || BC[i]->getTipoCC() == nmExhaustValve) {
2027  dynamic_cast<TCCCilindro*>(BC[i])->AsignaCilindro(Engine[0]);
2028  }
2029  }
2030  }
2031 
2032  for(int i = 0; i < NumberOfConnections; i++) {
2033  if(BC[i]->getTipoCC() == nmCompresor) {
2034  dynamic_cast<TCCCompresor*>(BC[i])->AsignData(Plenum, NumberOfPipes, Pipe, BC, NumberOfConnections,
2035  AtmosphericComposition, Compressor, AmbientTemperature, AmbientPressure);
2036  }
2037  }
2038 
2039  for(int i = 0; i < NumberOfPlenums; i++) {
2040  Plenum[i]->AsignacionCC(BC, NumberOfConnections);
2041  if(Plenum[i]->getTipoDeposito() == nmTurbinaSimple || Plenum[i]->getTipoDeposito() == nmTurbinaTwin) {
2042  dynamic_cast<TTurbina*>(Plenum[i])->AsignaEntradaSalidaCC();
2043  } else if(Plenum[i]->getTipoDeposito() == nmVenturi) {
2044  dynamic_cast<TVenturi*>(Plenum[i])->AsignaEntradaSalidaLateralCC();
2045  } else if(Plenum[i]->getTipoDeposito() == nmUnionDireccional) {
2046  dynamic_cast<TUnionDireccional*>(Plenum[i])->AsignaCCUnionDireccional();
2047  }
2048  }
2049 
2050  for(int i = 0; i < NumberOfConnections; i++) {
2051  if(BC[i]->getTipoCC() == nmPipeToPlenumConnection) {
2052  dynamic_cast<TCCDeposito*>(BC[i])->AsignaDeposito(Plenum);
2053  } else if(BC[i]->getTipoCC() == nmUnionEntreDepositos) {
2054  dynamic_cast<TCCUnionEntreDepositos*>(BC[i])->AsignaDepositos(Plenum);
2055  }
2056  }
2057 
2058  for(int i = 0; i < NumberOfPipes; i++) {
2059  Pipe[i]->ComunicacionTubo_CC(BC);
2060  }
2061 
2062  for(int i = 0; i < NumberOfCompressors; i++) {
2063  Compressor[i]->AsignAcousticElements(Pipe, Plenum);
2064  }
2065 
2066  for(int i = 0; i < NumberOfTurbines; i++) {
2067  Turbine[i]->AsignAcousticElements(Pipe);
2068  }
2069 
2070 #ifdef ParticulateFilter
2071  for(int i = 0; i < NumberOfDPF; i++) {
2072  for(int j = 0; j < DPF[i]->getNumeroHacesCanales(); j++) {
2073  DPF[i]->GetCanal(j, 0)->ComunicacionCanal_CC(BC);
2074  DPF[i]->GetCanal(j, 1)->ComunicacionCanal_CC(BC);
2075  }
2076  DPF[i]->ComunicacionTubos(BC, NumberOfConnections);
2077  }
2078 #endif
2079 }
2080 
2081 void TOpenWAM::ConnectControlElements() {
2082  int ID = 0;
2083 
2084  // Asign elements to sensor
2085  for(int i = 0; i < NumberOfSensors; i++) {
2086 
2087  switch(Sensor[i]->ObjectSensed()) {
2088  case nmSensTubo:
2089  ID = Sensor[i]->ObjectID();
2090  Sensor[i]->AsignaObjeto((TObject*) Pipe[ID - 1]);
2091  break;
2092  case nmSensDeposito:
2093  ID = Sensor[i]->ObjectID();
2094  Sensor[i]->AsignaObjeto((TObject*) Plenum[ID - 1]);
2095  break;
2096  case nmSensMotor:
2097  Sensor[i]->AsignaObjeto((TObject*) Engine[0]);
2098  break;
2099  }
2100  }
2101 
2102  // Asign output sensor to controllers
2103  for(int i = 0; i < NumberOfControllers; ++i) {
2104  Controller[i]->AsignaObjetos(Sensor, Controller);
2105  }
2106 
2107  // Asign controllers to elments.
2108  for(int i = 0; i < NumberOfTurbines; i++) {
2109  Turbine[i]->AsignaRackController(Controller);
2110  }
2111  for(int i = 0; i < NumberOfButerflyValves; i++) {
2112  dynamic_cast<TMariposa*>(BCButerflyValve[i])->AsignaLevController(Controller);
2113  }
2114  for(int i = 0; i < NumberOfIntakeValves; i++) {
2115  if(dynamic_cast<TCCCilindro*>(BCIntakeValve[i])->getValvula()->getTypeOfValve() == nmValvula4T) {
2116  dynamic_cast<TValvula4T*>(dynamic_cast<TCCCilindro*>(BCIntakeValve[i])->getValvula())->AsignaLevController(Controller);
2117  }
2118  }
2119  for(int i = 0; i < NumberOfExhaustValves; i++) {
2120  if(dynamic_cast<TCCCilindro*>(BCExhaustValve[i])->getValvula()->getTypeOfValve() == nmValvula4T) {
2121  dynamic_cast<TValvula4T*>(dynamic_cast<TCCCilindro*>(BCExhaustValve[i])->getValvula())->AsignaLevController(Controller);
2122  }
2123  }
2124 
2125  if(EngineBlock) {
2126  Engine[0]->AsignRPMController(Controller);
2127  Engine[0]->AsignMfController(Controller);
2128  }
2129 
2130  if(NumberOfAxis > 0)
2131  Axis[0]->AsignaRPMController(Controller);
2132 }
2133 
2134 void TOpenWAM::InitialHeatTransferParameters() {
2135 
2136  CalculateNewHeatPositions();
2137 
2138  for(int i = 0; i < NumberOfPipes; i++) {
2139  Pipe[i]->IniciaVariablesTransmisionCalor(BC, Engine, AmbientTemperature);
2140  Pipe[i]->CalculaCoeficientePeliculaInterior(BC);
2141  }
2142 #ifdef ParticulateFilter
2143  for(int i = 0; i < NumberOfDPF; i++) {
2144  DPF[i]->IniciaVariablesTransmisionCalor(AmbientTemperature);
2145  for(int j = 0; j < DPF[i]->getNumeroHacesCanales(); j++) {
2146  (DPF[i]->GetCanal(j, 0))->CalculaCoeficientePeliculaInterior();
2147  (DPF[i]->GetCanal(j, 1))->CalculaCoeficientePeliculaInterior();
2148  if(j == DPF[i]->getNumeroHacesCanales() - 1) {
2149  (DPF[i]->GetCanal(j, 0))->CalculaCoeficientePeliculaExterior
2150  (AmbientPressure);
2151  (DPF[i]->GetCanal(j, 1))->CalculaCoeficientePeliculaExterior
2152  (AmbientPressure);
2153  }
2154 #ifdef ConcentricElement
2155  DPF[i]->CalculoResistenciaTC_First_Time(j, Pipe, Concentric);
2156 #else
2157  DPF[i]->CalculoResistenciaTC_First_Time(j, Pipe, NULL);
2158 #endif
2159  }
2160 
2161  }
2162 #endif
2163 }
2164 
2165 void TOpenWAM::CalculateNewHeatPositions()
2166 
2167 {
2168  try {
2169  int NodoOrigen = 0;
2170  int NodoFin = 0;
2171  bool Encontrado = false;
2172 
2173  for(int i = 0; i < NumberOfConnections; i++) {
2174  if(BC[i]->getTipoCC() == nmExhaustValve) {
2175  BC[i]->PutPosicionNodo(0.);
2176  } else {
2177  BC[i]->PutPosicionNodo(100000.);
2178  }
2179  }
2180 
2181  for(int i = 0; i < NumberOfExhaustValves; i++) {
2182  NodoOrigen = BCExhaustValve[i]->getNumeroCC();
2183 
2184  // PIPES
2185  for(int j = 0; j < NumberOfPipes; j++) {
2186  if(Pipe[j]->getNodoDer() == NodoOrigen) {
2187  NodoFin = Pipe[j]->getNodoIzq();
2188  Encontrado = true;
2189  } else if(Pipe[j]->getNodoIzq() == NodoOrigen) {
2190  NodoFin = Pipe[j]->getNodoDer();
2191  Encontrado = true;
2192  }
2193  if(Encontrado) {
2194  CalculateDistance(NodoOrigen, NodoFin, Pipe[j]->getLongitudTotal(), NumberOfPlenums, NumberOfPipes, NumberOfConnections,
2195  Pipe, BC);
2196  }
2197  Encontrado = false;
2198  }
2199 
2200  // PLENUMS
2201  for(int i = 0; i < NumberOfPlenums; i++) {
2202  if(BC[NodoOrigen - 1]->getTipoCC() == nmPipeToPlenumConnection) {
2203  if(dynamic_cast<TCCDeposito*>(BC[NodoOrigen - 1])->getNumeroDeposito() == i + 1) {
2204  for(int k = 0; k < NumberOfConnections; k++) {
2205  if(BC[k]->getTipoCC() == nmPipeToPlenumConnection) {
2206  if(dynamic_cast<TCCDeposito*>(BC[NodoOrigen - 1])->getNumeroDeposito() == dynamic_cast<TCCDeposito*>
2207  (BC[k])->getNumeroDeposito()) {
2208  NodoFin = k + 1;
2209  CalculateDistance(NodoOrigen, NodoFin, 0., NumberOfPlenums, NumberOfPipes, NumberOfConnections, Pipe, BC);
2210  }
2211  }
2212  if(BC[k]->getTipoCC() == nmUnionEntreDepositos) {
2213  if(dynamic_cast<TCCDeposito*>(BC[NodoOrigen - 1])->getNumeroDeposito() == dynamic_cast<TCCUnionEntreDepositos*>
2214  (BC[k])->getNumeroDeposito1()
2215  || dynamic_cast<TCCDeposito*>(BC[NodoOrigen - 1])->getNumeroDeposito() == dynamic_cast<TCCUnionEntreDepositos*>
2216  (BC[k])->getNumeroDeposito2()) {
2217  NodoFin = k + 1;
2218  CalculateDistance(NodoOrigen, NodoFin, 0., NumberOfPlenums, NumberOfPipes, NumberOfConnections, Pipe, BC);
2219  }
2220  }
2221  }
2222  }
2223  }
2224  if(BC[NodoOrigen - 1]->getTipoCC() == nmUnionEntreDepositos) {
2225  if(dynamic_cast<TCCUnionEntreDepositos*>(BC[NodoOrigen - 1])->getNumeroDeposito1() == i + 1) {
2226  for(int k = 0; k < NumberOfConnections; k++) {
2227  if(BC[k]->getTipoCC() == nmPipeToPlenumConnection) {
2228  if(dynamic_cast<TCCUnionEntreDepositos*>(BC[NodoOrigen - 1])->getNumeroDeposito1() == dynamic_cast<TCCDeposito*>
2229  (BC[k])->getNumeroDeposito()) {
2230  NodoFin = k + 1;
2231  CalculateDistance(NodoOrigen, NodoFin, 0., NumberOfPlenums, NumberOfPipes, NumberOfConnections, Pipe, BC);
2232  }
2233  }
2234  if(BC[k]->getTipoCC() == nmUnionEntreDepositos) {
2235  if(dynamic_cast<TCCUnionEntreDepositos*>(BC[NodoOrigen - 1])->getNumeroDeposito1() ==
2236  dynamic_cast<TCCUnionEntreDepositos*>(BC[k])->getNumeroDeposito1()
2237  || dynamic_cast<TCCUnionEntreDepositos*>(BC[NodoOrigen - 1])->getNumeroDeposito1() ==
2238  dynamic_cast<TCCUnionEntreDepositos*>(BC[k])->getNumeroDeposito2()) {
2239  NodoFin = k + 1;
2240  CalculateDistance(NodoOrigen, NodoFin, 0., NumberOfPlenums, NumberOfPipes, NumberOfConnections, Pipe, BC);
2241  }
2242  }
2243  }
2244  } else if(dynamic_cast<TCCUnionEntreDepositos*>(BC[NodoOrigen - 1])->getNumeroDeposito2() == i + 1) {
2245  for(int k = 0; k < NumberOfConnections; k++) {
2246  if(BC[k]->getTipoCC() == nmPipeToPlenumConnection) {
2247  if(dynamic_cast<TCCUnionEntreDepositos*>(BC[NodoOrigen - 1])->getNumeroDeposito2() == dynamic_cast<TCCDeposito*>
2248  (BC[k])->getNumeroDeposito()) {
2249  NodoFin = k + 1;
2250  CalculateDistance(NodoOrigen, NodoFin, 0., NumberOfPlenums, NumberOfPipes, NumberOfConnections, Pipe, BC);
2251  }
2252  }
2253  if(BC[k]->getTipoCC() == nmUnionEntreDepositos) {
2254  if(dynamic_cast<TCCUnionEntreDepositos*>(BC[NodoOrigen - 1])->getNumeroDeposito2() ==
2255  dynamic_cast<TCCUnionEntreDepositos*>(BC[k])->getNumeroDeposito1()
2256  || dynamic_cast<TCCUnionEntreDepositos*>(BC[NodoOrigen - 1])->getNumeroDeposito2() ==
2257  dynamic_cast<TCCUnionEntreDepositos*>(BC[k])->getNumeroDeposito2()) {
2258  NodoFin = k + 1;
2259  CalculateDistance(NodoOrigen, NodoFin, 0., NumberOfPlenums, NumberOfPipes, NumberOfConnections, Pipe, BC);
2260  }
2261  }
2262  }
2263  }
2264  }
2265  }
2266  }
2267 
2268  } catch(exception & N) {
2269  std::cout << " ERROR : CalculateNewHeatPositions " << std::endl;
2270  std::cout << " Tipo de error : " << N.what() << std::endl;
2271  throw Exception(N.what());
2272  }
2273 }
2274 
2275 void TOpenWAM::CalculateDistance(int LNodoOrigen, int LNodoFin, double LLongitud, int LNumberOfPlenums,
2276  int LNumberOfPipes, int LNumberOfConnections, TTubo **LPipe, TCondicionContorno **LBC) {
2277 
2278  try {
2279  int NodoOrigen1 = 0, NodoFin1 = 0;
2280  double Long = 0.;
2281 
2282  int j = SelectPipe(LPipe, LNumberOfPipes, LNodoOrigen, LNodoFin);
2283  if(LPipe[j]->getTipoTransCal() == 3 || LLongitud == 0.)
2284  Long = 0.;
2285  else
2286  Long = LLongitud;
2287 
2288  if(LBC[LNodoFin - 1]->getPosicionNodo() > LBC[LNodoOrigen - 1]->getPosicionNodo() + Long) {
2289  LBC[LNodoFin - 1]->PutPosicionNodo(LBC[LNodoOrigen - 1]->getPosicionNodo() + Long);
2290 
2291  // PIPES
2292  for(int i = 0; i < LNumberOfPipes; i++) {
2293  if(LPipe[i]->getNodoDer() == LNodoFin && LPipe[i]->getNodoIzq() != LNodoOrigen) {
2294  NodoOrigen1 = LNodoFin;
2295  NodoFin1 = LPipe[i]->getNodoIzq();
2296  CalculateDistance(NodoOrigen1, NodoFin1, LPipe[i]->getLongitudTotal(), LNumberOfPlenums, LNumberOfPipes,
2297  LNumberOfConnections, LPipe, LBC);
2298  } else if(LPipe[i]->getNodoIzq() == LNodoFin && LPipe[i]->getNodoDer() != LNodoOrigen) {
2299  NodoOrigen1 = LNodoFin;
2300  NodoFin1 = LPipe[i]->getNodoDer();
2301  CalculateDistance(NodoOrigen1, NodoFin1, LPipe[i]->getLongitudTotal(), LNumberOfPlenums, LNumberOfPipes,
2302  LNumberOfConnections, LPipe, LBC);
2303  }
2304  }
2305 
2306  // PLENUMS
2307  for(int i = 0; i < LNumberOfPlenums; i++) {
2308  if(LBC[LNodoOrigen - 1]->getTipoCC() == nmPipeToPlenumConnection) {
2309  if(dynamic_cast<TCCDeposito*>(LBC[LNodoOrigen - 1])->getNumeroDeposito() == i + 1) {
2310  for(int k = 0; k < LNumberOfConnections; k++) {
2311  if(LBC[k]->getTipoCC() == nmPipeToPlenumConnection) {
2312  if(dynamic_cast<TCCDeposito*>(LBC[LNodoOrigen - 1])->getNumeroDeposito() == dynamic_cast<TCCDeposito*>
2313  (LBC[k])->getNumeroDeposito()) {
2314  NodoOrigen1 = LNodoFin;
2315  NodoFin1 = k + 1;
2316  CalculateDistance(NodoOrigen1, NodoFin1, 0, LNumberOfPlenums, LNumberOfPipes, LNumberOfConnections, LPipe, LBC);
2317  }
2318  }
2319  if(LBC[k]->getTipoCC() == nmUnionEntreDepositos) {
2320  if(dynamic_cast<TCCDeposito*>(LBC[LNodoOrigen - 1])->getNumeroDeposito() == dynamic_cast<TCCUnionEntreDepositos*>
2321  (LBC[k])->getNumeroDeposito1()
2322  || dynamic_cast<TCCDeposito*>(LBC[LNodoOrigen - 1])->getNumeroDeposito() == dynamic_cast<TCCUnionEntreDepositos*>
2323  (LBC[k])->getNumeroDeposito2()) {
2324  NodoOrigen1 = LNodoFin;
2325  NodoFin1 = k + 1;
2326  CalculateDistance(NodoOrigen1, NodoFin1, 0, LNumberOfPlenums, LNumberOfPipes, LNumberOfConnections, LPipe, LBC);
2327  }
2328  }
2329  }
2330  }
2331 
2332  }
2333  if(LBC[LNodoOrigen - 1]->getTipoCC() == nmUnionEntreDepositos) {
2334  if(dynamic_cast<TCCUnionEntreDepositos*>(LBC[LNodoOrigen - 1])->getNumeroDeposito1() == i + 1) {
2335  for(int k = 0; k < LNumberOfConnections; k++) {
2336  if(LBC[k]->getTipoCC() == nmPipeToPlenumConnection) {
2337  if(dynamic_cast<TCCUnionEntreDepositos*>(LBC[LNodoOrigen - 1])->getNumeroDeposito1() == dynamic_cast<TCCDeposito*>
2338  (LBC[k])->getNumeroDeposito()) {
2339  NodoOrigen1 = LNodoFin;
2340  NodoFin1 = k + 1;
2341  CalculateDistance(NodoOrigen1, NodoFin1, 0, LNumberOfPlenums, LNumberOfPipes, LNumberOfConnections, LPipe, LBC);
2342  }
2343  }
2344  if(LBC[k]->getTipoCC() == nmUnionEntreDepositos) {
2345  if(dynamic_cast<TCCUnionEntreDepositos*>(LBC[LNodoOrigen - 1])->getNumeroDeposito1() ==
2346  dynamic_cast<TCCUnionEntreDepositos*>(LBC[k])->getNumeroDeposito1()
2347  || dynamic_cast<TCCUnionEntreDepositos*>(LBC[LNodoOrigen - 1])->getNumeroDeposito1() ==
2348  dynamic_cast<TCCUnionEntreDepositos*>(LBC[k])->getNumeroDeposito2()) {
2349  NodoOrigen1 = LNodoFin;
2350  NodoFin1 = k + 1;
2351  CalculateDistance(NodoOrigen1, NodoFin1, 0, LNumberOfPlenums, LNumberOfPipes, LNumberOfConnections, LPipe, LBC);
2352  }
2353  }
2354  }
2355  } else if(dynamic_cast<TCCUnionEntreDepositos*>(LBC[LNodoOrigen - 1])->getNumeroDeposito2() == i + 1) {
2356  for(int k = 0; k < LNumberOfConnections; k++) {
2357  if(LBC[k]->getTipoCC() == nmPipeToPlenumConnection) {
2358  if(dynamic_cast<TCCUnionEntreDepositos*>(LBC[LNodoOrigen - 1])->getNumeroDeposito2() == dynamic_cast<TCCDeposito*>
2359  (LBC[k])->getNumeroDeposito()) {
2360  NodoOrigen1 = LNodoFin;
2361  NodoFin1 = k + 1;
2362  CalculateDistance(NodoOrigen1, NodoFin1, 0, LNumberOfPlenums, LNumberOfPipes, LNumberOfConnections, LPipe, LBC);
2363  }
2364  }
2365  if(LBC[k]->getTipoCC() == nmUnionEntreDepositos) {
2366  if(dynamic_cast<TCCUnionEntreDepositos*>(LBC[LNodoOrigen - 1])->getNumeroDeposito2() ==
2367  dynamic_cast<TCCUnionEntreDepositos*>(LBC[k])->getNumeroDeposito1()
2368  || dynamic_cast<TCCUnionEntreDepositos*>(LBC[LNodoOrigen - 1])->getNumeroDeposito2() ==
2369  dynamic_cast<TCCUnionEntreDepositos*>(LBC[k])->getNumeroDeposito2()) {
2370  NodoOrigen1 = LNodoFin;
2371  NodoFin1 = k + 1;
2372  CalculateDistance(NodoOrigen1, NodoFin1, 0, LNumberOfPlenums, LNumberOfPipes, LNumberOfConnections, LPipe, LBC);
2373  }
2374  }
2375  }
2376  }
2377  }
2378 
2379  }
2380  }
2381  } catch(exception & N) {
2382  std::cout << " ERROR : CalculateDistance " << std::endl;
2383  std::cout << " Tipo de error : " << N.what() << std::endl;
2384  throw Exception(N.what());
2385  }
2386 }
2387 
2388 int TOpenWAM::SelectPipe(TTubo **LPipe, int LNumberOfPipes, int Lnodo1, int Lnodo2) {
2389 
2390  for(int i = 0; i < LNumberOfPipes; i++) {
2391  if((LPipe[i]->getNodoDer() == Lnodo1 && LPipe[i]->getNodoIzq() == Lnodo2) || (LPipe[i]->getNodoDer() == Lnodo2
2392  && LPipe[i]->getNodoIzq() == Lnodo1)) {
2393  return i;
2394  }
2395  }
2396  return 0;
2397 
2398 }
2399 
2400 void TOpenWAM::Progress() {
2401  Percentage = (float)((Theta - ThetaIni) / (thmax - ThetaIni) * 100.);
2402  Increment = int(Percentage);
2403  if(Increment > Steps) {
2404  std::cout << std::endl;
2405  std::cout << "===================================" << std::endl;
2406  std::cout << "Progress : " << Percentage << "% " << std::endl;
2407  std::cout << "-----------------------------------" << std::endl;
2408 
2409 #ifdef gestorcom
2410  if(GestorWAM != NULL)
2411  GestorWAM->ProcesoTranscurrido(Percentage);
2412 #endif
2413  ++Steps;
2414  ftime(&current);
2415  float tiempoac = (current.time - begining.time) * 1000 + (current.millitm - begining.millitm);
2416  float tiempoest = tiempoac * 100 / Percentage - tiempoac;
2417  int seg = int(tiempoest / 1000.);
2418  int min = int(seg / 60.);
2419  int hor = int(min / 60.);
2420  int mil = int(tiempoest) - seg * 1000;
2421  seg = seg - min * 60;
2422  min = min - hor * 60;
2423  printf("Time left to the end: %d:%02d:%02d,%03d \n", hor, min, seg, mil);
2424  std::cout << "===================================" << std::endl;
2425  std::cout << std::endl;
2426  }
2427 }
2428 
2429 void TOpenWAM::DetermineTimeStepIndependent() {
2430 
2431  MethodStability();
2432 
2433  StudyInflowOutflowMass();
2434 
2435  FixTimeStep();
2436 
2437  RecalculateStability();
2438 
2439 }
2440 
2441 void TOpenWAM::DetermineTimeStepCommon() {
2442 
2443  MethodStability();
2444 
2445  SearchMinimumTimeStep();
2446 
2447  if(JCurrent != -2) {
2448  TimeEndStep = Pipe[JCurrent]->getTime1();
2449 
2450  Run.TimeStep = Pipe[JCurrent]->getTime1() - Pipe[JCurrent]->getTime0();
2451  } else {
2452 #ifdef ParticulateFilter
2453  TimeEndStep = DPF[JCurrentDPF]->getTime1DPF();
2454  Run.TimeStep = DPF[JCurrentDPF]->getTime1DPF() - DPF[JCurrentDPF]
2455  ->getTime0DPF();
2456 #endif
2457  }
2458  for(int j = 0; j < NumberOfPipes; j++) {
2459  Pipe[j]->AjustaPaso(TimeEndStep);
2460  }
2461 #ifdef ParticulateFilter
2462  for(int j = 0; j < NumberOfDPF; j++) {
2463  DPF[j]->AjustaPaso(TimeEndStep);
2464  }
2465 #endif
2466  StudyInflowOutflowMass();
2467 
2468  FixTimeStep();
2469 
2470 }
2471 
2472 void TOpenWAM::DetermineTimeStep(double t) {
2473 
2474  MethodStability();
2475 
2476  SearchMinimumTimeStep();
2477 
2478  TimeEndStep = Pipe[JCurrent]->getTime1();
2479 
2480  Run.TimeStep = Pipe[JCurrent]->getTime1() - Pipe[JCurrent]->getTime0();
2481 
2482  for(int j = 0; j < NumberOfPipes; j++) {
2483  Pipe[j]->AjustaPaso(TimeEndStep);
2484  }
2485 
2486  StudyInflowOutflowMass();
2487 
2488  FixTimeStepExternal(t - Pipe[JCurrent]->getTime0());
2489 
2490 }
2491 
2492 void TOpenWAM::MethodStability() {
2493  double TiempoFinPaso0 = 0.;
2494 
2495  TiempoFinPaso0 = TimeEndStep;
2496 
2497  for(int j = 0; j < NumberOfPipes; j++) {
2498  if(Pipe[j]->getTime1() >= TimeEndStep) {
2499  TimeEndStep = Pipe[j]->getTime1();
2500  PipeStepMax = true;
2501  JStepMax = j;
2502  }
2503  DPFStepMax = false;
2504  JStepMaxDPF = -1;
2505  }
2506 
2507 #ifdef ParticulateFilter
2508  for(int j = 0; j < NumberOfDPF; j++) {
2509  if(DPF[j]->getTime1DPF() >= TimeEndStep) {
2510  TimeEndStep = DPF[j]->getTime1DPF();
2511  JStepMaxDPF = j;
2512  DPFStepMax = true;
2513  PipeStepMax = false;
2514  JStepMax = -1;
2515  }
2516  }
2517 #endif
2518 
2519 #ifdef ConcentricElement
2520  for(int j = 0; j < NumberOfConcentrics; j++) {
2521  if(Concentric[j]->GetHayDPF()) {
2522  if(Concentric[j]->GetTiempoDPF() > Concentric[j]->GetTiempo(0)) {
2523  Concentric[j]->PutTiempoDPF(Concentric[j]->GetTiempo(0));
2524  } else {
2525  Concentric[j]->PutTiempo(0, Concentric[j]->GetTiempoDPF());
2526  }
2527  } else {
2528  if(Concentric[j]->GetTiempo(0) > Concentric[j]->GetTiempo(1)) {
2529  Concentric[j]->PutTiempo(0, Concentric[j]->GetTiempo(1));
2530  } else {
2531  Concentric[j]->PutTiempo(1, Concentric[j]->GetTiempo(0));
2532  }
2533  }
2534  }
2535 #endif
2536 
2537  Run.TimeStep = TimeEndStep - TiempoFinPaso0;
2538  FirstIteration = false;
2539 
2540 }
2541 
2542 void TOpenWAM::SearchMinimumTimeStep() {
2543 
2544  double TMinimo = 1e5;
2545  if(PipeStepMax) {
2546  TMinimo = Pipe[JStepMax]->getTime1();
2547  JCurrent = JStepMax;
2548  JCurrentDPF = -2;
2549  TimeMinPipe = true;
2550  TimeMinDPF = false;
2551  } else {
2552 #ifdef ParticulateFilter
2553  TMinimo = DPF[JStepMaxDPF]->getTime1DPF();
2554  JCurrentDPF = JStepMaxDPF;
2555  JCurrent = -2;
2556  TimeMinPipe = false;
2557  TimeMinDPF = true;
2558 #endif
2559  }
2560 
2561  for(int j = NumberOfPipes - 1; j >= 0; j--) {
2562  if(Pipe[j]->getTime1() <= TMinimo && j != JStepMax) {
2563  TMinimo = Pipe[j]->getTime1();
2564  JCurrent = j;
2565  JCurrentDPF = -2;
2566  TimeMinPipe = true;
2567  TimeMinDPF = false;
2568  }
2569  }
2570 #ifdef ParticulateFilter
2571  for(int j = 0; j < NumberOfDPF; j++) {
2572  if(DPF[j]->getTime1DPF() <= TMinimo && j != JStepMaxDPF) {
2573  TMinimo = DPF[j]->getTime1DPF();
2574  JCurrent = -2;
2575  JCurrentDPF = j;
2576  TimeMinPipe = false;
2577  TimeMinDPF = true;
2578  }
2579  }
2580 #endif
2581 }
2582 
2583 void TOpenWAM::StudyInflowOutflowMass() {
2584  try {
2585  double smadd = 0, cociente, gasta = 0, gaste = 0;
2586  int i = 0;
2587  bool masacil, masadep;
2588  double TMinimo = 0.;
2589  DeltaTPlenums = Run.TimeStep;
2590  cociente = 0.;
2591 
2592  do {
2593  masacil = true;
2594  masadep = true;
2595 
2596  i = 0;
2597  if(EngineBlock) {
2598  do {
2599  gasta = 0.;
2600  for(int j = 0; j < Engine[0]->GetCilindro(i)->getNumeroUnionesAdm(); ++j) {
2601  gasta += dynamic_cast<TCCCilindro*>(Engine[0]->GetCilindro(i)->GetCCValvulaAdm(j))->getMassflow();
2602  }
2603  gaste = 0.;
2604  for(int j = 0; j < Engine[0]->GetCilindro(i)->getNumeroUnionesEsc(); ++j) {
2605  gaste += dynamic_cast<TCCCilindro*>(Engine[0]->GetCilindro(i)->GetCCValvulaEsc(j))->getMassflow();
2606  }
2607  if((Engine[0]->GetCilindro(i)->getMasa() - DeltaTPlenums * (gasta + gaste)) * 1e3 <= 1e-4) {
2608  masacil = false;
2609  }
2610  ++i;
2611  } while(masacil && i < Engine[0]->getGeometria().NCilin);
2612  }
2613  if(masacil && NumberOfPlenums != 0) {
2614 
2615  i = 0;
2616  do {
2617  SearchMinimumTime(i + 1, &TMinimo, Plenum);
2618  smadd = Plenum[i]->CriterioEstabilidad(TMinimo);
2619  for(int j = 0; j < NumberOfPlenums; j++) {
2620  Plenum[j]->PutRealizado(false);
2621  }
2622  if(smadd * 1e3 <= 1e-4) {
2623  masadep = false;
2624  printf(" WARNING : Plenum %d with critical conditions \n ", i + 1);
2625  }
2626  cociente = smadd / Plenum[i]->getMasa();
2627  ++i;
2628  } while(masadep && i < NumberOfPlenums && cociente < 2.);
2629  }
2630  if(!masacil || !masadep || (cociente >= 2.)) {
2631  if(!masacil)
2632  printf(" WARNING : there is no mass in the cylinder \n ");
2633  if(!masadep)
2634  printf(" WARNING : there is no mass in the plenum \n ");
2635  if(cociente >= 2.)
2636  printf(" WARNING::Mass increment in a plenum too big \n ");
2637  std::cout << " Time step reduction in Theta = " << Theta << std::endl;
2638  std::cout << " Original time step : " << DeltaTPlenums << std::endl;
2639  DeltaTPlenums *= .95;
2640  std::cout << " New time step : " << DeltaTPlenums << std::endl;
2641  if(DeltaTPlenums <= 2e-7) {
2642  if(cociente >= 2)
2643  printf(" ERROR : plenum n. %d too small \n ", i + 1);
2644  printf(" ERROR : in time step \n ");
2645  throw Exception(" ERROR : in time step ");
2646  }
2647  }
2648  } while(!masacil || !masadep || (cociente >= 2.));
2649  } catch(exception & N) {
2650  std::cout << " ERROR : StudyInflowOutflowMass " << std::endl;
2651  std::cout << " Tipo de error : " << N.what() << std::endl;
2652  throw Exception(N.what());
2653  }
2654 }
2655 
2656 void TOpenWAM::SearchMinimumTime(int LNumDepInicial, double *LTMinimo, TDeposito **LPlenum) {
2657  try {
2658  int NumDepSiguiente = 0;
2659 
2660  *LTMinimo = 100000.;
2661 
2662  if(!LPlenum[LNumDepInicial - 1]->getEstudioEstabilidadRealizado()) {
2663  if(LPlenum[LNumDepInicial - 1]->getNUniones() != 0) {
2664  for(int i = 0; i < LPlenum[LNumDepInicial - 1]->getNUniones(); i++) {
2665  if(LPlenum[LNumDepInicial - 1]->GetCCDeposito(i)->getUnionDPF()) {
2666 #ifdef ParticulateFilter
2667  if(LPlenum[LNumDepInicial - 1]->GetCCDeposito(i)
2668  ->GetTuboExtremo(0).DPF->getTime1DPF()
2669  < *LTMinimo) {
2670  *LTMinimo = LPlenum[LNumDepInicial - 1]
2671  ->GetCCDeposito(i)->GetTuboExtremo(0)
2672  .DPF->getTime1DPF();
2673  }
2674 #endif
2675  } else {
2676  if(LPlenum[LNumDepInicial - 1]->GetCCDeposito(i)->GetTuboExtremo(0).Pipe->getTime1() < *LTMinimo) {
2677  *LTMinimo = LPlenum[LNumDepInicial - 1]->GetCCDeposito(i)->GetTuboExtremo(0).Pipe->getTime1();
2678  }
2679  }
2680  }
2681  }
2682  }
2683  LPlenum[LNumDepInicial - 1]->PutRealizado(true);
2684 
2685  if(LPlenum[LNumDepInicial - 1]->getNUnionesED() != 0) {
2686  for(int j = 0; j < LPlenum[LNumDepInicial - 1]->getNUnionesED(); j++) {
2687  if(LPlenum[LNumDepInicial - 1]->GetCCUnionEntreDep(j)->getTipoCC() == nmUnionEntreDepositos) {
2688 
2689  if(dynamic_cast<TCCUnionEntreDepositos*>(LPlenum[LNumDepInicial - 1]->GetCCUnionEntreDep(
2690  j))->getNumeroDeposito1() == LNumDepInicial) {
2691  NumDepSiguiente = dynamic_cast<TCCUnionEntreDepositos*>(LPlenum[LNumDepInicial - 1]->GetCCUnionEntreDep(
2692  j))->getNumeroDeposito2();
2693  } else
2694  NumDepSiguiente = dynamic_cast<TCCUnionEntreDepositos*>(LPlenum[LNumDepInicial - 1]->GetCCUnionEntreDep(
2695  j))->getNumeroDeposito1();
2696 
2697  }
2698  if(LPlenum[LNumDepInicial - 1]->GetCCUnionEntreDep(j)->getTipoCC() == nmCompresor) {
2699  if(dynamic_cast<TCCCompresor*>(LPlenum[LNumDepInicial - 1]->GetCCUnionEntreDep(j))->getNumeroDepositoRot() ==
2700  LNumDepInicial) {
2701  NumDepSiguiente = dynamic_cast<TCCCompresor*>(LPlenum[LNumDepInicial - 1]->GetCCUnionEntreDep(
2702  j))->getNumeroDepositoEst();
2703  } else
2704  NumDepSiguiente = dynamic_cast<TCCCompresor*>(LPlenum[LNumDepInicial - 1]->GetCCUnionEntreDep(
2705  j))->getNumeroDepositoRot();
2706  }
2707 
2708  if(!LPlenum[NumDepSiguiente - 1]->getEstudioEstabilidadRealizado()) {
2709  SearchMinimumTimeGroup(LTMinimo, NumDepSiguiente, LPlenum);
2710  }
2711  }
2712  }
2713 
2714  } catch(exception & N) {
2715  std::cout << " ERROR : SearchMinimumTime : " << std::endl;
2716  std::cout << " Tipo de error : " << N.what() << std::endl;
2717  throw Exception(N.what());
2718  }
2719 }
2720 
2721 void TOpenWAM::SearchMinimumTimeGroup(double *LTMinimo, int LNumDeposito, TDeposito **LPlenum) {
2722  try {
2723  int NumDepSiguiente = 0;
2724 
2725  if(LPlenum[LNumDeposito - 1]->getNUniones() != 0) {
2726  for(int i = 0; i < Plenum[LNumDeposito - 1]->getNUniones(); i++) {
2727  if(Plenum[LNumDeposito - 1]->GetCCDeposito(i)->getUnionDPF()) {
2728 #ifdef ParticulateFilter
2729  if(Plenum[LNumDeposito - 1]->GetCCDeposito(i)
2730  ->GetTuboExtremo(0).DPF->getTime1DPF() < *LTMinimo) {
2731  *LTMinimo = Plenum[LNumDeposito - 1]->GetCCDeposito(i)
2732  ->GetTuboExtremo(0).DPF->getTime1DPF();
2733  }
2734 #endif
2735  } else {
2736  if(Plenum[LNumDeposito - 1]->GetCCDeposito(i)->GetTuboExtremo(0).Pipe->getTime1() < *LTMinimo) {
2737  *LTMinimo = Plenum[LNumDeposito - 1]->GetCCDeposito(i)->GetTuboExtremo(0).Pipe->getTime1();
2738  }
2739  }
2740  }
2741  }
2742 
2743  Plenum[LNumDeposito - 1]->PutRealizado(true);
2744 
2745  if(Plenum[LNumDeposito - 1]->getNUnionesED() != 0) {
2746  for(int j = 0; j < Plenum[LNumDeposito - 1]->getNUnionesED(); j++) {
2747  if(Plenum[LNumDeposito - 1]->GetCCUnionEntreDep(j)->getTipoCC() == nmUnionEntreDepositos) {
2748 
2749  if(dynamic_cast<TCCUnionEntreDepositos*>(Plenum[LNumDeposito - 1]->GetCCUnionEntreDep(
2750  j))->getNumeroDeposito1() == LNumDeposito) {
2751  NumDepSiguiente = dynamic_cast<TCCUnionEntreDepositos*>(Plenum[LNumDeposito - 1]->GetCCUnionEntreDep(
2752  j))->getNumeroDeposito2();
2753  } else
2754  NumDepSiguiente = dynamic_cast<TCCUnionEntreDepositos*>(Plenum[LNumDeposito - 1]->GetCCUnionEntreDep(
2755  j))->getNumeroDeposito1();
2756 
2757  }
2758  if(Plenum[LNumDeposito - 1]->GetCCUnionEntreDep(j)->getTipoCC() == nmCompresor) {
2759  if(dynamic_cast<TCCCompresor*>(Plenum[LNumDeposito - 1]->GetCCUnionEntreDep(j))->getNumeroDepositoRot() ==
2760  LNumDeposito) {
2761  NumDepSiguiente = dynamic_cast<TCCCompresor*>(Plenum[LNumDeposito - 1]->GetCCUnionEntreDep(j))->getNumeroDepositoEst();
2762  } else
2763  NumDepSiguiente = dynamic_cast<TCCCompresor*>(Plenum[LNumDeposito - 1]->GetCCUnionEntreDep(j))->getNumeroDepositoRot();
2764  }
2765 
2766  if(!Plenum[NumDepSiguiente - 1]->getEstudioEstabilidadRealizado()) {
2767  SearchMinimumTimeGroup(LTMinimo, NumDepSiguiente, Plenum);
2768  }
2769  }
2770  }
2771 
2772  } catch(exception & N) {
2773  std::cout << " ERROR : SearchMinimumTime en el deposito : " << std::endl;
2774  std::cout << " Tipo de error : " << N.what() << std::endl;
2775  throw Exception(N.what());
2776  }
2777 }
2778 
2779 void TOpenWAM::FixTimeStep() {
2780 
2781  double TInicialPaso = 0., m = 0., RegimenFicticio = 0.;
2782  TInicialPaso = TimeEndStep - Run.TimeStep;
2783  if(DeltaTPlenums < Run.TimeStep) {
2784  TimeEndStep = TInicialPaso + DeltaTPlenums;
2785  for(int j = 0; j < NumberOfPipes; j++) {
2786  if(Pipe[j]->getTime1() > TimeEndStep) {
2787  Pipe[j]->AjustaPaso(TimeEndStep);
2788  }
2789  if(PipeStepMax) {
2790  JStepMax = j;
2791  }
2792  }
2793 #ifdef ParticulateFilter
2794  for(int j = 0; j < NumberOfDPF; j++) {
2795  if(DPF[j]->getTime1DPF() > TimeEndStep) {
2796  DPF[j]->AjustaPaso(TimeEndStep);
2797  }
2798  if(DPFStepMax) {
2799  JStepMaxDPF = j;
2800  }
2801  }
2802 #endif
2803  Run.TimeStep = DeltaTPlenums;
2804  }
2805  if(EngineBlock) {
2806  Run.AngleStep = Run.TimeStep * 6. * Engine[0]->getRegimen();
2807  } else {
2808  RegimenFicticio = 720. / 6. / SimulationDuration;
2809  Run.AngleStep = Run.TimeStep * 6. * RegimenFicticio;
2810  }
2811  Theta0 = Theta;
2812  Theta += Run.AngleStep;
2813  if(EngineBlock) {
2814  Engine[0]->PutTheta(Theta);
2815  m = floor(Theta / Engine[0]->getAngTotalCiclo());
2816  CrankAngle = Theta - m * Engine[0]->getAngTotalCiclo();
2817  } else {
2818  m = floor(Theta / 720.);
2819  CrankAngle = Theta - m * 720.;
2820  }
2821  AcumulatedTime += Run.TimeStep;
2822 
2823 }
2824 
2825 void TOpenWAM::FixTimeStepExternal(double deltat) {
2826 
2827  double TInicialPaso = 0., m = 0., RegimenFicticio = 0.;
2828  TInicialPaso = TimeEndStep - Run.TimeStep;
2829 
2830  if(deltat < Min(Run.TimeStep, DeltaTPlenums)) {
2831  Is_EndStep = true;
2832  Run.TimeStep = deltat;
2833  for(int j = 0; j < NumberOfPipes; j++) {
2834  Pipe[j]->AjustaPaso(TimeEndStep);
2835  }
2836  } else {
2837  Is_EndStep = false;
2838  if(DeltaTPlenums < Run.TimeStep) {
2839  Run.TimeStep = DeltaTPlenums;
2840  for(int j = 0; j < NumberOfPipes; j++) {
2841  Pipe[j]->AjustaPaso(TimeEndStep);
2842  }
2843  }
2844 
2845  }
2846  JStepMax = NumberOfPipes - 1;
2847 
2848  if(EngineBlock) {
2849  Run.AngleStep = Run.TimeStep * 6. * Engine[0]->getRegimen();
2850  } else {
2851  RegimenFicticio = 720. / 6. / SimulationDuration;
2852  Run.AngleStep = Run.TimeStep * 6. * RegimenFicticio;
2853  }
2854  Theta0 = Theta;
2855  Theta += Run.AngleStep;
2856  if(EngineBlock) {
2857  Engine[0]->PutTheta(Theta);
2858  m = floor(Theta / Engine[0]->getAngTotalCiclo());
2859  CrankAngle = Theta - m * Engine[0]->getAngTotalCiclo();
2860  } else {
2861  m = floor(Theta / 720.);
2862  CrankAngle = Theta - m * 720.;
2863  }
2864  AcumulatedTime += Run.TimeStep;
2865 
2866 }
2867 
2868 void TOpenWAM::RecalculateStability() {
2869 
2870  double i = 0.;
2871 
2872  if(PipeStepMax) {
2873  for(int j = 0; j < NumberOfPipes; j++) {
2874  if((Pipe[JStepMax]->getTime1() - Pipe[j]->getTime0()) < (Pipe[j]->getTime1() - Pipe[j]->getTime0())) {
2875  Pipe[j]->PutTime1(Pipe[JStepMax]->getTime1());
2876  } else {
2877  i = 0.;
2878  while((Pipe[j]->getTime1() - Pipe[j]->getTime0()) < (Pipe[JStepMax]->getTime1() - Pipe[JStepMax]->getTime0()) / pow(2.,
2879  i)) {
2880  i++;
2881  }
2882  Pipe[j]->PutTime1(Pipe[j]->getTime0() + (Pipe[JStepMax]->getTime1() - Pipe[JStepMax]->getTime0()) / pow(2., i));
2883  }
2884  Pipe[j]->PutDeltaTime(Pipe[j]->getTime1() - Pipe[j]->getTime0());
2885  }
2886 #ifdef ParticulateFilter
2887  for(int j = 0; j < NumberOfDPF; j++) {
2888  if((Pipe[JStepMax]->getTime1() - DPF[j]->getTime0DPF()) <
2889  (DPF[j]->getTime1DPF() - DPF[j]->getTime0DPF())) {
2890  DPF[j]->putTime1DPF(Pipe[JStepMax]->getTime1());
2891  } else {
2892  i = 0.;
2893  while((DPF[j]->getTime1DPF() - DPF[j]->getTime0DPF()) <
2894  (Pipe[JStepMax]->getTime1() - Pipe[JStepMax]->getTime0())
2895  / pow(2., i)) {
2896  i++;
2897  }
2898  DPF[j]->putTime1DPF
2899  (DPF[j]->getTime0DPF() + (Pipe[JStepMax]->getTime1()
2900  - Pipe[JStepMax]->getTime0()) / pow(2., i));
2901  }
2902  DPF[j]->putDeltaTimeDPF(DPF[j]->getTime1DPF() - DPF[j]->getTime0DPF
2903  ());
2904  for(int k = 0; k < DPF[j]->getNumeroHacesCanales(); k++) {
2905  (DPF[j]->GetCanal(k, 0))->putTime1(DPF[j]->getTime1DPF());
2906  (DPF[j]->GetCanal(k, 0))->putDeltaTime
2907  (DPF[j]->getDeltaTimeDPF());
2908  (DPF[j]->GetCanal(k, 1))->putTime1(DPF[j]->getTime1DPF());
2909  (DPF[j]->GetCanal(k, 1))->putDeltaTime
2910  (DPF[j]->getDeltaTimeDPF());
2911  }
2912  }
2913 #endif
2914  } else if(DPFStepMax) {
2915 #ifdef ParticulateFilter
2916  for(int j = 0; j < NumberOfPipes; j++) {
2917  if((DPF[JStepMaxDPF]->getTime1DPF() - Pipe[j]->getTime0()) <
2918  (Pipe[j]->getTime1() - Pipe[j]->getTime0())) {
2919  Pipe[j]->PutTime1(DPF[JStepMaxDPF]->getTime1DPF());
2920  } else {
2921  i = 0.;
2922  while((Pipe[j]->getTime1() - Pipe[j]->getTime0()) <
2923  (DPF[JStepMaxDPF]->getTime1DPF() - DPF[JStepMaxDPF]
2924  ->getTime0DPF()) / pow(2., i)) {
2925  i++;
2926  }
2927  Pipe[j]->PutTime1(Pipe[j]->getTime0() +
2928  (DPF[JStepMaxDPF]->getTime1DPF() - DPF[JStepMaxDPF]
2929  ->getTime0DPF()) / pow(2., i));
2930  }
2931  Pipe[j]->PutDeltaTime(Pipe[j]->getTime1() - Pipe[j]->getTime0());
2932  }
2933 
2934  for(int j = 0; j < NumberOfDPF; j++) {
2935  if((DPF[JStepMaxDPF]->getTime1DPF() - DPF[j]->getTime0DPF()) <
2936  (DPF[j]->getTime1DPF() - DPF[j]->getTime0DPF())) {
2937  DPF[j]->putTime1DPF(DPF[JStepMaxDPF]->getTime1DPF());
2938  } else {
2939  i = 0.;
2940  while((DPF[j]->getTime1DPF() - DPF[j]->getTime0DPF()) <
2941  (DPF[JStepMaxDPF]->getTime1DPF() - DPF[JStepMaxDPF]
2942  ->getTime0DPF()) / pow(2., i)) {
2943  i++;
2944  }
2945  DPF[j]->putTime1DPF(DPF[j]->getTime0DPF() +
2946  (DPF[JStepMaxDPF]->getTime1DPF() - DPF[JStepMaxDPF]
2947  ->getTime0DPF()) / pow(2., i));
2948  }
2949  DPF[j]->putDeltaTimeDPF(DPF[j]->getTime1DPF() - DPF[j]->getTime0DPF
2950  ());
2951  for(int k = 0; k < DPF[j]->getNumeroHacesCanales(); k++) {
2952  (DPF[j]->GetCanal(k, 0))->putTime1(DPF[j]->getTime1DPF());
2953  (DPF[j]->GetCanal(k, 0))->putDeltaTime
2954  (DPF[j]->getDeltaTimeDPF());
2955  (DPF[j]->GetCanal(k, 1))->putTime1(DPF[j]->getTime1DPF());
2956  (DPF[j]->GetCanal(k, 1))->putDeltaTime
2957  (DPF[j]->getDeltaTimeDPF());
2958  }
2959  }
2960 #endif
2961  }
2962 
2963 }
2964 
2965 void TOpenWAM::RecalculateStabilitySolver() {
2966 
2967  double i = 0.;
2968 
2969  if(PipeStepMax) {
2970  if(TimeMinPipe) {
2971  if((Pipe[JStepMax]->getTime1() - Pipe[JCurrent]->getTime0()) < (Pipe[JCurrent]->getTime1() -
2972  Pipe[JCurrent]->getTime0())) {
2973  Pipe[JCurrent]->PutTime1(Pipe[JStepMax]->getTime1());
2974  } else {
2975  i = 0;
2976  while((Pipe[JCurrent]->getTime1() - Pipe[JCurrent]->getTime0()) < (Pipe[JStepMax]->getTime1() -
2977  Pipe[JStepMax]->getTime0()) / pow(2., i)) {
2978  i++;
2979  }
2980  }
2981  Pipe[JCurrent]->PutDeltaTime(Pipe[JCurrent]->getTime1() - Pipe[JCurrent]->getTime0());
2982  } else if(TimeMinDPF) {
2983 #ifdef ParticulateFilter
2984  if((Pipe[JStepMax]->getTime1() - DPF[JCurrentDPF]->getTime0DPF())
2985  < (DPF[JCurrentDPF]->getTime1DPF() - DPF[JCurrentDPF]
2986  ->getTime0DPF())) {
2987  DPF[JCurrentDPF]->putTime1DPF(Pipe[JStepMax]->getTime1());
2988  } else {
2989  i = 0;
2990  while((DPF[JCurrentDPF]->getTime1DPF() - DPF[JCurrentDPF]
2991  ->getTime0DPF()) < (Pipe[JStepMax]->getTime1()
2992  - Pipe[JStepMax]->getTime0()) / pow(2., i)) {
2993  i++;
2994  }
2995  DPF[JCurrentDPF]->putTime1DPF
2996  (DPF[JCurrentDPF]->getTime0DPF() +
2997  (Pipe[JStepMax]->getTime1() - Pipe[JStepMax]->getTime0())
2998  / pow(2., i));
2999  }
3000  DPF[JCurrentDPF]->putDeltaTimeDPF
3001  (DPF[JCurrentDPF]->getTime1DPF() - DPF[JCurrentDPF]
3002  ->getTime0DPF());
3003  for(int j = 0; j < DPF[JCurrentDPF]->getNumeroHacesCanales(); j++) {
3004  (DPF[JCurrentDPF]->GetCanal(j, 0))->putTime1
3005  (DPF[JCurrentDPF]->getTime1DPF());
3006  (DPF[JCurrentDPF]->GetCanal(j, 0))->putDeltaTime
3007  (DPF[JCurrentDPF]->getDeltaTimeDPF());
3008  (DPF[JCurrentDPF]->GetCanal(j, 1))->putTime1
3009  (DPF[JCurrentDPF]->getTime1DPF());
3010  (DPF[JCurrentDPF]->GetCanal(j, 1))->putDeltaTime
3011  (DPF[JCurrentDPF]->getDeltaTimeDPF());
3012  }
3013 #endif
3014  }
3015  } else if(DPFStepMax) {
3016 #ifdef ParticulateFilter
3017  if(TimeMinPipe) {
3018  if((DPF[JStepMaxDPF]->getTime1DPF() - Pipe[JCurrent]->getTime0())
3019  < (Pipe[JCurrent]->getTime1() - Pipe[JCurrent]->getTime0())) {
3020  Pipe[JCurrent]->PutTime1(DPF[JStepMaxDPF]->getTime1DPF());
3021  } else {
3022  i = 0;
3023  while((Pipe[JCurrent]->getTime1() - Pipe[JCurrent]->getTime0()
3024  ) < (DPF[JStepMaxDPF]->getTime1DPF() - DPF[JStepMaxDPF]
3025  ->getTime0DPF()) / pow(2., i)) {
3026  i++;
3027  }
3028  Pipe[JCurrent]->PutTime1(Pipe[JCurrent]->getTime0() +
3029  (DPF[JStepMaxDPF]->getTime1DPF() - DPF[JStepMaxDPF]
3030  ->getTime0DPF()) / pow(2., i));
3031  }
3032  Pipe[JCurrent]->PutDeltaTime
3033  (Pipe[JCurrent]->getTime1() - Pipe[JCurrent]->getTime0());
3034  } else if(TimeMinDPF) {
3035  if((DPF[JStepMaxDPF]->getTime1DPF() - DPF[JCurrentDPF]->getTime0DPF
3036  ()) < (DPF[JCurrentDPF]->getTime1DPF() - DPF[JCurrentDPF]
3037  ->getTime0DPF())) {
3038  DPF[JCurrentDPF]->putTime1DPF(DPF[JStepMaxDPF]->getTime1DPF());
3039  } else {
3040  i = 0;
3041  while((DPF[JCurrentDPF]->getTime1DPF() - DPF[JCurrentDPF]
3042  ->getTime0DPF()) < (DPF[JStepMaxDPF]->getTime1DPF()
3043  - DPF[JStepMaxDPF]->getTime0DPF()) / pow(2., i)) {
3044  i++;
3045  }
3046  DPF[JCurrentDPF]->putTime1DPF
3047  (DPF[JCurrentDPF]->getTime0DPF() +
3048  (DPF[JStepMaxDPF]->getTime1DPF() - DPF[JStepMaxDPF]
3049  ->getTime0DPF()) / pow(2., i));
3050  }
3051  DPF[JCurrentDPF]->putDeltaTimeDPF
3052  (DPF[JCurrentDPF]->getTime1DPF() - DPF[JCurrentDPF]
3053  ->getTime0DPF());
3054  for(int j = 0; j < DPF[JCurrentDPF]->getNumeroHacesCanales(); j++) {
3055  (DPF[JCurrentDPF]->GetCanal(j, 0))->putTime1
3056  (DPF[JCurrentDPF]->getTime1DPF());
3057  (DPF[JCurrentDPF]->GetCanal(j, 0))->putDeltaTime
3058  (DPF[JCurrentDPF]->getDeltaTimeDPF());
3059  (DPF[JCurrentDPF]->GetCanal(j, 1))->putTime1
3060  (DPF[JCurrentDPF]->getTime1DPF());
3061  (DPF[JCurrentDPF]->GetCanal(j, 1))->putDeltaTime
3062  (DPF[JCurrentDPF]->getDeltaTimeDPF());
3063  }
3064  }
3065 #endif
3066  }
3067 
3068 }
3069 
3070 void TOpenWAM::InitializeOutput() {
3071  Output->DoSpaceTimeFiles(SpeciesNumber);
3072 
3073  Output->HeaderSpaceTimeResults(thmax, grmax, agincr, SpeciesNumber);
3074 
3075  Output->HeaderAverageResults(SpeciesName, EXTERN, ThereIsDLL);
3076 
3077  Output->CopyAverageResultsToFile(0);
3078 
3079  Output->PutInsPeriod(agincr);
3080  // <- OUTPUT
3081 
3082  if(ThereIsDLL) {
3083  EXTERN->InicializaMedias();
3084  }
3085 #ifdef gestorcom
3086  if(GestorWAM != NULL)
3087  GestorWAM->CabeceraResMediosActualizada();
3088 #endif
3089 }
3090 
3091 void TOpenWAM::CalculateFlowIndependent() {
3092 
3093  int OneDEnd = 0;
3094 
3095  do {
3096  // ! Search which pipe must be calculated
3097  SearchMinimumTimeStep();
3098  if(TimeMinPipe) {
3099  #pragma omp parallel for private(OneDEnd) num_threads(fi_num_threads)
3100  for(int i = -1; i < 2; i++) {
3101  if(i == -1) {
3102  // ! Solver for the flow in the pipe
3103  Pipe[JCurrent]->CalculaVariablesFundamentales();
3104  } else {
3105  // ! Calculation of the boundary conditions at the pipe end
3106  if(i == 0)
3107  OneDEnd = Pipe[JCurrent]->getNodoIzq();
3108  if(i == 1)
3109  OneDEnd = Pipe[JCurrent]->getNodoDer();
3110 
3111  BC[OneDEnd - 1]->CalculaCaracteristicas(Pipe[JCurrent]->getTime1());
3112 
3113  BC[OneDEnd - 1]->TuboCalculandose(JCurrent);
3114 
3115  if(BC[OneDEnd - 1]->getTipoCC() == nmVolumetricCompressor) {
3116  dynamic_cast<TCCCompresorVolumetrico*>(BC[OneDEnd - 1])->ObtencionValoresInstantaneos(ene);
3117 
3118  } else if(BC[OneDEnd - 1]->getTipoCC() == nmInjectionEnd) {
3119  dynamic_cast<TCCExtremoInyeccion*>(BC[OneDEnd - 1])->ObtencionValoresInstantaneos(Theta);
3120 
3121  } else if(BC[OneDEnd - 1]->getTipoCC() == nmCompresor) {
3122 
3123  dynamic_cast<TCCCompresor*>(BC[OneDEnd - 1])->ObtencionValoresInstantaneos(Theta, Pipe[JCurrent]->getTime1());
3124  }
3125 
3126  BC[OneDEnd - 1]->CalculaCondicionContorno(Pipe[JCurrent]->getTime1());
3127 
3128  SolveAdjacentElements(OneDEnd, Pipe[JCurrent]->getTime1());
3129  }
3130  }
3131  Pipe[JCurrent]->ActualizaValoresNuevos(BC);
3132 
3133  Pipe[JCurrent]->ActualizaPropiedadesGas();
3134 
3135  Pipe[JCurrent]->ReduccionFlujoSubsonico();
3136 
3137  Pipe[JCurrent]->CalculaCoeficientePeliculaInterior(BC);
3138  if(!EngineBlock) {
3139  Pipe[JCurrent]->CalculaCoeficientePeliculaExterior(Engine, AmbientPressure, AmbientTemperature);
3140  Pipe[JCurrent]->CalculaResistenciasdePared(BC);
3141  } else {
3142  if(Engine[0]->getCiclo() < 1) {
3143  Pipe[JCurrent]->CalculaCoeficientePeliculaExterior(Engine, AmbientPressure, AmbientTemperature);
3144  Pipe[JCurrent]->CalculaResistenciasdePared(BC);
3145  }
3146  }
3147  if(!Pipe[JCurrent]->getConcentrico()) {
3148  if(EngineBlock) {
3149  Pipe[JCurrent]->CalculaTemperaturaPared(Engine, Theta, CrankAngle, BC);
3150  } else {
3151  Pipe[JCurrent]->CalculaTemperaturaParedSinMotor(BC);
3152  }
3153  } else {
3154 #ifdef ParticulateFilter
3155  for(int j = 0; j < NumberOfConcentrics; j++) {
3156  if(Pipe[JCurrent]->getNumeroTubo() == Concentric[j]
3157  ->GetNumTuboExterno()) {
3158  Concentric[j]->CalculaTemperaturaPared(Engine, Theta,
3159  BC);
3160  }
3161  }
3162 #endif
3163  }
3164  Pipe[JCurrent]->CalculaResultadosMedios(Theta);
3165  Pipe[JCurrent]->EstabilidadMetodoCalculo();
3166  if(Pipe[JCurrent]->getTime0() < TimeEndStep) {
3167  RecalculateStabilitySolver();
3168  }
3169  } else if(TimeMinDPF) {
3170 #ifdef ParticulateFilter
3171  for(int j = 0; j < DPF[JCurrentDPF]->getNumeroHacesCanales(); j++) {
3172  for(int k = 0; k < 2; k++) {
3173  (DPF[JCurrentDPF]->GetCanal(j, k))
3174  ->CalculaVariablesFundamentales();
3175  // printf("%lf\n",DPF[JActualDPF]->Time1DPF);
3176  double IncrementoTiempo = DPF[JCurrentDPF]->getTime1DPF()
3177  - DPF[JCurrentDPF]->getTime0DPF();
3178  (DPF[JCurrentDPF]->GetCanal(j, k))
3179  ->CalculaCaracteristicasExtremos(BC,
3180  IncrementoTiempo);
3181 
3182  /* Calculo de las Condiciones de Contorno en los extremos de los canales */
3183  for(int i = 0; i < 2; i++) {
3184  if(i == 0)
3185  OneDEnd = (DPF[JCurrentDPF]->GetCanal(j, k))
3186  ->getNodoIzq();
3187  if(i == 1)
3188  OneDEnd = (DPF[JCurrentDPF]->GetCanal(j, k))
3189  ->getNodoDer();
3190 
3191  if(OneDEnd != 0) {
3192  BC[OneDEnd - 1]->CalculaCondicionContorno
3193  (DPF[JCurrentDPF]->getTime1DPF());
3194  }
3195  }
3196  (DPF[JCurrentDPF]->GetCanal(j, k))->ActualizaValoresNuevos
3197  (BC);
3198  (DPF[JCurrentDPF]->GetCanal(j, k))->ActualizaPropiedadesGas
3199  ();
3200 
3201  (DPF[JCurrentDPF]->GetCanal(j, k))->ReduccionFlujoSubsonico
3202  ();
3203 
3204  }
3205  SolveAdjacentElements(OneDEnd, DPF[JCurrentDPF]->getTime1DPF());
3206 
3207  if(!EngineBlock) {
3208  if(DPF[JCurrentDPF]->getTime1DPF() < DPF[JCurrentDPF]
3209  ->getDuracionCiclo()) {
3210  if(j == DPF[JCurrentDPF]->getNumeroHacesCanales() - 1) {
3211  (DPF[JCurrentDPF]->GetCanal(j, 0))
3212  ->CalculaCoeficientePeliculaExterior
3213  (AmbientPressure);
3214  }
3215 #ifdef ConcentricElement
3216  DPF[JCurrentDPF]->CalculoResistenciaTC(j, Pipe,
3217  Concentric);
3218 #else
3219  DPF[JCurrentDPF]->CalculoResistenciaTC(j, Pipe, NULL);
3220 #endif
3221  }
3222  } else if(Engine[0]->getCiclo() < 1) {
3223  if(j == DPF[JCurrentDPF]->getNumeroHacesCanales() - 1) {
3224  (DPF[JCurrentDPF]->GetCanal(j, 0))
3225  ->CalculaCoeficientePeliculaExterior
3226  (AmbientPressure);
3227  }
3228 #ifdef ConcentricElement
3229  DPF[JCurrentDPF]->CalculoResistenciaTC(j, Pipe, Concentric);
3230 #else
3231  DPF[JCurrentDPF]->CalculoResistenciaTC(j, Pipe, NULL);
3232 #endif
3233  }
3234  }
3235 #ifdef ConcentricElement
3236  DPF[JCurrentDPF]->CalculoTransmisionCalor(Engine, Theta, Pipe,
3237  Concentric);
3238 #else
3239  DPF[JCurrentDPF]->CalculoTransmisionCalor(Engine, Theta, Pipe,
3240  NULL);
3241 #endif
3242  DPF[JCurrentDPF]->CalculoSubmodelos();
3243  DPF[JCurrentDPF]->CalculaResultadosMedios(Theta);
3244 
3245  DPF[JCurrentDPF]->CalculoEstabilidadDPF();
3246  if(DPF[JCurrentDPF]->getTime0DPF() < TimeEndStep) {
3247  RecalculateStabilitySolver();
3248  }
3249 #endif
3250  }
3251  for(int j = 0; j < NumberOfSensors; j++) {
3252  Sensor[j]->ActualizaMedida(Pipe[JStepMax]->getTime1());
3253  }
3254  } while(JCurrent != JStepMax && JCurrentDPF != JStepMaxDPF);
3255  // Loop end for all pipes.
3256 
3257  if(EngineBlock) {
3258  UpdateEngine();
3259  SolveRoadLoadModel();
3260  }
3261 
3262  for(int i = 0; i < NumberOfPlenums; i++) {
3263  if(SimulationType == nmTransitorioRegimen || SimulationType == nmTransitorioRegimenExterno
3264  || !(Plenum[i]->getCalculadoPaso())) {
3265  if(PipeStepMax) {
3266  if(Plenum[i]->getTipoDeposito() == nmDepVolVble) {
3267  Plenum[i]->UpdateProperties0DModel(Pipe[JStepMax]->getTime0());
3268  } else {
3269  Plenum[i]->ActualizaTiempo(Pipe[JStepMax]->getTime0());
3270  }
3271  } else if(DPFStepMax) {
3272 #ifdef ParticulateFilter
3273  if(Plenum[i]->getTipoDeposito() == nmDepVolVble) {
3274  Plenum[i]->UpdateProperties0DModel
3275  (DPF[JStepMaxDPF]->getTime0DPF());
3276  } else {
3277  Plenum[i]->ActualizaTiempo(DPF[JStepMaxDPF]->getTime0DPF());
3278  }
3279 #endif
3280  }
3281  }
3282  }
3283 
3284  UpdateTurbocharger();
3285 }
3286 
3287 void TOpenWAM::SolveAdjacentElements(int OneDEnd, double TiempoActual) {
3288  try {
3289  int NumDepInicial = 0, NumeroCilindro = 0;
3290  int NumDepSiguiente = 0;
3291  bool CalculaElementosAdyacentes = false;
3292  bool CalculoCilindro = false;
3293  bool CalculoDeposito = false;
3294  int indiceUED = 0;
3295 
3296  if(BC[OneDEnd - 1]->getTipoCC() == nmPipeToPlenumConnection) {
3297  CalculaElementosAdyacentes = true;
3298  CalculoDeposito = true;
3299  } else if(BC[OneDEnd - 1]->getTipoCC() == nmCompresor) {
3300  if(dynamic_cast<TCCCompresor*>(BC[OneDEnd - 1])->getCompressor()->getModeloCompresor() == nmCompOriginal) {
3301  if(dynamic_cast<TCCCompresor*>(BC[OneDEnd - 1])->getEntradaCompresor() == nmPlenum) {
3302  CalculaElementosAdyacentes = true;
3303  CalculoDeposito = true;
3304  }
3305  }
3306  } else if(BC[OneDEnd - 1]->getTipoCC() == nmIntakeValve || BC[OneDEnd - 1]->getTipoCC() == nmExhaustValve) {
3307  CalculaElementosAdyacentes = true;
3308  CalculoCilindro = true;
3309  }
3310 
3311  if(CalculaElementosAdyacentes) {
3312 
3313  /* Se determina el namero de deposito o cilindro al que pertenece la condicion de contorno current */
3314  if(BC[OneDEnd - 1]->getTipoCC() == nmPipeToPlenumConnection) {
3315  NumDepInicial = dynamic_cast<TCCDeposito*>(BC[OneDEnd - 1])->getPlenum()->getNumeroDeposito();
3316  if(dynamic_cast<TCCDeposito*>(BC[OneDEnd - 1])->getValvula()->getCDTubVol() == 0
3317  && dynamic_cast<TCCDeposito*>(BC[OneDEnd - 1])->getValvula()->getCDVolTub() == 0) {
3318  Plenum[NumDepInicial - 1]->PutCalculadoPaso(false);
3319  } else
3320  Plenum[NumDepInicial - 1]->PutCalculadoPaso(true);
3321  } else if(BC[OneDEnd - 1]->getTipoCC() == nmCompresor) {
3322  if(dynamic_cast<TCCCompresor*>(BC[OneDEnd - 1])->getCompressor()->getModeloCompresor() == nmCompOriginal) {
3323  if(dynamic_cast<TCCCompresor*>(BC[OneDEnd - 1])->getEntradaCompresor() == nmPlenum) {
3324  NumDepInicial = dynamic_cast<TCCCompresor*>(BC[OneDEnd - 1])->getPlenum()->getNumeroDeposito();
3325  Plenum[NumDepInicial - 1]->PutCalculadoPaso(true);
3326  }
3327  }
3328  } else if(BC[OneDEnd - 1]->getTipoCC() == nmIntakeValve || BC[OneDEnd - 1]->getTipoCC() == nmExhaustValve) {
3329  NumeroCilindro = dynamic_cast<TCCCilindro*>(BC[OneDEnd - 1])->getNumeroCilindro();
3330  if(dynamic_cast<TCCCilindro*>(BC[OneDEnd - 1])->getValvula()->getCDTubVol() == 0
3331  && dynamic_cast<TCCCilindro*>(BC[OneDEnd - 1])->getValvula()->getCDVolTub() == 0) {
3332  Engine[0]->GetCilindro(NumeroCilindro - 1)->PutCalculadoPaso(false);
3333  } else
3334  Engine[0]->GetCilindro(NumeroCilindro - 1)->PutCalculadoPaso(true);
3335  }
3336 
3337  /* Si se trata de un deposito de volumen constante o variable se inicia la busqueda de condiciones de contorno de tipo
3338  union entre depositos o compresores entre depositos que posea, para realizar su calculo. Esta busqueda se realiza
3339  de forma recursiva hasta que se llega a otro tubo. */
3340  if(CalculoDeposito) {
3341  if(Plenum[NumDepInicial - 1]->getCalculadoPaso()) {
3342  if(Plenum[NumDepInicial - 1]->getTipoDeposito() == nmDepVolCte
3343  || Plenum[NumDepInicial - 1]->getTipoDeposito() == nmDepVolVble) {
3344  for(int i = 0; i < Plenum[NumDepInicial - 1]->getNUnionesED(); i++) {
3345  if(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i)->getTipoCC() == nmCompresor) {
3346  if(dynamic_cast<TCCCompresor*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->getCompressor()->getModeloCompresor()
3347  == nmCompPlenums && dynamic_cast<TCCCompresor*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(
3348  i))->getInstanteCalculo() != TiempoActual) {
3349 
3350  /* Aqui se determina el siguiente deposito en el que se continuara la busqueda */
3351  if(dynamic_cast<TCCCompresor*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->getNumeroDepositoRot() ==
3352  NumDepInicial) {
3353  NumDepSiguiente = dynamic_cast<TCCCompresor*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->getNumeroDepositoEst();
3354  } else
3355  NumDepSiguiente = dynamic_cast<TCCCompresor*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->getNumeroDepositoRot();
3356 
3357  Plenum[NumDepSiguiente - 1]->PutCalculadoPaso(true);
3358 
3359  /* Calculo de la condicion de contorno compresor entre depositos encontrada */
3360  dynamic_cast<TCCCompresor*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->ObtencionValoresInstantaneos(Theta,
3361  TiempoActual);
3362  Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i)->CalculaCondicionContorno(TiempoActual);
3363  dynamic_cast<TCCCompresor*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->PutInstanteCalculo(TiempoActual);
3364  }
3365  /* Comienzo de la busqueda recursiva en el siguiente deposito */
3366  if(Plenum[NumDepSiguiente - 1]->getCalculadoPaso()) {
3367  SolveBranch(NumDepSiguiente, TiempoActual);
3368  }
3369  }
3370  if(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i)->getTipoCC() == nmUnionEntreDepositos
3371  && dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(
3372  i))->getInstanteCalculo() != TiempoActual) {
3373 
3374  /* Aqui se determina el siguiente deposito en el que se continuara la busqueda */
3375  if(dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(
3376  i))->getNumeroDeposito1() == NumDepInicial) {
3377  NumDepSiguiente = dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(
3378  i))->getNumeroDeposito2();
3379  } else
3380  NumDepSiguiente = dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(
3381  i))->getNumeroDeposito1();
3382 
3383  for(int j = 0; j < Plenum[NumDepSiguiente - 1]->getNUnionesED(); j++) {
3384  if(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(j)->getTipoCC() == nmCompresor) {
3385  if(dynamic_cast<TCCCompresor*>(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(j))->getNumeroCC() ==
3386  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(
3387  i))->getNumeroCC()) {
3388  indiceUED = j;
3389  }
3390  } else if(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(j)->getTipoCC() == nmUnionEntreDepositos) {
3391  if(dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(
3392  j))->getNumeroCC() == dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(
3393  i))->getNumeroCC()) {
3394  indiceUED = j;
3395  }
3396  }
3397  }
3398  if(dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(
3399  indiceUED))->getValvula()->getCDTubVol() == 0
3400  && dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(
3401  indiceUED))->getValvula()->getCDVolTub() == 0) {
3402  Plenum[NumDepSiguiente - 1]->PutCalculadoPaso(false);
3403  } else
3404  Plenum[NumDepSiguiente - 1]->PutCalculadoPaso(true);
3405 
3406  /* Calculo de la condicion de contorno union entre depositos encontrada */
3407  if(dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(
3408  i))->getValvula()->getTypeOfValve() != nmCDFijo) {
3409  if(EngineBlock) {
3410  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->CalculaCoeficientesDescarga(
3411  TiempoActual, Engine[0]->getMasaFuel(),
3412  Engine[0]->getRegimen());
3413  } else {
3414  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->CalculaCoeficientesDescarga(
3415  TiempoActual);
3416  }
3417  }
3418 
3419  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->PutInstanteCalculo(
3420  TiempoActual);
3421  Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i)->CalculaCondicionContorno(TiempoActual);
3422  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->AcumulaResultadosMediosUED(
3423  TiempoActual);
3424  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepInicial - 1]->GetCCUnionEntreDep(i))->getValvula()->AcumulaCDMedio(
3425  TiempoActual);
3426 
3427  /* Comienzo de la busqueda recursiva en el siguiente deposito */
3428  if(Plenum[NumDepSiguiente - 1]->getCalculadoPaso()) {
3429  SolveBranch(NumDepSiguiente, TiempoActual);
3430  }
3431  }
3432 
3433  }
3434  }
3435  }
3436  }
3437 
3438  if(CalculoCilindro) {
3439  if(Engine[0]->GetCilindro(NumeroCilindro - 1)->getCalculadoPaso()) {
3440  Engine[0]->GetCilindro(NumeroCilindro - 1)->ActualizaPropiedades(TiempoActual);
3441  Engine[0]->GetCilindro(NumeroCilindro - 1)->CalculaVariablesResultados();
3442  Engine[0]->GetCilindro(NumeroCilindro - 1)->AcumulaResultadosMediosCilindro(TiempoActual);
3443  Engine[0]->AcumulaResultadosMediosBloqueMotor(TiempoActual, NumeroCilindro);
3444  }
3445  } else if(Plenum[NumDepInicial - 1]->getCalculadoPaso()) {
3446  /* Calculo del Deposito en el instante de calculo del Pipe Actual */
3447  Plenum[NumDepInicial - 1]->UpdateProperties0DModel(TiempoActual);
3448  }
3449  }
3450 
3451  } catch(exception & N) {
3452  std::cout << " ERROR : SolveAdjacentElements " << std::endl;
3453  std::cout << " Tipo de error : " << N.what() << std::endl;
3454  throw Exception(N.what());
3455  }
3456 }
3457 
3458 void TOpenWAM::SolveBranch(int NumDeposito, double TiempoActual) {
3459 
3460  try {
3461 
3462  bool ExisteDepSiguiente = false;
3463  int NumDepSiguiente = 0;
3464  int indiceUED = 0;
3465 
3466  for(int i = 0; i < Plenum[NumDeposito - 1]->getNUnionesED(); i++) {
3467  if(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i)->getTipoCC() == nmCompresor) {
3468  if(dynamic_cast<TCCCompresor*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->getCompressor()->getModeloCompresor() ==
3469  nmCompPlenums && dynamic_cast<TCCCompresor*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(
3470  i))->getInstanteCalculo() != TiempoActual) {
3471 
3472  /* Aqui se determina el siguiente deposito en el que se continuara la busqueda */
3473  if(dynamic_cast<TCCCompresor*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->getNumeroDepositoRot() == NumDeposito) {
3474  NumDepSiguiente = dynamic_cast<TCCCompresor*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->getNumeroDepositoEst();
3475  } else
3476  NumDepSiguiente = dynamic_cast<TCCCompresor*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->getNumeroDepositoRot();
3477  ExisteDepSiguiente = true;
3478 
3479  Plenum[NumDepSiguiente - 1]->PutCalculadoPaso(true);
3480 
3481  /* Calculo de la condicion de contorno compresor entre depositos encontrada */
3482  dynamic_cast<TCCCompresor*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->ObtencionValoresInstantaneos(Theta,
3483  TiempoActual);
3484  Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i)->CalculaCondicionContorno(TiempoActual);
3485  dynamic_cast<TCCCompresor*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->PutInstanteCalculo(TiempoActual);
3486  }
3487  }
3488  if(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i)->getTipoCC() == nmUnionEntreDepositos
3489  && dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(
3490  i))->getInstanteCalculo() != TiempoActual) {
3491 
3492  /* Aqui se determina el siguiente deposito en el que se continuara la busqueda */
3493  if(dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(
3494  i))->getNumeroDeposito1() == NumDeposito) {
3495  NumDepSiguiente = dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(
3496  i))->getNumeroDeposito2();
3497  } else
3498  NumDepSiguiente = dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(
3499  i))->getNumeroDeposito1();
3500  ExisteDepSiguiente = true;
3501 
3502  for(int j = 0; j < Plenum[NumDepSiguiente - 1]->getNUnionesED(); j++) {
3503  if(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(j)->getTipoCC() == nmCompresor) {
3504  if(dynamic_cast<TCCCompresor*>(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(j))->getNumeroCC() ==
3505  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(
3506  i))->getNumeroCC()) {
3507  indiceUED = j;
3508  }
3509  } else if(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(j)->getTipoCC() == nmUnionEntreDepositos) {
3510  if(dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(
3511  j))->getNumeroCC() == dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(
3512  i))->getNumeroCC()) {
3513  indiceUED = j;
3514  }
3515  }
3516  }
3517  if(dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(
3518  indiceUED))->getValvula()->getCDTubVol() == 0
3519  && dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDepSiguiente - 1]->GetCCUnionEntreDep(
3520  indiceUED))->getValvula()->getCDVolTub() == 0) {
3521  Plenum[NumDepSiguiente - 1]->PutCalculadoPaso(false);
3522  } else
3523  Plenum[NumDepSiguiente - 1]->PutCalculadoPaso(true);
3524 
3525  /* Calculo de la condicion de contorno compresor entre depositos encontrada */
3526  if(dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(
3527  i))->getValvula()->getTypeOfValve() != nmCDFijo) {
3528  if(EngineBlock) {
3529  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->CalculaCoeficientesDescarga(
3530  TiempoActual, Engine[0]->getMasaFuel(),
3531  Engine[0]->getRegimen());
3532  } else {
3533  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->CalculaCoeficientesDescarga(
3534  TiempoActual);
3535  }
3536  }
3537 
3538  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->PutInstanteCalculo(TiempoActual);
3539  Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i)->CalculaCondicionContorno(TiempoActual);
3540  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->AcumulaResultadosMediosUED(
3541  TiempoActual);
3542  dynamic_cast<TCCUnionEntreDepositos*>(Plenum[NumDeposito - 1]->GetCCUnionEntreDep(i))->getValvula()->AcumulaCDMedio(
3543  TiempoActual);
3544 
3545  }
3546  if(ExisteDepSiguiente) {
3547  if(Plenum[NumDepSiguiente - 1]->getCalculadoPaso()) {
3548  SolveBranch(NumDepSiguiente, TiempoActual);
3549  }
3550  }
3551  }
3552 
3553  Plenum[NumDeposito - 1]->UpdateProperties0DModel(TiempoActual);
3554 
3555  } catch(exception & N) {
3556  std::cout << " ERROR : SolveBranch " << std::endl;
3557  std::cout << " Tipo de error : " << N.what() << std::endl;
3558  throw Exception(N.what());
3559  }
3560 }
3561 
3562 void TOpenWAM::UpdateEngine() {
3563  for(int i = 0; i < Engine[0]->getGeometria().NCilin; i++) {
3564  if(SimulationType == nmTransitorioRegimen || SimulationType == nmTransitorioRegimenExterno
3565  || !(Engine[0]->GetCilindro(i)->getCalculadoPaso())) {
3566  if(PipeStepMax) {
3567  if(Engine[0]->GetCilindro(i)->getTiempoActual() < Pipe[JStepMax]->getTime0()) {
3568  Engine[0]->GetCilindro(i)->ActualizaPropiedades(Pipe[JStepMax]->getTime0());
3569  Engine[0]->GetCilindro(i)->CalculaVariablesResultados();
3570  Engine[0]->GetCilindro(i)->AcumulaResultadosMediosCilindro(Pipe[JStepMax]->getTime0());
3571  Engine[0]->AcumulaResultadosMediosBloqueMotor(Pipe[JStepMax]->getTime0(), i + 1);
3572  for(int j = 0; j < Engine[0]->GetCilindro(i)->getNumeroUnionesAdm(); j++) {
3573  dynamic_cast<TCCCilindro*>(Engine[0]->GetCilindro(i)->GetCCValvulaAdm(j))->ActualizaAnguloValvula(
3574  Pipe[JStepMax]->getTime0(), Engine[0]->getRegimen());
3575  }
3576  for(int j = 0; j < Engine[0]->GetCilindro(i)->getNumeroUnionesEsc(); j++) {
3577  dynamic_cast<TCCCilindro*>(Engine[0]->GetCilindro(i)->GetCCValvulaEsc(j))->ActualizaAnguloValvula(
3578  Pipe[JStepMax]->getTime0(), Engine[0]->getRegimen());
3579  }
3580  }
3581  } else if(DPFStepMax) {
3582 #ifdef ParticulateFilter
3583  if(Engine[0]->GetCilindro(i)->getTiempoActual()
3584  < DPF[JStepMaxDPF]->getTime0DPF()) {
3585  Engine[0]->GetCilindro(i)->ActualizaPropiedades
3586  (DPF[JStepMaxDPF]->getTime0DPF());
3587  Engine[0]->GetCilindro(i)->CalculaVariablesResultados();
3588  Engine[0]->GetCilindro(i)->AcumulaResultadosMediosCilindro
3589  (DPF[JStepMaxDPF]->getTime0DPF());
3590  Engine[0]->AcumulaResultadosMediosBloqueMotor
3591  (DPF[JStepMaxDPF]->getTime0DPF(), i + 1);
3592  for(int j = 0;
3593  j < Engine[0]->GetCilindro(i)->getNumeroUnionesAdm();
3594  j++) {
3595  dynamic_cast<TCCCilindro*>
3596  (Engine[0]->GetCilindro(i)->GetCCValvulaAdm(j))
3597  ->ActualizaAnguloValvula
3598  (DPF[JStepMaxDPF]->getTime0DPF(),
3599  Engine[0]->getRegimen());
3600  }
3601  for(int j = 0;
3602  j < Engine[0]->GetCilindro(i)->getNumeroUnionesEsc();
3603  j++) {
3604  dynamic_cast<TCCCilindro*>
3605  (Engine[0]->GetCilindro(i)->GetCCValvulaEsc(j))
3606  ->ActualizaAnguloValvula
3607  (DPF[JStepMaxDPF]->getTime0DPF(),
3608  Engine[0]->getRegimen());
3609  }
3610  }
3611 #endif
3612  }
3613  } else if(Engine[0]->GetCilindro(i)->getCalculadoPaso()) {
3614  /* !
3615  If in this time sted the cylinder has been calculate in CalculaElementosAdyacentes
3616  this parameter is asigned as false
3617  */Engine[0]->GetCilindro(i)->PutCalculadoPaso(false);
3618  }
3619  }
3620 }
3621 
3622 void TOpenWAM::SolveRoadLoadModel() {
3623  Engine[0]->ModeloDeVehiculo(AcumulatedTime);
3624  if(SimulationType == nmTransitorioRegimen || SimulationType == nmTransitorioRegimenExterno) {
3625  // ! Update speed of variable volume plenums connected to the engine.
3626  for(int i = 0; i < NumberOfPlenums; i++) {
3627  if(Plenum[i]->getTipoDeposito() == nmDepVolVble) {
3628  dynamic_cast<TDepVolVariable*>(Plenum[i])->UpdateSpeed(Engine[0]->getRegimen());
3629  }
3630  }
3631 
3632  }
3633 }
3634 
3635 void TOpenWAM::UpdateTurbocharger() {
3636  for(int i = 0; i < NumberOfAxis; i++) {
3637  Axis[i]->CalculaEjesTurbogrupo(Theta, SimulationType, AcumulatedTime, CrankAngle);
3638  Axis[i]->AcumulaResultadosMediosEje(AcumulatedTime);
3639  }
3640 }
3641 
3642 void TOpenWAM::CalculateFlowCommon() {
3643 
3644  for(int j = 0; j < NumberOfPipes; j++) {
3645  Pipe[j]->CalculaVariablesFundamentales();
3646  Pipe[j]->CalculaCaracteristicasExtremos(BC, Run.TimeStep);
3647  }
3648 #ifdef ParticulateFilter
3649  for(int i = 0; i < NumberOfDPF; i++) {
3650  for(int j = 0; j < DPF[i]->getNumeroHacesCanales(); j++) {
3651  for(int k = 0; k < 2; k++) {
3652  (DPF[i]->GetCanal(j, k))->CalculaVariablesFundamentales();
3653  (DPF[i]->GetCanal(j, k))->CalculaCaracteristicasExtremos(BC,
3654  Run.TimeStep);
3655  }
3656  }
3657  }
3658 #endif
3659 
3660  for(int i = 0; i < NumberOfConnections; i++) {
3661  if(BC[i]->getTipoCC() == nmVolumetricCompressor) {
3662  dynamic_cast<TCCCompresorVolumetrico*>(BC[i])->ObtencionValoresInstantaneos(ene);
3663  } else if(BC[i]->getTipoCC() == nmInjectionEnd) {
3664  dynamic_cast<TCCExtremoInyeccion*>(BC[i])->ObtencionValoresInstantaneos(Theta);
3665  } else if(BC[i]->getTipoCC() == nmCompresor) {
3666  dynamic_cast<TCCCompresor*>(BC[i])->ObtencionValoresInstantaneos(Theta, TimeEndStep);
3667  }
3668  BC[i]->CalculaCondicionContorno(TimeEndStep);
3669 
3670  if(BC[i]->getTipoCC() == nmUnionEntreDepositos) {
3671  dynamic_cast<TCCUnionEntreDepositos*>(BC[i])->AcumulaResultadosMediosUED(TimeEndStep);
3672  dynamic_cast<TCCUnionEntreDepositos*>(BC[i])->getValvula()->AcumulaCDMedio(TimeEndStep);
3673  }
3674  }
3675 
3676  for(int j = 0; j < NumberOfPipes; j++) {
3677  Pipe[j]->ActualizaValoresNuevos(BC);
3678  Pipe[j]->ActualizaPropiedadesGas();
3679 
3680  Pipe[j]->ReduccionFlujoSubsonico();
3681 
3682  Pipe[j]->CalculaCoeficientePeliculaInterior(BC);
3683  if(!EngineBlock) {
3684  Pipe[j]->CalculaCoeficientePeliculaExterior(Engine, AmbientPressure, AmbientTemperature);
3685  Pipe[j]->CalculaResistenciasdePared(BC);
3686  } else {
3687  if(Engine[0]->getCiclo() < 1) {
3688  Pipe[j]->CalculaCoeficientePeliculaExterior(Engine, AmbientPressure, AmbientTemperature);
3689  Pipe[j]->CalculaResistenciasdePared(BC);
3690  }
3691  }
3692  if(!Pipe[j]->getConcentrico()) {
3693  if(Engine != NULL) {
3694  Pipe[j]->CalculaTemperaturaPared(Engine, Theta, CrankAngle, BC);
3695  } else {
3696  Pipe[j]->CalculaTemperaturaParedSinMotor(BC);
3697  }
3698  } else {
3699 #ifdef ConcentricElement
3700  for(int j = 0; j < NumberOfConcentrics; j++) {
3701  if(Pipe[j]->getNumeroTubo() == Concentric[j]->GetNumTuboExterno
3702  ()) {
3703  Concentric[j]->CalculaTemperaturaPared(Engine, Theta, BC);
3704  }
3705  }
3706 #endif
3707  }
3708 
3709  Pipe[j]->CalculaResultadosMedios(Theta);
3710 
3711  Pipe[j]->EstabilidadMetodoCalculo();
3712  }
3713 #ifdef ParticulateFilter
3714  for(int i = 0; i < NumberOfDPF; i++) {
3715  for(int j = 0; j < DPF[i]->getNumeroHacesCanales(); j++) {
3716  for(int k = 0; k < 2; k++) {
3717  (DPF[i]->GetCanal(j, k))->ActualizaValoresNuevos(BC);
3718  (DPF[i]->GetCanal(j, k))->ActualizaPropiedadesGas();
3719  (DPF[i]->GetCanal(j, k))->ReduccionFlujoSubsonico();
3720  }
3721  if(!EngineBlock) {
3722  if(j == DPF[i]->getNumeroHacesCanales() - 1) {
3723  (DPF[i]->GetCanal(j, 0))->CalculaCoeficientePeliculaExterior
3724  (AmbientPressure);
3725  }
3726  DPF[i]->CalculoResistenciaTC(j, Pipe, Concentric);
3727  } else if(Engine[0]->getCiclo() < 1) {
3728  if(j == DPF[i]->getNumeroHacesCanales() - 1) {
3729  (DPF[i]->GetCanal(j, 0))->CalculaCoeficientePeliculaExterior
3730  (AmbientPressure);
3731  }
3732  DPF[i]->CalculoResistenciaTC(j, Pipe, Concentric);
3733  }
3734  }
3735  DPF[i]->CalculoTransmisionCalor(Engine, Theta, Pipe, Concentric);
3736  DPF[i]->CalculoSubmodelos();
3737  DPF[i]->CalculaResultadosMedios(Theta);
3738 
3739  DPF[i]->CalculoEstabilidadDPF();
3740  }
3741 #endif
3742  for(int j = 0; j < NumberOfSensors; j++) {
3743  Sensor[j]->ActualizaMedida(Pipe[JStepMax]->getTime1());
3744  }
3745 
3746  if(EngineBlock) {
3747  UpdateEngine();
3748  SolveRoadLoadModel();
3749  }
3750 
3751  for(int i = 0; i < NumberOfPlenums; i++) {
3752  Plenum[i]->UpdateProperties0DModel(TimeEndStep);
3753  }
3754 
3755  UpdateTurbocharger();
3756 
3757  if(ThereIsDLL) {
3758 
3759  comunica_wam_dll();
3760 
3761  Actuadores();
3762 
3763  } /* fin haydll */
3764 }
3765 
3766 void TOpenWAM::ManageOutput() {
3767  if(Engine != NULL) {
3768  Output->WriteInstantaneous(EngineBlock, CrankAngle, Run.AngleStep, Engine[0], SimulationDuration);
3769  } else {
3770  Output->WriteInstantaneous(EngineBlock, CrankAngle, Run.AngleStep,
3771  NULL, SimulationDuration);
3772  }
3773 
3774  Output->CopyInstananeousResultsToFile(0);
3775 
3776  Output->HeaderInstantaneousResults(EXTERN, ThereIsDLL, EngineBlock, SpeciesName);
3777 
3778 #ifdef gestorcom
3779  if(GestorWAM != NULL)
3780  GestorWAM->CabeceraResInstantActualizada();
3781  if(GestorWAM != NULL)
3782  GestorWAM->FichResInstantActualizado();
3783 #endif
3784  // OUTPUT ->
3785  Output->PlotControl(Theta0, Theta, Run.CycleDuration);
3786 
3787  if(EngineBlock) {
3788 
3789  Output->OutputInstantaneousResults(EXTERN, ThereIsDLL, EngineBlock, Theta, Engine[0], AcumulatedTime);
3790 
3791  Output->WriteSpaceTime(EngineBlock, Engine[0], Run.CycleDuration);
3792 
3793  Output->PrintSpaceTimeResults(EngineBlock, Theta, Run.CycleDuration, Engine, SpeciesNumber);
3794 
3795  if(CrankAngle - Run.AngleStep <= 0. && Theta >= 750.) {
3796  Output->OutputAverageResults(AcumulatedTime, EXTERN, ThereIsDLL);
3797 
3798  Output->CopyAverageResultsToFile(1);
3799 
3800 #ifdef gestorcom
3801  if(GestorWAM != NULL)
3802  GestorWAM->FichResMediosActualizado();
3803 #endif
3804 
3805  Engine[0]->PrestacionesMotor();
3806 
3807  for(int i = 0; i < Engine[0]->getGeometria().NCilin; i++) {
3808  Engine[0]->GetCilindro(i)->SalidaGeneralCilindros();
3809  }
3810 
3811  printf(" \n INFO : == CYCLE N. %d == \n \n ", Engine[0]->getCiclo() + 1);
3812 
3813  }
3814  } else {
3815  Output->OutputInstantaneousResults(EXTERN, ThereIsDLL, EngineBlock, Theta, NULL, AcumulatedTime);
3816 
3817  Output->WriteSpaceTime(EngineBlock, NULL, Run.CycleDuration);
3818 
3819  Output->PrintSpaceTimeResults(EngineBlock, Theta, Run.CycleDuration,
3820  NULL, SpeciesNumber);
3821  }
3822 
3823 }
3824 
3825 void TOpenWAM::GeneralOutput() {
3826 
3827  Output->CopyInstananeousResultsToFile(1);
3828 
3829  if(EngineBlock) {
3830  Engine[0]->PrestacionesMotor();
3831  for(int i = 0; i < Engine[0]->getGeometria().NCilin; i++) {
3832  Engine[0]->GetCilindro(i)->SalidaGeneralCilindros();
3833  }
3834  }
3835  for(int i = 0; i < NumberOfPlenums; i++) {
3836  Plenum[i]->SalidaGeneralDep(SpeciesName);
3837  }
3838  for(int i = 0; i < NumberOfPipes; i++) {
3839  Pipe[i]->SalidaGeneralTubos(SpeciesName);
3840  }
3841 }
3842 
3843 bool TOpenWAM::CalculationEnd() {
3844  return Output->GetFControlAngle1() > thmax;
3845 }
3846 
3847 void TOpenWAM::ProgressBegin() {
3848  char* tzcharstring = new char[tzstr.length() + 1];
3849  std::strcpy(tzcharstring, tzstr.c_str());
3850  putenv(tzcharstring);
3851 
3852 #ifdef gestorcom
3853  if(GestorWAM != NULL)
3854  GestorWAM->NuevoMensaje("Calculating main loop...");
3855 #endif
3856  // tzset();
3857  ftime(&begining);
3858  printf(" Seconds since 1 / 1 / 1970 GMT : % ld \n ", begining.time);
3859  printf(" Thousandths of a second : %d \n ", begining.millitm);
3860 }
3861 
3862 void TOpenWAM::ProgressEnd() {
3863 
3864  ftime(&final);
3865  float tiempotot = (final.time - begining.time) * 1000 + (final.millitm - begining.millitm);
3866 
3867  int seg = int(tiempotot / 1000.);
3868  int min = int(seg / 60.);
3869  int hor = int(min / 60.);
3870  int mil = int(tiempotot) - seg * 1000;
3871  seg = seg - min * 60;
3872  min = min - hor * 60;
3873  std::cout << std::endl;
3874  std::cout << "===================================" << std::endl;
3875  printf("Time consumed: %d:%02d:%02d,%03d \n", hor, min, seg, mil);
3876  std::cout << "===================================" << std::endl;
3877  std::cout << std::endl;
3878 }
3879 
3880 void TOpenWAM::NewEngineCycle() {
3881 
3882  if(EngineBlock) {
3883  if(CrankAngle - Run.AngleStep <= 0. && Theta >= Engine[0]->getAngTotalCiclo()) {
3884 
3885  Engine[0]->PutCiclo(Engine[0]->getCiclo() + 1);
3886  for(int i = 0; i < NumberOfPipes; i++) {
3887  Pipe[i]->CalculaCoeficientePeliculaExterior(Engine, AmbientPressure, AmbientTemperature);
3888  Pipe[i]->CalculaResistenciasdePared(BC);
3889  }
3890  }
3891  }
3892  // Calculo de las propiedades de transmision de calor en el filtro de particulas cada paso de integracion global
3893 #ifdef ParticulateFilter
3894  for(int i = 0; i < NumberOfDPF; i++) {
3895  if(DPF[i]->getCicloDPF() > 1) {
3896  for(int j = 0; j < DPF[i]->getNumeroHacesCanales(); j++) {
3897  (DPF[i]->GetCanal(j, 0))->CalculaCoeficientePeliculaInterior();
3898  (DPF[i]->GetCanal(j, 1))->CalculaCoeficientePeliculaInterior();
3899  if(j == DPF[i]->getNumeroHacesCanales() - 1) {
3900  (DPF[i]->GetCanal(j, 0))->CalculaCoeficientePeliculaExterior
3901  (AmbientPressure);
3902  (DPF[i]->GetCanal(j, 1))->CalculaCoeficientePeliculaExterior
3903  (AmbientPressure);
3904  }
3905  DPF[i]->CalculoResistenciaTC(j, Pipe, Concentric);
3906  }
3907  }
3908  }
3909 #endif
3910 }
3911 
3912 void TOpenWAM::UpdateExternalBoundary(int i, double U0, double U1, double T0, double T1, double P0, double P1,
3913  double t) {
3914 
3915  BCExtConnection[i]->UpdateCurrentExternalProperties(U0, U1, T0, T1, P0, P1, t);
3916 
3917 }
3918 
3919 void TOpenWAM::UpdateExternalBoundary(int i, double U0, double T0, double P0, double t) {
3920 
3921  BCExtConnectionVol[i - 1]->UpdateCurrentExternalProperties(U0, T0, P0, t);
3922 
3923 }
3924 
3925 void TOpenWAM::InitiateExternalBoundary(int i, double D0, double D1, double dX) {
3926 
3927  BCExtConnection[i]->AsignGeometricalData(D0, D1, dX);
3928 
3929 }
3930 
3931 void TOpenWAM::InitiateExternalBoundary(int i, double D0, double dX) {
3932 
3933  BCExtConnectionVol[i]->AsignGeometricalData(D0, dX);
3934 
3935 }
3936 
3937 void TOpenWAM::LoadNewData(int i, double* p, double* T, double* u) {
3938 
3939  BCExtConnectionVol[i]->LoadNewData(p, T, u);
3940 }
3941 
3942 bool TOpenWAM::GetIs_EndStep() {
3943  return Is_EndStep;
3944 }
3945 
3946 void TOpenWAM::comunica_wam_dll() {
3947 
3948  if(Pipe != NULL)
3949  EXTERN->Calculo_Sensores_Tubos(Pipe, Run.TimeStep);
3950  if(Plenum != NULL)
3951  EXTERN->Calculo_Sensores_Deposito(Plenum, Run.TimeStep);
3952  if(Axis != NULL)
3953  EXTERN->Calculo_Sensores_TG(Run.TimeStep, Axis);
3954  if(Turbine != NULL)
3955  EXTERN->Calculo_Sensores_Turbina(Run.TimeStep, Turbine);
3956  if(Engine != NULL)
3957  EXTERN->Calculo_Sensores_Cilindro(Run.TimeStep, Engine);
3958  if(Venturi != NULL)
3959  EXTERN->Calculo_Sensores_Venturi(Run.TimeStep, Venturi);
3960  if(Engine != NULL)
3961  EXTERN->Calculo_Sensores_Motor(Run.TimeStep, Engine, AcumulatedTime);
3962  EXTERN->LlamadaECU(Run.TimeStep, Engine);
3963 
3964  if(EXTERN->getConvergencia() && ConvergenceFirstTime == false) {
3965  ModificacionControlEjecucion();
3966  ConvergenceFirstTime = true;
3967  }
3968 
3969 }
3970 
3971 void TOpenWAM::ModificacionControlEjecucion() {
3972  int nuevaduracionejecucion = 0;
3973 
3974  if(!EngineBlock) {
3975  if(Theta < 700.) {
3976  thmax = Theta + 20.;
3977  }
3978  grmax = 0.;
3979  } else {
3980  nuevaduracionejecucion = (Engine[0]->getCiclo() + 1) + 10;
3981  thmax = nuevaduracionejecucion * Engine[0]->getAngTotalCiclo();
3982  grmax = thmax - Engine[0]->getAngTotalCiclo();
3983  }
3984 
3985 }
3986 
3987 void TOpenWAM::Actuadores()
3988 
3989 {
3990  int compo = 0, contador = 0;
3991  /* Asignacion de actuadores a variables de WAM */
3992 
3993  /* Extremos matlab */
3994  if(nematlab != 0) {
3995  for(int i = 0; i < nematlab; ++i) {
3996  MatlabDischarge[i]->PutPresion(EXTERN->GetOutput_dll(compo));
3997  MatlabDischarge[i]->PutTemperatura(__units::degCToK(EXTERN->GetOutput_dll(compo + 1)));
3998  compo += 2;
3999  }
4000  }
4001 
4002  /* Coeficientes de descarga */
4003  if(controlvalv == 1) {
4004  for(int i = 0; i <= NumberOfExternalCalculatedValves - 1; ++i) {
4005  dynamic_cast<TCDExterno*>(CCCalcExtern[i])->PutCDEntMatlab(EXTERN->GetOutput_dll(compo));
4006  dynamic_cast<TCDExterno*>(CCCalcExtern[i])->PutCDSalMatlab(EXTERN->GetOutput_dll(compo + 1));
4007  dynamic_cast<TCDExterno*>(CCCalcExtern[i])->PutCTorMatlab(EXTERN->GetOutput_dll(compo + 2));
4008  compo += 3;
4009  }
4010  }
4011 
4012  /* Gasto de combustible */
4013  if(EXTERN->getcontrolmfcomb()) {
4014  for(int i = 0; i < Engine[0]->getGeometria().NCilin; ++i) {
4015  if(Engine[0]->GetCilindro(i)->getAnguloActual() > Engine[0]->GetCilindro(i)->getDistribucion().CA
4016  && Engine[0]->GetCilindro(i)->getAnguloAnterior() <= Engine[0]->GetCilindro(i)->getDistribucion().CA) {
4017  Engine[0]->GetCilindro(i)->PutMasaFuel(EXTERN->GetOutput_dll(compo));
4018  /* Actuador de fuel del cilindro en cuestion */
4019  }
4020  compo += 1; /* Hay que hacer un bucle */
4021  }
4022  }
4023 
4024  /* Inyeccion */
4025  if(EXTERN->getcontroliny()) {
4026  for(int i = 0; i < Engine[0]->getGeometria().NCilin; ++i) {
4027  if(Engine[0]->GetCilindro(i)->getAnguloActual() > Engine[0]->GetCilindro(i)->getDistribucion().CA
4028  && Engine[0]->GetCilindro(i)->getAnguloAnterior() <= Engine[0]->GetCilindro(i)->getDistribucion().CA) {
4029  Engine[0]->GetCilindro(i)->PutNumeroInyecciones(EXTERN->GetOutput_dll(compo));
4030  Engine[0]->GetCilindro(i)->PutPresionInyeccion(EXTERN->GetOutput_dll(compo + 1));
4031  contador = 0;
4032  for(int j = 0; j < 8; j++) {
4033  if(Engine[0]->getACT()) {
4034  // Significa que la combustion es con ACT
4035  Engine[0]->GetCilindro(i)->PutSOP(j, EXTERN->GetOutput_dll(compo + 2 + j + contador));
4036  Engine[0]->GetCilindro(i)->PutMasaFuelPorInyeccion(j, EXTERN->GetOutput_dll(compo + 3 + j + contador));
4037  }
4038  contador++;
4039  }
4040  }
4041  compo += 18; /* Hay que hacer un bucle */
4042  }
4043  }
4044 
4045  for(int i = 0; i < CountVGT; ++i) {
4046  dynamic_cast<TEstatorTurbina*>(DatosTGV[i].Estator[0])->PutCDVbl(EXTERN->GetOutput_dll(compo));
4047  dynamic_cast<TRotorTurbina*>(DatosTGV[i].Rotor)->PutCDVbl(EXTERN->GetOutput_dll(compo + 1));
4048  DatosTGV[i].Rendimiento[0] = EXTERN->GetOutput_dll(compo + 2);
4049  if(DatosTGV[i].Entradas == 2) {
4050  dynamic_cast<TEstatorTurbina*>(DatosTGV[i].Estator[1])->PutCDVbl(EXTERN->GetOutput_dll(compo + 3));
4051  dynamic_cast<TRotorTurbina*>(DatosTGV[i].Rotor)->PutCDVbl(EXTERN->GetOutput_dll(compo + 4));
4052  DatosTGV[i].Rendimiento[1] = EXTERN->GetOutput_dll(compo + 5);
4053  }
4054  compo += 6;
4055  }
4056 
4057  if(EXTERN->getajustbaraba()) {
4058  Engine[0]->PutATCAdm(EXTERN->GetOutput_dll(compo));
4059  Engine[0]->PutATCEsc(EXTERN->GetOutput_dll(compo + 1));
4060  compo += 2;
4061  }
4062 
4063  if(EXTERN->getmodcomb()) {
4064  for(int i = 0; i <= Engine[0]->getGeometria().NCilin - 1; ++i) {
4065  Engine[0]->GetCilindro(i)->PutFQL(EXTERN->GetOutput_dll(compo));
4066  Engine[0]->GetCilindro(i)->PutInicioComb(EXTERN->GetOutput_dll(compo + 1));
4067  Engine[0]->GetCilindro(i)->PutFinComb(EXTERN->GetOutput_dll(compo + 2));
4068  compo += 3;
4069  }
4070  }
4071 
4072  if(SimulationType == nmTransitorioRegimenExterno) {
4073  Engine[0]->PutRegimen(EXTERN->GetOutput_dll(compo));
4074  compo += 1;
4075  }
4076 
4077  if(EXTERN->getFraccionMasicaEspeciesCil()) {
4078  for(int i = 0; i < Engine[0]->getGeometria().NCilin; ++i) {
4079  if(Engine[0]->GetCilindro(i)->getAnguloActual() > Engine[0]->GetCilindro(i)->getDistribucion().AE
4080  && Engine[0]->GetCilindro(i)->getAnguloAnterior() <= Engine[0]->GetCilindro(i)->getDistribucion().AE) {
4081  for(int j = 0; j < Engine[0]->getSpeciesNumber() - 1;
4082  j++) { // Se pone -1 porque la ultima especie es siempre el EGR, y este no debe modificarlo el usuario.
4083  Engine[0]->GetCilindro(i)->PutFraccionMasicaEspecie(j, EXTERN->GetOutput_dll(compo));
4084 
4085  }
4086  }
4087  compo += Engine[0]->getSpeciesNumber();
4088  }
4089 
4090  }
4091 
4092  if(EXTERN->getControlK()) {
4093  for(int i = 0; i < NumTCCPerdidaPresion; ++i) {
4094  PerdidaPresion[i]->PutK(EXTERN->GetOutput_dll(compo));
4095  compo += 1;
4096  }
4097  }
4098 
4099  EXTERN->AcumulaMedias(Run.TimeStep);
4100 
4101 }
4102 
4103 void TOpenWAM::InitFlowIndependentNumThreads() {
4104  fi_num_threads = 1;
4105 #ifdef WITH_OPENMP
4106  std::stringstream ss;
4107  int n_threads = 0;
4108  char const* env_value = getenv("OMP_NUM_THREADS");
4109  if(env_value == NULL) {
4110  n_threads = omp_get_num_procs();
4111  } else {
4112  ss.str(env_value);
4113  if(!(ss >> n_threads)) {
4114  // OMP_NUM_THREADS isn't a valid integer.
4115  n_threads = 1;
4116  }
4117  }
4118  if(n_threads > 2) {
4119  fi_num_threads = 3;
4120  } else if(n_threads > 1) {
4121  fi_num_threads = 2;
4122  }
4123 #endif
4124 }
4125 
4126 // ---------------------------------------------------------------------------
4127 
4128 #pragma package(smart_init)kage(smart_init)age(smart_init)
stEspecies
Definition: Globales.h:297
TTubo::getNodoDer
int getNodoDer() const
Gets the right-hand side node.
Definition: TTubo.cpp:5456
TRotorTurbina
Definition: TRotorTurbina.h:48
TEjeTurbogrupo
Definition: TEjeTurbogrupo.h:47
TUnionDireccional
Definition: TUnionDireccional.h:33
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
TCCDescargaExtremoAbierto
Definition: TCCDescargaExtremoAbierto.h:43
TController
Definition: TController.h:37
TTubo::getTime1
double getTime1() const
Gets the time at the following time-step.
Definition: TTubo.cpp:5492
TDecisor
Definition: TDecisor.h:37
TCilindro
Definition: TCilindro.h:59
TTurbina
Definition: TTurbina.h:41
TCCPulso
Definition: TCCPulso.h:39
TTurbinaTwin
Definition: TTurbinaTwin.h:39
TCCExtremoInyeccion
Definition: TCCExtremoInyeccion.h:37
TController::AsignaObjetos
virtual void AsignaObjetos(TSensor **Sensor, TController **Controller)=0
TTipoValvula
Definition: TTipoValvula.h:53
TCCCompresorVolumetrico
Definition: TCCCompresorVolumetrico.h:37
TDPF
Definition: TDPF.h:45
TCCUnionEntreDepositos
Definition: TCCUnionEntreDepositos.h:41
TSensor::ObjectID
int ObjectID()
Definition: TSensor.cpp:438
TTubo::LeeDatosGeometricosTubo
void LeeDatosGeometricosTubo(const char *FileWAM, fpos_t &filepos, double ene, int tipomallado, TBloqueMotor **Engine)
Definition: TTubo.cpp:681
TCalculoExtern
Definition: TCalculoExtern.h:190
TWasteGate
Definition: TWasteGate.h:47
TCompTubDep
Definition: TCompTubDep.h:40
TValvulaContr
Definition: TValvulaContr.h:46
TPIDController
Definition: TPIDController.h:35
TLamina
Definition: TLamina.h:50
TCompresor
Definition: TCompresor.h:47
TCondicionContorno
Definition: TCondicionContorno.h:54
TCompresorDep
Definition: TCompresorDep.h:37
TCDFijo
Definition: TCDFijo.h:43
TSensor::AsignaObjeto
void AsignaObjeto(TObject *Object)
Definition: TSensor.cpp:125
TDeposito
Definition: TDeposito.h:44
TMariposa
Definition: TMariposa.h:43
TController::LeeController
virtual void LeeController(const char *FileWAM, fpos_t &filepos)=0
TValvula4T
Definition: TValvula4T.h:45
stDatosTGV
Definition: Globales.h:336
TSensor::ReadSensor
void ReadSensor(const char *FileWAM, fpos_t &filepos)
Definition: TSensor.cpp:49
Exception
Custom exception class.
Definition: Exception.hpp:39
TCompTubos
Definition: TCompTubos.h:79
TCFDConnection
Definition: TCFDConnection.h:10
TCCCompresor
Definition: TCCCompresor.h:44
TCCCilindro
Foo.
Definition: TCCCilindro.h:46
TGain
Definition: TGain.h:42
TDiscoRotativo
Definition: TDiscoRotativo.h:44
TCCEntradaCompresor
Definition: TCCEntradaCompresor.h:41
TTubo::getMallado
double getMallado() const
Gets the mesh size.
Definition: TTubo.cpp:5452
TSensor::ActualizaMedida
void ActualizaMedida(double Time)
Definition: TSensor.cpp:142
TTable1D
Definition: TTable1D.h:37
TCCRamificacion
Definition: TCCRamificacion.h:37
TCCPreVble
Definition: TCCPreVble.h:39
TVenturi
Definition: TVenturi.h:33
TLumbrera
Definition: TLumbrera.h:45
TBloqueMotor
Definition: TBloqueMotor.h:43
TEstatorTurbina
Definition: TEstatorTurbina.h:47
TCCDeposito
Definition: TCCDeposito.h:40
TTubo::LeeDatosGeneralesTubo
void LeeDatosGeneralesTubo(const char *FileWAM, fpos_t &filepos)
Definition: TTubo.cpp:535
TCDExterno
Definition: TCDExterno.h:43
TConcentricoDPF
Definition: TConcentricoDPF.h:37
TSensor
Definition: TSensor.h:42
TObject
Definition: Globales.h:2031
TDepVolVariable
Definition: TDepVolVariable.h:35
TCCPerdidadePresion
Definition: TCCPerdidadePresion.h:44
TCCUnionEntreTubos
Definition: TCCUnionEntreTubos.h:37
TController::IniciaMedias
virtual void IniciaMedias()=0
TConcentricoTubos
Definition: TConcentricoTubos.h:44
TCCExtremoCerrado
Definition: TCCExtremoCerrado.h:37
TConcentrico
Definition: TConcentrico.h:45
TCCExtremoAnecoico
Definition: TCCExtremoAnecoico.h:37
TCCExternalConnectionVol
Definition: TCCExternalConnectionVol.h:9
TCGestorWAM
Definition: TCGestorWAM.h:42
TOutputResults
Definition: TOutputResults.h:34
TDepVolCte
Definition: TDepVolCte.h:33
TSensor::IniciaMedias
void IniciaMedias()
Definition: TSensor.cpp:367
TTubo::getNodoIzq
int getNodoIzq() const
Gets the left-hand side node.
Definition: TTubo.cpp:5460
TTurbinaSimple
Definition: TTurbinaSimple.h:42