OpenWAM
TMariposa.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 "TMariposa.h"
32 
33 //---------------------------------------------------------------------------
34 
35 TMariposa::TMariposa() :
36  TTipoValvula(nmMariposa) {
37  FLevControlled = false;
38  fun_CDin = NULL;
39  fun_CDout = NULL;
40 }
41 
42 TMariposa::~TMariposa() {
43 }
44 
45 TMariposa::TMariposa(TMariposa *Origen, int valv) :
46  TTipoValvula(nmMariposa) {
47  FNumLev = Origen->FNumLev;
48 
49  FDiametroRef = Origen->FDiametroRef;
50 
51  FDiamRef = FDiametroRef;
52 
53  FValvula = valv;
54 
55  FLevantamiento.resize(Origen->FLevantamiento.size());
56  FDatosCDEntrada.resize(Origen->FDatosCDEntrada.size());
57  FDatosCDSalida.resize(Origen->FDatosCDSalida.size());
58 
59  for(int i = 0; i < FNumLev; i++) {
60  FLevantamiento[i] = Origen->FLevantamiento[i];
61  FDatosCDEntrada[i] = Origen->FDatosCDEntrada[i];
62  FDatosCDSalida[i] = Origen->FDatosCDSalida[i];
63  }
64  fun_CDin = new Hermite_interp(FLevantamiento, FDatosCDEntrada);
65  fun_CDout = new Hermite_interp(FLevantamiento, FDatosCDSalida);
66 
67  FLevActual = Origen->FLevActual;
68  FLevControlled = Origen->FLevControlled;
69  FControllerID = Origen->FControllerID;
70  FLevControlled = Origen->FLevControlled;
71 }
72 
73 void TMariposa::LeeDatosIniciales(const char *FileWAM, fpos_t &filepos, int norden, bool HayMotor,
74  TBloqueMotor *Engine) {
75  int ctrl = 0, prm = 0;
76 
77  FILE *fich = fopen(FileWAM, "r");
78  fsetpos(fich, &filepos);
79 
80  FNumeroOrden = norden;
81 
82  fscanf(fich, "%d %lf ", &FNumLev, &FDiametroRef);
83 
84  FLevantamiento.resize(FNumLev);
85  FDatosCDEntrada.resize(FNumLev);
86  FDatosCDSalida.resize(FNumLev);
87 
88  for(int i = 0; i < FNumLev; i++) {
89  fscanf(fich, " %lf %lf %lf", &FLevantamiento[i], &FDatosCDEntrada[i], &FDatosCDSalida[i]);
90  }
91 
92  fscanf(fich, " %lf", &FLevActual);
93 
94  fscanf(fich, " %d", &ctrl);
95  if(ctrl != 0) {
96  FLevControlled = true;
97  fscanf(fich, " %d %d", &prm, &FControllerID);
98  }
99 
100  fgetpos(fich, &filepos);
101  fclose(fich);
102 }
103 
104 void TMariposa::AsignaLevController(TController **Controller) {
105  if(FLevControlled)
106  FController = Controller[FControllerID - 1];
107 }
108 
109 void TMariposa::CalculaCD(double Time) {
110  if(FLevControlled)
111  FLevActual = FController->Output(Time);
112 
113  FCDTubVol = fun_CDin->interp(FLevActual) * FSectionRatio;
114  FCDVolTub = fun_CDout->interp(FLevActual) * FSectionRatio;
115 }
116 
117 void TMariposa::GetCDin(double Time) {
118 
119  if(FLevControlled)
120  FLevActual = FController->Output(Time);
121 
122  FCDTubVol = fun_CDin->interp(FLevActual) * FSectionRatio;
123 }
124 
125 void TMariposa::GetCDout(double Time) {
126 
127  if(FLevControlled)
128  FLevActual = FController->Output(Time);
129 
130  FCDVolTub = fun_CDout->interp(FLevActual) * FSectionRatio;
131 }
132 
133 #pragma package(smart_init)
TController
Definition: TController.h:37
TTipoValvula
Definition: TTipoValvula.h:53
Hermite_interp
Definition: Math_wam.h:311
TMariposa
Definition: TMariposa.h:43
TBloqueMotor
Definition: TBloqueMotor.h:43
TController::Output
virtual double Output(double Time)=0