]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/propulsion/FGRocket.cpp
Sync w. JSBSim CVS (merge from PRE_OSG_PLIB_20061029 branch)
[flightgear.git] / src / FDM / JSBSim / models / propulsion / FGRocket.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGRocket.cpp
4  Author:       Jon S. Berndt
5  Date started: 09/12/2000
6  Purpose:      This module models a rocket engine
7
8  ------------- Copyright (C) 2000  Jon S. Berndt (jsb@hal-pc.org) --------------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU Lesser General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
18  details.
19
20  You should have received a copy of the GNU Lesser General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU Lesser General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 This class descends from the FGEngine class and models a rocket engine based on
31 parameters given in the engine config file for this class
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 09/12/2000  JSB  Created
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <sstream>
42
43 #include "FGRocket.h"
44
45 namespace JSBSim {
46
47 static const char *IdSrc = "$Id$";
48 static const char *IdHdr = ID_ROCKET;
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 CLASS IMPLEMENTATION
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 FGRocket::FGRocket(FGFDMExec* exec, Element *el, int engine_number)
55   : FGEngine(exec, el, engine_number)
56 {
57   Element* thrust_table_element = 0;
58   ThrustTable = 0L;
59   BurnTime = 0.0;
60
61   // Defaults
62    Variance = 0.0;
63    MinThrottle = 0.0;
64    MaxThrottle = 1.0;
65
66   if (el->FindElement("shr"))
67     SHR = el->FindElementValueAsNumber("shr");
68   if (el->FindElement("max_pc"))
69     maxPC = el->FindElementValueAsNumberConvertTo("max_pc", "PSF");
70   if (el->FindElement("prop_eff"))
71     propEff = el->FindElementValueAsNumber("prop_eff");
72   if (el->FindElement("maxthrottle"))
73     MaxThrottle = el->FindElementValueAsNumber("maxthrottle");
74   if (el->FindElement("minthrottle"))
75     MinThrottle = el->FindElementValueAsNumber("minthrottle");
76   if (el->FindElement("slfuelflowmax"))
77     SLFuelFlowMax = el->FindElementValueAsNumberConvertTo("slfuelflowmax", "LBS/SEC");
78   if (el->FindElement("sloxiflowmax"))
79     SLOxiFlowMax = el->FindElementValueAsNumberConvertTo("sloxiflowmax", "LBS/SEC");
80   if (el->FindElement("variance"))
81     Variance = el->FindElementValueAsNumber("variance");
82
83   thrust_table_element = el->FindElement("thrust_table");
84   if (thrust_table_element) {
85     ThrustTable = new FGTable(PropertyManager, thrust_table_element);
86   }
87
88   Debug(0);
89
90   Type = etRocket;
91   Flameout = false;
92
93   PC = 0.0;
94   kFactor = (2.0*SHR*SHR/(SHR-1.0))*pow(2.0/(SHR+1), (SHR+1)/(SHR-1));
95 }
96
97 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98
99 FGRocket::~FGRocket(void)
100 {
101   Debug(1);
102 }
103
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
106 double FGRocket::Calculate(void)
107 {
108   double Cf=0;
109
110   if (!Flameout && !Starved) ConsumeFuel();
111
112   Throttle = FCS->GetThrottlePos(EngineNumber);
113
114   // If there is a thrust table, it is a function of elapsed burn time. The engine
115   // is started when the throttle is advanced to 1.0. After that, it burns
116   // without regard to throttle setting. The table returns a value between zero
117   // and one, representing the percentage of maximum vacuum thrust being applied.
118
119   if (ThrustTable != 0L) {
120     if (Throttle == 1 || BurnTime > 0.0) {
121       BurnTime += State->Getdt();
122     }
123     Throttle = ThrustTable->GetValue(BurnTime);
124   }
125
126   if (Throttle < MinThrottle || Starved) {
127     PctPower = Thrust = 0.0; // desired thrust
128     Flameout = true;
129     PC = 0.0;
130   } else {
131     PctPower = Throttle / MaxThrottle;
132     //todo: remove Variance?
133     PC = maxPC*PctPower * (1.0 + Variance * ((double)rand()/(double)RAND_MAX - 0.5));
134     // The Cf (below) is CF from Eqn. 3-30, "Rocket Propulsion Elements", Fifth Edition,
135     // George P. Sutton. Note that the thruster function GetPowerRequired() might
136     // be better called GetResistance() or something; this function returns the
137     // nozzle exit pressure.
138     Cf = sqrt(kFactor*(1 - pow(Thruster->GetPowerRequired()/(PC), (SHR-1)/SHR)));
139     Flameout = false;
140   }
141
142   return Thruster->Calculate(Cf*maxPC*PctPower*propEff);
143 }
144
145 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146
147 string FGRocket::GetEngineLabels(string delimeter)
148 {
149   std::ostringstream buf;
150
151   buf << Name << " Chamber Pressure (engine " << EngineNumber << " in psf)" << delimeter
152       << Thruster->GetThrusterLabels(EngineNumber, delimeter);
153
154   return buf.str();
155 }
156
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158
159 string FGRocket::GetEngineValues(string delimeter)
160 {
161   std::ostringstream buf;
162
163   buf << PC << delimeter << Thruster->GetThrusterValues(EngineNumber, delimeter);
164
165   return buf.str();
166 }
167
168 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 //    The bitmasked value choices are as follows:
170 //    unset: In this case (the default) JSBSim would only print
171 //       out the normally expected messages, essentially echoing
172 //       the config files as they are read. If the environment
173 //       variable is not set, debug_lvl is set to 1 internally
174 //    0: This requests JSBSim not to output any messages
175 //       whatsoever.
176 //    1: This value explicity requests the normal JSBSim
177 //       startup messages
178 //    2: This value asks for a message to be printed out when
179 //       a class is instantiated
180 //    4: When this value is set, a message is displayed when a
181 //       FGModel object executes its Run() method
182 //    8: When this value is set, various runtime state variables
183 //       are printed out periodically
184 //    16: When set various parameters are sanity checked and
185 //       a message is printed out when they go out of bounds
186
187 void FGRocket::Debug(int from)
188 {
189   if (debug_lvl <= 0) return;
190
191   if (debug_lvl & 1) { // Standard console startup message output
192     if (from == 0) { // Constructor
193       cout << "      Engine Name: " << Name << endl;
194       cout << "      Specific Heat Ratio = " << SHR << endl;
195       cout << "      Maximum Chamber Pressure = " << maxPC << endl;
196       cout << "      Propulsive Efficiency = " << propEff << endl;
197       cout << "      MaxThrottle = " << MaxThrottle << endl;
198       cout << "      MinThrottle = " << MinThrottle << endl;
199       cout << "      FuelFlowMax = " << SLFuelFlowMax << endl;
200       cout << "      OxiFlowMax = " << SLOxiFlowMax << endl;
201       cout << "      Variance = " << Variance << endl;
202     }
203   }
204   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
205     if (from == 0) cout << "Instantiated: FGRocket" << endl;
206     if (from == 1) cout << "Destroyed:    FGRocket" << endl;
207   }
208   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
209   }
210   if (debug_lvl & 8 ) { // Runtime state variables
211   }
212   if (debug_lvl & 16) { // Sanity checking
213   }
214   if (debug_lvl & 64) {
215     if (from == 0) { // Constructor
216       cout << IdSrc << endl;
217       cout << IdHdr << endl;
218     }
219   }
220 }
221 }