OpenWAM
TTipoValvula.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 "TTipoValvula.h"
32 #include "TTubo.h"
33 #include "TCilindro.h"
34 #include "TDeposito.h"
35 
36 //---------------------------------------------------------------------------
37 //---------------------------------------------------------------------------
38 
39 TTipoValvula::TTipoValvula(nmTipoValvula TipVal) {
40 
41  FTipoValvula = TipVal;
42  FCRecuperacion = 0;
43  FGraficasINS = false;
44  FGraficasMED = false;
45  FGraficaCDEINS = false;
46  FGraficaCDSINS = false;
47  FGraficaCDEMED = false;
48  FGraficaCDSMED = false;
49  FSumCDE = 0.;
50  FSumCDS = 0.;
51  FSumTime = 0.;
52  FTiempoAnt = 0.;
53  FToCylinder = false;
54  FEngine = NULL;
55  FTime0 = 0.;
56 }
57 
58 //---------------------------------------------------------------------------
59 //---------------------------------------------------------------------------
60 
61 TTipoValvula::~TTipoValvula() {
62 
63 }
64 
65 //---------------------------------------------------------------------------
66 //---------------------------------------------------------------------------
67 
68 void TTipoValvula::AsignaParametros(int Pipe, int Nodo, int Tipo, int Valvula, double dTubo, int sentido) {
69  try {
70  FTubo = Pipe;
71  FNodo = Nodo;
72  FTipo = Tipo;
73  FValvula = Valvula;
74  FDiamTubo = dTubo;
75  FSentido = sentido;
76  } catch(exception &N) {
77  std::cout << "ERROR: AsignaParametros TypeOfValve" << std::endl;
78  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
79  throw Exception(N.what());
80 
81  }
82 }
83 
84 //---------------------------------------------------------------------------
85 //---------------------------------------------------------------------------
86 
87 double TTipoValvula::LeeDiametro() {
88  try {
89  if(FDiamRef > 0) {
90  return FDiamRef;
91  } else {
92  return FDiamTubo;
93  }
94  } catch(exception &N) {
95  std::cout << "ERROR: LeeDiametro TypeOfValve" << std::endl;
96  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
97  throw Exception(N.what());
98 
99  }
100 }
101 
102 //---------------------------------------------------------------------------
103 //---------------------------------------------------------------------------
104 
105 //void TTipoValvula::PutDiametroTubo(double Valor)
106 //{
107 //FDiamTubo=Valor;
108 //}
109 
110 //---------------------------------------------------------------------------
111 //---------------------------------------------------------------------------
112 
113 void TTipoValvula::AsignaCRecuperacion(double Valor) {
114  FCRecuperacion = Valor;
115 }
116 
117 //---------------------------------------------------------------------------
118 //---------------------------------------------------------------------------
119 
120 void TTipoValvula::AsignaCDVolTub(double Valor) {
121  FCDVolTub = Valor;
122 }
123 
124 //---------------------------------------------------------------------------
125 //---------------------------------------------------------------------------
126 
127 void TTipoValvula::LeeDatosGraficasINS(const char *FileWAM, fpos_t &filepos) {
128  try {
129  int ndv = 0, var = 0;
130  FILE *fich = fopen(FileWAM, "r");
131  fsetpos(fich, &filepos);
132  FGraficasINS = true;
133 
134  fscanf(fich, " %d", &ndv);
135  for(int i = 0; i < ndv; i++) {
136  fscanf(fich, " %d", &var);
137  switch(var) {
138  case 0:
139  FGraficaCDEINS = true;
140  break;
141  case 1:
142  FGraficaCDSINS = true;
143  break;
144  }
145  }
146  fgetpos(fich, &filepos);
147  fclose(fich);
148  } catch(exception &N) {
149  std::cout << "ERROR: LeeDatosGraficas TypeOfValve" << std::endl;
150  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
151  throw Exception(N.what());
152 
153  }
154 }
155 
156 //---------------------------------------------------------------------------
157 //---------------------------------------------------------------------------
158 
159 void TTipoValvula::CabeceraGraficaINS(stringstream& insoutput, int nodo) {
160  try {
161 //FILE *fich=fopen(FileSALIDA,"a");
162  std::string Label;
163 
164  if(FGraficasINS) {
165  if(FGraficaCDEINS) {
166  Label = "\t" + PutLabel(11) + std::to_string(nodo) + PutLabel(901);
167  insoutput << Label.c_str();
168  }
169  if(FGraficaCDSINS) {
170  Label = "\t" + PutLabel(12) + std::to_string(nodo) + PutLabel(901);
171  insoutput << Label.c_str();
172  }
173  }
174 //fclose(fich);
175  } catch(exception &N) {
176  std::cout << "ERROR: CabeceraGrafica TypeOfValve" << std::endl;
177  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
178  throw Exception(N.what());
179 
180  }
181 }
182 
183 //---------------------------------------------------------------------------
184 //---------------------------------------------------------------------------
185 
186 void TTipoValvula::ImprimeGraficaINS(stringstream& insoutput) {
187  try {
188 //FILE *fich=fopen(FileSALIDA,"a");
189  if(FGraficasINS) {
190  if(FGraficaCDEINS)
191  insoutput << "\t" << FCDTubVol;
192  if(FGraficaCDSINS)
193  insoutput << "\t" << FCDVolTub;
194  }
195 //fclose(fich);
196  } catch(exception &N) {
197  std::cout << "ERROR: ImprimeGrafica TypeOfValve" << std::endl;
198  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
199  throw Exception(N.what());
200 
201  }
202 }
203 
204 //---------------------------------------------------------------------------
205 //---------------------------------------------------------------------------
206 
207 void TTipoValvula::AcumulaCDMedio(double TiempoActual) {
208  try {
209  double DeltaT = 0.;
210  DeltaT = TiempoActual - FTiempoAnt;
211  FTiempoAnt = TiempoActual;
212 
213  if(FGraficasMED) {
214  if(FGraficaCDEMED)
215  FSumCDE += FCDTubVol * DeltaT;
216  if(FGraficaCDSMED)
217  FSumCDS += FCDVolTub * DeltaT;
218  FSumTime += DeltaT;
219  }
220  } catch(exception &N) {
221  std::cout << "ERROR: AcumulaCDMedio TypeOfValve" << std::endl;
222  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
223  throw Exception(N.what());
224 
225  }
226 }
227 
228 //---------------------------------------------------------------------------
229 //---------------------------------------------------------------------------
230 
231 void TTipoValvula::LeeDatosGraficasMED(const char *FileWAM, fpos_t &filepos) {
232  try {
233  int ndv = 0, var = 0;
234  FILE *fich = fopen(FileWAM, "r");
235  fsetpos(fich, &filepos);
236 
237  FGraficasMED = true;
238 
239  fscanf(fich, " %d", &ndv);
240  for(int i = 0; i < ndv; i++) {
241  fscanf(fich, " %d", &var);
242  switch(var) {
243  case 0:
244  FGraficaCDEMED = true;
245  break;
246  case 1:
247  FGraficaCDSMED = true;
248  break;
249  }
250  }
251  fgetpos(fich, &filepos);
252  fclose(fich);
253  } catch(exception &N) {
254  std::cout << "ERROR: LeeDatosGraficas TypeOfValve" << std::endl;
255  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
256  throw Exception(N.what());
257 
258  }
259 }
260 
261 //---------------------------------------------------------------------------
262 //---------------------------------------------------------------------------
263 
264 void TTipoValvula::CabeceraGraficaMED(stringstream& medoutput, int nodo) {
265  try {
266 //FILE *fich=fopen(FileSALIDA,"a");
267  std::string Label;
268 
269  if(FGraficasMED) {
270  if(FGraficaCDEMED) {
271  Label = "\t" + PutLabel(11) + std::to_string(nodo) + PutLabel(901);
272  medoutput << Label.c_str();
273  }
274  if(FGraficaCDSMED) {
275  Label = "\t" + PutLabel(12) + std::to_string(nodo) + PutLabel(901);
276  medoutput << Label.c_str();
277  }
278  }
279 //fclose(fich);
280  } catch(exception &N) {
281  std::cout << "ERROR: CabeceraGrafica TypeOfValve" << std::endl;
282  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
283  throw Exception(N.what());
284 
285  }
286 }
287 
288 //---------------------------------------------------------------------------
289 //---------------------------------------------------------------------------
290 
291 void TTipoValvula::ImprimeGraficaMED(stringstream& medoutput) {
292  try {
293 //FILE *fich=fopen(FileSALIDA,"a");
294  if(FGraficasMED) {
295  if(FGraficaCDEMED) {
296  FCDEMedio = FSumCDE / FSumTime;
297  medoutput << "\t" << FCDEMedio;
298  FSumCDE = 0.;
299  }
300  if(FGraficaCDSMED) {
301  FCDSMedio = FSumCDS / FSumTime;
302  medoutput << "\t" << FCDSMedio;
303  FSumCDS = 0.;
304  }
305  FSumTime = 0;
306  }
307 //fclose(fich);
308  } catch(exception &N) {
309  std::cout << "ERROR: ImprimeGrafica TypeOfValve" << std::endl;
310  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
311  throw Exception(N.what());
312 
313  }
314 }
315 
316 //---------------------------------------------------------------------------
317 //---------------------------------------------------------------------------
318 
319 void TTipoValvula::PutPipe(TTubo *Pipe, int node) {
320  FPipe = Pipe;
321  FPipeNode = node;
322  FDiamTubo = FPipe->GetDiametro(FPipeNode);
323  if(FDiamRef > 0) {
324  FSectionRatio = pow2(FDiamRef / FDiamTubo);
325  } else {
326  FSectionRatio = 1;
327  }
328  FCDTubVol *= FSectionRatio;
329  FCDVolTub *= FSectionRatio;
330  //FDiamTubo=FPipe->D
331 }
332 
333 //---------------------------------------------------------------------------
334 //---------------------------------------------------------------------------
335 
336 void TTipoValvula::PutCylider(TCilindro *Cylinder) {
337  FCylinder = Cylinder;
338  FToCylinder = true;
339 }
340 //---------------------------------------------------------------------------
341 //---------------------------------------------------------------------------
342 
343 void TTipoValvula::PutPlenum(TDeposito *Plenum) {
344  FPlenum = Plenum;
345  FToCylinder = false;
346 }
347 
348 //---------------------------------------------------------------------------
349 //---------------------------------------------------------------------------
350 
351 #pragma package(smart_init)
TTubo
a Finite differences pipe.
Definition: TTubo.h:116
TCilindro
Definition: TCilindro.h:59
TTubo::GetDiametro
double GetDiametro(int i) const
Gets the cell diameter.
Definition: TTubo.cpp:5436
TDeposito
Definition: TDeposito.h:44
PutLabel
std::string PutLabel(int idx)
Returns an integer.
Definition: labels.cpp:475
Exception
Custom exception class.
Definition: Exception.hpp:39
TTubo.h
pow2
T pow2(T x)
Returns x to the power of 2.
Definition: Math_wam.h:88