]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/propulsion/FGTank.h
Merge branch 'next' of git://gitorious.org/fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / propulsion / FGTank.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGTank.h
4  Author:       Jon S. Berndt
5  Date started: 01/21/99
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
8
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
12  version.
13
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
17  details.
18
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.
22
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.
25
26 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
28
29 Based on Flightgear code, which is based on LaRCSim. This class simulates
30 a generic Tank.
31
32 HISTORY
33 --------------------------------------------------------------------------------
34 01/21/99   JSB   Created
35
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 SENTRY
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #ifndef FGTank_H
41 #define FGTank_H
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 INCLUDES
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #include "FGJSBBase.h"
48 #include "math/FGColumnVector3.h"
49 #include <string>
50
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 DEFINITIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55 #define ID_TANK "$Id: FGTank.h,v 1.23 2011/06/13 15:23:09 jentron Exp $"
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 FORWARD DECLARATIONS
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
61 namespace JSBSim {
62
63 class Element;
64 class FGPropertyManager;
65 class FGFDMExec;
66
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 CLASS DOCUMENTATION
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70
71 /** Models a fuel tank.
72
73 <h3>Fuel Temperature:</h3>
74  
75     Fuel temperature is calculated using the following assumptions:
76
77     Fuel temperature will only be calculated for tanks which have an initial fuel
78     temperature specified in the configuration file.
79
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.  
86
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.
89
90 <h3>Fuel Dump:</h3>
91
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.
95
96 <h3>Fuel Transfer:</h3>
97
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.
104
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.
113
114 <h3>Configuration File Format:</h3>
115
116 @code
117 <tank type="{FUEL | OXIDIZER}">
118   <grain_config type="{CYLINDRICAL | ENDBURNING}">
119     <length unit="{IN | FT | M}"> {number} </radius>
120   </grain_config>
121   <location unit="{FT | M | IN}">
122     <x> {number} </x>
123     <y> {number} </y>
124     <z> {number} </z>
125   </location>
126   <drain_location unit="{FT | M | IN}">
127     <x> {number} </x>
128     <y> {number} </y>
129     <z> {number} </z>
130   </drain_location>
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 -->
139 </tank>
140 @endcode
141
142 <h3>Definition of the tank configuration file parameters:</h3>
143
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
157
158 location:
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.
162
163 drain_location:
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.
167
168 <h3>Default values of the tank configuration file parameters:</h3>
169
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)
176 - \b radius - 0.0
177 - \b capacity - 0.00001 (tank capacity must not be zero)
178 - \b contents - 0.0
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)
182 - \b density - 6.6
183
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
188 */
189
190 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 CLASS DECLARATION
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
193
194 class FGTank : public FGJSBBase
195 {
196 public:
197   /** Constructor.
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).
202   */
203   FGTank(FGFDMExec* exec, Element* el, int tank_number);
204   /// Destructor
205   ~FGTank();
206
207   enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER};
208   enum GrainType {gtUNKNOWN, gtCYLINDRICAL, gtENDBURNING};
209
210   /** Removes fuel from the tank.
211       This function removes fuel from a tank. If the tank empties, it is
212       deselected.
213       @param used the amount of fuel used in lbs.
214       @return the remaining contents of the tank in lbs.
215   */
216   double Drain(double used);
217
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       @return the current temperature in degrees Celsius.
222   */
223   double Calculate(double dt);
224
225   /** Retrieves the type of tank: Fuel or Oxidizer.
226       @return the tank type, 0 for undefined, 1 for fuel, and 2 for oxidizer.
227   */
228   int GetType(void) {return Type;}
229
230   /** Resets the tank parameters to the initial conditions */
231   void ResetToIC(void);
232
233   /** If the tank is set to supply fuel, this function returns true.
234       @return true if this tank is set to a non-zero priority.*/
235   bool GetSelected(void) {return Selected;}
236
237   /** Gets the tank fill level.
238       @return the fill level in percent, from 0 to 100.*/
239   double GetPctFull(void) {return PctFull;}
240
241   /** Gets the capacity of the tank.
242       @return the capacity of the tank in pounds. */
243   double GetCapacity(void) {return Capacity;}
244
245   /** Gets the capacity of the tank.
246       @return the capacity of the tank in gallons. */
247   double GetCapacityGallons(void) {return Capacity/Density;}
248
249   /** Gets the contents of the tank.
250       @return the contents of the tank in pounds. */
251   double GetContents(void) const {return Contents;}
252
253   /** Gets the contents of the tank.
254       @return the contents of the tank in gallons. */
255   double GetContentsGallons(void) const {return Contents/Density;}
256
257   /** Gets the temperature of the fuel.
258       The temperature of the fuel is calculated if an initial tempearture is
259       given in the configuration file. 
260       @return the temperature of the fuel in degrees C IF an initial temperature
261       is given, otherwise 0.0 C is returned. */
262   double GetTemperature_degC(void) {return Temperature;}
263
264   /** Gets the temperature of the fuel.
265       The temperature of the fuel is calculated if an initial tempearture is
266       given in the configuration file. 
267       @return the temperature of the fuel in degrees F IF an initial temperature
268       is given, otherwise 32 degrees F is returned. */
269   double GetTemperature(void) {return CelsiusToFahrenheit(Temperature);}
270
271   /** Returns the density of a named fuel type.
272       @return the density, in lbs/gal, or 6.6 if name cannot be resolved. */
273   double ProcessFuelName(std::string const& name); 
274
275   double GetIxx(void) {return Ixx;}
276   double GetIyy(void) {return Iyy;}
277   double GetIzz(void) {return Izz;}
278
279   double GetStandpipe(void) {return Standpipe;}
280
281   int  GetPriority(void) const {return Priority;}
282   void SetPriority(int p) { Priority = p; Selected = p>0 ? true:false; } 
283
284   double GetDensity(void) const {return Density;}
285   void   SetDensity(double d) { Density = d; }
286
287   double GetExternalFlow(void) const {return ExternalFlow;}
288   void   SetExternalFlow(double f) { ExternalFlow = f; }
289
290   const FGColumnVector3 GetXYZ(void);
291   const double GetXYZ(int idx);
292
293   const GrainType GetGrainType(void) {return grainType;}
294
295   double Fill(double amount);
296   void SetContents(double amount);
297   void SetContentsGallons(double gallons);
298   void SetTemperature(double temp) { Temperature = temp; }
299   void SetStandpipe(double amount) { Standpipe = amount; }
300   void SetSelected(bool sel) { sel==true ? SetPriority(1):SetPriority(0); }
301
302 private:
303   TankType Type;
304   GrainType grainType;
305   int TankNumber;
306   std::string type;
307   std::string strGType;
308   FGColumnVector3 vXYZ;
309   FGColumnVector3 vXYZ_drain;
310   double Capacity;
311   double Radius;
312   double InnerRadius;
313   double Length;
314   double Volume;
315   double Density;
316   double Ixx;
317   double Iyy;
318   double Izz;
319   double PctFull;
320   double Contents, InitialContents;
321   double Area;
322   double Temperature, InitialTemperature;
323   double Standpipe, InitialStandpipe;
324   double ExternalFlow;
325   bool  Selected;
326   int Priority, InitialPriority;
327   FGFDMExec* Exec;
328   FGPropertyManager* PropertyManager;
329   void CalculateInertias(void);
330   void Debug(int from);
331 };
332 }
333 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 #endif
335