OpenWAM
TTable.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 "TTable.h"
32 
33 //---------------------------------------------------------------------------
34 
35 TTable::TTable(int i) :
36  TController(nmCtlPID, i) {
37 
38  /*fError_ant=0;
39  fTime_ant=0;
40  fInicio=true; */
41 }
42 TTable::~TTable() {
43 
44 }
45 
46 double TTable::Output(double Time) {
47 
48 }
49 
50 void TTable::LeeController(const char *FileWAM, fpos_t &filepos) {
51 
52  int xnum = 0, ynum = 0;
53  double x = 0., y = 0., z = 0.;
54  std::vector<double> zz;
55 
56  FILE *fich = fopen(FileWAM, "r");
57  fsetpos(fich, &filepos);
58 
59  fscanf(fich, "%d ", &fDimensiones);
60  fscanf(fich, "%d ", &xnum);
61  for(int i = 0; i < xnum; i++) {
62  fscanf(fich, "%d ", &x);
63  fX_map.push_back(x);
64  }
65  if(fDimensiones == 1) {
66  for(int i = 0; i < xnum; i++) {
67  fscanf(fich, "%d ", &y);
68  fY_map.push_back(y);
69  }
70  } else if(fDimensiones == 2) {
71 
72  }
73 
74  fgetpos(fich, &filepos);
75  fclose(fich);
76 
77 }
78 
79 void TTable::AsignaObjetos(TSensor **Sensor, TController **Controller) {
80 //std::cout << "entro";
81 
82  FSensor.push_back(Sensor[FSensorID[0] - 1]);
83 
84 //fSetPointController=Controller[fSetPointControllerID-1];
85 
86 }
87 
88 void TTable::LeeResultadosMedControlador(const char *FileWAM, fpos_t &filepos) {
89  try {
90  int nvars = 0, var = 0;
91 
92  FILE *fich = fopen(FileWAM, "r");
93  fsetpos(fich, &filepos);
94 
95  fscanf(fich, "%d ", &nvars);
96  for(int i = 0; i < nvars; i++) {
97  fscanf(fich, "%d ", &var);
98  switch(var) {
99  case 0:
100  FResMediosCtrl.Output = true;
101  break;
102  case 1:
103  FResMediosCtrl.Error = true;
104  break;
105  case 2:
106  FResMediosCtrl.POutput = true;
107  break;
108  case 3:
109  FResMediosCtrl.IOutput = true;
110  break;
111  case 4:
112  FResMediosCtrl.DOutput = true;
113  break;
114  case 5:
115  FResMediosCtrl.Output_filt = true;
116  break;
117  default:
118  std::cout << "Resultados medios en Controlador " << fID << " no implementados " << std::endl;
119  }
120  }
121 
122  fgetpos(fich, &filepos);
123  fclose(fich);
124  } catch(exception &N) {
125  std::cout << "ERROR: TTable::LeeResultadosControlador en el controlador " << fID << std::endl;
126  std::cout << "Tipo de error: " << N.what() << std::endl;
127  throw Exception(N.what());
128  }
129 }
130 
131 void TTable::LeeResultadosInsControlador(const char *FileWAM, fpos_t &filepos) {
132  try {
133  int nvars = 0, var = 0;
134 
135  FILE *fich = fopen(FileWAM, "r");
136  fsetpos(fich, &filepos);
137 
138  fscanf(fich, "%d ", &nvars);
139  for(int i = 0; i < nvars; i++) {
140  fscanf(fich, "%d ", &var);
141  switch(var) {
142  case 0:
143  FResInstantCtrl.Output = true;
144  break;
145  case 1:
146  FResInstantCtrl.Error = true;
147  break;
148  case 2:
149  FResInstantCtrl.POutput = true;
150  break;
151  case 3:
152  FResInstantCtrl.IOutput = true;
153  break;
154  case 4:
155  FResInstantCtrl.DOutput = true;
156  break;
157  case 5:
158  FResInstantCtrl.Output_filt = true;
159  break;
160  default:
161  std::cout << "Resultados instantaneos en Controlador " << fID << " no implementados " << std::endl;
162  }
163  }
164 
165  fgetpos(fich, &filepos);
166  fclose(fich);
167  } catch(exception &N) {
168  std::cout << "ERROR: TTable::LeeResultadosInsControlador en el controlador " << fID << std::endl;
169  std::cout << "Tipo de error: " << N.what() << std::endl;
170  throw Exception(N.what());
171  }
172 }
173 
174 void TTable::CabeceraResultadosMedControlador(stringstream *medoutput) {
175  try {
176  std::string Label;
177 
178  if(FResMediosCtrl.Output) {
179  Label = "\t" + PutLabel(705) + std::to_string(fID) + PutLabel(901);
180  *medoutput << Label.c_str();
181  }
182  if(FResMediosCtrl.Error) {
183  Label = "\t" + PutLabel(706) + std::to_string(fID) + PutLabel(901);
184  *medoutput << Label.c_str();
185  }
186  if(FResMediosCtrl.POutput) {
187  Label = "\t" + PutLabel(709) + std::to_string(fID) + PutLabel(901);
188  *medoutput << Label.c_str();
189  }
190  if(FResMediosCtrl.IOutput) {
191  Label = "\t" + PutLabel(710) + std::to_string(fID) + PutLabel(901);
192  *medoutput << Label.c_str();
193  }
194  if(FResMediosCtrl.DOutput) {
195  Label = "\t" + PutLabel(711) + std::to_string(fID) + PutLabel(901);
196  *medoutput << Label.c_str();
197  }
198  if(FResMediosCtrl.Output_filt) {
199  Label = "\t" + PutLabel(712) + std::to_string(fID) + PutLabel(901);
200  *medoutput << Label.c_str();
201  }
202 
203  } catch(exception &N) {
204  std::cout << "ERROR: TTable::CabeceraResultadosMedControlador en el controlador " << fID << std::endl;
205  std::cout << "Tipo de error: " << N.what() << std::endl;
206  throw Exception(N.what());
207  }
208 }
209 
210 void TTable::CabeceraResultadosInsControlador(stringstream *insoutput) {
211  try {
212  std::string Label;
213 
214  if(FResInstantCtrl.Output) {
215  Label = "\t" + PutLabel(705) + std::to_string(fID) + PutLabel(901);
216  *insoutput << Label.c_str();
217  }
218  if(FResInstantCtrl.Error) {
219  Label = "\t" + PutLabel(706) + std::to_string(fID) + PutLabel(901);
220  *insoutput << Label.c_str();
221  }
222  if(FResInstantCtrl.POutput) {
223  Label = "\t" + PutLabel(709) + std::to_string(fID) + PutLabel(901);
224  *insoutput << Label.c_str();
225  }
226  if(FResInstantCtrl.IOutput) {
227  Label = "\t" + PutLabel(710) + std::to_string(fID) + PutLabel(901);
228  *insoutput << Label.c_str();
229  }
230  if(FResInstantCtrl.DOutput) {
231  Label = "\t" + PutLabel(711) + std::to_string(fID) + PutLabel(901);
232  *insoutput << Label.c_str();
233  }
234  if(FResInstantCtrl.Output_filt) {
235  Label = "\t" + PutLabel(712) + std::to_string(fID) + PutLabel(901);
236  *insoutput << Label.c_str();
237  }
238  } catch(exception &N) {
239  std::cout << "ERROR: TTable::CabeceraResultadosInsControlador en el controlador " << fID << std::endl;
240  std::cout << "Tipo de error: " << N.what() << std::endl;
241  throw Exception(N.what());
242  }
243 }
244 
245 void TTable::ImprimeResultadosMedControlador(stringstream *medoutput) {
246  try {
247  std::string Label;
248 
249  if(FResMediosCtrl.Output) {
250  *medoutput << "\t" << FResMediosCtrl.OutputMED;
251  }
252  if(FResMediosCtrl.Error) {
253  *medoutput << "\t" << FResMediosCtrl.ErrorMED;
254  }
255  if(FResMediosCtrl.POutput) {
256  *medoutput << "\t" << FResMediosCtrl.POutputMED;
257  }
258  if(FResMediosCtrl.IOutput) {
259  *medoutput << "\t" << FResMediosCtrl.IOutputMED;
260  }
261  if(FResMediosCtrl.DOutput) {
262  *medoutput << "\t" << FResMediosCtrl.DOutputMED;
263  }
264  if(FResMediosCtrl.Output_filt) {
265  *medoutput << "\t" << FResMediosCtrl.Output_filtMED;
266  }
267  } catch(exception &N) {
268  std::cout << "ERROR: TTable::ImprimeResultadosMedControlador en el controlador " << fID << std::endl;
269  std::cout << "Tipo de error: " << N.what() << std::endl;
270  throw Exception(N.what());
271  }
272 }
273 
274 void TTable::ImprimeResultadosInsControlador(stringstream *insoutput) {
275  try {
276  std::string Label;
277 
278  if(FResInstantCtrl.Output) {
279  *insoutput << "\t" << FResInstantCtrl.OutputINS;
280  }
281  if(FResInstantCtrl.Error) {
282  *insoutput << "\t" << FResInstantCtrl.ErrorINS;
283  }
284  if(FResInstantCtrl.POutput) {
285  *insoutput << "\t" << FResInstantCtrl.POutputINS;
286  }
287  if(FResInstantCtrl.IOutput) {
288  *insoutput << "\t" << FResInstantCtrl.IOutputINS;
289  }
290  if(FResInstantCtrl.DOutput) {
291  *insoutput << "\t" << FResInstantCtrl.DOutputINS;
292  }
293  if(FResInstantCtrl.Output_filt) {
294  *insoutput << "\t" << FResInstantCtrl.Output_filtINS;
295  }
296  } catch(exception &N) {
297  std::cout << "ERROR: TTable::CabeceraResultadosInsControlador en el controlador " << fID << std::endl;
298  std::cout << "Tipo de error: " << N.what() << std::endl;
299  throw Exception(N.what());
300  }
301 }
302 
304  try {
305 
306  FResMediosCtrl.OutputSUM = 0.;
307  FResMediosCtrl.ErrorSUM = 0.;
308  FResMediosCtrl.POutputSUM = 0.;
309  FResMediosCtrl.IOutputSUM = 0.;
310  FResMediosCtrl.DOutputSUM = 0.;
311  FResMediosCtrl.Output_filtSUM = 0.;
312  FResMediosCtrl.TiempoSUM = 0.;
313  FResMediosCtrl.Tiempo0 = 0.;
314 
315  } catch(exception &N) {
316  std::cout << "ERROR: TTable::IniciaMedias en el controlador: " << fID << std::endl;
317 //std::cout << "Tipo de error: " << N.what() << std::endl;
318  throw Exception(N.what());
319  }
320 }
321 
323  try {
324 
325  if(FResMediosCtrl.Output) {
326  FResMediosCtrl.OutputMED = FResMediosCtrl.OutputSUM / FResMediosCtrl.TiempoSUM;
327  FResMediosCtrl.OutputSUM = 0.;
328  }
329  if(FResMediosCtrl.Error) {
330  FResMediosCtrl.ErrorMED = FResMediosCtrl.ErrorSUM / FResMediosCtrl.TiempoSUM;
331  FResMediosCtrl.ErrorSUM = 0.;
332  }
333  if(FResMediosCtrl.POutput) {
334  FResMediosCtrl.POutputMED = FResMediosCtrl.POutputSUM / FResMediosCtrl.TiempoSUM;
335  FResMediosCtrl.POutputSUM = 0.;
336  }
337  if(FResMediosCtrl.IOutput) {
338  FResMediosCtrl.IOutputMED = FResMediosCtrl.IOutputSUM / FResMediosCtrl.TiempoSUM;
339  FResMediosCtrl.IOutputSUM = 0.;
340  }
341  if(FResMediosCtrl.DOutput) {
342  FResMediosCtrl.DOutputMED = FResMediosCtrl.DOutputSUM / FResMediosCtrl.TiempoSUM;
343  FResMediosCtrl.DOutputSUM = 0.;
344  }
345  if(FResMediosCtrl.Output_filt) {
346  FResMediosCtrl.Output_filtMED = FResMediosCtrl.Output_filtSUM / FResMediosCtrl.TiempoSUM;
347  FResMediosCtrl.Output_filtSUM = 0.;
348  }
349  FResMediosCtrl.TiempoSUM = 0;
350 
351  } catch(exception &N) {
352  std::cout << "ERROR: TTable::ResultadosMediosController en el eje: " << fID << std::endl;
353 //std::cout << "Tipo de error: " << N.what() << std::endl;
354  throw Exception(N.what());
355  }
356 }
357 
359  try {
360  /* Lo que se hace en esta funcion se realiza dentro del calculo del eje, para asi poder
361  llevar a cabo la salida de resultados medios por pantalla. */
362  double Delta = Actual - FResMediosCtrl.Tiempo0;
363 
364  if(FResMediosCtrl.Output) {
365  FResMediosCtrl.OutputSUM += fOutput * Delta;
366  }
367  if(FResMediosCtrl.Error) {
368  FResMediosCtrl.ErrorSUM += fError * Delta;
369  }
370  if(FResMediosCtrl.POutput) {
371  FResMediosCtrl.POutputSUM += fpact * Delta;
372  }
373  if(FResMediosCtrl.IOutput) {
374  FResMediosCtrl.IOutputSUM += fiact * Delta;
375  }
376  if(FResMediosCtrl.DOutput) {
377  FResMediosCtrl.DOutputSUM += fdact * Delta;
378  }
379  if(FResMediosCtrl.Output_filt) {
380  FResMediosCtrl.Output_filtSUM += fOutput_filt * Delta;
381  }
382  FResMediosCtrl.TiempoSUM += Delta;
383  FResMediosCtrl.Tiempo0 = Actual;
384 
385  } catch(exception &N) {
386  std::cout << "ERROR: TTable::AcumulaResultadosMediosController en el eje: " << fID << std::endl;
387 //std::cout << "Tipo de error: " << N.what() << std::endl;
388  throw Exception(N.what());
389  }
390 }
391 
393  try {
394  if(FResInstantCtrl.Output)
395  FResInstantCtrl.OutputINS = fOutput;
396  if(FResInstantCtrl.Error)
397  FResInstantCtrl.ErrorINS = fError;
398  if(FResInstantCtrl.POutput)
399  FResInstantCtrl.POutputINS = fpact;
400  if(FResInstantCtrl.IOutput)
401  FResInstantCtrl.IOutputINS = fiact;
402  if(FResInstantCtrl.DOutput)
403  FResInstantCtrl.DOutputINS = fdact;
404  if(FResInstantCtrl.Output_filt)
405  FResInstantCtrl.Output_filtINS = fOutput_filt;
406 
407  } catch(exception &N) {
408  std::cout << "ERROR: TTable::ResultadosInstantController en el eje " << fID << std::endl;
409  std::cout << "Tipo de error: " << N.what() << std::endl;
410  throw Exception(N.what());
411  }
412 }
413 
414 #pragma package(smart_init)
TTable::Output
double Output(double Time)
Definition: TTable.cpp:46
TController
Definition: TController.h:37
TTable::LeeController
void LeeController(const char *FileWAM, fpos_t &filepos)
Definition: TTable.cpp:50
TTable::IniciaMedias
void IniciaMedias()
Definition: TTable.cpp:303
TTable::LeeResultadosMedControlador
void LeeResultadosMedControlador(const char *FileWAM, fpos_t &filepos)
Definition: TTable.cpp:88
TTable::LeeResultadosInsControlador
void LeeResultadosInsControlador(const char *FileWAM, fpos_t &filepos)
Definition: TTable.cpp:131
TController::FSensorID
iVector FSensorID
Array with the ID of the sensor inputs.
Definition: TController.h:43
TController::FResMediosCtrl
stResMediosCtrl FResMediosCtrl
Struct with the average results of the controllers.
Definition: TController.h:49
PutLabel
std::string PutLabel(int idx)
Returns an integer.
Definition: labels.cpp:475
Exception
Custom exception class.
Definition: Exception.hpp:39
TTable::ResultadosInstantController
void ResultadosInstantController()
Definition: TTable.cpp:392
TTable::AsignaObjetos
void AsignaObjetos(TSensor **Sensor, TController **Controller)
Definition: TTable.cpp:79
TController::FResInstantCtrl
stResInstantCtrl FResInstantCtrl
Struct with the average results of the controllers.
Definition: TController.h:50
TTable::AcumulaResultadosMediosController
void AcumulaResultadosMediosController(double Actual)
Definition: TTable.cpp:358
TTable::ResultadosMediosController
void ResultadosMediosController()
Definition: TTable.cpp:322
TSensor
Definition: TSensor.h:42
TController::FSensor
std::vector< TSensor * > FSensor
Array with the pointers of the sensor inputs.
Definition: TController.h:40