Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not make direct calls to FGAtmosphere #885

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/FGFDMExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,10 @@ void FGFDMExec::LoadInputs(unsigned int idx)
Inertial->in.Position = Propagate->GetLocation();
break;
case eAtmosphere:
Atmosphere->in.altitudeASL = Propagate->GetAltitudeASL();
Atmosphere->in.altitudeASL = Propagate->GetAltitudeASL();
Atmosphere->in.vUVW = Propagate->GetUVW();
Atmosphere->in.TotalWindNED = Winds->GetTotalWindNED();
Atmosphere->in.Tl2b = Propagate->GetTl2b();
break;
case eWinds:
Winds->in.AltitudeASL = Propagate->GetAltitudeASL();
Expand All @@ -462,15 +465,11 @@ void FGFDMExec::LoadInputs(unsigned int idx)
Winds->in.totalDeltaT = dT * Winds->GetRate();
break;
case eAuxiliary:
Auxiliary->in.Pressure = Atmosphere->GetPressure();
Auxiliary->in.Density = Atmosphere->GetDensity();
Auxiliary->in.DensitySL = Atmosphere->GetDensitySL();
Auxiliary->in.PressureSL = Atmosphere->GetPressureSL();
Auxiliary->in.Temperature = Atmosphere->GetTemperature();
Auxiliary->in.SoundSpeed = Atmosphere->GetSoundSpeed();
Auxiliary->in.KinematicViscosity = Atmosphere->GetKinematicViscosity();
Auxiliary->in.DistanceAGL = Propagate->GetDistanceAGL();
Auxiliary->in.AltitudeASL = Propagate->GetAltitudeASL();
Auxiliary->in.Mass = MassBalance->GetMass();
Auxiliary->in.Tl2b = Propagate->GetTl2b();
Auxiliary->in.Tb2l = Propagate->GetTb2l();
Expand Down Expand Up @@ -503,11 +502,11 @@ void FGFDMExec::LoadInputs(unsigned int idx)
Propulsion->in.DensityRatio = Atmosphere->GetDensityRatio();
Propulsion->in.Density = Atmosphere->GetDensity();
Propulsion->in.Soundspeed = Atmosphere->GetSoundSpeed();
Propulsion->in.TotalPressure = Auxiliary->GetTotalPressure();
Propulsion->in.Vc = Auxiliary->GetVcalibratedKTS();
Propulsion->in.TotalPressure = Atmosphere->GetTotalPressure();
Propulsion->in.TAT_c = Atmosphere->GetTAT_C();
Propulsion->in.Vc = Atmosphere->GetVcalibratedKTS();
Propulsion->in.Vt = Auxiliary->GetVt();
Propulsion->in.qbar = Auxiliary->Getqbar();
Propulsion->in.TAT_c = Auxiliary->GetTAT_C();
Propulsion->in.AeroUVW = Auxiliary->GetAeroUVW();
Propulsion->in.AeroPQR = Auxiliary->GetAeroPQR();
Propulsion->in.alpha = Auxiliary->Getalpha();
Expand Down Expand Up @@ -535,7 +534,7 @@ void FGFDMExec::LoadInputs(unsigned int idx)
case eGroundReactions:
// There are no external inputs to this model.
GroundReactions->in.Vground = Auxiliary->GetVground();
GroundReactions->in.VcalibratedKts = Auxiliary->GetVcalibratedKTS();
GroundReactions->in.VcalibratedKts = Atmosphere->GetVcalibratedKTS();
GroundReactions->in.Temperature = Atmosphere->GetTemperature();
GroundReactions->in.TakeoffThrottle = (FCS->GetThrottlePos().size() > 0) ? (FCS->GetThrottlePos(0) > 0.90) : false;
GroundReactions->in.BrakePos = FCS->GetBrakePos();
Expand Down
3 changes: 2 additions & 1 deletion src/input_output/FGOutputFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ INCLUDES
#include "FGOutputFG.h"
#include "FGXMLElement.h"
#include "models/FGAuxiliary.h"
#include "models/FGAtmosphere.h"
#include "models/FGPropulsion.h"
#include "models/FGFCS.h"
#include "models/propulsion/FGPiston.h"
Expand Down Expand Up @@ -217,7 +218,7 @@ void FGOutputFG::SocketDataFill(void)
net1->phidot = (float)(Auxiliary->GetEulerRates(ePhi)); // roll rate (radians/sec)
net1->thetadot = (float)(Auxiliary->GetEulerRates(eTht)); // pitch rate (radians/sec)
net1->psidot = (float)(Auxiliary->GetEulerRates(ePsi)); // yaw rate (radians/sec)
net1->vcas = (float)(Auxiliary->GetVcalibratedKTS()); // VCAS, knots
net1->vcas = (float)(Atmosphere->GetVcalibratedKTS()); // VCAS, knots
net1->climb_rate = (float)(Propagate->Gethdot()); // altitude rate, ft/sec
net1->v_north = (float)(Propagate->GetVel(eNorth)); // north vel in NED frame, fps
net1->v_east = (float)(Propagate->GetVel(eEast)); // east vel in NED frame, fps
Expand Down
25 changes: 25 additions & 0 deletions src/models/FGAtmosphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex)
{
Name = "FGAtmosphere";

in.altitudeASL = 0.0;
in.Tl2b = { 1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0};
in.vUVW.InitMatrix();
in.TotalWindNED.InitMatrix();

bind();
Debug(0);
}
Expand All @@ -78,6 +85,9 @@ bool FGAtmosphere::InitModel(void)
SLpressure = Pressure = StdDaySLpressure;
SLdensity = Density = Pressure/(Reng*Temperature);
SLsoundspeed = Soundspeed = StdDaySLsoundspeed;
vcas = 0.0;
TotalPressure = StdDaySLpressure;
TotalTemperature = StdDaySLtemperature;
Calculate(0.0);

