OpenWAM
TLumbrera.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 "TLumbrera.h"
32 #include "TCilindro.h"
33 
34 //---------------------------------------------------------------------------
35 //---------------------------------------------------------------------------
36 TLumbrera::TLumbrera(double Biela, double Carrera) :
37  TTipoValvula(nmLumbrera2T) {
38 
39  FBiela = Biela;
40  FCarrera = Carrera;
41  fun_CDin = NULL;
42  fun_CDout = NULL;
43 
44 }
45 
46 //---------------------------------------------------------------------------
47 //---------------------------------------------------------------------------
48 
49 TLumbrera::~TLumbrera() {
50 
51 }
52 
53 //---------------------------------------------------------------------------
54 //---------------------------------------------------------------------------
55 
56 TLumbrera::TLumbrera(TLumbrera *Origen, int Valvula) :
57  TTipoValvula(nmLumbrera2T) {
58 
59  FValvula = Valvula;
60  FAltura = Origen->FAltura;
61  FAnchura = Origen->FAnchura;
62  FRadioSup = Origen->FRadioSup;
63  FRadioInf = Origen->FRadioInf;
64  FPosicionPMI = Origen->FPosicionPMI;
65  FDiametroRef = Origen->FDiametroRef;
66 
67  FDiamRef = FDiametroRef;
68 
69  FNumeroOrden = Origen->FNumeroOrden;
70 
71  FNumCD = Origen->FNumCD;
72 
73  FAnguloApertura = Origen->FAnguloApertura; // Hector 2T
74  FAnguloCierre = Origen->FAnguloCierre; // Hector 2T
75  FBiela = Origen->FBiela; // Hector 2T
76  FCarrera = Origen->FCarrera; // Hector 2T
77 
78  FApertura.resize(Origen->FApertura.size());
79  FDatosCDEntrada.resize(Origen->FDatosCDEntrada.size());
80  FDatosCDSalida.resize(Origen->FDatosCDSalida.size());
81 
82  for(int i = 0; i < FNumCD; i++) {
83  FApertura[i] = Origen->FApertura[i];
84  FDatosCDEntrada[i] = Origen->FDatosCDEntrada[i];
85  FDatosCDSalida[i] = Origen->FDatosCDSalida[i];
86  }
87  fun_CDin = new Hermite_interp(FApertura, FDatosCDEntrada);
88  fun_CDout = new Hermite_interp(FApertura, FDatosCDSalida);
89 }
90 
91 //---------------------------------------------------------------------------
92 //---------------------------------------------------------------------------
93 
94 void TLumbrera::LeeDatosIniciales(const char *FileWAM, fpos_t &filepos, int norden, bool HayMotor,
95  TBloqueMotor *Engine) {
96  try {
97 
98  FILE *fich = fopen(FileWAM, "r");
99  fsetpos(fich, &filepos);
100 
101  FNumeroOrden = norden;
102 
103  fscanf(fich, "%lf %lf %lf %lf %lf %lf ", &FAltura, &FAnchura, &FRadioSup, &FRadioInf, &FPosicionPMI, &FDiametroRef);
104  fscanf(fich, "%d ", &FNumCD);
105 
106  FApertura.resize(FNumCD);
107  FDatosCDEntrada.resize(FNumCD);
108  FDatosCDSalida.resize(FNumCD);
109 
110  for(int j = 0; j < FNumCD; ++j) {
111  fscanf(fich, "%lf ", &FApertura[j]);
112  }
113  for(int j = 0; j < FNumCD; ++j) {
114  fscanf(fich, "%lf ", &FDatosCDEntrada[j]);
115  }
116  for(int j = 0; j < FNumCD; ++j) {
117  fscanf(fich, "%lf ", &FDatosCDSalida[j]);
118  }
119 
120  CalculateOpeningANDClose();
121 
122  fgetpos(fich, &filepos);
123  fclose(fich);
124 
125  } catch(exception &N) {
126  std::cout << "ERROR: LeeDatosIniciales Lumbrera" << std::endl;
127  //std::cout << "Tipo de error: " << N.what().scr() << std::endl;
128  throw Exception(N.what());
129 
130  }
131 }
132 
133 //---------------------------------------------------------------------------
134 //---------------------------------------------------------------------------
135 
136 void TLumbrera::CalculaCD(double Angulo) {
137 
138  FApertActual = FAltura + FPosicionPMI - CalculaDistPMI(Angulo);
139 
140  if(FApertActual <= 0) {
141  FApertActual = 0.;
142  FCDTubVol = 0.;
143  FCDVolTub = 0.;
144  } else {
145  FCDTubVol = fun_CDin->interp(FApertActual);
146  FCDVolTub = fun_CDout->interp(FApertActual);
147  }
148 }
149 
150 void TLumbrera::GetCDin(double Time) {
151 
152  double Angulo = FCylinder->getAnguloActual();
153 
154  FApertActual = FAltura + FPosicionPMI - CalculaDistPMI(Angulo);
155 
156  if(FApertActual <= 0) {
157  FApertActual = 0.;
158  FCDTubVol = 0.;
159  } else {
160  FCDTubVol = fun_CDin->interp(FApertActual);
161  }
162 }
163 
164 void TLumbrera::GetCDout(double Time) {
165 
166  double Angulo = FCylinder->getAnguloActual();
167 
168  FApertActual = FAltura + FPosicionPMI - CalculaDistPMI(Angulo);
169 
170  if(FApertActual <= 0) {
171  FApertActual = 0.;
172  FCDVolTub = 0.;
173  } else {
174  FCDVolTub = fun_CDout->interp(FApertActual);
175  }
176 }
177 
178 //---------------------------------------------------------------------------
179 //---------------------------------------------------------------------------
180 
181 inline double TLumbrera::CalculaDistPMI(double x) {
182 
183  double c = __units::DegToRad(x);
184 
185  return FCarrera - (FBiela + FCarrera * (1. - cos(c)) / 2. - sqrt(pow2(FBiela) - pow2(FCarrera * sin(c) / 2.)));
186 }
187 
188 inline double TLumbrera::CalculaApertura(double x) {
189  return FAltura + FPosicionPMI - CalculaDistPMI(x);
190 }
191 
192 void TLumbrera::CalculateOpeningANDClose() {
193  bool ang_found = false;
194  double ang0 = 0.;
195  double ang1 = 180.;
196  double apt0 = FAltura + FPosicionPMI - CalculaDistPMI(ang0);
197  double apt1 = FAltura + FPosicionPMI - CalculaDistPMI(ang1);
198  double ang = 0., apt = 0.;
199  while(ang1 - ang0 > 0.01) {
200  ang = (ang1 + ang0) / 2.;
201  apt = FAltura + FPosicionPMI - CalculaDistPMI(ang);
202  if(apt > 0) {
203  ang1 = ang;
204  apt1 = apt;
205  } else {
206  ang0 = ang;
207  apt0 = apt;
208  }
209  }
210  FAnguloApertura = ang;
211  FAnguloCierre = 360. - ang;
212 
213 }
214 
215 #pragma package(smart_init)
TTipoValvula
Definition: TTipoValvula.h:53
Hermite_interp
Definition: Math_wam.h:311
Exception
Custom exception class.
Definition: Exception.hpp:39
TLumbrera
Definition: TLumbrera.h:45
TBloqueMotor
Definition: TBloqueMotor.h:43
pow2
T pow2(T x)
Returns x to the power of 2.
Definition: Math_wam.h:88