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