OpenWAM
TCCExternalConnection.cpp
1 // ---------------------------------------------------------------------------
2 
3 #pragma hdrstop
4 
5 #include "TCCExternalConnection.h"
6 #include "TTubo.h"
7 
8 // ---------------------------------------------------------------------------
9 
10 TCCExternalConnection::TCCExternalConnection(nmTypeBC TipoCC, int numCC, nmTipoCalculoEspecies SpeciesModel,
11  int numeroespecies, nmCalculoGamma GammaCalculation, bool ThereIsEGR) :
12  TCondicionContorno(TipoCC, numCC, SpeciesModel, numeroespecies, GammaCalculation, ThereIsEGR) {
13 
14  FTuboExtremo = NULL;
15  // FComposicion = NULL;
16 
17  FUExt.resize(2);
18  FTExt.resize(2);
19  FPExt.resize(2);
20  FDExt.resize(2);
21  FAExt.resize(2);
22 }
23 
24 TCCExternalConnection::~TCCExternalConnection() {
25 }
26 
27 void TCCExternalConnection::UpdateCurrentExternalProperties(double U0, double U1, double T0, double T1, double P0,
28  double P1, double t) {
29 
30  FUExt[0] = U0;
31  FUExt[1] = U1;
32  FTExt[0] = T0;
33  FTExt[1] = T1;
34  FPExt[0] = P0;
35  FPExt[1] = P1;
36 
37  FCurrentTime = t;
38 }
39 
40 void TCCExternalConnection::AsignGeometricalData(double D0, double D1, double deltaX) {
41 
42  FDExt[0] = D0;
43  FDExt[1] = D1;
44  FAExt[0] = __geom::Circle_area(D0);
45  FAExt[1] = __geom::Circle_area(D1);
46 
47  FDeltaX = deltaX;
48 }
49 
50 void TCCExternalConnection::ExternalCharacteristics(double Time) {
51 
52  // Calculo Entropia
53  double x = 0., Px = 0., Tx = 0., Ux = 0., Ax = 0.;
54  double Deltat = Time - FCurrentTime;
55 
56  double g = __Gamma::G;
57  double gg = __Gamma::G_5;
58 
59  double A0 = sqrt(g * __R::Air * FTExt[0]);
60  double A1 = sqrt(g * __R::Air * FTExt[1]);
61 
62  double AA0 = A0 / pow(FPExt[0], gg);
63  double AA1 = A1 / pow(FPExt[1], gg);
64 
65  if(FUExt[0] > 0) {
66  x = FUExt[0] * FDeltaX / (FDeltaX / Deltat + FUExt[0] - FUExt[1]);
67 
68  FA_AExt = (AA0 * (FDeltaX - x) + AA1 * x) / FDeltaX / __cons::ARef;
69 
70  } else {
71  FA_AExt = AA0 / __cons::ARef;
72  }
73  double UWave0 = A0 + FUExt[0];
74  double UWave1 = A1 + FUExt[1];
75 
76  x = UWave0 * FDeltaX / (FDeltaX / Deltat + UWave0 - UWave1);
77 
78  Ux = (FUExt[0] * (FDeltaX - x) + FUExt[1] * x) / FDeltaX;
79  Ax = (A0 * (FDeltaX - x) + A1 * x) / FDeltaX;
80 
81  double deltaEnt = Ax * (AA0 - FA_AExt * __cons::ARef) / FA_AExt / __cons::ARef;
82 
83  FK_CExt = (Ax + (g - 1) / 2 * Ux + deltaEnt) / __cons::ARef;
84 
85 }
86 
87 void TCCExternalConnection::CalculaCondicionContorno(double Time) {
88 
89  double flujo = 0.;
90 
91  ExternalCharacteristics(Time);
92 
93  flujo = (FK_CExt / FA_AExt) / (*FCC / FTuboExtremo[0].Entropia);
94 
95  if(flujo < 0.999995) {
96 
97  double A = FTuboExtremo[0].Entropia / (FTuboExtremo[0].Entropia + FA_AExt) * (*FCC + FK_CExt);
98  FT_Boundary = pow2(A * __cons::ARef) / __R::Air / __Gamma::G;
99  FU_Boundary = (A - *FCC) / __Gamma::G_3;
100  *FCD = A + __Gamma::G_3 * FU_Boundary;
101  FU_Boundary *= __cons::ARef;
102  FP_Boundary = pow(A / FTuboExtremo[0].Entropia, __Gamma::G_4);
103  } else if(flujo > 1.000005) {
104  double A = FA_AExt / (FTuboExtremo[0].Entropia + FA_AExt) * (*FCC + FK_CExt);
105  FT_Boundary = pow2(A * __cons::ARef) / __R::Air / __Gamma::G;
106  FU_Boundary = (FK_CExt - A) / __Gamma::G_3;
107  *FCD = A + __Gamma::G_3 * FU_Boundary;
108  *FCC = A - __Gamma::G_3 * FU_Boundary;
109  FTuboExtremo[0].Entropia = FA_AExt;
110  FU_Boundary *= __cons::ARef;
111  FP_Boundary = pow(A / FTuboExtremo[0].Entropia, __Gamma::G_4);
112 
113  } else {
114  double A = *FCC;
115  FT_Boundary = pow2(A * __cons::ARef) / __R::Air / __Gamma::G;
116  FU_Boundary = 0;
117  *FCD = *FCC;
118  FP_Boundary = pow(A / FTuboExtremo[0].Entropia, __Gamma::G_4);
119  }
120 
121 }
122 
123 void TCCExternalConnection::ReadBoundaryData(const char *FileWAM, fpos_t &filepos, int NumberOfPipes, TTubo **Pipe,
124  int nDPF, TDPF **DPF) {
125 
126  int i = 0;
127 
128  FTuboExtremo = new stTuboExtremo[1];
129  FTuboExtremo[0].Pipe = NULL;
130 
131  while(FNumeroTubosCC < 1 && i < NumberOfPipes) {
132  if(Pipe[i]->getNodoIzq() == FNumeroCC) {
133  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
134  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmLeft;
135  FCC = &(FTuboExtremo[FNumeroTubosCC].Beta);
136  FCD = &(FTuboExtremo[FNumeroTubosCC].Landa);
137  FNodoFin = 0;
138  FIndiceCC = 0;
139  FNumeroTubosCC++;
140  }
141  if(Pipe[i]->getNodoDer() == FNumeroCC) {
142  FTuboExtremo[FNumeroTubosCC].Pipe = Pipe[i];
143  FTuboExtremo[FNumeroTubosCC].TipoExtremo = nmRight;
144  FCC = &(FTuboExtremo[FNumeroTubosCC].Landa);
145  FCD = &(FTuboExtremo[FNumeroTubosCC].Beta);
146  FNodoFin = FTuboExtremo[FNumeroTubosCC].Pipe->getNin() - 1;
147  FIndiceCC = 1;
148  FNumeroTubosCC++;
149  }
150  i++;
151  }
152 
153  // Inicializacion del transporte de especies quimicas.
154  FFraccionMasicaEspecie = new double[FNumeroEspecies - FIntEGR];
155  for(int i = 0; i < FNumeroEspecies - FIntEGR; i++) {
156  FFraccionMasicaEspecie[i] = FTuboExtremo[0].Pipe->GetFraccionMasicaInicial(i);
157  }
158 
159  FILE *fich = fopen(FileWAM, "r");
160  fsetpos(fich, &filepos);
161 
162  fscanf(fich, "%d ", &FID);
163 
164  fgetpos(fich, &filepos);
165  fclose(fich);
166 
167 }
168 
169 void TCCExternalConnection::LoadNewData(double* p, double* T, double* u) {
170 
171  *p = FP_Boundary;
172  *T = FT_Boundary;
173  *u = FU_Boundary;
174 }
175 
176 #pragma package(smart_init)
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
stTuboExtremo
Definition: Globales.h:730
TDPF
Definition: TDPF.h:45
TTubo::GetFraccionMasicaInicial
double GetFraccionMasicaInicial(int i) const
Gets the initial mass fraction of species i.
Definition: TTubo.cpp:5440
TCondicionContorno
Definition: TCondicionContorno.h:54
TTubo.h
pow2
T pow2(T x)
Returns x to the power of 2.
Definition: Math_wam.h:88