OpenWAM
TTubo.cpp
Go to the documentation of this file.
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 
53 // ---------------------------------------------------------------------------
54 #pragma hdrstop
55 
56 #include "TTubo.h"
57 #include "TBloqueMotor.h"
58 
59 // ---------------------------------------------------------------------------
60 // ---------------------------------------------------------------------------
61 
62 TTubo::TTubo(int SpeciesNumber, int j, double SimulationDuration, TBloqueMotor **Engine,
63  nmTipoCalculoEspecies SpeciesModel, nmCalculoGamma GammaCalculation, bool ThereIsEGR) {
64 
65  if(Engine != NULL) {
66  FAnguloTotalCiclo = Engine[0]->getAngTotalCiclo();
67  } else if(Engine == NULL) {
68  FAnguloTotalCiclo = 720.;
69  FRegimenFicticio = 720. / 6. / SimulationDuration;
70  }
71 
72 #ifdef ParticulateFilter
73  FDPFEntradaTubo = NULL;
74  FDPFSalidaTubo = NULL;
75  FHayDPFNodoIzq = false;
76  FHayDPFNodoDer = false;
77 #endif
78 
79  FHayEGR = ThereIsEGR;
80  if(FHayEGR)
81  FIntEGR = 0;
82  else
83  FIntEGR = 1;
84 
85  FSUMTime = 0.;
86  FCicloTubo = 0;
87  FNumeroTubo = j + 1;
88 
89  FNumeroEspecies = SpeciesNumber;
90  FCalculoEspecies = SpeciesModel;
91  FCalculoGamma = GammaCalculation;
92  FNumEcuaciones = 3 + (FNumeroEspecies - 1 - FIntEGR);
93 
94  FComposicionInicial = NULL;
95  FFraccionMasicaEspecie = NULL;
96  FFraccionMasicaCC = NULL;
97  FVelocidadCC = NULL;
98  FDensidadCC = NULL;
99  FAreaCC = NULL;
100  FGamma = NULL;
101  FRMezcla = NULL;
102  FGamma1 = NULL;
103  FGamma3 = NULL;
104  FGamma4 = NULL;
105  FGamma5 = NULL;
106  FGamma6 = NULL;
107 
108  FDExtTramo = NULL;
109  FLTramo = NULL;
110  FDiametroTubo = NULL;
111  FDiametroD12 = NULL;
112  FDiametroS12 = NULL;
113  FDerLin = NULL;
114  FDerLin12 = NULL;
115  FDerLinArea = NULL;
116  FDerLinArea12 = NULL;
117  FArea = NULL;
118  FArea12 = NULL;
119  FPresion0 = NULL;
120  FAsonido0 = NULL;
121  FVelocidad0 = NULL;
122  FVelocidadMedia = NULL;
123  FAsonidoMedia = NULL;
124  FPresionMedia = NULL;
125  FPresion1 = NULL;
126  FAsonido1 = NULL;
127  FVelocidad1 = NULL;
128  FUt = NULL;
129  FU0 = NULL;
130  FU0Sum = NULL;
131  FU0Medio = NULL;
132  FU1 = NULL;
133  FU12 = NULL;
134  FW = NULL;
135  FV1 = NULL;
136  FV2 = NULL;
137  FUfct0 = NULL;
138  FUfct1 = NULL;
139  FUfctd = NULL;
140  FUfctad = NULL;
141  Ffl = NULL;
142  FdU = NULL;
143  FDeltaFCTd = NULL;
144  FflU = NULL;
145  FaU = NULL;
146  FVelPro = NULL;
147  FCoefTurbulencia = NULL;
148  FSUMTPTuboPro = NULL;
149  FTPTubo = NULL;
150  FTParedAnt = NULL;
151  ResultadosMedios = NULL;
152  ResultInstantaneos = NULL;
153  FNumResMedios = 0;
154  FNumResInstant = 0;
155  FNumDistSensores = 0;
156  FIntercooler = false;
157  FConcentrico = false;
158  FMod.Modelo = nmLaxWendroff;
159  FMod.SubModelo = nmNinguno;
160  FMod.OpcionSubModelo = nmNinguna;
161  FMod.FormulacionLeyes = nmSinArea;
162  /* FTVD=NULL;
163  FTVDdU=NULL;
164  FTVDpp=NULL;
165  FTVDpn=NULL;
166  FTVDrp=NULL;
167  FTVDrn=NULL;
168  FTVDphp=NULL;
169  FTVDphn=NULL;
170  FTVDGp=NULL;
171  FTVDGn=NULL; */
172  FCourantLocal = NULL;
173  Fhi = NULL;
174  Fhe = NULL;
175  Frho = NULL;
176  FRe = NULL;
177  FTVD.Bmas = NULL;
178  FTVD.Bvector = NULL;
179  FTVD.Bmen = NULL;
180  FTVD.Qmatrix = NULL;
181  FTVD.Pmatrix = NULL;
182  FTVD.gflux = NULL;
183  FTVD.Alpha = NULL;
184  FTVD.Beta = NULL;
185  FTVD.DeltaU = NULL;
186  FTVD.DeltaB = NULL;
187  FTVD.DeltaW = NULL;
188  FTVD.hLandaD = NULL;
189  FTVD.LandaD = NULL;
190  FTVD.Phi = NULL;
191  FTVD.R = NULL;
192  FTVD.W = NULL;
193 
194  FCapa = NULL;
195 
196  FResistRadInt = NULL;
197  FResistRadExt = NULL;
198  FResistAxiAnt = NULL;
199  FResistAxiPos = NULL;
200  FCapInt = NULL;
201  FCapMed = NULL;
202  FCapExt = NULL;
203 
204  FVelocidadDim = NULL;
205  FAsonidoDim = NULL;
206  FTemperature = NULL;
207  FFlowMass = NULL;
208 
209 }
210 
211 // ---------------------------------------------------------------------------
212 // ---------------------------------------------------------------------------
213 
215 
216  DestruyeVector(FVelocidadDim);
217  DestruyeVector(FAsonidoDim);
218  DestruyeVector(FTemperature);
219  DestruyeVector(FFlowMass);
220 
221  DestruyeVector(FComposicionInicial);
222 
223  // if(FComposicionInicial) delete[] FComposicionInicial;
224  if(FFraccionMasicaEspecie != NULL) {
225  for(int i = 0; i < FNin; i++)
226  delete[] FFraccionMasicaEspecie[i];
227  delete[] FFraccionMasicaEspecie;
228  }
229  if(FFraccionMasicaCC != NULL) {
230  for(int i = 0; i < 2; i++)
231  delete[] FFraccionMasicaCC[i];
232  delete[] FFraccionMasicaCC;
233  }
234  if(FVelocidadCC != NULL)
235  delete[] FVelocidadCC;
236  if(FDensidadCC != NULL)
237  delete[] FDensidadCC;
238  if(FAreaCC != NULL)
239  delete[] FAreaCC;
240  if(FGamma != NULL)
241  delete[] FGamma;
242  if(FRMezcla != NULL)
243  delete[] FRMezcla;
244  if(FGamma1 != NULL)
245  delete[] FGamma1;
246  if(FGamma3 != NULL)
247  delete[] FGamma3;
248  if(FGamma4 != NULL)
249  delete[] FGamma4;
250  if(FGamma5 != NULL)
251  delete[] FGamma5;
252  if(FGamma6 != NULL)
253  delete[] FGamma6;
254 
255  if(FDExtTramo != NULL)
256  delete[] FDExtTramo;
257  if(FLTramo != NULL)
258  delete[] FLTramo;
259  if(FDiametroTubo != NULL)
260  delete[] FDiametroTubo;
261  if(FDiametroD12 != NULL)
262  delete[] FDiametroD12;
263  if(FDiametroS12 != NULL)
264  delete[] FDiametroS12;
265  if(FDerLin != NULL)
266  delete[] FDerLin;
267  if(FDerLin12 != NULL)
268  delete[] FDerLin12;
269  if(FDerLinArea != NULL)
270  delete[] FDerLinArea;
271  if(FDerLinArea12 != NULL)
272  delete[] FDerLinArea12;
273  if(FArea != NULL)
274  delete[] FArea;
275  if(FArea12 != NULL)
276  delete[] FArea12;
277  if(FPresion0 != NULL)
278  delete[] FPresion0;
279  if(FAsonido0 != NULL)
280  delete[] FAsonido0;
281  if(FVelocidad0 != NULL)
282  delete[] FVelocidad0;
283  if(FVelocidadMedia != NULL)
284  delete[] FVelocidadMedia;
285  if(FAsonidoMedia != NULL)
286  delete[] FAsonidoMedia;
287  if(FPresionMedia != NULL)
288  delete[] FPresionMedia;
289  if(FPresion1 != NULL)
290  delete[] FPresion1;
291  if(FAsonido1 != NULL)
292  delete[] FAsonido1;
293  if(FVelocidad1 != NULL)
294  delete[] FVelocidad1;
295  if(Fhi != NULL)
296  delete[] Fhi;
297  if(Fhe != NULL)
298  delete[] Fhe;
299  if(Frho != NULL)
300  delete[] Frho;
301  if(FRe != NULL)
302  delete[] FRe;
303 
304  if(FUt != NULL) {
305  for(int i = 0; i < 3; i++)
306  delete[] FUt[i];
307  delete[] FUt;
308  }
309  if(FU0 != NULL) {
310  for(int i = 0; i < FNumEcuaciones; i++)
311  delete[] FU0[i];
312  delete[] FU0;
313  }
314  if(FU0Sum != NULL) {
315  for(int i = 0; i < FNumEcuaciones; i++)
316  delete[] FU0Sum[i];
317  delete[] FU0Sum;
318  }
319  if(FU0Medio != NULL) {
320  for(int i = 0; i < FNumEcuaciones; i++)
321  delete[] FU0Medio[i];
322  delete[] FU0Medio;
323  }
324  if(FU1 != NULL) {
325  for(int i = 0; i < FNumEcuaciones; i++)
326  delete[] FU1[i];
327  delete[] FU1;
328  }
329  if(FU12 != NULL) {
330  for(int i = 0; i < FNumEcuaciones; i++)
331  delete[] FU12[i];
332  delete[] FU12;
333  }
334  if(FW != NULL) {
335  for(int i = 0; i < FNumEcuaciones; i++)
336  delete[] FW[i];
337  delete[] FW;
338  }
339  if(FV1 != NULL) {
340  for(int i = 0; i < FNumEcuaciones; i++)
341  delete[] FV1[i];
342  delete[] FV1;
343  }
344  if(FV2 != NULL) {
345  for(int i = 0; i < FNumEcuaciones; i++)
346  delete[] FV2[i];
347  delete[] FV2;
348  }
349  if(FUfct0 != NULL) {
350  for(int i = 0; i < FNumEcuaciones; i++)
351  delete[] FUfct0[i];
352  delete[] FUfct0;
353  }
354  if(FUfct1 != NULL) {
355  for(int i = 0; i < FNumEcuaciones; i++)
356  delete[] FUfct1[i];
357  delete[] FUfct1;
358  }
359  if(FUfctd != NULL) {
360  for(int i = 0; i < FNumEcuaciones; i++)
361  delete[] FUfctd[i];
362  delete[] FUfctd;
363  }
364  if(FUfctad != NULL) {
365  for(int i = 0; i < FNumEcuaciones; i++)
366  delete[] FUfctad[i];
367  delete[] FUfctad;
368  }
369  if(Ffl != NULL) {
370  for(int i = 0; i < FNumEcuaciones; i++)
371  delete[] Ffl[i];
372  delete[] Ffl;
373  }
374  if(FdU != NULL) {
375  for(int i = 0; i < FNumEcuaciones; i++)
376  delete[] FdU[i];
377  delete[] FdU;
378  }
379  if(FDeltaFCTd != NULL) {
380  for(int i = 0; i < FNumEcuaciones; i++)
381  delete[] FDeltaFCTd[i];
382  delete[] FDeltaFCTd;
383  }
384  if(FflU != NULL) {
385  for(int i = 0; i < FNumEcuaciones; i++)
386  delete[] FflU[i];
387  delete[] FflU;
388  }
389  if(FaU != NULL) {
390  for(int i = 0; i < FNumEcuaciones; i++)
391  delete[] FaU[i];
392  delete[] FaU;
393  }
394  if(FVelPro != NULL)
395  delete[] FVelPro;
396  if(FCoefTurbulencia != NULL)
397  delete[] FCoefTurbulencia;
398  if(FSUMTPTuboPro != NULL) {
399  for(int i = 0; i < 2; i++) {
400  for(int j = 0; j < 3; j++) {
401  delete[] FSUMTPTuboPro[i][j];
402  }
403  delete[] FSUMTPTuboPro[i];
404  }
405  delete[] FSUMTPTuboPro;
406  }
407  if(FTPTubo != NULL) {
408  for(int i = 0; i < 3; i++)
409  delete[] FTPTubo[i];
410  delete[] FTPTubo;
411  }
412  if(FTParedAnt != NULL) {
413  for(int i = 0; i < 3; i++)
414  delete[] FTParedAnt[i];
415  delete[] FTParedAnt;
416  }
417 
418  for(int i = 0; i < FNumResMedios; i++) {
419  if(ResultadosMedios[i].FraccionSUM != NULL)
420  delete[] ResultadosMedios[i].FraccionSUM;
421  if(ResultadosMedios[i].FraccionMED != NULL)
422  delete[] ResultadosMedios[i].FraccionMED;
423  }
424  if(ResultadosMedios != NULL)
425  delete[] ResultadosMedios;
426  for(int i = 0; i < FNumResInstant; i++) {
427  if(ResultInstantaneos[i].FraccionINS != NULL)
428  delete[] ResultInstantaneos[i].FraccionINS;
429  }
430  if(ResultInstantaneos != NULL)
431  delete[] ResultInstantaneos;
432 
433  if(FCourantLocal != NULL)
434  delete[] FCourantLocal;
435 
436  for(int i = 0; i < FNumEcuaciones; i++) {
437  for(int k = 0; k < FNumEcuaciones; k++) {
438  if(FTVD.Pmatrix != NULL)
439  delete[] FTVD.Pmatrix[i][k];
440  if(FTVD.Qmatrix != NULL)
441  delete[] FTVD.Qmatrix[i][k];
442  }
443  if(FTVD.Pmatrix != NULL)
444  delete[] FTVD.Pmatrix[i];
445  if(FTVD.Qmatrix != NULL)
446  delete[] FTVD.Qmatrix[i];
447  }
448  for(int i = 0; i < FNumEcuaciones; i++) {
449  if(FTVD.Bmas != NULL)
450  delete[] FTVD.Bmas[i];
451  if(FTVD.Bmen != NULL)
452  delete[] FTVD.Bmen[i];
453  if(FTVD.Bvector != NULL)
454  delete[] FTVD.Bvector[i];
455  if(FTVD.gflux != NULL)
456  delete[] FTVD.gflux[i];
457  if(FTVD.Alpha != NULL)
458  delete[] FTVD.Alpha[i];
459  if(FTVD.Beta != NULL)
460  delete[] FTVD.Beta[i];
461  if(FTVD.DeltaU != NULL)
462  delete[] FTVD.DeltaU[i];
463  if(FTVD.DeltaB != NULL)
464  delete[] FTVD.DeltaB[i];
465  if(FTVD.DeltaW != NULL)
466  delete[] FTVD.DeltaW[i];
467  if(FTVD.hLandaD != NULL)
468  delete[] FTVD.hLandaD[i];
469  if(FTVD.LandaD != NULL)
470  delete[] FTVD.LandaD[i];
471  if(FTVD.Phi != NULL)
472  delete[] FTVD.Phi[i];
473  if(FTVD.W != NULL)
474  delete[] FTVD.W[i];
475  if(FTVD.R != NULL)
476  delete[] FTVD.R[i];
477  }
478 
479  if(FTVD.Pmatrix != NULL)
480  delete[] FTVD.Pmatrix;
481  if(FTVD.Qmatrix != NULL)
482  delete[] FTVD.Qmatrix;
483  if(FTVD.Bmas != NULL)
484  delete[] FTVD.Bmas;
485  if(FTVD.Bmen != NULL)
486  delete[] FTVD.Bmen;
487  if(FTVD.Bvector != NULL)
488  delete[] FTVD.Bvector;
489  if(FTVD.gflux != NULL)
490  delete[] FTVD.gflux;
491  if(FTVD.Alpha != NULL)
492  delete[] FTVD.Alpha;
493  if(FTVD.Beta != NULL)
494  delete[] FTVD.Beta;
495  if(FTVD.DeltaU != NULL)
496  delete[] FTVD.DeltaU;
497  if(FTVD.DeltaB != NULL)
498  delete[] FTVD.DeltaB;
499  if(FTVD.DeltaW != NULL)
500  delete[] FTVD.DeltaW;
501  if(FTVD.hLandaD != NULL)
502  delete[] FTVD.hLandaD;
503  if(FTVD.LandaD != NULL)
504  delete[] FTVD.LandaD;
505  if(FTVD.Phi != NULL)
506  delete[] FTVD.Phi;
507  if(FTVD.W != NULL)
508  delete[] FTVD.W;
509  if(FTVD.R != NULL)
510  delete[] FTVD.R;
511 
512  if(FCapa != NULL)
513  delete[] FCapa;
514 
515  if(FResistRadInt != NULL)
516  delete[] FResistRadInt;
517  if(FResistRadExt != NULL)
518  delete[] FResistRadExt;
519  if(FResistAxiAnt != NULL)
520  delete[] FResistAxiAnt;
521  if(FResistAxiPos != NULL)
522  delete[] FResistAxiPos;
523  if(FCapInt != NULL)
524  delete[] FCapInt;
525  if(FCapMed != NULL)
526  delete[] FCapMed;
527  if(FCapExt != NULL)
528  delete[] FCapExt;
529 
530 }
531 
532 // ---------------------------------------------------------------------------
533 // ---------------------------------------------------------------------------
534 
535 void TTubo::LeeDatosGeneralesTubo(const char *FileWAM, fpos_t &filepos) {
536 #ifdef usetry
537  try {
538 #endif
539  int TipTC = 0, Concentrico;
540  int metodo[4];
541  double fracciontotal = 0.;
542 
543  FILE *fich = fopen(FileWAM, "r");
544  fsetpos(fich, &filepos);
545 
546  fscanf(fich, "%d %d %d %d", &FNodoIzq, &FNodoDer, &FNTramos, &FNumeroConductos);
547  fscanf(fich, "%lf ", &FFriccion);
548  fscanf(fich, "%lf %lf %lf %lf ", &FTIniParedTub, &FTini, &FPini, &FVelMedia);
549  fscanf(fich, "%d %lf %lf ", &TipTC, &FCoefAjusTC, &FCoefAjusFric);
550 
551  switch(TipTC) {
552  case 1:
553  FTipoTransCal = nmTuboAdmision;
554  break;
555  case 2:
556  FTipoTransCal = nmTuboEscape;
557  break;
558  case 3:
559  FTipoTransCal = nmPipaEscape;
560  break;
561  case 4:
562  FTipoTransCal = nmPipaAdmision;
563  break;
564  }
565 
566  FComposicionInicial = new double[FNumeroEspecies - FIntEGR];
567  for(int i = 0; i < FNumeroEspecies - 1; i++) {
568  fscanf(fich, "%lf ", &FComposicionInicial[i]);
569  fracciontotal += FComposicionInicial[i];
570  }
571  if(FHayEGR) {
572  if(FCalculoEspecies == nmCalculoCompleto) {
573  if(FComposicionInicial[0] > 0.2)
574  FComposicionInicial[FNumeroEspecies - 1] = 0.;
575  else
576  FComposicionInicial[FNumeroEspecies - 1] = 1.;
577  } else {
578  if(FComposicionInicial[0] > 0.5)
579  FComposicionInicial[FNumeroEspecies - 1] = 1.;
580  else
581  FComposicionInicial[FNumeroEspecies - 1] = 0.;
582  }
583  }
584 
585  if(fracciontotal > 1 + 1.e-10 && fracciontotal < 1 - 1e-10) {
586  std::cout << "ERROR: Total mass fraction must be equal to 1. Check input data for pipe " << FNumeroTubo << std::endl;
587  throw Exception(" ");
588  }
589 
590  fscanf(fich, "%lf %d ", &FMallado, &FTctpt);
591 
592  switch(FTctpt) {
593  case 0:
594  FTipoCalcTempPared = nmVariableConInerciaTermica;
595  break;
596  case 1:
597  FTipoCalcTempPared = nmVariableSinInerciaTermica;
598  break;
599  case 2:
600  FTipoCalcTempPared = nmTempConstante;
601  break;
602  }
603 
604  fscanf(fich, "%d ", &metodo[0]);
605 
606  if(metodo[0] == 0) {
607  FMod.Modelo = nmLaxWendroff;
608  fscanf(fich, "%d ", &metodo[1]);
609  if(metodo[1] == 0) {
610  // Lax&Wendroff
611  metodo[3] = 1;
612  switch(metodo[3]) {
613  case 0:
614  FMod.FormulacionLeyes = nmSinArea;
615  break;
616  case 1:
617  FMod.FormulacionLeyes = nmConArea;
618  break;
619  }
620  }
621 
622  if(metodo[1] == 1) {
623  // Lax&Wendroff + FCT
624  FMod.FormulacionLeyes = nmConArea;
625  FMod.SubModelo = nmFCT;
626  fscanf(fich, "%d ", &metodo[2]);
627  switch(metodo[2]) {
628  case 0:
629  FMod.OpcionSubModelo = nmDDNAD;
630  FMod.Difusion = nmDamping;
631  FMod.Antidifusion = nmNaive;
632  break;
633  case 1:
634  FMod.OpcionSubModelo = nmDDPAD;
635  FMod.Difusion = nmDamping;
636  FMod.Antidifusion = nmPhoenical;
637  break;
638  case 2:
639  FMod.OpcionSubModelo = nmDDEAD;
640  FMod.Difusion = nmDamping;
641  FMod.Antidifusion = nmExplicit;
642  break;
643  case 3:
644  FMod.OpcionSubModelo = nmDSNAD;
645  FMod.Difusion = nmSmoothing;
646  FMod.Antidifusion = nmNaive;
647  break;
648  case 4:
649  FMod.OpcionSubModelo = nmDSPAD;
650  FMod.Difusion = nmSmoothing;
651  FMod.Antidifusion = nmPhoenical;
652  break;
653  case 5:
654  FMod.OpcionSubModelo = nmDSEAD;
655  FMod.Difusion = nmSmoothing;
656  FMod.Antidifusion = nmPhoenical;
657  break;
658  }
659  }
660  } else if(metodo[0] == 2) {
661  FMod.Modelo = nmTVD;
662  FMod.FormulacionLeyes = nmConArea;
663  }
664 
665  fscanf(fich, "%lf ", &FCourant);
666 
667  fgetpos(fich, &filepos);
668  fclose(fich);
669 #ifdef usetry
670  } catch(exception & N) {
671  std::cout << "ERROR: TTubo::LeeDatosGeneralesTubo en el tubo: " << FNumeroTubo << std::endl;
672  std::cout << "Tipo de error: " << N.what() << std::endl;
673  throw Exception(N.what());
674  }
675 #endif
676 }
677 
678 // ---------------------------------------------------------------------------
679 // ---------------------------------------------------------------------------
680 
681 void TTubo::LeeDatosGeometricosTubo(const char *FileWAM, fpos_t &filepos, double ene, int tipomallado,
682  TBloqueMotor **Engine) {
683  double EspesorPrin = 0.;
684  int EsPrincipal = 0, refrigerante = 0, EsFluida = 0;
685  int datoWAMer = 0;
686 
687  FDExtTramo = new double[FNTramos + 1];
688  FLTramo = new double[FNTramos + 1];
689 #ifdef usetry
690  try {
691 #endif
692 
693  FILE *fich = fopen(FileWAM, "r");
694  fsetpos(fich, &filepos);
695 
696  switch(tipomallado) {
697  case 1:
698  FTipoMallado = nmDistancia;
699  break;
700  case 2:
701  FTipoMallado = nmAngular;
702  break;
703  }
704 
705  if(FTipoMallado == nmAngular && ene < 0.) {
706  std::cout << "ERROR: El mallado no puede ser angular al no existir motor.Pipe: " << FNumeroTubo << std::endl;
707  throw Exception("");
708  }
709 
710  fscanf(fich, "%lf ", &FDExtTramo[0]);
711  for(int i = 1; i <= FNTramos; i++) {
712  fscanf(fich, "%lf %lf ", &FLTramo[i], &FDExtTramo[i]);
713  }
714  CalculoPuntosMalla(ene);
715 
716  if(FTipoCalcTempPared != nmTempConstante) {
717  FResistRadInt = new double[FNin];
718  FResistRadExt = new double[FNin];
719  FResistAxiAnt = new double[FNin];
720  FResistAxiPos = new double[FNin];
721  FCapInt = new double[FNin];
722  FCapMed = new double[FNin];
723  FCapExt = new double[FNin];
724 
725  if(Engine == NULL) {
726  fscanf(fich, "%lf %d ", &FDuracionCiclo, &FNumCiclosSinInerciaTermica);
727  }
728 
729  if(FTipoTransCal != nmPipaEscape && FTipoTransCal != nmPipaAdmision) {
730  fscanf(fich, "%lf %lf %d ", &FCoefExt, &FEmisividad, &refrigerante);
731  switch(refrigerante) {
732  case 0:
733  FTipRefrig = nmAire;
734  break;
735  case 1:
736  FTipRefrig = nmAgua;
737  break;
738  }
739  if(FTipRefrig == nmAgua)
740  fscanf(fich, "%lf ", &FTRefrigerante); /* Esta en degC */
741  } else {
742  FCoefExt = 1.;
743  FEmisividad = 0.5;
744  fscanf(fich, "%d", &datoWAMer);
745  }
746 
747  fscanf(fich, "%d ", &FNumCapas);
748  FCapa = new stCapa[FNumCapas];
749  EspesorPrin = 0.;
750  for(int i = 0; i < FNumCapas; i++) {
751  fscanf(fich, "%d %d ", &EsPrincipal, &EsFluida);
752  EsPrincipal == 0 ? FCapa[i].EsPrincipal = false : FCapa[i].EsPrincipal = true;
753  EsFluida == 0 ? FCapa[i].EsFluida = false : FCapa[i].EsFluida == true;
754  if(FCapa[i].EsFluida) {
755  fscanf(fich, "%lf %lf ", &FCapa[i].EmisividadInterior, &FCapa[i].EmisividadExterior);
756  } else {
757  fscanf(fich, "%lf %lf %lf %lf ", &FCapa[i].Density, &FCapa[i].CalorEspecifico, &FCapa[i].Conductividad,
758  &FCapa[i].Espesor);
759  fscanf(fich, "%lf %lf ", &FCapa[i].EmisividadInterior, &FCapa[i].EmisividadExterior);
760  }
761  if(FCapa[i].EsPrincipal) {
762  FEspesorIntPrin = EspesorPrin;
763  FEspesorPrin = FCapa[i].Espesor;
764  FDensidadPrin = FCapa[i].Density;
765  FCalEspPrin = FCapa[i].CalorEspecifico;
766  FConductPrin = FCapa[i].Conductividad;
767  EspesorPrin = 0.;
768  } else {
769  EspesorPrin += FCapa[i].Espesor;
770  }
771  }
772  // }
773  FEspesorExtPrin = EspesorPrin;
774  } else if(FTipoTransCal == nmPipaEscape || FTipoTransCal == nmPipaAdmision) {
775  fscanf(fich, "%d", &datoWAMer);
776  }
777 
778  fgetpos(fich, &filepos);
779  fclose(fich);
780 #ifdef usetry
781  } catch(exception & N) {
782  std::cout << "ERROR: TTubo::LeeDatosGeometricoTubo en el tubo: " << FNumeroTubo << std::endl;
783  std::cout << "Tipo de error: " << N.what() << std::endl;
784  throw Exception(N.what());
785  }
786 #endif
787 }
788 
789 // ---------------------------------------------------------------------------
790 // ---------------------------------------------------------------------------
791 
792 void TTubo::CalculoPuntosMalla(double ene) {
793 #ifdef usetry
794  try {
795 #endif
796  double *FLTotalTramo;
797  double xx = 0.;
798 
799  FLTotalTramo = new double[FNTramos + 1];
800 
801  FLTramo[0] = 0.;
802  FLTotalTramo[0] = FLTramo[0];
803 
804  for(int i = 1; i <= FNTramos; i++)
805  FLTotalTramo[i] = FLTotalTramo[i - 1] + FLTramo[i];
806  FLongitudTotal = FLTotalTramo[FNTramos];
807 
808  if(FTipoMallado == nmDistancia)
809  xx = FLongitudTotal / FMallado + 0.5;
810  if(FTipoMallado == nmAngular)
811  xx = FLongitudTotal / 650. / FMallado * 6. * ene + 0.5;
812  if(FTipoMallado != nmDistancia && FTipoMallado != nmAngular) {
813  std::cout << "WARNING: No se ha definido una forma correcta de mallado en el tubo: " << FNumeroTubo << std::endl;
814  }
815 
816  FNin = (int) xx + 1;
817  if(FNin < 3)
818  FNin = 3;
819 
820  FXref = FLongitudTotal / (double)(FNin - 1);
821 
822  int ii = 0;
823  FDiametroTubo = new double[FNin];
824  FArea = new double[FNin];
825  for(int i = 1; i < FNin - 1; i++) {
826  do {
827  ii = ii + 1;
828  } while(FLTotalTramo[ii] < i * FXref);
829  ii = ii - 1;
830  double r1 = i * FXref - FLTotalTramo[ii];
831  FDiametroTubo[i] = Interpola(FDExtTramo[ii], FDExtTramo[ii + 1], FLTramo[ii + 1], r1);
832  FArea[i] = __geom::Circle_area(FDiametroTubo[i]);
833  }
834  FDiametroTubo[0] = FDExtTramo[0];
835  FArea[0] = __geom::Circle_area(FDiametroTubo[0]);
836  FDiametroTubo[FNin - 1] = FDExtTramo[FNTramos];
837  FArea[FNin - 1] = __geom::Circle_area(FDiametroTubo[FNin - 1]);
838 
839  FDiametroD12 = new double[FNin];
840  FDiametroS12 = new double[FNin];
841  FArea12 = new double[FNin];
842  for(int i = 0; i < FNin - 1; i++) {
843  FDiametroD12[i] = (FDiametroTubo[i + 1] + FDiametroTubo[i]) / 2.;
844  FDiametroS12[i] = sqrt((pow2(FDiametroTubo[i + 1]) + pow2(FDiametroTubo[i])) / 2.);
845  FArea12[i] = (FArea[i + 1] + FArea[i]) / 2.;
846  }
847 
848  delete[] FLTotalTramo;
849 #ifdef usetry
850  } catch(exception & N) {
851  std::cout << "ERROR: TTubo::CalculoPuntosMalla en el tubo: " << FNumeroTubo << std::endl;
852  std::cout << "Tipo de error: " << N.what() << std::endl;
853  throw Exception(N.what());
854  }
855 #endif
856 }
857 
858 // ---------------------------------------------------------------------------
859 // ---------------------------------------------------------------------------
860 
862 #ifdef usetry
863  try {
864 #endif
865 
866  for(int i = 0; i < BC[FNodoIzq - 1]->getNumeroTubosCC(); i++) {
867  if(FNumeroTubo == BC[FNodoIzq - 1]->GetTuboExtremo(i).Pipe->getNumeroTubo()) {
868  FTuboCCNodoIzq = i;
869  }
870  }
871 
872  for(int i = 0; i < BC[FNodoDer - 1]->getNumeroTubosCC(); i++) {
873  if(FNumeroTubo == BC[FNodoDer - 1]->GetTuboExtremo(i).Pipe->getNumeroTubo()) {
874  FTuboCCNodoDer = i;
875  }
876  }
877 #ifdef usetry
878  }
879 
880  catch(exception & N) {
881  std::cout << "ERROR: TTubo::ComunicacionTubo_CC en el tubo: " << FNumeroTubo << std::endl;
882  std::cout << "Tipo de error: " << N.what() << std::endl;
883  throw Exception(N.what());
884  }
885 #endif
886 }
887 
888 // ---------------------------------------------------------------------------
889 // ---------------------------------------------------------------------------
890 
891 #ifdef ParticulateFilter
892 
893 void TTubo::ComunicacionDPF(TCondicionContorno **CC, TDeposito **Deposito) {
894  try {
895  int numDeposito = 0;
896  bool PrimeraVez = false;
897 
898  if(FTipoCalcTempPared != nmTempConstante) {
899  FTipoCanal = new int[2];
900  if(CC[FNodoIzq - 1]->getTipoCC() == nmPipeToPlenumConnection) {
901  numDeposito = dynamic_cast<TCCDeposito*>(CC[FNodoIzq - 1])
902  ->getNumeroDeposito();
903  for(int k = 0; k < Deposito[numDeposito - 1]->getNUniones();
904  k++) {
905  if(Deposito[numDeposito - 1]->GetCCDeposito(k)->getUnionDPF
906  () && !PrimeraVez) {
907  FHayDPFNodoIzq = true;
908  FTipoCanal[0] = Deposito[numDeposito - 1]->GetCCDeposito
909  (k)->GetTuboExtremo(0).TipoCanal;
910  FDPFEntradaTubo = Deposito[numDeposito - 1]
911  ->GetCCDeposito(k)->GetTuboExtremo(0).DPF;
912  if(Deposito[numDeposito - 1]->GetCCDeposito(k)
913  ->GetTuboExtremo(0).TipoExtremo == nmLeft) {
914  FNodoDPFEntrada = 0;
915  } else {
916  FNodoDPFEntrada = FDPFEntradaTubo->GetCanal(0, 0)
917  ->getNin() - 1;
918  }
919  PrimeraVez = true;
920  }
921  }
922  }
923  PrimeraVez = false;
924  if(CC[FNodoDer - 1]->getTipoCC() == nmPipeToPlenumConnection) {
925  numDeposito = dynamic_cast<TCCDeposito*>(CC[FNodoDer - 1])
926  ->getNumeroDeposito();
927  for(int k = 0; k < Deposito[numDeposito - 1]->getNUniones();
928  k++) {
929  if(Deposito[numDeposito - 1]->GetCCDeposito(k)->getUnionDPF
930  () && !PrimeraVez) {
931  FHayDPFNodoDer = true;
932  FTipoCanal[1] = Deposito[numDeposito - 1]->GetCCDeposito
933  (k)->GetTuboExtremo(0).TipoCanal;
934  FDPFSalidaTubo = Deposito[numDeposito - 1]
935  ->GetCCDeposito(k)->GetTuboExtremo(0).DPF;
936  if(Deposito[numDeposito - 1]->GetCCDeposito(k)
937  ->GetTuboExtremo(0).TipoExtremo == nmLeft) {
938  FNodoDPFSalida = 0;
939  } else {
940  FNodoDPFSalida = FDPFSalidaTubo->GetCanal(0, 0)
941  ->getNin() - 1;
942  }
943  PrimeraVez = true;
944  }
945  }
946  }
947  }
948 
949  } catch(Exception & N) {
950  std::cout << "ERROR: TTubo::ComunicacionDPF en el Tubo " <<
951  FNumeroTubo << std::endl;
952  std::cout << "Tipo de error: " << N.what() << std::endl;
953  throw Exception(N.what());
954  }
955 }
956 
957 #endif
958 // ---------------------------------------------------------------------------
959 // ---------------------------------------------------------------------------
960 
962 #ifdef usetry
963  try {
964 #endif
965  double RMezclaIni = 0., CpMezclaIni = 0., CvMezclaIni = 0., GammaIni = 0.;
966 
967  FPresion0 = new double[FNin];
968  FAsonido0 = new double[FNin];
969  FVelocidad0 = new double[FNin];
970  FPresion1 = new double[FNin];
971  FAsonido1 = new double[FNin];
972  FVelocidadMedia = new double[FNin];
973  FPresionMedia = new double[FNin];
974  FAsonidoMedia = new double[FNin];
975  FVelocidad1 = new double[FNin];
976 
977  FVelocidadDim = new double[FNin];
978  FAsonidoDim = new double[FNin];
979  FTemperature = new double[FNin];
980  FFlowMass = new double[FNin];
981 
982  FFraccionMasicaEspecie = new double*[FNin];
983  for(int i = 0; i < FNin; i++)
984  FFraccionMasicaEspecie[i] = new double[FNumeroEspecies - FIntEGR];
985  FFraccionMasicaCC = new double*[2];
986  for(int i = 0; i < 2; i++)
987  FFraccionMasicaCC[i] = new double[FNumeroEspecies - FIntEGR];
988  FVelocidadCC = new double[2];
989  FDensidadCC = new double[2];
990  FAreaCC = new double[2];
991  FGamma = new double[FNin];
992  FGamma1 = new double[FNin];
993  FGamma3 = new double[FNin];
994  FGamma4 = new double[FNin];
995  FGamma5 = new double[FNin];
996  FGamma6 = new double[FNin];
997  FRMezcla = new double[FNin];
998 
999  FUt = new double*[3];
1000  for(int i = 0; i < 3; i++)
1001  FUt[i] = new double[FNin];
1002  FU0 = new double*[FNumEcuaciones];
1003  for(int i = 0; i < FNumEcuaciones; i++)
1004  FU0[i] = new double[FNin];
1005  FU0Sum = new double*[FNumEcuaciones];
1006  for(int i = 0; i < FNumEcuaciones; i++)
1007  FU0Sum[i] = new double[FNin];
1008  for(int i = 0; i < FNin; i++) {
1009  for(int k = 0; k < FNumEcuaciones; k++) {
1010  FU0Sum[k][i] = 0;
1011  }
1012  }
1013  FU0Medio = new double*[FNumEcuaciones];
1014  for(int i = 0; i < FNumEcuaciones; i++)
1015  FU0Medio[i] = new double[FNin];
1016  FU1 = new double*[FNumEcuaciones];
1017  for(int i = 0; i < FNumEcuaciones; i++)
1018  FU1[i] = new double[FNin];
1019  FU12 = new double*[FNumEcuaciones];
1020  for(int i = 0; i < FNumEcuaciones; i++)
1021  FU12[i] = new double[FNin];
1022  FW = new double*[FNumEcuaciones];
1023  for(int i = 0; i < FNumEcuaciones; i++)
1024  FW[i] = new double[FNin];
1025  FV1 = new double*[FNumEcuaciones];
1026  for(int i = 0; i < FNumEcuaciones; i++)
1027  FV1[i] = new double[FNin];
1028  FV2 = new double*[FNumEcuaciones];
1029  for(int i = 0; i < FNumEcuaciones; i++)
1030  FV2[i] = new double[FNin];
1031  if(FMod.SubModelo == nmFCT) {
1032  FUfct0 = new double*[FNumEcuaciones];
1033  for(int i = 0; i < FNumEcuaciones; i++)
1034  FUfct0[i] = new double[FNin + 1];
1035  FUfct1 = new double*[FNumEcuaciones];
1036  for(int i = 0; i < FNumEcuaciones; i++)
1037  FUfct1[i] = new double[FNin + 1];
1038  FUfctd = new double*[FNumEcuaciones];
1039  for(int i = 0; i < FNumEcuaciones; i++)
1040  FUfctd[i] = new double[FNin + 1];
1041  FUfctad = new double*[FNumEcuaciones];
1042  for(int i = 0; i < FNumEcuaciones; i++)
1043  FUfctad[i] = new double[FNin + 1];
1044  Ffl = new double*[FNumEcuaciones];
1045  for(int i = 0; i < FNumEcuaciones; i++)
1046  Ffl[i] = new double[FNin + 1];
1047  FdU = new double*[FNumEcuaciones];
1048  for(int i = 0; i < FNumEcuaciones; i++)
1049  FdU[i] = new double[FNin + 1];
1050  FDeltaFCTd = new double*[FNumEcuaciones];
1051  for(int i = 0; i < FNumEcuaciones; i++)
1052  FDeltaFCTd[i] = new double[FNin + 1];
1053  FflU = new double*[FNumEcuaciones];
1054  for(int i = 0; i < FNumEcuaciones; i++)
1055  FflU[i] = new double[FNin + 1];
1056  FaU = new double*[FNumEcuaciones];
1057  for(int i = 0; i < FNumEcuaciones; i++)
1058  FaU[i] = new double[FNin + 1];
1059  }
1060 
1061  Frho = new double[FNin];
1062  FRe = new double[FNin];
1063 
1064  if(FMod.Modelo == nmTVD)
1065  DimensionaTVD();
1066 
1067  FDerLin = new double[FNin - 1];
1068  FDerLin12 = new double[FNin - 1];
1069 
1070  FDerLinArea = new double[FNin - 1];
1071  FDerLinArea12 = new double[FNin - 1];
1072 
1073  FTime0 = 0.;
1074  FTime1 = 0.;
1075  FDeltaTime = 0.;
1076 
1077  for(int i = 0; i < FNin - 1; i++) {
1078  FDerLin[i] = DerLinF(FDiametroTubo[i], FDiametroTubo[i + 1], FXref);
1079  FDerLinArea[i] = DerLinFArea(FArea[i], FArea[i + 1], FXref);
1080  }
1081 
1082  for(int i = 1; i < FNin - 1; i++) {
1083  FDerLin12[i] = DerLinF(FDiametroD12[i], FDiametroD12[i - 1], FXref);
1084  FDerLinArea12[i] = DerLinFArea(FArea12[i - 1], FArea12[i], FXref);
1085  }
1086 
1087  // Calculo de Gamma y R para la composicion inicial.
1088  if(FCalculoEspecies == nmCalculoCompleto) {
1089 
1090  RMezclaIni = CalculoCompletoRMezcla(FComposicionInicial[0], FComposicionInicial[1], FComposicionInicial[2], 0,
1091  FCalculoGamma, nmMEP);
1092  CpMezclaIni = CalculoCompletoCpMezcla(FComposicionInicial[0], FComposicionInicial[1], FComposicionInicial[2], 0,
1093  __units::degCToK(FTini), FCalculoGamma, nmMEP);
1094  GammaIni = CalculoCompletoGamma(RMezclaIni, CpMezclaIni, FCalculoGamma);
1095 
1096  } else if(FCalculoEspecies == nmCalculoSimple) {
1097 
1098  RMezclaIni = CalculoSimpleRMezcla(FComposicionInicial[0], FComposicionInicial[1], FCalculoGamma, nmMEP);
1099  CvMezclaIni = CalculoSimpleCvMezcla(__units::degCToK(FTini), FComposicionInicial[0], FComposicionInicial[1],
1100  FCalculoGamma, nmMEP);
1101  GammaIni = CalculoSimpleGamma(RMezclaIni, CvMezclaIni, FCalculoGamma);
1102 
1103  }
1104 
1105  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
1106  FFraccionMasicaCC[0][j] = FComposicionInicial[j];
1107  FFraccionMasicaCC[1][j] = FComposicionInicial[j];
1108  }
1109 
1110  double viscgas = 1.4615e-6 * pow150(__units::degCToK(FTini)) / (__units::degCToK(FTini) + 110.4);
1111 
1112  for(int i = 0; i < FNin; i++) {
1113 
1114  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
1115  FFraccionMasicaEspecie[i][j] = FComposicionInicial[j];
1116  }
1117  FRMezcla[i] = RMezclaIni;
1118  FGamma[i] = GammaIni;
1119  FGamma1[i] = __Gamma::G1(FGamma[i]);
1120  FGamma3[i] = __Gamma::G3(FGamma[i]);
1121  FGamma4[i] = __Gamma::G4(FGamma[i]);
1122  FGamma5[i] = __Gamma::G5(FGamma[i]);
1123  FGamma6[i] = __Gamma::G6(FGamma[i]);
1124 
1125  FPresion0[i] = FPini;
1126  FTemperature[i] = __units::degCToK(FTini);
1127  FAsonidoDim[i] = sqrt(__units::degCToK(FTini) * FGamma[i] * FRMezcla[i]);
1128  FAsonido0[i] = FAsonidoDim[i] / __cons::ARef;
1129  FVelocidadDim[i] = FVelMedia;
1130  FVelocidad0[i] = FVelMedia / __cons::ARef;
1131  FPresion1[i] = FPini;
1132  FAsonido1[i] = FAsonido0[i];
1133  FVelocidad1[i] = FVelocidad0[i];
1134  FFlowMass[i] = FArea[i] * FVelocidadDim[i] * __units::BarToPa(FPresion0[i]) / FRMezcla[i] / FTemperature[i];
1135 
1136  if(FMod.FormulacionLeyes == nmSinArea) {
1137  Transforma1(FVelocidad0[i], FAsonido0[i], FPresion0[i], FU0, FGamma[i], FGamma1[i], FFraccionMasicaEspecie[i], i);
1138 
1139  Transforma1(FVelocidad1[i], FAsonido1[i], FPresion1[i], FU1, FGamma[i], FGamma1[i], FFraccionMasicaEspecie[i], i);
1140 
1141  Frho[i] = FU0[0][i];
1142  } else if(FMod.FormulacionLeyes == nmConArea) {
1143  Transforma1Area(FVelocidad0[i], FAsonido0[i], FPresion0[i], FU0, FArea[i], FGamma[i], FGamma1[i],
1144  FFraccionMasicaEspecie[i], i);
1145 
1146  Transforma1Area(FVelocidad1[i], FAsonido1[i], FPresion1[i], FU1, FArea[i], FGamma[i], FGamma1[i],
1147  FFraccionMasicaEspecie[i], i);
1148 
1149  Frho[i] = FU0[0][i] / FArea[i];
1150  }
1151 
1152  else {
1153  std::cout << "ERROR: El tipo de formulacion de las leyes de conservacion no esta bien definido" << std::endl;
1154  throw Exception("");
1155  }
1156  FRe[i] = Frho[i] * FVelocidadDim[i] * FDiametroTubo[i] / viscgas;
1157  }
1158 #ifdef usetry
1159  } catch(exception & N) {
1160  std::cout << "ERROR: TTubo::IniciaVariableFundamentalesTubo en el tubo: " << FNumeroTubo << std::endl;
1161  std::cout << "Tipo de error: " << N.what() << std::endl;
1162  throw Exception(N.what());
1163  }
1164 #endif
1165 }
1166 
1167 // ---------------------------------------------------------------------------
1168 // ---------------------------------------------------------------------------
1169 
1171 #ifdef usetry
1172  try {
1173 #endif
1174  for(int i = 0; i < FNin; i++) {
1175  FTemperature[i] = pow2(FAsonidoDim[i]) / (FGamma[i] * FRMezcla[i]);
1176 
1177  // Calculo de Gamma y R a partir de la composicion en cada nodo.
1178  if(FCalculoEspecies == nmCalculoSimple) {
1179 
1180  FRMezcla[i] = CalculoSimpleRMezcla(FFraccionMasicaEspecie[i][0], 0, FCalculoGamma, nmMEP);
1181  double CvMezcla = CalculoSimpleCvMezcla(FTemperature[i], FFraccionMasicaEspecie[i][0], 0, FCalculoGamma, nmMEP);
1182  FGammaN = CalculoSimpleGamma(FRMezcla[i], CvMezcla, FCalculoGamma);
1183  if(abs(FGammaN - FGamma[i]) > 0.025) {
1184  FGamma[i];
1185  } else {
1186  FGamma[i] = 0.9995 * FGamma[i] + 0.0005 * FGammaN;
1187  }
1188  } else {
1189 
1190  FRMezcla[i] = CalculoCompletoRMezcla(FFraccionMasicaEspecie[i][0], FFraccionMasicaEspecie[i][1],
1191  FFraccionMasicaEspecie[i][2], 0, FCalculoGamma, nmMEP);
1192  double CpMezcla = CalculoCompletoCpMezcla(FFraccionMasicaEspecie[i][0], FFraccionMasicaEspecie[i][1],
1193  FFraccionMasicaEspecie[i][2], 0, FTemperature[i], FCalculoGamma, nmMEP);
1194  FGammaN = CalculoCompletoGamma(FRMezcla[i], CpMezcla, FCalculoGamma);
1195  if(abs(FGammaN - FGamma[i]) > 0.025) {
1196  FGamma[i];
1197  } else {
1198  FGamma[i] = 0.9995 * FGamma[i] + 0.0005 * FGammaN;
1199  }
1200 
1201  }
1202 
1203  FGamma1[i] = __Gamma::G1(FGamma[i]);
1204  FGamma3[i] = __Gamma::G3(FGamma[i]);
1205  FGamma4[i] = __Gamma::G4(FGamma[i]);
1206  FGamma5[i] = __Gamma::G5(FGamma[i]);
1207  FGamma6[i] = __Gamma::G6(FGamma[i]);
1208 
1209  Frho[i] = __units::BarToPa(FPresion0[i]) / FRMezcla[i] / FTemperature[i];
1210  }
1211 #ifdef usetry
1212  } catch(exception & N) {
1213  std::cout << "ERROR: TTubo::CalculoPropiedadesGas en el tubo: " << FNumeroTubo << std::endl;
1214  std::cout << "Tipo de error: " << N.what() << std::endl;
1215  throw Exception(N.what());
1216  }
1217 #endif
1218 }
1219 
1220 // ---------------------------------------------------------------------------
1221 // ---------------------------------------------------------------------------
1222 
1223 void TTubo::Transforma1(const double& v, const double& a, const double& p, double **U, const double& Gamma,
1224  const double& Gamma1, double *Yespecie, const int& i) {
1225 #ifdef usetry
1226  try {
1227 #endif
1228  double V = v * __cons::ARef;
1229  double Ppa = __units::BarToPa(p);
1230 
1231  U[0][i] = Gamma * Ppa / pow2(a * __cons::ARef);
1232  U[1][i] = U[0][i] * V;
1233  U[2][i] = Ppa / Gamma1 + U[1][i] * V / 2.0;
1234  for(int j = 3; j < 3 + (FNumeroEspecies - 2); j++) {
1235  U[j][i] = U[0][i] * Yespecie[j - 3];
1236  }
1237  if(FHayEGR)
1238  U[3 + (FNumeroEspecies - 2)][i] = U[0][i] * Yespecie[FNumeroEspecies - 1];
1239 #ifdef usetry
1240  } catch(exception & N) {
1241  std::cout << "ERROR: TTubo::Transforma1 en el tubo: " << FNumeroTubo << std::endl;
1242  std::cout << "Tipo de error: " << N.what() << std::endl;
1243  throw Exception(N.what());
1244  }
1245 #endif
1246 }
1247 
1248 // ---------------------------------------------------------------------------
1249 // ---------------------------------------------------------------------------
1250 
1251 void TTubo::Transforma1Area(const double& v, const double& a, const double& p, double **U, const double& area,
1252  const double& Gamma, const double& Gamma1, double *Yespecie, const int& i) {
1253 #ifdef usetry
1254  try {
1255 #endif
1256  double APpa = area * __units::BarToPa(p);
1257  double V = v * __cons::ARef;
1258 
1259  U[0][i] = Gamma * APpa / pow2(a * __cons::ARef);
1260  U[1][i] = U[0][i] * V;
1261  U[2][i] = APpa / Gamma1 + U[1][i] * V / 2.0;
1262  for(int j = 3; j < 3 + (FNumeroEspecies - 2); j++) {
1263  U[j][i] = U[0][i] * Yespecie[j - 3];
1264  }
1265  if(FHayEGR)
1266  U[3 + (FNumeroEspecies - 2)][i] = U[0][i] * Yespecie[FNumeroEspecies - 1];
1267 
1268 #ifdef usetry
1269  }
1270 
1271  catch(exception & N) {
1272  std::cout << "ERROR: TTubo::Transforma1Area en el tubo: " << FNumeroTubo << std::endl;
1273  std::cout << "Tipo de error: " << N.what() << std::endl;
1274  throw Exception(N.what());
1275  }
1276 #endif
1277 }
1278 
1279 // ---------------------------------------------------------------------------
1280 // ---------------------------------------------------------------------------
1281 
1282 void TTubo::Transforma2(double& v, double& a, double& p, double **U, const double& Gamma, const double& Gamma1,
1283  double *Yespecie, const int& i) {
1284 #ifdef usetry
1285  try {
1286 #endif
1287  double fraccionmasicaacum = 0.;
1288  double V = U[1][i] / U[0][i];
1289  v = V / __cons::ARef;
1290  double P = (U[2][i] - U[1][i] * V / 2.0) * Gamma1;
1291  p = __units::PaToBar(P);
1292  a = sqrt(Gamma * P / U[0][i] / __cons::ARef2);
1293  if(v > 1e200 || v < -1e200) {
1294  std::cout << "ERROR: Valor de velocidad no valido" << std::endl;
1295  throw Exception("Error Velociad");
1296  }
1297  if(p > 1e200 || p < 0) {
1298  std::cout << "ERROR: Valor de presion no valido en el tubo " << FNumeroTubo << " nodo " << i << std::endl;
1299  throw Exception("Error presion");
1300  }
1301  if(a > 1e200 || a < 0) {
1302  std::cout << "ERROR: Valor de velocidad del sonido no valido" << std::endl;
1303  throw Exception("Error velocidad del sonido");
1304  }
1305 
1306  // Solucion del Transporte de Especies Quimicas.
1307  for(int j = 0; j < FNumeroEspecies - 2; j++) {
1308  Yespecie[j] = U[j + 3][i] / U[0][i];
1309  fraccionmasicaacum += Yespecie[j];
1310  }
1311  Yespecie[FNumeroEspecies - 2] = 1. - fraccionmasicaacum;
1312  if(FHayEGR)
1313  Yespecie[FNumeroEspecies - 1] = U[FNumeroEspecies - 2 + 3][i] / U[0][i];
1314 #ifdef usetry
1315  } catch(exception & N) {
1316  std::cout << "ERROR: TTubo::Transforma2 en el tubo: " << FNumeroTubo << std::endl;
1317  std::cout << "Tipo de error: " << N.what() << std::endl;
1318  throw Exception(N.what());
1319  }
1320 #endif
1321 }
1322 
1323 // ---------------------------------------------------------------------------
1324 // ---------------------------------------------------------------------------
1325 
1326 void TTubo::Transforma2Area(double& v, double& a, double& p, double **U, const double& area, const double& Gamma,
1327  const double& Gamma1, double *Yespecie, const int& i) {
1328 #ifdef usetry
1329  try {
1330 #endif
1331  double fraccionmasicaacum = 0.;
1332  if(U[0][i] < 0) {
1333  std::cout << "ERROR: Calculation in pipe " << FNumeroTubo << " is unstable" << std::endl;
1334  if(FMod.Modelo == nmLaxWendroff)
1335  std::cout << " Try to use TVD scheme for this pipe" << std::endl;
1336  else
1337  std::cout << " Check the input data" << std::endl;
1338  throw Exception("ERROR: the pipe calculation is unstable");
1339  }
1340 
1341  double V = U[1][i] / U[0][i];
1342  double P = (U[2][i] - U[1][i] * V / 2.0) * Gamma1;
1343 
1344  v = V / __cons::ARef;
1345  p = __units::PaToBar(P) / area;
1346  a = sqrt(Gamma * P / U[0][i] / __cons::ARef2);
1347 
1348  for(int j = 0; j < FNumeroEspecies - 2; j++) {
1349  Yespecie[j] = U[j + 3][i] / U[0][i];
1350  fraccionmasicaacum += Yespecie[j];
1351  }
1352  Yespecie[FNumeroEspecies - 2] = 1. - fraccionmasicaacum;
1353  if(FHayEGR)
1354  Yespecie[FNumeroEspecies - 1] = U[FNumeroEspecies - 2 + 3][i] / U[0][i];
1355 #ifdef usetry
1356  } catch(exception & N) {
1357  std::cout << "ERROR: TTubo::Transforma2Area en el tubo: " << FNumeroTubo << std::endl;
1358  std::cout << "Tipo de error: " << N.what() << std::endl;
1359  throw Exception(N.what());
1360  }
1361 #endif
1362 }
1363 
1364 // ---------------------------------------------------------------------------
1365 // ---------------------------------------------------------------------------
1366 
1367 void TTubo::Transforma3Area(double **Ufct, double **U, double Area, double Gamma, double Gamma1, double Gamma6, int i) {
1368 #ifdef usetry
1369  try {
1370 #endif
1371 
1372  Ufct[0][i] = U[1][i]; // Massflow
1373  Ufct[1][i] = Gamma * U[2][i] / U[0][i] - pow2(U[1][i]) * Gamma1 / 2. / U[0][i] / U[0][i];
1374  Ufct[2][i] = ((U[2][i] - pow2(U[1][i]) / U[0][i] / 2.) * Gamma1) * pow(
1375  (1. + (Gamma1 / 2.) * pow2(U[1][i]) / U[0][i] / U[0][i] / (Gamma * ((U[2][i] - pow2(
1376  U[1][i]) / U[0][i] / 2.) * Gamma1) / U[0][i])), Gamma * Gamma6) / Area;
1377 
1378  for(int j = 3; j < FNumEcuaciones; j++) {
1379  Ufct[j][i] = U[j][i] * U[1][i] / U[0][i];
1380  // Massflow de cada especie.
1381  }
1382 #ifdef usetry
1383  } catch(exception & N) {
1384  std::cout << "ERROR: TTubo::Transforma3Area en el tubo: " << FNumeroTubo << std::endl;
1385  std::cout << "Tipo de error: " << N.what() << std::endl;
1386  throw Exception(N.what());
1387  }
1388 #endif
1389 }
1390 
1391 // ---------------------------------------------------------------------------
1392 // ---------------------------------------------------------------------------
1393 
1394 void TTubo::Transforma4Area(double **U1, double **Ufctd, double Area, double Gamma, double Gamma1, double Gamma3,
1395  double Gamma4, double Gamma6, int i) {
1396  double error = 0., fu = 0., dfu = 0., vel = 0., vel1 = 0.;
1397  double v, a, p, *Y;
1398  bool peta = false;
1399  // double pruebadefuego1,pruebadefuego2;
1400 #ifdef usetry
1401  try {
1402 #endif
1403 
1404  Y = new double[FNumeroEspecies - 1];
1405  // secante = false;
1406  vel = Ufctd[0][i] / (U1[0][i]);
1407  error = 1.;
1408 
1409  // Newton Raphson
1410  while(error > 0.00000001) {
1411 
1412  fu = vel - Ufctd[0][i] / (Area * Ufctd[2][i] * Gamma4) * pow(2. * Ufctd[1][i],
1413  (Gamma / Gamma1)) * pow((2. * Ufctd[1][i] - pow2(vel)), -Gamma6);
1414 
1415  dfu = 1. - Ufctd[0][i] * vel / (Area * Ufctd[2][i] * Gamma) * pow(2. * Ufctd[1][i],
1416  (Gamma / Gamma1)) * pow((2. * Ufctd[1][i] - pow2(vel)), -Gamma / Gamma1);
1417 
1418  vel1 = vel - fu / dfu;
1419  error = fabs(vel1 - vel);
1420  vel = vel1;
1421  }
1422 
1423  if(!peta) {
1424  v = vel / __cons::ARef;
1425  a = sqrt(Gamma1 * (Ufctd[1][i] - (vel * vel) / 2.)) / __cons::ARef;
1426  p = Ufctd[2][i] / pow((1 + Gamma3 * pow2(v / a)), Gamma / Gamma1) / 1.e5;
1427  for(int j = 0; j < FNumeroEspecies - 1 - FIntEGR; j++) {
1428  if(Ufctd[0][i] != 0.) {
1429  Y[j] = Ufctd[j + 3][i] / Ufctd[0][i];
1430  // Fraccion masica de cada especie.
1431  } else {
1432  Y[j] = FFraccionMasicaEspecie[i][j];
1433  }
1434  }
1435 
1436  Transforma1Area(v, a, p, U1, Area, Gamma, Gamma1, Y, i);
1437  }
1438 
1439  delete[] Y;
1440 #ifdef usetry
1441  } catch(exception & N) {
1442  std::cout << "ERROR: TTubo::Transforma4Area en el tubo: " << FNumeroTubo << std::endl;
1443  std::cout << "Tipo de error: " << N.what() << std::endl;
1444  throw Exception(N.what());
1445  }
1446 #endif
1447 }
1448 
1449 // ---------------------------------------------------------------------------
1450 // ---------------------------------------------------------------------------
1451 
1452 void TTubo::IniciaVariablesTransmisionCalor(TCondicionContorno **BC, TBloqueMotor **Engine, double AmbientTemperature) {
1453  double dist1 = 0., dist2 = 0.;
1454 #ifdef usetry
1455  try {
1456 #endif
1457 
1458  Fhi = new double[FNin];
1459  Fhe = new double[FNin];
1460  FVelPro = new double[FNin];
1461  FCoefTurbulencia = new double[FNin];
1462  FSUMTPTuboPro = new double**[2];
1463  for(int i = 0; i < 2; i++)
1464  FSUMTPTuboPro[i] = new double*[3];
1465  for(int i = 0; i < 2; i++) {
1466  for(int j = 0; j < 3; j++) {
1467  FSUMTPTuboPro[i][j] = new double[FNin];
1468  }
1469  }
1470  FTPTubo = new double*[3];
1471  for(int i = 0; i < 3; i++)
1472  FTPTubo[i] = new double[FNin];
1473  FTParedAnt = new double*[3];
1474  for(int i = 0; i < 3; i++)
1475  FTParedAnt[i] = new double[FNin];
1476 
1477  for(int i = 0; i < FNin; i++) {
1478  dist1 = FXref * (double) i + BC[FNodoIzq - 1]->getPosicionNodo();
1479  dist2 = FXref * (double)(FNin - 1 - i) + BC[FNodoDer - 1]->getPosicionNodo();
1480  if(Minimo(dist1, dist2) >= 10000.)
1481  FCoefTurbulencia[i] = 1.;
1482  else
1483  FCoefTurbulencia[i] = 1. + 3. * exp(-Minimo(dist1, dist2) / (4 * FDiametroTubo[i]));
1484  for(int j = 0; j < 3; j++) {
1485  FTPTubo[j][i] = FTIniParedTub;
1486  FTParedAnt[j][i] = FTIniParedTub;
1487  }
1488  for(int k = 0; k < 2; k++) {
1489  for(int j = 0; j < 3; j++) {
1490  FSUMTPTuboPro[k][j][i] = 0.;
1491  }
1492  }
1493  FVelPro[i] = 5.;
1494  Fhi[i] = 0.;
1495  Fhe[i] = 0.;
1496 
1497  }
1498  if(FTipoCalcTempPared != nmTempConstante) {
1499  if(FTipoTransCal == nmPipaAdmision || FTipoTransCal == nmPipaEscape) {
1500  FTExt = __units::degCToK(Engine[0]->getTempRefrigerante());
1501  } else {
1502  if(FTipRefrig == nmAgua)
1503  FTExt = __units::degCToK(FTRefrigerante);
1504  else
1505  FTExt = __units::degCToK(AmbientTemperature);
1506  }
1507  }
1508 #ifdef usetry
1509  } catch(exception & N) {
1510  std::cout << "ERROR: TTubo::IniciaVariablesTransmisionCalor en el tubo: " << FNumeroTubo << std::endl;
1511  std::cout << "Tipo de error: " << N.what() << std::endl;
1512  throw Exception(N.what());
1513  }
1514 #endif
1515 }
1516 // ---------------------------------------------------------------------------
1517 // ---------------------------------------------------------------------------
1518 
1520  double VTotalMax = 0., VTotalNodo = 0.;
1521 #ifdef usetry
1522  try {
1523 #endif
1524 
1525  VTotalMax = (FAsonidoDim[0] + fabs(FVelocidadDim[0]));
1526  for(int i = 0; i < FNin; i++) {
1527  VTotalNodo = (FAsonidoDim[i] + fabs(FVelocidadDim[i]));
1528  if(VTotalNodo > VTotalMax)
1529  VTotalMax = VTotalNodo;
1530  }
1531  FDeltaTime = FCourant * FXref / VTotalMax;
1532 
1533  if(FMod.Modelo == nmTVD) {
1534  TVD_Estabilidad();
1535  }
1536 
1537  FTime0 = FTime1;
1538  FTime1 = FTime0 + FDeltaTime;
1539 #ifdef usetry
1540  } catch(exception & N) {
1541  std::cout << "ERROR: TTubo::EstabilidadMetodoCalculo en el tubo: " << FNumeroTubo << std::endl;
1542  std::cout << "Tipo de error: " << N.what() << std::endl;
1543  throw Exception(N.what());
1544  }
1545 #endif
1546 }
1547 // ---------------------------------------------------------------------------
1548 // ---------------------------------------------------------------------------
1549 
1551 #ifdef usetry
1552  try {
1553 #endif
1554  if(FMod.Modelo == nmLaxWendroff && FMod.FormulacionLeyes == nmSinArea)
1555  LaxWendroff();
1556  else if(FMod.Modelo == nmLaxWendroff && FMod.FormulacionLeyes == nmConArea) {
1557  LaxWendroffArea();
1558  if(FMod.SubModelo == nmFCT) {
1559  // ReduccionFlujoSubsonicoFCT();
1560  FluxCorrectedTransport();
1561  }
1562  } else if(FMod.Modelo == nmTVD) {
1563  TVD_Limitador();
1564  } else {
1565  std::cout << "ERROR: Metodo de calculo no implementado" << std::endl;
1566  throw Exception("");
1567  }
1568 #ifdef usetry
1569  } catch(exception & N) {
1570  std::cout << "ERROR: TTubo::CalculaVariablesFundamentales en el tubo: " << FNumeroTubo << std::endl;
1571  std::cout << "Tipo de error: " << N.what() << std::endl;
1572  throw Exception(N.what());
1573  }
1574 #endif
1575 }
1576 
1577 // ---------------------------------------------------------------------------
1578 // ---------------------------------------------------------------------------
1579 
1580 void TTubo::LaxWendroff() {
1581 #ifdef usetry
1582  try {
1583 #endif
1584  int Nodos = 0;
1585  double x1, x2, x3, x4, *hi12, *rho12, *Re12, *TPTubo12, *Gamma12, *Rmezcla12, *Gamma1_12;
1586 
1587  hi12 = new double[FNin - 1];
1588  rho12 = new double[FNin - 1];
1589  Re12 = new double[FNin - 1];
1590  TPTubo12 = new double[FNin - 1];
1591  Gamma12 = new double[FNin - 1];
1592  Rmezcla12 = new double[FNin - 1];
1593  Gamma1_12 = new double[FNin - 1];
1594 
1595  double dtdx = FDeltaTime / FXref;
1596  double dt2 = FDeltaTime / 2;
1597 
1598  // Paso Primero
1599  Nodos = FNin;
1600 
1601  CalculaFlujo(FU0, FW, FGamma, FGamma1, Nodos);
1602 
1603  CalculaFuente1(FU0, FV1, FGamma, FGamma1, Nodos);
1604 
1605  CalculaFuente2(FU0, FV2, FDiametroTubo, Fhi, Frho, FRe, FTPTubo[0], FGamma, FRMezcla, FGamma1, Nodos);
1606 
1607  for(int i = 0; i < FNin - 1; i++) {
1608  for(int j = 0; j < FNumEcuaciones; j++) {
1609  x1 = FU0[j][i] + FU0[j][i + 1];
1610  x2 = -dtdx * (FW[j][i + 1] - FW[j][i]);
1611  x3 = -dt2 * (FV1[j][i + 1] + FV1[j][i]) * FDerLin[i];
1612  x4 = -dt2 * (FV2[j][i + 1] + FV2[j][i]);
1613  FU12[j][i] = (x1 + x2 + x3 + x4) / 2;
1614  }
1615  }
1616 
1617  // Paso segundo
1618  for(int i = 0; i < FNin - 1; i++) {
1619  hi12[i] = (Fhi[i] + Fhi[i + 1]) / 2.;
1620  rho12[i] = (Frho[i] + Frho[i + 1]) / 2.;
1621  Re12[i] = (FRe[i] + FRe[i + 1]) / 2.;
1622  TPTubo12[i] = (FTPTubo[0][i] + FTPTubo[0][i + 1]) / 2.;
1623  Gamma12[i] = (FGamma[i] + FGamma[i + 1]) / 2.;
1624  Rmezcla12[i] = (FRMezcla[i] + FRMezcla[i + 1]) / 2.;
1625  Gamma1_12[i] = (FGamma1[i] + FGamma1[i + 1]) / 2.;
1626  }
1627  Nodos = FNin - 1;
1628  CalculaFlujo(FU12, FW, Gamma12, Gamma1_12, Nodos);
1629 
1630  CalculaFuente1(FU12, FV1, Gamma12, Gamma1_12, Nodos);
1631 
1632  CalculaFuente2(FU12, FV2, FDiametroD12, hi12, rho12, Re12, TPTubo12, Gamma12, Rmezcla12, Gamma1_12, Nodos);
1633 
1634  for(int i = 1; i < FNin - 1; i++) {
1635  for(int j = 0; j < FNumEcuaciones; j++) {
1636  x1 = FU0[j][i];
1637  x2 = -dtdx * (FW[j][i] - FW[j][i - 1]);
1638  x3 = -dt2 * (FV1[j][i] + FV1[j][i - 1]) * FDerLin12[i];
1639  x4 = -dt2 * (FV2[j][i] + FV2[j][i - 1]);
1640  FU1[j][i] = x1 + x2 + x3 + x4;
1641  }
1642  }
1643 
1644  // Liberacion de memoria en vectores locales.
1645  delete[] hi12;
1646  delete[] rho12;
1647  delete[] Re12;
1648  delete[] TPTubo12;
1649  delete[] Gamma12;
1650  delete[] Rmezcla12;
1651  delete[] Gamma1_12;
1652 #ifdef usetry
1653  } catch(exception & N) {
1654  std::cout << "ERROR: TTubo::LaxWendrof en el tubo: " << FNumeroTubo << std::endl;
1655  std::cout << "Tipo de error: " << N.what() << std::endl;
1656  throw Exception(N.what());
1657  }
1658 #endif
1659 }
1660 
1661 // ---------------------------------------------------------------------------
1662 // ---------------------------------------------------------------------------
1663 
1664 void TTubo::FluxCorrectedTransport() {
1665  double c1 = 0., c2 = 0., c3 = 0., c4 = 0., sign = 0.;
1666 #ifdef usetry
1667  try {
1668 #endif
1669  if(FNin > 3) {
1670  for(int k = 0; k < FNumEcuaciones; k++) {
1671  FU1[k][0] = FU0[k][0];
1672  FU1[k][FNin - 1] = FU0[k][FNin - 1];
1673  }
1674  // Transformacion de variables
1675  for(int i = 0; i < FNin; i++) {
1676  Transforma3Area(FUfct0, FU0, FArea[i], FGamma[i], FGamma1[i], FGamma6[i], i);
1677 
1678  Transforma3Area(FUfct1, FU1, FArea[i], FGamma[i], FGamma1[i], FGamma6[i], i);
1679 
1680  }
1681 
1682  // Etapa de Difusion
1683  if(FMod.Difusion == nmDamping) {
1684  for(int i = 0; i < FNin - 1; i++) {
1685  for(int k = 0; k < FNumEcuaciones; k++) {
1686  Ffl[k][i] = (FUfct0[k][i + 1] - FUfct0[k][i]) / 8.;
1687  }
1688  }
1689  } else if(FMod.Difusion == nmSmoothing) {
1690  for(int i = 0; i < FNin - 1; i++) {
1691  for(int k = 0; k < FNumEcuaciones; k++) {
1692  Ffl[k][i] = (FUfct1[k][i + 1] - FUfct1[k][i]) / 8.;
1693  }
1694  }
1695  } else {
1696  std::cout << "ERROR: Metodo de Difusion mal definido para el FCT en el tubo n. " << FNumeroTubo << std::endl;
1697  throw Exception("");
1698  }
1699 
1700  for(int i = 1; i < FNin - 1; i++) {
1701  for(int k = 0; k < FNumEcuaciones; k++) {
1702  FdU[k][i] = Ffl[k][i] - Ffl[k][i - 1];
1703  FUfctd[k][i] = FUfct1[k][i] + FdU[k][i];
1704  }
1705  }
1706 
1707  for(int k = 0; k < FNumEcuaciones; k++) {
1708  FUfctd[k][0] = FUfct1[k][0];
1709  FUfctd[k][FNin - 1] = FUfct1[k][FNin - 1];
1710  }
1711 
1712  // Etapa de Antidifusion
1713  if(FMod.Antidifusion == nmExplicit) {
1714  for(int i = 1; i < FNin; i++) {
1715  for(int k = 0; k < FNumEcuaciones; k++) {
1716  FDeltaFCTd[k][i] = FUfctd[k][i] - FUfctd[k][i - 1];
1717  }
1718  }
1719  } else if(FMod.Antidifusion == nmNaive) {
1720  for(int i = 1; i < FNin; i++) {
1721  for(int k = 0; k < FNumEcuaciones; k++) {
1722  FDeltaFCTd[k][i] = FUfct0[k][i] - FUfct0[k][i - 1];
1723  }
1724  }
1725  } else if(FMod.Antidifusion == nmPhoenical) {
1726  for(int i = 1; i < FNin; i++) {
1727  for(int k = 0; k < FNumEcuaciones; k++) {
1728  FDeltaFCTd[k][i] = FUfct1[k][i] - FUfct1[k][i - 1];
1729  }
1730  }
1731  } else {
1732  std::cout << "ERROR: Metodo de Antidifusion mal definido para el FCT en el tubo n. " << FNumeroTubo << std::endl;
1733  throw Exception("");
1734  }
1735 
1736  for(int k = 0; k < FNumEcuaciones; k++) {
1737  FDeltaFCTd[k][0] = FDeltaFCTd[k][1];
1738  FDeltaFCTd[k][FNin] = FDeltaFCTd[k][FNin - 1];
1739  }
1740  for(int i = 1; i < FNin - 2; i++) {
1741  for(int k = 0; k < FNumEcuaciones; k++) {
1742  if(FDeltaFCTd[k][i + 1] >= 0.) {
1743  sign = 1.;
1744  } else {
1745  sign = -1.;
1746  }
1747  c1 = 5. * sign * FDeltaFCTd[k][i] / 8.;
1748  c2 = fabs(FDeltaFCTd[k][i + 1]) / 8.;
1749  c3 = 5. * sign * FDeltaFCTd[k][i + 2] / 8.;
1750  if(c1 < c2)
1751  c4 = c1;
1752  else
1753  c4 = c2;
1754  if(c3 < c4)
1755  c4 = c3;
1756  if(c4 > 0.)
1757  FflU[k][i] = sign * c4;
1758  else
1759  FflU[k][i] = 0.;
1760  }
1761  }
1762 
1763  // PipeEnd Izquierdo
1764  for(int k = 0; k < FNumEcuaciones; k++) {
1765  if(FDeltaFCTd[k][1] >= 0.) {
1766  sign = 1.;
1767  } else {
1768  sign = -1.;
1769  }
1770  c2 = fabs(FDeltaFCTd[k][1]) / 8.;
1771  c3 = 5. * sign * FDeltaFCTd[k][2] / 8.;
1772  if(c2 < c3)
1773  c4 = c2;
1774  else
1775  c4 = c3;
1776  if(c4 > 0.)
1777  FflU[k][0] = sign * c4;
1778  else
1779  FflU[k][0] = 0.;
1780  }
1781  // PipeEnd Derecho
1782  for(int k = 0; k < FNumEcuaciones; k++) {
1783  if(FDeltaFCTd[k][FNin - 2] >= 0.) {
1784  sign = 1.;
1785  } else {
1786  sign = -1.;
1787  }
1788  c1 = 5. * sign * FDeltaFCTd[k][FNin - 2] / 8.;
1789  c2 = fabs(FDeltaFCTd[k][FNin - 1]) / 8.;
1790  if(c1 < c2)
1791  c4 = c1;
1792  else
1793  c4 = c2;
1794  if(c4 > 0.)
1795  FflU[k][FNin - 2] = sign * c4;
1796  else
1797  FflU[k][FNin - 2] = 0.;
1798  }
1799 
1800  for(int i = 1; i < FNin - 1; i++) {
1801  for(int k = 0; k < FNumEcuaciones; k++) {
1802  FaU[k][i] = -FflU[k][i] + FflU[k][i - 1];
1803  FUfctad[k][i] = FUfctd[k][i] + FaU[k][i];
1804  }
1805  Transforma4Area(FU1, FUfctad, FArea[i], FGamma[i], FGamma1[i], FGamma3[i], FGamma4[i], FGamma6[i], i);
1806  }
1807 
1808  }
1809 #ifdef usetry
1810  } catch(exception & N) {
1811  std::cout << "ERROR: TTubo::FluxCorrectedTransport en el tubo: " << FNumeroTubo << std::endl;
1812  std::cout << "Tipo de error: " << N.what() << std::endl;
1813  throw Exception(N.what());
1814  }
1815 #endif
1816 }
1817 
1818 // ---------------------------------------------------------------------------
1819 // ---------------------------------------------------------------------------
1820 
1821 void TTubo::LaxWendroffArea() {
1822 #ifdef usetry
1823  try {
1824 #endif
1825  int Nodos = 0;
1826  double x1, x2, x3, x4, *hi12, *rho12, *Re12, *TPTubo12, *Gamma12, *Rmezcla12, *Gamma1_12;
1827 
1828  hi12 = new double[FNin - 1];
1829  rho12 = new double[FNin - 1];
1830  Re12 = new double[FNin - 1];
1831  TPTubo12 = new double[FNin - 1];
1832  Gamma12 = new double[FNin - 1];
1833  Rmezcla12 = new double[FNin - 1];
1834  Gamma1_12 = new double[FNin - 1];
1835 
1836  double dtdx = FDeltaTime / FXref;
1837  double dt2 = FDeltaTime / 2.;
1838 
1839  // Paso Primero
1840  Nodos = FNin;
1841 
1842  CalculaFlujo(FU0, FW, FGamma, FGamma1, Nodos);
1843 
1844  CalculaFuente1Area(FU0, FV1, FArea, FGamma1, Nodos);
1845 
1846  CalculaFuente2Area(FU0, FV2, FArea, Fhi, Frho, FRe, FTPTubo[0], FGamma, FRMezcla, FGamma1, Nodos);
1847 
1848  for(int i = 0; i < FNin - 1; i++) {
1849  for(int j = 0; j < FNumEcuaciones; j++) {
1850  x1 = (FU0[j][i] + FU0[j][i + 1]);
1851  x2 = -dtdx * (FW[j][i + 1] - FW[j][i]);
1852  x3 = -dt2 * (FV1[j][i + 1] + FV1[j][i]) * FDerLinArea[i];
1853  x4 = -dt2 * (FV2[j][i + 1] + FV2[j][i]);
1854  FU12[j][i] = (x1 + x2 + x3 + x4) / 2.;
1855  }
1856  }
1857 
1858  // Paso segundo
1859  for(int i = 0; i < FNin - 1; i++) {
1860  hi12[i] = (Fhi[i] + Fhi[i + 1]) / 2.;
1861  rho12[i] = (Frho[i] + Frho[i + 1]) / 2.;
1862  Re12[i] = (FRe[i] + FRe[i + 1]) / 2.;
1863  TPTubo12[i] = (FTPTubo[0][i] + FTPTubo[0][i + 1]) / 2.;
1864  Gamma12[i] = (FGamma[i] + FGamma[i + 1]) / 2.;
1865  Rmezcla12[i] = (FRMezcla[i] + FRMezcla[i + 1]) / 2.;
1866  Gamma1_12[i] = (FGamma1[i] + FGamma1[i + 1]) / 2.;
1867  }
1868  Nodos = FNin - 1;
1869  CalculaFlujo(FU12, FW, Gamma12, Gamma1_12, Nodos);
1870 
1871  CalculaFuente1Area(FU12, FV1, FArea12, Gamma1_12, Nodos);
1872 
1873  CalculaFuente2Area(FU12, FV2, FArea12, hi12, rho12, Re12, TPTubo12, Gamma12, Rmezcla12, Gamma1_12, Nodos);
1874 
1875  for(int i = 1; i < FNin - 1; i++) {
1876  for(int j = 0; j < FNumEcuaciones; j++) {
1877  x1 = FU0[j][i];
1878  x2 = -dtdx * (FW[j][i] - FW[j][i - 1]);
1879  x3 = -dt2 * (FV1[j][i] + FV1[j][i - 1]) * FDerLinArea12[i];
1880  x4 = -dt2 * (FV2[j][i] + FV2[j][i - 1]);
1881  FU1[j][i] = x1 + x2 + x3 + x4;
1882  }
1883  }
1884 
1885  // Liberacion de memoria en vectores locales.
1886  delete[] hi12;
1887  delete[] rho12;
1888  delete[] Re12;
1889  delete[] TPTubo12;
1890  delete[] Gamma12;
1891  delete[] Rmezcla12;
1892  delete[] Gamma1_12;
1893 #ifdef usetry
1894  } catch(exception & N) {
1895  std::cout << "ERROR: TTubo::LaxWendroffArea en el tubo: " << FNumeroTubo << std::endl;
1896  std::cout << "Tipo de error: " << N.what() << std::endl;
1897  throw Exception(N.what());
1898  }
1899 #endif
1900 }
1901 
1902 // ---------------------------------------------------------------------------
1903 // ---------------------------------------------------------------------------
1904 
1905 void TTubo::CalculaFlujo(double **U, double **W, double *Gamma, double *Gamma1, int Nodos) {
1906 #ifdef usetry
1907  try
1908 
1909  {
1910 #endif
1911  double U1U0 = 0.;
1912 
1913  for(int i = 0; i < Nodos; i++) {
1914  if(!DoubEqZero(U[1][i])) {
1915  U1U0 = U[1][i] / U[0][i];
1916 
1917  W[0][i] = U[1][i];
1918  W[1][i] = U[2][i] * Gamma1[i] - (Gamma[i] - 3.0) * U[1][i] * U1U0 / 2.;
1919  W[2][i] = Gamma[i] * U[2][i] * U1U0 - Gamma1[i] * U[1][i] * pow2(U1U0) / 2.;
1920  for(int j = 3; j < FNumEcuaciones; j++) {
1921  W[j][i] = U[j][i] * U1U0;
1922  }
1923  } else {
1924  W[0][i] = 0;
1925  W[1][i] = U[2][i] * Gamma1[i];
1926  W[2][i] = 0;
1927  for(int j = 3; j < FNumEcuaciones; j++) {
1928  W[j][i] = 0;
1929  }
1930  }
1931  }
1932 #ifdef usetry
1933  } catch(exception & N) {
1934  std::cout << "ERROR: TTubo::CalculaFlujo en el tubo: " << FNumeroTubo << std::endl;
1935  std::cout << "Tipo de error: " << N.what() << std::endl;
1936  throw Exception(N.what());
1937  }
1938 #endif
1939 }
1940 
1941 // ---------------------------------------------------------------------------
1942 // ---------------------------------------------------------------------------
1943 
1944 void TTubo::CalculaFuente1(double **U, double **V1, double *Gamma, double *Gamma1, int Nodos) {
1945 #ifdef usetry
1946  try {
1947 #endif
1948  double U1U0 = 0.;
1949  for(int i = 0; i < Nodos; i++) {
1950  U1U0 = U[1][i] / U[0][i];
1951 
1952  V1[0][i] = U[1][i];
1953  V1[1][i] = U[1][i] * U1U0;
1954  V1[2][i] = Gamma[i] * U[2][i] * U1U0 - Gamma1[i] * U[1][i] * pow2(U1U0) / 2.;
1955  for(int j = 3; j < FNumEcuaciones; j++) {
1956  V1[j][i] = U[j][i] * U1U0;
1957  }
1958  }
1959 #ifdef usetry
1960  } catch(exception & N) {
1961  std::cout << "ERROR: TTubo::CalculaFuente1 en el tubo: " << FNumeroTubo << std::endl;
1962  std::cout << "Tipo de error: " << N.what() << std::endl;
1963  throw Exception(N.what());
1964  }
1965 #endif
1966 }
1967 
1968 // ---------------------------------------------------------------------------
1969 // ---------------------------------------------------------------------------
1970 
1971 void TTubo::CalculaFuente1Area(double **U, double **V1, double *Area, double *Gamma1, int Nodos) {
1972  double p = 0.;
1973 #ifdef usetry
1974  try {
1975 #endif
1976  for(int i = 0; i < Nodos; i++) {
1977  if(DoubEqZero(U[1][i])) {
1978  p = (U[2][i]) * Gamma1[i] / Area[i];
1979  } else {
1980  p = (U[2][i] - pow2(U[1][i]) / U[0][i] / 2.0) * Gamma1[i] / Area[i];
1981  }
1982 
1983  V1[0][i] = 0.;
1984  V1[1][i] = -p;
1985  V1[2][i] = 0.;
1986  for(int j = 3; j < FNumEcuaciones; j++) {
1987  V1[j][i] = 0.;
1988  }
1989  }
1990 #ifdef usetry
1991  } catch(exception & N) {
1992  std::cout << "ERROR: TTubo::CalculaFuente1Area en el tubo: " << FNumeroTubo << std::endl;
1993  std::cout << "Tipo de error: " << N.what() << std::endl;
1994  throw Exception(N.what());
1995  }
1996 #endif
1997 }
1998 
1999 // ---------------------------------------------------------------------------
2000 // ---------------------------------------------------------------------------
2001 
2002 void TTubo::CalculaFuente2(double **U, double **V2, double *diame, double *hi, double *rho, double *Re,
2003  double *TempParedTubo, double *Gamma, double *Rmezcla, double *Gamma1, int Nodos) {
2004  double v = 0, a = 0., p = 0., tgas = 0., g = 0., q = 0., f = 0.;
2005 #ifdef usetry
2006  try {
2007 #endif
2008  for(int i = 0; i < Nodos; i++) {
2009  /* paso de las variables en funcion de la velocidad,asonido y presion */
2010  v = U[1][i] / U[0][i];
2011  p = (U[2][i] - U[1][i] * v / 2.0) * Gamma1[i];
2012  a = sqrt(Gamma[i] * p / U[0][i]);
2013  if(v > 1e200 || v < -1e200) {
2014  std::cout << "ERROR: Valor de velocidad no valido" << std::endl;
2015  throw Exception("Error Velociad");
2016  }
2017  if(p > 1e200 || p < 0) {
2018  std::cout << "ERROR: Valor de presion no valido en el tubo " << FNumeroTubo << " nodo " << i << std::endl;
2019  throw Exception("Error presion");
2020  }
2021  if(a > 1e200 || a < 0) {
2022  std::cout << "ERROR: Valor de velocidad del sonido no valido" << std::endl;
2023  throw Exception("Error velocidad del sonido");
2024  }
2025 
2026  /* calculo factor friccion */
2027  if(DoubEqZero(v) || DoubEqZero(FCoefAjusFric)) {
2028  g = 0.;
2029  } else {
2030  Colebrook(FFriccion, diame[i], f, Re[i]);
2031  g = f * v * v * v / fabs(v) * 2 / diame[i] * FCoefAjusFric;
2032  }
2033 
2034  /* determinacion factor calor */
2035  if(DoubEqZero(FCoefAjusTC)) {
2036  q = 0.;
2037  } else {
2038  tgas = a * a / (Gamma[i] * Rmezcla[i]);
2039  TransmisionCalor(tgas, diame[i], q, hi[i], rho[i], TempParedTubo[i]);
2040  q = q * FCoefAjusTC;
2041  }
2042 
2043  /* asignacion a V2 */
2044  V2[0][i] = 0.0;
2045  V2[1][i] = U[0][i] * g;
2046  V2[2][i] = -U[0][i] * q;
2047  for(int j = 3; j < FNumEcuaciones; j++) {
2048  V2[j][i] = 0.;
2049  }
2050  }
2051 #ifdef usetry
2052  } catch(exception & N) {
2053  std::cout << "ERROR: TTubo::CalculaFuente1 en el tubo: " << FNumeroTubo << std::endl;
2054  std::cout << "Tipo de error: " << N.what() << std::endl;
2055  throw Exception(N.what());
2056  }
2057 #endif
2058 }
2059 
2060 // ---------------------------------------------------------------------------
2061 // ---------------------------------------------------------------------------
2062 
2063 void TTubo::CalculaFuente2Area(double **U, double **V2, double *Area, double *hi, double *rho, double *Re,
2064  double *TempParedTubo, double *Gamma, double *Rmezcla, double *Gamma1, int Nodos) {
2065  double v = 0., a = 0., pA = 0., tgas = 0., g = 0., q = 0., f = 0.;
2066  double diame = 0.;
2067 #ifdef usetry
2068  try {
2069 #endif
2070  for(int i = 0; i < Nodos; i++) {
2071  /* paso de las variables en funcion de la velocidad,asonido y presion */
2072  v = U[1][i] / U[0][i];
2073  pA = (U[2][i] - U[1][i] * v / 2.0) * Gamma1[i];
2074  a = sqrt(Gamma[i] * pA / U[0][i]);
2075 
2076  diame = sqrt(Area[i] * __cons::_4_Pi);
2077  /* calculo factor friccion */
2078  if(DoubEqZero(v) || DoubEqZero(FCoefAjusFric)) {
2079  g = 0.;
2080  } else {
2081  Colebrook(FFriccion, diame, f, Re[i]);
2082  g = f * v * v * v / fabs(v) * 2 / diame * FCoefAjusFric;
2083  }
2084 
2085  /* determinacion factor calor */
2086  if(DoubEqZero(FCoefAjusTC)) { /* q=0 */
2087  q = 0.;
2088  } else {
2089  tgas = a * a / (Gamma[i] * Rmezcla[i]);
2090  TransmisionCalor(tgas, diame, q, hi[i], rho[i], TempParedTubo[i]);
2091  q = q * FCoefAjusTC;
2092  }
2093 
2094  /* asignacion a V2 */
2095  V2[0][i] = 0.0;
2096  V2[1][i] = U[0][i] * g;
2097  V2[2][i] = -U[0][i] * q;
2098  for(int j = 3; j < FNumEcuaciones; j++) {
2099  V2[j][i] = 0.;
2100  }
2101  }
2102 #ifdef usetry
2103  } catch(exception & N) {
2104  std::cout << "ERROR: TTubo::CalculaFuente1 en el tubo: " << FNumeroTubo << std::endl;
2105  std::cout << "Tipo de error: " << N.what() << std::endl;
2106  throw Exception(N.what());
2107  }
2108 #endif
2109 }
2110 
2111 // ---------------------------------------------------------------------------
2112 // ---------------------------------------------------------------------------
2113 
2114 void TTubo::Colebrook(double rug, double dia, double& f, double Re) {
2115  double temp = 0., temp2 = 0.;
2116 
2117  double pow_approx = 0.;
2118 
2119  if(Re > 2000) {
2120  if(Re > 130000.) {
2121  temp = rug / (3700.0 * dia) + 5.74 / pow(Re, 0.9);
2122  } else if(Re > 50000.) {
2123  // pow(Re, 0.9) approximation between Re = 50000 and Re = 130000
2124  // with less than 0.015 % of error.
2125  pow_approx = 7.04596786e-13 * pow3(Re) - 3.55878012e-07 * pow2(Re) + 3.34536053e-01 * Re + 1.02365893e+03;
2126  temp = rug / (3700.0 * dia) + 5.74 / pow_approx;
2127  } else if(Re > 20000.) {
2128  // pow(Re, 0.9) approximation between Re = 20000 and Re = 50000
2129  // with less than 0.015 % of error.
2130  pow_approx = 5.09028031e-12 * pow3(Re) - 1.00134262e-06 * pow2(Re) + 3.67476796e-01 * Re + 4.40171892e+02;
2131  temp = rug / (3700.0 * dia) + 5.74 / pow_approx;
2132  } else if(Re > 10000.) {
2133  // pow(Re, 0.9) approximation between Re = 10000 and Re = 20000
2134  // with less than 0.015 % of error.
2135  pow_approx = 2.92727184e-11 * pow3(Re) - 2.48693415e-06 * pow2(Re) + 3.98901290e-01 * Re + 2.11628209e+02;
2136  temp = rug / (3700.0 * dia) + 5.74 / pow_approx;
2137  } else if(Re > 4000.) {
2138  // pow(Re, 0.9) approximation between Re = 4000 and Re = 10000
2139  // with less than 0.015 % of error.
2140  pow_approx = 1.49478492e-10 * pow3(Re) - 5.88098006e-06 * pow2(Re) + 4.31645206e-01 * Re + 1.03406848e+02;
2141  temp = rug / (3700.0 * dia) + 5.74 / pow_approx;
2142  } else {
2143  temp = rug / (3700.0 * dia) + 0.00328895476345;
2144  }
2145  if(temp > 0.042) {
2146  temp2 = pow2(log10(temp));
2147  } else if(temp > 0.019) {
2148  // pow2(log10(temp)) approximation between temp = 0.019 and
2149  // temp = 0.042 with less than 0.02 % of error.
2150  temp2 = 6.76495011e+05 * pow4(temp) - 1.07370937e+05 * pow3(temp) + 6.95435632e+03 * pow2(
2151  temp) - 2.44427511e+02 * temp + 5.74410691e+00;
2152  } else if(temp > 0.008) {
2153  // pow2(log10(temp)) approximation between temp = 0.008 and
2154  // temp = 0.019 with less than 0.02 % of error.
2155  temp2 = 2.08516955e+07 * pow4(temp) - 1.46552875e+06 * pow3(temp) + 4.20051994e+04 * pow2(
2156  temp) - 6.58067557e+02 * temp + 7.63733377e+00;
2157  } else if(temp > 0.00329) {
2158  // pow2(log10(temp)) approximation between temp = 0.00329 and
2159  // temp = 0.008 with less than 0.02 % of error.
2160  temp2 = 7.84991530e+08 * pow4(temp) - 2.30952512e+07 * pow3(temp) + 2.77321091e+05 * pow2(
2161  temp) - 1.83296385e+03 * temp + 9.92239603e+00;
2162  } else if(temp > 0.0013) {
2163  // pow2(log10(temp)) approximation between temp = 0.0013 and
2164  // temp = 0.00329 with less than 0.02 % of error.
2165  temp2 = 3.29050277e+10 * pow4(temp) - 3.93727194e+08 * pow3(temp) + 1.92219159e+06 * pow2(
2166  temp) - 5.18844300e+03 * temp + 1.25952908e+01;
2167  } else if(temp > 0.0005) {
2168  // pow2(log10(temp)) approximation between temp = 0.0005 and
2169  // temp = 0.0013 with less than 0.02 % of error.
2170  temp2 = 1.57146781e+12 * pow4(temp) - 7.37699295e+09 * pow3(temp) + 1.41288296e+07 * pow2(
2171  temp) - 1.50182432e+04 * temp + 1.56956366e+01;
2172  } else if(temp > 0.00019) {
2173  // pow2(log10(temp)) approximation between temp = 0.00019 and
2174  // temp = 0.0005 with less than 0.02 % of error.
2175  temp2 = 8.09890844e+13 * pow4(temp) - 1.45825030e+11 * pow3(temp) + 1.07169184e+08 * pow2(
2176  temp) - 4.38671762e+04 * temp + 1.92059658e+01;
2177  } else if(temp > 0.00007) {
2178  // pow2(log10(temp)) approximation between temp = 0.00007 and
2179  // temp = 0.00019 with less than 0.02 % of error.
2180  temp2 = 4.47104917e+15 * pow4(temp) - 3.03334424e+12 * pow3(temp) + 8.39454836e+08 * pow2(
2181  temp) - 1.29630353e+05 * temp + 2.31540981e+01;
2182  } else {
2183  temp2 = pow2(log10(temp));
2184  }
2185  f = 0.0625 / temp2;
2186  } else if(Re > 1) {
2187  f = 32. / Re;
2188  } else {
2189  f = 32.;
2190  }
2191 }
2192 
2193 // ---------------------------------------------------------------------------
2194 // ---------------------------------------------------------------------------
2195 
2196 void TTubo::TransmisionCalor(double tgas, double diametro, double& q, double hi, double rho, double Tw) {
2197 #ifdef usetry
2198  try {
2199 #endif
2200 
2201  if(hi != 0) {
2202  q = 4. * hi * (__units::degCToK(Tw) - tgas) / rho / diametro;
2203  } else
2204  q = 0.;
2205 #ifdef usetry
2206  } catch(exception & N) {
2207  std::cout << "ERROR: TTubo::TransmisionCalor en el tubo: " << FNumeroTubo << std::endl;
2208  std::cout << "Tipo de error: " << N.what() << std::endl;
2209  throw Exception(N.what());
2210  }
2211 #endif
2212 }
2213 
2214 // ---------------------------------------------------------------------------
2215 // ---------------------------------------------------------------------------
2216 
2217 inline double TTubo::DerLinF(double d1, double d2, double xref) {
2218  // double dm,ret_val;
2219 #ifdef usetry
2220  try {
2221 #endif
2222 
2223  return 2. * (d2 - d1) / ((d1 + d2) / 2.0) / xref;
2224 
2225 #ifdef usetry
2226  } catch(exception & N) {
2227  std::cout << "ERROR: TTubo::DerLinF en el tubo: " << FNumeroTubo << std::endl;
2228  std::cout << "Tipo de error: " << N.what() << std::endl;
2229  throw Exception(N.what());
2230  }
2231 #endif
2232 }
2233 
2234 // ---------------------------------------------------------------------------
2235 // ---------------------------------------------------------------------------
2236 
2237 inline double TTubo::DerLinFArea(double area1, double area2, double xref) {
2238 
2239 #ifdef usetry
2240  try {
2241 #endif
2242  return (area2 - area1) / xref;
2243 
2244 #ifdef usetry
2245  } catch(exception & N) {
2246  std::cout << "ERROR: TTubo::DerLinFArea en el tubo: " << FNumeroTubo << std::endl;
2247  std::cout << "Tipo de error: " << N.what() << std::endl;
2248  throw Exception(N.what());
2249  }
2250 #endif
2251 }
2252 
2253 // ---------------------------------------------------------------------------
2254 // ---------------------------------------------------------------------------
2255 
2257 #ifdef usetry
2258  try {
2259 #endif
2260 
2261  double a = 0., v = 0., p = 0.;
2262  double LandaIzq = 0., BetaIzq = 0., EntropiaIzq = 0.;
2263  double LandaDer = 0., BetaDer = 0., EntropiaDer = 0.;
2264  double *YIzq, *YDer;
2265 
2266  YIzq = new double[FNumeroEspecies - FIntEGR];
2267  YDer = new double[FNumeroEspecies - FIntEGR];
2268 
2269  LandaIzq = BC[FNodoIzq - 1]->GetTuboExtremo(FTuboCCNodoIzq).Landa;
2270  BetaIzq = BC[FNodoIzq - 1]->GetTuboExtremo(FTuboCCNodoIzq).Beta;
2271  EntropiaIzq = BC[FNodoIzq - 1]->GetTuboExtremo(FTuboCCNodoIzq).Entropia;
2272 
2273  TransformaContorno(LandaIzq, BetaIzq, EntropiaIzq, a, v, p, 1, FGamma1[0], FGamma3[0], FGamma4[0], FGamma5[0]);
2274  if(BC[FNodoIzq - 1]->getTipoCC() == nmBranch) {
2275  if(v < 0.) {
2276  for(int i = 0; i < FNumeroEspecies - FIntEGR; i++) {
2277  YIzq[i] = FFraccionMasicaCC[0][i];
2278  }
2279  } else {
2280  for(int i = 0; i < FNumeroEspecies - FIntEGR; i++) {
2281  YIzq[i] = BC[FNodoIzq - 1]->GetFraccionMasicaEspecie(i);
2282  }
2283  }
2284  } else {
2285  for(int i = 0; i < FNumeroEspecies - FIntEGR; i++) {
2286  YIzq[i] = BC[FNodoIzq - 1]->GetFraccionMasicaEspecie(i);
2287  }
2288  }
2289 
2290  if(FMod.FormulacionLeyes == nmSinArea)
2291  Transforma1(v, a, p, FU1, FGamma[0], FGamma1[0], YIzq, 0);
2292  else if(FMod.FormulacionLeyes == nmConArea)
2293  Transforma1Area(v, a, p, FU1, FArea[0], FGamma[0], FGamma1[0], YIzq, 0);
2294 
2295  LandaDer = BC[FNodoDer - 1]->GetTuboExtremo(FTuboCCNodoDer).Landa;
2296  BetaDer = BC[FNodoDer - 1]->GetTuboExtremo(FTuboCCNodoDer).Beta;
2297  EntropiaDer = BC[FNodoDer - 1]->GetTuboExtremo(FTuboCCNodoDer).Entropia;
2298 
2299  TransformaContorno(LandaDer, BetaDer, EntropiaDer, a, v, p, 1, FGamma1[FNin - 1], FGamma3[FNin - 1], FGamma4[FNin - 1],
2300  FGamma5[FNin - 1]);
2301  if(BC[FNodoDer - 1]->getTipoCC() == nmBranch) {
2302  if(v > 0.) {
2303  for(int i = 0; i < FNumeroEspecies - FIntEGR; i++) {
2304  YDer[i] = FFraccionMasicaCC[1][i];
2305  }
2306  } else {
2307  for(int i = 0; i < FNumeroEspecies - FIntEGR; i++) {
2308  YDer[i] = BC[FNodoDer - 1]->GetFraccionMasicaEspecie(i);
2309  }
2310  }
2311  } else {
2312  for(int i = 0; i < FNumeroEspecies - FIntEGR; i++) {
2313  YDer[i] = BC[FNodoDer - 1]->GetFraccionMasicaEspecie(i);
2314  }
2315  }
2316 
2317  if(FMod.FormulacionLeyes == nmSinArea)
2318  Transforma1(v, a, p, FU1, FGamma[FNin - 1], FGamma1[FNin - 1], YDer, FNin - 1);
2319  else if(FMod.FormulacionLeyes == nmConArea)
2320  Transforma1Area(v, a, p, FU1, FArea[FNin - 1], FGamma[FNin - 1], FGamma1[FNin - 1], YDer, FNin - 1);
2321 
2322  if(FMod.FormulacionLeyes == nmSinArea) {
2323  for(int i = 0; i < FNin; i++) {
2324  Transforma2(FVelocidad0[i], FAsonido0[i], FPresion0[i], FU1, FGamma[i], FGamma1[i], FFraccionMasicaEspecie[i], i);
2325  for(int k = 0; k < FNumEcuaciones; k++) {
2326  FU0[k][i] = FU1[k][i];
2327  }
2328  FVelocidadDim[i] = FVelocidad0[i] * __cons::ARef;
2329  FAsonidoDim[i] = FAsonido0[i] * __cons::ARef;
2330  FFlowMass[i] = FU0[1][i] * FArea[i];
2331  }
2332  } else if(FMod.FormulacionLeyes == nmConArea) {
2333  for(int i = 0; i < FNin; i++) {
2334  Transforma2Area(FVelocidad0[i], FAsonido0[i], FPresion0[i], FU1, FArea[i], FGamma[i], FGamma1[i],
2335  FFraccionMasicaEspecie[i], i);
2336  for(int k = 0; k < FNumEcuaciones; k++) {
2337  FU0[k][i] = FU1[k][i];
2338  }
2339  FVelocidadDim[i] = FVelocidad0[i] * __cons::ARef;
2340  FAsonidoDim[i] = FAsonido0[i] * __cons::ARef;
2341  FFlowMass[i] = FU0[1][i];
2342  if(FVelocidadDim[i] > FAsonidoDim[i] + 1.0e-10) {
2343  printf("Supersonic flow in pipe: %d node: %d, Mach = %lf\n", FNumeroTubo, i, FVelocidadDim[i] / FAsonidoDim[i]);
2344  }
2345 
2346  }
2347  }
2348 
2349  delete[] YIzq;
2350  delete[] YDer;
2351 #ifdef usetry
2352  }
2353 
2354  catch(exception & N) {
2355  std::cout << "ERROR: TTubo::ValoresDeContorno tubo: " << FNumeroTubo << std::endl;
2356  std::cout << "Tipo de error: " << N.what() << std::endl;
2357  throw Exception(N.what());
2358  }
2359 #endif
2360 }
2361 // ---------------------------------------------------------------------------
2362 // ---------------------------------------------------------------------------
2363 
2364 void TTubo::TransformaContorno(double& L, double& B, double& E, double& a, double& v, double& p, const int& modo,
2365  const double& Gamma1, const double& Gamma3, const double& Gamma4, const double& Gamma5) {
2366 #ifdef usetry
2367  try {
2368 #endif
2369  if(modo == 0) {
2370  L = (a + Gamma3 * v);
2371  B = (a - Gamma3 * v);
2372  E = a / pow(p, Gamma5);
2373  } else {
2374  a = (L + B) / 2.;
2375  v = (L - B) / Gamma1;
2376  p = pow(a / E, Gamma4);
2377  }
2378 #ifdef usetry
2379  } catch(exception & N) {
2380  std::cout << "ERROR: TTubo::TransformaContorno en el tubo: " << FNumeroTubo << std::endl;
2381  std::cout << "Tipo de error: " << N.what() << std::endl;
2382  throw Exception(N.what());
2383  }
2384 #endif
2385 }
2386 
2387 // ---------------------------------------------------------------------------
2388 // ---------------------------------------------------------------------------
2389 
2391  double Machx = 0., Machy = 0., Velocidady = 0., Sonidoy = 0.;
2392 #ifdef usetry
2393  try {
2394 #endif
2395 
2396  for(int i = 0; i < FNin; i++) {
2397  Machx = FVelocidad0[i] / FAsonido0[i];
2398  if(-1. >= Machx || Machx > 1.) {
2399  Machy = Machx / fabs(Machx) * sqrt((pow2(Machx) + 2. / FGamma1[i]) / (FGamma4[i] * pow2(Machx) - 1.));
2400  Sonidoy = FAsonido0[i] * sqrt((FGamma1[i] / 2. * pow2(Machx) + 1.) / (FGamma1[i] / 2. * pow2(Machy) + 1.));
2401 
2402  Velocidady = Sonidoy * Machy;
2403  FAsonido0[i] = Sonidoy;
2404  FVelocidad0[i] = Velocidady;
2405  }
2406  }
2407 #ifdef usetry
2408  } catch(exception & N) {
2409  std::cout << "ERROR: TTubo::ReduccionFlujoSubsonico en el tubo: " << FNumeroTubo << std::endl;
2410  std::cout << "Tipo de error: " << N.what() << std::endl;
2411  throw Exception(N.what());
2412  }
2413 #endif
2414 }
2415 
2416 // ---------------------------------------------------------------------------
2417 // ---------------------------------------------------------------------------
2418 
2420  double Machx = 0., Machy = 0., Velocidady = 0., Sonidoy = 0.;
2421  double velocidad = 0., asonido = 0., presion = 0.;
2422 #ifdef usetry
2423  try {
2424 #endif
2425 
2426  for(int i = 1; i < FNin - 1; i++) {
2427  velocidad = FU1[1][i] / FU1[0][i] / __cons::ARef;
2428  presion = __units::PaToBar((FU1[2][i] - FU1[1][i] * velocidad * __cons::ARef / 2.0) * FGamma1[i] / FArea[i]);
2429  asonido = sqrt(FGamma[i] * __units::BarToPa(presion) * FArea[i] / FU1[0][i] / __cons::ARef2);
2430  Machx = velocidad / asonido;
2431  if(-1. >= Machx || Machx > 1.) {
2432  Machy = Machx / fabs(Machx) * sqrt((pow2(Machx) + 2. / FGamma1[i]) / (FGamma4[i] * pow2(Machx) - 1.));
2433  Sonidoy = asonido * sqrt((FGamma1[i] / 2. * pow2(Machx) + 1.) / (FGamma1[i] / 2. * pow2(Machy) + 1.));
2434 
2435  Velocidady = Sonidoy * Machy;
2436  asonido = Sonidoy;
2437  velocidad = Velocidady;
2438  FU1[0][i] = FGamma[i] * __units::BarToPa(presion) / pow2(asonido * __cons::ARef) * FArea[i];
2439  FU1[1][i] = FU1[0][i] * velocidad * __cons::ARef;
2440  FU1[2][i] = FArea[i] * __units::BarToPa(presion) / FGamma1[i] + FU1[1][i] * velocidad * __cons::ARef / 2.0;
2441 
2442  }
2443  }
2444 #ifdef usetry
2445  } catch(exception & N) {
2446  std::cout << "ERROR: TTubo::ReduccionFlujoSubsonicoFCT en el tubo: " << FNumeroTubo << std::endl;
2447  std::cout << "Tipo de error: " << N.what() << std::endl;
2448  throw Exception(N.what());
2449  }
2450 #endif
2451 }
2452 
2453 // ---------------------------------------------------------------------------
2454 // ---------------------------------------------------------------------------
2455 
2456 void TTubo::ReadAverageResultsTubo(const char *FileWAM, fpos_t &filepos, bool HayMotor) {
2457  int NumVars = 0, TipoVar = 0;
2458 #ifdef usetry
2459  try {
2460 #endif
2461 
2462  FILE *fich = fopen(FileWAM, "r");
2463  fsetpos(fich, &filepos);
2464 
2465  fscanf(fich, "%d ", &FNumResMedios);
2466  ResultadosMedios = new stResMediosTubo[FNumResMedios];
2467  FTiempoMedSUM = 0.;
2468  FControlResMed = 1;
2469 
2470  for(int i = 0; i < FNumResMedios; i++) {
2471  ResultadosMedios[i].TemperaturaGas = false;
2472  ResultadosMedios[i].TemperaturaGasSUM = 0.;
2473  ResultadosMedios[i].TemperaturaGasMED = 0;
2474  ResultadosMedios[i].Pressure = false;
2475  ResultadosMedios[i].PresionSUM = 0.;
2476  ResultadosMedios[i].PresionMED = 0.;
2477  ResultadosMedios[i].Velocity = false;
2478  ResultadosMedios[i].VelocidadSUM = 0.;
2479  ResultadosMedios[i].VelocidadMED = 0.;
2480  ResultadosMedios[i].Massflow = false;
2481  ResultadosMedios[i].GastoSUM = 0.;
2482  ResultadosMedios[i].GastoMED = 0.;
2483  ResultadosMedios[i].TemperaturaInternaPared = false;
2484  ResultadosMedios[i].TemperaturaInternaParedSUM = 0.;
2485  ResultadosMedios[i].TemperaturaInternaParedMED = 0.;
2486  ResultadosMedios[i].TemperaturaIntermediaPared = false;
2487  ResultadosMedios[i].TemperaturaIntermediaParedSUM = 0.;
2488  ResultadosMedios[i].TemperaturaIntermediaParedMED = 0.;
2489  ResultadosMedios[i].TemperaturaExternaPared = false;
2490  ResultadosMedios[i].TemperaturaExternaParedSUM = 0.;
2491  ResultadosMedios[i].TemperaturaExternaParedMED = 0.;
2492  ResultadosMedios[i].NITmedio = false;
2493  ResultadosMedios[i].NITmedioSUM = 0;
2494  ResultadosMedios[i].NITmedioMED = 0;
2495  ResultadosMedios[i].CoefPelInterior = false;
2496  ResultadosMedios[i].CoefPelInteriorSUM = 0.;
2497  ResultadosMedios[i].CoefPelInteriorMED = 0.;
2498  ResultadosMedios[i].FraccionMasicaEspecies = false;
2499  ResultadosMedios[i].FraccionSUM = new double[FNumeroEspecies - FIntEGR];
2500  ResultadosMedios[i].FraccionMED = new double[FNumeroEspecies - FIntEGR];
2501  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
2502  ResultadosMedios[i].FraccionSUM[j] = 0.;
2503  ResultadosMedios[i].FraccionMED[j] = 0.;
2504  }
2505  ResultadosMedios[i].PonderacionSUM = 0.;
2506  ResultadosMedios[i].GastoPonderacionSUM = 0.;
2507 
2508  fscanf(fich, "%lf %d ", &ResultadosMedios[i].Distancia, &NumVars);
2509 
2510  for(int j = 0; j < NumVars; j++) {
2511  fscanf(fich, "%d ", &TipoVar);
2512  switch(TipoVar) {
2513  case 0:
2514  ResultadosMedios[i].TemperaturaGas = true;
2515  break;
2516  case 1:
2517  ResultadosMedios[i].Pressure = true;
2518  break;
2519  case 2:
2520  ResultadosMedios[i].Velocity = true;
2521  break;
2522  case 3:
2523  ResultadosMedios[i].Massflow = true;
2524  break;
2525  case 4:
2526  ResultadosMedios[i].TemperaturaInternaPared = true;
2527  break;
2528  case 5:
2529  ResultadosMedios[i].TemperaturaIntermediaPared = true;
2530  break;
2531  case 6:
2532  ResultadosMedios[i].TemperaturaExternaPared = true;
2533  break;
2534  case 7:
2535  ResultadosMedios[i].NITmedio = true;
2536  if(!HayMotor) {
2537  std::cout << "ERROR: No puedes pedir el NIT como resultado si no hay motor" << std::endl;
2538  throw Exception(" ");
2539  }
2540  break;
2541  case 8:
2542  ResultadosMedios[i].CoefPelInterior = true;
2543  break;
2544  case 9:
2545  ResultadosMedios[i].FraccionMasicaEspecies = true;
2546  break;
2547  default:
2548  std::cout << "WARNING: El tipo de variable seleccionada para la salida de resultados medios no es valida" << std::endl;
2549  };
2550 
2551  }
2552 
2553  }
2554 
2555  fgetpos(fich, &filepos);
2556  fclose(fich);
2557 #ifdef usetry
2558  } catch(exception & N) {
2559  std::cout << "ERROR: TTubo::ReadAverageResults en el tubo: " << FNumeroTubo << std::endl;
2560  std::cout << "Tipo de error: " << N.what() << std::endl;
2561  throw Exception(N.what());
2562  }
2563 #endif
2564 }
2565 
2566 // ---------------------------------------------------------------------------
2567 // ---------------------------------------------------------------------------
2568 
2569 void TTubo::HeaderAverageResults(stringstream& medoutput, stEspecies *DatosEspecies) const {
2570 #ifdef usetry
2571  try {
2572 #endif
2573 
2574  std::string Label;
2575  std::ostringstream TextDist;
2576  TextDist.precision(8);
2577 
2578  for(int i = 0; i < FNumResMedios; i++) {
2579  TextDist << ResultadosMedios[i].Distancia;
2580 
2581  if(ResultadosMedios[i].TemperaturaGas) {
2582  Label = "\t" + PutLabel(303) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2583  910);
2584  medoutput << Label.c_str();
2585  }
2586  if(ResultadosMedios[i].Pressure) {
2587  Label = "\t" + PutLabel(301) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2588  908);
2589  medoutput << Label.c_str();
2590  }
2591  if(ResultadosMedios[i].Velocity) {
2592  Label = "\t" + PutLabel(302) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2593  909);
2594  medoutput << Label.c_str();
2595  }
2596  if(ResultadosMedios[i].Massflow) {
2597  Label = "\t" + PutLabel(304) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2598  904);
2599  medoutput << Label.c_str();
2600  }
2601  if(ResultadosMedios[i].TemperaturaInternaPared) {
2602  Label = "\t" + PutLabel(310) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2603  910);
2604  medoutput << Label.c_str();
2605  }
2606  if(ResultadosMedios[i].TemperaturaIntermediaPared) {
2607  Label = "\t" + PutLabel(311) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2608  910);
2609  medoutput << Label.c_str();
2610  }
2611  if(ResultadosMedios[i].TemperaturaExternaPared) {
2612  Label = "\t" + PutLabel(312) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2613  910);
2614  medoutput << Label.c_str();
2615  }
2616  if(ResultadosMedios[i].NITmedio) {
2617  Label = "\t" + PutLabel(309) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2618  903);
2619  medoutput << Label.c_str();
2620  }
2621  if(ResultadosMedios[i].CoefPelInterior) {
2622  Label = "\t" + PutLabel(313) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2623  911);
2624  medoutput << Label.c_str();
2625  }
2626  if(ResultadosMedios[i].FraccionMasicaEspecies) {
2627  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
2628  Label = "\t" + PutLabel(314) + DatosEspecies[j].Nombre + PutLabel(318) + std::to_string(FNumeroTubo) + PutLabel(
2629  316) + TextDist.str() + PutLabel(317) + PutLabel(901);
2630  medoutput << Label.c_str();
2631  }
2632  }
2633  }
2634 
2635 #ifdef usetry
2636  } catch(exception & N) {
2637  std::cout << "ERROR: TTubo::HeaderAverageResults en el tubo: " << FNumeroTubo << std::endl;
2638  std::cout << "Tipo de error: " << N.what() << std::endl;
2639  throw Exception(N.what());
2640  }
2641 #endif
2642 }
2643 
2644 // ---------------------------------------------------------------------------
2645 // ---------------------------------------------------------------------------
2646 
2647 void TTubo::ImprimeResultadosMedios(stringstream& medoutput) const {
2648 #ifdef usetry
2649  try {
2650 #endif
2651 
2652  // FILE *fich=fopen(FileSALIDA,"a");
2653 
2654  for(int i = 0; i < FNumResMedios; i++) {
2655  if(ResultadosMedios[i].TemperaturaGas)
2656  medoutput << "\t" << __units::KTodegC(ResultadosMedios[i].TemperaturaGasMED);
2657  if(ResultadosMedios[i].Pressure)
2658  medoutput << "\t" << ResultadosMedios[i].PresionMED;
2659  if(ResultadosMedios[i].Velocity)
2660  medoutput << "\t" << ResultadosMedios[i].VelocidadMED;
2661  if(ResultadosMedios[i].Massflow)
2662  medoutput << "\t" << ResultadosMedios[i].GastoMED;
2663  if(ResultadosMedios[i].TemperaturaInternaPared)
2664  medoutput << "\t" << ResultadosMedios[i].TemperaturaInternaParedMED;
2665  if(ResultadosMedios[i].TemperaturaIntermediaPared)
2666  medoutput << "\t" << ResultadosMedios[i].TemperaturaIntermediaParedMED;
2667  if(ResultadosMedios[i].TemperaturaExternaPared)
2668  medoutput << "\t" << ResultadosMedios[i].TemperaturaExternaParedMED;
2669  if(ResultadosMedios[i].NITmedio)
2670  medoutput << "\t" << ResultadosMedios[i].NITmedioMED;
2671  if(ResultadosMedios[i].CoefPelInterior)
2672  medoutput << "\t" << ResultadosMedios[i].CoefPelInteriorMED;
2673  if(ResultadosMedios[i].FraccionMasicaEspecies) {
2674  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
2675  medoutput << "\t" << ResultadosMedios[i].FraccionMED[j];
2676  }
2677  }
2678  }
2679 
2680 #ifdef usetry
2681  } catch(exception & N) {
2682  std::cout << "ERROR: TTubo::ResultadosMedios en el tubo: " << FNumeroTubo << std::endl;
2683  std::cout << "Tipo de error: " << N.what() << std::endl;
2684  throw Exception(N.what());
2685  }
2686 #endif
2687 }
2688 
2689 // ---------------------------------------------------------------------------
2690 // ---------------------------------------------------------------------------
2691 void TTubo::ReadInstantaneousResultsTubo(const char *FileWAM, fpos_t &filepos, bool HayMotor) {
2692  int NumVars = 0, TipoVar = 0;
2693 #ifdef usetry
2694  try {
2695 #endif
2696 
2697  FILE *fich = fopen(FileWAM, "r");
2698  fsetpos(fich, &filepos);
2699 
2700  fscanf(fich, "%d ", &FNumResInstant); // Puntos del tubo en los que se piden resultados instantaneos
2701  ResultInstantaneos = new stResInstantTubo[FNumResInstant];
2702 
2703  for(int i = 0; i < FNumResInstant; i++) {
2704  ResultInstantaneos[i].Pressure = false;
2705  ResultInstantaneos[i].PresionINS = 0.;
2706  ResultInstantaneos[i].Velocity = false;
2707  ResultInstantaneos[i].VelocidadINS = 0.;
2708  ResultInstantaneos[i].TemperaturaGas = false;
2709  ResultInstantaneos[i].TemperaturaGasINS = 0.;
2710  ResultInstantaneos[i].FlujoMasico = false;
2711  ResultInstantaneos[i].FlujoMasicoINS = 0.;
2712  ResultInstantaneos[i].VelocidadDerecha = false;
2713  ResultInstantaneos[i].VelocidadDerechaINS = 0.;
2714  ResultInstantaneos[i].VelocidadIzquierda = false;
2715  ResultInstantaneos[i].VelocidadIzquierdaINS = 0.;
2716  ResultInstantaneos[i].PresionDerecha = false;
2717  ResultInstantaneos[i].PresionDerechaINS = 0.;
2718  ResultInstantaneos[i].PresionIzquierda = false;
2719  ResultInstantaneos[i].PresionIzquierdaINS = 0.;
2720  ResultInstantaneos[i].NIT = false;
2721  ResultInstantaneos[i].NITINS = 0.;
2722  ResultInstantaneos[i].TemperaturaInternaPared = false;
2723  ResultInstantaneos[i].TemperaturaInternaParedINS = 0.;
2724  ResultInstantaneos[i].TemperaturaIntermediaPared = false;
2725  ResultInstantaneos[i].TemperaturaIntermediaParedINS = 0.;
2726  ResultInstantaneos[i].TemperaturaExternaPared = false;
2727  ResultInstantaneos[i].TemperaturaExternaParedINS = 0.;
2728  ResultInstantaneos[i].CoefPelInterior = false;
2729  ResultInstantaneos[i].CoefPelInteriorINS = 0.;
2730  ResultInstantaneos[i].FraccionMasicaEspecies = false;
2731  ResultInstantaneos[i].FraccionINS = new double[FNumeroEspecies - FIntEGR];
2732  ResultInstantaneos[i].Gamma = false;
2733  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
2734  ResultInstantaneos[i].FraccionINS[j] = 0.;
2735  }
2736 
2737  fscanf(fich, "%lf %d ", &ResultInstantaneos[i].Distancia, &NumVars);
2738 
2739  for(int j = 0; j < NumVars; j++) {
2740  fscanf(fich, "%d ", &TipoVar);
2741  switch(TipoVar) {
2742  case 0:
2743  ResultInstantaneos[i].Pressure = true;
2744  break;
2745  case 1:
2746  ResultInstantaneos[i].Velocity = true;
2747  break;
2748  case 2:
2749  ResultInstantaneos[i].TemperaturaGas = true;
2750  break;
2751  case 3:
2752  ResultInstantaneos[i].FlujoMasico = true;
2753  break;
2754  case 4:
2755  ResultInstantaneos[i].VelocidadDerecha = true;
2756  break;
2757  case 5:
2758  ResultInstantaneos[i].VelocidadIzquierda = true;
2759  break;
2760  case 6:
2761  ResultInstantaneos[i].PresionDerecha = true;
2762  break;
2763  case 7:
2764  ResultInstantaneos[i].PresionIzquierda = true;
2765  break;
2766  case 8:
2767  ResultInstantaneos[i].NIT = true;
2768  if(!HayMotor) {
2769  std::cout << "ERROR: No puedes pedir el NIT como resultado si no hay motor" << std::endl;
2770  throw Exception(" ");
2771  }
2772  break;
2773  case 9:
2774  ResultInstantaneos[i].TemperaturaInternaPared = true;
2775  break;
2776  case 10:
2777  ResultInstantaneos[i].TemperaturaIntermediaPared = true;
2778  break;
2779  case 11:
2780  ResultInstantaneos[i].TemperaturaExternaPared = true;
2781  break;
2782  case 12:
2783  ResultInstantaneos[i].CoefPelInterior = true;
2784  break;
2785  case 13:
2786  ResultInstantaneos[i].FraccionMasicaEspecies = true;
2787  break;
2788  case 14:
2789  ResultInstantaneos[i].Gamma = true;
2790  break;
2791  default:
2792  std::cout << "WARNING: El tipo de variable seleccionada para la salida de resultados instantaneos no es valida" <<
2793  std::endl;
2794  }
2795  }
2796  }
2797 
2798  fgetpos(fich, &filepos);
2799  fclose(fich);
2800 #ifdef usetry
2801  } catch(exception & N) {
2802  std::cout << "ERROR: TTubo::ReadInstantaneousResults en el tubo: " << FNumeroTubo << std::endl;
2803  std::cout << "Tipo de error: " << N.what() << std::endl;
2804  throw Exception(N.what());
2805  }
2806 #endif
2807 }
2808 
2809 // ---------------------------------------------------------------------------
2810 // ---------------------------------------------------------------------------
2811 
2812 void TTubo::HeaderInstantaneousResults(stringstream& insoutput, stEspecies *DatosEspecies) const {
2813 #ifdef usetry
2814  try {
2815 #endif
2816 
2817  std::string Label;
2818  std::ostringstream TextDist;
2819  TextDist.precision(8);
2820 
2821  for(int i = 0; i < FNumResInstant; i++) {
2822  TextDist << ResultInstantaneos[i].Distancia;
2823  if(ResultInstantaneos[i].Pressure) {
2824  Label = "\t" + PutLabel(301) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2825  908);
2826  insoutput << Label.c_str();
2827  }
2828  if(ResultInstantaneos[i].Velocity) {
2829  Label = "\t" + PutLabel(302) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2830  909);
2831  insoutput << Label.c_str();
2832  }
2833  if(ResultInstantaneos[i].TemperaturaGas) {
2834  Label = "\t" + PutLabel(303) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2835  910);
2836  insoutput << Label.c_str();
2837  }
2838  if(ResultInstantaneos[i].FlujoMasico) {
2839  Label = "\t" + PutLabel(304) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2840  904);
2841  insoutput << Label.c_str();
2842  }
2843  if(ResultInstantaneos[i].VelocidadDerecha) {
2844  Label = "\t" + PutLabel(305) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2845  909);
2846  insoutput << Label.c_str();
2847  }
2848  if(ResultInstantaneos[i].VelocidadIzquierda) {
2849  Label = "\t" + PutLabel(306) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2850  909);
2851  insoutput << Label.c_str();
2852  }
2853  if(ResultInstantaneos[i].PresionDerecha) {
2854  Label = "\t" + PutLabel(307) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2855  908);
2856  insoutput << Label.c_str();
2857  }
2858  if(ResultInstantaneos[i].PresionIzquierda) {
2859  Label = "\t" + PutLabel(308) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2860  908);
2861  insoutput << Label.c_str();
2862  }
2863  if(ResultInstantaneos[i].NIT) {
2864  Label = "\t" + PutLabel(309) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2865  903);
2866  insoutput << Label.c_str();
2867  }
2868  if(ResultInstantaneos[i].TemperaturaInternaPared) {
2869  Label = "\t" + PutLabel(310) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2870  910);
2871  insoutput << Label.c_str();
2872  }
2873  if(ResultInstantaneos[i].TemperaturaIntermediaPared) {
2874  Label = "\t" + PutLabel(311) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2875  910);
2876  insoutput << Label.c_str();
2877  }
2878  if(ResultInstantaneos[i].TemperaturaExternaPared) {
2879  Label = "\t" + PutLabel(312) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2880  910);
2881  insoutput << Label.c_str();
2882  }
2883  if(ResultInstantaneos[i].CoefPelInterior) {
2884  Label = "\t" + PutLabel(313) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2885  911);
2886  insoutput << Label.c_str();
2887  }
2888  if(ResultInstantaneos[i].FraccionMasicaEspecies) {
2889  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
2890  Label = "\t" + PutLabel(314) + DatosEspecies[j].Nombre + PutLabel(318) + std::to_string(FNumeroTubo) + PutLabel(
2891  316) + TextDist.str() + PutLabel(317) + PutLabel(901);
2892  insoutput << Label.c_str();
2893  }
2894  }
2895  if(ResultInstantaneos[i].Gamma) {
2896  Label = "\t" + PutLabel(315) + std::to_string(FNumeroTubo) + PutLabel(316) + TextDist.str() + PutLabel(317) + PutLabel(
2897  901);
2898  insoutput << Label.c_str();
2899  }
2900  }
2901 
2902 #ifdef usetry
2903  } catch(exception & N) {
2904  std::cout << "ERROR: TTubo::HeaderInstantaneousResults en el tubo nº: " << FNumeroTubo << std::endl;
2905  std::cout << "Tipo de error: " << N.what() << std::endl;
2906  throw Exception(N.what());
2907  }
2908 #endif
2909 }
2910 
2911 // ---------------------------------------------------------------------------
2912 // ---------------------------------------------------------------------------
2913 
2914 void TTubo::ImprimeResultadosInstantaneos(stringstream& insoutput) const {
2915 #ifdef usetry
2916  try {
2917 #endif
2918 
2919  for(int i = 0; i < FNumResInstant; i++) {
2920  if(ResultInstantaneos[i].Pressure)
2921  insoutput << "\t" << ResultInstantaneos[i].PresionINS;
2922  if(ResultInstantaneos[i].Velocity)
2923  insoutput << "\t" << ResultInstantaneos[i].VelocidadINS;
2924  if(ResultInstantaneos[i].TemperaturaGas)
2925  insoutput << "\t" << ResultInstantaneos[i].TemperaturaGasINS;
2926  if(ResultInstantaneos[i].FlujoMasico)
2927  insoutput << "\t" << ResultInstantaneos[i].FlujoMasicoINS;
2928  if(ResultInstantaneos[i].VelocidadDerecha)
2929  insoutput << "\t" << ResultInstantaneos[i].VelocidadDerechaINS;
2930  if(ResultInstantaneos[i].VelocidadIzquierda)
2931  insoutput << "\t" << ResultInstantaneos[i].VelocidadIzquierdaINS;
2932  if(ResultInstantaneos[i].PresionDerecha)
2933  insoutput << "\t" << ResultInstantaneos[i].PresionDerechaINS;
2934  if(ResultInstantaneos[i].PresionIzquierda)
2935  insoutput << "\t" << ResultInstantaneos[i].PresionIzquierdaINS;
2936  if(ResultInstantaneos[i].NIT)
2937  insoutput << "\t" << ResultInstantaneos[i].NITINS;
2938  if(ResultInstantaneos[i].TemperaturaInternaPared)
2939  insoutput << "\t" << ResultInstantaneos[i].TemperaturaInternaParedINS;
2940  if(ResultInstantaneos[i].TemperaturaIntermediaPared)
2941  insoutput << "\t" << ResultInstantaneos[i].TemperaturaIntermediaParedINS;
2942  if(ResultInstantaneos[i].TemperaturaExternaPared)
2943  insoutput << "\t" << ResultInstantaneos[i].TemperaturaExternaParedINS;
2944  if(ResultInstantaneos[i].CoefPelInterior)
2945  insoutput << "\t" << ResultInstantaneos[i].CoefPelInteriorINS;
2946  if(ResultInstantaneos[i].FraccionMasicaEspecies) {
2947  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
2948  insoutput << "\t" << ResultInstantaneos[i].FraccionINS[j];
2949  }
2950  }
2951  if(ResultInstantaneos[i].Gamma)
2952  insoutput << "\t" << ResultInstantaneos[i].GammaINS;
2953 
2954  }
2955 
2956 #ifdef usetry
2957  } catch(exception & N) {
2958  std::cout << "ERROR: TTubo::ResultadosInstantaneos en el tubo nº: " << FNumeroTubo << std::endl;
2959  std::cout << "Tipo de error: " << N.what() << std::endl;
2960  throw Exception(N.what());
2961  }
2962 #endif
2963 }
2964 
2965 // ---------------------------------------------------------------------------
2966 // ---------------------------------------------------------------------------
2967 
2969  double dist = 0., Vble = 0., d = 0., Rmezcla = 0., Gamma = 0., GastoPonderacion = 0.;
2970  int n1 = 0, n2 = 0;
2971 #ifdef usetry
2972  try {
2973 #endif
2974 
2975  FTiempoMedSUM += FDeltaTime;
2976 
2977  for(int i = 0; i < FNumResMedios; i++) {
2978  dist = ResultadosMedios[i].Distancia / FXref;
2979  n1 = (int) floor(dist);
2980  if(n1 >= FNin - 1) {
2981  if(ResultadosMedios[i].TemperaturaGas || ResultadosMedios[i].FraccionMasicaEspecies) {
2982  GastoPonderacion = fabs(FFlowMass[FNin - 1]);
2983  ResultadosMedios[i].PonderacionSUM += FFlowMass[FNin - 1] * FDeltaTime;
2984  ResultadosMedios[i].GastoPonderacionSUM += GastoPonderacion;
2985  }
2986  if(ResultadosMedios[i].TemperaturaGas)
2987  ResultadosMedios[i].TemperaturaGasSUM += (FTemperature[FNin - 1]) * GastoPonderacion;
2988  if(ResultadosMedios[i].Pressure)
2989  ResultadosMedios[i].PresionSUM += FPresion0[FNin - 1] * FDeltaTime;
2990  if(ResultadosMedios[i].Velocity)
2991  ResultadosMedios[i].VelocidadSUM += FVelocidadDim[FNin - 1] * FDeltaTime;
2992  if(ResultadosMedios[i].Massflow) {
2993  ResultadosMedios[i].GastoSUM += FFlowMass[i] * FDeltaTime;
2994  }
2995  if(ResultadosMedios[i].TemperaturaInternaPared)
2996  ResultadosMedios[i].TemperaturaInternaParedSUM += FTPTubo[0][FNin - 1] * FDeltaTime;
2997  if(ResultadosMedios[i].TemperaturaIntermediaPared)
2998  ResultadosMedios[i].TemperaturaIntermediaParedSUM += FTPTubo[1][FNin - 1] * FDeltaTime;
2999  if(ResultadosMedios[i].TemperaturaExternaPared)
3000  ResultadosMedios[i].TemperaturaExternaParedSUM += FTPTubo[2][FNin - 1] * FDeltaTime;
3001  if(ResultadosMedios[i].NITmedio) {
3002  double nit = CalculaNIT(FAsonido0[FNin - 1], FVelocidad0[FNin - 1], FPresion0[FNin - 1], FDiametroTubo[FNin - 1],
3003  FGamma[FNin - 1], FRMezcla[FNin - 1]);
3004  ResultadosMedios[i].NITmedioSUM += nit * FDeltaTime;
3005  }
3006  if(ResultadosMedios[i].CoefPelInterior) {
3007  ResultadosMedios[i].CoefPelInteriorSUM += Fhi[FNin - 1] * FDeltaTime;
3008  }
3009  if(ResultadosMedios[i].FraccionMasicaEspecies) {
3010  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
3011  ResultadosMedios[i].FraccionSUM[j] += FFraccionMasicaEspecie[FNin - 1][j] * GastoPonderacion * FDeltaTime;
3012  }
3013  }
3014  } else {
3015  n2 = n1 + 1;
3016  d = dist - (double) n1;
3017 
3018  if(ResultadosMedios[i].TemperaturaGas || ResultadosMedios[i].FraccionMasicaEspecies) {
3019  GastoPonderacion = fabs(Interpola(FFlowMass[n1], FFlowMass[n2], 1., d));
3020  ResultadosMedios[i].GastoPonderacionSUM += GastoPonderacion;
3021  ResultadosMedios[i].PonderacionSUM += GastoPonderacion * FDeltaTime;
3022  }
3023 
3024  if(ResultadosMedios[i].TemperaturaGas)
3025  Vble = Interpola(FTemperature[n1], FTemperature[n2], 1., d);
3026  ResultadosMedios[i].TemperaturaGasSUM += Vble * GastoPonderacion;
3027  if(ResultadosMedios[i].Pressure) {
3028  Vble = Interpola(FPresion0[n1], FPresion0[n2], 1., d);
3029  ResultadosMedios[i].PresionSUM += Vble * FDeltaTime;
3030  }
3031  if(ResultadosMedios[i].Velocity) {
3032  Vble = Interpola(FVelocidad0[n1], FVelocidad0[n2], 1., d);
3033  ResultadosMedios[i].VelocidadSUM += Vble * __cons::ARef * FDeltaTime;
3034  }
3035  if(ResultadosMedios[i].Massflow) {
3036  Vble = Interpola(FFlowMass[n1], FFlowMass[n2], 1., d);
3037  ResultadosMedios[i].GastoSUM += Vble * FDeltaTime;
3038  }
3039  if(ResultadosMedios[i].TemperaturaInternaPared) {
3040  Vble = Interpola(FTPTubo[0][n1], FTPTubo[0][n2], 2., d);
3041  ResultadosMedios[i].TemperaturaInternaParedSUM += Vble * FDeltaTime;
3042  }
3043  if(ResultadosMedios[i].TemperaturaIntermediaPared) {
3044  Vble = Interpola(FTPTubo[1][n1], FTPTubo[1][n2], 2., d);
3045  ResultadosMedios[i].TemperaturaIntermediaParedSUM += Vble * FDeltaTime;
3046  }
3047  if(ResultadosMedios[i].TemperaturaExternaPared) {
3048  Vble = Interpola(FTPTubo[2][n1], FTPTubo[2][n2], 2., d);
3049  ResultadosMedios[i].TemperaturaExternaParedSUM += Vble * FDeltaTime;
3050  }
3051  if(ResultadosMedios[i].NITmedio) {
3052  double a = Interpola(FAsonido0[n1], FAsonido0[n2], 1., d);
3053  double v = Interpola(FVelocidad0[n1], FVelocidad0[n2], 1., d);
3054  double p = Interpola(FPresion0[n1], FPresion0[n2], 1., d);
3055  double diam = Interpola(FDiametroTubo[n1], FDiametroTubo[n2], 1., d);
3056  Gamma = Interpola(FGamma[n1], FGamma[n2], 1., d);
3057  Rmezcla = Interpola(FRMezcla[n1], FRMezcla[n2], 1., d);
3058  double nit = CalculaNIT(a, v, p, diam, Gamma, Rmezcla);
3059  ResultadosMedios[i].NITmedioSUM += nit * FDeltaTime;
3060  }
3061  if(ResultadosMedios[i].CoefPelInterior) {
3062  Vble = Interpola(Fhi[n1], Fhi[n2], 1., d);
3063  ResultadosMedios[i].CoefPelInteriorSUM += Vble * FDeltaTime;
3064  }
3065  if(ResultadosMedios[i].FraccionMasicaEspecies) {
3066  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
3067  Vble = Interpola(FFraccionMasicaEspecie[n1][j], FFraccionMasicaEspecie[n2][j], 1., d);
3068  ResultadosMedios[i].FraccionSUM[j] += Vble * GastoPonderacion * FDeltaTime;
3069  }
3070  }
3071 
3072  }
3073  }
3074 
3075  if(Theta > FControlResMed * FAnguloTotalCiclo) {
3076 
3077  for(int i = 0; i < FNumResMedios; i++) {
3078  if(ResultadosMedios[i].Pressure) {
3079  ResultadosMedios[i].PresionMED = ResultadosMedios[i].PresionSUM / FTiempoMedSUM;
3080  ResultadosMedios[i].PresionSUM = 0.;
3081  }
3082  if(ResultadosMedios[i].TemperaturaGas) {
3083  if(ResultadosMedios[i].GastoPonderacionSUM != 0)
3084  ResultadosMedios[i].TemperaturaGasMED = ResultadosMedios[i].TemperaturaGasSUM / ResultadosMedios[i].GastoPonderacionSUM;
3085  else
3086  ResultadosMedios[i].TemperaturaGasMED = 0;
3087  ResultadosMedios[i].TemperaturaGasSUM = 0.;
3088  ResultadosMedios[i].GastoPonderacionSUM = 0.;
3089  }
3090  if(ResultadosMedios[i].Velocity) {
3091  ResultadosMedios[i].VelocidadMED = ResultadosMedios[i].VelocidadSUM / FTiempoMedSUM;
3092  ResultadosMedios[i].VelocidadSUM = 0.;
3093  }
3094  if(ResultadosMedios[i].Massflow) {
3095  ResultadosMedios[i].GastoMED = ResultadosMedios[i].GastoSUM / FTiempoMedSUM;
3096  ResultadosMedios[i].GastoSUM = 0.;
3097  }
3098  if(ResultadosMedios[i].TemperaturaInternaPared) {
3099  ResultadosMedios[i].TemperaturaInternaParedMED = ResultadosMedios[i].TemperaturaInternaParedSUM / FTiempoMedSUM;
3100  ResultadosMedios[i].TemperaturaInternaParedSUM = 0.;
3101  }
3102  if(ResultadosMedios[i].TemperaturaIntermediaPared) {
3103  ResultadosMedios[i].TemperaturaIntermediaParedMED = ResultadosMedios[i].TemperaturaIntermediaParedSUM / FTiempoMedSUM;
3104  ResultadosMedios[i].TemperaturaIntermediaParedSUM = 0.;
3105  }
3106  if(ResultadosMedios[i].TemperaturaExternaPared) {
3107  ResultadosMedios[i].TemperaturaExternaParedMED = ResultadosMedios[i].TemperaturaExternaParedSUM / FTiempoMedSUM;
3108  ResultadosMedios[i].TemperaturaExternaParedSUM = 0.;
3109  }
3110  if(ResultadosMedios[i].NITmedio) {
3111  ResultadosMedios[i].NITmedioMED = ResultadosMedios[i].NITmedioSUM / FTiempoMedSUM;
3112  ResultadosMedios[i].NITmedioSUM = 0.;
3113  }
3114  if(ResultadosMedios[i].CoefPelInterior) {
3115  ResultadosMedios[i].CoefPelInteriorMED = ResultadosMedios[i].CoefPelInteriorSUM / FTiempoMedSUM;
3116  ResultadosMedios[i].CoefPelInteriorSUM = 0.;
3117  }
3118  if(ResultadosMedios[i].FraccionMasicaEspecies) {
3119  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
3120  if(DoubEqZero(ResultadosMedios[i].PonderacionSUM)) {
3121  ResultadosMedios[i].FraccionMED[j] = 0.;
3122  } else {
3123  ResultadosMedios[i].FraccionMED[j] = ResultadosMedios[i].FraccionSUM[j] / ResultadosMedios[i].PonderacionSUM;
3124  }
3125  ResultadosMedios[i].FraccionSUM[j] = 0.;
3126  }
3127  ResultadosMedios[i].PonderacionSUM = 0.;
3128  }
3129  }
3130  FTiempoMedSUM = 0.;
3131  FControlResMed = FControlResMed + 1.;
3132  }
3133 #ifdef usetry
3134  } catch(exception & N) {
3135  std::cout << "ERROR: TTubo::CalculaResultadosMedios en el tubo: " << FNumeroTubo << std::endl;
3136  std::cout << "Tipo de error: " << N.what() << std::endl;
3137  throw Exception(N.what());
3138  }
3139 #endif
3140 }
3141 
3142 // ---------------------------------------------------------------------------
3143 // ---------------------------------------------------------------------------
3144 
3146  double dist = 0., d = 0., ason = 0., vel = 0., Aa = 0., ason1 = 0., vel1 = 0., Aa1 = 0., ason2 = 0., vel2 = 0.,
3147  Aa2 = 0.;
3148  int n1 = 0, n2 = 0;
3149 #ifdef usetry
3150  try {
3151 #endif
3152 
3153  if(FNumResInstant != 0) {
3154  for(int i = 0; i < FNumResInstant; i++) {
3155  dist = ResultInstantaneos[i].Distancia / FXref;
3156  n1 = (int) floor(dist);
3157  if(n1 >= FNin - 1) {
3158  if(ResultInstantaneos[i].Pressure)
3159  ResultInstantaneos[i].PresionINS = FPresion0[FNin - 1];
3160  if(ResultInstantaneos[i].Velocity)
3161  ResultInstantaneos[i].VelocidadINS = FVelocidad0[FNin - 1] * __cons::ARef;
3162  if(ResultInstantaneos[i].TemperaturaGas) {
3163  double temp = __units::KTodegC(pow2(FAsonido0[FNin - 1] * __cons::ARef) / (FGamma[FNin - 1] * FRMezcla[FNin - 1]));
3164  ResultInstantaneos[i].TemperaturaGasINS = temp;
3165  }
3166  if(ResultInstantaneos[i].FlujoMasico) {
3167  ResultInstantaneos[i].FlujoMasicoINS = FFlowMass[FNin - 1];
3168  }
3169  if(ResultInstantaneos[i].VelocidadDerecha || ResultInstantaneos[i].VelocidadIzquierda
3170  || ResultInstantaneos[i].PresionDerecha || ResultInstantaneos[i].PresionIzquierda) {
3171  ason = FAsonidoDim[FNin - 1];
3172  vel = FGamma1[FNin - 1] / 2 * FVelocidadDim[FNin - 1];
3173  Aa = ason / pow(FPresion0[FNin - 1], FGamma5[FNin - 1]);
3174  }
3175  if(ResultInstantaneos[i].VelocidadDerecha) {
3176  double VelDer = ((ason + vel) - Aa) / FGamma1[FNin - 1];
3177  ResultInstantaneos[i].VelocidadDerechaINS = VelDer;
3178  }
3179  if(ResultInstantaneos[i].VelocidadIzquierda) {
3180  double VelIzq = -((ason - vel) - Aa) / FGamma1[FNin - 1];
3181  ResultInstantaneos[i].VelocidadIzquierdaINS = VelIzq;
3182  }
3183  if(ResultInstantaneos[i].PresionDerecha) {
3184  double PreDer = pow(((ason + vel) / Aa + 1) / 2., FGamma4[FNin - 1]);
3185  ResultInstantaneos[i].PresionDerechaINS = PreDer;
3186  }
3187  if(ResultInstantaneos[i].PresionIzquierda) {
3188  double PreIzq = pow(((ason - vel) / Aa + 1) / 2., FGamma4[FNin - 1]);
3189  ResultInstantaneos[i].PresionIzquierdaINS = PreIzq;
3190  }
3191  if(ResultInstantaneos[i].NIT) {
3192  double nit = CalculaNIT(FAsonido0[FNin - 1], FVelocidad0[FNin - 1], FPresion0[FNin - 1], FDiametroTubo[FNin - 1],
3193  FGamma[FNin - 1], FRMezcla[FNin - 1]);
3194  ResultInstantaneos[i].NITINS = nit;
3195  }
3196  if(ResultInstantaneos[i].TemperaturaInternaPared)
3197  ResultInstantaneos[i].TemperaturaInternaParedINS = FTPTubo[0][FNin - 1];
3198  if(ResultInstantaneos[i].TemperaturaIntermediaPared)
3199  ResultInstantaneos[i].TemperaturaIntermediaParedINS = FTPTubo[1][FNin - 1];
3200  if(ResultInstantaneos[i].TemperaturaExternaPared)
3201  ResultInstantaneos[i].TemperaturaExternaParedINS = FTPTubo[2][FNin - 1];
3202  if(ResultInstantaneos[i].CoefPelInterior)
3203  ResultInstantaneos[i].CoefPelInteriorINS = Fhi[FNin - 1];
3204  if(ResultInstantaneos[i].FraccionMasicaEspecies) {
3205  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
3206  ResultInstantaneos[i].FraccionINS[j] = FFraccionMasicaEspecie[FNin - 1][j];
3207  }
3208  }
3209  if(ResultInstantaneos[i].Gamma)
3210  ResultInstantaneos[i].GammaINS = FGamma[FNin - 1];
3211  } else {
3212  n2 = n1 + 1;
3213  d = dist - (double) n1;
3214  if(ResultInstantaneos[i].Pressure) {
3215  double pres = Interpola(FPresion0[n1], FPresion0[n2], 1., d);
3216  ResultInstantaneos[i].PresionINS = pres;
3217  }
3218  if(ResultInstantaneos[i].Velocity) {
3219  double vel = Interpola(FVelocidadDim[n1], FVelocidadDim[n2], 1., d);
3220  ResultInstantaneos[i].VelocidadINS = vel;
3221  }
3222  if(ResultInstantaneos[i].TemperaturaGas) {
3223  double temp1 = FTemperature[n1];
3224  double temp2 = FTemperature[n2];
3225  double temp = Interpola(temp1, temp2, 1., d);
3226  ResultInstantaneos[i].TemperaturaGasINS = __units::KTodegC(temp);
3227  }
3228  if(ResultInstantaneos[i].FlujoMasico) {
3229  // double area1=pow(FDiametroTubo[n1],2)*__cons::Pi_4;
3230  // double dens1=FGamma[n1]*FPresion0[n1]*1e5/pow(FAsonido0[n1]*__cons::ARef,2.);
3231  double gto1 = FFlowMass[n1];
3232  // double area2=pow(FDiametroTubo[n2],2)*__cons::Pi_4;
3233  // double dens2=FGamma[n2]*FPresion0[n2]*1e5/pow(FAsonido0[n2]*__cons::ARef,2.);
3234  double gto2 = FFlowMass[n2];
3235  double gto = Interpola(gto1, gto2, 1., d);
3236  ResultInstantaneos[i].FlujoMasicoINS = gto;
3237  }
3238  if(ResultInstantaneos[i].VelocidadDerecha || ResultInstantaneos[i].VelocidadIzquierda
3239  || ResultInstantaneos[i].PresionDerecha || ResultInstantaneos[i].PresionIzquierda) {
3240  ason1 = FAsonidoDim[n1];
3241  vel1 = FGamma1[n1] / 2 * FVelocidadDim[n1];
3242  Aa1 = ason1 / pow(FPresion0[n1], FGamma5[n1]);
3243  ason2 = FAsonidoDim[n2];
3244  vel2 = FGamma1[n2] / 2 * FVelocidadDim[n2];
3245  Aa2 = ason2 / pow(FPresion0[n2], FGamma5[n2]);
3246  }
3247  if(ResultInstantaneos[i].VelocidadDerecha) {
3248  double VelDer1 = ((ason1 + vel1) - Aa1) / FGamma1[n1];
3249  double VelDer2 = ((ason2 + vel2) - Aa2) / FGamma1[n2];
3250  double VelDer = Interpola(VelDer1, VelDer2, 1., d);
3251  ResultInstantaneos[i].VelocidadDerechaINS = VelDer;
3252  }
3253  if(ResultInstantaneos[i].VelocidadIzquierda) {
3254  double VelIzq1 = -((ason1 - vel1) - Aa1) / FGamma1[n1];
3255  double VelIzq2 = -((ason2 - vel2) - Aa2) / FGamma1[n2];
3256  double VelIzq = Interpola(VelIzq1, VelIzq2, 1., d);
3257  ResultInstantaneos[i].VelocidadIzquierdaINS = VelIzq;
3258  }
3259  if(ResultInstantaneos[i].PresionDerecha) {
3260  double PreDer1 = pow(((ason1 + vel1) / Aa1 + 1) / 2., FGamma4[n1]);
3261  double PreDer2 = pow(((ason2 + vel2) / Aa2 + 1) / 2., FGamma4[n2]);
3262  double PreDer = Interpola(PreDer1, PreDer2, 1., d);
3263  ResultInstantaneos[i].PresionDerechaINS = PreDer;
3264  }
3265  if(ResultInstantaneos[i].PresionIzquierda) {
3266  double PreIzq1 = pow(((ason1 - vel1) / Aa1 + 1) / 2., FGamma4[n1]);
3267  double PreIzq2 = pow(((ason2 - vel2) / Aa2 + 1) / 2., FGamma4[n2]);
3268  double PreIzq = Interpola(PreIzq1, PreIzq2, 1., d);
3269  ResultInstantaneos[i].PresionIzquierdaINS = PreIzq;
3270  }
3271  if(ResultInstantaneos[i].NIT) {
3272  double nit1 = CalculaNIT(FAsonido0[n1], FVelocidad0[n1], FPresion0[n1], FDiametroTubo[n1], FGamma[n1], FRMezcla[n1]);
3273  double nit2 = CalculaNIT(FAsonido0[n2], FVelocidad0[n2], FPresion0[n2], FDiametroTubo[n2], FGamma[n2], FRMezcla[n2]);
3274  double nit = Interpola(nit1, nit2, 1., d);
3275  ResultInstantaneos[i].NITINS = nit;
3276  }
3277  if(ResultInstantaneos[i].TemperaturaInternaPared) {
3278  double TP = Interpola(FTPTubo[0][n1], FTPTubo[0][n2], 1., d);
3279  ResultInstantaneos[i].TemperaturaInternaParedINS = TP;
3280  }
3281  if(ResultInstantaneos[i].TemperaturaIntermediaPared) {
3282  double TP = Interpola(FTPTubo[1][n1], FTPTubo[1][n2], 1., d);
3283  ResultInstantaneos[i].TemperaturaIntermediaParedINS = TP;
3284  }
3285  if(ResultInstantaneos[i].TemperaturaExternaPared) {
3286  double TP = Interpola(FTPTubo[2][n1], FTPTubo[2][n2], 1., d);
3287  ResultInstantaneos[i].TemperaturaExternaParedINS = TP;
3288  }
3289  if(ResultInstantaneos[i].CoefPelInterior) {
3290  double hi = Interpola(Fhi[n1], Fhi[n2], 1., d);
3291  ResultInstantaneos[i].CoefPelInteriorINS = hi;
3292  }
3293  if(ResultInstantaneos[i].FraccionMasicaEspecies) {
3294  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
3295  double Fraccion = Interpola(FFraccionMasicaEspecie[n1][j], FFraccionMasicaEspecie[n2][j], 1., d);
3296  ResultInstantaneos[i].FraccionINS[j] = Fraccion;
3297  }
3298  }
3299  if(ResultInstantaneos[i].Gamma) {
3300  double gamma = Interpola(FGamma[n1], FGamma[n2], 1., d);
3301  ResultInstantaneos[i].GammaINS = gamma;
3302  }
3303  }
3304  }
3305 
3306  }
3307 #ifdef usetry
3308  } catch(exception & N) {
3309  std::cout << "ERROR: TTubo::CalculaResultadosInstantaneos en el tubo: " << FNumeroTubo << std::endl;
3310  std::cout << "Tipo de error: " << N.what() << std::endl;
3311  throw Exception(N.what());
3312  }
3313 #endif
3314 }
3315 
3316 // ---------------------------------------------------------------------------
3317 // ---------------------------------------------------------------------------
3318 
3319 double TTubo::CalculaNIT(double a, double v, double p, double d, double Gamma, double R) {
3320 #ifdef usetry
3321  try {
3322 #endif
3323  double kp = 0.;
3324  double tem0 = 0., pre0 = 0., area = 0., gto = 0., nit = 0., V = 0., A = 0., V2 = 0., A2 = 0.;
3325 
3326  kp = Gamma * R / (Gamma - 1);
3327  V = v * __cons::ARef;
3328  V2 = V * V;
3329  A = a * __cons::ARef;
3330  A2 = A * A;
3331  tem0 = A2 / (Gamma * R) + V2 / 2. / kp;
3332  pre0 = __units::BarToPa(p) * pow((1 + V2 / 2. / kp / A2), (kp / 287.));
3333  area = __geom::Circle_area(d);
3334  gto = Gamma * __units::BarToPa(p) * area * V / A2;
3335  nit = gto * kp * tem0 * (1 - pow(pre0 / 100000., (-287. / kp)));
3336  return nit;
3337 #ifdef usetry
3338  } catch(exception & N) {
3339  std::cout << "ERROR: TTubo::CalculaNIT en el tubo: " << FNumeroTubo << std::endl;
3340  std::cout << "Tipo de error: " << N.what() << std::endl;
3341  throw Exception(N.what());
3342  }
3343 #endif
3344 }
3345 
3346 // ---------------------------------------------------------------------------
3347 // ---------------------------------------------------------------------------
3348 
3349 void TTubo::CalculaCoeficientePeliculaExterior(TBloqueMotor **Engine, double AmbientPressure,
3350  double AmbientTemperature) {
3351 #ifdef usetry
3352  try {
3353 #endif
3354 
3355  double dtem, temed, rhog, viscext, Re, Pr, cond, viscpared, vel, n1, n2, L;
3356 
3357  if(FTipoCalcTempPared != nmTempConstante && FCoefAjusTC != 0) {
3358 
3359  if(FTipoTransCal == nmTuboAdmision || FTipoTransCal == nmTuboEscape) {
3360  for(int i = 0; i < FNin; i++) {
3361  dtem = fabs(__units::degCToK(FTPTubo[2][i]) - FTExt);
3362  temed = (__units::degCToK(FTPTubo[2][i]) + FTExt) / 2.;
3363 
3364  // Calculo del coeficiente de pelicula exterior
3365 
3366  // Calculo de las caracteristicas del refrigerante
3367  switch(FTipRefrig) {
3368  case nmAire:
3369  // Condiciones del aire a temperatura media (temed) y 1m/s
3370  rhog = __units::BarToPa(AmbientPressure) / __R::Air / temed;
3371  // Density del aire atmosferico (se considera R=cte=287)
3372  viscext = 1.4615e-6 * pow150(temed) / (temed + 110.4);
3373  Pr = 0.7;
3374  cond = (-8.39061e-09 * temed + 7.05256e-05) * temed + 6.51528e-03;
3375  Re = rhog * 1. * (FDiametroTubo[i] + 2 * (FEspesorIntPrin + FEspesorPrin + FEspesorExtPrin)) / viscext;
3376  break;
3377  case nmAgua:
3378  // Condiciones de agua saturada a (temed) y 1m/s
3379  rhog = 980;
3380  if(temed > 373.) {
3381  viscext = 0.000282;
3382  Pr = 1.76;
3383  cond = 0.6775;
3384  } else {
3385  viscext = ((-2.632351E-09 * temed + 2.737629E-06) * temed - 9.530709E-04) * temed + 1.114642E-01;
3386  Pr = ((-2.022269E-05 * temed + 2.106518E-02) * temed - 7.340298E+00) * temed + 8.581110E+02;
3387  cond = ((9.496332E-09 * temed - 1.707697E-05) * temed + 9.183462E-03) * temed - 8.626578E-01;
3388  }
3389  Re = rhog * 1. * (FDiametroTubo[i] + 2 * (FEspesorIntPrin + FEspesorPrin + FEspesorExtPrin)) / viscext;
3390  break;
3391  default:
3392  std::cout << "WARNING: Tipo de refrigeracion mal definida en el tubo: " << FNumeroTubo << std::endl;
3393  }
3394  // Termino de conveccion de Churchill Bernstein
3395  if((2e4 < Re) && (Re < 4e5)) {
3396  n1 = 0.5;
3397  n2 = 1.;
3398  } else {
3399  n1 = 0.625;
3400  n2 = 0.8;
3401  }
3402  Fhe[i] = 0.3 + 0.62 * sqrt(Re) * cbrt(Pr) / pow025(1 + pow(0.4 / Pr, 0.666666)) * pow(1 + pow(Re / 282000, n1),
3403  n2) * cond / FDiametroTubo[i];
3404 
3405  // Termino de radiacion
3406  if(dtem != 0.) {
3407  Fhe[i] = Fhe[i] + __cons::Sigma * FEmisividad * (pow4(__units::degCToK(FTPTubo[2][i])) - pow4(FTExt)) / dtem;
3408  }
3409  Fhe[i] = Fhe[i] * FCoefExt;
3410  }
3411  } else {
3412  temed = __units::degCToK(Engine[0]->getTempRefrigerante());
3413  rhog = 980.;
3414  viscext = ((-2.632351E-09 * temed + 2.737629E-06) * temed - 9.530709E-04) * temed + 1.114642E-01;
3415  L = 1.5 * Engine[0]->getGeometria().Diametro;
3416  // Longitud caracteristica del conducto refrigerante.
3417  vel = 5.64268e-7 * Engine[0]->getRegimen() / 60. * Engine[0]->getParPotMax() / Engine[0]->getGeometria().NCilin / pow(L,
3418  2.);
3419  Re = rhog * fabs(vel) * L / 2.3 / viscext;
3420  Pr = ((-2.022269E-05 * temed + 2.106518E-02) * temed - 7.340298E+00) * temed + 8.581110E+02;
3421  cond = ((9.496332E-09 * temed - 1.707697E-05) * temed + 9.183462E-03) * temed - 8.626578E-01;
3422 
3423  for(int i = 0; i < FNin; i++) {
3424  // Condiciones del agua de refrigerante del motor.
3425  // Termino de conveccion de Seider-Tate con el termino de Cipolla.
3426 
3427  if(FTPTubo[2][i] > 100.) {
3428  viscpared = 0.000282;
3429  } else {
3430  double Tp2 = __units::degCToK(FTPTubo[2][i]);
3431  viscpared = ((-2.632351E-09 * Tp2 + 2.737629E-06) * Tp2 - 9.530709E-04) * Tp2 + 1.114642E-01;
3432  }
3433 
3434  Fhe[i] = 0.027 * (1 + 24.2 / pow(2.3, 0.7) / pow025(Re)) * pow(Re, 0.8) * cbrt(Pr) * pow(viscext / viscpared,
3435  0.14) * cond / (L / 2.3);
3436  }
3437  }
3438  }
3439 #ifdef usetry
3440  } catch(exception & N) {
3441  std::cout << "ERROR: TTubo::CalculaCoeficientePeliculaExterior en el tubo: " << FNumeroTubo << std::endl;
3442  std::cout << "Tipo de error: " << N.what() << std::endl;
3443  throw Exception(N.what());
3444  }
3445 #endif
3446 }
3447 
3448 // ---------------------------------------------------------------------------
3449 // ---------------------------------------------------------------------------
3450 
3452 #ifdef usetry
3453  try {
3454 #endif
3455  double Dext, Dint, DIntPrin /* ,Tmed */, Text, Tint, Rcond, Rrad, UnionEspes, UnionConduct, Cap;
3456  bool EsInterior;
3457 
3458  if(FTipoCalcTempPared != nmTempConstante && FCoefAjusTC != 0 && !FConcentrico) {
3459  for(int i = 0; i < FNin; i++) {
3460  // Calculo de las resistencias termicas radiales.
3461  EsInterior = true;
3462  Dint = FDiametroTubo[i];
3463  FResistRadInt[i] = 0;
3464  FResistRadExt[i] = 0;
3465  for(int j = 0; j < FNumCapas; j++) {
3466  Dext = Dint + 2 * FCapa[j].Espesor;
3467  if(FCapa[j].EsPrincipal == false) {
3468  Rcond = log(Dext / Dint) / __cons::Pi_x_2 / FCapa[j].Conductividad / FXref;
3469  if(EsInterior) {
3470  // Calculo de la resistencia termica radial interior.
3471  if(FCapa[j].EsFluida) {
3472  // Capa de camara de fluido.
3473  Text = __units::degCToK(FTPTubo[1][i]);
3474  Tint = __units::degCToK(FTPTubo[0][i]);
3475  // Tmed=(Text+Tint)/2;
3476  if(Tint != Text) {
3477  Rrad = (1 / FCapa[j].EmisividadInterior + Dint / Dext * (1 / FCapa[j].EmisividadExterior - 1)) /
3478  (__cons::Sigma * __cons::Pi * Dint * FXref) * (Tint - Text) / (pow4(
3479  Tint) - pow4(Text));
3480  FResistRadInt[i] += 1 / (1 / Rcond + 1 / Rrad);
3481  } else {
3482  FResistRadInt[i] += Rcond;
3483  }
3484  } else {
3485  // Capa de material.
3486  FResistRadInt[i] += Rcond;
3487  }
3488  } else {
3489  // Calculo de la resistencia termica radial exterior.
3490  // Calculo de la resistencia termica radial interior.
3491  if(FCapa[j].EsFluida) {
3492  // Capa de camara de fluido.
3493  Text = __units::degCToK(FTPTubo[2][i]);
3494  Tint = __units::degCToK(FTPTubo[1][i]);
3495  if(Tint != Text) {
3496  Rrad = (1 / FCapa[j].EmisividadInterior + Dint / Dext * (1 / FCapa[j].EmisividadExterior - 1)) /
3497  (__cons::Sigma * __cons::Pi * Dint * FXref) * (Tint - Text) / (pow4(
3498  Tint) - pow4(Text));
3499  FResistRadExt[i] += 1 / (1 / Rcond + 1 / Rrad);
3500  } else {
3501  FResistRadExt[i] += Rcond;
3502  }
3503  } else {
3504  // Capa de material.
3505  FResistRadExt[i] += Rcond;
3506  }
3507  }
3508  } else {
3509  // Calculo de la resistencia termica radial exterior e interior de la capa principal.
3510  FResistRadInt[i] += log((Dint + FCapa[j].Espesor) / Dint) / __cons::Pi_x_2 / FCapa[j].Conductividad / FXref;
3511  FResistRadExt[i] += log(Dext / (Dint + FCapa[j].Espesor)) / __cons::Pi_x_2 / FCapa[j].Conductividad / FXref;
3512  EsInterior = false;
3513  }
3514  Dint = Dext;
3515  }
3516 
3517  // Calculo de las resistencias termicas axiales.
3518  FResistAxiAnt[i] = 0;
3519  FResistAxiPos[i] = 0;
3520  DIntPrin = FDiametroTubo[i] + 2 * FEspesorIntPrin;
3521  if(i == 0) {
3522  if(BC[FNodoIzq - 1]->getTipoCC() == nmPipesConnection) {
3523  UnionEspes = dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoIzq - 1])->getEspesor();
3524  UnionConduct = dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoIzq - 1])->getConductividad();
3525  if(UnionConduct > 0) {
3526  FResistAxiAnt[i] = UnionEspes / UnionConduct / (__cons::Pi * (DIntPrin + FEspesorPrin) * FEspesorPrin);
3527  }
3528  }
3529  FResistAxiPos[i] = FXref / FConductPrin / (__cons::Pi * (DIntPrin + FEspesorPrin) * FEspesorPrin);
3530  }
3531 #ifdef ParticulateFilter
3532  else if(BC[FNodoIzq - 1]->getTipoCC()
3533  == nmPipeToPlenumConnection) {
3534  if(FHayDPFNodoIzq) {
3535  if(FTipoCanal[0] == 0) {
3536  // Junction to a DPF inlet channel
3537  FResistAxiAnt[i] = FDPFEntradaTubo->getAjustRAxAnt
3538  () /
3539  (Pi * FDPFEntradaTubo->getConductividadMetal
3540  () * (FDPFEntradaTubo->getDiametroEfect()
3541  + 2 * FDPFEntradaTubo->getEspesorAislante
3542  () + 2 * FDPFEntradaTubo->getEspesorAire()
3543  + FDPFEntradaTubo->getEspesorMetal())
3544  * FDPFEntradaTubo->getEspesorMetal());
3545  } else { // Junction to a DPF outlet channel
3546  FResistAxiAnt[i] = FDPFEntradaTubo->getAjustRAxPos
3547  () /
3548  (Pi * FDPFEntradaTubo->getConductividadMetal
3549  () * (FDPFEntradaTubo->getDiametroEfect()
3550  + 2 * FDPFEntradaTubo->getEspesorAislante
3551  () + 2 * FDPFEntradaTubo->getEspesorAire()
3552  + FDPFEntradaTubo->getEspesorMetal())
3553  * FDPFEntradaTubo->getEspesorMetal());
3554  }
3555  }
3556  }
3557 #endif
3558  else if(i == FNin - 1) {
3559  FResistAxiAnt[i] = FXref / FConductPrin / (__cons::Pi * (DIntPrin + FEspesorPrin) * FEspesorPrin);
3560  if(BC[FNodoDer - 1]->getTipoCC() == nmPipesConnection) {
3561  UnionEspes = dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoDer - 1])->getEspesor();
3562  UnionConduct = dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoDer - 1])->getConductividad();
3563  if(UnionConduct > 0) {
3564  FResistAxiPos[i] = UnionEspes / UnionConduct / (__cons::Pi * (DIntPrin + FEspesorPrin) * FEspesorPrin);
3565  }
3566  }
3567 #ifdef ParticulateFilter
3568  else if(BC[FNodoDer - 1]->getTipoCC()
3569  == nmPipeToPlenumConnection) {
3570  if(FHayDPFNodoDer) {
3571  if(FTipoCanal[1] == 0) {
3572  // Junction to a DPF inlet channel
3573  FResistAxiPos[i]
3574  = FDPFSalidaTubo->getAjustRAxAnt() /
3575  (Pi * FDPFSalidaTubo->getConductividadMetal
3576  () * (FDPFSalidaTubo->getDiametroEfect()
3577  + 2 *
3578  FDPFSalidaTubo->getEspesorAislante()
3579  + 2 * FDPFSalidaTubo->getEspesorAire()
3580  + FDPFSalidaTubo->getEspesorMetal())
3581  * FDPFSalidaTubo->getEspesorMetal());
3582  } else { // Junction to a DPF outlet channel
3583  FResistAxiPos[i]
3584  = FDPFSalidaTubo->getAjustRAxPos() /
3585  (Pi * FDPFSalidaTubo->getConductividadMetal
3586  () * (FDPFSalidaTubo->getDiametroEfect()
3587  + 2 *
3588  FDPFSalidaTubo->getEspesorAislante()
3589  + 2 * FDPFSalidaTubo->getEspesorAire()
3590  + FDPFSalidaTubo->getEspesorMetal())
3591  * FDPFSalidaTubo->getEspesorMetal());
3592  }
3593  }
3594  }
3595 #endif
3596  } else {
3597  FResistAxiAnt[i] = FXref / FConductPrin / (__cons::Pi * (DIntPrin + FEspesorPrin) * FEspesorPrin);
3598  FResistAxiPos[i] = FXref / FConductPrin / (__cons::Pi * (DIntPrin + FEspesorPrin) * FEspesorPrin);
3599  }
3600 
3601  // Calculo de las capacidades termicas.
3602  EsInterior = true;
3603  Dint = FDiametroTubo[i];
3604  FCapInt[i] = 0.;
3605  FCapMed[i] = 0.;
3606  FCapExt[i] = 0.;
3607  for(int j = 0; j < FNumCapas; j++) {
3608  Dext = Dint + 2 * FCapa[j].Espesor;
3609  if(FCapa[j].EsPrincipal == false) {
3610  if(EsInterior) {
3611  // Calculo de la capacidad termica interior.
3612  if(!FCapa[j].EsFluida) {
3613  // Capa de material.
3614  Cap = FCapa[j].Density * FCapa[j].CalorEspecifico * __geom::Ring_area(Dint, Dext) * FXref;
3615  FCapInt[i] += Cap;
3616  }
3617  } else {
3618  // Calculo de la capacidad termica exterior.
3619  if(!FCapa[j].EsFluida) {
3620  // Capa de material.
3621  Cap = FCapa[j].Density * FCapa[j].CalorEspecifico * __geom::Ring_area(Dint, Dext) * FXref;
3622  FCapExt[i] += Cap;
3623  }
3624  }
3625  } else {
3626  // Calculo de la capacidad termica exterior, media e interior de la capa principal.
3627  FCapInt[i] += FDensidadPrin * FCalEspPrin * __geom::Ring_area(DIntPrin, DIntPrin + 0.5 * FEspesorPrin) * FXref;
3628  FCapMed[i] = FDensidadPrin * FCalEspPrin * __geom::Ring_area(DIntPrin + 0.5 * FEspesorPrin,
3629  DIntPrin + 1.5 * FEspesorPrin) * FXref;
3630  FCapExt[i] += FDensidadPrin * FCalEspPrin * __geom::Ring_area(DIntPrin + 1.5 * FEspesorPrin,
3631  DIntPrin + 2 * FEspesorPrin) * FXref;
3632  EsInterior = false;
3633  }
3634  Dint = Dext;
3635  }
3636  }
3637  }
3638 #ifdef usetry
3639  } catch(exception & N) {
3640  std::cout << "ERROR: TTubo::CalculaResistenciasdePared en el tubo: " << FNumeroTubo << std::endl;
3641  std::cout << "Tipo de error: " << N.what() << std::endl;
3642  throw Exception(N.what());
3643  }
3644 #endif
3645 }
3646 
3647 // ---------------------------------------------------------------------------
3648 // ---------------------------------------------------------------------------
3649 
3651 #ifdef usetry
3652  try {
3653 #endif
3654  double Tg = 0., cesp = 0., viscgas = 0., cond = 0., viscpared = 0.;
3655 
3656  if(FCoefAjusTC != 0) {
3657  for(int i = 0; i < FNin; i++) {
3658 
3659  Tg = FTemperature[i];
3660  cesp = FGamma[i] * FRMezcla[i] / (FGamma[i] - 1);
3661  viscgas = 1.4615e-6 * pow150(Tg) / (Tg + 110.4);
3662  cond = viscgas * cesp / 0.709;
3663  if(DoubEqZero(FVelPro[i])) {
3664  FRe[i] = 1E-06; // Para que nunca valga 0 y evitar divisiones por cero.
3665  } else {
3666  FRe[i] = Frho[i] * FVelPro[i] * FDiametroTubo[i] / viscgas;
3667  }
3668 
3669  // Calculo del coeficiente de pelicula interior
3670  switch(FTipoTransCal) {
3671  case nmTuboAdmision:
3672  // Termino de conveccion correlacion Depcick - Assanis
3673  Fhi[i] = 0.0694 * pow075(FRe[i]) * cond / FDiametroTubo[i];
3674  break;
3675  case nmPipaAdmision:
3676  // Termino de conveccion correlacion Depcick - Assanis
3677  Fhi[i] = 0.0694 * pow075(FRe[i]) * cond / FDiametroTubo[i];
3678  break;
3679  case nmTuboEscape:
3680  // Termino de conveccion correlacion M. Reyes
3681  Fhi[i] = 1.6 * pow(FRe[i], 0.4) * cond / FDiametroTubo[i] * FCoefTurbulencia[i];
3682  break;
3683  case nmPipaEscape:
3684  // Termino de conveccion correlacion de Caton + M. Reyes
3685  viscpared = 1.4615e-6 * pow150(__units::degCToK(FTPTubo[0][i])) / (__units::degCToK(FTPTubo[0][i]) + 110.4);
3686  Fhi[i] = 0.1 * pow(FRe[i], 0.8) * 0.709 * pow(viscgas / viscpared, 0.14) * cond / FDiametroTubo[i];
3687  break;
3688  default:
3689  std::cout << "WARNING: Transmision de calor mal definida en el tubo: " << FNumeroTubo << std::endl;
3690  }
3691  }
3692  } else if(FCoefAjusFric != 0) {
3693  for(int i = 0; i < FNin; i++) {
3694  Tg = FTemperature[i];
3695  viscgas = 1.4615e-6 * pow150(Tg) / (Tg + 110.4);
3696  FRe[i] = Frho[i] * FVelPro[i] * FDiametroTubo[i] / viscgas;
3697  }
3698  }
3699 #ifdef usetry
3700  } catch(exception & N) {
3701  std::cout << "ERROR: TTubo::CalculaCoeficientePeliculaInterior en el tubo: " << FNumeroTubo << std::endl;
3702  std::cout << "Tipo de error: " << N.what() << std::endl;
3703  throw Exception(N.what());
3704  }
3705 #endif
3706 }
3707 
3708 // ---------------------------------------------------------------------------
3709 // ---------------------------------------------------------------------------
3710 
3711 void TTubo::CalculaTemperaturaPared(TBloqueMotor **Engine, double Theta, double CrankAngle, TCondicionContorno **BC) {
3712  double Tg = 0.;
3713  double zzz = 0., czz = 0., cz1 = 0., uq1 = 0.;
3714  double DeltaTTPared = 0.;
3715  double Tpant0 = 0., Tpant1 = 0., Tpant2 = 0., Tpantant = 0., Tpantpos = 0., Text = 0., Ri = 0., Re = 0., ErrorTp = 0.;
3716  bool EsPrimeraVez;
3717  int extremo = 0, nodo = 0;
3718 #ifdef usetry
3719  try {
3720 #endif
3721 
3722  DeltaTTPared = FTime1 - FTime0;
3723 
3724  for(int i = 0; i < FNin; i++) {
3725  FTParedAnt[0][i] = FTPTubo[0][i];
3726  FTParedAnt[1][i] = FTPTubo[1][i];
3727  FTParedAnt[2][i] = FTPTubo[2][i];
3728 
3729  zzz = 0.013 / DeltaTTPared;
3730  czz = 2 / (zzz + 1);
3731  uq1 = fabs(FVelocidadDim[i]);
3732  if(FTipoTransCal == nmTuboEscape)
3733  cz1 = czz;
3734  else
3735  cz1 = 1;
3736  FVelPro[i] = cz1 * uq1 + (1 - cz1) * FVelPro[i];
3737  }
3738 
3739  if(FTipoCalcTempPared != nmTempConstante && FCoefAjusTC != 0) {
3740  // Tiene que existir motor.
3741  if(Theta > FAnguloTotalCiclo) {
3742  FSUMTime += DeltaTTPared;
3743  }
3744  for(int i = 0; i < FNin; i++) {
3745  // Establece la temperatura del gas en el interior del conducto.
3746  Tg = FTemperature[i];
3747 
3748  // Establece la temperatura del fluido en el exterior del conducto.
3749  if(FTipoTransCal == nmTuboAdmision || FTipoTransCal == nmTuboEscape) {
3750  Text = FTExt;
3751  } else {
3752  Text = __units::degCToK(Engine[0]->getTempRefrigerante());
3753  }
3754 
3755  // Establece la temperatura de la pared en el instante de calculo anterior...
3756  // ...en los nodos anterior y posterior.
3757  // Tpantant=FTParedAnt[1][i]+273.;
3758  // Tpantpos=FTParedAnt[1][i]+273.;
3759  if(i == 0) {
3760  if(BC[FNodoIzq - 1]->getTipoCC() == nmPipesConnection) {
3761  if(dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoIzq - 1])->getConductividad() > 0) {
3762  if(BC[FNodoIzq - 1]->GetTuboExtremo(0).Pipe->getNumeroTubo() == FNumeroTubo) {
3763  extremo = 1;
3764  if(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
3765  nodo = 0;
3766  } else {
3767  nodo = BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
3768  }
3769  } else {
3770  extremo = 0;
3771  if(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
3772  nodo = 0;
3773  } else {
3774  nodo = BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
3775  }
3776  }
3777  Tpantant = __units::degCToK(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->GetTPTuboAnt(1, nodo));
3778  }
3779  }
3780 #ifdef ParticulateFilter
3781  else if(BC[FNodoIzq - 1]->getTipoCC() == nmPipeToPlenumConnection) {
3782  if(FHayDPFNodoIzq) {
3783  Tpantant = __units::degCToK(FDPFEntradaTubo->GetTSuperficie
3784  (FNodoDPFEntrada, 2));
3785  }
3786  }
3787 #endif
3788  Tpantpos = __units::degCToK(FTParedAnt[1][i + 1]);
3789  } else if(i == FNin - 1) {
3790  Tpantant = __units::degCToK(FTParedAnt[1][i - 1]);
3791  if(BC[FNodoDer - 1]->getTipoCC() == nmPipesConnection) {
3792  if(dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoDer - 1])->getConductividad() > 0) {
3793  if(BC[getNodoDer() - 1]->GetTuboExtremo(0).Pipe->getNumeroTubo() == FNumeroTubo) {
3794  extremo = 1;
3795  if(BC[FNodoDer - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
3796  nodo = 0;
3797  } else {
3798  nodo = BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
3799  }
3800  } else {
3801  extremo = 0;
3802  if(BC[FNodoDer - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
3803  nodo = 0;
3804  } else {
3805  nodo = BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
3806  }
3807  }
3808  Tpantpos = __units::degCToK(BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->GetTPTuboAnt(1, nodo));
3809  }
3810  }
3811 #ifdef ParticulaFilter
3812  else if(BC[FNodoDer - 1]->getTipoCC() == nmPlenum) {
3813  if(FHayDPFNodoDer) {
3814  Tpantpos = __units::degCToK(FDPFSalidaTubo->GetTSuperficie
3815  (FNodoDPFSalida, 2));
3816  }
3817  }
3818 #endif
3819  } else {
3820  Tpantant = __units::degCToK(FTParedAnt[1][i - 1]);
3821  Tpantpos = __units::degCToK(FTParedAnt[1][i + 1]);
3822  }
3823  // ...en los nodos interior, medio y exterior.
3824  Tpant0 = __units::degCToK(FTParedAnt[0][i]);
3825  Tpant1 = __units::degCToK(FTParedAnt[1][i]);
3826  Tpant2 = __units::degCToK(FTParedAnt[2][i]);
3827 
3828  // Resistencias termicas interior y exterior.
3829  if(DoubEqZero(Fhi[i])) {
3830  Ri = 100000000.;
3831  } else {
3832  Ri = 1 / __cons::Pi / FDiametroTubo[i] / Fhi[i] / FCoefAjusTC / FXref;
3833  }
3834  if(DoubEqZero(Fhe[i])) {
3835  Re = 100000000.;
3836  } else {
3837  Re = 1 / __cons::Pi / (FDiametroTubo[i] + 2 * (FEspesorIntPrin + FEspesorPrin + FEspesorExtPrin)) / Fhe[i] / FXref;
3838  }
3839  // Calculo de las temperaturas de pared.
3840  FTPTubo[2][i] = DeltaTTPared / FCapExt[i] * (1 / FResistRadExt[i] * (Tpant1 - Tpant2) + 1 / Re *
3841  (Text - Tpant2)) + Tpant2;
3842  if(FResistAxiAnt[i] > 0. && FResistAxiPos[i] > 0.) {
3843  FTPTubo[1][i] = DeltaTTPared / FCapMed[i] * (1 / FResistRadInt[i] * (Tpant0 - Tpant1) + 1 / FResistRadExt[i] *
3844  (Tpant2 - Tpant1) + 1 / FResistAxiAnt[i] * (Tpantant - Tpant1) + 1 / FResistAxiPos[i] * (Tpantpos - Tpant1)) + Tpant1;
3845  } else if(FResistAxiAnt[i] > 0.) {
3846  FTPTubo[1][i] = DeltaTTPared / FCapMed[i] * (1 / FResistRadInt[i] * (Tpant0 - Tpant1) + 1 / FResistRadExt[i] *
3847  (Tpant2 - Tpant1) + 1 / FResistAxiAnt[i] * (Tpantant - Tpant1)) + Tpant1;
3848  } else if(FResistAxiPos[i] > 0.) {
3849  FTPTubo[1][i] = DeltaTTPared / FCapMed[i] * (1 / FResistRadInt[i] * (Tpant0 - Tpant1) + 1 / FResistRadExt[i] *
3850  (Tpant2 - Tpant1) + 1 / FResistAxiPos[i] * (Tpantpos - Tpant1)) + Tpant1;
3851  } else {
3852  FTPTubo[1][i] = DeltaTTPared / FCapMed[i] * (1 / FResistRadInt[i] * (Tpant0 - Tpant1) + 1 / FResistRadExt[i] *
3853  (Tpant2 - Tpant1)) + Tpant1;
3854  }
3855  FTPTubo[0][i] = DeltaTTPared / FCapInt[i] * (1 / Ri * (Tg - Tpant0) + 1 / FResistRadInt[i] *
3856  (Tpant1 - Tpant0)) + Tpant0;
3857  for(int k = 0; k < 3; k++) {
3858  FTPTubo[k][i] = __units::KTodegC(FTPTubo[k][i]);
3859  }
3860 
3861  // Si el tipo de calculo es sin inercia termica o lleva menos de "NumCiclosSinInerciaTermica" ciclos calculando...
3862  if(FTipoCalcTempPared == nmVariableSinInerciaTermica
3863  || Theta / FAnguloTotalCiclo <= Engine[0]->getNumCiclosSinInerciaTermica()) {
3864  if(Fhi[i] != 0. && Theta > FAnguloTotalCiclo) {
3865  // Sumatorio de h*Tg*incrt intermedio(para el calculo de la integral).
3866  FSUMTPTuboPro[0][1][i] += 1 / (Ri + FResistRadInt[i]) * Tg * DeltaTTPared;
3867  // Sumatorio de h*incrt intermedio(para el calculo de la integral).
3868  FSUMTPTuboPro[1][1][i] += 1 / (Ri + FResistRadInt[i]) * DeltaTTPared;
3869  // Sumatorio de h*Tg*incrt interior(para el calculo de la integral).
3870  FSUMTPTuboPro[0][0][i] += 1 / Ri * Tg * DeltaTTPared;
3871  // Sumatorio de h*incrt interior(para el calculo de la integral).
3872  FSUMTPTuboPro[1][0][i] += 1 / Ri * DeltaTTPared;
3873  }
3874  }
3875 
3876  }
3877 
3878  // Si esta al final del ciclo...
3879  if(FCicloTubo != Engine[0]->getCiclo() && FSUMTime > 0.) {
3880  // ...si (el tipo de calculo es sin inercia termica o lleva menos de "NumCiclosSinInerciaTermica" ciclos calculando) y esta en el segundo ciclo, calcula la temperatura de convergencia
3881  if((FTipoCalcTempPared == nmVariableSinInerciaTermica
3882  || Theta / FAnguloTotalCiclo <= Engine[0]->getNumCiclosSinInerciaTermica()) && Theta > FAnguloTotalCiclo + 1) {
3883  ErrorTp = 1.;
3884  EsPrimeraVez = true;
3885  while(ErrorTp >=
3886  1) { // Itera hasta conseguir una diferencia entre las temperaturas de pared menor a 1degC entre Steps.
3887  ErrorTp = 0.;
3888  for(int i = 0; i < FNin; i++) {
3889  // Establece la temperatura de la pared en el instante de calculo anterior...
3890  // ...en los nosdos anterior y posterior.
3891  Tpantant = __units::degCToK(FTPTubo[1][i]);
3892  Tpantpos = __units::degCToK(FTPTubo[1][i]);
3893  if(i == 0) {
3894  if(BC[FNodoIzq - 1]->getTipoCC() == nmPipesConnection) {
3895  if(dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoIzq - 1])->getConductividad() > 0) {
3896  if(BC[FNodoIzq - 1]->GetTuboExtremo(0).Pipe->getNumeroTubo() == FNumeroTubo) {
3897  extremo = 1;
3898  if(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
3899  nodo = 0;
3900  } else {
3901  nodo = BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
3902  }
3903  } else {
3904  extremo = 0;
3905  if(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
3906  nodo = 0;
3907  } else {
3908  nodo = BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
3909  }
3910  }
3911  Tpantant = __units::degCToK(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->GetTPTuboAnt(1, nodo));
3912  }
3913  }
3914 #ifdef ParticulateFilter
3915  else if
3916  (BC[FNodoIzq - 1]->getTipoCC()
3917  == nmPipeToPlenumConnection) {
3918  if(FHayDPFNodoIzq) {
3919  Tpantant =
3920  __units::degCToK(FDPFEntradaTubo->GetTSuperficie
3921  (FNodoDPFEntrada, 2));
3922  }
3923  }
3924 #endif
3925  Tpantpos = __units::degCToK(FTPTubo[1][i + 1]);
3926  } else if(i == FNin - 1) {
3927  Tpantant = __units::degCToK(FTPTubo[1][i - 1]);
3928  if(BC[FNodoDer - 1]->getTipoCC() == nmPipesConnection) {
3929  if(dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoDer - 1])->getConductividad() > 0) {
3930  if(BC[FNodoDer - 1]->GetTuboExtremo(0).Pipe->getNumeroTubo() == FNumeroTubo) {
3931  extremo = 1;
3932  if(BC[FNodoDer - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
3933  nodo = 0;
3934  } else {
3935  nodo = BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
3936  }
3937  } else {
3938  extremo = 0;
3939  if(BC[FNodoDer - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
3940  nodo = 0;
3941  } else {
3942  nodo = BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
3943  }
3944  }
3945  Tpantpos = __units::degCToK(BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->GetTPTuboAnt(1, nodo));
3946  }
3947  }
3948 #ifdef ParticulateFilter
3949  else if
3950  (BC[FNodoDer - 1]->getTipoCC()
3951  == nmPipeToPlenumConnection) {
3952  if(FHayDPFNodoDer) {
3953  Tpantpos =
3954  __units::degCToK(FDPFSalidaTubo->GetTSuperficie
3955  (FNodoDPFSalida, 2));
3956  }
3957  }
3958 #endif
3959  } else {
3960  Tpantant = __units::degCToK(FTPTubo[1][i - 1]);
3961  Tpantpos = __units::degCToK(FTPTubo[1][i + 1]);
3962  }
3963 
3964  // ...en los nodos interior, medio y exterior.
3965  Tpant0 = __units::degCToK(FTPTubo[0][i]);
3966  Tpant1 = __units::degCToK(FTPTubo[1][i]);
3967  Tpant2 = __units::degCToK(FTPTubo[2][i]);
3968 
3969  if(EsPrimeraVez) {
3970  FTPTubo[1][i] = (FSUMTime * 1 / (Re + FResistRadExt[i]) * Text + FSUMTPTuboPro[0][1][i]) / (FSUMTime * 1 /
3971  (Re + FResistRadExt[i]) + FSUMTPTuboPro[1][1][i]);
3972  } else {
3973  if(FResistAxiAnt[i] > 0. && FResistAxiPos[i] > 0.) {
3974  FTPTubo[1][i] = (FSUMTime * (1 / (Re + FResistRadExt[i]) * Text + 1 / FResistAxiAnt[i] * Tpantant + 1 / FResistAxiPos[i]
3975  * Tpantpos) + FSUMTPTuboPro[0][1][i]) / (FSUMTime * (1 / (Re + FResistRadExt[i]) + 1 / FResistAxiAnt[i] + 1 /
3976  FResistAxiPos[i]) + FSUMTPTuboPro[1][1][i]);
3977  } else if(FResistAxiAnt[i] > 0.) {
3978  FTPTubo[1][i] = (FSUMTime * (1 / (Re + FResistRadExt[i]) * Text + 1 / FResistAxiAnt[i] * Tpantant) +
3979  FSUMTPTuboPro[0][1][i]) / (FSUMTime * (1 / (Re + FResistRadExt[i]) + 1 / FResistAxiAnt[i]) + FSUMTPTuboPro[1][1][i]);
3980  } else if(FResistAxiPos[i] > 0.) {
3981  FTPTubo[1][i] = (FSUMTime * (1 / (Re + FResistRadExt[i]) * Text + 1 / FResistAxiPos[i] * Tpantpos) +
3982  FSUMTPTuboPro[0][1][i]) / (FSUMTime * (1 / (Re + FResistRadExt[i]) + 1 / FResistAxiPos[i]) + FSUMTPTuboPro[1][1][i]);
3983  } else {
3984  FTPTubo[1][i] = (FSUMTime * (1 / (Re + FResistRadExt[i]) * Text) + FSUMTPTuboPro[0][1][i]) / (FSUMTime * (1 /
3985  (Re + FResistRadExt[i])) + FSUMTPTuboPro[1][1][i]);
3986  }
3987  }
3988  FTPTubo[0][i] = ((FSUMTime * 1 / FResistRadInt[i] * Tpant1 + FSUMTPTuboPro[0][0][i]) /
3989  (FSUMTime * 1 / FResistRadInt[i] + FSUMTPTuboPro[1][0][i]));
3990  FTPTubo[2][i] = (FSUMTime * (1 / Re * Text + 1 / FResistRadExt[i] * Tpant1)) / (FSUMTime *
3991  (1 / Re + 1 / FResistRadExt[i]));
3992  if(ErrorTp < fabs(Tpant1 - FTPTubo[1][i])) {
3993  ErrorTp = fabs(Tpant1 - FTPTubo[1][i]);
3994  }
3995  for(int k = 0; k < 3; k++) {
3996  FTPTubo[k][i] = __units::KTodegC(FTPTubo[k][i]);
3997  }
3998  }
3999  EsPrimeraVez = false;
4000  }
4001  }
4002  for(int i = 0; i < FNin; i++) {
4003  for(int j = 0; j < 2; j++) {
4004  for(int k = 0; k < 3; k++) {
4005  FSUMTPTuboPro[j][k][i] = 0.;
4006  }
4007  }
4008  }
4009  }
4010  }
4011 
4012  if(FTipoCalcTempPared != nmTempConstante && FCoefAjusTC != 0) {
4013  if(FCicloTubo != Engine[0]->getCiclo()) {
4014  FSUMTime = 0.;
4015  FCicloTubo = Engine[0]->getCiclo();
4016  }
4017  }
4018 #ifdef usetry
4019  } catch(exception & N) {
4020  std::cout << "ERROR: TTubo::CalculaTemperaturaPared en el tubo: " << FNumeroTubo << std::endl;
4021  std::cout << "Tipo de error: " << N.what() << std::endl;
4022  throw Exception(N.what());
4023  }
4024 #endif
4025 }
4026 
4027 // ---------------------------------------------------------------------------
4028 // ---------------------------------------------------------------------------
4029 
4030 void TTubo::CalculaTemperaturaParedSinMotor(TCondicionContorno **BC) {
4031  double Tg = 0.;
4032  double zzz = 0., czz = 0., cz1 = 0., uq1 = 0.;
4033  double DeltaTTPared = 0.;
4034  double Tpant0 = 0., Tpant1 = 0., Tpant2 = 0., Tpantant = 0., Tpantpos = 0., Text = 0., Ri = 0., Re = 0., ErrorTp = 0.;
4035  bool EsPrimeraVez;
4036  int extremo = 0, nodo = 0;
4037 
4038 #ifdef usetry
4039  try {
4040 #endif
4041 
4042  DeltaTTPared = FTime1 - FTime0;
4043 
4044  for(int i = 0; i < FNin; i++) {
4045  FTParedAnt[0][i] = FTPTubo[0][i];
4046  FTParedAnt[1][i] = FTPTubo[1][i];
4047  FTParedAnt[2][i] = FTPTubo[2][i];
4048 
4049  zzz = 0.013 / DeltaTTPared;
4050  czz = 2 / (zzz + 1);
4051  uq1 = fabs(FVelocidadDim[i]);
4052  if(FTipoTransCal == nmTuboEscape)
4053  cz1 = czz;
4054  else
4055  cz1 = 1;
4056  FVelPro[i] = cz1 * uq1 + (1 - cz1) * FVelPro[i];
4057  }
4058 
4059  if(FTipoCalcTempPared != nmTempConstante && FCoefAjusTC != 0) {
4060  FCicloActual = FTime1 / FDuracionCiclo;
4061  if(FTime1 > FDuracionCiclo) {
4062  FSUMTime += DeltaTTPared;
4063  }
4064  for(int i = 0; i < FNin; i++) {
4065  // Establece la temperatura del gas en el interior del conducto.
4066  Tg = FTemperature[i];
4067 
4068  // Establece la temperatura del fluido en el exterior del conducto.
4069  // Como no hay motor quito los if referentes a tipo de tubo.
4070  Text = FTExt;
4071 
4072  // Establece la temperatura de la pared en el instante de calculo anterior...
4073  // ...en los nodos anterior y posterior.
4074  // Tpantant=FTParedAnt[1][i]+273.;
4075  // Tpantpos=FTParedAnt[1][i]+273.;
4076  if(i == 0) {
4077  if(BC[FNodoIzq - 1]->getTipoCC() == nmPipesConnection) {
4078  if(dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoIzq - 1])->getConductividad() > 0) {
4079  if(BC[FNodoIzq - 1]->GetTuboExtremo(0).Pipe->getNumeroTubo() == FNumeroTubo) {
4080  extremo = 1;
4081  if(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
4082  nodo = 0;
4083  } else {
4084  nodo = BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
4085  }
4086  } else {
4087  extremo = 0;
4088  if(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
4089  nodo = 0;
4090  } else {
4091  nodo = BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
4092  }
4093  }
4094  Tpantant = __units::degCToK(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->GetTPTuboAnt(1, nodo));
4095  }
4096  }
4097 #ifdef ParticulateFilter
4098  else if(BC[FNodoIzq - 1]->getTipoCC() == nmPipeToPlenumConnection) {
4099  if(FHayDPFNodoIzq) {
4100  Tpantant = __units::degCToK(FDPFEntradaTubo->GetTSuperficie
4101  (FNodoDPFEntrada, 2));
4102  }
4103  }
4104 #endif
4105  Tpantpos = __units::degCToK(FTParedAnt[1][i + 1]);
4106  } else if(i == FNin - 1) {
4107  Tpantant = __units::degCToK(FTParedAnt[1][i - 1]);
4108  if(BC[FNodoDer - 1]->getTipoCC() == nmPipesConnection) {
4109  if(dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoDer - 1])->getConductividad() > 0) {
4110  if(BC[getNodoDer() - 1]->GetTuboExtremo(0).Pipe->getNumeroTubo() == FNumeroTubo) {
4111  extremo = 1;
4112  if(BC[FNodoDer - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
4113  nodo = 0;
4114  } else {
4115  nodo = BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
4116  }
4117  } else {
4118  extremo = 0;
4119  if(BC[FNodoDer - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
4120  nodo = 0;
4121  } else {
4122  nodo = BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
4123  }
4124  }
4125  Tpantpos = __units::degCToK(BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->GetTPTuboAnt(1, nodo));
4126  }
4127  }
4128 #ifdef ParticulateFilter
4129  else if(BC[FNodoDer - 1]->getTipoCC() == nmPipeToPlenumConnection) {
4130  if(FHayDPFNodoDer) {
4131  Tpantpos = __units::degCToK(FDPFSalidaTubo->GetTSuperficie
4132  (FNodoDPFSalida, 2));
4133  }
4134  }
4135 #endif
4136  } else {
4137  Tpantant = __units::degCToK(FTParedAnt[1][i - 1]);
4138  Tpantpos = __units::degCToK(FTParedAnt[1][i + 1]);
4139  }
4140  // ...en los nodos interior, medio y exterior.
4141  Tpant0 = __units::degCToK(FTParedAnt[0][i]);
4142  Tpant1 = __units::degCToK(FTParedAnt[1][i]);
4143  Tpant2 = __units::degCToK(FTParedAnt[2][i]);
4144 
4145  // Resistencias termicas interior y exterior.
4146  if(DoubEqZero(Fhi[i])) {
4147  Ri = 100000000.;
4148  } else {
4149  Ri = 1 / __cons::Pi / FDiametroTubo[i] / Fhi[i] / FCoefAjusTC / FXref;
4150  }
4151  if(DoubEqZero(Fhe[i])) {
4152  Re = 100000000.;
4153  } else {
4154  Re = 1 / __cons::Pi / (FDiametroTubo[i] + 2 * (FEspesorIntPrin + FEspesorPrin + FEspesorExtPrin)) / Fhe[i] / FXref;
4155  }
4156  // Calculo de las temperaturas de pared.
4157  FTPTubo[2][i] = DeltaTTPared / FCapExt[i] * (1 / FResistRadExt[i] * (Tpant1 - Tpant2) + 1 / Re *
4158  (Text - Tpant2)) + Tpant2;
4159  if(FResistAxiAnt[i] > 0. && FResistAxiPos[i] > 0.) {
4160  FTPTubo[1][i] = DeltaTTPared / FCapMed[i] * (1 / FResistRadInt[i] * (Tpant0 - Tpant1) + 1 / FResistRadExt[i] *
4161  (Tpant2 - Tpant1) + 1 / FResistAxiAnt[i] * (Tpantant - Tpant1) + 1 / FResistAxiPos[i] * (Tpantpos - Tpant1)) + Tpant1;
4162  } else if(FResistAxiAnt[i] > 0.) {
4163  FTPTubo[1][i] = DeltaTTPared / FCapMed[i] * (1 / FResistRadInt[i] * (Tpant0 - Tpant1) + 1 / FResistRadExt[i] *
4164  (Tpant2 - Tpant1) + 1 / FResistAxiAnt[i] * (Tpantant - Tpant1)) + Tpant1;
4165  } else if(FResistAxiPos[i] > 0.) {
4166  FTPTubo[1][i] = DeltaTTPared / FCapMed[i] * (1 / FResistRadInt[i] * (Tpant0 - Tpant1) + 1 / FResistRadExt[i] *
4167  (Tpant2 - Tpant1) + 1 / FResistAxiPos[i] * (Tpantpos - Tpant1)) + Tpant1;
4168  } else {
4169  FTPTubo[1][i] = DeltaTTPared / FCapMed[i] * (1 / FResistRadInt[i] * (Tpant0 - Tpant1) + 1 / FResistRadExt[i] *
4170  (Tpant2 - Tpant1)) + Tpant1;
4171  }
4172  FTPTubo[0][i] = DeltaTTPared / FCapInt[i] * (1 / Ri * (Tg - Tpant0) + 1 / FResistRadInt[i] *
4173  (Tpant1 - Tpant0)) + Tpant0;
4174  for(int k = 0; k < 3; k++) {
4175  FTPTubo[k][i] = __units::KTodegC(FTPTubo[k][i]);
4176  }
4177 
4178  // Si el tipo de calculo es sin inercia termica o lleva menos de "NumCiclosSinInerciaTermica" ciclos calculando...
4179  if(FTipoCalcTempPared == nmVariableSinInerciaTermica || FCicloActual <= FNumCiclosSinInerciaTermica) {
4180  if(FTime1 > FDuracionCiclo) {
4181  // Sumatorio de h*Tg*incrt intermedio(para el calculo de la integral).
4182  FSUMTPTuboPro[0][1][i] += 1 / (Ri + FResistRadInt[i]) * Tg * DeltaTTPared;
4183  // Sumatorio de h*incrt intermedio(para el calculo de la integral).
4184  FSUMTPTuboPro[1][1][i] += 1 / (Ri + FResistRadInt[i]) * DeltaTTPared;
4185  // Sumatorio de h*Tg*incrt interior(para el calculo de la integral).
4186  FSUMTPTuboPro[0][0][i] += 1 / Ri * Tg * DeltaTTPared;
4187  // Sumatorio de h*incrt interior(para el calculo de la integral).
4188  FSUMTPTuboPro[1][0][i] += 1 / Ri * DeltaTTPared;
4189  }
4190  }
4191 
4192  }
4193 
4194  // Si esta al final del ciclo...
4195  if(FCicloTubo != FCicloActual && FSUMTime > 0. && FCicloActual > 1) {
4196  // ...si (el tipo de calculo es sin inercia termica o lleva menos de "NumCiclosSinInerciaTermica" ciclos calculando) y esta en el segundo ciclo, calcula la temperatura de convergencia
4197  if((FTipoCalcTempPared == nmVariableSinInerciaTermica || FCicloActual <= FNumCiclosSinInerciaTermica)
4198  && FTime1 > FDuracionCiclo) {
4199  ErrorTp = 1.;
4200  EsPrimeraVez = true;
4201  while(ErrorTp >=
4202  1) { // Itera hasta conseguir una diferencia entre las temperaturas de pared menor a 1degC entre Steps.
4203  ErrorTp = 0.;
4204  for(int i = 0; i < FNin; i++) {
4205  // Establece la temperatura de la pared en el instante de calculo anterior...
4206  // ...en los nosdos anterior y posterior.
4207  Tpantant = __units::degCToK(FTPTubo[1][i]);
4208  Tpantpos = __units::degCToK(FTPTubo[1][i]);
4209  if(i == 0) {
4210  if(BC[FNodoIzq - 1]->getTipoCC() == nmPipesConnection) {
4211  if(dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoIzq - 1])->getConductividad() > 0) {
4212  if(BC[FNodoIzq - 1]->GetTuboExtremo(0).Pipe->getNumeroTubo() == FNumeroTubo) {
4213  extremo = 1;
4214  if(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
4215  nodo = 0;
4216  } else {
4217  nodo = BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
4218  }
4219  } else {
4220  extremo = 0;
4221  if(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
4222  nodo = 0;
4223  } else {
4224  nodo = BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
4225  }
4226  }
4227  Tpantant = __units::degCToK(BC[FNodoIzq - 1]->GetTuboExtremo(extremo).Pipe->GetTPTuboAnt(1, nodo));
4228  }
4229  }
4230 #ifdef ParticulateFilter
4231  else if
4232  (BC[FNodoIzq - 1]->getTipoCC()
4233  == nmPipeToPlenumConnection) {
4234  if(FHayDPFNodoIzq) {
4235  Tpantant =
4236  __units::degCToK(FDPFEntradaTubo->GetTSuperficie
4237  (FNodoDPFEntrada, 2));
4238  }
4239  }
4240 #endif
4241  Tpantpos = __units::degCToK(FTPTubo[1][i + 1]);
4242  } else if(i == FNin - 1) {
4243  Tpantant = __units::degCToK(FTPTubo[1][i - 1]);
4244  if(BC[FNodoDer - 1]->getTipoCC() == nmPipesConnection) {
4245  if(dynamic_cast<TCCUnionEntreTubos*>(BC[FNodoDer - 1])->getConductividad() > 0) {
4246  if(BC[FNodoDer - 1]->GetTuboExtremo(0).Pipe->getNumeroTubo() == FNumeroTubo) {
4247  extremo = 1;
4248  if(BC[FNodoDer - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
4249  nodo = 0;
4250  } else {
4251  nodo = BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
4252  }
4253  } else {
4254  extremo = 0;
4255  if(BC[FNodoDer - 1]->GetTuboExtremo(extremo).TipoExtremo == nmLeft) {
4256  nodo = 0;
4257  } else {
4258  nodo = BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->getNin() - 1;
4259  }
4260  }
4261  Tpantpos = __units::degCToK(BC[FNodoDer - 1]->GetTuboExtremo(extremo).Pipe->GetTPTuboAnt(1, nodo));
4262  }
4263  }
4264 #ifdef ParticulateFilter
4265  else if
4266  (BC[FNodoDer - 1]->getTipoCC()
4267  == nmPipeToPlenumConnection) {
4268  if(FHayDPFNodoDer) {
4269  Tpantpos =
4270  __units::degCToK(FDPFSalidaTubo->GetTSuperficie
4271  (FNodoDPFSalida, 2));
4272  }
4273  }
4274 #endif
4275  } else {
4276  Tpantant = __units::degCToK(FTPTubo[1][i - 1]);
4277  Tpantpos = __units::degCToK(FTPTubo[1][i + 1]);
4278  }
4279 
4280  // ...en los nodos interior, medio y exterior.
4281  Tpant0 = __units::degCToK(FTPTubo[0][i]);
4282  Tpant1 = __units::degCToK(FTPTubo[1][i]);
4283  Tpant2 = __units::degCToK(FTPTubo[2][i]);
4284 
4285  if(EsPrimeraVez) {
4286  FTPTubo[1][i] = (FSUMTime / (Re + FResistRadExt[i]) * Text + FSUMTPTuboPro[0][1][i]) / (FSUMTime /
4287  (Re + FResistRadExt[i]) + FSUMTPTuboPro[1][1][i]);
4288  } else {
4289  if(FResistAxiAnt[i] > 0. && FResistAxiPos[i] > 0.) {
4290  FTPTubo[1][i] = (FSUMTime * (1 / (Re + FResistRadExt[i]) * Text + 1 / FResistAxiAnt[i] * Tpantant + 1 / FResistAxiPos[i]
4291  * Tpantpos) + FSUMTPTuboPro[0][1][i]) / (FSUMTime * (1 / (Re + FResistRadExt[i]) + 1 / FResistAxiAnt[i] + 1 /
4292  FResistAxiPos[i]) + FSUMTPTuboPro[1][1][i]);
4293  } else if(FResistAxiAnt[i] > 0.) {
4294  FTPTubo[1][i] = (FSUMTime * (1 / (Re + FResistRadExt[i]) * Text + 1 / FResistAxiAnt[i] * Tpantant) +
4295  FSUMTPTuboPro[0][1][i]) / (FSUMTime * (1 / (Re + FResistRadExt[i]) + 1 / FResistAxiAnt[i]) + FSUMTPTuboPro[1][1][i]);
4296  } else if(FResistAxiPos[i] > 0.) {
4297  FTPTubo[1][i] = (FSUMTime * (1 / (Re + FResistRadExt[i]) * Text + 1 / FResistAxiPos[i] * Tpantpos) +
4298  FSUMTPTuboPro[0][1][i]) / (FSUMTime * (1 / (Re + FResistRadExt[i]) + 1 / FResistAxiPos[i]) + FSUMTPTuboPro[1][1][i]);
4299  } else {
4300  FTPTubo[1][i] = (FSUMTime * (1 / (Re + FResistRadExt[i]) * Text) + FSUMTPTuboPro[0][1][i]) / (FSUMTime * (1 /
4301  (Re + FResistRadExt[i])) + FSUMTPTuboPro[1][1][i]);
4302  }
4303  }
4304  FTPTubo[0][i] = ((FSUMTime / FResistRadInt[i] * Tpant1 + FSUMTPTuboPro[0][0][i]) / (FSUMTime / FResistRadInt[i] +
4305  FSUMTPTuboPro[1][0][i]));
4306  FTPTubo[2][i] = (FSUMTime * (1 / Re * Text + 1 / FResistRadExt[i] * Tpant1)) / (FSUMTime *
4307  (1 / Re + 1 / FResistRadExt[i]));
4308  if(ErrorTp < fabs(Tpant1 - FTPTubo[1][i])) {
4309  ErrorTp = fabs(Tpant1 - FTPTubo[1][i]);
4310  }
4311  for(int k = 0; k < 3; k++) {
4312  FTPTubo[k][i] = __units::KTodegC(FTPTubo[k][i]);
4313  }
4314  }
4315  EsPrimeraVez = false;
4316  }
4317  }
4318  for(int i = 0; i < FNin; i++) {
4319  for(int j = 0; j < 2; j++) {
4320  for(int k = 0; k < 3; k++) {
4321  FSUMTPTuboPro[j][k][i] = 0.;
4322  }
4323  }
4324  }
4325  }
4326  if(FCicloTubo != FCicloActual) {
4327  FCicloTubo = FCicloActual;
4328  FSUMTime = 0.;
4329  }
4330  }
4331 #ifdef usetry
4332  } catch(exception & N) {
4333  std::cout << "ERROR: TTubo::CalculaTemperaturaParedSinMotor en el tubo: " << FNumeroTubo << std::endl;
4334  std::cout << "Tipo de error: " << N.what() << std::endl;
4335  throw Exception(N.what());
4336  }
4337 #endif
4338 }
4339 
4340 // ---------------------------------------------------------------------------
4341 // ---------------------------------------------------------------------------
4342 
4343 void TTubo::SalidaGeneralTubos(stEspecies *DatosEspecies) const {
4344 #ifdef usetry
4345  try {
4346 #endif
4347  if(FNumResMedios > 0) {
4348  printf("__________________________________\n");
4349  printf(" AVERAGE RESULTS IN PIPES \n");
4350  printf("__________________________________\n\n\n");
4351  for(int i = 0; i < FNumResMedios; i++) {
4352  std::cout << "Average results in point " << i << " place in pipe " << FNumeroTubo;
4353  std::cout << " at " << ResultadosMedios[i].Distancia << " metres from left end" << std::endl;
4354  if(ResultadosMedios[i].TemperaturaGas)
4355  std::cout << "Average Temperature = " << ResultadosMedios[i].TemperaturaGasMED << " C" << std::endl;
4356  if(ResultadosMedios[i].Pressure)
4357  std::cout << "Average Pressure = " << ResultadosMedios[i].PresionMED << " bar" << std::endl;
4358  if(ResultadosMedios[i].Velocity)
4359  std::cout << "Average Velocity = " << ResultadosMedios[i].VelocidadMED << " m/s" << std::endl;
4360  if(ResultadosMedios[i].Massflow)
4361  std::cout << "Average Massflow = " << ResultadosMedios[i].GastoMED << " kg/s" << std::endl;
4362  if(ResultadosMedios[i].NITmedio)
4363  std::cout << "NIT Medio = " << ResultadosMedios[i].NITmedioMED << " Watts" << std::endl << std::endl;
4364  // std::cout << "Fraccion Masica Media de " << DatosEspecies[i].Nombre << ": " << ResultadosMedios[i].FraccionMED[i] << std::endl;
4365  }
4366  }
4367 #ifdef usetry
4368  } catch(exception & N) {
4369  std::cout << "ERROR: TTubo::SalidaGeneralTubos en el tubo nº: " << FNumeroTubo << std::endl;
4370  std::cout << "Tipo de error: " << N.what() << std::endl;
4371  throw Exception(N.what());
4372  }
4373 #endif
4374 }
4375 
4376 // ---------------------------------------------------------------------------
4377 // ---------------------------------------------------------------------------
4378 
4379 inline double TTubo::Maximo(double x, double y) {
4380  return x > y ? x : y;
4381 }
4382 
4383 // ---------------------------------------------------------------------------
4384 // ---------------------------------------------------------------------------
4385 
4386 inline double TTubo::Minimo(double x, double y) {
4387  return x > y ? y : x;
4388 }
4389 
4390 // ---------------------------------------------------------------------------
4391 // ---------------------------------------------------------------------------
4392 
4393 void TTubo::AjustaPaso(double TimeEndStep) {
4394 #ifdef usetry
4395  try {
4396 #endif
4397  FTime1 = TimeEndStep;
4398  FDeltaTime = FTime1 - FTime0;
4399 #ifdef usetry
4400  } catch(exception & N) {
4401  std::cout << "ERROR: TTubo::AjustaPaso en el tubo: " << FNumeroTubo << std::endl;
4402  std::cout << "Tipo de error: " << N.what() << std::endl;
4403  throw Exception(N.what());
4404  }
4405 #endif
4406 }
4407 
4408 // ---------------------------------------------------------------------------
4409 // ---------------------------------------------------------------------------
4410 
4412 #ifdef usetry
4413  try {
4414 #endif
4415 
4416  if(FVelocidad0[0] <= 0) {
4417  BC[FNodoIzq - 1]->PutEntropia(FTuboCCNodoIzq,
4418  Interpola_Entropia(BC[FNodoIzq - 1]->GetTuboExtremo(FTuboCCNodoIzq).TipoExtremo, DeltaTiempo));
4419  }
4420  BC[FNodoIzq - 1]->PutBeta(FTuboCCNodoIzq,
4421  Interpola_Caracteristica(BC[FNodoIzq - 1]->GetTuboExtremo(FTuboCCNodoIzq).Entropia, 1, 0, DeltaTiempo));
4422 
4423  if(FVelocidad0[FNin - 1] >= 0) {
4424  BC[FNodoDer - 1]->PutEntropia(FTuboCCNodoDer,
4425  Interpola_Entropia(BC[FNodoDer - 1]->GetTuboExtremo(FTuboCCNodoDer).TipoExtremo, DeltaTiempo));
4426  }
4427  BC[FNodoDer - 1]->PutLanda(FTuboCCNodoDer,
4428  Interpola_Caracteristica(BC[FNodoDer - 1]->GetTuboExtremo(FTuboCCNodoDer).Entropia, -1, getNin() - 1, DeltaTiempo));
4429 #ifdef usetry
4430  } catch(exception & N) {
4431  std::cout << "ERROR: TTubo::CalculaCaracteristicasExtremos en el tubo: " << FNumeroTubo << std::endl;
4432  std::cout << "Tipo de error: " << N.what() << std::endl;
4433  throw Exception(N.what());
4434  }
4435 #endif
4436 }
4437 
4438 // ---------------------------------------------------------------------------
4439 // ---------------------------------------------------------------------------
4440 
4441 double TTubo::Interpola_Entropia(nmPipeEnd TipoExtremoTubo, double DeltaTiempo) {
4442 #ifdef usetry
4443  try {
4444 #endif
4445 
4446  int signo = 1;
4447  int extremo = 0;
4448  int indiceCC = 0;
4449 
4450  if(TipoExtremoTubo == nmRight) { // PipeEnd Derecho
4451  signo = -1;
4452  extremo = FNin - 1;
4453  indiceCC = 1;
4454  }
4455  double dtdx = DeltaTiempo / FXref;
4456  int ind = extremo;
4457  double entropia = 0.;
4458  double velocidadp = 0.;
4459  double asonidop = 0.;
4460 
4461  if(DeltaTiempo < 1e-15 || DoubEqZero(FVelocidadDim[extremo])) {
4462 
4463  Calculo_Entropia(entropia, velocidadp, extremo, 0., signo, DeltaTiempo, indiceCC);
4464 
4465  } else {
4466  int ind1 = ind + signo;
4467 
4468  stPathOrigin PathOrigin(FU0[0][ind], FU0[1][ind], FU0[0][ind1], FU0[1][ind1], dtdx, signo);
4469 
4470  double dist = zbrent(PathOrigin, 0., 1., 1e-5);
4471 
4472  Calculo_Entropia(entropia, velocidadp, ind, dist, signo, DeltaTiempo, indiceCC);
4473 
4474  }
4475 
4476  return entropia / __cons::ARef;
4477 #ifdef usetry
4478  } catch(exception & N) {
4479  std::cout << "ERROR: TTubo::Interpola_Entropia: " << std::endl;
4480  std::cout << "Tipo de error: " << N.what() << std::endl;
4481  throw Exception(N.what());
4482  }
4483 #endif
4484 }
4485 
4486 // ---------------------------------------------------------------------------
4487 // ---------------------------------------------------------------------------
4488 
4489 void TTubo::Calculo_Entropia(double& entropia, double& velocidadp, int ind, double dist, int signo, double DeltaTiempo,
4490  int indiceCC) {
4491 #ifdef usetry
4492  try {
4493 #endif
4494 
4495  int ind1 = ind + signo;
4496 
4497  double w0 = FU0[0][ind];
4498  double w1 = FU0[1][ind];
4499  double w2 = FU0[2][ind];
4500  double gammap = FGamma[ind];
4501  double Rmezclap = FRMezcla[ind];
4502  double diamep = FDiametroTubo[ind];
4503 
4504  double tptubop = FTPTubo[0][ind];
4505  double hip = Fhi[ind];
4506  double rhop = Frho[ind];
4507  double Rep = FRe[ind];
4508 
4509  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
4510  FFraccionMasicaCC[indiceCC][j] = FFraccionMasicaEspecie[ind][j];
4511  }
4512 
4513  if(dist > 0. || dist < 1.) {
4514  w0 = Interpola(FU0[0][ind], FU0[0][ind1], 1., dist);
4515  w1 = Interpola(FU0[1][ind], FU0[1][ind1], 1., dist);
4516  w2 = Interpola(FU0[2][ind], FU0[2][ind1], 1., dist);
4517  gammap = Interpola(FGamma[ind], FGamma[ind1], 1., dist);
4518  Rmezclap = Interpola(FRMezcla[ind], FRMezcla[ind1], 1., dist);
4519  diamep = Interpola(FDiametroTubo[ind], FDiametroTubo[ind1], 1., dist);
4520  if(FCoefAjusTC != 0 || FCoefAjusFric != 0) {
4521  tptubop = Interpola(FTPTubo[0][ind], FTPTubo[0][ind1], 1., dist);
4522  hip = Interpola(Fhi[ind], Fhi[ind1], 1., dist);
4523  Rep = Interpola(FRe[ind], FRe[ind1], 1., dist);
4524  }
4525 
4526  for(int j = 0; j < FNumeroEspecies - FIntEGR; j++) {
4527  FFraccionMasicaCC[indiceCC][j] = Interpola(FFraccionMasicaEspecie[ind][j], FFraccionMasicaEspecie[ind1][j], 1., dist);
4528  }
4529  }
4530 
4531  double gamma1p = __Gamma::G1(gammap);
4532  double gamma3p = __Gamma::G3(gammap);
4533  double gamma5p = __Gamma::G5(gammap);
4534  velocidadp = w1 / w0;
4535  rhop = w0 / __geom::Circle_area(diamep);
4536  double asonidop = sqrt(gammap * gamma1p * (w2 / w0 - pow2(velocidadp) / 2));
4537  double presionp = __units::PaToBar((w2 - pow2(w1) / 2. / w0) * gamma1p / __geom::Circle_area(diamep));
4538  double entropiap = asonidop / pow(presionp, gamma5p);
4539  entropia = entropiap;
4540 
4541  FAreaCC[indiceCC] = FArea[ind];
4542  FDensidadCC[indiceCC] = rhop;
4543  FVelocidadCC[indiceCC] = velocidadp; // Se que no hace falta hacerlo asi,pero me queda más ordenado.
4544 
4545  /* variacion de la entropia debida a la transmision del calor */
4546  /* ------------------------------------------ */
4547  if(!DoubEqZero(FCoefAjusTC)) {
4548 
4549  double q = 0;
4550  double tgasp = pow2(asonidop) / (gammap * Rmezclap);
4551 
4552  TransmisionCalor(tgasp, diamep, q, hip, rhop, tptubop);
4553 
4554  // Las siguientes expresiones estan en la Tesis de Corberan. Pagina 23
4555  double dacal = gamma3p * entropiap * q * FCoefAjusTC * DeltaTiempo / pow2(asonidop);
4556 
4557  entropia += dacal;
4558  }
4559 
4560  /* variacion de la entropia debida al termino de friccion */
4561  /* --------------------------------------- */
4562  if(!DoubEqZero(velocidadp) && !DoubEqZero(FCoefAjusFric)) {
4563 
4564  double f = 0.;
4565  double velabs = fabs(velocidadp);
4566  Colebrook(FFriccion, diamep, f, Rep);
4567  double dafric = gamma1p * FCoefAjusFric * f * entropiap * pow3(velabs) * DeltaTiempo / (diamep * pow2(asonidop));
4568  entropia += dafric;
4569  }
4570 #ifdef usetry
4571  }
4572 
4573  catch(exception & N) {
4574  std::cout << "ERROR: TTubo::Calculo_Entropia " << FNumeroTubo << std::endl;
4575  std::cout << "Tipo de error: " << N.what() << std::endl;
4576  throw Exception(N.what());
4577  }
4578 #endif
4579 }
4580 
4581 // ---------------------------------------------------------------------------
4582 // ---------------------------------------------------------------------------
4583 
4584 double TTubo::Interpola_Caracteristica(double entropia, int signo, int extremo, double DeltaTiempo) {
4585 #ifdef usetry
4586  try {
4587 #endif
4588 
4589  double dtdx = DeltaTiempo / FXref;
4590  int ind = extremo;
4591  double caracteristica = 0.;
4592  double velocidadp = 0.;
4593  double asonidop = 0.;
4594 
4595  if(DeltaTiempo < 1e-15) {
4596  Calculo_Caracteristica(caracteristica, velocidadp, asonidop, ind, 0., signo, entropia, DeltaTiempo);
4597  } else {
4598 
4599  dtdx = DeltaTiempo / FXref;
4600 
4601  int ind1 = ind + signo;
4602 
4603  stCharOrigin CharOrigin(FU0[0][ind], FU0[1][ind], FU0[2][ind], FU0[0][ind1], FU0[1][ind1], FU0[2][ind1], FGamma[ind],
4604  FGamma[ind1], dtdx, signo);
4605 
4606  double dist = zbrent(CharOrigin, 0., 1., 1e-5);
4607 
4608  Calculo_Caracteristica(caracteristica, velocidadp, asonidop, ind, dist, signo, entropia, DeltaTiempo);
4609  }
4610  return caracteristica / __cons::ARef;
4611 #ifdef usetry
4612  } catch(exception & N) {
4613  std::cout << "ERROR: TTubo::Interpola_Caracteristica " << FNumeroTubo << std::endl;
4614  std::cout << "Tipo de error: " << N.what() << std::endl;
4615  throw Exception(N.what());
4616  }
4617 #endif
4618 }
4619 
4620 // ---------------------------------------------------------------------------
4621 // ---------------------------------------------------------------------------
4622 
4623 void TTubo::Calculo_Caracteristica(double& caracteristica, double& velocidadp, double& asonidop, int ind, double dist,
4624  int signo, double entropia, double DeltaTiempo) {
4625 #ifdef usetry
4626  try {
4627 #endif
4628 
4629  int ind1 = ind + signo;
4630 
4631  double w0 = FU0[0][ind];
4632  double w1 = FU0[1][ind];
4633  double w2 = FU0[2][ind];
4634  double gammap = FGamma[ind];
4635  double Rmezclap = FRMezcla[ind];
4636  double diamep = FDiametroTubo[ind];
4637 
4638  double tptubop = FTPTubo[0][ind];
4639  double hip = Fhi[ind];
4640  double rhop = Frho[ind];
4641  double Rep = FRe[ind];
4642 
4643  if(dist < 1. && dist > 0) {
4644 
4645  w0 = Interpola(FU0[0][ind], FU0[0][ind1], 1., dist);
4646  w1 = Interpola(FU0[1][ind], FU0[1][ind1], 1., dist);
4647  w2 = Interpola(FU0[2][ind], FU0[2][ind1], 1., dist);
4648  gammap = Interpola(FGamma[ind], FGamma[ind1], 1., dist);
4649  Rmezclap = Interpola(FRMezcla[ind], FRMezcla[ind1], 1., dist);
4650  diamep = Interpola(FDiametroTubo[ind], FDiametroTubo[ind1], 1., dist);
4651  if(FCoefAjusTC != 0 || FCoefAjusFric != 0) {
4652  tptubop = Interpola(FTPTubo[0][ind], FTPTubo[0][ind1], 1., dist);
4653  hip = Interpola(Fhi[ind], Fhi[ind1], 1., dist);
4654  rhop = Interpola(Frho[ind], Frho[ind1], 1., dist);
4655  Rep = Interpola(FRe[ind], FRe[ind1], 1., dist);
4656  }
4657 
4658  }
4659  double gamma1p = __Gamma::G1(gammap);
4660  double gamma3p = __Gamma::G3(gammap);
4661  double gamma5p = __Gamma::G5(gammap);
4662  velocidadp = w1 / w0;
4663  asonidop = sqrt(gammap * gamma1p * (w2 / w0 - pow2(velocidadp) / 2));
4664  caracteristica = asonidop - signo * gamma3p * velocidadp;
4665 
4666  // Las siguientes expresiones se pueden encontrar en la Tesis de Corberan
4667  // Pagina 22
4668  /* variacion debida a la transmision del calor */
4669  /* ------------------------------------------ */
4670  if(FCoefAjusTC != 0) {
4671 
4672  double q = 0;
4673 
4674  double tgasp = pow2(asonidop) / (gammap * Rmezclap);
4675 
4676  TransmisionCalor(tgasp, diamep, q, hip, rhop, tptubop);
4677 
4678  double dacal = gamma3p * gamma1p * DeltaTiempo * q * FCoefAjusTC / asonidop;
4679 
4680  caracteristica += dacal;
4681 
4682  }
4683  /* variacion debida a la variacion entropia */
4684  /* ---------------------------------------- */
4685 
4686  double presionp = __units::PaToBar((w2 - pow2(w1) / 2. / w0) * gamma1p / __geom::Circle_area(diamep));
4687  double entropiap = asonidop / pow(presionp, gamma5p);
4688  double increentropia = entropia * __cons::ARef - entropiap;
4689  double daen = asonidop * increentropia / entropiap;
4690  caracteristica += daen;
4691 
4692  /* variacion debida al cambio de seccion */
4693  /* ------------------------------------- */
4694  if(FDiametroTubo[ind1] != FDiametroTubo[ind]) {
4695  double daar = 0.;
4696  if(signo == 1) {
4697  daar = -gamma3p * asonidop * velocidadp * 2 * (FDiametroTubo[ind1] - FDiametroTubo[ind]) * DeltaTiempo /
4698  (diamep * FXref);
4699  } else if(signo == -1) {
4700  daar = -gamma3p * asonidop * velocidadp * 2 * (FDiametroTubo[ind] - FDiametroTubo[ind1]) * DeltaTiempo /
4701  (diamep * FXref);
4702  }
4703  caracteristica += daar;
4704  }
4705 
4706  /* variacion debida al termino de friccion */
4707  /* --------------------------------------- */
4708 
4709  if(velocidadp != 0. && FCoefAjusFric != 0.) {
4710 
4711  double velabs = fabs(velocidadp);
4712  double f = 0;
4713 
4714  Colebrook(FFriccion, diamep, f, Rep);
4715 
4716  double dafric = signo * gamma1p * (1. + signo * gamma1p * velocidadp / asonidop) * f * FCoefAjusFric * pow3(
4717  velocidadp) * DeltaTiempo / (diamep * velabs);
4718 
4719  caracteristica += dafric;
4720  }
4721 
4722 #ifdef usetry
4723  } catch(exception & N) {
4724  std::cout << "ERROR: TTubo::Calculo_Caracteristica " << FNumeroTubo << std::endl;
4725  std::cout << "Tipo de error: " << N.what() << std::endl;
4726  throw Exception(N.what());
4727  }
4728 #endif
4729 }
4730 
4731 // ---------------------------------------------------------------------------
4732 // ---------------------------------------------------------------------------
4733 
4735 #ifdef usetry
4736  try {
4737 #endif
4738 
4739  BC[FNodoIzq - 1]->PutLanda(FTuboCCNodoIzq, FAsonido0[0] + FGamma3[0] * FVelocidad0[0]);
4740  BC[FNodoIzq - 1]->PutBeta(FTuboCCNodoIzq, FAsonido0[0] - FGamma3[0] * FVelocidad0[0]);
4741  BC[FNodoIzq - 1]->PutEntropia(FTuboCCNodoIzq, FAsonido0[0] / pow(FPresion0[0], FGamma5[0]));
4742 
4743  BC[FNodoDer - 1]->PutLanda(FTuboCCNodoDer, FAsonido0[FNin - 1] + FGamma3[FNin - 1] * FVelocidad0[FNin - 1]);
4744  BC[FNodoDer - 1]->PutBeta(FTuboCCNodoDer, FAsonido0[FNin - 1] - FGamma3[FNin - 1] * FVelocidad0[FNin - 1]);
4745  BC[FNodoDer - 1]->PutEntropia(FTuboCCNodoDer, FAsonido0[FNin - 1] / pow(FPresion0[FNin - 1], FGamma5[FNin - 1]));
4746 #ifdef usetry
4747  } catch(exception & N) {
4748  std::cout << "ERROR: TTubo::InicializaCaracteristicas tubo:" << FNumeroTubo << std::endl;
4749  std::cout << "Tipo de error: " << N.what() << std::endl;
4750  throw Exception(N.what());
4751  }
4752 #endif
4753 }
4754 
4755 // ---------------------------------------------------------------------------
4756 // ---------------------------------------------------------------------------
4757 
4758 void TTubo::CalculaB() {
4759 #ifdef usetry
4760  try {
4761 #endif
4762  double v = 0., p = 0., f = 0., tgas = 0., g = 0., q = 0., diamemed = 0., Rm = 0., Rm1 = 0.;
4763  double Remed, gamma, gamma1, Rmed, himed, rhomed, twallmed, Vmed, H1, H2, Hmed, Amed, rhoAmed;
4764 
4765  for(int i = 0; i < FNin - 1; i++) {
4766 
4767  FTVD.Bvector[0][i] = 0.;
4768 
4769  FTVD.Bvector[1][i] = 0.;
4770 
4771  FTVD.Bvector[2][i] = 0.;
4772 
4773  if(FArea[i] != FArea[i + 1] || FCoefAjusFric != 0 || FCoefAjusTC != 0) {
4774 
4775  Rm = sqrtRhoA[i + 1] / sqrtRhoA[i + 1];
4776  Rm1 = Rm + 1;
4777  gamma = (Rm * FGamma[i + 1] + FGamma[i]) / Rm1;
4778  gamma1 = gamma - 1;
4779  // gamma2 = gamma1 / 2;
4780 
4781  Vmed = (Rm * FVelocidadDim[i + 1] + FVelocidadDim[i]) / Rm1;
4782 
4783  if(FArea[i] != FArea[i + 1] || FCoefAjusTC != 0) {
4784 
4785  H1 = 0.5 * FVelocidadDim[i] * FVelocidadDim[i] + FAsonidoDim[i] * FAsonidoDim[i] / gamma1;
4786  H2 = 0.5 * FVelocidadDim[i + 1] * FVelocidadDim[i + 1] + FAsonidoDim[i + 1] * FAsonidoDim[i + 1] / gamma1;
4787  Hmed = (Rm * H2 + H1) / Rm1;
4788  Amed = sqrt(gamma1 * (Hmed - 0.5 * Vmed * Vmed));
4789  rhomed = sqrt(Frho[i] * Frho[i + 1]);
4790 
4791  }
4792  if(FCoefAjusFric != 0 || FCoefAjusTC != 0) {
4793  rhoAmed = sqrtRhoA[i + 1] * sqrtRhoA[i + 1];
4794  }
4795 
4796  if(FArea[i] != FArea[i + 1]) {
4797  FTVD.Bvector[1][i] += rhomed * Amed * Amed / gamma * (FArea[i] - FArea[i + 1]);
4798  }
4799 
4800  if(FCoefAjusFric != 0) {
4801  Remed = 0.5 * (FRe[i] + FRe[i + 1]);
4802  if(Remed > 1e-6) {
4803  Colebrook(FFriccion, FDiametroD12[i], f, Remed);
4804  if(Vmed >= 0.)
4805  g = f * Vmed * Vmed * 2 / FDiametroD12[i] * FCoefAjusFric;
4806  else
4807  g = -f * Vmed * Vmed * 2 / FDiametroD12[i] * FCoefAjusFric;
4808 
4809  FTVD.Bvector[1][i] += FXref * g * rhoAmed;
4810  }
4811  }
4812 
4813  if(FCoefAjusTC != 0) {
4814  Rmed = 0.5 * (FRMezcla[i] + FRMezcla[i + 1]);
4815  himed = 0.5 * (Fhi[i] + Fhi[i + 1]);
4816  twallmed = 0.5 * (FTPTubo[0][i] + FTPTubo[0][i + 1]);
4817 
4818  tgas = Amed * Amed / gamma / Rmed;
4819 
4820  TransmisionCalor(tgas, FDiametroD12[i], q, himed, rhomed, twallmed);
4821 
4822  q = q * FCoefAjusTC;
4823 
4824  FTVD.Bvector[2][i] = -FXref * q * rhoAmed;
4825 
4826  }
4827 
4828  }
4829 
4830  }
4831 #ifdef usetry
4832  } catch(exception & N) {
4833  std::cout << "ERROR: TTubo::CalculaB tubo:" << FNumeroTubo << std::endl;
4834  std::cout << "Tipo de error: " << N.what() << std::endl;
4835  throw Exception(N.what());
4836  }
4837 #endif
4838 }
4839 
4840 // ---------------------------------------------------------------------------
4841 // ---------------------------------------------------------------------------
4842 
4843 void TTubo::CalculaBmen() {
4844 #ifdef usetry
4845  try {
4846 #endif
4847  double v, p, f, tgas, g, q, diamemed, B, Rm, Rm1, gamma, gamma1, Vmed, Amed, H1, H2, Hmed, rhoAmed;
4848  double Remed = 0., Rmed = 0., himed = 0., rhomed = 0., twallmed = 0.;
4849 
4850  for(int i = 1; i < FNin; i++) {
4851 
4852  FTVD.Bmen[0][i] = 0.;
4853 
4854  FTVD.Bmen[1][i] = 0.;
4855 
4856  FTVD.Bmen[2][i] = 0.;
4857 
4858  if(FArea[i] != FArea12[i - 1] || FCoefAjusFric != 0 || FCoefAjusTC != 0) {
4859 
4860  rhoAmed = sqrt(sqrtRhoA[i - 1] * pow3(sqrtRhoA[i]));
4861  B = FU0[0][i] + rhoAmed + sqrtRhoA[i] * sqrtRhoA[i - 1];
4862  Rm = B / sqrt(pow3(sqrtRhoA[i - 1]) * sqrtRhoA[i]);
4863  Rm1 = Rm + 1;
4864  gamma = (Rm * FGamma[i] + FGamma[i - 1]) / Rm1;
4865  gamma1 = gamma - 1;
4866  // gamma2 = gamma1 / 2;
4867 
4868  Vmed = (Rm * FVelocidadDim[i] + FVelocidadDim[i - 1]) / Rm1;
4869 
4870  if(FArea[i] != FArea12[i - 1] || FCoefAjusTC != 0) {
4871 
4872  H1 = 0.5 * FVelocidadDim[i] * FVelocidadDim[i] + FAsonidoDim[i] * FAsonidoDim[i] / gamma1;
4873  H2 = 0.5 * FVelocidadDim[i - 1] * FVelocidadDim[i - 1] + FAsonidoDim[i - 1] * FAsonidoDim[i - 1] / gamma1;
4874  Hmed = (Rm * H1 + H2) / Rm1;
4875  Amed = sqrt(gamma1 * (Hmed - 0.5 * Vmed * Vmed));
4876  rhomed = sqrt(Frho[i] * sqrt(Frho[i] * Frho[i - 1]));
4877 
4878  }
4879  if(FCoefAjusFric != 0 || FCoefAjusTC != 0) {
4880 
4881  diamemed = 0.75 * FDiametroTubo[i] + 0.25 * FDiametroTubo[i - 1];
4882  }
4883 
4884  if(FArea[i] != FArea12[i - 1]) {
4885  FTVD.Bmen[1][i] += rhomed * Amed * Amed / gamma * (FArea12[i - 1] - FArea[i]);
4886  }
4887 
4888  if(FCoefAjusFric != 0) {
4889  Remed = (Rm * FRe[i] + FRe[i - 1]) / Rm1;
4890  if(Remed > 1e-6) {
4891  Colebrook(FFriccion, diamemed, f, Remed);
4892  if(Vmed >= 0.)
4893  g = f * Vmed * Vmed * 2 / diamemed * FCoefAjusFric;
4894  else
4895  g = -f * Vmed * Vmed * 2 / diamemed * FCoefAjusFric;
4896 
4897  FTVD.Bmen[1][i] += FXref * g * rhoAmed;
4898  }
4899  }
4900 
4901  if(FCoefAjusTC != 0) {
4902  Rmed = (Rm * FRMezcla[i] + FRMezcla[i - 1]) / Rm1;
4903  himed = (Rm * Fhi[i] + Fhi[i - 1]) / Rm1;
4904  twallmed = (Rm * FTPTubo[0][i] + FTPTubo[0][i - 1]) / Rm1;
4905 
4906  tgas = Amed * Amed / gamma / Rmed;
4907 
4908  TransmisionCalor(tgas, diamemed, q, himed, rhomed, twallmed);
4909 
4910  q = q * FCoefAjusTC;
4911 
4912  FTVD.Bmen[2][i] = -FXref * q * rhoAmed;
4913 
4914  }
4915 
4916  }
4917  }
4918 
4919 #ifdef usetry
4920  } catch(exception & N) {
4921  std::cout << "ERROR: TTubo::CalculaBmen tubo:" << FNumeroTubo << std::endl;
4922  std::cout << "Tipo de error: " << N.what() << std::endl;
4923  throw Exception(N.what());
4924  }
4925 #endif
4926 }
4927 
4928 // ---------------------------------------------------------------------------
4929 // ---------------------------------------------------------------------------
4930 
4931 void TTubo::CalculaBmas() {
4932 #ifdef usetry
4933  try {
4934 #endif
4935  double v, p, f, tgas, g, q, diamemed, B, Rm, Rm1, gamma, gamma1, Vmed, Amed, H1, H2, Hmed, rhoAmed;
4936  double Remed = 0., Rmed = 0., himed = 0., rhomed = 0., twallmed = 0.;
4937 
4938  for(int i = 0; i < FNin - 1; i++) {
4939 
4940  FTVD.Bmas[0][i] = 0.;
4941 
4942  FTVD.Bmas[1][i] = 0.;
4943 
4944  FTVD.Bmas[2][i] = 0.;
4945 
4946  if(FArea[i] != FArea12[i] || FCoefAjusFric != 0 || FCoefAjusTC != 0) {
4947 
4948  rhoAmed = sqrt(sqrtRhoA[i + 1] * pow3(sqrtRhoA[i]));
4949  B = FU0[0][i] + rhoAmed + sqrtRhoA[i] * sqrtRhoA[i + 1];
4950  Rm = B / sqrt(pow3(sqrtRhoA[i + 1]) * sqrtRhoA[i]);
4951  Rm1 = Rm + 1;
4952  gamma = (Rm * FGamma[i] + FGamma[i + 1]) / Rm1;
4953  gamma1 = gamma - 1;
4954  // gamma2 = gamma1 / 2;
4955 
4956  Vmed = (Rm * FVelocidadDim[i] + FVelocidadDim[i + 1]) / Rm1;
4957 
4958  if(FArea[i] != FArea12[i] || FCoefAjusTC != 0) {
4959 
4960  H1 = 0.5 * FVelocidadDim[i] * FVelocidadDim[i] + FAsonidoDim[i] * FAsonidoDim[i] / gamma1;
4961  H2 = 0.5 * FVelocidadDim[i + 1] * FVelocidadDim[i + 1] + FAsonidoDim[i + 1] * FAsonidoDim[i + 1] / gamma1;
4962  Hmed = (Rm * H1 + H2) / Rm1;
4963  Amed = sqrt(gamma1 * (Hmed - 0.5 * Vmed * Vmed));
4964  rhomed = sqrt(Frho[i] * sqrt(Frho[i] * Frho[i + 1]));
4965 
4966  }
4967  if(FCoefAjusFric != 0 || FCoefAjusTC != 0) {
4968 
4969  diamemed = 0.75 * FDiametroTubo[i] + 0.25 * FDiametroTubo[i + 1];
4970  }
4971 
4972  if(FArea[i] != FArea12[i]) {
4973  FTVD.Bmas[1][i] += rhomed * Amed * Amed / gamma * (FArea[i] - FArea12[i]);
4974  }
4975 
4976  if(FCoefAjusFric != 0) {
4977  Remed = (Rm * FRe[i] + FRe[i + 1]) / Rm1;
4978  if(Remed > 1e-6) {
4979  Colebrook(FFriccion, diamemed, f, Remed);
4980  if(Vmed >= 0.)
4981  g = f * Vmed * Vmed * 2 / diamemed * FCoefAjusFric;
4982  else
4983  g = -f * Vmed * Vmed * 2 / diamemed * FCoefAjusFric;
4984 
4985  FTVD.Bmas[1][i] += FXref * g * rhoAmed;
4986  }
4987  }
4988 
4989  if(FCoefAjusTC != 0) {
4990  Rmed = (Rm * FRMezcla[i] + FRMezcla[i + 1]) / Rm1;
4991  himed = (Rm * Fhi[i] + Fhi[i + 1]) / Rm1;
4992  twallmed = (Rm * FTPTubo[0][i] + FTPTubo[0][i + 1]) / Rm1;
4993 
4994  tgas = Amed * Amed / gamma / Rmed;
4995 
4996  TransmisionCalor(tgas, diamemed, q, himed, rhomed, twallmed);
4997 
4998  q = q * FCoefAjusTC;
4999 
5000  FTVD.Bmas[2][i] = -FXref * q * rhoAmed;
5001 
5002  }
5003 
5004  }
5005 
5006  }
5007 #ifdef usetry
5008  } catch(exception & N) {
5009  std::cout << "ERROR: TTubo::CalculaBmas tubo:" << FNumeroTubo << std::endl;
5010  std::cout << "Tipo de error: " << N.what() << std::endl;
5011  throw Exception(N.what());
5012  }
5013 #endif
5014 }
5015 
5016 // ---------------------------------------------------------------------------
5017 // ---------------------------------------------------------------------------
5018 
5019 void TTubo::CalculaMatrizJacobiana() {
5020 #ifdef usetry
5021  try {
5022 #endif
5023  double Rmed = 0., Vmed = 0., Vmed2 = 0., Hmed = 0., Amed = 0., Amed2 = 0., gamma = 0., H1 = 0., H2 = 0., Rmed1 = 0.;
5024  double *Ymed, gamma1, gamma2, gaAmed2;
5025 
5026  Ymed = new double[FNumeroEspecies - 1 - FIntEGR];
5027 
5028  for(int i = 0; i < FNin - 1; i++) {
5029 
5030  RoeConstants();
5031 
5032  // Calculo de las medias de Roe
5033  Rmed = sqrtRhoA[i + 1] / sqrtRhoA[i + 1];
5034  Rmed1 = Rmed + 1;
5035  gamma = (Rmed * FGamma[i + 1] + FGamma[i]) / Rmed1;
5036  gamma1 = gamma - 1;
5037  gamma2 = gamma1 / 2;
5038  H1 = 0.5 * FVelocidadDim[i] * FVelocidadDim[i] + FAsonidoDim[i] * FAsonidoDim[i] / gamma1;
5039  H2 = 0.5 * FVelocidadDim[i + 1] * FVelocidadDim[i + 1] + FAsonidoDim[i + 1] * FAsonidoDim[i + 1] / gamma1;
5040  Vmed = (Rmed * FVelocidadDim[i + 1] + FVelocidadDim[i]) / Rmed1;
5041  Vmed2 = Vmed * Vmed;
5042  Hmed = (Rmed * H2 + H1) / Rmed1;
5043  Amed2 = gamma1 * (Hmed - 0.5 * Vmed2);
5044  Amed = sqrt(Amed2);
5045  for(int j = 0; j < FNumeroEspecies - 1 - FIntEGR; j++) {
5046  Ymed[j] = (Rmed * FFraccionMasicaEspecie[i + 1][j] + FFraccionMasicaEspecie[i][j]) / Rmed1;
5047  }
5048 
5049  FTVD.Pmatrix[1][0][i] = Vmed - Amed;
5050  FTVD.Pmatrix[1][1][i] = Vmed;
5051  FTVD.Pmatrix[1][2][i] = Vmed + Amed;
5052 
5053  FTVD.Pmatrix[2][0][i] = Hmed - Vmed * Amed;
5054  FTVD.Pmatrix[2][1][i] = Vmed2 / 2.;
5055  FTVD.Pmatrix[2][2][i] = Hmed + Vmed * Amed;
5056 
5057  gaAmed2 = gamma2 / Amed2;
5058  // Calculo de la matriz Q (autovectores a la derecha)
5059  FTVD.Qmatrix[0][0][i] = (Vmed / Amed + gaAmed2 * Vmed2) / 2.;
5060  FTVD.Qmatrix[0][1][i] = -0.5 / Amed - gaAmed2 * Vmed;
5061  FTVD.Qmatrix[0][2][i] = gaAmed2;
5062 
5063  FTVD.Qmatrix[1][0][i] = 1. - gaAmed2 * Vmed2;
5064  FTVD.Qmatrix[1][1][i] = gamma1 * Vmed / Amed2;
5065  FTVD.Qmatrix[1][2][i] = -gamma1 / Amed2;
5066 
5067  FTVD.Qmatrix[2][0][i] = -(Vmed / Amed + gaAmed2 * Vmed2) / 2.;
5068  FTVD.Qmatrix[2][1][i] = 0.5 / Amed - gaAmed2 * Vmed;
5069  FTVD.Qmatrix[2][2][i] = gaAmed2;
5070 
5071  // Valores propios de la matriz jacobiana
5072  FTVD.Alpha[0][i] = FTVD.Pmatrix[1][0][i];
5073  FTVD.Alpha[1][i] = Vmed;
5074  FTVD.Alpha[2][i] = FTVD.Pmatrix[1][2][i];
5075 
5076  for(int j = 3; j < FNumEcuaciones; j++) {
5077  FTVD.Alpha[j][i] = (Vmed);
5078 
5079  }
5080  }
5081  delete[] Ymed;
5082 #ifdef usetry
5083  } catch(exception & N) {
5084  std::cout << "ERROR: TTubo::CalculaMatrizJacobiana tubo:" << FNumeroTubo << std::endl;
5085  std::cout << "Tipo de error: " << N.what() << std::endl;
5086  throw Exception(N.what());
5087  }
5088 #endif
5089 }
5090 
5091 // ---------------------------------------------------------------------------
5092 // ---------------------------------------------------------------------------
5093 
5094 void TTubo::TVD_Estabilidad() {
5095 #ifdef usetry
5096  try {
5097 #endif
5098  double VTotalMax = 0.;
5099  double VLocal = 0., DeltaT_tvd = 0.;
5100 
5101  CalculaFlujo(FU0, FTVD.W, FGamma, FGamma1, FNin);
5102 
5103  CalculaMatrizJacobiana();
5104 
5105  CalculaB();
5106 
5107  for(int i = 0; i < FNin - 1; i++) {
5108  for(int k = 0; k < 3; ++k) {
5109  FTVD.DeltaU[k][i] = FTVD.Qmatrix[k][0][i] * (FU0[0][i + 1] - FU0[0][i]) + FTVD.Qmatrix[k][1][i] *
5110  (FU0[1][i + 1] - FU0[1][i]) + FTVD.Qmatrix[k][2][i] * (FU0[2][i + 1] - FU0[2][i]);
5111  FTVD.DeltaB[k][i] = FTVD.Qmatrix[k][0][i] * FTVD.Bvector[0][i] + FTVD.Qmatrix[k][1][i] * FTVD.Bvector[1][i] +
5112  FTVD.Qmatrix[k][2][i] * FTVD.Bvector[2][i];
5113  FTVD.DeltaW[k][i] = FTVD.Qmatrix[k][0][i] * (FTVD.W[0][i + 1] - FTVD.W[0][i] + FTVD.Bvector[0][i]) +
5114  FTVD.Qmatrix[k][1][i] * (FTVD.W[1][i + 1] - FTVD.W[1][i] + FTVD.Bvector[1][i]) + FTVD.Qmatrix[k][2][i] *
5115  (FTVD.W[2][i + 1] - FTVD.W[2][i] + FTVD.Bvector[2][i]);
5116  if(fabs(FTVD.DeltaU[k][i]) < 1e-3) {
5117  FTVD.Beta[k][i] = FTVD.DeltaB[k][i] / 1e-3;
5118  } else {
5119  FTVD.Beta[k][i] = FTVD.DeltaB[k][i] / FTVD.DeltaU[k][i];
5120  }
5121  // if (FNumeroTubo == 63){
5122  // printf("%d ",k);
5123  // printf("%lf ", FTVD.DeltaB[k][i] );
5124  // printf("%lf ", FTVD.DeltaU[k][i] );
5125  // if(FTVD.DeltaU[k][i]!=0) printf("%lf ",FTVD.DeltaB[k][i] / FTVD.DeltaU[k][i] );
5126  // printf("\n ");
5127  // }
5128  if(FTVD.Alpha[k][i] + FTVD.Beta[k][i] != 0) {
5129  if((VLocal = fabs(FTVD.Alpha[k][i]) + fabs(FTVD.Beta[k][i])) > VTotalMax) {
5130  VTotalMax = VLocal;
5131  }
5132  }
5133  }
5134  for(int k = 3; k < FNumEcuaciones; k++) {
5135  FTVD.Beta[k][i] = 0.;
5136  }
5137  }
5138  DeltaT_tvd = FCourant * FXref / VTotalMax;
5139  if(DeltaT_tvd < FDeltaTime)
5140  FDeltaTime = DeltaT_tvd;
5141 #ifdef usetry
5142  } catch(exception & N) {
5143  std::cout << "ERROR: TTubo::TVD_Estabilidad tubo:" << FNumeroTubo << std::endl;
5144  std::cout << "Tipo de error: " << N.what() << std::endl;
5145  throw Exception(N.what());
5146  }
5147 #endif
5148 }
5149 
5150 // ---------------------------------------------------------------------------
5151 // ---------------------------------------------------------------------------
5152 
5153 void TTubo::TVD_Limitador() {
5154 #ifdef usetry
5155  try {
5156 #endif
5157  double dtdx = FDeltaTime / FXref;
5158 
5159  CalculaBmas();
5160 
5161  CalculaBmen();
5162 
5163  for(int i = 0; i < FNin - 1; ++i) {
5164  // Calculo de las variables en el sistema de coordenadas Q
5165  for(int k = 0; k < FNumEcuaciones; k++) {
5166  FTVD.LandaD[k][i] = dtdx * (FTVD.Alpha[k][i] + FTVD.Beta[k][i]);
5167  if(FTVD.LandaD[k][i] >= 0.) {
5168  FTVD.hLandaD[k][i] = 1;
5169  } else {
5170  FTVD.hLandaD[k][i] = -1;
5171  }
5172  }
5173  }
5174  for(int i = 1; i < FNin - 2; ++i) {
5175  for(int k = 0; k < 3; k++) {
5176  double den = (((double) FTVD.hLandaD[k][i] - FTVD.LandaD[k][i]) * FTVD.DeltaW[k][i]);
5177  double num = ((double) FTVD.hLandaD[k][i - FTVD.hLandaD[k][i]] - FTVD.LandaD[k][i - FTVD.hLandaD[k][i]]) *
5178  (FTVD.DeltaW[k][i - FTVD.hLandaD[k][i]]);
5179  if(fabs(den) > 1e-10)
5180  FTVD.R[k][i] = num / den;
5181  else
5182  FTVD.R[k][i] = 1;
5183  }
5184 
5185  for(int k = 3; k < FNumEcuaciones; k++) {
5186  double num = ((double) FTVD.hLandaD[k][i - FTVD.hLandaD[k][i]] - FTVD.LandaD[k][i - FTVD.hLandaD[k][i]]) *
5187  (FTVD.W[k][i + 1 - FTVD.hLandaD[k][i]] - FTVD.W[k][i - FTVD.hLandaD[k][i]]);
5188  double den = ((double) FTVD.hLandaD[k][i] - FTVD.LandaD[k][i]) * (FTVD.W[k][i + 1] - FTVD.W[k][i]);
5189  if(fabs(den) > 1e-10)
5190  FTVD.R[k][i] = num / den;
5191  else
5192  FTVD.R[k][i] = 1;
5193  }
5194  }
5195  for(int k = 0; k < FNumEcuaciones; k++) {
5196  FTVD.R[k][0] = FTVD.R[k][1];
5197  FTVD.R[k][FNin - 2] = FTVD.R[k][FNin - 3];
5198  }
5199  for(int i = 0; i < FNin - 1; ++i) {
5200  for(int k = 0; k < 3; k++) {
5201  FTVD.Phi[k][i] = (double) FTVD.hLandaD[k][i] - Limita(FTVD.R[k][i]) * ((double) FTVD.hLandaD[k][i] - FTVD.LandaD[k][i]);
5202  }
5203  }
5204 
5205  for(int i = 0; i < FNin - 1; ++i) {
5206  for(int k = 0; k < 3; ++k) {
5207  FTVD.gflux[k][i] = 0.5 * (FTVD.W[k][i] + FTVD.W[k][i + 1] - FTVD.Bmas[k][i] + FTVD.Bmen[k][i + 1] -
5208  (FTVD.Pmatrix[k][0][i] * FTVD.Phi[0][i] * FTVD.DeltaW[0][i] + FTVD.Pmatrix[k][1][i] * FTVD.Phi[1][i] * FTVD.DeltaW[1][i]
5209  + FTVD.Pmatrix[k][2][i] * FTVD.Phi[2][i] * FTVD.DeltaW[2][i]));
5210  }
5211  for(int k = 3; k < FNumEcuaciones; k++) {
5212  FTVD.gflux[k][i] = 0.5 * (FTVD.W[k][i] + FTVD.W[k][i + 1] - (double) FTVD.hLandaD[k][i] *
5213  (FTVD.W[k][i + 1] - FTVD.W[k][i])) + 0.5 * Limita(FTVD.R[k][i]) * ((double) FTVD.hLandaD[k][i] - FTVD.LandaD[k][i]) *
5214  (FTVD.W[k][i + 1] - FTVD.W[k][i]);
5215  }
5216 
5217  }
5218  for(int i = 1; i < FNin - 1; ++i) {
5219  for(int k = 0; k < FNumEcuaciones; k++) {
5220  FU1[k][i] = FU0[k][i] - dtdx * ((FTVD.gflux[k][i] - FTVD.gflux[k][i - 1]) + (FTVD.Bmen[k][i] + FTVD.Bmas[k][i]));
5221  }
5222  }
5223 #ifdef usetry
5224  } catch(exception & N) {
5225  std::cout << "ERROR: TTubo::TVD_Limitador tubo:" << FNumeroTubo << std::endl;
5226  std::cout << "Tipo de error: " << N.what() << std::endl;
5227  throw Exception(N.what());
5228  }
5229 #endif
5230 }
5231 
5232 // ---------------------------------------------------------------------------
5233 // ---------------------------------------------------------------------------
5234 
5235 inline double TTubo::Limita(double r) {
5236  double ret_val = 0.;
5237  // ------Van Albada
5238  // double ret_val=(r*r+r)/(1+r*r);
5239 
5240  // ------Van Leer
5241 
5242 #ifdef __BORLANDC__
5243  if(r != r)
5244  ret_val = 1;
5245  else
5246  ret_val = (fabs(r) + r) / (1. + fabs(r));
5247 
5248  if(ret_val != ret_val)
5249  ret_val = 1.;
5250 #else
5251  if(std::isnan(r)) {
5252  if(signbit(r))
5253  ret_val = 1;
5254  else
5255  ret_val = 1;
5256  } else
5257  ret_val = (fabs(r) + r) / (1. + fabs(r));
5258 
5259  if(std::isnan(ret_val)) {
5260  if(signbit(r))
5261  ret_val = 1;
5262  else
5263  ret_val = 1;
5264  }
5265 #endif
5266 
5267  // ------Minmod
5268  // double ret_val=Minimo(2*fabs(r),1.);
5269  // double ret_val1=Minimo(2*r,1.);
5270  // double ret_val=Maximo(0,ret_val1);
5271 
5272  // ------Limitador de Roe (minmod)
5273  // double ret_val1=Minimo(r,1);
5274  // double ret_val=Maximo(0,ret_val1);
5275 
5276  // ------Limitador Roe Superbee
5277  // double ret_val1=Minimo(2*r,1);
5278  // double ret_val2=Minimo(r,2);
5279  // double ret_val3=Maximo(0,ret_val1);
5280  // double ret_val=Maximo(ret_val2,ret_val3);
5281 
5282  // ------Limitador de Osher (phi=1.5)
5283  // double ret_val1=Minimo(r,2);
5284  // double ret_val=Maximo(0,ret_val1);
5285 
5286  // ------Limitador de Sweby (phi=1.5)
5287  // double ret_val1=Minimo(2*r,1);
5288  // double ret_val2=Minimo(r,2);
5289  // double ret_val3=Maximo(0,ret_val1);
5290  // double ret_val=Maximo(ret_val2,ret_val3);
5291 
5292  // ------Limitador de Ospre (WAterson & Deconinck)
5293  // double ret_val=1.5*(r*r+r)/(r*r+r+1.);
5294 
5295  // ------Limitador de MC de van Leer
5296  // double ret_val1=Minimo(0.5+0.5*r,2);
5297  // double ret_val2=Minimo(ret_val1,2*r);
5298  // double ret_val=Maximo(0,ret_val2);
5299 
5300  // ------Limitador de UMIST
5301  // double ret_val1=Minimo(0.75+0.25*r,2);
5302  // double ret_val2=Minimo(ret_val1,0.25+0.75*r);
5303  // double ret_val3=Minimo(ret_val2,2*r);
5304  // double ret_val=Maximo(0,ret_val3);
5305 
5306  // ------Limitador de Koren
5307  // double ret_val1=Minimo((1+2*r)/3,2);
5308  // double ret_val2=Minimo(ret_val1,2*r);
5309  // double ret_val=Maximo(0,ret_val2);
5310 
5311  return ret_val;
5312 
5313 }
5314 
5315 // ---------------------------------------------------------------------------
5316 // ---------------------------------------------------------------------------
5317 
5318 void TTubo::DimensionaTVD() {
5319 #ifdef usetry
5320  try {
5321 #endif
5322 
5323  FTVD.Bmas = new double*[FNumEcuaciones];
5324  FTVD.Bvector = new double*[FNumEcuaciones];
5325  FTVD.Bmen = new double*[FNumEcuaciones];
5326  FTVD.gflux = new double*[FNumEcuaciones];
5327  FTVD.Alpha = new double*[FNumEcuaciones];
5328  FTVD.Beta = new double*[FNumEcuaciones];
5329  FTVD.DeltaU = new double*[FNumEcuaciones];
5330  FTVD.DeltaB = new double*[FNumEcuaciones];
5331  FTVD.DeltaW = new double*[FNumEcuaciones];
5332  FTVD.hLandaD = new int*[FNumEcuaciones];
5333  FTVD.LandaD = new double*[FNumEcuaciones];
5334  FTVD.Phi = new double*[FNumEcuaciones];
5335  FTVD.R = new double*[FNumEcuaciones];
5336  FTVD.W = new double*[FNumEcuaciones];
5337  FTVD.Qmatrix = new double**[FNumEcuaciones];
5338  FTVD.Pmatrix = new double**[FNumEcuaciones];
5339 
5340  sqrtRhoA = new double[FNin];
5341 
5342  for(int k = 0; k < FNumEcuaciones; ++k) {
5343  FTVD.Bmas[k] = new double[FNin];
5344  FTVD.Bvector[k] = new double[FNin];
5345  FTVD.Bmen[k] = new double[FNin];
5346  FTVD.gflux[k] = new double[FNin];
5347  FTVD.Alpha[k] = new double[FNin];
5348  FTVD.Beta[k] = new double[FNin];
5349  FTVD.DeltaU[k] = new double[FNin];
5350  FTVD.DeltaB[k] = new double[FNin];
5351  FTVD.DeltaW[k] = new double[FNin];
5352  FTVD.hLandaD[k] = new int[FNin];
5353  FTVD.LandaD[k] = new double[FNin];
5354  FTVD.Phi[k] = new double[FNin];
5355  FTVD.R[k] = new double[FNin];
5356  FTVD.W[k] = new double[FNin];
5357  }
5358 
5359  for(int k = 0; k < FNumEcuaciones; ++k) {
5360  FTVD.Qmatrix[k] = new double*[FNumEcuaciones];
5361  FTVD.Pmatrix[k] = new double*[FNumEcuaciones];
5362 
5363  for(int i = 0; i < FNumEcuaciones; i++) {
5364  FTVD.Qmatrix[k][i] = new double[FNin];
5365  FTVD.Pmatrix[k][i] = new double[FNin];
5366  }
5367  }
5368  for(int i = 0; i < FNin; i++) {
5369 
5370  for(int k = 3; k < FNumEcuaciones; k++) {
5371  for(int j = 3; j < FNumEcuaciones; j++) {
5372  FTVD.Pmatrix[k][j][i] = 0.;
5373  }
5374  }
5375  FTVD.Pmatrix[0][0][i] = 1.;
5376  FTVD.Pmatrix[0][1][i] = 1.;
5377  FTVD.Pmatrix[0][2][i] = 1.;
5378  for(int j = 3; j < FNumEcuaciones; j++) {
5379  FTVD.Pmatrix[j][j][i] = 1.;
5380  }
5381 
5382  for(int k = 3; k < FNumEcuaciones; k++) {
5383  for(int j = 3; j < FNumEcuaciones; j++) {
5384  FTVD.Qmatrix[k][j][i] = 0.;
5385  }
5386  }
5387  for(int j = 3; j < FNumEcuaciones; j++) {
5388  FTVD.Qmatrix[j][j][i] = 1.;
5389  }
5390  }
5391 #ifdef usetry
5392  } catch(exception & N) {
5393  std::cout << "ERROR: TTubo::TVD_Limitador tubo:" << FNumeroTubo << std::endl;
5394  std::cout << "Tipo de error: " << N.what() << std::endl;
5395  throw Exception(N.what());
5396  }
5397 #endif
5398 }
5399 
5400 void TTubo::RoeConstants() {
5401 
5402  sqrtRhoA[0] = sqrt(FU1[0][0]);
5403  for(int i = 0; i < FNin - 1; i++) {
5404  sqrtRhoA[i + 1] = sqrt(FU1[0][i + 1]);
5405  }
5406 }
5407 
5408 double TTubo::GetArea(int i) const {
5409  return FArea[i];
5410 }
5411 
5412 double TTubo::GetAsonido(int i) const {
5413  return FAsonido0[i];
5414 }
5415 
5416 double TTubo::GetCoefTurbulencia(int i) const {
5417  return FCoefTurbulencia[i];
5418 }
5419 
5420 double TTubo::GetCpMezcla(int i) const {
5421  return FCpMezcla[i];
5422 }
5423 
5424 double TTubo::GetCvMezcla(int i) const {
5425  return FCvMezcla[i];
5426 }
5427 
5428 double TTubo::getDeltaTime() const {
5429  return FDeltaTime;
5430 }
5431 
5432 double TTubo::GetDensidad(int i) const {
5433  return Frho[i];
5434 }
5435 
5436 double TTubo::GetDiametro(int i) const {
5437  return FDiametroTubo[i];
5438 }
5439 
5440 double TTubo::GetFraccionMasicaInicial(int i) const {
5441  return FComposicionInicial[i];
5442 }
5443 
5444 double TTubo::GetGamma(int i) const {
5445  return FGamma[i];
5446 }
5447 
5448 double TTubo::getLongitudTotal() const {
5449  return FLongitudTotal;
5450 }
5451 
5452 double TTubo::getMallado() const {
5453  return FMallado;
5454 }
5455 
5456 int TTubo::getNodoDer() const {
5457  return FNodoDer;
5458 }
5459 
5460 int TTubo::getNodoIzq() const {
5461  return FNodoIzq;
5462 }
5463 
5465  return FNumeroTubo;
5466 }
5467 
5468 double TTubo::GetPresion(int i) const {
5469  return FPresion0[i];
5470 }
5471 
5473  return FPini;
5474 }
5475 
5476 double TTubo::GetRMezcla(int i) const {
5477  return FRMezcla[i];
5478 }
5479 
5481  return FTini;
5482 }
5483 
5484 double TTubo::getTempWallIni() const {
5485  return FTIniParedTub;
5486 }
5487 
5488 double TTubo::getTime0() const {
5489  return FTime0;
5490 }
5491 
5492 double TTubo::getTime1() const {
5493  return FTime1;
5494 }
5495 
5496 double TTubo::GetTPTubo(int j, int i) const {
5497  // j is the wall node and i is the cell
5498  return FTPTubo[j][i];
5499 }
5500 
5501 double TTubo::GetTPTuboAnt(int j, int i) const {
5502  return FTParedAnt[j][i];
5503 }
5504 
5505 double TTubo::GetVelocidad(int i) const {
5506  return FVelocidad0[i];
5507 }
5508 
5510  return FVelMedia;
5511 }
5512 
5513 double TTubo::GetVelPro(int i) const {
5514  return FVelPro[i];
5515 }
5516 
5517 void TTubo::PutDeltaTime(double valor) {
5518  FDeltaTime = valor;
5519 }
5520 
5521 void TTubo::PutTime0(double valor) {
5522  FTime0 = valor;
5523 }
5524 
5525 void TTubo::PutTime1(double valor) {
5526  FTime1 = valor;
5527 }
5528 
5529 void TTubo::PutTPTubo(int k, int i, double valor) {
5530  FTPTubo[k][i] = valor;
5531 }
5532 
5533 void TTubo::PutVelPro(int i, double valor) {
5534  FVelPro[i] = valor;
5535 }
5536 
5537 #pragma package(smart_init)
stEspecies
Definition: Globales.h:297
zbrent
double zbrent(T &func, const double &x1, const double &x2, const double &tol)
Solves a function using Brent's method.
Definition: Math_wam.h:352
TTubo::ActualizaValoresNuevos
void ActualizaValoresNuevos(TCondicionContorno **BC)
Definition: TTubo.cpp:2256
TTubo::getNodoDer
int getNodoDer() const
Gets the right-hand side node.
Definition: TTubo.cpp:5456
stPathOrigin
Definition: BoundaryFunctions.h:545
TTubo::CalculaVariablesFundamentales
void CalculaVariablesFundamentales()
Definition: TTubo.cpp:1550
TTubo::FTime1
double FTime1
Time at following time step.
Definition: TTubo.h:734
TTubo::CalculaCoeficientePeliculaExterior
void CalculaCoeficientePeliculaExterior(TBloqueMotor **Engine, double AmbientPressure, double AmbientTemperature)
Definition: TTubo.cpp:3349
pow075
T pow075(T x)
Returns x to the power of 0.75.
Definition: Math_wam.h:153
stCapa
Definition: Globales.h:1394
TTubo::getLongitudTotal
double getLongitudTotal() const
Gets the total length of the pipe.
Definition: TTubo.cpp:5448
pow150
T pow150(T x)
Returns x to the power of 1.5.
Definition: Math_wam.h:140
TTubo::getTemperaturaInicial
double getTemperaturaInicial() const
Gets the initial temperature.
Definition: TTubo.cpp:5480
TTubo::getTime1
double getTime1() const
Gets the time at the following time-step.
Definition: TTubo.cpp:5492
TTubo::GetGamma
double GetGamma(int i) const
Gets the specific heat capacities ratio at a given cell.
Definition: TTubo.cpp:5444
pow3
T pow3(T x)
Returns x to the power of 3.
Definition: Math_wam.h:101
TTubo::getTempWallIni
double getTempWallIni() const
Gets the initial temperature of the wall.
Definition: TTubo.cpp:5484
TTubo::HeaderInstantaneousResults
void HeaderInstantaneousResults(std::stringstream &insoutput, stEspecies *DatosEspecies) const
Definition: TTubo.cpp:2812
TTubo::GetCoefTurbulencia
double GetCoefTurbulencia(int i) const
Gets the turbulence coefficient.
Definition: TTubo.cpp:5416
TTubo::InicializaCaracteristicas
void InicializaCaracteristicas(TCondicionContorno **BC)
Definition: TTubo.cpp:4734
TTubo::GetTPTuboAnt
double GetTPTuboAnt(int j, int) const
Gets the previous wall temperature at a given cell and node.
Definition: TTubo.cpp:5501
TTubo::Interpola_Caracteristica
double Interpola_Caracteristica(double entropia, int signo, int extremo, double DeltaTiempo)
Definition: TTubo.cpp:4584
TTubo::FDeltaTime
double FDeltaTime
Time step.
Definition: TTubo.h:754
TTubo::LeeDatosGeometricosTubo
void LeeDatosGeometricosTubo(const char *FileWAM, fpos_t &filepos, double ene, int tipomallado, TBloqueMotor **Engine)
Definition: TTubo.cpp:681
TTubo::GetDiametro
double GetDiametro(int i) const
Gets the cell diameter.
Definition: TTubo.cpp:5436
TTubo::PutDeltaTime
void PutDeltaTime(double valor)
Sets the time step.
Definition: TTubo.cpp:5517
TTubo::ImprimeResultadosInstantaneos
void ImprimeResultadosInstantaneos(std::stringstream &insoutput) const
Definition: TTubo.cpp:2914
TTubo::CalculaCaracteristicasExtremos
void CalculaCaracteristicasExtremos(TCondicionContorno **BC, double DeltaTiempo)
Definition: TTubo.cpp:4411
TTubo::HeaderAverageResults
void HeaderAverageResults(std::stringstream &medoutput, stEspecies *DatosEspecies) const
Definition: TTubo.cpp:2569
pow025
T pow025(T x)
Returns x to the power of 0.25.
Definition: Math_wam.h:127
TTubo::ComunicacionDPF
void ComunicacionDPF(TCondicionContorno **CC, TDeposito **Deposito)
TTubo::GetVelocidad
double GetVelocidad(int i) const
Gets the fluid speed.
Definition: TTubo.cpp:5505
TTubo::ImprimeResultadosMedios
void ImprimeResultadosMedios(std::stringstream &medoutput) const
Definition: TTubo.cpp:2647
TTubo::GetFraccionMasicaInicial
double GetFraccionMasicaInicial(int i) const
Gets the initial mass fraction of species i.
Definition: TTubo.cpp:5440
TTubo::GetPresion
double GetPresion(int i) const
Gets the fluid pressure.
Definition: TTubo.cpp:5468
TCondicionContorno
Definition: TCondicionContorno.h:54
TTubo::CalculaResistenciasdePared
void CalculaResistenciasdePared(TCondicionContorno **BC)
Definition: TTubo.cpp:3451
TTubo::GetTPTubo
double GetTPTubo(int j, int i) const
Gets the wall temperature at a given cell and node.
Definition: TTubo.cpp:5496
TDeposito
Definition: TDeposito.h:44
TTubo::GetVelPro
double GetVelPro(int i) const
Gets the integrated gas velocity.
Definition: TTubo.cpp:5513
TTubo::GetCpMezcla
double GetCpMezcla(int i) const
Gets the specific heat capacity at constant pressure at a given cell.
Definition: TTubo.cpp:5420
PutLabel
std::string PutLabel(int idx)
Returns an integer.
Definition: labels.cpp:475
TTubo::getDeltaTime
double getDeltaTime() const
Gets the time step.
Definition: TTubo.cpp:5428
TTubo::GetCvMezcla
double GetCvMezcla(int i) const
Gets the specific heat capacity at constant volume at a given cell.
Definition: TTubo.cpp:5424
stResInstantTubo
Definition: Globales.h:795
Exception
Custom exception class.
Definition: Exception.hpp:39
TTubo::SalidaGeneralTubos
void SalidaGeneralTubos(stEspecies *DatosEspecies) const
Definition: TTubo.cpp:4343
TTubo::PutTPTubo
void PutTPTubo(int k, int i, double valor)
Sets the wall temperature at a given cell and node.
Definition: TTubo.cpp:5529
pow4
T pow4(T x)
Returns x to the power of 4.
Definition: Math_wam.h:114
TTubo::FTime0
double FTime0
Time at current time step.
Definition: TTubo.h:712
TTubo::AjustaPaso
void AjustaPaso(double Intervalo)
Definition: TTubo.cpp:4393
TTubo::getTime0
double getTime0() const
Gets the current time.
Definition: TTubo.cpp:5488
TTubo::getMallado
double getMallado() const
Gets the mesh size.
Definition: TTubo.cpp:5452
TTubo::ComunicacionTubo_CC
void ComunicacionTubo_CC(TCondicionContorno **BC)
Definition: TTubo.cpp:861
TTubo::PutTime1
void PutTime1(double valor)
Sets the time after the following time-step.
Definition: TTubo.cpp:5525
stResMediosTubo
Definition: Globales.h:756
TTubo::ReduccionFlujoSubsonico
void ReduccionFlujoSubsonico()
Definition: TTubo.cpp:2390
TTubo::CalculaTemperaturaPared
void CalculaTemperaturaPared(TBloqueMotor **Engine, double Theta, double CrankAngle, TCondicionContorno **BC)
Definition: TTubo.cpp:3711
TTubo.h
stCharOrigin
Definition: BoundaryFunctions.h:517
TBloqueMotor
Definition: TBloqueMotor.h:43
TCCDeposito
Definition: TCCDeposito.h:40
TTubo::LeeDatosGeneralesTubo
void LeeDatosGeneralesTubo(const char *FileWAM, fpos_t &filepos)
Definition: TTubo.cpp:535
pow2
T pow2(T x)
Returns x to the power of 2.
Definition: Math_wam.h:88
TTubo::IniciaVariablesFundamentalesTubo
void IniciaVariablesFundamentalesTubo()
Definition: TTubo.cpp:961
TTubo::GetDensidad
double GetDensidad(int i) const
Gets the density.
Definition: TTubo.cpp:5432
TTubo::IniciaVariablesTransmisionCalor
void IniciaVariablesTransmisionCalor(TCondicionContorno **BC, TBloqueMotor **Engine, double AmbientTemperature)
Definition: TTubo.cpp:1452
TTubo::PutVelPro
void PutVelPro(int i, double valor)
Sets the integrated gas velocity.
Definition: TTubo.cpp:5533
TTubo::CalculaResultadosMedios
void CalculaResultadosMedios(double Theta)
Definition: TTubo.cpp:2968
TTubo::ReadInstantaneousResultsTubo
void ReadInstantaneousResultsTubo(const char *FileWAM, fpos_t &filepos, bool HayMotor)
Definition: TTubo.cpp:2691
TTubo::GetRMezcla
double GetRMezcla(int i) const
Gets the gas constant of the mixture at a given cell.
Definition: TTubo.cpp:5476
TTubo::~TTubo
~TTubo()
Definition: TTubo.cpp:214
TCCUnionEntreTubos
Definition: TCCUnionEntreTubos.h:37
TTubo::getNumeroTubo
int getNumeroTubo() const
Gets the pipe id.
Definition: TTubo.cpp:5464
TTubo::CalculaCoeficientePeliculaInterior
void CalculaCoeficientePeliculaInterior(TCondicionContorno **BC)
Definition: TTubo.cpp:3650
TTubo::getPresionInicial
double getPresionInicial() const
Gets the initial pressure.
Definition: TTubo.cpp:5472
TTubo::Interpola_Entropia
double Interpola_Entropia(nmPipeEnd TipoExtremoTubo, double DeltaTiempo)
Definition: TTubo.cpp:4441
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
TTubo::ActualizaPropiedadesGas
void ActualizaPropiedadesGas()
Definition: TTubo.cpp:1170
TTubo::PutTime0
void PutTime0(double valor)
Sets the current time.
Definition: TTubo.cpp:5521
TTubo::GetArea
double GetArea(int i) const
Gets the cross section at a given cell.
Definition: TTubo.cpp:5408
TTubo::EstabilidadMetodoCalculo
void EstabilidadMetodoCalculo()
Definition: TTubo.cpp:1519
TTubo::ReduccionFlujoSubsonicoFCT
void ReduccionFlujoSubsonicoFCT()
Definition: TTubo.cpp:2419
TTubo::ReadAverageResultsTubo
void ReadAverageResultsTubo(const char *FileWAM, fpos_t &filepos, bool HayMotor)
Definition: TTubo.cpp:2456
TTubo::getNodoIzq
int getNodoIzq() const
Gets the left-hand side node.
Definition: TTubo.cpp:5460
TTubo::TTubo
TTubo(int SpeciesNumber, int j, double SimulationDuration, TBloqueMotor **Engine, nmTipoCalculoEspecies SpeciesModel, nmCalculoGamma GammaCalculation, bool ThereIsEGR)
Definition: TTubo.cpp:62
TTubo::CalculaResultadosInstantaneos
void CalculaResultadosInstantaneos()
Definition: TTubo.cpp:3145