From 04524c0cca4dde900dc85dbd8be5dc13013a1d61 Mon Sep 17 00:00:00 2001 From: Thorsten Renk Date: Mon, 16 Nov 2015 17:41:57 +0200 Subject: [PATCH] Tentative improvements to AW gust modeling --- Environment/local-weather-defaults.xml | 2 + Nasal/local_weather/compat_layer.nas | 26 ++++++- Nasal/local_weather/local_weather.nas | 25 +++++-- .../local_weather/weather_tile_management.nas | 15 ++++- gui/dialogs/local_weather_tiles.xml | 67 ++++++++++++++----- 5 files changed, 109 insertions(+), 26 deletions(-) diff --git a/Environment/local-weather-defaults.xml b/Environment/local-weather-defaults.xml index 68e609937..93970ac9a 100644 --- a/Environment/local-weather-defaults.xml +++ b/Environment/local-weather-defaults.xml @@ -19,6 +19,7 @@ 0 0 1 + 1.0 1 0 25.0 @@ -37,6 +38,7 @@ 0.0 0.0 0.0 + 1.0 0.0 0 260.0 diff --git a/Nasal/local_weather/compat_layer.nas b/Nasal/local_weather/compat_layer.nas index e5ca6b228..85553b565 100644 --- a/Nasal/local_weather/compat_layer.nas +++ b/Nasal/local_weather/compat_layer.nas @@ -285,8 +285,10 @@ setprop("/environment/precipitation-control/snow-flake-size", size); #################################### var setTurbulence = func (turbulence) { - -setprop("/environment/turbulence/magnitude-norm",turbulence); + +var turbulence_scale = getprop("/local-weather/config/turbulence-scale"); + +setprop("/environment/turbulence/magnitude-norm",turbulence * turbulence_scale); setprop("/environment/turbulence/rate-hz",3.0); } @@ -415,10 +417,28 @@ setprop("/environment/clouds/layer[0]/elevation-ft",0.0); # interpolating across several frames ########################################################### +var smoothDirection = func (dir0, dir1, factor) { + +var diff = ( math.mod( dir0 - dir1 + 180 + 360, 360 ) - 180 ); +diff *= factor; + +return math.mod( 360 + dir1 + ( diff / 2), 360); +} + var setWindSmoothly = func (dir, speed) { -setWind(dir, speed); +var curDir = getprop("/environment/wind-from-heading-deg"); +var curSpeed = getprop("/environment/wind-speed-kt"); + +dir = math.mod(dir, 360); + +var newSpeed = (curSpeed * 9 + speed) / 10; +var newDir = smoothDirection(dir, curDir, 0.2); + +setWind(newDir, newSpeed); + +#setWind(dir, speed); } diff --git a/Nasal/local_weather/local_weather.nas b/Nasal/local_weather/local_weather.nas index 0b39a8570..075302f74 100644 --- a/Nasal/local_weather/local_weather.nas +++ b/Nasal/local_weather/local_weather.nas @@ -924,7 +924,21 @@ if (gust_frequency > 0.0) if (alt_scaling_factor < 1.0) {alt_scaling_factor = 1.0;} # expected mean number of gusts in time interval (should be < 1) - var p_gust = gust_frequency * interpolation_loop_time; + var p_gust = gust_frequency * interpolation_loop_time; + + # real time series show a ~10-30 second modulation as well + var p_squall = gust_frequency * 0.1 * interpolation_loop_time; + var squall_scale = getprop("/local-weather/tmp/squall-scaling-norm"); + + if (rand() < p_squall) + { + squall_scale = rand(); + # prefer large changes + if ((squall_scale > 0.3) and (squall_scale < 0.7)) + {squall_scale = rand();} + + setprop("/local-weather/tmp/squall-scaling-norm", squall_scale); + } winddir_change = 0.0; @@ -932,7 +946,10 @@ if (gust_frequency > 0.0) { var alt_fact = 1.0 - altitude_agl/(boundary_alt * alt_scaling_factor); if (alt_fact < 0.0) {alt_fact = 0.0}; - windspeed_multiplier = (1.0 + ((rand()) * gust_relative_strength * alt_fact)); + + var random_factor = 0.3 * rand() + 0.7 * squall_scale; + + windspeed_multiplier = (1.0 + (random_factor * gust_relative_strength * alt_fact)); winddir_change = alt_fact * (1.0 - 2.0 * rand()) * gust_angvar; winddir_change = winddir_change * 0.2; # Markov chain parameter, max. change per frame is 1/5 @@ -947,7 +964,7 @@ if (gust_frequency > 0.0) winddir = winddir_last + winddir_change; } - + @@ -4052,7 +4069,7 @@ if (local_weather.cloud_shadow_flag == 1) weather_tile_management.shadow_management_loop(0); } -# weather_tile_management.watchdog_loop(); +#weather_tile_management.watchdog_loop(); # start thunderstorm management diff --git a/Nasal/local_weather/weather_tile_management.nas b/Nasal/local_weather/weather_tile_management.nas index c89d7fdd8..9da5d565f 100644 --- a/Nasal/local_weather/weather_tile_management.nas +++ b/Nasal/local_weather/weather_tile_management.nas @@ -1493,7 +1493,14 @@ settimer( func {shadow_management_loop(i)}, 0); var watchdog_loop = func { -var tNode = props.globals.getNode(lw~"tiles", 1).getChildren("tile"); +var winddir = getprop("/environment/wind-from-heading-deg"); +var windspeed = getprop("/environment/wind-speed-kt"); + +print (windspeed, " ", winddir); + + +if (0==1) +{var tNode = props.globals.getNode(lw~"tiles", 1).getChildren("tile"); var i = 0; @@ -1536,6 +1543,8 @@ for (var i = 0; i < wsize; i=i+1) { } print("dir_int: ", sum_wind[0], " speed_int: ", sum_wind[1]/sum_norm); +} + if (0==1) { @@ -1589,9 +1598,9 @@ print("Mismatch: ", relangle(res[0], getprop(lw~"tiles/tile[4]/orientation-deg") } -print("===================="); +#print("===================="); -settimer(watchdog_loop, 10.0); +settimer(watchdog_loop, 4.0); } diff --git a/gui/dialogs/local_weather_tiles.xml b/gui/dialogs/local_weather_tiles.xml index 6dd2693bb..2b5e4c40e 100644 --- a/gui/dialogs/local_weather_tiles.xml +++ b/gui/dialogs/local_weather_tiles.xml @@ -214,7 +214,7 @@ 1 fill 0.0 - 2.0 + 1.0 /local-weather/tmp/gust-frequency-hz dialog-apply @@ -441,23 +441,58 @@ + + 3 0 right - + 3 1 right - + 3 2 + 0.0 + 1.5 + /local-weather/config/turbulence-scale + + dialog-apply + + + + + 3 + 3 + left + + + + + + 4 + 0 + right + + + + + 4 + 1 + right + + + + + 4 + 2 0.1 1.0 /local-weather/config/ground-haze-factor @@ -467,28 +502,28 @@ - 3 + 4 3 left - 4 + 5 0 right - 4 + 5 1 right - 4 + 5 2 0.0 1.0 @@ -499,28 +534,28 @@ - 4 + 5 3 left - 5 + 6 0 right - 5 + 6 1 right - 5 + 6 2 0.0 12.0 @@ -531,14 +566,14 @@ - 5 + 6 3 left - 6 + 7 0 right