OpenWAM
TControlInyeccion.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 "TControlInyeccion.h"
32 
33 //---------------------------------------------------------------------------
34 //---------------------------------------------------------------------------
35 
36 TControlInyeccion::TControlInyeccion() {
37 
38  FVector_Mf_mapa = NULL;
39  FVector_Mf_mapaPrail = NULL;
40  FVector_Prail_Regimen_mapa = NULL;
41  FVector_Regimen_mapa = NULL;
42 
43  FMapa_SOI_Principal = NULL;
44  FMapa_SOI_Piloto = NULL;
45  FMapa_Combustible_Piloto = NULL;
46  FMapa_Prail = NULL;
47  FSOI = NULL;
48  FMasaFuel = NULL;
49 
50 }
51 
52 //---------------------------------------------------------------------------
53 //---------------------------------------------------------------------------
54 
55 TControlInyeccion::~TControlInyeccion() {
56 
57  if(FVector_Mf_mapa != NULL)
58  delete FVector_Mf_mapa;
59  if(FVector_Mf_mapaPrail != NULL)
60  delete FVector_Mf_mapaPrail;
61  if(FVector_Prail_Regimen_mapa != NULL)
62  delete FVector_Prail_Regimen_mapa;
63  if(FVector_Regimen_mapa != NULL)
64  delete FVector_Regimen_mapa;
65 
66  for(int i = 0; i < FNumeroDatos_Mf; i++) {
67  delete FMapa_Combustible_Piloto[i];
68  delete FMapa_SOI_Principal[i];
69  delete FMapa_SOI_Piloto[i];
70  delete FMapa_Prail[i];
71  }
72  delete[] FMapa_Combustible_Piloto;
73  delete[] FMapa_SOI_Principal;
74  delete[] FMapa_SOI_Piloto;
75  delete[] FMapa_Prail;
76  delete[] FSOI;
77  delete[] FMasaFuel;
78 
79 }
80 
81 //---------------------------------------------------------------------------
82 //---------------------------------------------------------------------------
83 
84 void TControlInyeccion::LeeDatosEntrada(char *Ruta, FILE *fich) {
85  char *FileInyeccion;
86  char *DatosInyeccion;
87 
88  try {
89  for(int i = 0; i <= (int) strlen(Ruta); i++) {
90  DatosInyeccion[i] = Ruta[i];
91  }
92 
93  fscanf(fich, "%s ", &FileInyeccion);
94  strcat(DatosInyeccion, FileInyeccion);
95 
96  FichInyeccion = fopen(DatosInyeccion, "r");
97  if((FichInyeccion = fopen(DatosInyeccion, "r")) == NULL) {
98  std::cout << "ERROR: Fichero de con datos del inyeccion no cargado";
99  } else {
100  fscanf(FichInyeccion, "%d %d %d %d ", &FNumeroDatos_Prail_Regimen, &FNumeroDatos_Mf_Prail, &FNumeroDatos_Mf,
101  &FNumeroDatos_Regimen);
102  FVector_Mf_mapa = new double[FNumeroDatos_Mf];
103  FVector_Mf_mapaPrail = new double[FNumeroDatos_Mf_Prail];
104  FVector_Prail_Regimen_mapa = new double[FNumeroDatos_Prail_Regimen];
105  FVector_Regimen_mapa = new double[FNumeroDatos_Regimen];
106 
107  FMapa_Combustible_Piloto = new double*[FNumeroDatos_Mf];
108  FMapa_SOI_Principal = new double*[FNumeroDatos_Mf];
109  FMapa_SOI_Piloto = new double*[FNumeroDatos_Mf];
110  FMapa_Prail = new double*[FNumeroDatos_Mf_Prail];
111  for(int i = 0; i < FNumeroDatos_Mf; i++) {
112  FMapa_Combustible_Piloto[i] = new double[FNumeroDatos_Regimen];
113  FMapa_SOI_Principal[i] = new double[FNumeroDatos_Regimen];
114  FMapa_SOI_Piloto[i] = new double[FNumeroDatos_Regimen];
115  FMapa_Prail[i] = new double[FNumeroDatos_Prail_Regimen];
116  }
117 
118  for(int i = 0; i < FNumeroDatos_Prail_Regimen; i++) {
119  fscanf(FichInyeccion, "%lf ", &FVector_Prail_Regimen_mapa[i]);
120  }
121  for(int i = 0; i < FNumeroDatos_Regimen; i++) {
122  fscanf(FichInyeccion, "%lf ", &FVector_Regimen_mapa[i]);
123  }
124  for(int i = 0; i < FNumeroDatos_Mf; i++) {
125  fscanf(FichInyeccion, "%lf ", &FVector_Mf_mapa[i]);
126  }
127  for(int i = 0; i < FNumeroDatos_Mf_Prail; i++) {
128  fscanf(FichInyeccion, "%lf ", &FVector_Mf_mapaPrail[i]);
129  }
130  for(int i = 0; i < FNumeroDatos_Mf_Prail; i++) {
131  for(int j = 0; j < FNumeroDatos_Prail_Regimen; j++) {
132  fscanf(FichInyeccion, "%lf ", &FMapa_Prail[i][j]);
133  }
134  }
135  for(int i = 0; i < FNumeroDatos_Mf; i++) {
136  for(int j = 0; j < FNumeroDatos_Regimen; j++) {
137  fscanf(FichInyeccion, "%lf ", &FMapa_SOI_Principal[i][j]);
138  }
139  }
140  for(int i = 0; i < FNumeroDatos_Mf; i++) {
141  for(int j = 0; j < FNumeroDatos_Regimen; j++) {
142  fscanf(FichInyeccion, "%lf ", &FMapa_SOI_Piloto[i][j]);
143  }
144  }
145  for(int i = 0; i < FNumeroDatos_Mf; i++) {
146  for(int j = 0; j < FNumeroDatos_Regimen; j++) {
147  fscanf(FichInyeccion, "%lf ", &FMapa_Combustible_Piloto[i][j]);
148  }
149  }
150  fclose(FichInyeccion);
151  }
152  FSOI = new double[2];
153  FMasaFuel = new double[2];
154 
155  } catch(exception &N) {
156  std::cout << "ERROR: TControlInyeccion::LeeDatosEntrada (DLL)" << std::endl;
157  std::cout << "Tipo de error: " << N.what() << std::endl;
158  throw Exception(N.what());
159  }
160 }
161 
162 //---------------------------------------------------------------------------
163 //---------------------------------------------------------------------------
164 
165 void TControlInyeccion::CalculaSistemaInyeccion(double MasaFuel, double Regimen) {
166  try {
167  double Prail = 0.;
168 // En esta funcion u otras que puedas necesitar debes programar las acciones
169 // a realizar para realizar el control sobre el sistema de inyeccion, de acuerdo
170 // a los requerimientos de ACT. Actualmente ACT necesita como datos para cada ciclo:
171 // 1.- Numero de inyecciones.
172 // 2.- Presion de inyeccion.
173 // 3.- ACT puede calcular hasta con 8 inyecciones de combustible. Para cada una de
174 // ellas se ha de definir el CrankAngle de begining y la masa inyectada. Hay que dar
175 // estos datos para las 8, de modo que aquellas que no son utilizadas deben tener
176 // como angulo de begining el valor 180 y como masa inyectada 0, de acuerdo a lo que
177 // el manual de ACT nos indica.
178 
179  FNumeroInyecciones = 2;
180  MasaFuel = MasaFuel * 1e6; // En los mapas la masa de fuel esta en mg/cc. En ACT tambien,
181  // luego se pasara el dato ya en estas unidades.
182 
183  Prail = Interpolacion_bidimensional(Regimen, MasaFuel, FVector_Mf_mapaPrail, FVector_Prail_Regimen_mapa, FMapa_Prail,
184  FNumeroDatos_Prail_Regimen, FNumeroDatos_Mf_Prail);
185 
186  FPrail = Prail * 10; // Presion del common-rail en bar
187 
188  /* SOI de la inyeccion principal */
189  FSOI[1] = Interpolacion_bidimensional(Regimen, MasaFuel, FVector_Mf_mapa, FVector_Regimen_mapa, FMapa_SOI_Principal,
190  FNumeroDatos_Regimen, FNumeroDatos_Mf);
191 
192  /* Masa de fuel inyectada en la piloto */
193  FMasaFuel[0] = Interpolacion_bidimensional(Regimen, MasaFuel, FVector_Mf_mapa, FVector_Regimen_mapa,
194  FMapa_Combustible_Piloto, FNumeroDatos_Regimen, FNumeroDatos_Mf);
195 
196  /* Masa de fuel inyectada en la principal */
197  FMasaFuel[1] = MasaFuel - FMasaFuel[0];
198 
199  FDiferencia_SOI = Interpolacion_bidimensional(Regimen, MasaFuel, FVector_Mf_mapa, FVector_Regimen_mapa,
200  FMapa_SOI_Piloto, FNumeroDatos_Regimen, FNumeroDatos_Mf);
201 
202  /* SOI de la inyeccion piloto */
203  FSOI[0] = FSOI[1] - FDiferencia_SOI;
204 
205  for(int i = 2; i < 8; i++) {
206  FMasaFuel[i] = 0.;
207  FSOI[i] = 180.;
208  }
209 
210  } catch(exception &N) {
211  std::cout << "ERROR: TControlInyeccion::CalculaSistemaInyeccion " << std::endl;
212  std::cout << "Tipo de error: " << N.what() << std::endl;
213  throw Exception(N.what());
214  }
215 }
216 
217 //---------------------------------------------------------------------------
218 //---------------------------------------------------------------------------
219 
220 double TControlInyeccion::GetSOI(int i) {
221  try {
222 
223  return FSOI[i];
224 
225  } catch(exception &N) {
226  std::cout << "ERROR: TControlInyeccion::GetSOI (DLL) " << std::endl;
227  std::cout << "Tipo de error: " << N.what() << std::endl;
228  throw Exception(N.what());
229  }
230 }
231 
232 //---------------------------------------------------------------------------
233 //---------------------------------------------------------------------------
234 
235 double TControlInyeccion::GetMasaFuel(int i) {
236  try {
237 
238  return FMasaFuel[i];
239 
240  } catch(exception &N) {
241  std::cout << "ERROR: TControlInyeccion::GetMasaFuel (DLL)" << std::endl;
242  std::cout << "Tipo de error: " << N.what() << std::endl;
243  throw Exception(N.what());
244  }
245 }
246 
247 //---------------------------------------------------------------------------
248 //---------------------------------------------------------------------------
249 
250 #pragma package(smart_init)
251 
Exception
Custom exception class.
Definition: Exception.hpp:39