1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 09/12/2000
6 Purpose: This module models a rocket engine
8 ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.org) --------------
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
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
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.
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.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
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
34 --------------------------------------------------------------------------------
35 09/12/2000 JSB Created
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 static const char *IdSrc = "$Id$";
48 static const char *IdHdr = ID_ROCKET;
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 FGRocket::FGRocket(FGFDMExec* exec, Element *el, int engine_number)
55 : FGEngine(exec, el, engine_number)
57 Element* thrust_table_element = 0;
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");
83 thrust_table_element = el->FindElement("thrust_table");
84 if (thrust_table_element) {
85 ThrustTable = new FGTable(PropertyManager, thrust_table_element);
94 kFactor = (2.0*SHR*SHR/(SHR-1.0))*pow(2.0/(SHR+1), (SHR+1)/(SHR-1));
97 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 FGRocket::~FGRocket(void)
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 double FGRocket::Calculate(void)
110 if (!Flameout && !Starved) ConsumeFuel();
112 Throttle = FCS->GetThrottlePos(EngineNumber);
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.
119 if (ThrustTable != 0L) {
120 if (Throttle == 1 || BurnTime > 0.0) {
121 BurnTime += State->Getdt();
123 Throttle = ThrustTable->GetValue(BurnTime);
126 if (Throttle < MinThrottle || Starved) {
127 PctPower = Thrust = 0.0; // desired thrust
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)));
142 return Thruster->Calculate(Cf*maxPC*PctPower*propEff);
145 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 string FGRocket::GetEngineLabels(string delimeter)
149 std::ostringstream buf;
151 buf << Name << " Chamber Pressure (engine " << EngineNumber << " in psf)" << delimeter
152 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 string FGRocket::GetEngineValues(string delimeter)
161 std::ostringstream buf;
163 buf << PC << delimeter << Thruster->GetThrusterValues(EngineNumber, delimeter);
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
176 // 1: This value explicity requests the normal JSBSim
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
187 void FGRocket::Debug(int from)
189 if (debug_lvl <= 0) return;
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;
204 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
205 if (from == 0) cout << "Instantiated: FGRocket" << endl;
206 if (from == 1) cout << "Destroyed: FGRocket" << endl;
208 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
210 if (debug_lvl & 8 ) { // Runtime state variables
212 if (debug_lvl & 16) { // Sanity checking
214 if (debug_lvl & 64) {
215 if (from == 0) { // Constructor
216 cout << IdSrc << endl;
217 cout << IdHdr << endl;