return true;
Expand All @@ -87,11 +97,21 @@ bool FGAtmosphere::InitModel(void)

bool FGAtmosphere::Run(bool Holding)
{
constexpr double a = 0.5*(SHRatio-1.0);

if (FGModel::Run(Holding)) return true;
if (Holding) return false;

Calculate(in.altitudeASL);

FGColumnVector3 vAeroUVW = in.vUVW - in.Tl2b * in.TotalWindNED;
double Mach = vAeroUVW.Magnitude() / Soundspeed;

TotalPressure = PitotTotalPressure(Mach, Pressure);
vcas = StdDaySLsoundspeed * MachFromImpactPressure(TotalPressure - Pressure,
StdDaySLpressure);
TotalTemperature = Temperature*(1+a*Mach*Mach);

Debug(2);
return false;
}
Expand Down Expand Up @@ -397,6 +417,11 @@ void FGAtmosphere::bind(void)
PropertyManager->Tie("atmosphere/a-ratio", this, &FGAtmosphere::GetSoundSpeedRatio);
PropertyManager->Tie("atmosphere/density-altitude", this, &FGAtmosphere::GetDensityAltitude);
PropertyManager->Tie("atmosphere/pressure-altitude", this, &FGAtmosphere::GetPressureAltitude);
PropertyManager->Tie("velocities/vc-fps", this, &FGAtmosphere::GetVcalibratedFPS);
PropertyManager->Tie("velocities/vc-kts", this, &FGAtmosphere::GetVcalibratedKTS);
PropertyManager->Tie("propulsion/tat-r", this, &FGAtmosphere::GetTotalTemperature);
PropertyManager->Tie("propulsion/tat-c", this, &FGAtmosphere::GetTAT_C);
PropertyManager->Tie("propulsion/pt-lbs_sqft", this, &FGAtmosphere::GetTotalPressure);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
40 changes: 37 additions & 3 deletions src/models/FGAtmosphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SENTRY
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#include "math/FGMatrix33.h"
#include "models/FGModel.h"

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -241,12 +242,41 @@ class JSBSIM_API FGAtmosphere : public FGModel {
* */
double MachFromVcalibrated(double vcas, double altitude) const;

/** Returns Calibrated airspeed in feet/second.*/
double GetVcalibratedFPS(void) const { return vcas; }

/** Returns Calibrated airspeed in knots.*/
double GetVcalibratedKTS(void) const { return vcas*fpstokts; }

/** Returns the total pressure in PSF.
Total pressure is freestream total pressure for subsonic only.
For supersonic it is the 1D total pressure behind a normal shock.
*/
double GetTotalPressure(void) const { return TotalPressure; }

/** Returns the total temperature in Rankine.
The total temperature ("tat", isentropic flow) is calculated:
@code
tat = Temperature*(1 + 0.2*Mach*Mach)
@endcode
(where "Temperature" is the temperature calculated by the atmosphere model)
*/
double GetTotalTemperature(void) const { return TotalTemperature; }

/** Return the total ambient temperature in degrees Celsius.
@see GetTotalTemperature
*/
double GetTAT_C(void) const { return RankineToCelsius(TotalTemperature); }

struct Inputs {
double altitudeASL;
FGColumnVector3 vUVW;
FGMatrix33 Tl2b;
FGColumnVector3 TotalWindNED;
} in;

static constexpr double StdDaySLtemperature = 518.67;
static constexpr double StdDaySLpressure = 2116.228;
static constexpr double StdDaySLtemperature = 518.67; // deg Rankine
static constexpr double StdDaySLpressure = 2116.228; // PSF
const double StdDaySLsoundspeed;

protected:
Expand All @@ -264,10 +294,14 @@ class JSBSIM_API FGAtmosphere : public FGModel {
double DensityAltitude = 0.0;

static constexpr double SutherlandConstant = 198.72; // deg Rankine
static constexpr double Beta = 2.269690E-08; // slug/(sec ft R^0.5)
static constexpr double Beta = 2.269690E-08; // slug/(sec ft R^0.5)
double Viscosity = 0.0;
double KinematicViscosity = 0.0;

double vcas = 0.0;
double TotalPressure = 0.0;
double TotalTemperature = 1.8;

/// Calculate the atmosphere for the given altitude.
virtual void Calculate(double altitude);

Expand Down
28 changes: 3 additions & 25 deletions src/models/FGAuxiliary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ CLASS IMPLEMENTATION
FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex)
{
Name = "FGAuxiliary";
pt = 2116.23; // ISA SL pressure
tatc = 15.0; // ISA SL temperature
tat = 518.67;

vcas = veas = 0.0;
veas = 0.0;
qbar = qbarUW = qbarUV = 0.0;
Mach = MachU = 0.0;
alpha = beta = 0.0;
Expand Down Expand Up @@ -96,11 +93,7 @@ bool FGAuxiliary::InitModel(void)
{
if (!FGModel::InitModel()) return false;

pt = in.Pressure;
tat = in.Temperature;
tatc = RankineToCelsius(tat);

vcas = veas = 0.0;
veas = 0.0;
qbar = qbarUW = qbarUV = 0.0;
Mach = MachU = 0.0;
alpha = beta = 0.0;
Expand Down Expand Up @@ -191,17 +184,7 @@ bool FGAuxiliary::Run(bool Holding)
if (psigt < 0.0) psigt += 2*M_PI;
gamma = atan2(-in.vVel(eDown), Vground);

tat = in.Temperature*(1 + 0.2*Mach*Mach); // Total Temperature, isentropic flow
tatc = RankineToCelsius(tat);

pt = FDMExec->GetAtmosphere()->PitotTotalPressure(Mach, in.Pressure);

if (abs(Mach) > 0.0) {
vcas = FDMExec->GetAtmosphere()->VcalibratedFromMach(Mach, in.AltitudeASL);
veas = sqrt(2 * qbar / in.DensitySL);
}
else
vcas = veas = 0.0;
veas = sqrt(2 * qbar / in.DensitySL);

vPilotAccel.InitMatrix();
vNcg = in.vBodyAccel/in.StandardGravity;
Expand Down Expand Up @@ -308,11 +291,6 @@ void FGAuxiliary::bind(void)
{
typedef double (FGAuxiliary::*PMF)(int) const;
typedef double (FGAuxiliary::*PF)(void) const;
PropertyManager->Tie("propulsion/tat-r", this, &FGAuxiliary::GetTotalTemperature);
PropertyManager->Tie("propulsion/tat-c", this, &FGAuxiliary::GetTAT_C);
PropertyManager->Tie("propulsion/pt-lbs_sqft", this, &FGAuxiliary::GetTotalPressure);
PropertyManager->Tie("velocities/vc-fps", this, &FGAuxiliary::GetVcalibratedFPS);
PropertyManager->Tie("velocities/vc-kts", this, &FGAuxiliary::GetVcalibratedKTS);
PropertyManager->Tie("velocities/ve-fps", this, &FGAuxiliary::GetVequivalentFPS);
PropertyManager->Tie("velocities/ve-kts", this, &FGAuxiliary::GetVequivalentKTS);
PropertyManager->Tie("velocities/vtrue-fps", this, &FGAuxiliary::GetVtrueFPS);
Expand Down
28 changes: 1 addition & 27 deletions src/models/FGAuxiliary.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ class JSBSIM_API FGAuxiliary : public FGModel {
// GET functions

// Atmospheric parameters GET functions
/** Returns Calibrated airspeed in feet/second.*/
double GetVcalibratedFPS(void) const { return vcas; }
/** Returns Calibrated airspeed in knots.*/
double GetVcalibratedKTS(void) const { return vcas*fpstokts; }
/** Returns equivalent airspeed in feet/second. */
double GetVequivalentFPS(void) const { return veas; }
/** Returns equivalent airspeed in knots. */
Expand All @@ -134,23 +130,6 @@ class JSBSIM_API FGAuxiliary : public FGModel {
/** Returns the true airspeed in knots. */
double GetVtrueKTS() const { return Vt * fpstokts; }

/** Returns the total pressure.
Total pressure is freestream total pressure for
subsonic only. For supersonic it is the 1D total pressure
behind a normal shock. */
double GetTotalPressure(void) const { return pt; }

/** Returns the total temperature.
The total temperature ("tat", isentropic flow) is calculated:
@code
tat = in.Temperature*(1 + 0.2*Mach*Mach)
@endcode
(where "in.Temperature" is standard temperature calculated by the atmosphere
model) */

double GetTotalTemperature(void) const { return tat; }
double GetTAT_C(void) const { return tatc; }

double GetPilotAccel(int idx) const { return vPilotAccel(idx); }
double GetNpilot(int idx) const { return vPilotAccelN(idx); }
double GetAeroPQR(int axis) const { return vAeroPQR(axis); }
Expand Down Expand Up @@ -252,15 +231,11 @@ class JSBSIM_API FGAuxiliary : public FGModel {
void SetAeroPQR(const FGColumnVector3& tt) { vAeroPQR = tt; }

struct Inputs {
double Pressure;
double Density;
double DensitySL;
double PressureSL;
double Temperature;
double SoundSpeed;
double KinematicViscosity;
double DistanceAGL;
double AltitudeASL;
double Wingspan;
double Wingchord;
double StandardGravity;
Expand Down Expand Up @@ -288,8 +263,7 @@ class JSBSIM_API FGAuxiliary : public FGModel {
} in;

private:
double vcas, veas;
double pt, tat, tatc; // Don't add a getter for pt!
double veas;

FGMatrix33 mTw2b;
FGMatrix33 mTb2w;
Expand Down
Loading