Skip to content

Commit

Permalink
Feat/Weather: Avoid overlapping cloud layers
Browse files Browse the repository at this point in the history
  • Loading branch information
TwinFan committed Sep 1, 2024
1 parent 8a3c224 commit 7f0f77c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Include/LTWeather.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ float WeatherQNHfromMETAR (const std::string& metar);

/// Distance when next weather is set to update immediately instead of gradually
constexpr double WEATHER_MAX_DIST_M = 50 * M_per_NM;
/// Thickness of a METAR cloud layer [m]
/// Standard thickness of a METAR cloud layer [m]
constexpr float WEATHER_METAR_CLOUD_HEIGHT_M = 500;
/// Minimum thickness of a METAR cloud layer [m]
constexpr float WEATHER_MIN_CLOUD_HEIGHT_M = 100;
/// Thickness of a METAR Cumulo-nimbus cloud layer [m]
constexpr float WEATHER_METAR_CB_CLOUD_HEIGHT_M = 5000;

Expand Down
10 changes: 9 additions & 1 deletion Src/LTWeather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,13 +1039,21 @@ class LTWeatherVisitor : public Visitor<bool> {
}
}

// Cleanup up cloud layers: Anything beyond iCloud, that is lower than the last METAR layer, is to be removed
// Cleanup up cloud layers:
if (iCloud > 0) {
// Anything beyond iCloud, that is lower than the last METAR layer, is to be removed
const float highestMetarBase = w.cloud_base_msl_m[iCloud-1];
for (std::size_t i = iCloud; i < w.cloud_type.size(); ++i) {
if (w.cloud_base_msl_m[i] <= highestMetarBase)
RemoveClouds(i);
}
// Avoid overlapping cloud layer
for (std::size_t i = 0; i < w.cloud_type.size()-1; ++i) {
if (w.cloud_tops_msl_m[i] > w.cloud_base_msl_m[i+1] - WEATHER_MIN_CLOUD_HEIGHT_M)
// Minimum 100m height, but otherwise we try to keep 100m vertical distance from next layer
w.cloud_tops_msl_m[i] = std::max(w.cloud_base_msl_m[i] + WEATHER_MIN_CLOUD_HEIGHT_M,
w.cloud_base_msl_m[i+1] - WEATHER_MIN_CLOUD_HEIGHT_M);
}
}

// Thunderstorms require a cumulo-nimbus somewhere
Expand Down

0 comments on commit 7f0f77c

Please sign in to comment.