1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Models the Martian atmosphere very simply
9 ------------- Copyright (C) 2004 Jon S. Berndt (jsb@hal-pc.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 Models the Martian atmosphere.
33 --------------------------------------------------------------------------------
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 COMMENTS, REFERENCES, and NOTES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 static const char *IdSrc = "$Id$";
50 static const char *IdHdr = ID_MARS;
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 FGMars::FGMars(FGFDMExec* fdmex) : FGAtmosphere(fdmex)
67 MagnitudedAccelDt = MagnitudeAccel = Magnitude = 0.0;
69 turbType = ttStandard;
70 // turbType = ttBerndt;
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 bool FGMars::InitModel(void)
93 SLtemperature = intTemperature;
94 SLpressure = intPressure;
95 SLdensity = intDensity;
96 SLsoundspeed = sqrt(SHRatio*Reng*intTemperature);
97 rSLtemperature = 1.0/intTemperature;
98 rSLpressure = 1.0/intPressure;
99 rSLdensity = 1.0/intDensity;
100 rSLsoundspeed = 1.0/SLsoundspeed;
101 temperature = &intTemperature;
102 pressure = &intPressure;
103 density = &intDensity;
110 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 bool FGMars::Run(void)
114 if (FGModel::Run()) return true;
115 if (FDMExec->Holding()) return false;
117 //do temp, pressure, and density first
119 h = Propagate->Geth();
123 if (turbType != ttNone) {
125 vWindNED += vTurbulence;
128 if (vWindNED(1) != 0.0) psiw = atan2( vWindNED(2), vWindNED(1) );
130 if (psiw < 0) psiw += 2*M_PI;
132 soundspeed = sqrt(SHRatio*Reng*(*temperature));
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 void FGMars::Calculate(double altitude)
143 //Calculate reftemp, refpress, and density
145 // LIMIT the temperatures so they do not descend below absolute zero.
147 if (altitude < 22960.0) {
148 intTemperature = -25.68 - 0.000548*altitude; // Deg Fahrenheit
150 intTemperature = -10.34 - 0.001217*altitude; // Deg Fahrenheit
152 intPressure = 14.62*exp(-0.00003*altitude); // psf - 14.62 psf =~ 7 millibars
153 intDensity = intPressure/(Reng*intTemperature); // slugs/ft^3 (needs deg R. as input
155 //cout << "Atmosphere: h=" << altitude << " rho= " << intDensity << endl;
158 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160 // square a value, but preserve the original sign
163 square_signed (double value)
166 return value * value * -1;
168 return value * value;
171 void FGMars::Turbulence(void)
175 vDirectiondAccelDt(eX) = 1 - 2.0*(double(rand())/double(RAND_MAX));
176 vDirectiondAccelDt(eY) = 1 - 2.0*(double(rand())/double(RAND_MAX));
177 vDirectiondAccelDt(eZ) = 1 - 2.0*(double(rand())/double(RAND_MAX));
179 MagnitudedAccelDt = 1 - 2.0*(double(rand())/double(RAND_MAX)) - Magnitude;
180 // Scale the magnitude so that it moves
181 // away from the peaks
182 MagnitudedAccelDt = ((MagnitudedAccelDt - Magnitude) /
183 (1 + fabs(Magnitude)));
184 MagnitudeAccel += MagnitudedAccelDt*rate*TurbRate*State->Getdt();
185 Magnitude += MagnitudeAccel*rate*State->Getdt();
187 vDirectiondAccelDt.Normalize();
189 // deemphasise non-vertical forces
190 vDirectiondAccelDt(eX) = square_signed(vDirectiondAccelDt(eX));
191 vDirectiondAccelDt(eY) = square_signed(vDirectiondAccelDt(eY));
193 vDirectionAccel += vDirectiondAccelDt*rate*TurbRate*State->Getdt();
194 vDirectionAccel.Normalize();
195 vDirection += vDirectionAccel*rate*State->Getdt();
197 vDirection.Normalize();
199 // Diminish turbulence within three wingspans
201 vTurbulence = TurbGain * Magnitude * vDirection;
202 double HOverBMAC = Auxiliary->GetHOverBMAC();
204 vTurbulence *= (HOverBMAC / 3.0) * (HOverBMAC / 3.0);
206 vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection;
208 vBodyTurbGrad = Propagate->GetTl2b()*vTurbulenceGrad;
209 vTurbPQR(eP) = vBodyTurbGrad(eY)/Aircraft->GetWingSpan();
210 // if (Aircraft->GetHTailArm() != 0.0)
211 // vTurbPQR(eQ) = vBodyTurbGrad(eZ)/Aircraft->GetHTailArm();
213 // vTurbPQR(eQ) = vBodyTurbGrad(eZ)/10.0;
215 if (Aircraft->GetVTailArm())
216 vTurbPQR(eR) = vBodyTurbGrad(eX)/Aircraft->GetVTailArm();
218 vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0;
220 // Clear the horizontal forces
221 // actually felt by the plane, now
222 // that we've used them to calculate
224 vTurbulence(eX) = 0.0;
225 vTurbulence(eY) = 0.0;
230 vDirectiondAccelDt(eX) = 1 - 2.0*(double(rand())/double(RAND_MAX));
231 vDirectiondAccelDt(eY) = 1 - 2.0*(double(rand())/double(RAND_MAX));
232 vDirectiondAccelDt(eZ) = 1 - 2.0*(double(rand())/double(RAND_MAX));
235 MagnitudedAccelDt = 1 - 2.0*(double(rand())/double(RAND_MAX)) - Magnitude;
236 MagnitudeAccel += MagnitudedAccelDt*rate*State->Getdt();
237 Magnitude += MagnitudeAccel*rate*State->Getdt();
239 vDirectiondAccelDt.Normalize();
240 vDirectionAccel += vDirectiondAccelDt*rate*State->Getdt();
241 vDirectionAccel.Normalize();
242 vDirection += vDirectionAccel*rate*State->Getdt();
244 // Diminish z-vector within two wingspans
246 double HOverBMAC = Auxiliary->GetHOverBMAC();
248 vDirection(eZ) *= HOverBMAC / 2.0;
250 vDirection.Normalize();
252 vTurbulence = TurbGain*Magnitude * vDirection;
253 vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection;
255 vBodyTurbGrad = Propagate->GetTl2b()*vTurbulenceGrad;
256 vTurbPQR(eP) = vBodyTurbGrad(eY)/Aircraft->GetWingSpan();
257 if (Aircraft->GetHTailArm() != 0.0)
258 vTurbPQR(eQ) = vBodyTurbGrad(eZ)/Aircraft->GetHTailArm();
260 vTurbPQR(eQ) = vBodyTurbGrad(eZ)/10.0;
262 if (Aircraft->GetVTailArm())
263 vTurbPQR(eR) = vBodyTurbGrad(eX)/Aircraft->GetVTailArm();
265 vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0;
274 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 // The bitmasked value choices are as follows:
276 // unset: In this case (the default) JSBSim would only print
277 // out the normally expected messages, essentially echoing
278 // the config files as they are read. If the environment
279 // variable is not set, debug_lvl is set to 1 internally
280 // 0: This requests JSBSim not to output any messages
282 // 1: This value explicity requests the normal JSBSim
284 // 2: This value asks for a message to be printed out when
285 // a class is instantiated
286 // 4: When this value is set, a message is displayed when a
287 // FGModel object executes its Run() method
288 // 8: When this value is set, various runtime state variables
289 // are printed out periodically
290 // 16: When set various parameters are sanity checked and
291 // a message is printed out when they go out of bounds
293 void FGMars::Debug(int from)
295 if (debug_lvl <= 0) return;
297 if (debug_lvl & 1) { // Standard console startup message output
298 if (from == 0) { // Constructor
301 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
302 if (from == 0) cout << "Instantiated: FGMars" << endl;
303 if (from == 1) cout << "Destroyed: FGMars" << endl;
305 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
307 if (debug_lvl & 8 ) { // Runtime state variables
309 if (debug_lvl & 16) { // Sanity checking
311 if (debug_lvl & 32) { // Turbulence
312 if (first_pass && from == 2) {
313 cout << "vTurbulence(X), vTurbulence(Y), vTurbulence(Z), "
314 << "vTurbulenceGrad(X), vTurbulenceGrad(Y), vTurbulenceGrad(Z), "
315 << "vDirection(X), vDirection(Y), vDirection(Z), "
317 << "vTurbPQR(P), vTurbPQR(Q), vTurbPQR(R), " << endl;
318 } else if (from == 2) {
319 cout << vTurbulence << ", " << vTurbulenceGrad << ", " << vDirection << ", " << Magnitude << ", " << vTurbPQR << endl;
322 if (debug_lvl & 64) {
323 if (from == 0) { // Constructor
324 cout << IdSrc << endl;
325 cout << IdHdr << endl;
330 } // namespace JSBSim