1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 09/12/2000
6 Purpose: This module models a rocket engine
8 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include "FGThruster.h"
50 static const char *IdSrc = "$Id: FGRocket.cpp,v 1.26 2011/08/04 13:45:42 jberndt Exp $";
51 static const char *IdHdr = ID_ROCKET;
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 FGRocket::FGRocket(FGFDMExec* exec, Element *el, int engine_number, struct Inputs& input)
58 : FGEngine(exec, el, engine_number, input)
61 Element* thrust_table_element = 0;
64 previousFuelNeedPerTank = 0.0;
65 previousOxiNeedPerTank = 0.0;
66 PropellantFlowRate = 0.0;
67 TotalPropellantExpended = 0.0;
68 FuelFlowRate = FuelExpended = 0.0;
69 OxidizerFlowRate = OxidizerExpended = 0.0;
70 SLOxiFlowMax = SLFuelFlowMax = 0.0;
73 ThrustVariation = 0.0;
74 TotalIspVariation = 0.0;
81 if (el->FindElement("isp"))
82 Isp = el->FindElementValueAsNumber("isp");
83 if (el->FindElement("builduptime"))
84 BuildupTime = el->FindElementValueAsNumber("builduptime");
85 if (el->FindElement("maxthrottle"))
86 MaxThrottle = el->FindElementValueAsNumber("maxthrottle");
87 if (el->FindElement("minthrottle"))
88 MinThrottle = el->FindElementValueAsNumber("minthrottle");
89 if (el->FindElement("slfuelflowmax"))
90 SLFuelFlowMax = el->FindElementValueAsNumberConvertTo("slfuelflowmax", "LBS/SEC");
91 if (el->FindElement("sloxiflowmax"))
92 SLOxiFlowMax = el->FindElementValueAsNumberConvertTo("sloxiflowmax", "LBS/SEC");
94 // If there is a thrust table element, this is a solid propellant engine.
95 thrust_table_element = el->FindElement("thrust_table");
96 if (thrust_table_element) {
97 ThrustTable = new FGTable(PropertyManager, thrust_table_element);
98 Element* variation_element = el->FindElement("variation");
99 if (variation_element) {
100 if (variation_element->FindElement("thrust")) {
101 ThrustVariation = variation_element->FindElementValueAsNumber("thrust");
103 if (variation_element->FindElement("total_isp")) {
104 TotalIspVariation = variation_element->FindElementValueAsNumber("total_isp");
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 FGRocket::~FGRocket(void)
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 void FGRocket::Calculate(void)
126 if (FDMExec->IntegrationSuspended()) return;
130 PropellantFlowRate = (FuelExpended + OxidizerExpended)/in.TotalDeltaT;
131 TotalPropellantExpended += FuelExpended + OxidizerExpended;
133 // If there is a thrust table, it is a function of propellant burned. The
134 // engine is started when the throttle is advanced to 1.0. After that, it
135 // burns without regard to throttle setting.
137 if (ThrustTable != 0L) { // Thrust table given -> Solid fuel used
139 if ((in.ThrottlePos[EngineNumber] == 1 || BurnTime > 0.0 ) && !Starved) {
141 VacThrust = ThrustTable->GetValue(TotalPropellantExpended)
142 * (ThrustVariation + 1)
143 * (TotalIspVariation + 1);
144 if (BurnTime <= BuildupTime && BuildupTime > 0.0) {
145 VacThrust *= sin((BurnTime/BuildupTime)*M_PI/2.0);
146 // VacThrust *= (1-cos((BurnTime/BuildupTime)*M_PI))/2.0; // 1 - cos approach
148 BurnTime += in.TotalDeltaT; // Increment burn time
153 } else { // liquid fueled rocket assumed
155 if (in.ThrottlePos[EngineNumber] < MinThrottle || Starved) { // Combustion not supported
157 PctPower = 0.0; // desired thrust
161 } else { // Calculate thrust
163 // PctPower = Throttle / MaxThrottle; // Min and MaxThrottle range from 0.0 to 1.0, normally.
165 PctPower = in.ThrottlePos[EngineNumber];
167 VacThrust = Isp * PropellantFlowRate;
171 } // End thrust calculations
173 LoadThrusterInputs();
174 It += Thruster->Calculate(VacThrust) * in.TotalDeltaT;
179 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 // The FuelFlowRate can be affected by the TotalIspVariation value (settable
182 // in a config file or via properties). The TotalIspVariation parameter affects
183 // thrust, but the thrust determines fuel flow rate, so it must be adjusted
184 // for Total Isp Variation.
186 double FGRocket::CalcFuelNeed(void)
188 if (ThrustTable != 0L) { // Thrust table given - infers solid fuel
189 FuelFlowRate = VacThrust/Isp; // This calculates wdot (weight flow rate in lbs/sec)
190 FuelFlowRate /= (1 + TotalIspVariation);
192 FuelFlowRate = SLFuelFlowMax*PctPower;
195 FuelExpended = FuelFlowRate * in.TotalDeltaT; // For this time step ...
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 double FGRocket::CalcOxidizerNeed(void)
203 OxidizerFlowRate = SLOxiFlowMax * PctPower;
204 OxidizerExpended = OxidizerFlowRate * in.TotalDeltaT;
205 return OxidizerExpended;
208 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 string FGRocket::GetEngineLabels(const string& delimiter)
212 std::ostringstream buf;
214 buf << Name << " Total Impulse (engine " << EngineNumber << " in psf)" << delimiter
215 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
220 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 string FGRocket::GetEngineValues(const string& delimiter)
224 std::ostringstream buf;
226 buf << It << delimiter << Thruster->GetThrusterValues(EngineNumber, delimiter);
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 // This function should tie properties to rocket engine specific properties
233 // that are not bound in the base class (FGEngine) code.
235 void FGRocket::bindmodel()
237 string property_name, base_property_name;
238 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
240 property_name = base_property_name + "/total-impulse";
241 PropertyManager->Tie( property_name.c_str(), this, &FGRocket::GetTotalImpulse);
242 property_name = base_property_name + "/vacuum-thrust_lbs";
243 PropertyManager->Tie( property_name.c_str(), this, &FGRocket::GetVacThrust);
245 if (ThrustTable) { // Solid rocket motor
246 property_name = base_property_name + "/thrust-variation_pct";
247 PropertyManager->Tie( property_name.c_str(), this, &FGRocket::GetThrustVariation,
248 &FGRocket::SetThrustVariation);
249 property_name = base_property_name + "/total-isp-variation_pct";
250 PropertyManager->Tie( property_name.c_str(), this, &FGRocket::GetTotalIspVariation,
251 &FGRocket::SetTotalIspVariation);
252 } else { // Liquid rocket motor
253 property_name = base_property_name + "/oxi-flow-rate-pps";
254 PropertyManager->Tie( property_name.c_str(), this, &FGRocket::GetOxiFlowRate);
258 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 // The bitmasked value choices are as follows:
260 // unset: In this case (the default) JSBSim would only print
261 // out the normally expected messages, essentially echoing
262 // the config files as they are read. If the environment
263 // variable is not set, debug_lvl is set to 1 internally
264 // 0: This requests JSBSim not to output any messages
266 // 1: This value explicity requests the normal JSBSim
268 // 2: This value asks for a message to be printed out when
269 // a class is instantiated
270 // 4: When this value is set, a message is displayed when a
271 // FGModel object executes its Run() method
272 // 8: When this value is set, various runtime state variables
273 // are printed out periodically
274 // 16: When set various parameters are sanity checked and
275 // a message is printed out when they go out of bounds
277 void FGRocket::Debug(int from)
279 if (debug_lvl <= 0) return;
281 if (debug_lvl & 1) { // Standard console startup message output
282 if (from == 0) { // Constructor
283 cout << " Engine Name: " << Name << endl;
284 cout << " Vacuum Isp = " << Isp << endl;
285 cout << " Maximum Throttle = " << MaxThrottle << endl;
286 cout << " Minimum Throttle = " << MinThrottle << endl;
287 cout << " Fuel Flow (max) = " << SLFuelFlowMax << endl;
288 cout << " Oxidizer Flow (max) = " << SLOxiFlowMax << endl;
289 if (SLFuelFlowMax > 0)
290 cout << " Mixture ratio = " << SLOxiFlowMax/SLFuelFlowMax << endl;
293 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
294 if (from == 0) cout << "Instantiated: FGRocket" << endl;
295 if (from == 1) cout << "Destroyed: FGRocket" << endl;
297 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
299 if (debug_lvl & 8 ) { // Runtime state variables
301 if (debug_lvl & 16) { // Sanity checking
303 if (debug_lvl & 64) {
304 if (from == 0) { // Constructor
305 cout << IdSrc << endl;
306 cout << IdHdr << endl;