OpenWAM
TSAEMap.cpp
1 // ---------------------------------------------------------------------------
2 
3 #pragma hdrstop
4 
5 #include "TSAEMap.h"
6 
7 // ---------------------------------------------------------------------------
8 
9 TSAEMap::TSAEMap(int i) :
10  TCompressorMap() {
11 
12  FNumeroCompresor = i;
13 
14  FMassMAX_int = NULL;
15  FPresMAX_int = NULL;
16  FEffMAX_int = NULL;
17 
18  FIsAdiabatic = true;
19 }
20 
21 TSAEMap::~TSAEMap() {
22 }
23 
24 void TSAEMap::ReadSAECompressorMap(FILE *fich) {
25 
26  double speed = 0., mass = 0., pres = 0., eff = 0.;
27  int i = 0; // Curva de isoregimen
28  int j = 0; // Puntos de la curva
29  int k = 0;
30  int puntos = 0;
31  double speedmax = 0, massmax = 0, presmax = 1, effmax = 0;
32  int points = 0;
33 
34  fscanf(fich, "%d", &points);
35  FSpeed.resize(i + 1);
36  FMass.resize(i + 1);
37  FPres.resize(i + 1);
38  FEff.resize(i + 1);
39 
40  while(k < points) {
41  fscanf(fich, "%lf %lf %lf %lf", &speed, &mass, &pres, &eff);
42  mass *= FMassMultiplier;
43  pres = (pres - 1.) * FCRMultiplier + 1.;
44  eff *= FEffMultiplier;
45  k += 1;
46  if(!feof(fich)) {
47  if(j > 0) {
48  if(speed != FSpeed[i][j - 1]) {
49  i++;
50  j = 0;
51  FSpeed.resize(i + 1);
52  FMass.resize(i + 1);
53  FPres.resize(i + 1);
54  FEff.resize(i + 1);
55  if(speed > speedmax)
56  speedmax = speed;
57  FMassMAX.push_back(massmax);
58  FPresMAX.push_back(presmax);
59  FEffMAX.push_back(effmax);
60  massmax = mass;
61  presmax = pres;
62  effmax = eff;
63  } else {
64  if(mass > massmax)
65  massmax = mass;
66  if(pres > presmax)
67  presmax = pres;
68  if(eff > effmax)
69  effmax = eff;
70  }
71  } else {
72  massmax = mass;
73  presmax = pres;
74  effmax = eff;
75  }
76  FSpeed[i].push_back(speed);
77  FMass[i].push_back(mass);
78  FPres[i].push_back(pres);
79  FEff[i].push_back(eff);
80  j++;
81  }
82  }
83  FMassMAX.push_back(massmax);
84  FPresMAX.push_back(presmax);
85  FEffMAX.push_back(effmax);
86  FSpeedMAX = speedmax;
87 
88  FNumLines = FSpeed.size();
89 
90  FMassMAXMAX = 0;
91  FPresMAXMAX = 1;
92  FEffMAXMAX = 0;
93 
94  for(int i = 0; i < FNumLines; i++) {
95  FSpeedVec.push_back(FSpeed[i][0]);
96 
97  if(FMassMAX[i] > FMassMAXMAX)
98  FMassMAXMAX = FMassMAX[i];
99  if(FPresMAX[i] > FPresMAXMAX)
100  FPresMAXMAX = FPresMAX[i];
101  if(FEffMAX[i] > FEffMAXMAX)
102  FEffMAXMAX = FEffMAX[i];
103  }
104 
105  AdimensionalizeMap();
106 
107 }
108 
109 void TSAEMap::AdimensionalizeMap() {
110 
111  double tmp = 0.;
112 
113  // FSpeedAdim.resize(FNumLines);
114  FMassAdim.resize(FNumLines);
115  FPresAdim.resize(FNumLines);
116  FEffAdim.resize(FNumLines);
117 
118  FPre_MassCurve.resize(FNumLines);
119  FEff_MassCurve.resize(FNumLines);
120 
121  for(int i = 0; i < FNumLines; i++) {
122  FSpeedAdim.push_back(FSpeedVec[i] / FSpeedMAX);
123  // printf("%lf %lf %lf\n",FSpeedVec[i] ,FSpeedAdim[i],FSpeedVec[i] / FSpeedMAX);
124  FMassMAXAdim.push_back(FMassMAX[i] / FMassMAXMAX);
125  FPresMAXAdim.push_back((FPresMAX[i] - 1) / (FPresMAXMAX - 1));
126  FEffMAXAdim.push_back(FEffMAX[i] / FEffMAXMAX);
127  for(unsigned int j = 0; j < FSpeed[i].size(); j++) {
128 
129  FMassAdim[i].push_back(FMass[i][j] / FMassMAX[i]);
130  FPresAdim[i].push_back((FPres[i][j] - 1) / (FPresMAX[i] - 1));
131  FEffAdim[i].push_back(FEff[i][j] / FEffMAX[i]);
132  }
133  FMassAdim[i].insert(FMassAdim[i].begin(), 0);
134  FPresAdim[i].insert(FPresAdim[i].begin(), FPresAdim[i][0]);
135  FEffAdim[i].insert(FEffAdim[i].begin(), FEffAdim[i][0]);
136 
137  FPre_MassCurve[i] = new Hermite_interp(FMassAdim[i], FPresAdim[i]);
138  FEff_MassCurve[i] = new Hermite_interp(FMassAdim[i], FEffAdim[i]);
139  }
140 
141  FSpeedAdim.insert(FSpeedAdim.begin(), 0.);
142  FMassMAXAdim.insert(FMassMAXAdim.begin(), 0.);
143  FPresMAXAdim.insert(FPresMAXAdim.begin(), 0.);
144  FEffMAXAdim.insert(FEffMAXAdim.begin(), 0.);
145 
146  // printf("%d\n", FPresMAXAdim.size());
147 
148  FMassMAX_int = new Hermite_interp(FSpeedAdim, FMassMAXAdim);
149  FPresMAX_int = new Hermite_interp(FSpeedAdim, FPresMAXAdim);
150  FEffMAX_int = new Hermite_interp(FSpeedAdim, FEffMAXAdim);
151 
152 }
153 
154 void TSAEMap::InterpolateMAP(double RTC) {
155 
156  FRTCAdim = RTC / FSpeedMAX;
157  FCurrentIND = FMassMAX_int->locate(FRTCAdim);
158 
159  // std::cout << FMassMAXAdim[4] << std::endl;
160 
161  if(FRTCAdim <= 1) {
162  FCurrentIND = FMassMAX_int->locate(FRTCAdim);
163  FCurrentMassMAX = FMassMAX_int->interp(FRTCAdim) * FMassMAXMAX;
164  FCurrentPresMAX = FPresMAX_int->interp(FRTCAdim) * (FPresMAXMAX - 1.) + 1.;
165  FCurrentEffMAX = FEffMAX_int->interp(FRTCAdim) * FEffMAXMAX;
166  FDeltaLow = (FRTCAdim - FSpeedAdim[FCurrentIND]) / (FSpeedAdim[FCurrentIND + 1] - FSpeedAdim[FCurrentIND]);
167 
168  } else {
169  FCurrentIND = FNumLines;
170  FCurrentMassMAX = pow(FRTCAdim, 1.2) * FMassMAXMAX;
171  FCurrentPresMAX = pow(FRTCAdim, 1.2) * (FPresMAXMAX - 1.) + 1.;
172  FCurrentEffMAX = exp(1 - FRTCAdim) * FEffMAX_int->interp(FRTCAdim) * FEffMAXMAX;
173  }
174 
175  // for (int i = 0; i <= FNumLines; ++i) {
176  // printf("%lf %lf\n", FSpeedAdim[i], FSpeedAdim[i] * FSpeedMAX);
177  // }
178 
179 }
180 
181 double TSAEMap::GetCurrentRC(double Mass) {
182 
183  double massadim = Mass / FCurrentMassMAX;
184  double CurrentRC = 0.;
185 
186  if(FCurrentIND == 0) {
187  CurrentRC = (FDeltaLow * FPre_MassCurve[FCurrentIND]->interp(massadim)) * (FCurrentPresMAX - 1) + 1;
188  } else if(FCurrentIND == FNumLines) {
189  CurrentRC = FPre_MassCurve[FCurrentIND - 1]->interp(massadim) * (FCurrentPresMAX - 1) + 1;
190  } else {
191  double pres_lo = FPre_MassCurve[FCurrentIND - 1]->interp(massadim);
192  double pres_hi = FPre_MassCurve[FCurrentIND]->interp(massadim);
193 
194  CurrentRC = ((1 - FDeltaLow) * pres_lo + FDeltaLow * pres_hi) * (FCurrentPresMAX - 1) + 1;
195  }
196  return CurrentRC;
197 
198 }
199 
200 double TSAEMap::GetCurrentEff(double Mass) {
201 
202  double massadim = Mass / FCurrentMassMAX;
203  double CurrentEff = 0.;
204 
205  if(FCurrentIND == 0) {
206  CurrentEff = (FDeltaLow * FEff_MassCurve[FCurrentIND]->interp(massadim)) * FCurrentEffMAX;
207  } else if(FCurrentIND == FNumLines) {
208  CurrentEff = FEff_MassCurve[FCurrentIND - 1]->interp(massadim) * FCurrentEffMAX;
209  } else {
210  double pres_lo = FEff_MassCurve[FCurrentIND - 1]->interp(massadim);
211  double pres_hi = FEff_MassCurve[FCurrentIND]->interp(massadim);
212 
213  CurrentEff = ((1 - FDeltaLow) * pres_lo + FDeltaLow * pres_hi) * FCurrentEffMAX;
214  }
215  return CurrentEff;
216 
217 }
218 
219 void TSAEMap::LeeMapa(FILE *fich) {
220 
221  int Adiab = 0;
222 
223  fscanf(fich, "%lf %lf ", &FPresionRef, &FTempRef);
224  FTempRef = __units::degCToK(FTempRef);
225  FPresionRef = __units::BarToPa(FPresionRef);
226 
227  fscanf(fich, "%lf %lf %lf ", &FMassMultiplier, &FCRMultiplier, &FEffMultiplier);
228 #ifdef tchtm
229  fscanf(fich, "%d ", &Adiab);
230  if(Adiab == 0) {
231  FIsAdiabatic = false;
232  fscanf(fich, "%lf ", &FTempMeasure);
233  }
234 #endif
235 
236  ReadSAECompressorMap(fich);
237 }
238 
239 double TSAEMap::EvaluaRCHermite(double mass) {
240  return GetCurrentRC(mass);
241 }
242 
243 double TSAEMap::EvaluaRendSplines(double mass) {
244  return GetCurrentEff(mass);
245 }
246 
247 double TSAEMap::getGastoRelComp1() {
248  return FCurrentMassMAX;
249 }
250 
251 double TSAEMap::getRelCompBombeo() {
252  if(FCurrentIND == 0) {
253  return (1 - FDeltaLow) + FDeltaLow * FPres[FCurrentIND][0];
254  }
255  if(FCurrentIND == FNumLines) {
256  return (FPres[FCurrentIND - 1][0] - 1) * pow(FRTCAdim, 1.2) + 1;
257  } else {
258  return (1 - FDeltaLow) * FPres[FCurrentIND - 1][0] + FDeltaLow * FPres[FCurrentIND][0];
259  }
260 }
261 
262 double TSAEMap::getGastoBombeo() {
263  if(FCurrentIND == FNumLines) {
264  return FMass[FCurrentIND - 1][0] * pow(FRTCAdim, 1.2);
265  } else {
266  return (1 - FDeltaLow) * FMass[FCurrentIND - 1][0] + FDeltaLow * FMass[FCurrentIND][0];
267  }
268 }
269 
270 void TSAEMap::InterpolaMapa(double rtc, double T10) {
271  double rtc_cor = rtc * sqrt(FTempRef / T10);
272 
273  InterpolateMAP(rtc_cor);
274 }
275 
276 double TSAEMap::getRegimenCorregido() {
277  return FRTCAdim * FSpeedMAX;
278 }
279 
280 void TSAEMap::PutReference(double pref, double tref) {
281  FTempRef = tref;
282  FPresionRef = pref;
283 }
284 
285 void TSAEMap::CalculateAdiabaticEfficiency(TTC_HTM *HTM, double TinT) {
286 #ifdef tchtm
287  double m = 0., eff = 0., Rtc = 0.;
288 
289  if(!FIsAdiabatic) {
290  for(int i = 0; i < FNumLines; i++) {
291  for(unsigned int j = 0; j < FSpeed[i].size(); j++) {
292  m = FMass[i][j] / __units::PaToBar(FPresionRef) / sqrt
293  (FTempMeasure / FTempRef);
294  Rtc = FSpeed[i][j] / sqrt(FTempRef / FTempMeasure);
295  if(FPres[i][j] > 1)
296  FEff[i][j] = HTM->CorrectCompressorMap(m, FPres[i][j],
297  FEff[i][j], FTempMeasure, TinT, Rtc);
298  if(j == 0)
299  FEffMAX[i] = FEff[i][j];
300  else if(FEff[i][j] > FEffMAX[i])
301  FEffMAX[i] = FEff[i][j];
302  }
303  for(unsigned int j = 0; j < FSpeed[i].size(); j++) {
304  FEffAdim[i][j] = FEff[i][j] / FEffMAX[i];
305  }
306 
307  if(FEff_MassCurve[i] != NULL)
308  delete FEff_MassCurve[i];
309 
310  FEff_MassCurve[i] = new Hermite_interp(FMassAdim[i], FEffAdim[i]);
311  if(i == 0)
312  FEffMAXMAX = FEffMAX[i];
313  else if(FEffMAX[i] > FEffMAXMAX)
314  FEffMAXMAX = FEffMAX[i];
315  }
316  for(int i = 0; i < FNumLines; i++) {
317  FEffMAXAdim[i] = FEffMAX[i] / FEffMAXMAX;
318  }
319  if(FEffMAX_int != NULL)
320  delete FEffMAX_int;
321  FEffMAX_int = new Hermite_interp(FSpeedAdim, FEffMAXAdim);
322 
323  }
324 
325 #endif
326 }
327 
328 #pragma package(smart_init)
TTC_HTM
Definition: TTC_HTM.h:307
Hermite_interp
Definition: Math_wam.h:311
TCompressorMap
Definition: TCompressorMap.h:12