]> git.mxchange.org Git - flightgear.git/blob - src/Environment/atmosphere.hxx
Port over remaining Point3D usage to the more type and unit safe SG* classes.
[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
33 using namespace std;
34
35 /**
36  * Model the atmosphere in a way consistent with the laws
37  * of physics.
38  *
39  * Each instance of this class models a particular air mass.
40  * You may freely move up, down, or sideways in the air mass.
41  * In contrast, if you want to compare different air masses,
42  * you should use a separate instance for each one.
43  *
44  * See also ./environment.hxx
45  */
46
47 #define SCD(name,val) const double name(val)
48 namespace atmodel {
49     SCD(g, 9.80665);            // [m/s/s] acceleration of gravity
50     SCD(mm, .0289644);          // [kg/mole] molar mass of air (dry?)
51     SCD(Rgas, 8.31432);         // [J/K/mole] gas constant
52     SCD(inch, 0.0254);          // [m] definition of inch
53     SCD(foot, 12 * inch);               // [m]
54     SCD(inHg, 101325.0 / 760 * 1000 * inch);  // [Pa] definition of inHg
55     SCD(freezing, 273.15);      // [K] centigrade - kelvin offset
56     SCD(nm, 1852);              // [m] nautical mile (NIST)
57     SCD(sm, 5280*foot);         // [m] nautical mile (NIST)
58
59     namespace ISA {
60         SCD(P0, 101325.0);              // [pascals] ISA sea-level pressure
61         SCD(T0, 15. + freezing);        // [K] ISA sea-level temperature
62         SCD(lam0, .0065);               // [K/m] ISA troposphere lapse rate
63     }
64 }
65 #undef SCD
66
67
68
69 // The base class is little more than a namespace.
70 // It has no constructor, no destructor, and no variables.
71 class FGAtmo {
72 public:
73     double p_vs_a(const double height);
74     double a_vs_p(const double press, const double qnh = atmodel::ISA::P0);
75     double fake_t_vs_a_us(const double h_ft);
76     double fake_dp_vs_a_us(const double dpsl, const double h_ft);
77     double P_layer(const double height, const double href,
78     const double Pref, const double Tref,
79     const double lapse );
80     void check_one(const double height);
81     double qnh(const double field_ft, const double press_in);
82 };
83
84
85
86 class FGAtmoCache : FGAtmo {
87     friend class FGAltimeter;
88     SGInterpTable * a_tvs_p;    // _tvs_ means "tabulated versus"
89
90 public:
91     FGAtmoCache();
92     ~FGAtmoCache();
93     void tabulate();
94     void cache();
95     void check_model();  // debug
96 };
97
98
99
100 class FGAltimeter : public FGAtmoCache {
101     double kset;
102     double kft;
103
104 public:
105     FGAltimeter();
106     double reading_ft(const double p_inHg,
107             const double set_inHg = atmodel::ISA::P0/atmodel::inHg);
108     inline double press_alt_ft(const double p_inHg) {
109         return a_tvs_p->interpolate(p_inHg);
110     }
111     inline double kollsman_ft(const double set_inHg) {
112         return a_tvs_p->interpolate(set_inHg);
113     }
114
115     // debug
116     void dump_stack();
117     void dump_stack1(const double Tref);
118 };
119
120 #endif // _ATMOSPHERE_HXX