| 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 ([email protected]) ------------- |
| 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 |
| 11 | Software Foundation; either version 2 of the License, or (at your option) any |
| 12 | later 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 |
| 20 | with this program; if not, write to the Free Software Foundation, Inc., 59 |
| 21 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | |
| 23 | Further information about the GNU Lesser General Public License can also be |
| 24 | found on 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 | |
| 50 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 51 | FORWARD DECLARATIONS |
| 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 53 | |
| 54 | namespace JSBSim { |
| 55 | |
| 56 | class Element; |
| 57 | class FGPropertyManager; |
| 58 | class FGFDMExec; |
| 59 | class FGFunction; |
| 60 | |
| 61 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 62 | CLASS DOCUMENTATION |
| 63 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 64 | |
| 65 | /** Models a fuel tank. |
| 66 | |
| 67 | <h3>Fuel Temperature:</h3> |
| 68 | |
| 69 | Fuel temperature is calculated using the following assumptions: |
| 70 | |
| 71 | Fuel temperature will only be calculated for tanks which have an initial |
| 72 | fuel temperature specified in the configuration file. |
| 73 | |
| 74 | The surface area of the tank is estimated from the capacity in pounds. It |
| 75 | is assumed that the tank is a wing tank with dimensions h by 4h by 10h. The |
| 76 | volume of the tank is then 40(h)(h)(h). The area of the upper or lower |
| 77 | surface is then 40(h)(h). The volume is also equal to the capacity divided |
| 78 | by 49.368 lbs/cu-ft, for jet fuel. The surface area of one side can then be |
| 79 | derived from the tank's capacity. |
| 80 | |
| 81 | The heat capacity of jet fuel is assumed to be 900 Joules/lbm/K, and the |
| 82 | heat transfer factor of the tank is 1.115 Watts/sq-ft/K. |
| 83 | |
| 84 | <h3>Fuel Dump:</h3> |
| 85 | |
| 86 | Fuel dumping is handled by the FGPropulsion class. A standpipe can be |
| 87 | defined here for each tank which sets the level of contents (in pounds) |
| 88 | which is not dumpable. Default standpipe level is zero, making all contents |
| 89 | dumpable. |
| 90 | |
| 91 | <h3>Fuel Transfer:</h3> |
| 92 | |
| 93 | Fuel transfer is handled by the FGPropulsion class, however the contents of |
| 94 | tanks may be manipulated directly using the SetContents() function here, or |
| 95 | via the property tree at <tt>propulsion/tank[i]/contents-lbs</tt>, where i |
| 96 | is the tank number (Tanks are automatically numbered, starting at zero, in |
| 97 | the order in which they are read in the aircraft configuration file). The |
| 98 | latter method allows one to use a system of FCS components to control tank |
| 99 | contents. |
| 100 | |
| 101 | There is also a property |
| 102 | <tt>propulsion/tank[i]/external-flow-rate-pps</tt>. Setting this property to |
| 103 | a positive value causes the tank to fill at the rate specified. Setting a |
| 104 | negative number causes the tank to drain. The value is the rate in pounds of |
| 105 | fuel per second. The tank will not fill past 100% full and will not drain |
| 106 | below 0%. Fuel may be transfered between two tanks by setting the source |
| 107 | tank's external flow rate to a negative value and the destination's external |
| 108 | flow rate to the same positive value. Care must be taken to stop fuel flow |
| 109 | before the source tank becomes empty to prevent phantom fuel being created. |
| 110 | |
| 111 | <h3>Configuration File Format:</h3> |
| 112 | |
| 113 | @code |
| 114 | <tank type="{FUEL | OXIDIZER}"> |
| 115 | <grain_config type="{CYLINDRICAL | ENDBURNING | FUNCTION}"> |
| 116 | <length unit="{IN | FT | M}"> {number} </length> |
| 117 | <bore_diameter unit="{IN | FT | M}"> {number} </bore_diameter> |
| 118 | [<ixx unit="{IN | FT | M}"> {function} </ixx> |
| 119 | <iyy unit="{IN | FT | M}"> {function} </iyy> |
| 120 | <izz unit="{IN | FT | M}"> {function} </izz>] |
| 121 | </grain_config> |
| 122 | <location unit="{FT | M | IN}"> |
| 123 | <x> {number} </x> |
| 124 | <y> {number} </y> |
| 125 | <z> {number} </z> |
| 126 | </location> |
| 127 | <drain_location unit="{FT | M | IN}"> |
| 128 | <x> {number} </x> |
| 129 | <y> {number} </y> |
| 130 | <z> {number} </z> |
| 131 | </drain_location> |
| 132 | <radius unit="{IN | FT | M}"> {number} </radius> |
| 133 | <capacity unit="{LBS | KG}"> {number} </capacity> |
| 134 | <inertia_factor> {number:0-1} </inertia_factor> |
| 135 | <contents unit="{LBS | KG}"> {number} </contents> |
| 136 | <temperature> {number} </temperature> <!-- must be degrees fahrenheit --> |
| 137 | <standpipe unit="{LBS | KG"}> {number} </standpipe> |
| 138 | <unusable unit="{GAL | LTR | M3 | IN3 | FT3 | CC}"> {number} </unusable> |
| 139 | <priority> {integer} </priority> |
| 140 | <density unit="{KG/L | LBS/GAL}"> {number} </density> |
| 141 | <type> {string} </type> <!-- will override previous density setting --> |
| 142 | </tank> |
| 143 | @endcode |
| 144 | |
| 145 | <h3>Definition of the tank configuration file parameters:</h3> |
| 146 | |
| 147 | - \b type - One of FUEL or OXIDIZER. This is required. |
| 148 | - \b radius - Equivalent radius of tank for modeling slosh, defaults to inches. |
| 149 | - \b grain_config type - One of CYLINDRICAL or ENDBURNING. |
| 150 | - \b length - length of tank for modeling solid fuel propellant grain, defaults |
| 151 | to inches. |
| 152 | - \b capacity - Capacity, defaults to pounds. |
| 153 | - \b contents - Initial contents, defaults to pounds. |
| 154 | - \b temperature - Initial temperature, defaults to degrees Fahrenheit. |
| 155 | - \b standpipe - Minimum contents to which tank can dump, defaults to pounds. |
| 156 | - \b unusable - Contents that cannot be used for combustion in the engine, |
| 157 | defaults to gallons. |
| 158 | - \b priority - Establishes feed sequence of tank. "1" is the highest priority. |
| 159 | - \b density - Density of liquid tank contents. |
| 160 | - \b type - Named fuel type. One of AVGAS, JET-A, JET-A1, JET-B, JP-1, JP-2, |
| 161 | JP-3, JP-4, JP-5, JP-6, JP-7, JP-8, JP-8+100, RP-1, T-1, ETHANOL, |
| 162 | HYDRAZINE, F-34, F-35, F-40, F-44, AVTAG, AVCAT |
| 163 | |
| 164 | location: |
| 165 | - \b x - Location of tank on aircraft's x-axis, defaults to inches. |
| 166 | - \b y - Location of tank on aircraft's y-axis, defaults to inches. |
| 167 | - \b z - Location of tank on aircraft's z-axis, defaults to inches. |
| 168 | |
| 169 | drain_location: |
| 170 | - \b x - Location of tank drain on aircraft's x-axis, defaults to inches. |
| 171 | - \b y - Location of tank drain on aircraft's y-axis, defaults to inches. |
| 172 | - \b z - Location of tank drain on aircraft's z-axis, defaults to inches. |
| 173 | |
| 174 | <h3>Default values of the tank configuration file parameters:</h3> |
| 175 | |
| 176 | - \b type - ttUNKNOWN (causes a load error in the propulsion configuration) |
| 177 | - \b location, \b drain_location - both optional, but a warning message will |
| 178 | be printed to the console if the location is not given |
| 179 | - \b x - 0.0 (both full and drained CG locations) |
| 180 | - \b y - 0.0 (both full and drained CG locations) |
| 181 | - \b z - 0.0 (both full and drained CG locations) |
| 182 | - \b radius - 0.0 |
| 183 | - \b capacity - 0.00001 (tank capacity must not be zero) |
| 184 | - \b contents - 0.0 |
| 185 | - \b temperature - -9999.0 (flag which indicates no temperature is set) |
| 186 | - \b standpipe - 0.0 (all contents may be dumped) |
| 187 | - \b unusable - 0.0 (all contents may be burnt) |
| 188 | - \b priority - 1 (highest feed sequence priority) |
| 189 | - \b density - 6.6 |
| 190 | |
| 191 | @author Jon Berndt, Dave Culp |
| 192 | @see Akbar, Raza et al. "A Simple Analysis of Fuel Addition to the CWT of |
| 193 | 747", California Institute of Technology, 1998, |
| 194 | http://www.galcit.caltech.edu/EDL/projects/JetA/reports/lumped.pdf |
| 195 | */ |
| 196 | |
| 197 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 198 | CLASS DECLARATION |
| 199 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 200 | |
| 201 | class JSBSIM_API FGTank : public FGJSBBase |
| 202 | { |
| 203 | public: |
| 204 | /** Constructor. |
| 205 | The constructor reads in the defining parameters from a configuration |
| 206 | file. |
| 207 | @param exec a pointer to the base FGFDMExec instance. |
| 208 | @param el a pointer to the Tank element. |
| 209 | @param tank_number the tank number (zero based). |
| 210 | */ |
| 211 | FGTank(FGFDMExec* exec, Element* el, int tank_number); |
| 212 | /// Destructor |
| 213 | ~FGTank(); |
| 214 | |
| 215 | enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER}; |
| 216 | enum GrainType {gtUNKNOWN, gtCYLINDRICAL, gtENDBURNING, gtFUNCTION}; |
| 217 | |
| 218 | /** Removes fuel from the tank. |
| 219 | This function removes fuel from a tank. If the tank empties, it is |
| 220 | deselected. |
| 221 | @param used the amount of fuel used in lbs. |
| 222 | @return the remaining contents of the tank in lbs. |
| 223 | */ |
| 224 | double Drain(double used); |
| 225 | |
| 226 | /** Performs local, tanks-specific calculations, such as fuel temperature. |
| 227 | This function calculates the temperature of the fuel in the tank. |
| 228 | @param dt the time step for this model. |
| 229 | @param TempC the Total Air Temperature in degrees Celsius. |
| 230 | @return the current temperature in degrees Celsius. |
| 231 | */ |
| 232 | double Calculate(double dt, double TempC); |
| 233 | |
| 234 | /** Retrieves the type of tank: Fuel or Oxidizer. |
| 235 | @return the tank type, 0 for undefined, 1 for fuel, and 2 for oxidizer. |
| 236 | */ |
| 237 | int GetType(void) const {return Type;} |
| 238 | |
| 239 | /** Resets the tank parameters to the initial conditions */ |
| 240 | void ResetToIC(void); |
| 241 | |
| 242 | /** If the tank is set to supply fuel, this function returns true. |
| 243 | @return true if this tank is set to a non-zero priority.*/ |
| 244 | bool GetSelected(void) const {return Selected;} |
| 245 | |
| 246 | /** Gets the tank fill level. |
| 247 | @return the fill level in percent, from 0 to 100.*/ |
| 248 | double GetPctFull(void) const {return PctFull;} |
| 249 | |
| 250 | /** Gets the capacity of the tank. |
| 251 | @return the capacity of the tank in pounds. */ |
| 252 | double GetCapacity(void) const {return Capacity;} |
| 253 | |
| 254 | /** Gets the capacity of the tank. |
| 255 | @return the capacity of the tank in gallons. */ |
| 256 | double GetCapacityGallons(void) const {return Capacity/Density;} |
| 257 | |
| 258 | /** Gets the contents of the tank. |
| 259 | @return the contents of the tank in pounds. */ |
| 260 | double GetContents(void) const {return Contents;} |
| 261 | |
| 262 | /** Gets the contents of the tank. |
| 263 | @return the contents of the tank in gallons. */ |
| 264 | double GetContentsGallons(void) const {return Contents/Density;} |
| 265 | |
| 266 | /** Gets the temperature of the fuel. |
| 267 | The temperature of the fuel is calculated if an initial tempearture is |
| 268 | given in the configuration file. |
| 269 | @return the temperature of the fuel in degrees C IF an initial temperature |
| 270 | is given, otherwise 0.0 C is returned. */ |
| 271 | double GetTemperature_degC(void) const {return Temperature;} |
| 272 | |
| 273 | /** Gets the temperature of the fuel. |
| 274 | The temperature of the fuel is calculated if an initial tempearture is |
| 275 | given in the configuration file. |
| 276 | @return the temperature of the fuel in degrees F IF an initial temperature |
| 277 | is given, otherwise 32 degrees F is returned. */ |
| 278 | double GetTemperature(void) const {return CelsiusToFahrenheit(Temperature);} |
| 279 | |
| 280 | /** Returns the density of a named fuel type. |
| 281 | @return the density, in lbs/gal, or 6.6 if name cannot be resolved. */ |
| 282 | double ProcessFuelName(const std::string& name); |
| 283 | |
| 284 | /** Returns the amount of unusable fuel in the tank. |
| 285 | @return the amount in lbs. */ |
| 286 | double GetUnusable(void) const {return UnusableVol*Density;} |
| 287 | |
| 288 | /** Returns the unusable volume of fuel in the tank. |
| 289 | @return the volume in gal. */ |
| 290 | double GetUnusableVolume(void) const {return UnusableVol;} |
| 291 | |
| 292 | /** Sets the volume of unusable fuel in the tank. |
| 293 | @param amount the amount of unusable fuel in gal. */ |
| 294 | void SetUnusableVolume(double volume) {UnusableVol = volume;} |
| 295 | |
| 296 | double GetIxx(void) const {return Ixx;} |
| 297 | double GetIyy(void) const {return Iyy;} |
| 298 | double GetIzz(void) const {return Izz;} |
| 299 | |
| 300 | inline double GetLocationX(void) const { return vXYZ(eX); } |
| 301 | inline double GetLocationY(void) const { return vXYZ(eY); } |
| 302 | inline double GetLocationZ(void) const { return vXYZ(eZ); } |
| 303 | inline void SetLocationX(double x) { vXYZ(eX) = x; } |
| 304 | inline void SetLocationY(double y) { vXYZ(eY) = y; } |
| 305 | inline void SetLocationZ(double z) { vXYZ(eZ) = z; } |
| 306 | |
| 307 | double GetStandpipe(void) const {return Standpipe;} |
| 308 | |
| 309 | int GetPriority(void) const {return Priority;} |
| 310 | void SetPriority(int p) { Priority = p; Selected = p>0 ? true:false; } |
| 311 | |
| 312 | /** Returns the fuel density. |
| 313 | @return the density in lbs/gal. */ |
| 314 | double GetDensity(void) const {return Density;} |
| 315 | /** Sets the fuel density. |
| 316 | @param d the density in lbs/gal. */ |
| 317 | void SetDensity(double d) { Density = d; } |
| 318 | |
| 319 | double GetExternalFlow(void) const {return ExternalFlow;} |
| 320 | void SetExternalFlow(double f) { ExternalFlow = f; } |
| 321 | |
| 322 | FGColumnVector3 GetXYZ(void) const; |
| 323 | double GetXYZ(int idx) const; |
| 324 | |
| 325 | GrainType GetGrainType(void) const {return grainType;} |
| 326 | |
| 327 | double Fill(double amount); |
| 328 | void SetContents(double amount); |
| 329 | void SetContentsGallons(double gallons); |
| 330 | void SetTemperature(double temp) { Temperature = temp; } |
| 331 | void SetStandpipe(double amount) { Standpipe = amount; } |
| 332 | void SetSelected(bool sel) { sel==true ? SetPriority(1):SetPriority(0); } |
| 333 | |
| 334 | private: |
| 335 | TankType Type; |
| 336 | GrainType grainType; |
| 337 | int TankNumber; |
| 338 | std::string type; |
| 339 | std::string strGType; |
| 340 | double ixx_unit; |
| 341 | double iyy_unit; |
| 342 | double izz_unit; |
| 343 | FGColumnVector3 vXYZ; |
| 344 | FGColumnVector3 vXYZ_drain; |
| 345 | FGFunction* function_ixx; |
| 346 | FGFunction* function_iyy; |
| 347 | FGFunction* function_izz; |
| 348 | double Capacity, UnusableVol; |
| 349 | double Radius; |
| 350 | double InnerRadius; |
| 351 | double Length; |
| 352 | double Volume; |
| 353 | double Density; |
| 354 | double Ixx; |
| 355 | double Iyy; |
| 356 | double Izz; |
| 357 | double InertiaFactor; |
| 358 | double PctFull; |
| 359 | double Contents, InitialContents; |
| 360 | double Area; |
| 361 | double Temperature, InitialTemperature; |
| 362 | double Standpipe, InitialStandpipe; |
| 363 | double ExternalFlow; |
| 364 | bool Selected; |
| 365 | int Priority, InitialPriority; |
| 366 | |
| 367 | void CalculateInertias(void); |
| 368 | void bind(FGPropertyManager* PropertyManager); |
| 369 | void Debug(int from); |
| 370 | }; |
| 371 | } |
| 372 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 373 | #endif |