|
1 | 1 | function allocate_profile(heights) |
2 | 2 | wind_speed = similar(heights, typeof(0.0u"m/s")) # output wind speeds |
3 | 3 | height_array = similar(heights, typeof(0.0u"m")) |
4 | | - height_array[end:-1:begin] .= heights |
| 4 | + height_array[end:-1:begin] .= heights |
5 | 5 | air_temperature = similar(heights, typeof(0.0u"K")) # output temperatures, need to do this otherwise get InexactError |
6 | 6 | relative_humidity = similar(heights, Float64) # output relative humidities |
7 | | - return (; heights, height_array, air_temperature, wind_speed, relative_humidity) |
| 7 | + obukhov_length_prev = Ref(-0.3u"m") # warm-start across timesteps |
| 8 | + return (; heights, height_array, air_temperature, wind_speed, relative_humidity, obukhov_length_prev) |
8 | 9 | end |
9 | 10 |
|
10 | 11 | """ |
@@ -91,7 +92,7 @@ function atmospheric_surface_profile!(buffers; |
91 | 92 | (; roughness_height, karman_constant, dyer_constant, elevation) = micro_terrain |
92 | 93 | (; atmospheric_pressure, reference_temperature, reference_wind_speed, reference_humidity, zenith_angle) = environment_instant |
93 | 94 |
|
94 | | - (; heights, height_array, air_temperature, wind_speed, relative_humidity) = buffers |
| 95 | + (; heights, height_array, air_temperature, wind_speed, relative_humidity, obukhov_length_prev) = buffers |
95 | 96 | N_heights = length(heights) |
96 | 97 | if minimum(heights) < roughness_height |
97 | 98 | throw(ArgumentError("The minimum height is not greater than the roughness height.")) |
@@ -138,10 +139,9 @@ function atmospheric_surface_profile!(buffers; |
138 | 139 | air_temperature[i] = roughness_height_temp + (reference_temp - roughness_height_temp) * log(height_array[i] / z0 + 1.0) / log_z_ratio |
139 | 140 | end |
140 | 141 | else |
141 | | - obukhov_length = -0.3u"m" # initialise Obukhov length |
142 | | - # TODO just pass the environment_instant through here |
143 | | - Obukhov_out = calc_Obukhov_length(reference_temp, surface_temp, v_ref_height, z0, z, ρcpTκg, κ, log_z_ratio, ΔT, ρ_cp; max_iter=30, tol=1e-2) |
| 142 | + Obukhov_out = calc_Obukhov_length(reference_temp, surface_temp, v_ref_height, z0, z, ρcpTκg, κ, log_z_ratio, ΔT, ρ_cp; max_iter=30, tol=1e-2, initial_obukhov_length=obukhov_length_prev[]) |
144 | 143 | obukhov_length = Obukhov_out.obukhov_length |
| 144 | + obukhov_length_prev[] = obukhov_length |
145 | 145 | roughness_height_temp = Obukhov_out.roughness_height_temperature |
146 | 146 | convective_heat_flux = Obukhov_out.convective_heat_flux |
147 | 147 | u_star = Obukhov_out.u_star |
@@ -415,9 +415,9 @@ Iteratively solve for Monin-Obukhov length and convective heat flux. |
415 | 415 | """ |
416 | 416 | @inline function calc_Obukhov_length( |
417 | 417 | reference_temp, surface_temp, v_ref_height, z0, z, ρcpTκg, κ, log_z_ratio, ΔT, ρ_cp; |
418 | | - γ=16.0, max_iter=30, tol=1e-2 |
| 418 | + γ=16.0, max_iter=30, tol=1e-2, initial_obukhov_length=-0.3u"m" |
419 | 419 | ) |
420 | | - obukhov_length = -0.3u"m" # initial Monin-Obukhov length |
| 420 | + obukhov_length = initial_obukhov_length |
421 | 421 |
|
422 | 422 | # initialise with zeros |
423 | 423 | convective_heat_flux = 0.0u"W/m^2" |
|
0 commit comments