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