Skip to content
New issue

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

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

Already on GitHub? # to your account

Add a unit test for FGAtmosphere #857

Merged
merged 4 commits into from
Mar 15, 2023
Merged
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
25 changes: 12 additions & 13 deletions src/models/FGAtmosphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ namespace JSBSim {
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

// Atmosphere constants in British units converted from the SI values specified in the
// Atmosphere constants in British units converted from the SI values specified in the
// ISA document - https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19770009539.pdf
double FGAtmosphere::Reng = Rstar / Mair;
const double FGAtmosphere::StdDaySLsoundspeed = sqrt(SHRatio*Reng0*StdDaySLtemperature);

const double FGAtmosphere::StdDaySLsoundspeed = sqrt(SHRatio*Reng*StdDaySLtemperature);

FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex),
PressureAltitude(0.0), // ft
DensityAltitude(0.0) // ft
FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex)
{
Name = "FGAtmosphere";

Expand All @@ -80,11 +76,11 @@ bool FGAtmosphere::InitModel(void)
{
if (!FGModel::InitModel()) return false;

Calculate(0.0);
SLtemperature = Temperature = StdDaySLtemperature;
SLpressure = Pressure = StdDaySLpressure;
SLdensity = Density = Pressure/(Reng*Temperature);
SLsoundspeed = Soundspeed = StdDaySLsoundspeed;
Calculate(0.0);

return true;
}
Expand Down Expand Up @@ -158,7 +154,7 @@ void FGAtmosphere::Calculate(double altitude)
Pressure = ValidatePressure(p, "", true);

if (!PropertyManager->HasNode("atmosphere/override/density"))
Density = GetDensity(altitude);
Density = Pressure/(Reng*Temperature);
else
Density = node->GetDouble("atmosphere/override/density");

Expand All @@ -177,6 +173,7 @@ void FGAtmosphere::SetPressureSL(ePressure unit, double pressure)
double press = ConvertToPSF(pressure, unit);

SLpressure = ValidatePressure(press, "Sea Level pressure");
SLdensity = GetDensity(0.0);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -204,6 +201,8 @@ void FGAtmosphere::SetTemperatureSL(double t, eTemperature unit)
double temp = ConvertToRankine(t, unit);

SLtemperature = ValidateTemperature(temp, "Sea Level temperature");
SLdensity = GetDensity(0.0);
SLsoundspeed = GetSoundSpeed(0.0);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand All @@ -226,7 +225,7 @@ double FGAtmosphere::ConvertToRankine(double t, eTemperature unit) const
targetTemp = t*1.8;
break;
default:
break;
throw BaseException("Undefined temperature unit given");
}

return targetTemp;
Expand All @@ -252,7 +251,7 @@ double FGAtmosphere::ConvertFromRankine(double t, eTemperature unit) const
targetTemp = t/1.8;
break;
default:
break;
throw BaseException("Undefined temperature unit given");
}

return targetTemp;
Expand All @@ -278,7 +277,7 @@ double FGAtmosphere::ConvertToPSF(double p, ePressure unit) const
targetPressure = p*70.7180803;
break;
default:
throw("Undefined pressure unit given");
throw BaseException("Undefined pressure unit given");
}

return targetPressure;
Expand All @@ -302,7 +301,7 @@ double FGAtmosphere::ConvertFromPSF(double p, ePressure unit) const
targetPressure = p/70.7180803;
break;
default:
throw("Undefined pressure unit given");
throw BaseException("Undefined pressure unit given");
}

return targetPressure;
Expand Down
34 changes: 22 additions & 12 deletions src/models/FGAtmosphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CLASS DOCUMENTATION
CLASS DECLARATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

class FGAtmosphere : public FGModel {
class JSBSIM_API FGAtmosphere : public FGModel {
public:

/// Enums for specifying temperature units.
Expand All @@ -90,7 +90,7 @@ class FGAtmosphere : public FGModel {

/** Runs the atmosphere forces model; called by the Executive.
Can pass in a value indicating if the executive is directing the simulation to Hold.
@param Holding if true, the executive has been directed to hold the sim from
@param Holding if true, the executive has been directed to hold the sim from
advancing time. Some models may ignore this flag, such as the Input
model, which may need to be active to listen on a socket for the
"Resume" command to be given.
Expand All @@ -111,7 +111,7 @@ class FGAtmosphere : public FGModel {
/// Returns the actual modeled temperature in degrees Rankine at a specified altitude.
/// @param altitude The altitude above sea level (ASL) in feet.
/// @return Modeled temperature in degrees Rankine at the specified altitude.
virtual double GetTemperature(double altitude) const = 0;
virtual double GetTemperature(double altitude) const = 0;

/// Returns the actual, modeled sea level temperature in degrees Rankine.
/// @return The modeled temperature in degrees Rankine at sea level.
Expand Down Expand Up @@ -184,7 +184,7 @@ class FGAtmosphere : public FGModel {

/// Returns the speed of sound in ft/sec at a given altitude in ft.
virtual double GetSoundSpeed(double altitude) const;

/// Returns the sea level speed of sound in ft/sec.
virtual double GetSoundSpeedSL(void) const { return SLsoundspeed; }

Expand Down Expand Up @@ -215,15 +215,23 @@ class FGAtmosphere : public FGModel {
static const double StdDaySLsoundspeed;

protected:
double SLtemperature, SLdensity, SLpressure, SLsoundspeed; // Sea level conditions
double Temperature, Density, Pressure, Soundspeed; // Current actual conditions at altitude

double PressureAltitude;
double DensityAltitude;
// Sea level conditions
double SLtemperature = 1.8;
double SLdensity = 1.0;
double SLpressure = 1.0;
double SLsoundspeed = 1.0;
// Current actual conditions at altitude
double Temperature = 1.8;
double Density = 0.0;
double Pressure = 0.0;
double Soundspeed = 0.0;
double PressureAltitude = 0.0;
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)
double Viscosity, KinematicViscosity;
double Viscosity = 0.0;
double KinematicViscosity = 0.0;

/// Calculate the atmosphere for the given altitude.
virtual void Calculate(double altitude);
Expand All @@ -244,7 +252,7 @@ class FGAtmosphere : public FGModel {

/// Converts to Rankine from one of several unit systems.
double ConvertToRankine(double t, eTemperature unit) const;

/// Converts from Rankine to one of several unit systems.
double ConvertFromRankine(double t, eTemperature unit) const;

Expand Down Expand Up @@ -277,11 +285,13 @@ class FGAtmosphere : public FGModel {
*/
static constexpr double g0 = 9.80665 / fttom;
/// Specific gas constant for air - ft*lbf/slug/R
static double Reng;
static constexpr double Reng0 = Rstar / Mair;
//@}

static constexpr double SHRatio = 1.4;

double Reng = Reng0;

virtual void bind(void);
void Debug(int from) override;
};
Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ set(UNIT_TESTS FGColumnVector3Test
FGParameterTest
FGParameterValueTest
FGConditionTest
FGPropertyManagerTest)
FGPropertyManagerTest
FGAtmosphereTest)

foreach(test ${UNIT_TESTS})
cxxtest_add_test(${test}1 ${test}.cpp ${CMAKE_CURRENT_SOURCE_DIR}/${test}.h)
Expand Down
Loading