OpenWAM
TDiscoRotativo.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 "TDiscoRotativo.h"
32 #include "TCilindro.h"
33 #include "TTubo.h"
34 #include "TBloqueMotor.h"
35 
36 //---------------------------------------------------------------------------
37 //---------------------------------------------------------------------------
38 
39 TDiscoRotativo::TDiscoRotativo() :
40  TTipoValvula(nmDiscoRotativo) {
41 
42  fun_CDin = NULL;
43  fun_CDout = NULL;
44  FAngle0 = 0.;
45 
46  FDCMultiplier = 1.;
47  FShift = 0.;
48  FDuration = 1.;
49 }
50 
51 //---------------------------------------------------------------------------
52 //---------------------------------------------------------------------------
53 
54 TDiscoRotativo::~TDiscoRotativo() {
55 
56 }
57 
58 //---------------------------------------------------------------------------
59 //---------------------------------------------------------------------------
60 
61 TDiscoRotativo::TDiscoRotativo(TDiscoRotativo *Origen, int Valvula) :
62  TTipoValvula(nmDiscoRotativo) {
63 
64  FDiametroRef = Origen->FDiametroRef;
65  FNumeroPuntos = Origen->FNumeroPuntos;
66 
67  FNumeroOrden = Origen->FNumeroOrden;
68 
69  FEngine = Origen->FEngine;
70 
71  FValvula = Valvula;
72 
73  FDiamRef = FDiametroRef;
74 
75  FAngle0 = Origen->FAngle0;
76 
77  FDCMultiplier = Origen->FDCMultiplier;
78  FShift = Origen->FShift;
79  FDuration = Origen->FDuration;
80 
81  FAngulo.resize(Origen->FAngulo.size());
82  FDatosCDEntrada.resize(Origen->FDatosCDEntrada.size());
83  FDatosCDSalida.resize(Origen->FDatosCDSalida.size());
84 
85  for(int i = 0; i < FNumeroPuntos; i++) {
86  FAngulo[i] = Origen->FAngulo[i];
87  FDatosCDEntrada[i] = Origen->FDatosCDEntrada[i];
88  FDatosCDSalida[i] = Origen->FDatosCDSalida[i];
89  }
90  fun_CDin = new Hermite_interp(FAngulo, FDatosCDEntrada);
91  fun_CDout = new Hermite_interp(FAngulo, FDatosCDSalida);
92 
93  FRegimen = Origen->getRegimen();
94  FRelacionVelocidades = Origen->getRelacionVelocidades();
95  FControlRegimen = Origen->getControlRegimen();
96 }
97 
98 //---------------------------------------------------------------------------
99 //---------------------------------------------------------------------------
100 
101 void TDiscoRotativo::LeeDatosIniciales(const char *FileWAM, fpos_t &filepos, int norden, bool HayMotor,
102  TBloqueMotor *Engine) {
103  try {
104  int ControlRegimen = 0;
105 
106  FILE *fich = fopen(FileWAM, "r");
107  fsetpos(fich, &filepos);
108 
109  FNumeroOrden = norden;
110 
111  FEngine = Engine;
112 
113  fscanf(fich, "%lf ", &FDiametroRef);
114  fscanf(fich, "%lf %lf %lf ", &FDCMultiplier, &FShift, &FDuration);
115 
116  fscanf(fich, "%d ", &FNumeroPuntos);
117 
118  FAngulo.resize(FNumeroPuntos);
119  FDatosCDEntrada.resize(FNumeroPuntos);
120  FDatosCDSalida.resize(FNumeroPuntos);
121 
122  for(int j = 0; j < FNumeroPuntos; ++j) {
123  fscanf(fich, "%lf ", &FAngulo[j]);
124  FAngulo[j] *= FDuration;
125  }
126  for(int j = 0; j < FNumeroPuntos; ++j) {
127  fscanf(fich, "%lf ", &FDatosCDEntrada[j]);
128  FDatosCDEntrada[j] *= FDCMultiplier;
129  }
130  for(int j = 0; j < FNumeroPuntos; ++j) {
131  fscanf(fich, "%lf ", &FDatosCDSalida[j]);
132  FDatosCDEntrada[j] *= FDCMultiplier;
133  }
134 
135  fscanf(fich, "%d ", &ControlRegimen);
136 
137  switch(ControlRegimen) {
138  case 0:
139  FControlRegimen = nmPropio;
140  break;
141  case 1:
142  FControlRegimen = nmMotor;
143  break;
144  }
145  if(FControlRegimen == nmPropio) {
146  fscanf(fich, "%lf ", &FRegimen);
147  FRelacionVelocidades = 1.;
148  } else if(FControlRegimen == nmMotor && HayMotor) {
149  fscanf(fich, "%lf ", &FRelacionVelocidades);
150  } else {
151  std::cout << "ERROR: TDiscoRotativo::LeeDatosIniciales Lectura del Control del Regimen erronea " << std::endl;
152  throw Exception(" ");
153  }
154 
155  fgetpos(fich, &filepos);
156  fclose(fich);
157  } catch(exception &N) {
158  std::cout << "ERROR: LeeDatosIniciales DiscoRotativo" << std::endl;
159  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
160  throw Exception(N.what());
161 
162  }
163 }
164 
165 //---------------------------------------------------------------------------
166 //---------------------------------------------------------------------------
167 
168 void TDiscoRotativo::CalculaCD(double AnguloActual) {
169 
170  FCDTubVol = fun_CDin->interp(AnguloActual) * FSectionRatio;
171  FCDVolTub = fun_CDout->interp(AnguloActual) * FSectionRatio;
172 
173 }
174 
175 void TDiscoRotativo::GetCDin(double Time) {
176 
177  double X = 0., XLv = 0., XCd = 0., Angulo = 0.;
178 
179  if(FControlRegimen == nmPropio) {
180  Angulo = 6. * FRegimen * Time - FShift; // It's correct if FRegimen is constant.
181  } else {
182  if(FToCylinder) {
183  Angulo = FCylinder->getAnguloActual() * 360. / FEngine->getAngTotalCiclo() - FShift;
184 
185  } else {
186  double DeltaT = Time - FTime0;
187  FTime0 = Time;
188  double DeltaA = 6 * FEngine->getRegimen() * DeltaT * FRelacionVelocidades;
189  Angulo = DeltaA + FAngle0;
190  }
191  }
192  if(Angulo < 0.)
193  Angulo += 360.;
194  else
195  Angulo = Angulo - 360 * int(floor(Angulo / 360));
196 
197  FAngle0 = Angulo;
198 
199  FCDTubVol = fun_CDin->interp(Angulo) * FSectionRatio;
200 
201  if(FCDTubVol > 1)
202  FCDTubVol = 1.;
203 
204 }
205 
206 void TDiscoRotativo::GetCDout(double Time) {
207  double X = 0., XLv = 0., XCd = 0., Angulo = 0.;
208 
209  if(FControlRegimen == nmPropio) {
210  Angulo = 360. * FRegimen / 60. * Time - FShift;
211  ; // It's correct if FRegimen is constant.
212  } else {
213  if(FToCylinder) {
214  Angulo = FCylinder->getAnguloActual() * 360. / FEngine->getAngTotalCiclo() - FShift;
215  } else {
216  double DeltaT = Time - FTime0;
217  FTime0 = Time;
218  double DeltaA = 6 * FEngine->getRegimen() * DeltaT * FRelacionVelocidades;
219  Angulo = DeltaA + FAngle0;
220  }
221  }
222 
223  if(Angulo < 0.)
224  Angulo += 360.;
225  else
226  Angulo = Angulo - 360 * int(floor(Angulo / 360));
227 
228  FAngle0 = Angulo;
229 
230  FCDVolTub = fun_CDout->interp(Angulo) * FSectionRatio;
231 
232  if(FCDVolTub > 1)
233  FCDVolTub = 1.;
234 
235 }
236 
237 //---------------------------------------------------------------------------
238 //---------------------------------------------------------------------------
239 
240 #pragma package(smart_init)
TTipoValvula
Definition: TTipoValvula.h:53
Hermite_interp
Definition: Math_wam.h:311
Exception
Custom exception class.
Definition: Exception.hpp:39
TDiscoRotativo
Definition: TDiscoRotativo.h:44
TTubo.h
TBloqueMotor
Definition: TBloqueMotor.h:43