X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2Fmodels%2FFGAtmosphere.cpp;h=7113fc3ca45df8d7d6a1c6043c597bc1b1fa4f0c;hb=642735ab18421db87a07d6841dd720fd4615bfff;hp=2db1c65d931a312ef3db0bf1891722f11231422f;hpb=63b3f802ec9412b47c089d7c82f740a6c41f3e3e;p=flightgear.git diff --git a/src/FDM/JSBSim/models/FGAtmosphere.cpp b/src/FDM/JSBSim/models/FGAtmosphere.cpp index 2db1c65d9..7113fc3ca 100644 --- a/src/FDM/JSBSim/models/FGAtmosphere.cpp +++ b/src/FDM/JSBSim/models/FGAtmosphere.cpp @@ -1,13 +1,12 @@ /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Module: FGAtmosphere.cpp - Author: Jon Berndt - Implementation of 1959 Standard Atmosphere added by Tony Peden - Date started: 11/24/98 - Purpose: Models the atmosphere - Called by: FGSimExec + Author: Jon Berndt, Tony Peden + Date started: 6/2011 + Purpose: Models an atmosphere interface class + Called by: FGFDMExec - ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) ------------- + ------------- Copyright (C) 2011 Jon S. Berndt (jon@jsbsim.org) ------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -28,77 +27,43 @@ FUNCTIONAL DESCRIPTION -------------------------------------------------------------------------------- -Models the atmosphere. The equation used below was determined by a third order -curve fit using Excel. The data is from the ICAO atmosphere model. +This models a base atmosphere class to serve as a common interface to any derived +atmosphere models. HISTORY -------------------------------------------------------------------------------- -11/24/98 JSB Created -07/23/99 TP Added implementation of 1959 Standard Atmosphere - Moved calculation of Mach number to FGPropagate - Later updated to '76 model +6/18/2011 Started Jon S. Berndt + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% COMMENTS, REFERENCES, and NOTES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -[1] Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill, - 1989, ISBN 0-07-001641-0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include "FGAtmosphere.h" -#include "FGAircraft.h" -#include "FGPropagate.h" -#include "FGInertial.h" -#include "FGAuxiliary.h" -#include "FGFDMExec.h" -#include "input_output/FGPropertyManager.h" #include +#include #include - -using namespace std; +#include "FGFDMExec.h" +#include "FGAtmosphere.h" namespace JSBSim { -static const char *IdSrc = "$Id: FGAtmosphere.cpp,v 1.35 2010/08/11 11:51:33 jberndt Exp $"; +static const char *IdSrc = "$Id: FGAtmosphere.cpp,v 1.51 2012/04/13 13:18:28 jberndt Exp $"; static const char *IdHdr = ID_ATMOSPHERE; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex) +FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex), + PressureAltitude(0.0), // ft + DensityAltitude(0.0), // ft + SutherlandConstant(198.72), // deg Rankine + Beta(2.269690E-08) // slug/(sec ft R^0.5) { Name = "FGAtmosphere"; - lastIndex = 0; - h = 0.0; - psiw = 0.0; - htab[0]=0; - htab[1]= 36089.0; - htab[2]= 65617.0; - htab[3]=104987.0; - htab[4]=154199.0; - htab[5]=167322.0; - htab[6]=232940.0; - htab[7]=278385.0; //ft. - - MagnitudedAccelDt = MagnitudeAccel = Magnitude = 0.0; -// SetTurbType( ttCulp ); - SetTurbType( ttNone ); - TurbGain = 1.0; - TurbRate = 10.0; - Rhythmicity = 0.1; - spike = target_time = strength = 0.0; - wind_from_clockwise = 0.0; - SutherlandConstant = 198.72; // deg Rankine - Beta = 2.269690E-08; // slug/(sec ft R^0.5) - - T_dev_sl = T_dev = delta_T = 0.0; - StandardTempOnly = false; - first_pass = true; - vGustNED.InitMatrix(); - vTurbulenceNED.InitMatrix(); bind(); Debug(0); @@ -115,525 +80,149 @@ FGAtmosphere::~FGAtmosphere() bool FGAtmosphere::InitModel(void) { - if (!FGModel::InitModel()) return false; + Calculate(0.0); + SLtemperature = Temperature = 518.67; + SLpressure = Pressure = 2116.22; + SLdensity = Density = Pressure/(Reng*Temperature); + SLsoundspeed = Soundspeed = sqrt(SHRatio*Reng*(Temperature)); - UseInternal(); // this is the default - - Calculate(h); - StdSLtemperature = SLtemperature = 518.67; - StdSLpressure = SLpressure = 2116.22; - StdSLdensity = SLdensity = 0.00237767; - StdSLsoundspeed = SLsoundspeed = sqrt(SHRatio*Reng*StdSLtemperature); - rSLtemperature = 1.0/StdSLtemperature; - rSLpressure = 1.0/StdSLpressure; - rSLdensity = 1.0/StdSLdensity; - rSLsoundspeed = 1.0/StdSLsoundspeed; + rSLtemperature = 1/SLtemperature ; + rSLpressure = 1/SLpressure ; + rSLdensity = 1/SLdensity ; + rSLsoundspeed = 1/SLsoundspeed ; return true; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGAtmosphere::Run(void) +bool FGAtmosphere::Run(bool Holding) { - if (FGModel::Run()) return true; - if (FDMExec->Holding()) return false; - - RunPreFunctions(); - - T_dev = 0.0; - h = Propagate->GetAltitudeASL(); - - if (!useExternal) { - Calculate(h); - CalculateDerived(); - } else { - CalculateDerived(); - } + if (FGModel::Run(Holding)) return true; + if (Holding) return false; - RunPostFunctions(); + Calculate(in.altitudeASL); Debug(2); return false; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// See reference 1 void FGAtmosphere::Calculate(double altitude) { - double slope, reftemp, refpress; - int i = lastIndex; - - if (altitude < htab[lastIndex]) { - if (altitude <= 0) { - i = 0; - altitude=0; - } else { - i = lastIndex-1; - while (htab[i] > altitude) i--; - } - } else if (altitude > htab[lastIndex+1]) { - if (altitude >= htab[7]) { - i = 7; - altitude = htab[7]; - } else { - i = lastIndex+1; - while (htab[i+1] < altitude) i++; - } - } - - switch(i) { - case 0: // Sea level - slope = -0.00356616; // R/ft. - reftemp = 518.67; // in degrees Rankine, 288.15 Kelvin - refpress = 2116.22; // psf - //refdens = 0.00237767; // slugs/cubic ft. - break; - case 1: // 36089 ft. or 11 km - slope = 0; - reftemp = 389.97; // in degrees Rankine, 216.65 Kelvin - refpress = 472.763; - //refdens = 0.000706032; - break; - case 2: // 65616 ft. or 20 km - slope = 0.00054864; - reftemp = 389.97; // in degrees Rankine, 216.65 Kelvin - refpress = 114.636; - //refdens = 0.000171306; - break; - case 3: // 104986 ft. or 32 km - slope = 0.001536192; - reftemp = 411.57; // in degrees Rankine, 228.65 Kelvin - refpress = 18.128; - //refdens = 1.18422e-05; - break; - case 4: // 154199 ft. 47 km - slope = 0; - reftemp = 487.17; // in degrees Rankine, 270.65 Kelvin - refpress = 2.316; - //refdens = 4.00585e-7; - break; - case 5: // 167322 ft. or 51 km - slope = -0.001536192; - reftemp = 487.17; // in degrees Rankine, 270.65 Kelvin - refpress = 1.398; - //refdens = 8.17102e-7; - break; - case 6: // 232940 ft. or 71 km - slope = -0.00109728; - reftemp = 386.368; // in degrees Rankine, 214.649 Kelvin - refpress = 0.0826; - //refdens = 8.77702e-9; - break; - case 7: // 278385 ft. or 84.8520 km - slope = 0; - reftemp = 336.5; // in degrees Rankine, 186.94 Kelvin - refpress = 0.00831; - //refdens = 2.19541e-10; - break; - default: // sea level - slope = -0.00356616; // R/ft. - reftemp = 518.67; // in degrees Rankine, 288.15 Kelvin - refpress = 2116.22; // psf - //refdens = 0.00237767; // slugs/cubic ft. - break; - - } - - // If delta_T is set, then that is our temperature deviation at any altitude. - // If not, then we'll estimate a deviation based on the sea level deviation (if set). - - if(!StandardTempOnly) { - T_dev = 0.0; - if (delta_T != 0.0) { - T_dev = delta_T; - } else { - if ((altitude < 36089.239) && (T_dev_sl != 0.0)) { - T_dev = T_dev_sl * ( 1.0 - (altitude/36089.239)); - } - } - reftemp+=T_dev; - } - - if (slope == 0) { - intTemperature = reftemp; - intPressure = refpress*exp(-Inertial->SLgravity()/(reftemp*Reng)*(altitude-htab[i])); - intDensity = intPressure/(Reng*intTemperature); - } else { - intTemperature = reftemp+slope*(altitude-htab[i]); - intPressure = refpress*pow(intTemperature/reftemp,-Inertial->SLgravity()/(slope*Reng)); - intDensity = intPressure/(Reng*intTemperature); - } - - lastIndex=i; + Temperature = GetTemperature(altitude); + Pressure = GetPressure(altitude); + Density = Pressure/(Reng*Temperature); + Soundspeed = sqrt(SHRatio*Reng*(Temperature)); + PressureAltitude = altitude; + DensityAltitude = altitude; + + Viscosity = Beta * pow(Temperature, 1.5) / (SutherlandConstant + Temperature); + KinematicViscosity = Viscosity / Density; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// Calculate parameters derived from T, P and rho -// Sum gust and turbulence values in NED frame into the wind vector. -void FGAtmosphere::CalculateDerived(void) +void FGAtmosphere::SetPressureSL(ePressure unit, double pressure) { - T_dev = (*temperature) - GetTemperature(h); - - if (T_dev == 0.0) density_altitude = h; - else density_altitude = 518.4/0.00357 * (1.0 - pow(GetDensityRatio(),0.235)); + double press = ConvertToPSF(pressure, unit); - if (turbType != ttNone) Turbulence(); - - vTotalWindNED = vWindNED + vGustNED + vTurbulenceNED; - - // psiw (Wind heading) is the direction the wind is blowing towards - if (vWindNED(eX) != 0.0) psiw = atan2( vWindNED(eY), vWindNED(eX) ); - if (psiw < 0) psiw += 2*M_PI; - - soundspeed = sqrt(SHRatio*Reng*(*temperature)); - - intViscosity = Beta * pow(intTemperature, 1.5) / (SutherlandConstant + intTemperature); - intKinematicViscosity = intViscosity / intDensity; -} - - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// Get the standard atmospheric properties at a specified altitude - -void FGAtmosphere::GetStdAtmosphere(double altitude) { - StandardTempOnly = true; - Calculate(altitude); - StandardTempOnly = false; - atmosphere.Temperature = intTemperature; - atmosphere.Pressure = intPressure; - atmosphere.Density = intDensity; - - // Reset the internal atmospheric state - Calculate(h); + SLpressure = press; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// Get the standard pressure at a specified altitude - -double FGAtmosphere::GetPressure(double altitude) { - GetStdAtmosphere(altitude); - return atmosphere.Pressure; -} +// Get the modeled density at a specified altitude -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// Get the standard temperature at a specified altitude - -double FGAtmosphere::GetTemperature(double altitude) { - GetStdAtmosphere(altitude); - return atmosphere.Temperature; -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// Get the standard density at a specified altitude - -double FGAtmosphere::GetDensity(double altitude) { - GetStdAtmosphere(altitude); - return atmosphere.Density; -} - - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// square a value, but preserve the original sign - -static inline double square_signed (double value) +double FGAtmosphere::GetDensity(double altitude) const { - if (value < 0) - return value * value * -1; - else - return value * value; + return GetPressure(altitude)/(Reng * GetTemperature(altitude)); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// psi is the angle that the wind is blowing *towards* +// This function sets the sea level temperature. +// Internally, the Rankine scale is used for calculations, so any temperature +// supplied must be converted to that unit. -void FGAtmosphere::SetWindspeed(double speed) +void FGAtmosphere::SetTemperatureSL(double t, eTemperature unit) { - if (vWindNED.Magnitude() == 0.0) { - psiw = 0.0; - vWindNED(eNorth) = speed; - } else { - vWindNED(eNorth) = speed * cos(psiw); - vWindNED(eEast) = speed * sin(psiw); - vWindNED(eDown) = 0.0; - } -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -double FGAtmosphere::GetWindspeed(void) const -{ - return vWindNED.Magnitude(); + SLtemperature = ConvertToRankine(t, unit); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -// -// psi is the angle that the wind is blowing *towards* -void FGAtmosphere::SetWindPsi(double dir) +double FGAtmosphere::ConvertToRankine(double t, eTemperature unit) const { - double mag = GetWindspeed(); - psiw = dir; - SetWindspeed(mag); -} - -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -void FGAtmosphere::Turbulence(void) -{ - double DeltaT = rate*FDMExec->GetDeltaT(); - - switch (turbType) { - case ttStandard: { - // TurbGain = TurbGain * TurbGain * 100.0; // what is this!? - - vDirectiondAccelDt(eX) = 1 - 2.0*(double(rand())/double(RAND_MAX)); - vDirectiondAccelDt(eY) = 1 - 2.0*(double(rand())/double(RAND_MAX)); - vDirectiondAccelDt(eZ) = 1 - 2.0*(double(rand())/double(RAND_MAX)); - - MagnitudedAccelDt = 1 - 2.0*(double(rand())/double(RAND_MAX)) - Magnitude; - // Scale the magnitude so that it moves - // away from the peaks - MagnitudedAccelDt = ((MagnitudedAccelDt - Magnitude) / - (1 + fabs(Magnitude))); - MagnitudeAccel += MagnitudedAccelDt*TurbRate*DeltaT; - Magnitude += MagnitudeAccel*DeltaT; - Magnitude = fabs(Magnitude); - - vDirectiondAccelDt.Normalize(); - - // deemphasise non-vertical forces - vDirectiondAccelDt(eX) = square_signed(vDirectiondAccelDt(eX)); - vDirectiondAccelDt(eY) = square_signed(vDirectiondAccelDt(eY)); - - vDirectionAccel += vDirectiondAccelDt*TurbRate*DeltaT; - vDirectionAccel.Normalize(); - vDirection += vDirectionAccel*DeltaT; - - vDirection.Normalize(); - - // Diminish turbulence within three wingspans - // of the ground - vTurbulenceNED = TurbGain * Magnitude * vDirection; - double HOverBMAC = Auxiliary->GetHOverBMAC(); - if (HOverBMAC < 3.0) - vTurbulenceNED *= (HOverBMAC / 3.0) * (HOverBMAC / 3.0); - - // I don't believe these next two statements calculate the proper gradient over - // the aircraft body. One reason is because this has no relationship with the - // orientation or velocity of the aircraft, which it must have. What is vTurbulenceGrad - // supposed to represent? And the direction and magnitude of the turbulence can change, - // so both accelerations need to be accounted for, no? - - // Need to determine the turbulence change in body axes between two time points. - - vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection; - vBodyTurbGrad = Propagate->GetTl2b()*vTurbulenceGrad; - - if (Aircraft->GetWingSpan() > 0) { - vTurbPQR(eP) = vBodyTurbGrad(eY)/Aircraft->GetWingSpan(); - } else { - vTurbPQR(eP) = vBodyTurbGrad(eY)/30.0; - } -// if (Aircraft->GetHTailArm() != 0.0) -// vTurbPQR(eQ) = vBodyTurbGrad(eZ)/Aircraft->GetHTailArm(); -// else -// vTurbPQR(eQ) = vBodyTurbGrad(eZ)/10.0; - - if (Aircraft->GetVTailArm() > 0) - vTurbPQR(eR) = vBodyTurbGrad(eX)/Aircraft->GetVTailArm(); - else - vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0; - - // Clear the horizontal forces - // actually felt by the plane, now - // that we've used them to calculate - // moments. - // Why? (JSB) -// vTurbulenceNED(eX) = 0.0; -// vTurbulenceNED(eY) = 0.0; + double targetTemp=0; // in degrees Rankine + switch(unit) { + case eFahrenheit: + targetTemp = t + 459.67; break; - } - case ttBerndt: { // This is very experimental and incomplete at the moment. - - vDirectiondAccelDt(eX) = GaussianRandomNumber(); - vDirectiondAccelDt(eY) = GaussianRandomNumber(); - vDirectiondAccelDt(eZ) = GaussianRandomNumber(); -/* - MagnitudedAccelDt = GaussianRandomNumber(); - MagnitudeAccel += MagnitudedAccelDt * DeltaT; - Magnitude += MagnitudeAccel * DeltaT; -*/ - Magnitude += GaussianRandomNumber() * DeltaT; - - vDirectiondAccelDt.Normalize(); - vDirectionAccel += TurbRate * vDirectiondAccelDt * DeltaT; - vDirectionAccel.Normalize(); - vDirection += vDirectionAccel*DeltaT; - - // Diminish z-vector within two wingspans of the ground - double HOverBMAC = Auxiliary->GetHOverBMAC(); - if (HOverBMAC < 2.0) vDirection(eZ) *= HOverBMAC / 2.0; - - vDirection.Normalize(); - - vTurbulenceNED = TurbGain*Magnitude * vDirection; - vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection; - - vBodyTurbGrad = Propagate->GetTl2b() * vTurbulenceGrad; - vTurbPQR(eP) = vBodyTurbGrad(eY) / Aircraft->GetWingSpan(); - if (Aircraft->GetHTailArm() > 0) - vTurbPQR(eQ) = vBodyTurbGrad(eZ) / Aircraft->GetHTailArm(); - else - vTurbPQR(eQ) = vBodyTurbGrad(eZ) / 10.0; - - if (Aircraft->GetVTailArm() > 0) - vTurbPQR(eR) = vBodyTurbGrad(eX) / Aircraft->GetVTailArm(); - else - vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0; - + case eCelsius: + targetTemp = t*9.0/5.0 + 32.0 + 459.67; break; - } - case ttCulp: { - - vTurbPQR(eP) = wind_from_clockwise; - if (TurbGain == 0.0) return; - - // keep the inputs within allowable limts for this model - if (TurbGain < 0.0) TurbGain = 0.0; - if (TurbGain > 1.0) TurbGain = 1.0; - if (TurbRate < 0.0) TurbRate = 0.0; - if (TurbRate > 30.0) TurbRate = 30.0; - if (Rhythmicity < 0.0) Rhythmicity = 0.0; - if (Rhythmicity > 1.0) Rhythmicity = 1.0; - - // generate a sine wave corresponding to turbulence rate in hertz - double time = FDMExec->GetSimTime(); - double sinewave = sin( time * TurbRate * 6.283185307 ); - - double random = 0.0; - if (target_time == 0.0) { - strength = random = 1 - 2.0*(double(rand())/double(RAND_MAX)); - target_time = time + 0.71 + (random * 0.5); - } - if (time > target_time) { - spike = 1.0; - target_time = 0.0; - } - - // max vertical wind speed in fps, corresponds to TurbGain = 1.0 - double max_vs = 40; - - vTurbulenceNED(1) = vTurbulenceNED(2) = vTurbulenceNED(3) = 0.0; - double delta = strength * max_vs * TurbGain * (1-Rhythmicity) * spike; - - // Vertical component of turbulence. - vTurbulenceNED(3) = sinewave * max_vs * TurbGain * Rhythmicity; - vTurbulenceNED(3)+= delta; - double HOverBMAC = Auxiliary->GetHOverBMAC(); - if (HOverBMAC < 3.0) - vTurbulenceNED(3) *= HOverBMAC * 0.3333; - - // Yaw component of turbulence. - vTurbulenceNED(1) = sin( delta * 3.0 ); - vTurbulenceNED(2) = cos( delta * 3.0 ); - - // Roll component of turbulence. Clockwise vortex causes left roll. - vTurbPQR(eP) += delta * 0.04; - - spike = spike * 0.9; + case eRankine: + targetTemp = t; + break; + case eKelvin: + targetTemp = t*9.0/5.0; break; - } default: break; } + + return targetTemp; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGAtmosphere::UseExternal(void) +double FGAtmosphere::ConvertToPSF(double p, ePressure unit) const { - temperature=&exTemperature; - pressure=&exPressure; - density=&exDensity; - useExternal=true; -} + double targetPressure=0; // Pressure in PSF -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + switch(unit) { + case ePSF: + targetPressure = p; + break; + case eMillibars: + targetPressure = p*2.08854342; + break; + case ePascals: + targetPressure = p*0.0208854342; + break; + case eInchesHg: + targetPressure = p*70.7180803; + break; + default: + throw("Undefined pressure unit given"); + } -void FGAtmosphere::UseInternal(void) -{ - temperature=&intTemperature; - pressure=&intPressure; - density=&intDensity; - useExternal=false; + return targetPressure; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGAtmosphere::bind(void) { - typedef double (FGAtmosphere::*PMF)(int) const; - typedef double (FGAtmosphere::*PMFv)(void) const; - typedef int (FGAtmosphere::*PMFt)(void) const; - typedef void (FGAtmosphere::*PMFd)(int,double); - typedef void (FGAtmosphere::*PMFi)(int); - PropertyManager->Tie("atmosphere/T-R", this, (PMFv)&FGAtmosphere::GetTemperature); - PropertyManager->Tie("atmosphere/rho-slugs_ft3", this, (PMFv)&FGAtmosphere::GetDensity); - PropertyManager->Tie("atmosphere/P-psf", this, (PMFv)&FGAtmosphere::GetPressure); + typedef double (FGAtmosphere::*PMFi)(int) const; + typedef void (FGAtmosphere::*PMF)(int, double); + PropertyManager->Tie("atmosphere/T-R", this, &FGAtmosphere::GetTemperature); + PropertyManager->Tie("atmosphere/rho-slugs_ft3", this, &FGAtmosphere::GetDensity); + PropertyManager->Tie("atmosphere/P-psf", this, &FGAtmosphere::GetPressure); PropertyManager->Tie("atmosphere/a-fps", this, &FGAtmosphere::GetSoundSpeed); PropertyManager->Tie("atmosphere/T-sl-R", this, &FGAtmosphere::GetTemperatureSL); PropertyManager->Tie("atmosphere/rho-sl-slugs_ft3", this, &FGAtmosphere::GetDensitySL); - PropertyManager->Tie("atmosphere/P-sl-psf", this, &FGAtmosphere::GetPressureSL); +// PropertyManager->Tie("atmosphere/P-sl-psf", this, ePSF, +// (PMFi)&FGAtmosphere::GetPressureSL, +// (PMF)&FGAtmosphere::SetPressureSL); PropertyManager->Tie("atmosphere/a-sl-fps", this, &FGAtmosphere::GetSoundSpeedSL); PropertyManager->Tie("atmosphere/theta", this, &FGAtmosphere::GetTemperatureRatio); PropertyManager->Tie("atmosphere/sigma", this, &FGAtmosphere::GetDensityRatio); PropertyManager->Tie("atmosphere/delta", this, &FGAtmosphere::GetPressureRatio); PropertyManager->Tie("atmosphere/a-ratio", this, &FGAtmosphere::GetSoundSpeedRatio); - PropertyManager->Tie("atmosphere/psiw-rad", this, &FGAtmosphere::GetWindPsi, &FGAtmosphere::SetWindPsi); - PropertyManager->Tie("atmosphere/delta-T", this, &FGAtmosphere::GetDeltaT, &FGAtmosphere::SetDeltaT); - PropertyManager->Tie("atmosphere/T-sl-dev-F", this, &FGAtmosphere::GetSLTempDev, &FGAtmosphere::SetSLTempDev); PropertyManager->Tie("atmosphere/density-altitude", this, &FGAtmosphere::GetDensityAltitude); - - PropertyManager->Tie("atmosphere/wind-north-fps", this, eNorth, (PMF)&FGAtmosphere::GetWindNED, - (PMFd)&FGAtmosphere::SetWindNED); - PropertyManager->Tie("atmosphere/wind-east-fps", this, eEast, (PMF)&FGAtmosphere::GetWindNED, - (PMFd)&FGAtmosphere::SetWindNED); - PropertyManager->Tie("atmosphere/wind-down-fps", this, eDown, (PMF)&FGAtmosphere::GetWindNED, - (PMFd)&FGAtmosphere::SetWindNED); - PropertyManager->Tie("atmosphere/wind-mag-fps", this, &FGAtmosphere::GetWindspeed, - &FGAtmosphere::SetWindspeed); - PropertyManager->Tie("atmosphere/total-wind-north-fps", this, eNorth, (PMF)&FGAtmosphere::GetTotalWindNED); - PropertyManager->Tie("atmosphere/total-wind-east-fps", this, eEast, (PMF)&FGAtmosphere::GetTotalWindNED); - PropertyManager->Tie("atmosphere/total-wind-down-fps", this, eDown, (PMF)&FGAtmosphere::GetTotalWindNED); - - PropertyManager->Tie("atmosphere/gust-north-fps", this, eNorth, (PMF)&FGAtmosphere::GetGustNED, - (PMFd)&FGAtmosphere::SetGustNED); - PropertyManager->Tie("atmosphere/gust-east-fps", this, eEast, (PMF)&FGAtmosphere::GetGustNED, - (PMFd)&FGAtmosphere::SetGustNED); - PropertyManager->Tie("atmosphere/gust-down-fps", this, eDown, (PMF)&FGAtmosphere::GetGustNED, - (PMFd)&FGAtmosphere::SetGustNED); - - PropertyManager->Tie("atmosphere/turb-north-fps", this, eNorth, (PMF)&FGAtmosphere::GetTurbNED, - (PMFd)&FGAtmosphere::SetTurbNED); - PropertyManager->Tie("atmosphere/turb-east-fps", this, eEast, (PMF)&FGAtmosphere::GetTurbNED, - (PMFd)&FGAtmosphere::SetTurbNED); - PropertyManager->Tie("atmosphere/turb-down-fps", this, eDown, (PMF)&FGAtmosphere::GetTurbNED, - (PMFd)&FGAtmosphere::SetTurbNED); - - PropertyManager->Tie("atmosphere/p-turb-rad_sec", this,1, (PMF)&FGAtmosphere::GetTurbPQR); - PropertyManager->Tie("atmosphere/q-turb-rad_sec", this,2, (PMF)&FGAtmosphere::GetTurbPQR); - PropertyManager->Tie("atmosphere/r-turb-rad_sec", this,3, (PMF)&FGAtmosphere::GetTurbPQR); - PropertyManager->Tie("atmosphere/turb-type", this, (PMFt)&FGAtmosphere::GetTurbType, (PMFi)&FGAtmosphere::SetTurbType); - PropertyManager->Tie("atmosphere/turb-rate", this, &FGAtmosphere::GetTurbRate, &FGAtmosphere::SetTurbRate); - PropertyManager->Tie("atmosphere/turb-gain", this, &FGAtmosphere::GetTurbGain, &FGAtmosphere::SetTurbGain); - PropertyManager->Tie("atmosphere/turb-rhythmicity", this, &FGAtmosphere::GetRhythmicity, - &FGAtmosphere::SetRhythmicity); + PropertyManager->Tie("atmosphere/pressure-altitude", this, &FGAtmosphere::GetPressureAltitude); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -664,8 +253,8 @@ void FGAtmosphere::Debug(int from) } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGAtmosphere" << endl; - if (from == 1) cout << "Destroyed: FGAtmosphere" << endl; + if (from == 0) std::cout << "Instantiated: FGAtmosphere" << std::endl; + if (from == 1) std::cout << "Destroyed: FGAtmosphere" << std::endl; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } @@ -673,23 +262,12 @@ void FGAtmosphere::Debug(int from) } if (debug_lvl & 16) { // Sanity checking } - if (debug_lvl & 128) { // Turbulence - if (first_pass && from == 2) { - first_pass = false; - cout << "vTurbulenceNED(X), vTurbulenceNED(Y), vTurbulenceNED(Z), " - << "vTurbulenceGrad(X), vTurbulenceGrad(Y), vTurbulenceGrad(Z), " - << "vDirection(X), vDirection(Y), vDirection(Z), " - << "Magnitude, " - << "vTurbPQR(P), vTurbPQR(Q), vTurbPQR(R), " << endl; - } - if (from == 2) { - cout << vTurbulenceNED << ", " << vTurbulenceGrad << ", " << vDirection << ", " << Magnitude << ", " << vTurbPQR << endl; - } + if (debug_lvl & 128) { // } if (debug_lvl & 64) { if (from == 0) { // Constructor - cout << IdSrc << endl; - cout << IdHdr << endl; + std::cout << IdSrc << std::endl; + std::cout << IdHdr << std::endl; } } }