OpenWAM
TCalculoExtern.cpp
1 /*--------------------------------------------------------------------------------*\
2 ==========================|
3  \\ /\ /\ // O pen | OpenWAM: The Open Source 1D Gas-Dynamic Code
4  \\ | X | // W ave |
5  \\ \/_\/ // A ction | CMT-Motores Termicos / Universidad Politecnica Valencia
6  \\/ \// M odel |
7  ----------------------------------------------------------------------------------
8  License
9 
10  This file is part of OpenWAM.
11 
12  OpenWAM is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  OpenWAM is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with OpenWAM. If not, see <http://www.gnu.org/licenses/>.
24 
25 
26  \*--------------------------------------------------------------------------------*/
27 
28 //---------------------------------------------------------------------------
29 #pragma hdrstop
30 #include "TCalculoExtern.h"
31 
32 #ifdef __BORLANDC__
33 #include <vcl.h>
34 #endif
35 
36 //#include "TMatlab.h"
37 #include "TTubo.h"
38 #include "TDeposito.h"
39 #include "TCCDeposito.h"
40 #include "TTGV.h"
41 #include "TControlFuel.h"
42 #include "TEGRV.h"
43 #include "TRegimenMotor.h"
44 #include "Tfql.h"
45 #include "TEjeTurbogrupo.h"
46 #include "TTurbina.h"
47 #include "TVenturi.h"
48 #include "TTipoValvula.h"
49 #include "TBloqueMotor.h"
50 #include "TRemansoMatlab.h"
51 #include "TCoefDescarga.h"
52 #include "TAjusteTransCalorCil.h"
53 #include "TCCUnionEntreDepositos.h"
54 #include "TControlInyeccion.h"
55 #include "TFraccionMasicaCilindro.h"
56 #include "TControlK.h"
57 
58 //---------------------------------------------------------------------------
59 
60 TCalculoExtern::TCalculoExtern() {
61  FInputs = NULL;
62  FOutputs = NULL;
63  FEntrada = NULL;
64  FSalida = NULL;
65 
66 // ATENCION: Los siguiente valores determinan el numero de entradas y salidas a Matlab
67 // Debes modificar estos numeros segun tus requerimientos.
68 
69  FNumeroInMat = 0;
70  FNumeroOutMat = 0;
71 
72  if(FNumeroInMat > 0)
73  FEntrada = new double[FNumeroInMat];
74 
75  if(FNumeroOutMat > 0)
76  FSalida = new double[FNumeroOutMat];
77 
78 //ECU=NULL;
79  FTGV = NULL;
80  FFuel = NULL;
81  FEGRV = NULL;
82  FRegimen = NULL;
83  Ffql = NULL;
84  FRemansoMatlab = NULL;
85  FAjusteTransCalorCil = NULL;
86  FFraccionMasicaCilindro = NULL;
87  FControlInyeccion = NULL;
88 
89  FSensorTubo = NULL;
90  FSensorDep = NULL;
91  FSensorTG = NULL;
92  FSensorTurbina = NULL;
93  FSensorCil = NULL;
94  FSensorVent = NULL;
95  FSensorMotor = NULL;
96 
97  FTiempo = 0;
98 
99  FNSensTubos = 0;
100  FNSensDepositos = 0;
101  FNSensTurbina = 0;
102  FNSensTurbogrupo = 0;
103  FNSensMotor = 0;
104  FNSensVenturis = 0;
105  FNSensCilindros = 0;
106 
107  FRutaTrabajo = NULL;
108 
109  FConvergencia = false;
110  FCalculoGamma = nmComposicionTemperatura;
111  FParametros = NULL;
112 
113  FPrimeraVez = true;
114 }
115 
116 //------------------------------------------------------------------------------
117 //------------------------------------------------------------------------------
118 
119 TCalculoExtern::~TCalculoExtern() {
120 // if(ECU!=NULL) delete ECU;
121 
122  if(FTGV != NULL) {
123  for(int i = 0; i < Fcontadortgv; i++) {
124  delete FTGV[i];
125  }
126  delete[] FTGV;
127  }
128 
129  if(FFuel != NULL)
130  delete FFuel;
131 
132  if(FEGRV != NULL)
133  delete FEGRV;
134 
135  if(FRegimen != NULL)
136  delete FRegimen;
137 
138  if(Ffql != NULL)
139  delete Ffql;
140 
141  if(FAjusteTransCalorCil != NULL)
142  delete FAjusteTransCalorCil;
143 
144  if(FFraccionMasicaCilindro != NULL)
145  delete FFraccionMasicaCilindro;
146 
147  if(FControlInyeccion != NULL)
148  delete FControlInyeccion;
149 
150  if(FInputs != NULL)
151  delete[] FInputs;
152 
153  if(FOutputs != NULL)
154  delete[] FOutputs;
155 
156  if(FEntrada != NULL)
157  delete[] FEntrada;
158 
159  if(FSalida != NULL)
160  delete[] FSalida;
161 
162  if(FSensorTubo != NULL)
163  delete[] FSensorTubo;
164 
165  if(FSensorDep != NULL)
166  delete[] FSensorDep;
167 
168  if(FSensorTG != NULL)
169  delete[] FSensorTG;
170 
171  if(FSensorTurbina != NULL)
172  delete[] FSensorTurbina;
173 
174  if(FSensorCil != NULL)
175  delete[] FSensorCil;
176 
177  if(FSensorVent != NULL)
178  delete[] FSensorVent;
179 
180  if(FSensorMotor != NULL)
181  delete[] FSensorMotor;
182 
183  if(FRemansoMatlab != NULL) {
184  for(int i = 0; i < Fnematlab; i++) {
185  delete FRemansoMatlab[i];
186  }
187  delete[] FRemansoMatlab;
188  }
189 
190  if(FCoefDescarga != NULL) {
191  for(int i = 0; i < Fnumunion; i++) {
192  delete FCoefDescarga[i];
193  }
194  delete[] FCoefDescarga;
195  }
196 
197  if(FRutaTrabajo != NULL)
198  delete[] FRutaTrabajo;
199 
200  if(FParametros != NULL)
201  delete[] FParametros;
202 }
203 
204 //-------------------------------------------------------------------------
205 //---------------------------------------------------------------------------
206 
207 void TCalculoExtern::LlamadaECU(double DeltaT, TBloqueMotor **Engine) {
208  try {
209 
210  FTiempo += DeltaT;
211 
212  //ATENCION: Asignar los valores que provienen de los sensores. El orden es muy importante.
213 
214  /* FInputs[0]=FSensorTubo[0].valact; // "Presion a la entrada de la turbina"
215  FInputs[1]=FSensorTubo[1].valact; // "Temperature a la entrada de la turbina"
216  FInputs[2]=FSensorTubo[2].valact; // "Massflow masico de EGR"
217  FInputs[3]=FSensorTubo[3].valact; // "Temperature a la salida del intercooler"
218  FInputs[4]=FSensorTubo[4].valact; // "Massflow masico antes del intercooler"
219  FInputs[5]=FSensorTubo[5].valact; // "Presion a la salida del intercooler (antes de la ramificacion en el colector"
220  FInputs[6]=FSensorMotor[0].valact; // "Regimen de giro del motor"
221  FInputs[7]=FSensorMotor[1].valact; // "Instante de tiempo del motor" */
222 
223 // if(Fhayecu){
224 //
225 // //ATENCION: A continuacion se deben asignar los valores de entrada de MATLAB
226 // //-----------------------------------------------------------------------------
227 // //
228 // //-----------------------------------------------------------------------------
229 //
230 // if(FTiempo>=Ftmuestreoecu){
231 // FTiempo=0.;
232 // for(int i=0;i<FNumeroInMat;i++)
233 // {
234 // ECU->Input[i]=FEntrada[i]; /*Al igual que el numero de entradas a Matlab (FNumeroInMat), los valores de FEntrada han de ser dados por cada usuario)*/
235 // }
236 // ECU->CalculaECU();
237 //
238 // //ATENCION: A continuacion se deben asignar los valores de salida de MATLAB
239 // //-----------------------------------------------------------------------------
240 // for(int i=0;i<FNumeroOutMat;i++)
241 // {/* estas son las variable que vienen de Matlab*/
242 // FSalida[i]=ECU->GetOutput(i);
243 // }
244 // //-----------------------------------------------------------------------------
245 // }
246 // }
247  //=========================================================================
248  //AQUI SE DEBEN REALIZAR LOS CALCULOS EXTERNOS
249  //*****************************************
250  //**** CALCULO DE LA DESCARGA A MATLAB ****//
251  //FRemansoMatlab[0]->CalculaRemanso(FInputs[1]);
252  /*if(FTiempo>=Ftmuestreoecu){
253  FTiempo=0.;
254  FEGRV->CalculaEGRV(FInputs[7],FInputs[2],FInputs[4],FConvergencia);
255  FTGV[0]->CalculaTurbina(FInputs[7],FInputs[5],FInputs[0],FConvergencia);
256  FAjusteTransCalorCil->CalculaTCC(FInputs[7],FInputs[4],FInputs[1],FConvergencia);
257  */
258  /* CONVERGENCIA DE LA EJECUCION */
259  /* if(FInputs[7]>0.6){
260  if(fabs(FTGV[0]->ErrorP2)<0.03 & fabs(FTGV[0]->ErrorP3)<0.03 & fabs(FEGRV->ErrorEGR)<0.01 & fabs(FAjusteTransCalorCil->getErrorGastoAire())<0.03){
261  FConvergencia=true;
262  }
263  }
264  } */
265 
266  //**** CALCULO COEFICIENTE DE DESCARGA EGR ****//
267 //FOutputs[0]=FEGRV->PutCDEntrante(FEGRV->CDEntrante);
268  //FOutputs[1]=FEGRV->getCDSaliente();
269  //FOutputs[2]=FEGRV->getCTorbellino();
270  //**** CALCULO DEL COMBUSTIBLE ACTUAL ****//
271  /* for(int i=0;i<Engine[0]->getGeometria().NCilin;i++){
272  if(Engine[0]->GetCilindro(i)->getAnguloActual()>Engine[0]->GetCilindro(i)->getDistribucion().CA && Engine[0]->GetCilindro(i)->getAnguloAnterior()<=Engine[0]->GetCilindro(i)->getDistribucion().CA){
273  double Fuel=FFuel->CalculaFuel();
274  FOutputs[i+3]=Fuel;
275  }
276  } */
277 
278  //**** CALCULO DE LOS Actuators EN TGV ****//
279  //FOutputs[0]=FTGV[0]->getCDStator();
280  //FOutputs[1]=FTGV[0]->getCDRotor();
281  //FOutputs[2]=FTGV[0]->getRendimiento();
282  // Hay 3 salidas mas, por si fuese una turbina twin. Indices 10,11,12
283  //**** CALCULO DE LOS COEFICIENTES DE TRANSMISION DE CALOR EN ADMISION Y ESCAPE****//
284  /*FOutputs[13]=FAjusteTransCalorCil->CAdmision;
285  FOutputs[14]=FAjusteTransCalorCil->CEscape;*/
286 
287  /* Variables que vienen de MATLAB */
288  //for(int i=0;i<FNumeroOutMat;i++){
289  // FOutputs[i]=FSalida[i];
290  //}
291  FOutputs[0] = FTiempo * 0.02;
292  FOutputs[1] = FTiempo * 0.02;
293  FOutputs[2] = 0;
294  if(FOutputs[0] > 1)
295  FOutputs[0] = 1;
296  if(FOutputs[1] > 1)
297  FOutputs[1] = 1;
298  } catch(exception &N) {
299  std::cout << "ERROR: LlamadaECU" << std::endl;
300  std::cout << "Tipo de error: " << N.what() << std::endl;
301  throw Exception(N.what());
302  }
303 }
304 
305 //-----------------------------------------------------------------------------
306 //-----------------------------------------------------------------------------
307 
308 void TCalculoExtern::FinECU() {
309  try {
310 //if(Fhayecu){
311 // ECU->FinalizaECU();
312 //}
313 
314  } catch(exception &N) {
315  std::cout << "ERROR: PutInputdll" << std::endl;
316  std::cout << "Tipo de error: " << N.what() << std::endl;
317  throw Exception(N.what());
318  }
319 }
320 
321 //------------------------------------------------------------------------------
322 //---------------------------------------------------------------------------
323 
324 double TCalculoExtern::GetOutput_dll(int i) {
325  try {
326  if(i < FNOutputsdll) {
327  return FOutputs[i];
328  } else {
329  std::cout << "WARNING: El valor de la salida de la dll se sale de rango" << std::endl;
330  std::cout << " Revisa el acceso a la dll" << std::endl;
331  return 0.;
332  }
333  } catch(exception &N) {
334  std::cout << "ERROR: GetOutputdll" << std::endl;
335  std::cout << "Tipo de error: " << N.what() << std::endl;
336  throw Exception(N.what());
337  }
338 }
339 
340 //------------------------------------------------------------------------------
341 //---------------------------------------------------------------------------
342 
343 TRemansoMatlab* TCalculoExtern::GetTRemansoMatlab(int i) {
344  try {
345 // if(i<FNOutputsdll){
346  return FRemansoMatlab[i];
347 // }else{
348 // std::cout << "WARNING: El valor de la salida de la dll se sale de rango" << std::endl;
349 // std::cout << " Revisa el acceso a la dll" << std::endl;
350 // return 0.;
351 // }
352  } catch(exception &N) {
353  std::cout << "ERROR: GetTRemansoMatlab" << std::endl;
354  std::cout << "Tipo de error: " << N.what() << std::endl;
355  throw Exception(N.what());
356  }
357 }
358 
359 //------------------------------------------------------------------------------
360 //---------------------------------------------------------------------------
361 
362 TCoefDescarga* TCalculoExtern::GetTCoefDescarga(int i) {
363  try {
364 // if(i<FNOutputsdll){
365  return FCoefDescarga[i];
366 // }else{
367 // std::cout << "WARNING: El valor de la salida de la dll se sale de rango" << std::endl;
368 // std::cout << " Revisa el acceso a la dll" << std::endl;
369 // return 0.;
370 // }
371  } catch(exception &N) {
372  std::cout << "ERROR: GetTCoefDescarga" << std::endl;
373  std::cout << "Tipo de error: " << N.what() << std::endl;
374  throw Exception(N.what());
375  }
376 }
377 
378 //------------------------------------------------------------------------------
379 //---------------------------------------------------------------------------
380 
381 TControlFuel* TCalculoExtern::GetFuel() {
382  try {
383 // if(i<FNOutputsdll){
384  return FFuel;
385 // }else{
386 // std::cout << "WARNING: El valor de la salida de la dll se sale de rango" << std::endl;
387 // std::cout << " Revisa el acceso a la dll" << std::endl;
388 // return 0.;
389 // }
390  } catch(exception &N) {
391  std::cout << "ERROR: GetFuel" << std::endl;
392  std::cout << "Tipo de error: " << N.what() << std::endl;
393  throw Exception(N.what());
394  }
395 }
396 
397 //------------------------------------------------------------------------------
398 //---------------------------------------------------------------------------
399 
400 void TCalculoExtern::LeeFicherosDLL(const char *FileWAM, fpos_t &filepos, int controlvalv, int nematlab, int ncilin,
401  int nunmat, int CountVGT, int numespecies, int NumeroPerdidasPresion) {
402  try {
403  FILE *fich = fopen(FileWAM, "r");
404  fsetpos(fich, &filepos);
405 
406  ObtenerRutaTrabajo(FileWAM);
407 
408  int ecu = 0, iny = 0, mfcomb = 0, comb = 0, baraba = 0, Yespecies = 0, CalculoK = 0;
409  Fhayecu = false;
410  Fcontroliny = false;
411  Fcontrolmfcomb = false;
412  Fmodcomb = false;
413  Fajustbaraba = false;
414  FFraccionMasicaEspeciesCil = false;
415  FCalculoK = false;
416  Fngrafmat = 0;
417  Ftmuestreoecu = 0.02;
418  fscanf(fich, " %d ", &ecu);
419  ecu == 0 ? Fhayecu = false : Fhayecu = true;
420  fscanf(fich, "%d %d %d %d %d %d ", &iny, &mfcomb, &comb, &baraba, &Yespecies, &CalculoK);
421  iny == 0 ? Fcontroliny = false : Fcontroliny = true;
422  mfcomb == 0 ? Fcontrolmfcomb = false : Fcontrolmfcomb = true;
423  comb == 0 ? Fmodcomb = false : Fmodcomb = true;
424  baraba == 0 ? Fajustbaraba = false : Fajustbaraba = true;
425  Yespecies == 0 ? FFraccionMasicaEspeciesCil = false : FFraccionMasicaEspeciesCil = true;
426  fscanf(fich, "%d ", &Fngrafmat); /* numero de magnitudes de la ECU que queremos graficar */
427  if(Fhayecu) {
428  //ECU=new TMatlab(FNumeroInMat,FNumeroOutMat);
429  //fscanf(fich,"%lf ",&Ftmuestreoecu);
430  //ECU->LeeFicherosECU(fich);
431  //ECU->IniciaECU();
432  std::cout << "WARNING: Matlab link must be adapted with your Matlab version" << std::endl;
433  }
434  if(controlvalv == 1) {
435  Fntact = nunmat * 3;
436  Fnumunion = nunmat;
437  /*FCoefDescarga=new TCoefDescarga*[nematlab];
438  for (int i=0;i<Fnumunion;i++){
439  FCoefDescarga[i]=new TCoefDescarga();
440 
441  } */
442  }
443  if(Fcontrolmfcomb) {
444  Fntact += ncilin;
445  }
446  if(Fcontroliny) {
447  Fntact += 18 * ncilin;
448  FControlInyeccion = new TControlInyeccion();
449  }
450  if(Fajustbaraba) {
451  Fntact += 2;
452  FAjusteTransCalorCil = new TAjusteTransCalorCil();
453  }
454  if(Fmodcomb) {
455  Fntact += 3 * ncilin;
456  Ffql = new Tfql(ncilin);
457  }
458  if(FFraccionMasicaEspeciesCil) {
459  Fntact += numespecies * ncilin;
460  FFraccionMasicaCilindro = new TFraccionMasicaCilindro();
461  }
462  Fntact += nematlab * 2;
463  Fntact += CountVGT * 6;
464  Fcontadortgv = CountVGT;
465  if(CountVGT != 0) {
466  FTGV = new TTGV*[CountVGT];
467  for(int i = 0; i < CountVGT; i++) {
468  FTGV[i] = new TTGV();
469  }
470  }
471  if(Fcontrolmfcomb) {
472  FFuel = new TControlFuel();
473  }
474 
475  FNumPerdidasPresion = 0;
476  if(FCalculoK) {
477  FNumPerdidasPresion = NumeroPerdidasPresion;
478  FControlK = new TControlK*[FNumPerdidasPresion];
479  for(int i = 0; i < FNumPerdidasPresion; i++) {
480  FControlK[i] = new TControlK();
481  }
482  Fntact += FNumPerdidasPresion;
483  }
484 
485  Fnematlab = nematlab;
486  if(Fnematlab != 0) {
487  FRemansoMatlab = new TRemansoMatlab*[nematlab];
488  for(int i = 0; i < Fnematlab; i++) {
489  FRemansoMatlab[i] = new TRemansoMatlab();
490  }
491  }
492  /*Si no hay valvula de EGR la siguiente linea se debe comentar*/
493  FEGRV = new TEGRV();
494  //FRegimen=new TRegimenMotor();
495  FNOutputsdll = Fntact;
496  FOutputs = new double[FNOutputsdll];
497  for(int i = 0; i < FNOutputsdll; i++) {
498  FOutputs[i] = 0.;
499  }
500 
501  fgetpos(fich, &filepos);
502  fclose(fich);
503  } catch(exception &N) {
504  std::cout << "ERROR: LeeFicherosDLL" << std::endl;
505  std::cout << "Tipo de error: " << N.what() << std::endl;
506  throw Exception(N.what());
507  }
508 }
509 
510 //---------------------------------------------------------------------------
511 //-----------------------------------------------------------------------------
512 
513 void TCalculoExtern::Lee_Sens_Tubos(const char *FileWAM, fpos_t &filepos, TTubo **Pipe,
514  nmTipoCalculoEspecies SpeciesModel, bool ThereIsEGR, bool HayCombustible) {
515  try {
516  FILE *fich = fopen(FileWAM, "r");
517  fsetpos(fich, &filepos);
518 
519  double T = 0., temp = 0., v1 = 0., den = 0.;
520  int n1 = 0, t = 0;
521  int tipo = 0, tubo = 0, nsensortubo = 0, ndistancias = 0;
522  double dist = 0.;
523  ndistancias = 0;
524  fscanf(fich, "%d ", &FNSensTubos); /*numero de sensores en tubos*/
525  fscanf(fich, "%d ", &ndistancias); /*numero total de distancias*/
526  int cont = 0;
527  FSensorTubo = new stSensorTubos[FNSensTubos];
528  if(FNSensTubos != 0) {
529  for(int i = 0; i <= ndistancias - 1; ++i) {
530  fscanf(fich, "%d %lf %d ", &tubo, &dist, &nsensortubo);
531  for(int j = 0; j <= nsensortubo - 1; ++j) {
532  FSensorTubo[cont].tubo = tubo;
533  FSensorTubo[cont].distancia = dist;
534  fscanf(fich, "%d ", &tipo);
535  switch(tipo) {
536  case 0:
537  FSensorTubo[cont].tipo = nmPrTubo;
538  break;
539  case 1:
540  FSensorTubo[cont].tipo = nmVelTubo;
541  break;
542  case 2:
543  FSensorTubo[cont].tipo = nmTempTubo;
544  break;
545  case 3:
546  FSensorTubo[cont].tipo = nmGastoTubo;
547  break;
548  case 4:
549  FSensorTubo[cont].tipo = nmN2Tubo;
550  break;
551  case 5:
552  FSensorTubo[cont].tipo = nmO2Tubo;
553  break;
554  case 6:
555  FSensorTubo[cont].tipo = nmCO2Tubo;
556  break;
557  case 7:
558  FSensorTubo[cont].tipo = nmH2OTubo;
559  break;
560  case 8:
561  FSensorTubo[cont].tipo = nmHCTubo;
562  break;
563  case 9:
564  FSensorTubo[cont].tipo = nmSootTubo;
565  break;
566  case 10:
567  FSensorTubo[cont].tipo = nmNOxTubo;
568  break;
569  case 11:
570  FSensorTubo[cont].tipo = nmCOTubo;
571  break;
572  case 12:
573  FSensorTubo[cont].tipo = nmAireFrTubo;
574  break;
575  case 13:
576  FSensorTubo[cont].tipo = nmGasQuemadoTubo;
577  break;
578  case 14:
579  FSensorTubo[cont].tipo = nmEGRTubo;
580  break;
581  case 15:
582  FSensorTubo[cont].tipo = nmCombustibleTubo;
583  break;
584  default:
585  printf("Error en el tipo de sensor\n");
586  throw Exception("");
587  } /*fin del switch*/
588  fscanf(fich, "%lf ", &FSensorTubo[cont].ganancia);
589  fscanf(fich, "%lf ", &FSensorTubo[cont].ctetiempo);
590 
591  FSensorTubo[cont].nodos = Pipe[FSensorTubo[cont].tubo - 1]->getNin();
592  FSensorTubo[cont].deltax = Pipe[FSensorTubo[cont].tubo - 1]->getXRef();
593 
594  t = FSensorTubo[cont].tubo - 1;
595 
596  switch(FSensorTubo[cont].tipo) {
597  case nmTempTubo:
598  temp = Pipe[t]->GetAsonido(0) * __cons::ARef;
599  FSensorTubo[cont].valreal = __units::KTodegC(temp * temp / Pipe[t]->GetGamma(0) / Pipe[t]->GetRMezcla(
600  0)); // Como es el instante inicial da igual el nodo a que se hace referencia
601  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
602  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
603  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
604  break;
605  case nmPrTubo:
606  FSensorTubo[cont].valreal = Pipe[t]->getPresionInicial();
607  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
608  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
609  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
610  break;
611  case nmVelTubo:
612  FSensorTubo[cont].valreal = Pipe[t]->getVelocidadMedia();
613  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
614  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
615  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
616  break;
617  case nmGastoTubo:
618  temp = Pipe[t]->GetAsonido(0) * __cons::ARef; // Como es el instante inicial el nodo es arbitrario
619  T = __units::KTodegC(temp * temp / Pipe[t]->GetGamma(0) / Pipe[t]->GetRMezcla(0));
620  den = __units::BarToPa(Pipe[t]->getPresionInicial()) / Pipe[t]->GetRMezcla(0) / __units::degCToK(T);
621  v1 = Pipe[t]->getVelocidadMedia();
622  FSensorTubo[cont].valreal = __geom::Circle_area(Pipe[t]->GetDiametro(n1)) * v1 * den;
623  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
624  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
625  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
626  break;
627  case nmN2Tubo:
628  if(SpeciesModel == nmCalculoCompleto) {
629  if(HayCombustible) {
630  FIndiceTuboN2 = 8;
631  } else
632  FIndiceTuboN2 = 7;
633  } else {
634  printf("No puede haber sensor de N2 si el calculo de especies no es completo. Revisa la lectura.\n");
635  throw Exception("");
636  }
637  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboN2);
638  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
639  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
640  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
641  break;
642  case nmO2Tubo:
643  if(SpeciesModel == nmCalculoCompleto) {
644  FIndiceTuboO2 = 0;
645  } else {
646  printf("No puede haber sensor de O2 si el calculo de especies no es completo. Revisa la lectura.\n");
647  throw Exception("");
648  }
649  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboO2);
650  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
651  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
652  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
653  break;
654  case nmCO2Tubo:
655  if(SpeciesModel == nmCalculoCompleto) {
656  FIndiceTuboCO2 = 1;
657  } else {
658  printf("No puede haber sensor de CO2 si el calculo de especies no es completo. Revisa la lectura.\n");
659  throw Exception("");
660  }
661  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboCO2);
662  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
663  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
664  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
665  break;
666  case nmH2OTubo:
667  if(SpeciesModel == nmCalculoCompleto) {
668  FIndiceTuboH2O = 2;
669  } else {
670  printf("No puede haber sensor de H2O si el calculo de especies no es completo. Revisa la lectura.\n");
671  throw Exception("");
672  }
673  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboH2O);
674  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
675  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
676  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
677  break;
678  case nmHCTubo:
679  if(SpeciesModel == nmCalculoCompleto) {
680  FIndiceTuboHC = 3;
681  } else {
682  printf("No puede haber sensor de HC si el calculo de especies no es completo. Revisa la lectura.\n");
683  throw Exception("");
684  }
685  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboHC);
686  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
687  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
688  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
689  break;
690  case nmSootTubo:
691  if(SpeciesModel == nmCalculoCompleto) {
692  FIndiceTuboSoot = 4;
693  } else {
694  printf("No puede haber sensor de Soot si el calculo de especies no es completo. Revisa la lectura.\n");
695  throw Exception("");
696  }
697  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboSoot);
698  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
699  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
700  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
701  break;
702  case nmNOxTubo:
703  if(SpeciesModel == nmCalculoCompleto) {
704  FIndiceTuboNOx = 5;
705  } else {
706  printf("No puede haber sensor de NOx si el calculo de especies no es completo. Revisa la lectura.\n");
707  throw Exception("");
708  }
709  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboNOx);
710  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
711  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
712  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
713  break;
714  case nmCOTubo:
715  if(SpeciesModel == nmCalculoCompleto) {
716  FIndiceTuboCO = 6;
717  } else {
718  printf("No puede haber sensor de CO si el calculo de especies no es completo. Revisa la lectura.\n");
719  throw Exception("");
720  }
721  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboCO);
722  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
723  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
724  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
725  break;
726  case nmAireFrTubo:
727  if(SpeciesModel == nmCalculoSimple) {
728  if(HayCombustible) {
729  FIndiceTuboAireFresco = 2;
730  } else
731  FIndiceTuboAireFresco = 1;
732  } else {
733  printf("No puede haber sensor de Aire Fresco si el calculo de especies no es simple. Revisa la lectura.\n");
734  throw Exception("");
735  }
736  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboAireFresco);
737  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
738  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
739  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
740  break;
741  case nmGasQuemadoTubo:
742  if(SpeciesModel == nmCalculoSimple) {
743  FIndiceTuboGasQuemado = 0;
744  } else {
745  printf("No puede haber sensor de Gas Quemado si el calculo de especies no es simple. Revisa la lectura.\n");
746  throw Exception("");
747  }
748  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboGasQuemado);
749  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
750  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
751  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
752  break;
753  case nmEGRTubo:
754  if(SpeciesModel == nmCalculoCompleto) {
755  if(HayCombustible) {
756  if(ThereIsEGR) {
757  FIndiceTuboEGR = 9;
758  } else {
759  printf("No puede haber sensor de EGR si no se transporta EGR. Revisa la lectura.\n");
760  throw Exception("");
761  }
762  } else {
763  if(ThereIsEGR) {
764  FIndiceTuboEGR = 8;
765  } else {
766  printf("No puede haber sensor de EGR si no se transporta EGR. Revisa la lectura.\n");
767  throw Exception("");
768  }
769  }
770  } else {
771  if(HayCombustible) {
772  if(ThereIsEGR) {
773  FIndiceTuboEGR = 3;
774  } else {
775  printf("No puede haber sensor de EGR si no se transporta EGR. Revisa la lectura.\n");
776  throw Exception("");
777  }
778  } else {
779  if(ThereIsEGR) {
780  FIndiceTuboEGR = 2;
781  } else {
782  printf("No puede haber sensor de EGR si no se transporta EGR. Revisa la lectura.\n");
783  throw Exception("");
784  }
785  }
786  }
787  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboEGR);
788  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
789  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
790  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
791  break;
792  case nmCombustibleTubo:
793  if(SpeciesModel == nmCalculoCompleto) {
794  if(HayCombustible) {
795  FIndiceTuboComb = 7;
796  } else {
797  printf("No puede haber sensor de Combustible si no se transporta. Revisa la lectura.\n");
798  throw Exception("");
799  }
800  } else {
801  if(HayCombustible) {
802  FIndiceTuboComb = 1;
803  } else {
804  printf("No puede haber sensor de Combustible si no se transporta. Revisa la lectura.\n");
805  throw Exception("");
806  }
807  }
808  FSensorTubo[cont].valreal = Pipe[t]->GetFraccionMasica(0, FIndiceTuboComb);
809  FSensorTubo[cont].valact = FSensorTubo[cont].valreal;
810  FSensorTubo[cont].valant = FSensorTubo[cont].valreal;
811  FSensorTubo[cont].valrealant = FSensorTubo[cont].valreal;
812  break;
813  }/*fin del switch*/
814 
815  cont++;
816  }/*Fin for sensores para cada tubo*/
817  }/*Fin for numero de distancias*/
818 
819  }
820 
821  fgetpos(fich, &filepos);
822  fclose(fich);
823  } catch(exception &N) {
824  std::cout << "ERROR: Lee_Sens_Tubos" << std::endl;
825  std::cout << "Tipo de error: " << N.what() << std::endl;
826  throw Exception(N.what());
827  }
828 }
829 
830 //---------------------------------------------------------------------------
831 //---------------------------------------------------------------------------
832 
833 void TCalculoExtern::Lee_Sens_Dep(const char *FileWAM, fpos_t &filepos, TDeposito **Plenum,
834  nmTipoCalculoEspecies SpeciesModel, bool ThereIsEGR, bool HayCombustible) {
835  try {
836  FILE *fich = fopen(FileWAM, "r");
837  fsetpos(fich, &filepos);
838 
839  int tipo = 0, ndep = 0, deposito = 0, nsensdeposito = 0;
840  ndep = 0;
841  fscanf(fich, "%d ", &FNSensDepositos); /*numero de sensores en depositos*/
842  fscanf(fich, "%d ", &ndep); /*numero de depositos con sensores*/
843  int cont = 0;
844  FSensorDep = new stSensorDep[FNSensDepositos];
845  if(FNSensDepositos != 0) {
846  for(int i = 0; i <= ndep - 1; ++i) {
847  fscanf(fich, "%d %d ", &deposito, &nsensdeposito);
848  for(int j = 0; j <= nsensdeposito - 1; ++j) {
849  FSensorDep[cont].deposito = deposito;
850  fscanf(fich, "%d ", &tipo);
851  switch(tipo) {
852  case 0:
853  FSensorDep[cont].tipo = nmPrDep;
854  break;
855  case 1:
856  FSensorDep[cont].tipo = nmTempDep;
857  break;
858  case 2:
859  FSensorDep[cont].tipo = nmN2Dep;
860  break;
861  case 3:
862  FSensorDep[cont].tipo = nmO2Dep;
863  break;
864  case 4:
865  FSensorDep[cont].tipo = nmCO2Dep;
866  break;
867  case 5:
868  FSensorDep[cont].tipo = nmH2ODep;
869  break;
870  case 6:
871  FSensorDep[cont].tipo = nmHCDep;
872  break;
873  case 7:
874  FSensorDep[cont].tipo = nmSootDep;
875  break;
876  case 8:
877  FSensorDep[cont].tipo = nmNOxDep;
878  break;
879  case 9:
880  FSensorDep[cont].tipo = nmCODep;
881  break;
882  case 10:
883  FSensorDep[cont].tipo = nmAireFrDep;
884  break;
885  case 11:
886  FSensorDep[cont].tipo = nmGasQuemadoDep;
887  break;
888  case 12:
889  FSensorDep[cont].tipo = nmEGRDep;
890  break;
891  case 13:
892  FSensorDep[cont].tipo = nmCombustibleDep;
893  break;
894  default:
895  printf("Error en el tipo de sensor\n");
896  throw Exception("");
897  } /*fin del switch*/
898  fscanf(fich, "%lf ", &FSensorDep[cont].ganancia);
899  fscanf(fich, "%lf ", &FSensorDep[cont].ctetiempo);
900 
901  switch(FSensorDep[cont].tipo) {
902  case nmPrDep:
903  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->getPressure();
904  FSensorDep[cont].valact = FSensorDep[cont].valreal;
905  FSensorDep[cont].valant = FSensorDep[cont].valreal;
906  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
907  break;
908  case nmTempDep:
909  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->getTemperature();
910  FSensorDep[cont].valact = FSensorDep[cont].valreal;
911  FSensorDep[cont].valant = FSensorDep[cont].valreal;
912  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
913  break;
914  case nmN2Dep:
915  if(SpeciesModel == nmCalculoCompleto) {
916  if(HayCombustible) {
917  FIndiceDepN2 = 8;
918  } else
919  FIndiceDepN2 = 7;
920  } else {
921  printf("No puede haber sensor de N2 si el calculo de especies no es completo. Revisa la lectura.\n");
922  throw Exception("");
923  }
924  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepN2);
925  FSensorDep[cont].valact = FSensorDep[cont].valreal;
926  FSensorDep[cont].valant = FSensorDep[cont].valreal;
927  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
928  break;
929  case nmO2Dep:
930  if(SpeciesModel == nmCalculoCompleto) {
931  FIndiceDepO2 = 0;
932  } else {
933  printf("No puede haber sensor de O2 si el calculo de especies no es completo. Revisa la lectura.\n");
934  throw Exception("");
935  }
936  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepO2);
937  FSensorDep[cont].valact = FSensorDep[cont].valreal;
938  FSensorDep[cont].valant = FSensorDep[cont].valreal;
939  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
940  break;
941  case nmCO2Dep:
942  if(SpeciesModel == nmCalculoCompleto) {
943  FIndiceDepCO2 = 1;
944  } else {
945  printf("No puede haber sensor de CO2 si el calculo de especies no es completo. Revisa la lectura.\n");
946  throw Exception("");
947  }
948  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepCO2);
949  FSensorDep[cont].valact = FSensorDep[cont].valreal;
950  FSensorDep[cont].valant = FSensorDep[cont].valreal;
951  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
952  break;
953  case nmH2ODep:
954  if(SpeciesModel == nmCalculoCompleto) {
955  FIndiceDepH2O = 2;
956  } else {
957  printf("No puede haber sensor de H2O si el calculo de especies no es completo. Revisa la lectura.\n");
958  throw Exception("");
959  }
960  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepH2O);
961  FSensorDep[cont].valact = FSensorDep[cont].valreal;
962  FSensorDep[cont].valant = FSensorDep[cont].valreal;
963  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
964  break;
965  case nmHCDep:
966  if(SpeciesModel == nmCalculoCompleto) {
967  FIndiceDepHC = 3;
968  } else {
969  printf("No puede haber sensor de HC si el calculo de especies no es completo. Revisa la lectura.\n");
970  throw Exception("");
971  }
972  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepHC);
973  FSensorDep[cont].valact = FSensorDep[cont].valreal;
974  FSensorDep[cont].valant = FSensorDep[cont].valreal;
975  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
976  break;
977  case nmSootDep:
978  if(SpeciesModel == nmCalculoCompleto) {
979  FIndiceDepSoot = 4;
980  } else {
981  printf("No puede haber sensor de Soot si el calculo de especies no es completo. Revisa la lectura.\n");
982  throw Exception("");
983  }
984  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepSoot);
985  FSensorDep[cont].valact = FSensorDep[cont].valreal;
986  FSensorDep[cont].valant = FSensorDep[cont].valreal;
987  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
988  break;
989  case nmNOxDep:
990  if(SpeciesModel == nmCalculoCompleto) {
991  FIndiceDepNOx = 5;
992  } else {
993  printf("No puede haber sensor de NOx si el calculo de especies no es completo. Revisa la lectura.\n");
994  throw Exception("");
995  }
996  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepNOx);
997  FSensorDep[cont].valact = FSensorDep[cont].valreal;
998  FSensorDep[cont].valant = FSensorDep[cont].valreal;
999  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
1000  break;
1001  case nmCODep:
1002  if(SpeciesModel == nmCalculoCompleto) {
1003  FIndiceDepCO = 6;
1004  } else {
1005  printf("No puede haber sensor de CO si el calculo de especies no es completo. Revisa la lectura.\n");
1006  throw Exception("");
1007  }
1008  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepCO);
1009  FSensorDep[cont].valact = FSensorDep[cont].valreal;
1010  FSensorDep[cont].valant = FSensorDep[cont].valreal;
1011  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
1012  break;
1013  case nmAireFrDep:
1014  if(SpeciesModel == nmCalculoSimple) {
1015  if(HayCombustible) {
1016  FIndiceDepAireFresco = 2;
1017  } else
1018  FIndiceDepAireFresco = 1;
1019  } else {
1020  printf("No puede haber sensor de Aire Fresco si el calculo de especies no es simple. Revisa la lectura.\n");
1021  throw Exception("");
1022  }
1023  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepAireFresco);
1024  FSensorDep[cont].valact = FSensorDep[cont].valreal;
1025  FSensorDep[cont].valant = FSensorDep[cont].valreal;
1026  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
1027  break;
1028  case nmGasQuemadoDep:
1029  if(SpeciesModel == nmCalculoSimple) {
1030  FIndiceDepGasQuemado = 0;
1031  } else {
1032  printf("No puede haber sensor de Gas Quemado si el calculo de especies no es simple. Revisa la lectura.\n");
1033  throw Exception("");
1034  }
1035  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepGasQuemado);
1036  FSensorDep[cont].valact = FSensorDep[cont].valreal;
1037  FSensorDep[cont].valant = FSensorDep[cont].valreal;
1038  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
1039  break;
1040  case nmEGRDep:
1041  if(SpeciesModel == nmCalculoCompleto) {
1042  if(HayCombustible) {
1043  if(ThereIsEGR) {
1044  FIndiceDepEGR = 9;
1045  } else {
1046  printf("No puede haber sensor de EGR si no se transporta EGR. Revisa la lectura.\n");
1047  throw Exception("");
1048  }
1049  } else {
1050  if(ThereIsEGR) {
1051  FIndiceDepEGR = 8;
1052  } else {
1053  printf("No puede haber sensor de EGR si no se transporta EGR. Revisa la lectura.\n");
1054  throw Exception("");
1055  }
1056  }
1057  } else {
1058  if(HayCombustible) {
1059  if(ThereIsEGR) {
1060  FIndiceDepEGR = 3;
1061  } else {
1062  printf("No puede haber sensor de EGR si no se transporta EGR. Revisa la lectura.\n");
1063  throw Exception("");
1064  }
1065  } else {
1066  if(ThereIsEGR) {
1067  FIndiceDepEGR = 2;
1068  } else {
1069  printf("No puede haber sensor de EGR si no se transporta EGR. Revisa la lectura.\n");
1070  throw Exception("");
1071  }
1072  }
1073  }
1074  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepEGR);
1075  FSensorDep[cont].valact = FSensorDep[cont].valreal;
1076  FSensorDep[cont].valant = FSensorDep[cont].valreal;
1077  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
1078  break;
1079  case nmCombustibleDep:
1080  if(SpeciesModel == nmCalculoCompleto) {
1081  if(HayCombustible) {
1082  FIndiceDepComb = 7;
1083  } else {
1084  printf("No puede haber sensor de Combustible si no se transporta. Revisa la lectura.\n");
1085  throw Exception("");
1086  }
1087  } else {
1088  if(HayCombustible) {
1089  FIndiceDepComb = 1;
1090  } else {
1091  printf("No puede haber sensor de Combustible si no se transporta. Revisa la lectura.\n");
1092  throw Exception("");
1093  }
1094  }
1095  FSensorDep[cont].valreal = Plenum[FSensorDep[cont].deposito - 1]->GetFraccionMasicaEspecie(FIndiceDepComb);
1096  FSensorDep[cont].valact = FSensorDep[cont].valreal;
1097  FSensorDep[cont].valant = FSensorDep[cont].valreal;
1098  FSensorDep[cont].valrealant = FSensorDep[cont].valreal;
1099  break;
1100  }/*fin del switch*/
1101 
1102  cont++;
1103  }/*Fin numero de sensores en deposito*/
1104  }/*Fin numero de depositos con sensor*/
1105  }
1106  fgetpos(fich, &filepos);
1107  fclose(fich);
1108  } catch(exception &N) {
1109  std::cout << "ERROR: Lee_Sens_Dep" << std::endl;
1110  std::cout << "Tipo de error: " << N.what() << std::endl;
1111  throw Exception(N.what());
1112  }
1113 }
1114 
1115 //----------------------------------------------------------------------------
1116 //-----------------------------------------------------------------------------
1117 
1118 void TCalculoExtern::Lee_Sens_TG(const char *FileWAM, fpos_t &filepos, TEjeTurbogrupo **Axis) {
1119  try {
1120  FILE *fich = fopen(FileWAM, "r");
1121  fsetpos(fich, &filepos);
1122 
1123  int tipo = 0, ntg = 0, turbogrupo = 0, nsensturbogrupo = 0;
1124  ntg = 0;
1125  fscanf(fich, "%d ", &FNSensTurbogrupo); /*numero de sensores en TG*/
1126  fscanf(fich, "%d ", &ntg); /*numero de turbogrupos con sensor*/
1127  int cont = 0;
1128  FSensorTG = new stSensorTG[FNSensTurbogrupo];
1129  if(FNSensTurbogrupo != 0) {
1130  for(int i = 0; i <= ntg - 1; ++i) {
1131  fscanf(fich, "%d %d ", &turbogrupo, &nsensturbogrupo);
1132  for(int j = 0; j <= nsensturbogrupo - 1; ++j) {
1133  FSensorTG[cont].turbogrupo = turbogrupo;
1134  fscanf(fich, "%d ", &tipo);
1135  switch(tipo) {
1136  case 0:
1137  FSensorTG[cont].tipo = nmRTCTG;
1138  break;
1139  default:
1140  printf("Error en el tipo de sensor\n");
1141  throw Exception("");
1142  } /*fin del switch*/
1143  fscanf(fich, "%lf ", &FSensorTG[cont].ganancia);
1144  fscanf(fich, "%lf ", &FSensorTG[cont].ctetiempo);
1145 
1146  switch(FSensorTG[cont].tipo) {
1147  case nmRTCTG:
1148  FSensorTG[cont].valreal = Axis[FSensorTG[cont].turbogrupo - 1]->getRegimen();
1149  FSensorTG[cont].valact = FSensorTG[cont].valreal;
1150  FSensorTG[cont].valant = FSensorTG[cont].valreal;
1151  FSensorTG[cont].valrealant = FSensorTG[cont].valreal;
1152  break;
1153  }/*fin del switch*/
1154 
1155  cont++;
1156  }/*Fin numero de sensores en turbogrupo*/
1157  }/*Fin numero de turbogrupos con sensores*/
1158  }
1159  fgetpos(fich, &filepos);
1160  fclose(fich);
1161  } catch(exception &N) {
1162  std::cout << "ERROR: Lee_Sens_TG" << std::endl;
1163  std::cout << "Tipo de error: " << N.what() << std::endl;
1164  throw Exception(N.what());
1165  }
1166 }
1167 
1168 //----------------------------------------------------------------------------
1169 //----------------------------------------------------------------------------
1170 
1171 void TCalculoExtern::Lee_Sens_Turbina(const char *FileWAM, fpos_t &filepos, TTurbina **Turbine) {
1172  try {
1173  FILE *fich = fopen(FileWAM, "r");
1174  fsetpos(fich, &filepos);
1175 
1176  int tipo = 0, nturbinas = 0, turbina = 0, nsensturbina = 0;
1177  nturbinas = 0;
1178  fscanf(fich, "%d ", &FNSensTurbina); /* numero de sensores en turbina */
1179  fscanf(fich, "%d ", &nturbinas); /* numero de turbinas con sensor */
1180  int cont = 0;
1181  FSensorTurbina = new stSensorTurbina[FNSensTurbina];
1182  if(FNSensTurbina != 0) {
1183  for(int i = 0; i <= nturbinas - 1; ++i) {
1184  fscanf(fich, "%d %d ", &turbina, &nsensturbina);
1185  for(int j = 0; j <= nsensturbina - 1; ++j) {
1186  FSensorTurbina[cont].turbina = turbina;
1187  fscanf(fich, "%d ", &tipo);
1188  switch(tipo) {
1189  case 0:
1190  FSensorTurbina[cont].tipo = nmRelaci1;
1191  break;
1192  case 1:
1193  FSensorTurbina[cont].tipo = nmRelaci2;
1194  break;
1195  default:
1196  printf("Error en el tipo de sensor\n");
1197  throw Exception("");
1198  } /*fin del switch*/
1199  fscanf(fich, "%lf ", &FSensorTurbina[cont].ganancia);
1200  fscanf(fich, "%lf ", &FSensorTurbina[cont].ctetiempo);
1201 
1202  switch(FSensorTurbina[cont].tipo) {
1203  case nmRelaci1:
1204  FSensorTurbina[cont].valreal = Turbine[FSensorTurbina[cont].turbina - 1]->GetRelacionCinematica(0);
1205  FSensorTurbina[cont].valact = FSensorTurbina[cont].valreal;
1206  FSensorTurbina[cont].valant = FSensorTurbina[cont].valreal;
1207  FSensorTurbina[cont].valrealant = FSensorTurbina[cont].valreal;
1208  break;
1209  case nmRelaci2:
1210  FSensorTurbina[cont].valreal = Turbine[FSensorTurbina[cont].turbina - 1]->GetRelacionCinematica(1);
1211  FSensorTurbina[cont].valact = FSensorTurbina[cont].valreal;
1212  FSensorTurbina[cont].valant = FSensorTurbina[cont].valreal;
1213  FSensorTurbina[cont].valrealant = FSensorTurbina[cont].valreal;
1214  break;
1215  } /*fin del switch*/
1216 
1217  cont++;
1218  }/*Fin numero de sensores en turbina*/
1219  }/*Fin numero de turbinas con sensores*/
1220  }
1221  fgetpos(fich, &filepos);
1222  fclose(fich);
1223  } catch(exception &N) {
1224  std::cout << "ERROR: TCalculoExtern::Lee_Sens_Turbina" << std::endl;
1225  std::cout << "Tipo de error: " << N.what() << std::endl;
1226  throw Exception(N.what());
1227  }
1228 }
1229 
1230 //----------------------------------------------------------------------------
1231 //----------------------------------------------------------------------------
1232 
1233 void TCalculoExtern::Lee_Sens_Cil(const char *FileWAM, fpos_t &filepos, TBloqueMotor **Engine) {
1234  try {
1235  FILE *fich = fopen(FileWAM, "r");
1236  fsetpos(fich, &filepos);
1237 
1238  int tipo = 0, ncil = 0, cilindro = 0, nsenscilindro = 0;
1239  ncil = 0;
1240  fscanf(fich, "%d ", &FNSensCilindros); /*numero de sensores en cilindros*/
1241  fscanf(fich, "%d ", &ncil); /*numero de cilindros con sensores*/
1242  int cont = 0;
1243  FSensorCil = new stSensorCil[FNSensCilindros];
1244  if(FNSensCilindros != 0) {
1245  for(int i = 0; i <= ncil - 1; ++i) {
1246  fscanf(fich, "%d %d ", &cilindro, &nsenscilindro);
1247  for(int j = 0; j <= nsenscilindro - 1; ++j) {
1248  FSensorCil[cont].cilindro = cilindro;
1249  fscanf(fich, "%d ", &tipo);
1250  switch(tipo) {
1251  case 0:
1252  FSensorCil[cont].tipo = nmPrCil;
1253  break;
1254  case 1:
1255  FSensorCil[cont].tipo = nmTempCil;
1256  break;
1257  case 2:
1258  FSensorCil[cont].tipo = nmMfCil;
1259  break;
1260  case 3:
1261  FSensorCil[cont].tipo = nmAFRCil;
1262  break;
1263  default:
1264  printf("Error en el tipo de sensor\n");
1265  throw Exception("");
1266  } /*fin del switch*/
1267  fscanf(fich, "%lf ", &FSensorCil[cont].ganancia);
1268  fscanf(fich, "%lf ", &FSensorCil[cont].ctetiempo);
1269 
1270  switch(FSensorCil[cont].tipo) {
1271  case nmTempCil:
1272  FSensorCil[cont].valreal = Engine[0]->GetCilindro(FSensorCil[cont].cilindro - 1)->getTemperature();
1273  FSensorCil[cont].valact = FSensorCil[cont].valreal;
1274  FSensorCil[cont].valant = FSensorCil[cont].valreal;
1275  FSensorCil[cont].valrealant = FSensorCil[cont].valreal;
1276  break;
1277  case nmPrCil:
1278  FSensorCil[cont].valreal = Engine[0]->GetCilindro(FSensorCil[cont].cilindro - 1)->getPressure();
1279  FSensorCil[cont].valact = FSensorCil[cont].valreal;
1280  FSensorCil[cont].valant = FSensorCil[cont].valreal;
1281  FSensorCil[cont].valrealant = FSensorCil[cont].valreal;
1282  break;
1283  case nmMfCil:
1284  FSensorCil[cont].valreal = Engine[0]->GetCilindro(FSensorCil[cont].cilindro - 1)->getMasaFuel();
1285  FSensorCil[cont].valact = FSensorCil[cont].valreal;
1286  FSensorCil[cont].valant = FSensorCil[cont].valreal;
1287  FSensorCil[cont].valrealant = FSensorCil[cont].valreal;
1288  break;
1289  case nmAFRCil:
1290  FSensorCil[cont].valreal = 15;
1291  FSensorCil[cont].valact = FSensorCil[cont].valreal;
1292  FSensorCil[cont].valant = FSensorCil[cont].valreal;
1293  FSensorCil[cont].valrealant = FSensorCil[cont].valreal;
1294  break;
1295 
1296  }/*fin del switch*/
1297 
1298  cont++;
1299  }/*Fin numero de sensores en cilindro*/
1300  }/*Fin numero de cilindros con sensor*/
1301  }
1302  fgetpos(fich, &filepos);
1303  fclose(fich);
1304  } catch(exception &N) {
1305  std::cout << "ERROR: Lee_Sens_Cil" << std::endl;
1306  std::cout << "Tipo de error: " << N.what() << std::endl;
1307  throw Exception(N.what());
1308  }
1309 }
1310 
1311 //-----------------------------------------------------------------------------
1312 //-----------------------------------------------------------------------------
1313 
1314 void TCalculoExtern::Lee_Sens_Vent(const char *FileWAM, fpos_t &filepos, TVenturi **Venturi) {
1315  try {
1316  FILE *fich = fopen(FileWAM, "r");
1317  fsetpos(fich, &filepos);
1318 
1319  int signo = 0;
1320  double prent = 0., prgar = 0., velent = 0., vellat = 0., gasent = 0., gaslat = 0.;
1321  int tipo = 0, nventuris = 0, venturi = 0, nsensventuri = 0, v = 0;
1322  nventuris = 0;
1323  fscanf(fich, "%d ", &FNSensVenturis); /*numero de sensores en venturis*/
1324  fscanf(fich, "%d ", &nventuris);
1325  int cont = 0;
1326  FSensorVent = new stSensorVent[FNSensVenturis];
1327  if(FNSensVenturis != 0) {
1328  for(int i = 0; i <= nventuris - 1; ++i) {
1329  fscanf(fich, "%d %d ", &venturi, &nsensventuri);
1330  for(int j = 0; j <= nsensventuri - 1; ++j) {
1331  FSensorVent[cont].venturi = venturi;
1332  fscanf(fich, "%d ", &tipo);
1333  switch(tipo) {
1334  case 0:
1335  FSensorVent[cont].tipo = nmPrEntVent;
1336  break;
1337  case 1:
1338  FSensorVent[cont].tipo = nmPrGarVent;
1339  break;
1340  case 2:
1341  FSensorVent[cont].tipo = nmVelEntVent;
1342  break;
1343  case 3:
1344  FSensorVent[cont].tipo = nmVelLatVent;
1345  break;
1346  case 4:
1347  FSensorVent[cont].tipo = nmGastoEntVent;
1348  break;
1349  case 5:
1350  FSensorVent[cont].tipo = nmGastoLatVent;
1351  break;
1352  default:
1353  printf("Error en el tipo de sensor\n");
1354  throw Exception("");
1355  } /*fin del switch*/
1356  fscanf(fich, "%lf ", &FSensorVent[cont].ganancia);
1357  fscanf(fich, "%lf ", &FSensorVent[cont].ctetiempo);
1358 
1359  v = FSensorVent[cont].venturi - 1;
1360  switch(FSensorVent[FNSensVenturis].tipo) {
1361  case nmPrEntVent:
1362  prent = Venturi[v]->getPressure();
1363  FSensorVent[cont].valreal = prent;
1364  FSensorVent[cont].valact = FSensorVent[cont].valreal;
1365  FSensorVent[cont].valant = FSensorVent[cont].valreal;
1366  FSensorVent[cont].valrealant = FSensorVent[cont].valreal;
1367  break;
1368  case nmPrGarVent:
1369  prent = Venturi[v]->getPressure();
1370  prgar = prent / pow(1 + Venturi[v]->getgamma3() * pow(dynamic_cast<TCCDeposito *>
1371  (Venturi[v]->getCCLateral())->getValvula()->getCRecuperacion(), 2.),
1372  Venturi[v]->getGamma() / Venturi[v]->getgamma1());
1373  FSensorVent[cont].valreal = prgar;
1374  FSensorVent[cont].valact = FSensorVent[cont].valreal;
1375  FSensorVent[cont].valant = FSensorVent[cont].valreal;
1376  FSensorVent[cont].valrealant = FSensorVent[cont].valreal;
1377  break;
1378  case nmVelEntVent:
1379  if(dynamic_cast<TCCDeposito *>(Venturi[v]->getCCEntrada())->getSentidoFlujo() == nmEntrante) {
1380  signo = 1; /* Si el flujo es entrante signo de la velocidad positivo */
1381  } else if(dynamic_cast<TCCDeposito *>(Venturi[v]->getCCEntrada())->getSentidoFlujo() == nmSaliente) {
1382  signo = -1; /* Si el flujo es saliente signo de la velocidad negativo */
1383  }
1384  velent = dynamic_cast<TCCDeposito *>(Venturi[v]->getCCEntrada())->getVelocity() * signo * __cons::ARef;
1385  FSensorVent[cont].valreal = velent;
1386  FSensorVent[cont].valact = FSensorVent[cont].valreal;
1387  FSensorVent[cont].valant = FSensorVent[cont].valreal;
1388  FSensorVent[cont].valrealant = FSensorVent[cont].valreal;
1389  break;
1390  case nmVelLatVent:
1391  vellat = dynamic_cast<TCCDeposito *>(Venturi[v]->getCCLateral())->getVelocity() * __cons::ARef;
1392  FSensorVent[cont].valreal = vellat;
1393  FSensorVent[cont].valact = FSensorVent[cont].valreal;
1394  FSensorVent[cont].valant = FSensorVent[cont].valreal;
1395  FSensorVent[cont].valrealant = FSensorVent[cont].valreal;
1396  break;
1397  case nmGastoEntVent:
1398  gasent = -dynamic_cast<TCCDeposito *>
1399  (Venturi[v]->getCCEntrada())->getMassflow(); /*Massflow entrante positivo.Saliente negativo. Pedro */
1400  /* gasent lleva el "-" delante porque se usa el convenio de signos de los depositos,que es el contrario al de las BC, de la que se obtiene el massflow */
1401  FSensorVent[cont].valreal = gasent;
1402  FSensorVent[cont].valact = FSensorVent[cont].valreal;
1403  FSensorVent[cont].valant = FSensorVent[cont].valreal;
1404  FSensorVent[cont].valrealant = FSensorVent[cont].valreal;
1405  break;
1406  case nmGastoLatVent:
1407  gaslat = dynamic_cast<TCCDeposito *>(Venturi[v]->getCCLateral())->getMassflow();
1408  FSensorVent[cont].valreal = gaslat;
1409  FSensorVent[cont].valact = FSensorVent[cont].valreal;
1410  FSensorVent[cont].valant = FSensorVent[cont].valreal;
1411  FSensorVent[cont].valrealant = FSensorVent[cont].valreal;
1412  break;
1413 
1414  }/*fin del switch*/
1415 
1416  cont++;
1417  }/*Fin numero de sensores en venturi*/
1418  }/*Fin numero de venturis con sensor*/
1419 
1420  }
1421  fgetpos(fich, &filepos);
1422  fclose(fich);
1423  } catch(exception &N) {
1424  std::cout << "ERROR: Lee_Sens_Vent" << std::endl;
1425  std::cout << "Tipo de error: " << N.what() << std::endl;
1426  throw Exception(N.what());
1427  }
1428 }
1429 
1430 //-----------------------------------------------------------------------------
1431 //-----------------------------------------------------------------------------
1432 
1433 void TCalculoExtern::Lee_Sens_Motor(const char *FileWAM, fpos_t &filepos, double CrankAngle, double ene,
1434  double AcumulatedTime) {
1435  try {
1436  FILE *fich = fopen(FileWAM, "r");
1437  fsetpos(fich, &filepos);
1438 
1439  int tipo = 0;
1440  fscanf(fich, "%d ", &FNSensMotor); /*numero de sensores en motor*/
1441  if(ene < 0. && FNSensMotor != 0) {
1442  std::cout << "ERROR: No puede haber sensores en el motor,pues no hay motor.Comprobad la lectura " << std::endl;
1443  throw Exception("");
1444  }
1445  FSensorMotor = new stSensorMotor[FNSensMotor];
1446  if(FNSensMotor != 0) {
1447  for(int i = 0; i <= FNSensMotor - 1; ++i) {
1448  fscanf(fich, "%d ", &tipo);
1449  FSensorMotor[i].motor = 1;
1450  switch(tipo) {
1451  case 0:
1452  FSensorMotor[i].tipo = nmAngulo;
1453  break;
1454  case 1:
1455  FSensorMotor[i].tipo = nmReg;
1456  break;
1457  case 2:
1458  FSensorMotor[i].tipo = nmTiempo;
1459  break;
1460  default:
1461  printf("Error en el tipo de sensor\n");
1462  throw Exception("");
1463  } /*fin del switch*/
1464 
1465  fscanf(fich, "%lf ", &FSensorMotor[i].ganancia);
1466  fscanf(fich, "%lf ", &FSensorMotor[i].ctetiempo);
1467 
1468  switch(FSensorMotor[i].tipo) {
1469  case nmAngulo:
1470  FSensorMotor[i].valreal = CrankAngle;
1471  FSensorMotor[i].valact = FSensorMotor[i].valreal;
1472  FSensorMotor[i].valant = FSensorMotor[i].valreal;
1473  FSensorMotor[i].valrealant = FSensorMotor[i].valreal;
1474  break;
1475  case nmReg:
1476  FSensorMotor[i].valreal = ene;
1477  FSensorMotor[i].valact = FSensorMotor[i].valreal;
1478  FSensorMotor[i].valant = FSensorMotor[i].valreal;
1479  FSensorMotor[i].valrealant = FSensorMotor[i].valreal;
1480  break;
1481  case nmTiempo:
1482  FSensorMotor[i].valreal = AcumulatedTime;
1483  FSensorMotor[i].valact = FSensorMotor[i].valreal;
1484  FSensorMotor[i].valant = FSensorMotor[i].valreal;
1485  FSensorMotor[i].valrealant = FSensorMotor[i].valreal;
1486  break;
1487 
1488  }/*fin del switch*/
1489  }
1490  }
1491  fgetpos(fich, &filepos);
1492  fclose(fich);
1493  } catch(exception &N) {
1494  std::cout << "ERROR: Lee_Sens_Motor" << std::endl;
1495  std::cout << "Tipo de error: " << N.what() << std::endl;
1496  throw Exception(N.what());
1497  }
1498 }
1499 
1500 //------------------------------------------------------------------------------
1501 //------------------------------------------------------------------------------
1502 
1503 void TCalculoExtern::Lee_Sens_UED(const char *FileWAM, fpos_t &filepos, TCondicionContorno **BC) {
1504  try {
1505  FILE *fich = fopen(FileWAM, "r");
1506  fsetpos(fich, &filepos);
1507  int nUED = 0, CCued = 0, nsensUED = 0;
1508  int tipo, cont = 0;
1509  fscanf(fich, "%d ", &FNSensUED); /*numero de sensores en UED*/
1510  fscanf(fich, "%d ", &nUED); /*numero de uniones entre tubos con sensores*/
1511  FSensorUED = new stSensorUED[FNSensUED];
1512  if(FNSensUED != 0) {
1513  for(int i = 0; i <= nUED - 1; ++i) {
1514  fscanf(fich, "%d %d ", &CCued, &nsensUED);
1515  for(int j = 0; j <= nsensUED - 1; ++j) {
1516  FSensorUED[cont].CCUED = CCued;
1517  fscanf(fich, "%d ", &tipo);
1518  switch(tipo) {
1519  case 0:
1520  FSensorUED[cont].tipo = nmGasto;
1521  break;
1522  default:
1523  printf("Error en el tipo de sensor\n");
1524  throw Exception("");
1525  } /*fin del switch*/
1526 
1527  fscanf(fich, "%lf ", &FSensorUED[cont].ganancia);
1528  fscanf(fich, "%lf ", &FSensorUED[cont].ctetiempo);
1529 
1530  switch(FSensorUED[cont].tipo) {
1531  case nmGasto:
1532  FSensorUED[cont].valreal = dynamic_cast<TCCUnionEntreDepositos*>(BC[FSensorUED[cont].CCUED - 1])->getGastoImpreso();
1533  FSensorUED[cont].valact = FSensorUED[cont].valreal;
1534  FSensorUED[cont].valant = FSensorUED[cont].valreal;
1535  FSensorUED[cont].valrealant = FSensorUED[cont].valreal;
1536  break;
1537  }/*fin del switch*/
1538  cont++;
1539  }/*Fin numero de sensores en UED*/
1540  }/*Fin numero de UED con sensor*/
1541  }
1542  fgetpos(fich, &filepos);
1543  fclose(fich);
1544  } catch(exception &N) {
1545  std::cout << "ERROR: Lee_Sens_UED" << std::endl;
1546  std::cout << "Tipo de error: " << N.what() << std::endl;
1547  throw Exception(N.what());
1548  }
1549 }
1550 
1551 //------------------------------------------------------------------------------
1552 //------------------------------------------------------------------------------
1553 
1554 void TCalculoExtern::Lectura_Datos_Adicionales(const char *FileWAM, fpos_t &filepos) {
1555  try {
1556 
1557  } catch(exception &N) {
1558  std::cout << "ERROR: Lectura_Datos_Adicionales" << std::endl;
1559  std::cout << "Tipo de error: " << N.what() << std::endl;
1560  throw Exception(N.what());
1561  }
1562 }
1563 
1564 //------------------------------------------------------------------------------
1565 //------------------------------------------------------------------------------
1566 
1567 void TCalculoExtern::IniciaEntradaDLL() {
1568  try {
1569  FNInputsdll = FNSensTubos + FNSensDepositos + FNSensTurbogrupo + FNSensTurbina + FNSensMotor + FNSensVenturis +
1570  FNSensCilindros + FNSensUED;
1571  FInputs = new double[FNInputsdll];
1572  } catch(exception &N) {
1573  std::cout << "ERROR: IniciaEntradaDLL" << std::endl;
1574  std::cout << "Tipo de error: " << N.what() << std::endl;
1575  throw Exception(N.what());
1576  }
1577 }
1578 //------------------------------------------------------------------------------
1579 //------------------------------------------------------------------------------
1580 
1581 void TCalculoExtern::Calculo_Sensores_Tubos(TTubo **Pipe, double deltaT) {
1582  try {
1583  double dist = 0., T = 0., temp = 0., v1 = 0., v2 = 0., den = 0., d = 0., p = 0., gto1 = 0., gto2 = 0., gamma, Rmezcla;
1584  int n1 = 0, j = 0, n2 = 0;
1585  for(int i = 0; i <= FNSensTubos - 1; i++) {
1586  dist = FSensorTubo[i].distancia / FSensorTubo[i].deltax;
1587  n1 = (int) floor(dist);
1588  j = FSensorTubo[i].tubo - 1;
1589  if(n1 == FSensorTubo[i].nodos - 1) {
1590  switch(FSensorTubo[i].tipo) {
1591  case nmTempTubo:
1592  temp = Pipe[j]->GetAsonido(n1) * __cons::ARef;
1593  FSensorTubo[i].valreal = __units::KTodegC(temp * temp / Pipe[j]->GetGamma(n1) / Pipe[j]->GetRMezcla(n1));
1594  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1595  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1596  deltaT);
1597  FSensorTubo[i].valant = FSensorTubo[i].valact;
1598  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1599  break;
1600  case nmPrTubo:
1601  FSensorTubo[i].valreal = Pipe[j]->GetPresion(n1);
1602  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1603  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1604  deltaT);
1605  FSensorTubo[i].valant = FSensorTubo[i].valact;
1606  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1607  break;
1608  case nmVelTubo:
1609  FSensorTubo[i].valreal = Pipe[j]->GetVelocidad(n1) * __cons::ARef;
1610  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1611  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1612  deltaT);
1613  FSensorTubo[i].valant = FSensorTubo[i].valact;
1614  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1615  break;
1616  case nmGastoTubo:
1617  temp = Pipe[j]->GetAsonido(n1) * __cons::ARef;
1618  T = __units::KTodegC(temp * temp / Pipe[j]->GetGamma(n1) / Pipe[j]->GetRMezcla(n1));
1619  den = __units::BarToPa(Pipe[j]->GetPresion(n1)) / Pipe[j]->GetRMezcla(n1) / __units::degCToK(T);
1620  v1 = Pipe[j]->GetVelocidad(n1) * __cons::ARef;
1621  FSensorTubo[i].valreal = (pow2(Pipe[j]->GetDiametro(n1)) * __cons::Pi) * v1 * den;
1622  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1623  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1624  deltaT);
1625  FSensorTubo[i].valant = FSensorTubo[i].valact;
1626  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1627  break;
1628  case nmN2Tubo:
1629  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboN2);
1630  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1631  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1632  deltaT);
1633  FSensorTubo[i].valant = FSensorTubo[i].valact;
1634  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1635  break;
1636  case nmO2Tubo:
1637  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboO2);
1638  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1639  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1640  deltaT);
1641  FSensorTubo[i].valant = FSensorTubo[i].valact;
1642  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1643  break;
1644  case nmCO2Tubo:
1645  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboCO2);
1646  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1647  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1648  deltaT);
1649  FSensorTubo[i].valant = FSensorTubo[i].valact;
1650  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1651  break;
1652  case nmH2OTubo:
1653  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboH2O);
1654  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1655  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1656  deltaT);
1657  FSensorTubo[i].valant = FSensorTubo[i].valact;
1658  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1659  break;
1660  case nmHCTubo:
1661  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboHC);
1662  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1663  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1664  deltaT);
1665  FSensorTubo[i].valant = FSensorTubo[i].valact;
1666  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1667  break;
1668  case nmSootTubo:
1669  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboSoot);
1670  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1671  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1672  deltaT);
1673  FSensorTubo[i].valant = FSensorTubo[i].valact;
1674  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1675  break;
1676  case nmNOxTubo:
1677  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboNOx);
1678  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1679  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1680  deltaT);
1681  FSensorTubo[i].valant = FSensorTubo[i].valact;
1682  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1683  break;
1684  case nmCOTubo:
1685  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboCO);
1686  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1687  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1688  deltaT);
1689  FSensorTubo[i].valant = FSensorTubo[i].valact;
1690  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1691  break;
1692  case nmAireFrTubo:
1693  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboAireFresco);
1694  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1695  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1696  deltaT);
1697  FSensorTubo[i].valant = FSensorTubo[i].valact;
1698  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1699  break;
1700  case nmGasQuemadoTubo:
1701  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboGasQuemado);
1702  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1703  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1704  deltaT);
1705  FSensorTubo[i].valant = FSensorTubo[i].valact;
1706  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1707  break;
1708  case nmEGRTubo:
1709  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboEGR);
1710  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1711  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1712  deltaT);
1713  FSensorTubo[i].valant = FSensorTubo[i].valact;
1714  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1715  break;
1716  case nmCombustibleTubo:
1717  FSensorTubo[i].valreal = Pipe[j]->GetFraccionMasica(n1, FIndiceTuboComb);
1718  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1719  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1720  deltaT);
1721  FSensorTubo[i].valant = FSensorTubo[i].valact;
1722  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1723  break;
1724  }/*fin del switch*/
1725  } else {
1726  n2 = n1 + 1;
1727  d = dist - n1;
1728  switch(FSensorTubo[i].tipo) {
1729  case nmTempTubo:
1730  temp = xit_(Pipe[j]->GetAsonido(n1), Pipe[j]->GetAsonido(n2), 1.0, d) * __cons::ARef;
1731  gamma = xit_(Pipe[j]->GetGamma(n1), Pipe[j]->GetGamma(n2), 1.0, d);
1732  Rmezcla = xit_(Pipe[j]->GetRMezcla(n1), Pipe[j]->GetRMezcla(n2), 1.0, d);
1733  FSensorTubo[i].valreal = __units::KTodegC(temp * temp / gamma / Rmezcla);
1734  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1735  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1736  deltaT);
1737  FSensorTubo[i].valant = FSensorTubo[i].valact;
1738  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1739  break;
1740  case nmPrTubo:
1741  FSensorTubo[i].valreal = xit_(Pipe[j]->GetPresion(n1), Pipe[j]->GetPresion(n2), 1.0, d);
1742  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1743  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1744  deltaT);
1745  FSensorTubo[i].valant = FSensorTubo[i].valact;
1746  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1747  break;
1748  case nmVelTubo:
1749  FSensorTubo[i].valreal = xit_(Pipe[j]->GetVelocidad(n1), Pipe[j]->GetVelocidad(n2), 1.0, d) * __cons::ARef;
1750  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1751  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1752  deltaT);
1753  FSensorTubo[i].valant = FSensorTubo[i].valact;
1754  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1755  break;
1756  case nmGastoTubo:
1757  temp = xit_(Pipe[j]->GetAsonido(n1), Pipe[j]->GetAsonido(n2), 1.0, d) * __cons::ARef;
1758  gamma = xit_(Pipe[j]->GetGamma(n1), Pipe[j]->GetGamma(n2), 1.0, d);
1759  Rmezcla = xit_(Pipe[j]->GetRMezcla(n1), Pipe[j]->GetRMezcla(n2), 1.0, d);
1760  T = __units::KTodegC(temp * temp / gamma / Rmezcla);
1761  p = xit_(Pipe[j]->GetPresion(n1), Pipe[j]->GetPresion(n2), 1.0, d);
1762  den = __units::BarToPa(p) / Rmezcla / __units::degCToK(T);
1763  v1 = Pipe[j]->GetVelocidad(n1) * __cons::ARef;
1764  v2 = Pipe[j]->GetVelocidad(n2) * __cons::ARef;
1765  gto1 = __geom::Circle_area(Pipe[j]->GetDiametro(n1));
1766  gto2 = __geom::Circle_area(Pipe[j]->GetDiametro(n2));
1767  gto1 *= v1;
1768  gto2 *= v2;
1769  FSensorTubo[i].valreal = xit_(gto1, gto2, 1.0, d) * den;
1770  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1771  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1772  deltaT);
1773  FSensorTubo[i].valant = FSensorTubo[i].valact;
1774  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1775  break;
1776  case nmN2Tubo:
1777  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboN2), Pipe[j]->GetFraccionMasica(n1,
1778  FIndiceTuboN2), 1.0, d);
1779  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1780  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1781  deltaT);
1782  FSensorTubo[i].valant = FSensorTubo[i].valact;
1783  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1784  break;
1785  case nmO2Tubo:
1786  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboO2), Pipe[j]->GetFraccionMasica(n1,
1787  FIndiceTuboO2), 1.0, d);
1788  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1789  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1790  deltaT);
1791  FSensorTubo[i].valant = FSensorTubo[i].valact;
1792  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1793  break;
1794  case nmCO2Tubo:
1795  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboCO2), Pipe[j]->GetFraccionMasica(n1,
1796  FIndiceTuboCO2), 1.0, d);
1797  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1798  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1799  deltaT);
1800  FSensorTubo[i].valant = FSensorTubo[i].valact;
1801  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1802  break;
1803  case nmH2OTubo:
1804  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboH2O), Pipe[j]->GetFraccionMasica(n1,
1805  FIndiceTuboH2O), 1.0, d);
1806  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1807  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1808  deltaT);
1809  FSensorTubo[i].valant = FSensorTubo[i].valact;
1810  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1811  break;
1812  case nmHCTubo:
1813  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboHC), Pipe[j]->GetFraccionMasica(n1,
1814  FIndiceTuboHC), 1.0, d);
1815  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1816  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1817  deltaT);
1818  FSensorTubo[i].valant = FSensorTubo[i].valact;
1819  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1820  break;
1821  case nmSootTubo:
1822  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboSoot), Pipe[j]->GetFraccionMasica(n1,
1823  FIndiceTuboSoot), 1.0, d);
1824  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1825  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1826  deltaT);
1827  FSensorTubo[i].valant = FSensorTubo[i].valact;
1828  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1829  break;
1830  case nmNOxTubo:
1831  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboNOx), Pipe[j]->GetFraccionMasica(n1,
1832  FIndiceTuboNOx), 1.0, d);
1833  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1834  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1835  deltaT);
1836  FSensorTubo[i].valant = FSensorTubo[i].valact;
1837  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1838  break;
1839  case nmCOTubo:
1840  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboCO), Pipe[j]->GetFraccionMasica(n1,
1841  FIndiceTuboCO), 1.0, d);
1842  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1843  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1844  deltaT);
1845  FSensorTubo[i].valant = FSensorTubo[i].valact;
1846  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1847  break;
1848  case nmAireFrTubo:
1849  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboAireFresco), Pipe[j]->GetFraccionMasica(n1,
1850  FIndiceTuboAireFresco), 1.0, d);
1851  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1852  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1853  deltaT);
1854  FSensorTubo[i].valant = FSensorTubo[i].valact;
1855  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1856  break;
1857  case nmGasQuemadoTubo:
1858  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboGasQuemado), Pipe[j]->GetFraccionMasica(n1,
1859  FIndiceTuboGasQuemado), 1.0, d);
1860  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1861  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1862  deltaT);
1863  FSensorTubo[i].valant = FSensorTubo[i].valact;
1864  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1865  break;
1866  case nmEGRTubo:
1867  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboEGR), Pipe[j]->GetFraccionMasica(n1,
1868  FIndiceTuboEGR), 1.0, d);
1869  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1870  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1871  deltaT);
1872  FSensorTubo[i].valant = FSensorTubo[i].valact;
1873  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1874  break;
1875  case nmCombustibleTubo:
1876  FSensorTubo[i].valreal = xit_(Pipe[j]->GetFraccionMasica(n1, FIndiceTuboComb), Pipe[j]->GetFraccionMasica(n1,
1877  FIndiceTuboComb), 1.0, d);
1878  FSensorTubo[i].valact = ((2 * FSensorTubo[i].ctetiempo - deltaT) * FSensorTubo[i].valant + deltaT *
1879  FSensorTubo[i].ganancia * (FSensorTubo[i].valreal + FSensorTubo[i].valrealant)) / (2 * FSensorTubo[i].ctetiempo +
1880  deltaT);
1881  FSensorTubo[i].valant = FSensorTubo[i].valact;
1882  FSensorTubo[i].valrealant = FSensorTubo[i].valreal;
1883  break;
1884  }/*fin del switch*/
1885  }/*fin del else*/
1886 
1887  }/*fin del for*/
1888  } catch(exception &N) {
1889  std::cout << "ERROR: Calculo_Sensores_Tubos" << std::endl;
1890  std::cout << "Tipo de error: " << N.what() << std::endl;
1891  throw Exception(N.what());
1892  }
1893 }
1894 
1895 //-----------------------------------------------------------------------------
1896 //-----------------------------------------------------------------------------
1897 
1898 void TCalculoExtern::Calculo_Sensores_Deposito(TDeposito **Plenum, double deltaT) {
1899  try {
1900  for(int i = 0; i <= FNSensDepositos - 1; i++) {
1901  switch(FSensorDep[i].tipo) {
1902  case nmPrDep:
1903  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->getPressure();
1904  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1905  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1906  FSensorDep[i].valant = FSensorDep[i].valact;
1907  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1908  break;
1909  case nmTempDep:
1910  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->getTemperature();
1911  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1912  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1913  FSensorDep[i].valant = FSensorDep[i].valact;
1914  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1915  break;
1916  case nmN2Dep:
1917  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboN2);
1918  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1919  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1920  FSensorDep[i].valant = FSensorDep[i].valact;
1921  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1922  break;
1923  case nmO2Dep:
1924  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboO2);
1925  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1926  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1927  FSensorDep[i].valant = FSensorDep[i].valact;
1928  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1929  break;
1930  case nmCO2Dep:
1931  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboCO2);
1932  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1933  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1934  FSensorDep[i].valant = FSensorDep[i].valact;
1935  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1936  break;
1937  case nmH2ODep:
1938  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboH2O);
1939  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1940  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1941  FSensorDep[i].valant = FSensorDep[i].valact;
1942  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1943  break;
1944  case nmHCDep:
1945  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboHC);
1946  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1947  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1948  FSensorDep[i].valant = FSensorDep[i].valact;
1949  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1950  break;
1951  case nmSootDep:
1952  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboSoot);
1953  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1954  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1955  FSensorDep[i].valant = FSensorDep[i].valact;
1956  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1957  break;
1958  case nmNOxDep:
1959  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboNOx);
1960  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1961  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1962  FSensorDep[i].valant = FSensorDep[i].valact;
1963  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1964  break;
1965  case nmCODep:
1966  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboCO);
1967  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1968  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1969  FSensorDep[i].valant = FSensorDep[i].valact;
1970  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1971  break;
1972  case nmAireFrDep:
1973  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboAireFresco);
1974  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1975  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1976  FSensorDep[i].valant = FSensorDep[i].valact;
1977  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1978  break;
1979  case nmGasQuemadoDep:
1980  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboGasQuemado);
1981  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1982  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1983  FSensorDep[i].valant = FSensorDep[i].valact;
1984  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1985  break;
1986  case nmEGRDep:
1987  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboEGR);
1988  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1989  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1990  FSensorDep[i].valant = FSensorDep[i].valact;
1991  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1992  break;
1993  case nmCombustibleDep:
1994  FSensorDep[i].valreal = Plenum[FSensorDep[i].deposito - 1]->GetFraccionMasicaEspecie(FIndiceTuboComb);
1995  FSensorDep[i].valact = ((2 * FSensorDep[i].ctetiempo - deltaT) * FSensorDep[i].valant + deltaT * FSensorDep[i].ganancia
1996  * (FSensorDep[i].valreal + FSensorDep[i].valrealant)) / (2 * FSensorDep[i].ctetiempo + deltaT);
1997  FSensorDep[i].valant = FSensorDep[i].valact;
1998  FSensorDep[i].valrealant = FSensorDep[i].valreal;
1999  break;
2000  }/*fin del switch*/
2001  }/*fin del for*/
2002  } catch(exception &N) {
2003  std::cout << "ERROR: Calculo_Sensores_Deposito" << std::endl;
2004  std::cout << "Tipo de error: " << N.what() << std::endl;
2005  throw Exception(N.what());
2006  }
2007 }
2008 
2009 //-----------------------------------------------------------------------------
2010 //-----------------------------------------------------------------------------
2011 
2012 void TCalculoExtern::Calculo_Sensores_TG(double deltaT, TEjeTurbogrupo **Axis) {
2013  try {
2014  for(int i = 0; i <= FNSensTurbogrupo - 1; i++) {
2015  switch(FSensorTG[i].tipo) {
2016  case nmRTCTG:
2017  FSensorTG[i].valreal = Axis[FSensorTG[i].turbogrupo - 1]->getRegimen();
2018  FSensorTG[i].valact = ((2 * FSensorTG[i].ctetiempo - deltaT) * FSensorTG[i].valant + deltaT * FSensorTG[i].ganancia *
2019  (FSensorTG[i].valreal + FSensorTG[i].valrealant)) / (2 * FSensorTG[i].ctetiempo + deltaT);
2020  FSensorTG[i].valant = FSensorTG[i].valact;
2021  FSensorTG[i].valrealant = FSensorTG[i].valreal;
2022  break;
2023  }/*fin del switch*/
2024  }/*fin del for*/
2025  } catch(exception &N) {
2026  std::cout << "ERROR: Calculo_Sensores_TG" << std::endl;
2027  std::cout << "Tipo de error: " << N.what() << std::endl;
2028  throw Exception(N.what());
2029  }
2030 }
2031 
2032 //-----------------------------------------------------------------------------
2033 //-----------------------------------------------------------------------------
2034 
2035 void TCalculoExtern::Calculo_Sensores_Turbina(double deltaT, TTurbina **Turbine) {
2036  try {
2037  for(int i = 0; i <= FNSensTurbina - 1; i++) {
2038  switch(FSensorTurbina[i].tipo) {
2039  case nmRelaci1:
2040  FSensorTurbina[i].valreal = Turbine[FSensorTurbina[i].turbina - 1]->GetRelacionCinematica(0);
2041  FSensorTurbina[i].valact = ((2 * FSensorTurbina[i].ctetiempo - deltaT) * FSensorTurbina[i].valant + deltaT *
2042  FSensorTurbina[i].ganancia * (FSensorTurbina[i].valreal + FSensorTurbina[i].valrealant)) /
2043  (2 * FSensorTurbina[i].ctetiempo + deltaT);
2044  FSensorTurbina[i].valant = FSensorTurbina[i].valact;
2045  FSensorTurbina[i].valrealant = FSensorTurbina[i].valreal;
2046  break;
2047  case nmRelaci2:
2048  FSensorTurbina[i].valreal = Turbine[FSensorTurbina[i].turbina - 1]->GetRelacionCinematica(1);
2049  FSensorTurbina[i].valact = ((2 * FSensorTurbina[i].ctetiempo - deltaT) * FSensorTurbina[i].valant + deltaT *
2050  FSensorTurbina[i].ganancia * (FSensorTurbina[i].valreal + FSensorTurbina[i].valrealant)) /
2051  (2 * FSensorTurbina[i].ctetiempo + deltaT);
2052  FSensorTurbina[i].valant = FSensorTurbina[i].valact;
2053  FSensorTurbina[i].valrealant = FSensorTurbina[i].valreal;
2054  break;
2055  }/*fin del switch*/
2056  }/*fin del for*/
2057  } catch(exception &N) {
2058  std::cout << "ERROR: TCalculoExtern::Calculo_Sensores_Turbina " << std::endl;
2059  std::cout << "Tipo de error: " << N.what() << std::endl;
2060  throw Exception(N.what());
2061  }
2062 }
2063 
2064 //-----------------------------------------------------------------------------
2065 //-----------------------------------------------------------------------------
2066 
2067 void TCalculoExtern::Calculo_Sensores_Cilindro(double deltaT, TBloqueMotor **Engine) {
2068  try {
2069  for(int i = 0; i <= FNSensCilindros - 1; i++) {
2070  switch(FSensorCil[i].tipo) {
2071  case nmTempCil:
2072  FSensorCil[i].valreal = Engine[0]->GetCilindro(FSensorCil[i].cilindro - 1)->getTemperature();
2073  FSensorCil[i].valact = ((2 * FSensorCil[i].ctetiempo - deltaT) * FSensorCil[i].valant + deltaT * FSensorCil[i].ganancia
2074  * (FSensorCil[i].valreal + FSensorCil[i].valrealant)) / (2 * FSensorCil[i].ctetiempo + deltaT);
2075  FSensorCil[i].valant = FSensorCil[i].valact;
2076  FSensorCil[i].valrealant = FSensorCil[i].valreal;
2077  break;
2078  case nmPrCil:
2079  FSensorCil[i].valreal = Engine[0]->GetCilindro(FSensorCil[i].cilindro - 1)->getPressure();
2080  FSensorCil[i].valact = ((2 * FSensorCil[i].ctetiempo - deltaT) * FSensorCil[i].valant + deltaT * FSensorCil[i].ganancia
2081  * (FSensorCil[i].valreal + FSensorCil[i].valrealant)) / (2 * FSensorCil[i].ctetiempo + deltaT);
2082  FSensorCil[i].valant = FSensorCil[i].valact;
2083  FSensorCil[i].valrealant = FSensorCil[i].valreal;
2084  break;
2085  case nmMfCil:
2086  FSensorCil[i].valreal = Engine[0]->GetCilindro(FSensorCil[i].cilindro - 1)->getMasaFuel();
2087  FSensorCil[i].valact = ((2 * FSensorCil[i].ctetiempo - deltaT) * FSensorCil[i].valant + deltaT * FSensorCil[i].ganancia
2088  * (FSensorCil[i].valreal + FSensorCil[i].valrealant)) / (2 * FSensorCil[i].ctetiempo + deltaT);
2089  FSensorCil[i].valant = FSensorCil[i].valact;
2090  FSensorCil[i].valrealant = FSensorCil[i].valreal;
2091  break;
2092  case nmAFRCil:
2093  FSensorCil[i].valreal = Engine[0]->GetCilindro(FSensorCil[i].cilindro - 1)->getAFR();
2094  FSensorCil[i].valact = ((2 * FSensorCil[i].ctetiempo - deltaT) * FSensorCil[i].valant + deltaT * FSensorCil[i].ganancia
2095  * (FSensorCil[i].valreal + FSensorCil[i].valrealant)) / (2 * FSensorCil[i].ctetiempo + deltaT);
2096  FSensorCil[i].valant = FSensorCil[i].valact;
2097  FSensorCil[i].valrealant = FSensorCil[i].valreal;
2098  break;
2099 
2100  }/*fin del switch*/
2101  }/*fin del for*/
2102  } catch(exception &N) {
2103  std::cout << "ERROR: Calculo_Sensores_Cilindro" << std::endl;
2104  std::cout << "Tipo de error: " << N.what() << std::endl;
2105  throw Exception(N.what());
2106  }
2107 }
2108 
2109 //-----------------------------------------------------------------------------
2110 //-----------------------------------------------------------------------------
2111 
2112 void TCalculoExtern::Calculo_Sensores_Venturi(double deltaT, TVenturi **Venturi) {
2113  try {
2114  int signo = 0;
2115  double prent = 0., prgar = 0., velent = 0., vellat = 0., gasent = 0., gaslat = 0.;
2116 
2117  for(int i = 0; i <= FNSensVenturis - 1; i++) {
2118  switch(FSensorVent[i].tipo) {
2119  case nmPrEntVent:
2120  prent = Venturi[FSensorVent[i].venturi - 1]->getPressure();
2121  FSensorVent[i].valreal = prent;
2122  FSensorVent[i].valact = ((2 * FSensorVent[i].ctetiempo - deltaT) * FSensorVent[i].valant + deltaT *
2123  FSensorVent[i].ganancia * (FSensorVent[i].valreal + FSensorVent[i].valrealant)) / (2 * FSensorVent[i].ctetiempo +
2124  deltaT);
2125  FSensorVent[i].valant = FSensorVent[i].valact;
2126  FSensorVent[i].valrealant = FSensorVent[i].valreal;
2127  break;
2128  case nmPrGarVent:
2129  prent = Venturi[FSensorVent[i].venturi - 1]->getPressure();
2130  prgar = prent / pow(
2131  1 + Venturi[FSensorVent[i].venturi - 1]->getgamma3() * pow(dynamic_cast<TCCDeposito *>
2132  (Venturi[FSensorVent[i].venturi - 1]->getCCLateral())->getValvula()->getCRecuperacion(), 2.),
2133  Venturi[FSensorVent[i].venturi - 1]->getGamma() / Venturi[FSensorVent[i].venturi - 1]->getgamma1());
2134  FSensorVent[i].valreal = prgar;
2135  FSensorVent[i].valact = ((2 * FSensorVent[i].ctetiempo - deltaT) * FSensorVent[i].valant + deltaT *
2136  FSensorVent[i].ganancia * (FSensorVent[i].valreal + FSensorVent[i].valrealant)) / (2 * FSensorVent[i].ctetiempo +
2137  deltaT);
2138  FSensorVent[i].valant = FSensorVent[i].valact;
2139  FSensorVent[i].valrealant = FSensorVent[i].valreal;
2140  break;
2141  case nmVelEntVent:
2142  if(dynamic_cast<TCCDeposito *>(Venturi[FSensorVent[i].venturi - 1]->getCCEntrada())->getSentidoFlujo() == nmEntrante) {
2143  signo = 1; /* Si el flujo es entrante signo de la velocidad positivo */
2144  } else if(dynamic_cast<TCCDeposito *>(Venturi[FSensorVent[i].venturi - 1]->getCCEntrada())->getSentidoFlujo() ==
2145  nmSaliente) {
2146  signo = -1; /* Si el flujo es saliente signo de la velocidad negativo */
2147  }
2148  velent = dynamic_cast<TCCDeposito *>(Venturi[FSensorVent[i].venturi - 1]->getCCEntrada())->getVelocity() * signo *
2149  __cons::ARef;
2150  FSensorVent[i].valreal = velent;
2151  FSensorVent[i].valact = ((2 * FSensorVent[i].ctetiempo - deltaT) * FSensorVent[i].valant + deltaT *
2152  FSensorVent[i].ganancia * (FSensorVent[i].valreal + FSensorVent[i].valrealant)) / (2 * FSensorVent[i].ctetiempo +
2153  deltaT);
2154  FSensorVent[i].valant = FSensorVent[i].valact;
2155  FSensorVent[i].valrealant = FSensorVent[i].valreal;
2156  break;
2157  case nmVelLatVent:
2158  vellat = dynamic_cast<TCCDeposito *>(Venturi[FSensorVent[i].venturi - 1]->getCCLateral())->getVelocity() * __cons::ARef;
2159  FSensorVent[i].valreal = vellat;
2160  FSensorVent[i].valact = ((2 * FSensorVent[i].ctetiempo - deltaT) * FSensorVent[i].valant + deltaT *
2161  FSensorVent[i].ganancia * (FSensorVent[i].valreal + FSensorVent[i].valrealant)) / (2 * FSensorVent[i].ctetiempo +
2162  deltaT);
2163  FSensorVent[i].valant = FSensorVent[i].valact;
2164  FSensorVent[i].valrealant = FSensorVent[i].valreal;
2165  break;
2166  case nmGastoEntVent:
2167  gasent = -dynamic_cast<TCCDeposito *>(Venturi[FSensorVent[i].venturi -
2168  1]->getCCEntrada())->getMassflow(); /*Massflow entrante positivo.Saliente negativo. Pedro */
2169  /* gasent lleva el "-" delante porque se usa el convenio de signos de los depositos,que es el contrario al de las BC, de la que se obtiene el massflow */
2170  FSensorVent[i].valreal = gasent;
2171  FSensorVent[i].valact = ((2 * FSensorVent[i].ctetiempo - deltaT) * FSensorVent[i].valant + deltaT *
2172  FSensorVent[i].ganancia * (FSensorVent[i].valreal + FSensorVent[i].valrealant)) / (2 * FSensorVent[i].ctetiempo +
2173  deltaT);
2174  FSensorVent[i].valant = FSensorVent[i].valact;
2175  FSensorVent[i].valrealant = FSensorVent[i].valreal;
2176  break;
2177  case nmGastoLatVent:
2178  gaslat = dynamic_cast<TCCDeposito *>(Venturi[FSensorVent[i].venturi - 1]->getCCLateral())->getMassflow();
2179  FSensorVent[i].valreal = gaslat;
2180  FSensorVent[i].valact = ((2 * FSensorVent[i].ctetiempo - deltaT) * FSensorVent[i].valant + deltaT *
2181  FSensorVent[i].ganancia * (FSensorVent[i].valreal + FSensorVent[i].valrealant)) / (2 * FSensorVent[i].ctetiempo +
2182  deltaT);
2183  FSensorVent[i].valant = FSensorVent[i].valact;
2184  FSensorVent[i].valrealant = FSensorVent[i].valreal;
2185  break;
2186 
2187  }/*fin del switch*/
2188  }/*fin del for*/
2189  } catch(exception &N) {
2190  std::cout << "ERROR: Calculo_Sensores_Venturi" << std::endl;
2191  std::cout << "Tipo de error: " << N.what() << std::endl;
2192  throw Exception(N.what());
2193  }
2194 }
2195 
2196 //------------------------------------------------------------------------------
2197 //------------------------------------------------------------------------------
2198 
2199 void TCalculoExtern::Calculo_Sensores_Motor(double deltaT, TBloqueMotor **Engine, double AcumulatedTime) {
2200  try {
2201  for(int i = 0; i <= FNSensMotor - 1; i++) {
2202  switch(FSensorMotor[i].tipo) {
2203  case nmAngulo:
2204  FSensorMotor[i].valreal = Engine[0]->getTheta();
2205  FSensorMotor[i].valact = ((2 * FSensorMotor[i].ctetiempo - deltaT) * FSensorMotor[i].valant + deltaT *
2206  FSensorMotor[i].ganancia * (FSensorMotor[i].valreal + FSensorMotor[i].valrealant)) /
2207  (2 * FSensorMotor[i].ctetiempo + deltaT);
2208  FSensorMotor[i].valant = FSensorMotor[i].valact;
2209  FSensorMotor[i].valrealant = FSensorMotor[i].valreal;
2210  break;
2211  case nmReg:
2212  FSensorMotor[i].valreal = Engine[0]->getRegimen();
2213  FSensorMotor[i].valact = ((2 * FSensorMotor[i].ctetiempo - deltaT) * FSensorMotor[i].valant + deltaT *
2214  FSensorMotor[i].ganancia * (FSensorMotor[i].valreal + FSensorMotor[i].valrealant)) /
2215  (2 * FSensorMotor[i].ctetiempo + deltaT);
2216  FSensorMotor[i].valant = FSensorMotor[i].valact;
2217  FSensorMotor[i].valrealant = FSensorMotor[i].valreal;
2218  break;
2219  case nmTiempo:
2220  FSensorMotor[i].valreal = AcumulatedTime;
2221  FSensorMotor[i].valact = ((2 * FSensorMotor[i].ctetiempo - deltaT) * FSensorMotor[i].valant + deltaT *
2222  FSensorMotor[i].ganancia * (FSensorMotor[i].valreal + FSensorMotor[i].valrealant)) /
2223  (2 * FSensorMotor[i].ctetiempo + deltaT);
2224  FSensorMotor[i].valant = FSensorMotor[i].valact;
2225  FSensorMotor[i].valrealant = FSensorMotor[i].valreal;
2226  break;
2227 
2228  }/*fin del switch*/
2229  }/*fin del for*/
2230  } catch(exception &N) {
2231  std::cout << "ERROR: Calculo_Sensores_Cilindro" << std::endl;
2232  std::cout << "Tipo de error: " << N.what() << std::endl;
2233  throw Exception(N.what());
2234  }
2235 }
2236 
2237 //------------------------------------------------------------------------------
2238 //------------------------------------------------------------------------------
2239 
2240 void TCalculoExtern::Calculo_Sensores_UED(double deltaT, TCondicionContorno **BC) {
2241  try {
2242  for(int i = 0; i <= FNSensUED - 1; i++) {
2243  switch(FSensorUED[i].tipo) {
2244  case nmGasto:
2245  FSensorUED[i].valreal = dynamic_cast<TCCUnionEntreDepositos*>(BC[FSensorUED[i].CCUED - 1])->getGastoImpreso();
2246  FSensorUED[i].valact = ((2 * FSensorUED[i].ctetiempo - deltaT) * FSensorUED[i].valant + deltaT * FSensorUED[i].ganancia
2247  * (FSensorUED[i].valreal + FSensorUED[i].valrealant)) / (2 * FSensorUED[i].ctetiempo + deltaT);
2248  FSensorUED[i].valant = FSensorUED[i].valact;
2249  FSensorUED[i].valrealant = FSensorUED[i].valreal;
2250  break;
2251  }/*fin del switch*/
2252  }/*fin del for*/
2253  } catch(exception &N) {
2254  std::cout << "ERROR: Calculo_Sensores_UED" << std::endl;
2255  std::cout << "Tipo de error: " << N.what() << std::endl;
2256  throw Exception(N.what());
2257  }
2258 }
2259 
2260 //-----------------------------------------------------------------------------
2261 //-----------------------------------------------------------------------------
2262 
2263 double TCalculoExtern::xit_(double vizq, double vder, double axid, double xif) {
2264  try {
2265  double xx = 0., yy = 0.;
2266  double ret_val = 0.;
2267 
2268  xx = vder - vizq;
2269  if(axid != 0.) {
2270  yy = xx / axid * xif;
2271  ret_val = vizq + yy;
2272  } else {
2273  printf("ERROR: valores entrada xit\n");
2274  throw Exception("");
2275  }
2276  return ret_val;
2277  } catch(exception &N) {
2278  std::cout << "ERROR: xit_" << std::endl;
2279  std::cout << "Tipo de error: " << N.what() << std::endl;
2280  throw Exception(N.what());
2281  }
2282 }
2283 
2284 //-----------------------------------------------------------------------------
2285 //-----------------------------------------------------------------------------
2286 void TCalculoExtern::InicializaMedias() {
2287  try {
2288 
2289  //Inicializa variables en el primer instante de calculo.
2290 
2291  printf("Recuerda que debes inicializar las variables que quieres graficar\n");
2292  // VariableSUM=0.;
2293  PosicionTurbinaSUM = 0.;
2294  SensorGastoAdmisionSUM = 0.;
2295  SensorP2SUM = 0.;
2296  SensorP3SUM = 0.;
2297  SensorP4SUM = 0.;
2298  SensorRegimenTurboSUM = 0.;
2299  } catch(exception &N) {
2300  std::cout << "ERROR: InicializaMedias" << std::endl;
2301  std::cout << "Tipo de error: " << N.what() << std::endl;
2302  throw Exception(N.what());
2303  }
2304 }
2305 
2306 //-----------------------------------------------------------------------------
2307 //-----------------------------------------------------------------------------
2308 void TCalculoExtern::AcumulaMedias(double DeltaT) {
2309  try {
2310 
2311  } catch(exception &N) {
2312  std::cout << "ERROR: AcumulaMedias: " << std::endl;
2313  std::cout << "Tipo de error: " << N.what() << std::endl;
2314  throw Exception(N.what());
2315  }
2316 }
2317 
2318 //-----------------------------------------------------------------------------
2319 //-----------------------------------------------------------------------------
2320 
2321 void TCalculoExtern::CalculaMedias() {
2322  try {
2323  // Variable1=VariableSUM/FTiempoSum;
2324 // PosicionTurbina=PosicionTurbinaSUM/FTiempoSum;
2325 // SensorGastoAdmision=SensorGastoAdmisionSUM/FTiempoSum;
2326 // SensorP2=SensorP2SUM/FTiempoSum;
2327 // SensorP3=SensorP3SUM/FTiempoSum;
2328 // SensorP4=SensorP4SUM/FTiempoSum;
2329 // SensorRegimenTurbo=SensorRegimenTurboSUM/FTiempoSum;
2330 // SensorRelCinematica=SensorRelCinematicaSUM/FTiempoSum;
2331 // PosicionTurbinaSUM=0.;
2332 // SensorGastoAdmisionSUM=0.;
2333 // SensorP2SUM=0.;
2334 // SensorP3SUM=0.;
2335 // SensorP4SUM=0.;
2336 // SensorRegimenTurboSUM=0.;
2337 // SensorRelCinematicaSUM=0.;
2338 // FTiempoSum=0.;
2339  // VariableSUM=0.;
2340 
2341  } catch(exception &N) {
2342  std::cout << "ERROR: CalculaMedias: " << std::endl;
2343  std::cout << "Tipo de error: " << N.what() << std::endl;
2344  throw Exception(N.what());
2345  }
2346 }
2347 
2348 //-----------------------------------------------------------------------------
2349 //-----------------------------------------------------------------------------
2350 
2351 void TCalculoExtern::ImprimeCabeceraMedias(stringstream& medoutput) {
2352  try {
2353 // fstream fich;
2354 // fich.open(FileMed,ios::out | ios::app);
2355 //
2356 // /* for(int i=0;i<Fngrafmat;i++){
2357 // //fich << '\t' << "Salida_Media_EXTERN_" << i;
2358 //
2359 // } */
2360 // fich << '\t' << "Posicion_Turbina_[%]";
2361 // fich << '\t' << "Sensor_Gasto_Admision_[kg/s]";
2362 // fich << '\t' << "Sensor_P2_[bar]";
2363 // fich << '\t' << "Sensor_P3_[bar]";
2364 // fich << '\t' << "Sensor_P4_[bar]";
2365 // fich << '\t' << "Regimen_Turbo_[rpm]";
2366 // fich << '\t' << "Sensor_Rel_Cin";
2367 // fich.close();
2368  } catch(exception &N) {
2369  std::cout << "ERROR: ImprimeCabeceraMedias: " << std::endl;
2370  std::cout << "Tipo de error: " << N.what() << std::endl;
2371  throw Exception(N.what());
2372  }
2373 }
2374 
2375 //-----------------------------------------------------------------------------
2376 //-----------------------------------------------------------------------------
2377 
2378 void TCalculoExtern::ImprimeGraficosMedias(stringstream& medoutput) {
2379  try {
2380 // fstream fich;
2381 // fich.open(FileMed,ios::out | ios::app);
2382 //
2383 // //fich << '\t' << Variable;
2384 // fich << '\t' << PosicionTurbina;
2385 // fich << '\t' << SensorGastoAdmision;
2386 // fich << '\t' << SensorP2;
2387 // fich << '\t' << SensorP3;
2388 // fich << '\t' << SensorP4;
2389 // fich << '\t' << SensorRegimenTurbo;
2390 // fich << '\t' << SensorRelCinematica;
2391 // fich.close();
2392 
2393  } catch(exception &N) {
2394  std::cout << "ERROR: ImprimeGraficosMedias: " << std::endl;
2395  std::cout << "Tipo de error: " << N.what() << std::endl;
2396  throw Exception(N.what());
2397  }
2398 }
2399 //------------------------------------------------------------------------------
2400 //------------------------------------------------------------------------------
2401 
2402 void TCalculoExtern::ImprimeCabeceraInstantaneas(stringstream& insoutput) {
2403  try {
2404  //fstream fich;
2405  //fich.open(FileIns,ios::out | ios::app);
2406 
2407  //for(int i=0;i<Fngrafmat;i++){
2408  // fich << '\t' << "Salida_Instantanea_EXTERN_" << i;
2409  //}
2410  //fich.close();
2411  } catch(exception &N) {
2412  std::cout << "ERROR: ImprimeCabeceraInstantaneas: " << std::endl;
2413  std::cout << "Tipo de error: " << N.what() << std::endl;
2414  throw Exception(N.what());
2415  }
2416 }
2417 
2418 //-----------------------------------------------------------------------------
2419 //-----------------------------------------------------------------------------
2420 
2421 void TCalculoExtern::ImprimeGraficosInstantaneas(stringstream& insoutput) {
2422  try {
2423  //fstream fich;
2424  //fich.open(FileIns,ios::out | ios::app);
2425 
2426  // fich << '\t' << Variable;
2427 
2428  //fich.close();
2429  } catch(exception &N) {
2430  std::cout << "ERROR: ImprimeGraficosInstantaneas: " << std::endl;
2431  std::cout << "Tipo de error: " << N.what() << std::endl;
2432  throw Exception(N.what());
2433  }
2434 }
2435 
2436 //------------------------------------------------------------------------------
2437 //------------------------------------------------------------------------------
2438 
2439 void TCalculoExtern::ObtenerRutaTrabajo(const char *origin) {
2440  try {
2441  int contpunto = 0;
2442  for(int i = (int) strlen(origin) - 1; i >= 0; i--) {
2443  if(origin[i] == '\\') {
2444  contpunto = i + 1; //ha encontrado el punto de la extension
2445  break;
2446  }
2447  }
2448  FRutaTrabajo = new char[contpunto + 1];
2449  for(int i = 0; i < contpunto; i++) {
2450  FRutaTrabajo[i] = origin[i];
2451  }
2452  FRutaTrabajo[contpunto] = '\0';
2453 
2454  } catch(exception &N) {
2455  std::cout << "ERROR: ObtenerRutaTrabajo: " << std::endl;
2456  std::cout << "Tipo de error: " << N.what() << std::endl;
2457  throw Exception(N.what());
2458  }
2459 }
2460 
2461 //------------------------------------------------------------------------------
2462 //------------------------------------------------------------------------------
2463 #pragma package(smart_init)
2464 
stSensorCil
Definition: TCalculoExtern.h:146
TEjeTurbogrupo
Definition: TEjeTurbogrupo.h:47
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
stSensorDep
Definition: TCalculoExtern.h:113
TEGRV
Definition: TEGRV.h:46
TControlFuel
Definition: TControlFuel.h:42
TControlInyeccion
Definition: TControlInyeccion.h:42
TTurbina
Definition: TTurbina.h:41
TCCUnionEntreDepositos
Definition: TCCUnionEntreDepositos.h:41
TControlK
Definition: TControlK.h:44
TTubo::GetVelocidad
double GetVelocidad(int i) const
Gets the fluid speed.
Definition: TTubo.cpp:5505
TAjusteTransCalorCil
Definition: TAjusteTransCalorCil.h:44
TTubo::GetPresion
double GetPresion(int i) const
Gets the fluid pressure.
Definition: TTubo.cpp:5468
TCondicionContorno
Definition: TCondicionContorno.h:54
TDeposito
Definition: TDeposito.h:44
TCoefDescarga
Definition: TCoefDescarga.h:42
stSensorTubos
Definition: TCalculoExtern.h:99
stSensorMotor
Definition: TCalculoExtern.h:168
Exception
Custom exception class.
Definition: Exception.hpp:39
TTGV
Definition: TTGV.h:40
TFraccionMasicaCilindro
Definition: TFraccionMasicaCilindro.h:40
TVenturi
Definition: TVenturi.h:33
TTubo.h
TBloqueMotor
Definition: TBloqueMotor.h:43
TCCDeposito
Definition: TCCDeposito.h:40
pow2
T pow2(T x)
Returns x to the power of 2.
Definition: Math_wam.h:88
TTubo::GetRMezcla
double GetRMezcla(int i) const
Gets the gas constant of the mixture at a given cell.
Definition: TTubo.cpp:5476
TRemansoMatlab
Definition: TRemansoMatlab.h:43
TTubo::GetFraccionMasica
double GetFraccionMasica(int j, int i)
Definition: TTubo.h:1219
stSensorVent
Definition: TCalculoExtern.h:157
TTubo::getPresionInicial
double getPresionInicial() const
Gets the initial pressure.
Definition: TTubo.cpp:5472
TTubo::GetAsonido
double GetAsonido(int i) const
Gets the speed of sound.
Definition: TTubo.cpp:5412
TTubo::getVelocidadMedia
double getVelocidadMedia() const
Gets the mean speed.
Definition: TTubo.cpp:5509
stSensorTurbina
Definition: TCalculoExtern.h:135
stSensorTG
Definition: TCalculoExtern.h:124
stSensorUED
Definition: TCalculoExtern.h:179
Tfql
Definition: Tfql.h:51