1 // atmosphere.hxx -- routines to model the air column
3 // Written by David Megginson, started February 2002.
4 // Modified by John Denker to correct physics errors in 2007
6 // Copyright (C) 2002 David Megginson - david@megginson.com
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #ifndef _ATMOSPHERE_HXX
26 #define _ATMOSPHERE_HXX
28 #include <simgear/compiler.h>
29 #include <simgear/math/interpolater.hxx>
30 #include "boost/tuple/tuple.hpp"
31 using namespace boost;
38 * Model the atmosphere in a way consistent with the laws
41 * Each instance of this class models a particular air mass.
42 * You may freely move up, down, or sideways in the air mass.
43 * In contrast, if you want to compare different air masses,
44 * you should use a separate instance for each one.
46 * See also ./environment.hxx
49 #define SCD(name,val) const double name(val)
51 SCD(g, 9.80665); // [m/s/s] acceleration of gravity
52 SCD(mm, .0289644); // [kg/mole] molar mass of air (dry?)
53 SCD(Rgas, 8.31432); // [J/K/mole] gas constant
54 SCD(inch, 0.0254); // [m] definition of inch
55 SCD(foot, 12 * inch); // [m]
56 SCD(inHg, 101325.0 / 760 * 1000 * inch); // [Pa] definition of inHg
57 SCD(mbar, 100.); // [Pa] definition of millibar
58 SCD(freezing, 273.15); // [K] centigrade - kelvin offset
59 SCD(nm, 1852); // [m] nautical mile (NIST)
60 SCD(sm, 5280*foot); // [m] nautical mile (NIST)
63 SCD(P0, 101325.0); // [pascals] ISA sea-level pressure
64 SCD(T0, 15. + freezing); // [K] ISA sea-level temperature
65 SCD(lam0, .0065); // [K/m] ISA troposphere lapse rate
77 ISA_layer(int, double h, double, double, double, double t, double,
78 double l=-1, double=0)
79 : height(h), // [meters]
85 extern const ISA_layer ISA_def[];
87 tuple<double,double> PT_vs_hpt(
89 const double _p0 = atmodel::ISA::P0,
90 const double _t0 = atmodel::ISA::T0);
92 double P_layer(const double height, const double href,
93 const double Pref, const double Tref, const double lapse );
95 double T_layer(const double height, const double href,
96 const double Pref, const double Tref, const double lapse );
98 // The base class is little more than a namespace.
99 // It has no constructor, no destructor, and no variables.
102 double a_vs_p(const double press, const double qnh = atmodel::ISA::P0);
103 double fake_T_vs_a_us(const double h_ft,
104 const double Tsl = atmodel::ISA::T0) const;
105 double fake_dp_vs_a_us(const double dpsl, const double h_ft);
106 void check_one(const double height);
108 // Altimeter setting _in pascals_
109 // ... caller gets to convert to inHg or millibars
110 // Field elevation in m
111 // Field pressure in pascals
112 // Valid for fields within the troposphere only.
113 double QNH(const double field_elev, const double field_press);
118 class FGAtmoCache : FGAtmo {
119 friend class FGAltimeter;
120 SGInterpTable * a_tvs_p; // _tvs_ means "tabulated versus"
127 void check_model(); // debug
132 class FGAltimeter : public FGAtmoCache {
138 double reading_ft(const double p_inHg,
139 const double set_inHg = atmodel::ISA::P0/atmodel::inHg);
140 inline double press_alt_ft(const double p_inHg) {
141 return a_tvs_p->interpolate(p_inHg);
143 inline double kollsman_ft(const double set_inHg) {
144 return a_tvs_p->interpolate(set_inHg);
149 void dump_stack1(const double Tref);
152 #endif // _ATMOSPHERE_HXX