OpenWAM
TGain.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  * TGain.cpp
26  *
27  * Created on: 14/07/2014
28  * Author: farnau
29  *
30  \*--------------------------------------------------------------------------------*/
31 
32 #include "TGain.h"
33 
34 TGain::TGain(int i) :
35  TController(nmGainCtrl, i) {
36  fID = i + 1;
37  FGain = 1.;
38 }
39 
40 TGain::~TGain() {
41 
42 }
43 
44 double TGain::Output(double Time) {
45 
46  fOutput = FGainInput->Output(Time) * FGain;
47  return fOutput;
48 }
49 
50 void TGain::LeeController(const char *FileWAM, fpos_t &filepos) {
51 
52  int Type = 0;
53 
54  FILE *fich = fopen(FileWAM, "r");
55  fsetpos(fich, &filepos);
56 
57  fscanf(fich, "%lf ", &FGain);
58  fscanf(fich, "%d %d", &Type, &FObjectID);
59  if(Type == 0) {
60  FInObject = nmInController;
61  } else {
62  FInObject = nmInSensor;
63  }
64 
65  fgetpos(fich, &filepos);
66  fclose(fich);
67 
68 }
69 
70 void TGain::AsignaObjetos(TSensor **Sensor, TController **Controller) {
71 
72  if(FInObject == nmInController) {
73  FGainInput = new stGainInputController(Controller[FObjectID - 1]);
74  } else {
75  FGainInput = new stGainInputSensor(Sensor[FObjectID - 1]);
76  }
77 }
78 
79 void TGain::LeeResultadosMedControlador(const char *FileWAM, fpos_t &filepos) {
80 
81  int nvars = 0, var = 0;
82 
83  FILE *fich = fopen(FileWAM, "r");
84  fsetpos(fich, &filepos);
85 
86  fscanf(fich, "%d ", &nvars);
87  for(int i = 0; i < nvars; i++) {
88  fscanf(fich, "%d ", &var);
89  switch(var) {
90  case 0:
91  FResMediosCtrl.Output = true;
92  break;
93 
94  default:
95  std::cout << "Resultados medios en Controlador " << fID << " no implementados " << std::endl;
96  }
97  }
98 
99  fgetpos(fich, &filepos);
100  fclose(fich);
101 
102 }
103 
104 void TGain::LeeResultadosInsControlador(const char *FileWAM, fpos_t &filepos) {
105 
106  int nvars = 0, var = 0;
107 
108  FILE *fich = fopen(FileWAM, "r");
109  fsetpos(fich, &filepos);
110 
111  fscanf(fich, "%d ", &nvars);
112  for(int i = 0; i < nvars; i++) {
113  fscanf(fich, "%d ", &var);
114  switch(var) {
115  case 0:
116  FResInstantCtrl.Output = true;
117  break;
118  default:
119  std::cout << "Resultados instantaneos en Controlador " << fID << " no implementados " << std::endl;
120  }
121  }
122 
123  fgetpos(fich, &filepos);
124  fclose(fich);
125 
126 }
127 
128 void TGain::CabeceraResultadosMedControlador(stringstream& medoutput) {
129 
130  std::string Label;
131 
132  if(FResMediosCtrl.Output) {
133  Label = "\t" + PutLabel(705) + std::to_string(fID) + PutLabel(901);
134  medoutput << Label.c_str();
135  }
136 
137 }
138 
139 void TGain::CabeceraResultadosInsControlador(stringstream& insoutput) {
140 
141  std::string Label;
142 
143  if(FResInstantCtrl.Output) {
144  Label = "\t" + PutLabel(705) + std::to_string(fID) + PutLabel(901);
145  insoutput << Label.c_str();
146  }
147 
148 }
149 
150 void TGain::ImprimeResultadosMedControlador(stringstream& medoutput) {
151 
152  std::string Label;
153 
154  if(FResMediosCtrl.Output) {
155  medoutput << "\t" << FResMediosCtrl.OutputMED;
156  }
157 
158 }
159 
160 void TGain::ImprimeResultadosInsControlador(stringstream& insoutput) {
161 
162  std::string Label;
163 
164  if(FResInstantCtrl.Output) {
165  insoutput << "\t" << FResInstantCtrl.OutputINS;
166  }
167 
168 }
169 
171 
172  FResMediosCtrl.OutputSUM = 0.;
173 
174 }
175 
177 
178  if(FResMediosCtrl.Output) {
179  FResMediosCtrl.OutputMED = FResMediosCtrl.OutputSUM / FResMediosCtrl.TiempoSUM;
180  FResMediosCtrl.OutputSUM = 0.;
181  }
182 
183  FResMediosCtrl.TiempoSUM = 0;
184 
185 }
186 
188 
189  /* Lo que se hace en esta funcion se realiza dentro del calculo del eje, para asi poder
190  llevar a cabo la salida de resultados medios por pantalla. */
191  double Delta = Actual - FResMediosCtrl.Tiempo0;
192 
193  if(FResMediosCtrl.Output) {
194  FResMediosCtrl.OutputSUM += fOutput * Delta;
195  }
196  FResMediosCtrl.TiempoSUM += Delta;
197  FResMediosCtrl.Tiempo0 = Actual;
198 
199 }
200 
202 
203  if(FResInstantCtrl.Output)
204  FResInstantCtrl.OutputINS = fOutput;
205 
206 }
TGain::ImprimeResultadosInsControlador
void ImprimeResultadosInsControlador(stringstream &insoutput)
Definition: TGain.cpp:160
stGainInputSensor
Definition: TController.h:129
TController
Definition: TController.h:37
TGain::ImprimeResultadosMedControlador
void ImprimeResultadosMedControlador(stringstream &medoutput)
Definition: TGain.cpp:150
TGain::AcumulaResultadosMediosController
void AcumulaResultadosMediosController(double Actual)
Definition: TGain.cpp:187
TGain::CabeceraResultadosMedControlador
void CabeceraResultadosMedControlador(stringstream &medoutput)
Definition: TGain.cpp:128
TGain::ResultadosInstantController
void ResultadosInstantController()
Definition: TGain.cpp:201
TController::FResMediosCtrl
stResMediosCtrl FResMediosCtrl
Struct with the average results of the controllers.
Definition: TController.h:49
TGain::CabeceraResultadosInsControlador
void CabeceraResultadosInsControlador(stringstream &insoutput)
Definition: TGain.cpp:139
TGain::LeeResultadosMedControlador
void LeeResultadosMedControlador(const char *FileWAM, fpos_t &filepos)
Definition: TGain.cpp:79
TGain::Output
double Output(double Time)
Definition: TGain.cpp:44
PutLabel
std::string PutLabel(int idx)
Returns an integer.
Definition: labels.cpp:475
TGain::IniciaMedias
void IniciaMedias()
Definition: TGain.cpp:170
TGain::ResultadosMediosController
void ResultadosMediosController()
Definition: TGain.cpp:176
TController::FResInstantCtrl
stResInstantCtrl FResInstantCtrl
Struct with the average results of the controllers.
Definition: TController.h:50
TSensor
Definition: TSensor.h:42
stGainInputController
Definition: TController.h:144
TGain::LeeController
void LeeController(const char *FileWAM, fpos_t &filepos)
Definition: TGain.cpp:50
TGain::LeeResultadosInsControlador
void LeeResultadosInsControlador(const char *FileWAM, fpos_t &filepos)
Definition: TGain.cpp:104
TGain::AsignaObjetos
void AsignaObjetos(TSensor **Sensor, TController **Controller)
Definition: TGain.cpp:70