OpenWAM
TWasteGate.cpp
1 /*--------------------------------------------------------------------------------*\
2 ==========================|
3  \\ /\ /\ // O pen | OpenWAM: The Open Source 1D Gas-Dynamic Code
4  \\ | X | // W ave |
5  \\ \/_\/ // A ction | CMT-Motores Termicos / Universidad Politecnica Valencia
6  \\/ \// M odel |
7  ----------------------------------------------------------------------------------
8  License
9 
10  This file is part of OpenWAM.
11 
12  OpenWAM is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  OpenWAM is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with OpenWAM. If not, see <http://www.gnu.org/licenses/>.
24 
25 
26  \*--------------------------------------------------------------------------------*/
27 
28 //---------------------------------------------------------------------------
29 #pragma hdrstop
30 
31 #include "TWasteGate.h"
32 #include "TTubo.h"
33 #include "TDeposito.h"
34 
35 //---------------------------------------------------------------------------
36 //---------------------------------------------------------------------------
37 
38 TWasteGate::TWasteGate() :
39  TTipoValvula(nmWasteGate) {
40 }
41 
42 //---------------------------------------------------------------------------
43 //---------------------------------------------------------------------------
44 
45 TWasteGate::~TWasteGate() {
46 }
47 
48 //---------------------------------------------------------------------------
49 //---------------------------------------------------------------------------
50 
51 TWasteGate::TWasteGate(TWasteGate *Origen, int Valvula) :
52  TTipoValvula(nmWasteGate) {
53 
54  FTuboControl = Origen->FTuboControl;
55  FDistancia = Origen->FDistancia;
56  FPresCapMando = Origen->FPresCapMando;
57  FCoefC1 = Origen->FCoefC1;
58  FCoefC2 = Origen->FCoefC2;
59  FMasa = Origen->FMasa;
60  FAmortiguamiento = Origen->FAmortiguamiento;
61  FRigidez = Origen->FRigidez;
62  FPrecarga = Origen->FPrecarga;
63  FAreaDiaf = Origen->FAreaDiaf;
64  FAreaPlato = Origen->FAreaPlato;
65  FDiametroRef = Origen->FDiametroRef;
66  FSentidoWG = Origen->FSentidoWG;
67 
68  FNumeroOrden = Origen->FNumeroOrden;
69 
70  FValvula = Valvula;
71 
72  FDiamRef = FDiametroRef;
73 
74  FX = 0.;
75  FdX = 0.;
76  FddX = 0.;
77 
78  FGraficasWG = false;
79 }
80 
81 //---------------------------------------------------------------------------
82 //---------------------------------------------------------------------------
83 
84 void TWasteGate::LeeDatosIniciales(const char *FileWAM, fpos_t &filepos, int norden, bool HayMotor,
85  TBloqueMotor *Engine) {
86  try {
87  int modo = 0;
88 
89  FNumeroOrden = norden;
90 
91  FILE *fich = fopen(FileWAM, "r");
92  fsetpos(fich, &filepos);
93 
94  fscanf(fich, "%d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %d", &FTuboControl, &FDistancia, &FPresCapMando, &FCoefC1,
95  &FCoefC2, &FMasa, &FAmortiguamiento, &FRigidez, &FPrecarga, &FAreaDiaf,
96  &FAreaPlato, &FDiametroRef, &modo);
97 
98  switch(modo) {
99  case 0:
100  FSentidoWG = 1;
101  break;
102  case 1:
103  FSentidoWG = -1;
104  break;
105  }
106  fgetpos(fich, &filepos);
107  fclose(fich);
108  } catch(exception &N) {
109  std::cout << "ERROR: LeeDatosIniciales WasteGate" << std::endl;
110  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
111  throw Exception(N.what());
112 
113  }
114 }
115 
116 //---------------------------------------------------------------------------
117 //---------------------------------------------------------------------------
118 
119 void TWasteGate::CalculoNodoAdm(TTubo **Pipe) {
120  try {
121 
122  FTuboAdm = Pipe[FTuboControl - 1];
123 
124  FNodoAdm = floor(FDistancia / Pipe[FTuboControl - 1]->getXRef());
125  if(FNodoAdm >= Pipe[FTuboControl - 1]->getNin() - 1) {
126  FNodoAdm = FNodoAdm - 1;
127  FDist = 1;
128  } else
129  FDist = FDistancia / Pipe[FTuboControl - 1]->getXRef() - FNodoAdm;
130 
131  } catch(exception &N) {
132  std::cout << "ERROR: TWasteGate::CalculoNodoAdm " << std::endl;
133  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
134  throw Exception(N.what());
135 
136  }
137 }
138 
139 //---------------------------------------------------------------------------
140 //---------------------------------------------------------------------------
141 
142 void TWasteGate::CalculaCD(double Padm, double PTubo, double PDeposito, double deltaT) {
143  try {
144  FFuerza = (Padm - FPresCapMando) * FAreaDiaf + FSentidoWG * (PDeposito - PTubo) * FAreaPlato - FPrecarga;
145 
146  FddX = (FFuerza - FRigidez * FX - FAmortiguamiento * FdX) / FMasa;
147  FX = FX + FdX * deltaT + FddX * deltaT * deltaT / 2.;
148  FdX = FdX + FddX * deltaT;
149  if(FX > 11.0e-3) {
150  FX = 11.0e-3;
151  FdX = 0.;
152  }
153  if(FX < 0) {
154  FX = 0.;
155  FdX = 0.;
156  FCDTubVol = 0.;
157  FCDVolTub = 0.;
158  } else {
159  FCDTubVol = FCoefC1 * (pow((FX / FDiametroRef), FCoefC2));
160  FCDVolTub = FCoefC1 * (pow((FX / FDiametroRef), FCoefC2));
161  }
162  } catch(exception &N) {
163  std::cout << "ERROR: LeeDatosIniciales WasteGate" << std::endl;
164  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
165  throw Exception(N.what());
166 
167  }
168 }
169 
170 void TWasteGate::GetCDin(double Time) {
171 
172  double deltaT = Time - FTime0;
173  double p1 = FTuboAdm->GetPresion(FNodoAdm);
174  double p2 = FTuboAdm->GetPresion(FNodoAdm + 1);
175  double Padm = Interpola(p1, p2, 1.0, FDist);
176  double PDeposito = FPlenum->getPressure();
177  double PTubo = FPipe->GetPresion(FPipeNode);
178  FFuerza = (Padm - FPresCapMando) * FAreaDiaf + FSentidoWG * (PDeposito - PTubo) * FAreaPlato - FPrecarga;
179 
180  FddX = (FFuerza - FRigidez * FX - FAmortiguamiento * FdX) / FMasa;
181  FX = FX + FdX * deltaT + FddX * deltaT * deltaT / 2.;
182  FdX = FdX + FddX * deltaT;
183  if(FX > 11.0e-3) {
184  FX = 11.0e-3;
185  FdX = 0.;
186  }
187  if(FX < 0) {
188  FX = 0.;
189  FdX = 0.;
190  FCDTubVol = 0.;
191  FCDVolTub = 0.;
192  } else {
193  FCDTubVol = FCoefC1 * (pow((FX / FDiametroRef), FCoefC2));
194  }
195 }
196 
197 void TWasteGate::GetCDout(double Time) {
198 
199  double deltaT = Time - FTime0;
200  double p1 = FTuboAdm->GetPresion(FNodoAdm);
201  double p2 = FTuboAdm->GetPresion(FNodoAdm + 1);
202  double Padm = Interpola(p1, p2, 1.0, FDist);
203  double PDeposito = FPlenum->getPressure();
204  double PTubo = FPipe->GetPresion(FPipeNode);
205  FFuerza = (Padm - FPresCapMando) * FAreaDiaf + FSentidoWG * (PDeposito - PTubo) * FAreaPlato - FPrecarga;
206 
207  FddX = (FFuerza - FRigidez * FX - FAmortiguamiento * FdX) / FMasa;
208  FX = FX + FdX * deltaT + FddX * deltaT * deltaT / 2.;
209  FdX = FdX + FddX * deltaT;
210  if(FX > 11.0e-3) {
211  FX = 11.0e-3;
212  FdX = 0.;
213  }
214  if(FX < 0) {
215  FX = 0.;
216  FdX = 0.;
217  FCDTubVol = 0.;
218  FCDVolTub = 0.;
219  } else {
220  FCDVolTub = FCoefC1 * (pow((FX / FDiametroRef), FCoefC2));
221  }
222 }
223 
224 //---------------------------------------------------------------------------
225 //---------------------------------------------------------------------------
226 
227 void TWasteGate::LeeDatosGraficas(const char *FileWAM, fpos_t &filepos) {
228  try {
229  int ndv = 0, var = 0;
230  FILE *fich = fopen(FileWAM, "r");
231  fsetpos(fich, &filepos);
232  FGraficasWG = true;
233  FGrafLev = false;
234  fscanf(fich, " %d", &ndv);
235  for(int i = 0; i < ndv; i++) {
236  fscanf(fich, " %d", &var);
237  switch(var) {
238  case 0:
239  FGrafLev = true;
240  break;
241  }
242  }
243  fgetpos(fich, &filepos);
244  fclose(fich);
245  } catch(exception &N) {
246  std::cout << "ERROR: LeeDatosGraficas WasteGate" << std::endl;
247  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
248  throw Exception(N.what());
249 
250  }
251 }
252 
253 //---------------------------------------------------------------------------
254 //---------------------------------------------------------------------------
255 
256 void TWasteGate::CabeceraGraficaINS(stringstream& insoutput, int lam) {
257  try {
258 //FILE *fich=fopen(FileSALIDA,"a");
259  std::string Label;
260 
261  if(FGraficasWG) {
262  if(FGrafLev) {
263  Label = "\t" + PutLabel(13) + std::to_string(lam) + PutLabel(902);
264  insoutput << Label.c_str();
265  }
266  }
267 //fclose(fich);
268  } catch(exception &N) {
269  std::cout << "ERROR: CabeceraGrafica WasteGate" << std::endl;
270  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
271  throw Exception(N.what());
272 
273  }
274 }
275 
276 //---------------------------------------------------------------------------
277 //---------------------------------------------------------------------------
278 
279 void TWasteGate::ImprimeGraficaINS(stringstream& insoutput) {
280  try {
281 //FILE *fich=fopen(FileSALIDA,"a");
282  if(FGraficasWG) {
283  if(FGrafLev)
284  insoutput << "\t" << FX;
285  }
286 //fclose(fich);
287  } catch(exception &N) {
288  std::cout << "ERROR: ImprimeGrafica WasteGate" << std::endl;
289  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
290  throw Exception(N.what());
291 
292  }
293 }
294 
295 //---------------------------------------------------------------------------
296 //---------------------------------------------------------------------------
297 
298 #pragma package(smart_init)
299 
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
TTipoValvula
Definition: TTipoValvula.h:53
TWasteGate
Definition: TWasteGate.h:47
TTubo::GetPresion
double GetPresion(int i) const
Gets the fluid pressure.
Definition: TTubo.cpp:5468
PutLabel
std::string PutLabel(int idx)
Returns an integer.
Definition: labels.cpp:475
Exception
Custom exception class.
Definition: Exception.hpp:39
TTubo.h
TBloqueMotor
Definition: TBloqueMotor.h:43