Add FGNullAtmosphere and extend LoadPlanet atmosphere factory#1462
Conversation
- FGNullAtmosphere: vacuum model for airless bodies (Moon) - Atmosphere factory supports "Mars" and "Null" in planet XML - Planet configs: moon.xml, mars.xml
The Mars atmosphere model computed temperature in Fahrenheit but passed it directly to the ideal gas law (Density = P/(R*T)) which requires Rankine. This produced negative density at all altitudes, causing NaN on the first simulation step. Add +459.67 offset (F→R conversion) before density calculation.
- test_mars_atmosphere: include planet, verify surface T/P/density and gravity - test_load_Mars_atmosphere: same via runtime LoadPlanet - test_load_Null_atmosphere: vacuum P=0, rho=0, T~2.725 K
- LoadPlanet: unbind old atmosphere before constructing the replacement. FGAtmosphere's ctor calls bind(), so the previous order silently failed to tie the new model's properties (atmosphere/T-R, P-psf, etc.) and the FDM kept reading stale values from the old instance. - FGMars / FGNullAtmosphere: remove redundant bind() in ctor. FGAtmosphere's base ctor already calls it; the duplicate produced 'Failed to tie' warnings once the factory began swapping models at runtime. - TestPlanet: add Mars and Null atmosphere tests.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1462 +/- ##
==========================================
- Coverage 25.15% 25.10% -0.05%
==========================================
Files 169 171 +2
Lines 18811 18843 +32
==========================================
Hits 4731 4731
- Misses 14080 14112 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the PR @AlexanderRex. Even though it makes sense to restore the Mars atmosphere, I am not so sure about adding the "null" atmosphere. In JSBSim, an empty And also I am bit worried about setting the pressure and density to zero. Has the code been reviewed to make sure that this would not lead to divisions by zero or any other similar problems ? |
bcoconni
left a comment
There was a problem hiding this comment.
I would suggest a few minor changes in addition to the points I have mentioned in another comment.
I am not sure about what you exactly mean by that ? Your statement is worded as if you had found an error in JSBSim, but the code in Lines 792 to 795 in 5e23ead And would the readings be frozen then the test Lines 64 to 76 in 5e23ead |
Hi @bcoconni, thanks for your review! The unbind/construct order on master is already correct. What I described I also check NullAtmosphere again and yeah it will trigger zero division, so I think to remove it from this PR and and keep this change focused on restoring Mars. Will implement your suggestions and remove NullAtmosphere |
Co-authored-by: Bertrand Coconnier <bcoconni@users.noreply.github.com>
Co-authored-by: Bertrand Coconnier <bcoconni@users.noreply.github.com>
Co-authored-by: Bertrand Coconnier <bcoconni@users.noreply.github.com>
If you mean just the lunar module descending to and taking off from the Moon then as @bcoconni mentioned you don't necessarily require a vacuum atmosphere model. You can set the planet to the Moon and leave the default earth atmosphere model and simply have no force/moment entries in the If you're talking about modelling the full Apollo mission from earth to the moon and back, then the issue is that there isn't a mechanism to swap/fade out/fade in one planet to another and one atmosphere to another. The closest I've seen I guess is the JSBSim/FlightGear Space Shuttle model, which needs aerodynamic forces/moments for take-off and landing, but needs the aerodynamic forces/moments to pretty much go to 0 while in orbit. Actually not sure if they use the MSIS atmosphere model, given it's defined from 0-1000km. Space Shuttle's orbit was between 320km - 620km. Or whether they use the standard ISA, and even though it's not defined above 87km, I'm guessing the density drops close enough to 0 that the Space Shuttle ends up with close to 0 aerodynamic forces/moments? |
Per maintainer feedback (JSBSim-Team#1462 review by @bcoconni, @seanmcleod70): - Empty <aerodynamics/> section already gives zero aero forces on airless bodies, removing the practical need for a vacuum model. - Setting Pressure and Density to zero risks division-by-zero in callers that read these (e.g. FGAtmosphere::Calculate computes Viscosity / Density, FGAuxiliary divides by pressure). This commit drops FGNullAtmosphere from the PR scope. Keeping only the Mars atmosphere restoration in LoadPlanet. Also fixes a typo in the previously-applied suggestion ("miss" should have been "msis") that prevented the MSIS atmosphere from being constructed at runtime, and adds the missing string_utilities.h include for to_lower(). - Delete src/models/atmosphere/FGNullAtmosphere.{cpp,h} - Remove FGNullAtmosphere from src/models/atmosphere/CMakeLists.txt - Remove FGNullAtmosphere from JSBSimForUnreal.vcxproj - Remove the "null" branch from LoadPlanet factory - Restore tests/moon.xml to upstream version - Remove test_load_Null_atmosphere from TestPlanet
To be honest I thought to split it into the stages like:
But at the moment Mars atmosphere is more necessary for me, so thats why I start fixing it :) |
Adds atmosphere support so JSBSim can simulate vehicles on Mars and the Moon.
What changes
<atmosphere model="Mars"/>and<atmosphere model="Null"/>are now valid inLoadPlanet, alongside the existing"MSIS".FGNullAtmosphereclass: a vacuum. Pressure and density are zero; temperature is set to the cosmic microwave background (~2.7 K) just so reads return a finite value. Use it for the Moon, Mercury, asteroids.Bugs found while wiring this up
LoadPlanetwas unbinding the old atmosphere after constructing the new one. ButFGAtmosphere's constructor callsbind(), and at that point the old model still ownedatmosphere/T-R,atmosphere/P-psf, etc., so the new model's ties silently failed, and the FDM kept reading stale values from the old instance. Fixed by unbinding first.FGMars::Calculatewas returning temperature in °F, butDensity = P / (Reng·T)needs absolute temperature. Surface T came out around −26 °F → negative absolute → negative density → NaN on the first step. Added the +459.67 F→R offset to both lapse branches.FGMarsandFGNullAtmosphereconstructors were callingbind()themselves, butFGAtmosphere's base constructor already does. The duplicate was harmless at FDM startup but produced a flood ofFailed to tie propertywarnings once the factory started swapping atmosphere models at runtime. Removed.Tests
Three new cases in
tests/TestPlanet.py:test_mars_atmosphere: via the planet<include>path; checks T = 433.99 R, P = 14.62 psf, ρ ≈ 1.43e-5 slugs/ft³, plus Mars radius and surface gravity.test_load_Mars_atmosphere: same expected values via runtimeLoadPlanet.test_load_Null_atmosphere: vacuum, P = ρ = 0, T = 4.905 R.tests/moon.xmlnow declares<atmosphere model="Null"/>(it's the Moon, no atmosphere). Newtests/mars.xml. FullTestPlanetsuite (8/8) passes.