]> git.mxchange.org Git - flightgear.git/blob - src/Environment/atmosphere.hxx
fix a pointer reference.
[flightgear.git] / src / Environment / atmosphere.hxx
1 // atmosphere.hxx -- routines to model the air column
2 //
3 // Written by David Megginson, started February 2002.
4 // Modified by John Denker to correct physics errors in 2007
5 //
6 // Copyright (C) 2002  David Megginson - david@megginson.com
7 //
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.
12 //
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.
17 //
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.
21 //
22 // $Id$
23
24
25 #ifndef _ATMOSPHERE_HXX
26 #define _ATMOSPHERE_HXX
27
28 #include <simgear/compiler.h>
29 #include <simgear/math/interpolater.hxx>
30
31 #include <cmath>
32 #include <utility>
33
34 using namespace std;
35
36 /**
37  * Model the atmosphere in a way consistent with the laws
38  * of physics.
39  *
40  * Each instance of this class models a particular air mass.
41  * You may freely move up, down, or sideways in the air mass.
42  * In contrast, if you want to compare different air masses,
43  * you should use a separate instance for each one.
44  *
45  * See also ./environment.hxx
46  */
47
48 #define SCD(name,val) const double name(val)
49 namespace atmodel {
50     SCD(g, 9.80665);            // [m/s/s] acceleration of gravity
51     SCD(mm, .0289644);          // [kg/mole] molar mass of air (dry?)
52     SCD(Rgas, 8.31432);         // [J/K/mole] gas constant
53     SCD(inch, 0.0254);          // [m] definition of inch
54     SCD(foot, 12 * inch);       // [m]
55     SCD(inHg, 101325.0 / 760 * 1000 * inch);  // [Pa] definition of inHg
56     SCD(mbar, 100.);            // [Pa] definition of millibar
57     SCD(freezing, 273.15);      // [K] centigrade - kelvin offset
58     SCD(nm, 1852);              // [m] nautical mile (NIST)
59     SCD(sm, 5280*foot);         // [m] nautical mile (NIST)
60
61     namespace ISA {
62         SCD(P0, 101325.0);              // [pascals] ISA sea-level pressure
63         SCD(T0, 15. + freezing);        // [K] ISA sea-level temperature
64         SCD(lam0, .0065);               // [K/m] ISA troposphere lapse rate
65     }
66 }
67 #undef SCD
68
69
70
71 class ISA_layer {
72 public:
73   double height;
74   double temp;
75   double lapse;
76   ISA_layer(int, double h, double, double, double, double t, double,
77                     double l=-1, double=0)
78    :  height(h),        // [meters]
79       temp(t),          // [kelvin]
80       lapse(l)          // [K/m]
81   {}
82 };
83
84 extern const ISA_layer ISA_def[];
85
86 std::pair<double,double> PT_vs_hpt(
87           const double hh, 
88           const double _p0 = atmodel::ISA::P0,
89           const double _t0 = atmodel::ISA::T0);
90
91 double P_layer(const double height, const double href,
92   const double Pref, const double Tref, const double lapse );
93
94 double T_layer(const double height, const double href,
95   const double Pref, const double Tref,  const double lapse );
96
97 // The base class is little more than a namespace.
98 // It has no constructor, no destructor, and no variables.
99 class FGAtmo {
100 public:
101     double a_vs_p(const double press, const double qnh = atmodel::ISA::P0);
102     double fake_T_vs_a_us(const double h_ft, 
103                 const double Tsl = atmodel::ISA::T0) const;
104     double fake_dp_vs_a_us(const double dpsl, const double h_ft);
105     void check_one(const double height);
106
107 // Altimeter setting _in pascals_ 
108 //  ... caller gets to convert to inHg or millibars
109 // Field elevation in m
110 // Field pressure in pascals
111 // Valid for fields within the troposphere only.
112     double QNH(const double field_elev, const double field_press);
113 };
114
115
116
117 class FGAtmoCache : FGAtmo {
118     friend class FGAltimeter;
119     SGInterpTable * a_tvs_p;    // _tvs_ means "tabulated versus"
120
121 public:
122     FGAtmoCache();
123     ~FGAtmoCache();
124     void tabulate();
125     void cache();
126     void check_model();  // debug
127 };
128
129
130
131 class FGAltimeter : public FGAtmoCache {
132     double kset;
133     double kft;
134
135 public:
136     FGAltimeter();
137     double reading_ft(const double p_inHg,
138             const double set_inHg = atmodel::ISA::P0/atmodel::inHg);
139     inline double press_alt_ft(const double p_inHg) {
140         return a_tvs_p->interpolate(p_inHg);
141     }
142     inline double kollsman_ft(const double set_inHg) {
143         return a_tvs_p->interpolate(set_inHg);
144     }
145
146     // debug
147     void dump_stack();
148     void dump_stack1(const double Tref);
149 };
150
151 #endif // _ATMOSPHERE_HXX