1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 01/05/2004
7 ------------- Copyright (C) 2004 Jon S. Berndt (jsb@hal-pc.org) -------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
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 General Public License for more
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
28 01/05/2004 JSB Created
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include <models/FGAtmosphere.h>
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #define ID_MARS "$Id$"
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 /** Models the Martian atmosphere.
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 class FGMars : public FGAtmosphere {
75 /** Runs the Martian atmosphere model; called by the Executive
76 @return false if no error */
81 /// Returns the temperature in degrees Rankine.
82 inline double GetTemperature(void) const {return *temperature;}
83 /** Returns the density in slugs/ft^3.
84 <i>This function may <b>only</b> be used if Run() is called first.</i> */
85 inline double GetDensity(void) const {return *density;}
86 /// Returns the pressure in psf.
87 inline double GetPressure(void) const {return *pressure;}
88 /// Returns the speed of sound in ft/sec.
89 inline double GetSoundSpeed(void) const {return soundspeed;}
91 /// Returns the sea level temperature in degrees Rankine.
92 inline double GetTemperatureSL(void) const { return SLtemperature; }
93 /// Returns the sea level density in slugs/ft^3
94 inline double GetDensitySL(void) const { return SLdensity; }
95 /// Returns the sea level pressure in psf.
96 inline double GetPressureSL(void) const { return SLpressure; }
97 /// Returns the sea level speed of sound in ft/sec.
98 inline double GetSoundSpeedSL(void) const { return SLsoundspeed; }
100 /// Returns the ratio of at-altitude temperature over the sea level value.
101 inline double GetTemperatureRatio(void) const { return (*temperature)*rSLtemperature; }
102 /// Returns the ratio of at-altitude density over the sea level value.
103 inline double GetDensityRatio(void) const { return (*density)*rSLdensity; }
104 /// Returns the ratio of at-altitude pressure over the sea level value.
105 inline double GetPressureRatio(void) const { return (*pressure)*rSLpressure; }
106 /// Returns the ratio of at-altitude sound speed over the sea level value.
107 inline double GetSoundSpeedRatio(void) const { return soundspeed*rSLsoundspeed; }
109 /// Tells the simulator to use an externally calculated atmosphere model.
110 void UseExternal(void);
111 /// Tells the simulator to use the internal atmosphere model.
112 void UseInternal(void); //this is the default
113 /// Gets the boolean that tells if the external atmosphere model is being used.
114 bool External(void) { return useExternal; }
116 /// Provides the external atmosphere model with an interface to set the temperature.
117 inline void SetExTemperature(double t) { exTemperature=t; }
118 /// Provides the external atmosphere model with an interface to set the density.
119 inline void SetExDensity(double d) { exDensity=d; }
120 /// Provides the external atmosphere model with an interface to set the pressure.
121 inline void SetExPressure(double p) { exPressure=p; }
123 /// Sets the wind components in NED frame.
124 inline void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;}
126 /// Retrieves the wind components in NED frame.
127 inline FGColumnVector3& GetWindNED(void) { return vWindNED; }
129 /** Retrieves the wind direction. The direction is defined as north=0 and
130 increases counterclockwise. The wind heading is returned in radians.*/
131 inline double GetWindPsi(void) const { return psiw; }
133 inline void SetTurbGain(double tt) {TurbGain = tt;}
134 inline void SetTurbRate(double tt) {TurbRate = tt;}
136 inline double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
137 inline FGColumnVector3& GetTurbPQR(void) {return vTurbPQR;}
146 enum tType {ttStandard, ttBerndt, ttNone} turbType;
151 double SLtemperature,SLdensity,SLpressure,SLsoundspeed;
152 double rSLtemperature,rSLdensity,rSLpressure,rSLsoundspeed; //reciprocals
153 double *temperature,*density,*pressure;
156 double exTemperature,exDensity,exPressure;
157 double intTemperature, intDensity, intPressure;
159 double MagnitudedAccelDt, MagnitudeAccel, Magnitude;
162 FGColumnVector3 vDirectiondAccelDt;
163 FGColumnVector3 vDirectionAccel;
164 FGColumnVector3 vDirection;
165 FGColumnVector3 vTurbulence;
166 FGColumnVector3 vTurbulenceGrad;
167 FGColumnVector3 vBodyTurbGrad;
168 FGColumnVector3 vTurbPQR;
170 FGColumnVector3 vWindNED;
173 void Calculate(double altitude);
174 void Turbulence(void);
175 void Debug(int from);
178 } // namespace JSBSim
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%