1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19 You should have received a copy of the GNU Lesser General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU Lesser General Public License can also be found on
24 the world wide web at http://www.gnu.org.
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
29 Based on Flightgear code, which is based on LaRCSim. This class simulates
33 --------------------------------------------------------------------------------
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #include "FGJSBBase.h"
48 #include "math/FGColumnVector3.h"
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 #define ID_TANK "$Id: FGTank.h,v 1.24 2011/08/03 03:21:06 jberndt Exp $"
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 class FGPropertyManager;
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
71 /** Models a fuel tank.
73 <h3>Fuel Temperature:</h3>
75 Fuel temperature is calculated using the following assumptions:
77 Fuel temperature will only be calculated for tanks which have an initial fuel
78 temperature specified in the configuration file.
80 The surface area of the tank is estimated from the capacity in pounds. It
81 is assumed that the tank is a wing tank with dimensions h by 4h by 10h. The
82 volume of the tank is then 40(h)(h)(h). The area of the upper or lower
83 surface is then 40(h)(h). The volume is also equal to the capacity divided
84 by 49.368 lbs/cu-ft, for jet fuel. The surface area of one side can then be
85 derived from the tank's capacity.
87 The heat capacity of jet fuel is assumed to be 900 Joules/lbm/K, and the
88 heat transfer factor of the tank is 1.115 Watts/sq-ft/K.
92 Fuel dumping is handled by the FGPropulsion class. A standpipe can be defined
93 here for each tank which sets the level of contents (in pounds) which is not dumpable.
94 Default standpipe level is zero, making all contents dumpable.
96 <h3>Fuel Transfer:</h3>
98 Fuel transfer is handled by the FGPropulsion class, however the contents of tanks
99 may be manipulated directly using the SetContents() function here, or via the property
100 tree at <tt>propulsion/tank[i]/contents-lbs</tt>, where i is the tank number (Tanks
101 are automatically numbered, starting at zero, in the order in which they are read in
102 the aircraft configuration file). The latter method allows one to use a system of FCS
103 components to control tank contents.
105 There is also a property <tt>propulsion/tank[i]/external-flow-rate-pps</tt>. Setting
106 this property to a positive value causes the tank to fill at the rate specified.
107 Setting a negative number causes the tank to drain. The value is the rate in pounds
108 of fuel per second. The tank will not fill past 100% full and will not drain below 0%.
109 Fuel may be transfered between two tanks by setting the source tank's external flow rate
110 to a negative value and the destination's external flow rate to the same positive value.
111 Care must be taken to stop fuel flow before the source tank becomes empty to prevent
112 phantom fuel being created.
114 <h3>Configuration File Format:</h3>
117 <tank type="{FUEL | OXIDIZER}">
118 <grain_config type="{CYLINDRICAL | ENDBURNING}">
119 <length unit="{IN | FT | M}"> {number} </radius>
121 <location unit="{FT | M | IN}">
126 <drain_location unit="{FT | M | IN}">
131 <radius unit="{IN | FT | M}"> {number} </radius>
132 <capacity unit="{LBS | KG}"> {number} </capacity>
133 <contents unit="{LBS | KG}"> {number} </contents>
134 <temperature> {number} </temperature> <!-- must be degrees fahrenheit -->
135 <standpipe unit="{LBS | KG"}> {number} </standpipe>
136 <priority> {integer} </priority>
137 <density unit="{KG/L | LBS/GAL}"> {number} </density>
138 <type> {string} </type> <!-- will override previous density setting -->
142 <h3>Definition of the tank configuration file parameters:</h3>
144 - \b type - One of FUEL or OXIDIZER. This is required.
145 - \b radius - Equivalent radius of tank for modeling slosh, defaults to inches.
146 - \b grain_config type - One of CYLINDRICAL or ENDBURNING.
147 - \b length - length of tank for modeling solid fuel propellant grain, defaults to inches.
148 - \b capacity - Capacity, defaults to pounds.
149 - \b contents - Initial contents, defaults to pounds.
150 - \b temperature - Initial temperature, defaults to degrees Fahrenheit.
151 - \b standpipe - Minimum contents to which tank can dump, defaults to pounds.
152 - \b priority - Establishes feed sequence of tank. "1" is the highest priority.
153 - \b density - Density of liquid tank contents.
154 - \b type - Named fuel type. One of AVGAS, JET-A, JET-A1, JET-B, JP-1, JP-2, JP-3,
155 - \b JP-4, JP-5, JP-6, JP-7, JP-8, JP-8+100, RP-1, T-1, ETHANOL, HYDRAZINE,
156 - \b F-34, F-35, F-40, F-44, AVTAG, AVCAT
159 - \b x - Location of tank on aircraft's x-axis, defaults to inches.
160 - \b y - Location of tank on aircraft's y-axis, defaults to inches.
161 - \b z - Location of tank on aircraft's z-axis, defaults to inches.
164 - \b x - Location of tank drain on aircraft's x-axis, defaults to inches.
165 - \b y - Location of tank drain on aircraft's y-axis, defaults to inches.
166 - \b z - Location of tank drain on aircraft's z-axis, defaults to inches.
168 <h3>Default values of the tank configuration file parameters:</h3>
170 - \b type - ttUNKNOWN (causes a load error in the propulsion configuration)
171 - \b location, \b drain_location - both optional, but a warning message will
172 be printed to the console if the location is not given
173 - \b x - 0.0 (both full and drained CG locations)
174 - \b y - 0.0 (both full and drained CG locations)
175 - \b z - 0.0 (both full and drained CG locations)
177 - \b capacity - 0.00001 (tank capacity must not be zero)
179 - \b temperature - -9999.0 (flag which indicates no temperature is set)
180 - \b standpipe - 0.0 (all contents may be dumped)
181 - \b priority - 1 (highest feed sequence priority)
184 @author Jon Berndt, Dave Culp
185 @see Akbar, Raza et al. "A Simple Analysis of Fuel Addition to the CWT of
186 747", California Institute of Technology, 1998,
187 http://www.galcit.caltech.edu/EDL/projects/JetA/reports/lumped.pdf
190 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
194 class FGTank : public FGJSBBase
198 The constructor reads in the defining parameters from a configuration file.
199 @param exec a pointer to the base FGFDMExec instance.
200 @param el a pointer to the Tank element.
201 @param tank_number the tank number (zero based).
203 FGTank(FGFDMExec* exec, Element* el, int tank_number);
207 enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER};
208 enum GrainType {gtUNKNOWN, gtCYLINDRICAL, gtENDBURNING};
210 /** Removes fuel from the tank.
211 This function removes fuel from a tank. If the tank empties, it is
213 @param used the amount of fuel used in lbs.
214 @return the remaining contents of the tank in lbs.
216 double Drain(double used);
218 /** Performs local, tanks-specific calculations, such as fuel temperature.
219 This function calculates the temperature of the fuel in the tank.
220 @param dt the time step for this model.
221 @param TempC the Total Air Temperature in degrees Celsius.
222 @return the current temperature in degrees Celsius.
224 double Calculate(double dt, double TempC);
226 /** Retrieves the type of tank: Fuel or Oxidizer.
227 @return the tank type, 0 for undefined, 1 for fuel, and 2 for oxidizer.
229 int GetType(void) {return Type;}
231 /** Resets the tank parameters to the initial conditions */
232 void ResetToIC(void);
234 /** If the tank is set to supply fuel, this function returns true.
235 @return true if this tank is set to a non-zero priority.*/
236 bool GetSelected(void) {return Selected;}
238 /** Gets the tank fill level.
239 @return the fill level in percent, from 0 to 100.*/
240 double GetPctFull(void) {return PctFull;}
242 /** Gets the capacity of the tank.
243 @return the capacity of the tank in pounds. */
244 double GetCapacity(void) {return Capacity;}
246 /** Gets the capacity of the tank.
247 @return the capacity of the tank in gallons. */
248 double GetCapacityGallons(void) {return Capacity/Density;}
250 /** Gets the contents of the tank.
251 @return the contents of the tank in pounds. */
252 double GetContents(void) const {return Contents;}
254 /** Gets the contents of the tank.
255 @return the contents of the tank in gallons. */
256 double GetContentsGallons(void) const {return Contents/Density;}
258 /** Gets the temperature of the fuel.
259 The temperature of the fuel is calculated if an initial tempearture is
260 given in the configuration file.
261 @return the temperature of the fuel in degrees C IF an initial temperature
262 is given, otherwise 0.0 C is returned. */
263 double GetTemperature_degC(void) {return Temperature;}
265 /** Gets the temperature of the fuel.
266 The temperature of the fuel is calculated if an initial tempearture is
267 given in the configuration file.
268 @return the temperature of the fuel in degrees F IF an initial temperature
269 is given, otherwise 32 degrees F is returned. */
270 double GetTemperature(void) {return CelsiusToFahrenheit(Temperature);}
272 /** Returns the density of a named fuel type.
273 @return the density, in lbs/gal, or 6.6 if name cannot be resolved. */
274 double ProcessFuelName(std::string const& name);
276 double GetIxx(void) {return Ixx;}
277 double GetIyy(void) {return Iyy;}
278 double GetIzz(void) {return Izz;}
280 double GetStandpipe(void) {return Standpipe;}
282 int GetPriority(void) const {return Priority;}
283 void SetPriority(int p) { Priority = p; Selected = p>0 ? true:false; }
285 double GetDensity(void) const {return Density;}
286 void SetDensity(double d) { Density = d; }
288 double GetExternalFlow(void) const {return ExternalFlow;}
289 void SetExternalFlow(double f) { ExternalFlow = f; }
291 const FGColumnVector3 GetXYZ(void);
292 const double GetXYZ(int idx);
294 const GrainType GetGrainType(void) {return grainType;}
296 double Fill(double amount);
297 void SetContents(double amount);
298 void SetContentsGallons(double gallons);
299 void SetTemperature(double temp) { Temperature = temp; }
300 void SetStandpipe(double amount) { Standpipe = amount; }
301 void SetSelected(bool sel) { sel==true ? SetPriority(1):SetPriority(0); }
308 std::string strGType;
309 FGColumnVector3 vXYZ;
310 FGColumnVector3 vXYZ_drain;
321 double Contents, InitialContents;
324 double Temperature, InitialTemperature;
325 double Standpipe, InitialStandpipe;
328 int Priority, InitialPriority;
330 FGPropertyManager* PropertyManager;
332 void CalculateInertias(void);
333 void Debug(int from);
336 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%