diff --git a/src/FGFDMExec.cpp b/src/FGFDMExec.cpp index a7e81ab2b9..f5ba6a6b1e 100644 --- a/src/FGFDMExec.cpp +++ b/src/FGFDMExec.cpp @@ -46,6 +46,7 @@ INCLUDES #include "FGFDMExec.h" #include "models/atmosphere/FGStandardAtmosphere.h" +#include "models/atmosphere/FGMSIS.h" #include "models/atmosphere/FGWinds.h" #include "models/FGFCS.h" #include "models/FGPropulsion.h" @@ -451,7 +452,9 @@ 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.GeodLatitudeDeg = Propagate->GetGeodLatitudeDeg(); + Atmosphere->in.LongitudeDeg = Propagate->GetLongitudeDeg(); break; case eWinds: Winds->in.AltitudeASL = Propagate->GetAltitudeASL(); @@ -762,7 +765,7 @@ bool FGFDMExec::LoadPlanet(const SGPath& PlanetPath, bool useAircraftPath) if (document->GetName() != "planet") { stringstream s; - s << "File: " << PlanetFileName << " is not a reset file."; + s << "File: " << PlanetFileName << " is not a planet file."; cerr << s.str() << endl; throw BaseException(s.str()); } @@ -786,6 +789,28 @@ bool FGFDMExec::LoadPlanet(Element* element) LoadPlanetConstants(); IC->InitializeIC(); InitializeModels(); + + // Process the atmosphere element. This element is OPTIONAL. + Element* atm_element = element->FindElement("atmosphere"); + if (atm_element && atm_element->HasAttribute("model")) { + string model = atm_element->GetAttributeValue("model"); + if (model == "MSIS") { + // Replace the existing atmosphere model + instance->Unbind(Models[eAtmosphere].get()); + Models[eAtmosphere] = std::make_shared(this); + Atmosphere = static_cast(Models[eAtmosphere].get()); + + // Model initialization sequence + LoadInputs(eAtmosphere); + Atmosphere->InitModel(); + result = Atmosphere->Load(atm_element); + if (!result) { + cerr << endl << "Incorrect definition of ." << endl; + return result; + } + InitializeModels(); + } + } } return result; diff --git a/tests/MSIS.xml b/tests/MSIS.xml new file mode 100644 index 0000000000..53d73ec5d6 --- /dev/null +++ b/tests/MSIS.xml @@ -0,0 +1,6 @@ + + + 172 + 29000 + + diff --git a/tests/TestPlanet.py b/tests/TestPlanet.py index 217b9e4186..7a66b972b0 100644 --- a/tests/TestPlanet.py +++ b/tests/TestPlanet.py @@ -61,6 +61,20 @@ def test_load_planet(self): self.assertAlmostEqual(self.fdm['metrics/terrain-radius']*0.3048/1736000, 1.0) + def test_load_MSIS_atmosphere(self): + tripod = FlightModel(self, 'tripod') + MSIS_file = self.sandbox.path_to_jsbsim_file('tests/MSIS.xml') + self.fdm = tripod.start() + self.fdm.load_planet(MSIS_file, False) + self.fdm['ic/h-sl-ft'] = 0.0 + self.fdm['ic/long-gc-deg'] = -70.0 + self.fdm['ic/lat-geod-deg'] = 60.0 + self.fdm.run_ic() + + self.assertAlmostEqual(self.fdm['atmosphere/T-R']*5/9, 281.46476, delta=1E-5) + self.assertAlmostEqual(self.fdm['atmosphere/rho-slugs_ft3']/0.001940318, 1.263428, delta=1E-6) + self.assertAlmostEqual(self.fdm['atmosphere/P-psf'], 2132.294, delta=1E-3) + def test_planet_geographic_error1(self): # Check that a negative equatorial radius raises an exception tripod = FlightModel(self, 'tripod')