OpenWAM
TRegimenMotor.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 "TRegimenMotor.h"
32 //---------------------------------------------------------------------------
33 //---------------------------------------------------------------------------
34 TRegimenMotor::TRegimenMotor() {
35 
36 }
37 
38 //---------------------------------------------------------------------------
39 //---------------------------------------------------------------------------
40 
41 TRegimenMotor::~TRegimenMotor() {
42  if(FTiempo != NULL)
43  delete[] FTiempo;
44 
45  if(FRegimen != NULL)
46  delete[] FRegimen;
47 }
48 
49 //---------------------------------------------------------------------------
50 //---------------------------------------------------------------------------
51 
52 void TRegimenMotor::LeeDatosEntrada(char *Ruta, FILE *fich) {
53  char *FileRegimen;
54  char *DatosRegimen;
55 
56  try {
57 
58  for(int i = 0; i <= (int) strlen(Ruta); i++) {
59  DatosRegimen[i] = Ruta[i];
60  }
61 
62  fscanf(fich, "%s ", &FileRegimen);
63  strcat(DatosRegimen, FileRegimen);
64 
65  FichRegimen = fopen(DatosRegimen, "r");
66  if((FichRegimen = fopen(DatosRegimen, "r")) == NULL) {
67  std::cout << "ERROR: Fichero de regimen de giro no cargado";
68  } else {
69  FNumeroDatos = 0;
70  double temp1 = 0.;
71  double temp2 = 0.;
72  while(!feof(FichRegimen)) {
73  fscanf(FichRegimen, "%lf %lf ", &temp1, &temp2);
74  FNumeroDatos++;
75  }
76  fclose(FichRegimen);
77  FTiempo = new double[FNumeroDatos];
78  FRegimen = new double[FNumeroDatos];
79  FichRegimen = fopen(DatosRegimen, "r");
80  int i = 0;
81  while(!feof(FichRegimen)) {
82  fscanf(FichRegimen, "%lf %lf ", &FTiempo[i], &FRegimen[i]);
83  i++;
84  }
85  fclose(FichRegimen);
86 
87  }
88  } catch(exception &N) {
89  std::cout << "ERROR: LeeDatosEntrada de RegimenMotor (DLL)" << std::endl;
90  std::cout << "Tipo de error: " << N.what() << std::endl;
91  throw Exception(N.what());
92  }
93 }
94 
95 //---------------------------------------------------------------------------
96 //---------------------------------------------------------------------------
97 
98 void TRegimenMotor::CalculaRegimen(double TiempoActual) {
99  try {
100 // AQUI SE CALCULAN LOS COEFICIENTES DE DESCARGA Y TURBULENCIA
101 
102  int j = 0, jmax = FNumeroDatos - 1;
103  double RegimenAct = 0., deltaT = 0., t = 0.;
104  while(TiempoActual > FTiempo[j] && j < jmax) {
105  j++;
106  }
107  if(j == jmax) {
108  RegimenAct = FRegimen[jmax];
109  } else {
110  deltaT = FTiempo[j] - FTiempo[j - 1];
111  t = TiempoActual - FTiempo[j - 1];
112  RegimenAct = xit_(FRegimen[j - 1], FRegimen[j], deltaT, t);
113  }
114 
115  FRegimenMotor = RegimenAct;
116 
117  } catch(exception &N) {
118  std::cout << "ERROR: Calculo del Regimen del Engine(DLL)" << std::endl;
119  std::cout << "Tipo de error: " << N.what() << std::endl;
120  throw Exception(N.what());
121  }
122 }
123 
124 //---------------------------------------------------------------------------
125 
126 double TRegimenMotor::xit_(double vizq, double vder, double axid, double xif) {
127  try {
128  double xx = 0., yy = 0.;
129  double ret_val = 0.;
130 
131  xx = vder - vizq;
132  if(axid != 0.) {
133  yy = xx / axid * xif;
134  ret_val = vizq + yy;
135  } else {
136  printf("ERROR: valores entrada xit\n");
137  throw Exception("");
138  }
139  return ret_val;
140  } catch(exception &N) {
141  std::cout << "ERROR: xit_" << std::endl;
142  std::cout << "Tipo de error: " << N.what() << std::endl;
143  throw Exception(N.what());
144  }
145 }
146 
147 //---------------------------------------------------------------------------
148 
149 #pragma package(smart_init)
Exception
Custom exception class.
Definition: Exception.hpp:39