]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAtmosphere.cpp
Merge branch 'jmt/dialog'
[flightgear.git] / src / FDM / JSBSim / models / FGAtmosphere.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGAtmosphere.cpp
4  Author:       Jon Berndt
5                Implementation of 1959 Standard Atmosphere added by Tony Peden
6  Date started: 11/24/98
7  Purpose:      Models the atmosphere
8  Called by:    FGSimExec
9
10  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
11
12  This program is free software; you can redistribute it and/or modify it under
13  the terms of the GNU Lesser General Public License as published by the Free Software
14  Foundation; either version 2 of the License, or (at your option) any later
15  version.
16
17  This program is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
20  details.
21
22  You should have received a copy of the GNU Lesser General Public License along with
23  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24  Place - Suite 330, Boston, MA  02111-1307, USA.
25
26  Further information about the GNU Lesser General Public License can also be found on
27  the world wide web at http://www.gnu.org.
28
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
31 Models the atmosphere. The equation used below was determined by a third order
32 curve fit using Excel. The data is from the ICAO atmosphere model.
33
34 HISTORY
35 --------------------------------------------------------------------------------
36 11/24/98   JSB   Created
37 07/23/99   TP    Added implementation of 1959 Standard Atmosphere
38                  Moved calculation of Mach number to FGPropagate
39                  Later updated to '76 model
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 COMMENTS, REFERENCES,  and NOTES
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 [1]   Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
44       1989, ISBN 0-07-001641-0
45
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 INCLUDES
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49
50 #include "FGAtmosphere.h"
51 #include "FGState.h"
52 #include "FGFDMExec.h"
53 #include "FGAircraft.h"
54 #include "FGPropagate.h"
55 #include "FGInertial.h"
56 #include "input_output/FGPropertyManager.h"
57 #include <iostream>
58 #include <cstdlib>
59
60 using namespace std;
61
62 namespace JSBSim {
63
64 static const char *IdSrc = "$Id$";
65 static const char *IdHdr = ID_ATMOSPHERE;
66
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 CLASS IMPLEMENTATION
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70
71 FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex)
72 {
73   Name = "FGAtmosphere";
74   lastIndex = 0;
75   h = 0.0;
76   psiw = 0.0;
77   htab[0]=0;
78   htab[1]= 36089.0;
79   htab[2]= 65617.0;
80   htab[3]=104987.0;
81   htab[4]=154199.0;
82   htab[5]=167322.0;
83   htab[6]=232940.0;
84   htab[7]=278385.0; //ft.
85
86   MagnitudedAccelDt = MagnitudeAccel = Magnitude = 0.0;
87 //  SetTurbType( ttCulp );
88   SetTurbType( ttNone );
89   TurbGain = 1.0;
90   TurbRate = 10.0;
91   Rhythmicity = 0.1;
92   spike = target_time = strength = 0.0;
93   wind_from_clockwise = 0.0;
94   SutherlandConstant = 198.72; // deg Rankine
95   Beta = 2.269690E-08; // slug/(sec ft R^0.5)
96
97   T_dev_sl = T_dev = delta_T = 0.0;
98   StandardTempOnly = false;
99   first_pass = true;
100   vGustNED.InitMatrix();
101   vTurbulenceNED.InitMatrix();
102
103   bind();
104   Debug(0);
105 }
106
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109 FGAtmosphere::~FGAtmosphere()
110 {
111   Debug(1);
112 }
113
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115
116 bool FGAtmosphere::InitModel(void)
117 {
118   if (!FGModel::InitModel()) return false;
119
120   UseInternal();  // this is the default
121
122   Calculate(h);
123   StdSLtemperature = SLtemperature = 518.67;
124   StdSLpressure    = SLpressure = 2116.22;
125   StdSLdensity     = SLdensity = 0.00237767;
126   StdSLsoundspeed  = SLsoundspeed = sqrt(SHRatio*Reng*StdSLtemperature);
127   rSLtemperature = 1.0/StdSLtemperature;
128   rSLpressure    = 1.0/StdSLpressure;
129   rSLdensity     = 1.0/StdSLdensity;
130   rSLsoundspeed  = 1.0/StdSLsoundspeed;
131
132   return true;
133 }
134
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
137 bool FGAtmosphere::Run(void)
138 {
139   if (FGModel::Run()) return true;
140   if (FDMExec->Holding()) return false;
141
142   T_dev = 0.0;
143   h = Propagate->GetAltitudeASL();
144
145   if (!useExternal) {
146     Calculate(h);
147     CalculateDerived();
148   } else {
149     CalculateDerived();
150   }
151
152   Debug(2);
153   return false;
154 }
155
156 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 //
158 // See reference 1
159
160 void FGAtmosphere::Calculate(double altitude)
161 {
162   double slope, reftemp, refpress;
163   int i = lastIndex;
164
165   if (altitude < htab[lastIndex]) {
166     if (altitude <= 0) {
167       i = 0;
168       altitude=0;
169     } else {
170        i = lastIndex-1;
171        while (htab[i] > altitude) i--;
172     }
173   } else if (altitude > htab[lastIndex+1]) {
174     if (altitude >= htab[7]) {
175       i = 7;
176       altitude = htab[7];
177     } else {
178       i = lastIndex+1;
179       while (htab[i+1] < altitude) i++;
180     }
181   }
182
183   switch(i) {
184   case 0: // Sea level
185     slope     = -0.00356616; // R/ft.
186     reftemp   = 518.67;   // in degrees Rankine, 288.15 Kelvin
187     refpress  = 2116.22;    // psf
188     //refdens   = 0.00237767;  // slugs/cubic ft.
189     break;
190   case 1:     // 36089 ft. or 11 km
191     slope     = 0;
192     reftemp   = 389.97; // in degrees Rankine, 216.65 Kelvin
193     refpress  = 472.763;
194     //refdens   = 0.000706032;
195     break;
196   case 2:     // 65616 ft. or 20 km
197     slope     = 0.00054864;
198     reftemp   = 389.97; // in degrees Rankine, 216.65 Kelvin
199     refpress  = 114.636;
200     //refdens   = 0.000171306;
201     break;
202   case 3:     // 104986 ft. or 32 km
203     slope     = 0.001536192;
204     reftemp   = 411.57; // in degrees Rankine, 228.65 Kelvin
205     refpress  = 18.128;
206     //refdens   = 1.18422e-05;
207     break;
208   case 4:     // 154199 ft. 47 km
209     slope     = 0;
210     reftemp   = 487.17; // in degrees Rankine, 270.65 Kelvin
211     refpress  = 2.316;
212     //refdens   = 4.00585e-7;
213     break;
214   case 5:     // 167322 ft. or 51 km
215     slope     = -0.001536192;
216     reftemp   = 487.17; // in degrees Rankine, 270.65 Kelvin
217     refpress  = 1.398;
218     //refdens   = 8.17102e-7;
219     break;
220   case 6:     // 232940 ft. or 71 km
221     slope     = -0.00109728;
222     reftemp   = 386.368; // in degrees Rankine, 214.649 Kelvin
223     refpress  = 0.0826;
224     //refdens   = 8.77702e-9;
225     break;
226   case 7:     // 278385 ft. or 84.8520 km
227     slope     = 0;
228     reftemp   = 336.5; // in degrees Rankine, 186.94 Kelvin
229     refpress  = 0.00831;
230     //refdens   = 2.19541e-10;
231     break;
232   default:     // sea level
233     slope     = -0.00356616; // R/ft.
234     reftemp   = 518.67;   // in degrees Rankine, 288.15 Kelvin
235     refpress  = 2116.22;    // psf
236     //refdens   = 0.00237767;  // slugs/cubic ft.
237     break;
238
239   }
240
241   // If delta_T is set, then that is our temperature deviation at any altitude.
242   // If not, then we'll estimate a deviation based on the sea level deviation (if set).
243
244   if(!StandardTempOnly) {
245     T_dev = 0.0;
246     if (delta_T != 0.0) {
247       T_dev = delta_T;
248     } else {
249       if ((altitude < 36089.239) && (T_dev_sl != 0.0)) {
250         T_dev = T_dev_sl * ( 1.0 - (altitude/36089.239));
251       }
252     }
253     reftemp+=T_dev;
254   }
255
256   if (slope == 0) {
257     intTemperature = reftemp;
258     intPressure = refpress*exp(-Inertial->SLgravity()/(reftemp*Reng)*(altitude-htab[i]));
259     intDensity = intPressure/(Reng*intTemperature);
260   } else {
261     intTemperature = reftemp+slope*(altitude-htab[i]);
262     intPressure = refpress*pow(intTemperature/reftemp,-Inertial->SLgravity()/(slope*Reng));
263     intDensity = intPressure/(Reng*intTemperature);
264   }
265   
266   lastIndex=i;
267 }
268
269 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 // Calculate parameters derived from T, P and rho
271 // Sum gust and turbulence values in NED frame into the wind vector.
272
273 void FGAtmosphere::CalculateDerived(void)
274 {
275   T_dev = (*temperature) - GetTemperature(h);
276   density_altitude = h + T_dev * 66.7;
277
278   if (turbType != ttNone) Turbulence();
279
280   vTotalWindNED = vWindNED + vGustNED + vTurbulenceNED;
281
282    // psiw (Wind heading) is the direction the wind is blowing towards
283   if (vWindNED(eX) != 0.0) psiw = atan2( vWindNED(eY), vWindNED(eX) );
284   if (psiw < 0) psiw += 2*M_PI;
285
286   soundspeed = sqrt(SHRatio*Reng*(*temperature));
287
288   intViscosity = Beta * pow(intTemperature, 1.5) / (SutherlandConstant + intTemperature);
289   intKinematicViscosity = intViscosity / intDensity;
290 }
291
292
293 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 // Get the standard atmospheric properties at a specified altitude
295
296 void FGAtmosphere::GetStdAtmosphere(double altitude) {
297   StandardTempOnly = true;
298   Calculate(altitude);
299   StandardTempOnly = false;
300   atmosphere.Temperature = intTemperature;
301   atmosphere.Pressure = intPressure;
302   atmosphere.Density = intDensity;
303
304   // Reset the internal atmospheric state
305   Calculate(h);
306 }
307
308 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 // Get the standard pressure at a specified altitude
310
311 double FGAtmosphere::GetPressure(double altitude) {
312   GetStdAtmosphere(altitude);
313   return atmosphere.Pressure;
314 }
315
316 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317 // Get the standard temperature at a specified altitude
318
319 double FGAtmosphere::GetTemperature(double altitude) {
320   GetStdAtmosphere(altitude);
321   return atmosphere.Temperature;
322 }
323
324 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 // Get the standard density at a specified altitude
326
327 double FGAtmosphere::GetDensity(double altitude) {
328   GetStdAtmosphere(altitude);
329   return atmosphere.Density;
330 }
331
332
333 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 // square a value, but preserve the original sign
335
336 static inline double square_signed (double value)
337 {
338     if (value < 0)
339         return value * value * -1;
340     else
341         return value * value;
342 }
343
344 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 //
346 // psi is the angle that the wind is blowing *towards*
347
348 void FGAtmosphere::SetWindspeed(double speed)
349 {
350   if (vWindNED.Magnitude() == 0.0) {
351     psiw = 0.0;
352     vWindNED(eNorth) = speed;
353   } else {
354     vWindNED(eNorth) = speed * cos(psiw);
355     vWindNED(eEast) = speed * sin(psiw);
356     vWindNED(eDown) = 0.0;
357   }
358 }
359
360 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361
362 double FGAtmosphere::GetWindspeed(void) const
363 {
364   return vWindNED.Magnitude();
365 }
366
367 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
368 //
369 // psi is the angle that the wind is blowing *towards*
370
371 void FGAtmosphere::SetWindPsi(double dir)
372 {
373   double mag = GetWindspeed();
374   psiw = dir;
375   SetWindspeed(mag);  
376 }
377
378 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379
380 void FGAtmosphere::Turbulence(void)
381 {
382   double DeltaT = rate*State->Getdt();
383
384   switch (turbType) {
385   case ttStandard: {
386     // TurbGain = TurbGain * TurbGain * 100.0; // what is this!?
387
388     vDirectiondAccelDt(eX) = 1 - 2.0*(double(rand())/double(RAND_MAX));
389     vDirectiondAccelDt(eY) = 1 - 2.0*(double(rand())/double(RAND_MAX));
390     vDirectiondAccelDt(eZ) = 1 - 2.0*(double(rand())/double(RAND_MAX));
391
392     MagnitudedAccelDt = 1 - 2.0*(double(rand())/double(RAND_MAX)) - Magnitude;
393                                 // Scale the magnitude so that it moves
394                                 // away from the peaks
395     MagnitudedAccelDt = ((MagnitudedAccelDt - Magnitude) /
396                          (1 + fabs(Magnitude)));
397     MagnitudeAccel    += MagnitudedAccelDt*TurbRate*DeltaT;
398     Magnitude         += MagnitudeAccel*DeltaT;
399     Magnitude          = fabs(Magnitude);
400
401     vDirectiondAccelDt.Normalize();
402
403                                 // deemphasise non-vertical forces
404     vDirectiondAccelDt(eX) = square_signed(vDirectiondAccelDt(eX));
405     vDirectiondAccelDt(eY) = square_signed(vDirectiondAccelDt(eY));
406
407     vDirectionAccel += vDirectiondAccelDt*TurbRate*DeltaT;
408     vDirectionAccel.Normalize();
409     vDirection      += vDirectionAccel*DeltaT;
410
411     vDirection.Normalize();
412
413                                 // Diminish turbulence within three wingspans
414                                 // of the ground
415     vTurbulenceNED = TurbGain * Magnitude * vDirection;
416     double HOverBMAC = Auxiliary->GetHOverBMAC();
417     if (HOverBMAC < 3.0)
418         vTurbulenceNED *= (HOverBMAC / 3.0) * (HOverBMAC / 3.0);
419
420     // I don't believe these next two statements calculate the proper gradient over
421     // the aircraft body. One reason is because this has no relationship with the
422     // orientation or velocity of the aircraft, which it must have. What is vTurbulenceGrad
423     // supposed to represent? And the direction and magnitude of the turbulence can change,
424     // so both accelerations need to be accounted for, no?
425
426     // Need to determine the turbulence change in body axes between two time points.
427
428     vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection;
429     vBodyTurbGrad = Propagate->GetTl2b()*vTurbulenceGrad;
430
431     if (Aircraft->GetWingSpan() > 0) {
432       vTurbPQR(eP) = vBodyTurbGrad(eY)/Aircraft->GetWingSpan();
433     } else {
434       vTurbPQR(eP) = vBodyTurbGrad(eY)/30.0;
435     }
436 //     if (Aircraft->GetHTailArm() != 0.0)
437 //       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/Aircraft->GetHTailArm();
438 //     else
439 //       vTurbPQR(eQ) = vBodyTurbGrad(eZ)/10.0;
440
441     if (Aircraft->GetVTailArm() > 0)
442       vTurbPQR(eR) = vBodyTurbGrad(eX)/Aircraft->GetVTailArm();
443     else
444       vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0;
445
446                                 // Clear the horizontal forces
447                                 // actually felt by the plane, now
448                                 // that we've used them to calculate
449                                 // moments.
450                                 // Why? (JSB)
451 //    vTurbulenceNED(eX) = 0.0;
452 //    vTurbulenceNED(eY) = 0.0;
453
454     break;
455   }
456   case ttBerndt: { // This is very experimental and incomplete at the moment.
457
458     vDirectiondAccelDt(eX) = GaussianRandomNumber();
459     vDirectiondAccelDt(eY) = GaussianRandomNumber();
460     vDirectiondAccelDt(eZ) = GaussianRandomNumber();
461 /*
462     MagnitudedAccelDt = GaussianRandomNumber();
463     MagnitudeAccel    += MagnitudedAccelDt * DeltaT;
464     Magnitude         += MagnitudeAccel * DeltaT;
465 */
466     Magnitude         += GaussianRandomNumber() * DeltaT;
467
468     vDirectiondAccelDt.Normalize();
469     vDirectionAccel += TurbRate * vDirectiondAccelDt * DeltaT;
470     vDirectionAccel.Normalize();
471     vDirection      += vDirectionAccel*DeltaT;
472
473     // Diminish z-vector within two wingspans of the ground
474     double HOverBMAC = Auxiliary->GetHOverBMAC();
475     if (HOverBMAC < 2.0) vDirection(eZ) *= HOverBMAC / 2.0;
476
477     vDirection.Normalize();
478
479     vTurbulenceNED = TurbGain*Magnitude * vDirection;
480     vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection;
481
482     vBodyTurbGrad = Propagate->GetTl2b() * vTurbulenceGrad;
483     vTurbPQR(eP) = vBodyTurbGrad(eY) / Aircraft->GetWingSpan();
484     if (Aircraft->GetHTailArm() > 0)
485       vTurbPQR(eQ) = vBodyTurbGrad(eZ) / Aircraft->GetHTailArm();
486     else
487       vTurbPQR(eQ) = vBodyTurbGrad(eZ) / 10.0;
488
489     if (Aircraft->GetVTailArm() > 0)
490       vTurbPQR(eR) = vBodyTurbGrad(eX) / Aircraft->GetVTailArm();
491     else
492       vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0;
493
494     break;
495   }
496   case ttCulp: { 
497
498     vTurbPQR(eP) = wind_from_clockwise;
499     if (TurbGain == 0.0) return;
500   
501     // keep the inputs within allowable limts for this model
502     if (TurbGain < 0.0) TurbGain = 0.0;
503     if (TurbGain > 1.0) TurbGain = 1.0;
504     if (TurbRate < 0.0) TurbRate = 0.0;
505     if (TurbRate > 30.0) TurbRate = 30.0;
506     if (Rhythmicity < 0.0) Rhythmicity = 0.0;
507     if (Rhythmicity > 1.0) Rhythmicity = 1.0;
508
509     // generate a sine wave corresponding to turbulence rate in hertz
510     double time = FDMExec->GetSimTime();
511     double sinewave = sin( time * TurbRate * 6.283185307 );
512
513     double random = 0.0;
514     if (target_time == 0.0) {
515       strength = random = 1 - 2.0*(double(rand())/double(RAND_MAX));
516       target_time = time + 0.71 + (random * 0.5);
517     }
518     if (time > target_time) {
519       spike = 1.0;
520       target_time = 0.0;
521     }    
522
523     // max vertical wind speed in fps, corresponds to TurbGain = 1.0
524     double max_vs = 40;
525
526     vTurbulenceNED(1) = vTurbulenceNED(2) = vTurbulenceNED(3) = 0.0;
527     double delta = strength * max_vs * TurbGain * (1-Rhythmicity) * spike;
528
529     // Vertical component of turbulence.
530     vTurbulenceNED(3) = sinewave * max_vs * TurbGain * Rhythmicity;
531     vTurbulenceNED(3)+= delta;
532     double HOverBMAC = Auxiliary->GetHOverBMAC();
533     if (HOverBMAC < 3.0)
534         vTurbulenceNED(3) *= HOverBMAC * 0.3333;
535  
536     // Yaw component of turbulence.
537     vTurbulenceNED(1) = sin( delta * 3.0 );
538     vTurbulenceNED(2) = cos( delta * 3.0 );
539
540     // Roll component of turbulence. Clockwise vortex causes left roll.
541     vTurbPQR(eP) += delta * 0.04;
542
543     spike = spike * 0.9;
544     break;
545   }
546   default:
547     break;
548   }
549 }
550
551 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
552
553 void FGAtmosphere::UseExternal(void)
554 {
555   temperature=&exTemperature;
556   pressure=&exPressure;
557   density=&exDensity;
558   useExternal=true;
559 }
560
561 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
562
563 void FGAtmosphere::UseInternal(void)
564 {
565   temperature=&intTemperature;
566   pressure=&intPressure;
567   density=&intDensity;
568   useExternal=false;
569 }
570
571 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
572
573 void FGAtmosphere::bind(void)
574 {
575   typedef double (FGAtmosphere::*PMF)(int) const;
576   typedef double (FGAtmosphere::*PMFv)(void) const;
577   typedef int (FGAtmosphere::*PMFt)(void) const;
578   typedef void   (FGAtmosphere::*PMFd)(int,double);
579   typedef void   (FGAtmosphere::*PMFi)(int);
580   PropertyManager->Tie("atmosphere/T-R", this, (PMFv)&FGAtmosphere::GetTemperature);
581   PropertyManager->Tie("atmosphere/rho-slugs_ft3", this, (PMFv)&FGAtmosphere::GetDensity);
582   PropertyManager->Tie("atmosphere/P-psf", this, (PMFv)&FGAtmosphere::GetPressure);
583   PropertyManager->Tie("atmosphere/a-fps", this, &FGAtmosphere::GetSoundSpeed);
584   PropertyManager->Tie("atmosphere/T-sl-R", this, &FGAtmosphere::GetTemperatureSL);
585   PropertyManager->Tie("atmosphere/rho-sl-slugs_ft3", this, &FGAtmosphere::GetDensitySL);
586   PropertyManager->Tie("atmosphere/P-sl-psf", this, &FGAtmosphere::GetPressureSL);
587   PropertyManager->Tie("atmosphere/a-sl-fps", this, &FGAtmosphere::GetSoundSpeedSL);
588   PropertyManager->Tie("atmosphere/theta", this, &FGAtmosphere::GetTemperatureRatio);
589   PropertyManager->Tie("atmosphere/sigma", this, &FGAtmosphere::GetDensityRatio);
590   PropertyManager->Tie("atmosphere/delta", this, &FGAtmosphere::GetPressureRatio);
591   PropertyManager->Tie("atmosphere/a-ratio", this, &FGAtmosphere::GetSoundSpeedRatio);
592   PropertyManager->Tie("atmosphere/psiw-rad", this, &FGAtmosphere::GetWindPsi, &FGAtmosphere::SetWindPsi);
593   PropertyManager->Tie("atmosphere/delta-T", this, &FGAtmosphere::GetDeltaT, &FGAtmosphere::SetDeltaT);
594   PropertyManager->Tie("atmosphere/T-sl-dev-F", this, &FGAtmosphere::GetSLTempDev, &FGAtmosphere::SetSLTempDev);
595   PropertyManager->Tie("atmosphere/density-altitude", this, &FGAtmosphere::GetDensityAltitude);
596
597   PropertyManager->Tie("atmosphere/wind-north-fps", this, eNorth, (PMF)&FGAtmosphere::GetWindNED,
598                                                           (PMFd)&FGAtmosphere::SetWindNED);
599   PropertyManager->Tie("atmosphere/wind-east-fps",  this, eEast, (PMF)&FGAtmosphere::GetWindNED,
600                                                           (PMFd)&FGAtmosphere::SetWindNED);
601   PropertyManager->Tie("atmosphere/wind-down-fps",  this, eDown, (PMF)&FGAtmosphere::GetWindNED,
602                                                           (PMFd)&FGAtmosphere::SetWindNED);
603   PropertyManager->Tie("atmosphere/wind-mag-fps", this, &FGAtmosphere::GetWindspeed,
604                                                         &FGAtmosphere::SetWindspeed);
605   PropertyManager->Tie("atmosphere/total-wind-north-fps", this, eNorth, (PMF)&FGAtmosphere::GetTotalWindNED);
606   PropertyManager->Tie("atmosphere/total-wind-east-fps",  this, eEast,  (PMF)&FGAtmosphere::GetTotalWindNED);
607   PropertyManager->Tie("atmosphere/total-wind-down-fps",  this, eDown,  (PMF)&FGAtmosphere::GetTotalWindNED);
608
609   PropertyManager->Tie("atmosphere/gust-north-fps", this, eNorth, (PMF)&FGAtmosphere::GetGustNED,
610                                                           (PMFd)&FGAtmosphere::SetGustNED);
611   PropertyManager->Tie("atmosphere/gust-east-fps",  this, eEast, (PMF)&FGAtmosphere::GetGustNED,
612                                                           (PMFd)&FGAtmosphere::SetGustNED);
613   PropertyManager->Tie("atmosphere/gust-down-fps",  this, eDown, (PMF)&FGAtmosphere::GetGustNED,
614                                                           (PMFd)&FGAtmosphere::SetGustNED);
615
616   PropertyManager->Tie("atmosphere/turb-north-fps", this, eNorth, (PMF)&FGAtmosphere::GetTurbNED,
617                                                           (PMFd)&FGAtmosphere::SetTurbNED);
618   PropertyManager->Tie("atmosphere/turb-east-fps",  this, eEast, (PMF)&FGAtmosphere::GetTurbNED,
619                                                           (PMFd)&FGAtmosphere::SetTurbNED);
620   PropertyManager->Tie("atmosphere/turb-down-fps",  this, eDown, (PMF)&FGAtmosphere::GetTurbNED,
621                                                           (PMFd)&FGAtmosphere::SetTurbNED);
622
623   PropertyManager->Tie("atmosphere/p-turb-rad_sec", this,1, (PMF)&FGAtmosphere::GetTurbPQR);
624   PropertyManager->Tie("atmosphere/q-turb-rad_sec", this,2, (PMF)&FGAtmosphere::GetTurbPQR);
625   PropertyManager->Tie("atmosphere/r-turb-rad_sec", this,3, (PMF)&FGAtmosphere::GetTurbPQR);
626   PropertyManager->Tie("atmosphere/turb-type", this, (PMFt)&FGAtmosphere::GetTurbType, (PMFi)&FGAtmosphere::SetTurbType);
627   PropertyManager->Tie("atmosphere/turb-rate", this, &FGAtmosphere::GetTurbRate, &FGAtmosphere::SetTurbRate);
628   PropertyManager->Tie("atmosphere/turb-gain", this, &FGAtmosphere::GetTurbGain, &FGAtmosphere::SetTurbGain);
629   PropertyManager->Tie("atmosphere/turb-rhythmicity", this, &FGAtmosphere::GetRhythmicity,
630                                                             &FGAtmosphere::SetRhythmicity);
631 }
632
633 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634 //    The bitmasked value choices are as follows:
635 //    unset: In this case (the default) JSBSim would only print
636 //       out the normally expected messages, essentially echoing
637 //       the config files as they are read. If the environment
638 //       variable is not set, debug_lvl is set to 1 internally
639 //    0: This requests JSBSim not to output any messages
640 //       whatsoever.
641 //    1: This value explicity requests the normal JSBSim
642 //       startup messages
643 //    2: This value asks for a message to be printed out when
644 //       a class is instantiated
645 //    4: When this value is set, a message is displayed when a
646 //       FGModel object executes its Run() method
647 //    8: When this value is set, various runtime state variables
648 //       are printed out periodically
649 //    16: When set various parameters are sanity checked and
650 //       a message is printed out when they go out of bounds
651
652 void FGAtmosphere::Debug(int from)
653 {
654   if (debug_lvl <= 0) return;
655
656   if (debug_lvl & 1) { // Standard console startup message output
657     if (from == 0) { // Constructor
658     }
659   }
660   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
661     if (from == 0) cout << "Instantiated: FGAtmosphere" << endl;
662     if (from == 1) cout << "Destroyed:    FGAtmosphere" << endl;
663   }
664   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
665   }
666   if (debug_lvl & 8 ) { // Runtime state variables
667   }
668   if (debug_lvl & 16) { // Sanity checking
669   }
670   if (debug_lvl & 128) { // Turbulence
671     if (first_pass && from == 2) {
672       first_pass = false;
673       cout << "vTurbulenceNED(X), vTurbulenceNED(Y), vTurbulenceNED(Z), "
674            << "vTurbulenceGrad(X), vTurbulenceGrad(Y), vTurbulenceGrad(Z), "
675            << "vDirection(X), vDirection(Y), vDirection(Z), "
676            << "Magnitude, "
677            << "vTurbPQR(P), vTurbPQR(Q), vTurbPQR(R), " << endl;
678     } 
679     if (from == 2) {
680       cout << vTurbulenceNED << ", " << vTurbulenceGrad << ", " << vDirection << ", " << Magnitude << ", " << vTurbPQR << endl;
681     }
682   }
683   if (debug_lvl & 64) {
684     if (from == 0) { // Constructor
685       cout << IdSrc << endl;
686       cout << IdHdr << endl;
687     }
688   }
689 }
690
691 } // namespace JSBSim