]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAtmosphere.h
Updates from JSBSim, including new turbine engine model from David Culp
[flightgear.git] / src / FDM / JSBSim / FGAtmosphere.h
1 /*******************************************************************************
2  
3  Header:       FGAtmosphere.h
4  Author:       Jon Berndt
5                Implementation of 1959 Standard Atmosphere added by Tony Peden
6  Date started: 11/24/98
7  
8  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
9  
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14  
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19  
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23  
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26  
27 HISTORY
28 --------------------------------------------------------------------------------
29 11/24/98   JSB   Created
30 07/23/99   TP   Added implementation of 1959 Standard Atmosphere
31            Moved calculation of Mach number to FGTranslation
32                 Updated to '76 model
33  
34  
35 ********************************************************************************
36 SENTRY
37 *******************************************************************************/
38
39 #ifndef FGAtmosphere_H
40 #define FGAtmosphere_H
41
42 /*******************************************************************************
43 INCLUDES
44 *******************************************************************************/
45
46 #include "FGModel.h"
47 #include "FGMatrix33.h"
48 #include "FGColumnVector3.h"
49 #include "FGColumnVector4.h"
50
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 DEFINITIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55 #define ID_ATMOSPHERE "$Id$"
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 FORWARD DECLARATIONS
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
65 [1]   Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
66       1989, ISBN 0-07-001641-0
67
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 CLASS DOCUMENTATION
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
71
72 /** Models the standard atmosphere.
73     @author Tony Peden, Jon Berndt
74     @version $Id$
75     @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGAtmosphere.h?rev=HEAD&content-type=text/vnd.viewcvs-markup">
76          Header File </a>
77     @see <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/jsbsim/JSBSim/FGAtmosphere.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup">
78          Source File </a>
79 */
80
81 /******************************************************************************
82 CLASS DECLARATION
83 *******************************************************************************/
84
85 namespace JSBSim {
86
87 class FGAtmosphere : public FGModel {
88 public:
89
90   /// Constructor
91   FGAtmosphere(FGFDMExec*);
92   /// Destructor
93   ~FGAtmosphere();
94   /** Runs the Atmosphere model; called by the Executive
95       @return false if no error */
96   bool Run(void);
97
98   bool InitModel(void);
99
100   /// Returns the temperature in degrees Rankine.
101   inline double GetTemperature(void) const {return *temperature;}
102   /** Returns the density in slugs/ft^3.
103       <i>This function may <b>only</b> be used if Run() is called first.</i> */
104   inline double GetDensity(void)  const {return *density;}
105   /// Returns the pressure in psf.
106   inline double GetPressure(void)  const {return *pressure;}
107   /// Returns the speed of sound in ft/sec.
108   inline double GetSoundSpeed(void) const {return soundspeed;}
109
110   /// Returns the sea level temperature in degrees Rankine.
111   inline double GetTemperatureSL(void) const { return SLtemperature; }
112   /// Returns the sea level density in slugs/ft^3
113   inline double GetDensitySL(void)  const { return SLdensity; }
114   /// Returns the sea level pressure in psf.
115   inline double GetPressureSL(void) const { return SLpressure; }
116   /// Returns the sea level speed of sound in ft/sec.
117   inline double GetSoundSpeedSL(void) const { return SLsoundspeed; }
118
119   /// Returns the ratio of at-altitude temperature over the sea level value.
120   inline double GetTemperatureRatio(void) const { return (*temperature)*rSLtemperature; }
121   /// Returns the ratio of at-altitude density over the sea level value.
122   inline double GetDensityRatio(void) const { return (*density)*rSLdensity; }
123   /// Returns the ratio of at-altitude pressure over the sea level value.
124   inline double GetPressureRatio(void) const { return (*pressure)*rSLpressure; }
125   /// Returns the ratio of at-altitude sound speed over the sea level value.
126   inline double GetSoundSpeedRatio(void) const { return soundspeed*rSLsoundspeed; }
127
128   /// Tells the simulator to use an externally calculated atmosphere model.
129   void UseExternal(void);
130   /// Tells the simulator to use the internal atmosphere model.
131   void UseInternal(void);  //this is the default
132   /// Gets the boolean that tells if the external atmosphere model is being used.
133   bool External(void) { return useExternal; }
134
135   /// Provides the external atmosphere model with an interface to set the temperature.
136   inline void SetExTemperature(double t)  { exTemperature=t; }
137   /// Provides the external atmosphere model with an interface to set the density.
138   inline void SetExDensity(double d)      { exDensity=d; }
139   /// Provides the external atmosphere model with an interface to set the pressure.
140   inline void SetExPressure(double p)     { exPressure=p; }
141
142   /// Sets the wind components in NED frame.
143   inline void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;}
144
145   /// Retrieves the wind components in NED frame.
146   inline FGColumnVector3& GetWindNED(void) { return vWindNED; }
147   
148   /** Retrieves the wind direction. The direction is defined as north=0 and
149       increases counterclockwise. The wind heading is returned in radians.*/
150   inline double GetWindPsi(void) const { return psiw; }
151   
152   inline void SetTurbGain(double tt) {TurbGain = tt;}
153   
154   inline double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
155   inline FGColumnVector3& GetTurbPQR(void) {return vTurbPQR;}
156   
157   void bind(void);
158   void unbind(void);
159
160   
161 private:
162   double rho;
163
164   enum tType {ttStandard, ttBerndt, ttNone} turbType;
165
166   int lastIndex;
167   double h;
168   double htab[8];
169   double SLtemperature,SLdensity,SLpressure,SLsoundspeed;
170   double rSLtemperature,rSLdensity,rSLpressure,rSLsoundspeed; //reciprocals
171   double *temperature,*density,*pressure;
172   double soundspeed;
173   bool useExternal;
174   double exTemperature,exDensity,exPressure;
175   double intTemperature, intDensity, intPressure;
176   
177   double MagnitudedAccelDt, MagnitudeAccel, Magnitude;
178   double TurbGain;
179   FGColumnVector3 vDirectiondAccelDt;
180   FGColumnVector3 vDirectionAccel;
181   FGColumnVector3 vDirection;
182   FGColumnVector3 vTurbulence;
183   FGColumnVector3 vTurbulenceGrad;
184   FGColumnVector3 vBodyTurbGrad;
185   FGColumnVector3 vTurbPQR;
186
187   FGColumnVector3 vWindNED;
188   double psiw;
189
190   void Calculate(double altitude);
191   void Turbulence(void);
192   void Debug(int from);
193 };
194
195 } // namespace JSBSim
196
197 /******************************************************************************/
198 #endif
199