|
| 1 | +using Plots |
| 2 | + |
| 3 | +using SurfaceFluxes |
| 4 | +const SF = SurfaceFluxes |
| 5 | +SurfaceFluxes.error_on_non_convergence() = true |
| 6 | + |
| 7 | +import SurfaceFluxes.UniversalFunctions as UF |
| 8 | +import Thermodynamics |
| 9 | +Thermodynamics.print_warning() = false |
| 10 | + |
| 11 | +include(joinpath(pkgdir(SurfaceFluxes), "parameters", "create_parameters.jl")) |
| 12 | +const SFP = SurfaceFluxes.Parameters |
| 13 | +const FT = Float64; |
| 14 | + |
| 15 | +### Generate parameter lists |
| 16 | +toml_dict = CP.create_toml_dict(FT; dict_type = "alias") |
| 17 | +param_set = create_parameters(toml_dict, UF.Gryanik()) |
| 18 | +thermo_params = SFP.thermodynamics_params(param_set) |
| 19 | +uft = SFP.universal_func_type(param_set) |
| 20 | +### |
| 21 | + |
| 22 | +""" |
| 23 | +Here, we reproduce Figure 6.4 from Bonan (2019) Chapter 6. |
| 24 | +
|
| 25 | +# References |
| 26 | +- [Bonan2019](@cite) (Chapter 6 Figure 6.4) |
| 27 | +
|
| 28 | +# Original Research |
| 29 | +- [Physick2019](@cite) |
| 30 | +
|
| 31 | +""" |
| 32 | +T₀ = FT(273.15) |
| 33 | +z_star = FT(49) |
| 34 | +d = FT(19) |
| 35 | +h_c = FT(22) |
| 36 | +z0m = FT(0.6) # Figure 6.4 |
| 37 | +z0b = FT(0.135) * z0m |
| 38 | + |
| 39 | +u_star_stable = FT(0.13) |
| 40 | +u_star_unstable = FT(0.4) |
| 41 | +θ_star_stable = FT(0.06) |
| 42 | +θ_star_unstable = FT(-0.5) |
| 43 | + |
| 44 | +κ = SFP.von_karman_const(param_set) |
| 45 | + |
| 46 | +# For these measured values, see Chapter 6.6 page 89 of Bonan (2019) |
| 47 | +z_measured = FT[21, 29, 21]; |
| 48 | +u_measured = FT[1.0, 2.1, 1.0]; |
| 49 | +θ_measured = FT[29.0, 28.1, 29.5] .+ T₀ |
| 50 | + |
| 51 | +p_sfc = FT(99340) # Pa |
| 52 | +q_sfc = FT(0.0107) # kg/kg |
| 53 | + |
| 54 | +θ_sfc = FT(289.7) # K |
| 55 | +ts_sfc_test = Thermodynamics.PhaseEquil_pθq(thermo_params, 99340.0, 289.7, 0.0107) |
| 56 | +ts_int_test = Thermodynamics.PhaseEquil_pθq(thermo_params, 95342.0, 298.0, 0.0085) |
| 57 | +state_in = SurfaceFluxes.InteriorValues(FT(100), (FT(1.0), FT(0)), ts_int_test) |
| 58 | +state_sfc = SurfaceFluxes.SurfaceValues(FT(0), (FT(0), FT(0)), ts_sfc_test) |
| 59 | +sc = SurfaceFluxes.ValuesOnly{FT}(; state_in, state_sfc, z0m, z0b) |
| 60 | +ts_sfc_test = Thermodynamics.PhaseEquil_pθq(thermo_params, 100000.0, 289.7, 0.0) |
| 61 | +ts_int_test = Thermodynamics.PhaseEquil_pθq(thermo_params, 99990.0, 298.0, 0.0) |
| 62 | +Z = collect(range(FT(d + 10^-10), stop = FT(100), length = 250)) |
| 63 | + |
| 64 | +""" |
| 65 | +save_profile(param_set, sc, ca, L_MOs, Z, X_sfc, transport, uft, scheme, x_star, d) |
| 66 | +
|
| 67 | +Saves profiles of variable X given values of Z coordinates. Follows Nishizawa equation (21,22) |
| 68 | +
|
| 69 | +## Arguments |
| 70 | + - param_set: Abstract Parameter Set containing physical, thermodynamic parameters. |
| 71 | + - sc: Container for surface conditions based on known combination |
| 72 | + of the state vector, and {fluxes, friction velocity, exchange coefficients} for a given experiment |
| 73 | + - L_MOs: Monin-Obukhov length(s) |
| 74 | + - Z: Z coordinate(s) (within surface layer) for which variable values are required |
| 75 | + - X_sfc: For variable X, values at interior and surface nodes |
| 76 | + - transport: Transport type, (e.g. Momentum or Heat, used to determine physical scale coefficients) |
| 77 | + - uft: A Universal Function type, (returned by, e.g., Businger()) |
| 78 | + - scheme: Discretization scheme (currently supports FD and FV) |
| 79 | + - rsl : Roughness Sublayer Formulation (e.g. NoRSL, PhysickRSL, DeRidderRSL) |
| 80 | + - x_star: characteristic scale for variable x |
| 81 | + - d: Displacement height (measure of the spatial lengthscale of the effect of the canopy roughness on near-wall turbulence) |
| 82 | +""" |
| 83 | +function save_profile( |
| 84 | + param_set::SurfaceFluxes.APS, |
| 85 | + sc::SurfaceFluxes.AbstractSurfaceConditions, |
| 86 | + L_MOs::Array{FT, 1}, |
| 87 | + Z::Array{FT, 1}, |
| 88 | + X_sfc, |
| 89 | + transport, |
| 90 | + uft::UF.AUFT, |
| 91 | + scheme::Union{SurfaceFluxes.FVScheme, SurfaceFluxes.FDScheme}, |
| 92 | + rsl::SurfaceFluxes.AbstractRoughnessSublayerType, |
| 93 | + x_star, |
| 94 | + d; |
| 95 | + title = nothing, |
| 96 | + xlims = nothing, |
| 97 | + ylims = nothing, |
| 98 | + xlabel = "u(z)", |
| 99 | + ylabel = "z", |
| 100 | + fig_prefix = "", |
| 101 | + xaxis = :identity, |
| 102 | + yaxis = :identity, |
| 103 | +) |
| 104 | + Plots.plot() |
| 105 | + for L_MO in L_MOs |
| 106 | + x_i = map(Z) do z |
| 107 | + Zi = typeof(rsl) == SurfaceFluxes.NoRSL ? FT(z - d) : FT(z) |
| 108 | + state_in = SurfaceFluxes.InteriorValues(FT(Zi), (FT(1.0), FT(0)), ts_int_test) |
| 109 | + state_sfc = SurfaceFluxes.SurfaceValues(FT(0), (FT(0), FT(0)), ts_sfc_test) |
| 110 | + sc = SurfaceFluxes.ValuesOnly{FT}(; state_in, state_sfc, z0m, z0b) |
| 111 | + rsc = SurfaceFluxes.surface_conditions(param_set, sc, SurfaceFluxes.FDScheme()) |
| 112 | + dx = SurfaceFluxes.recover_profile(param_set, sc, L_MO, Zi, X_sfc, x_star, transport, uft, scheme, rsl) |
| 113 | + end |
| 114 | + |
| 115 | + uf = UF.universal_func(uft, L_MO, SFP.uf_params(param_set)) |
| 116 | + _π_group = FT(UF.π_group(uf, transport)) |
| 117 | + |
| 118 | + Δx = @. (x_i - X_sfc) |
| 119 | + |
| 120 | + Plots.plot!(Δx, Z, label = "L_MO = $L_MO") |
| 121 | + Plots.plot!(; title, xlabel, ylabel, ylims, xlims, grid = :off, legend = :outerright, titlefontalign = :center) |
| 122 | + |
| 123 | + Plots.savefig("$(fig_prefix)_profile.png") |
| 124 | + end |
| 125 | +end |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +# Save profile for unstable and stable L_MO set |
| 130 | +Stable_L_MOs = FT[30, 50, 1000] |
| 131 | +Unstable_L_MOs = FT[-10, -50, -1000] |
| 132 | + |
| 133 | +testcanopy = SurfaceFluxes.SparseCanopy{FT}(d, z_star) |
| 134 | +PhysickRSL = SurfaceFluxes.PhysickRSL(testcanopy) |
| 135 | +NoRSL = SurfaceFluxes.NoRSL() |
| 136 | + |
| 137 | + |
| 138 | +# Bonan2019 Fig. 6.4a (With PG95 RSL) |
| 139 | +save_profile( |
| 140 | + param_set, |
| 141 | + sc, |
| 142 | + Unstable_L_MOs, |
| 143 | + Z, |
| 144 | + FT(0), |
| 145 | + UF.MomentumTransport(), |
| 146 | + uft, |
| 147 | + SurfaceFluxes.FDScheme(), |
| 148 | + PhysickRSL, |
| 149 | + u_star_unstable, |
| 150 | + d; |
| 151 | + xlims = (0, 4), |
| 152 | + ylims = (15, 50), |
| 153 | + fig_prefix = "Fig6.4a_canopy", |
| 154 | + title = "Vertical Profile of Wind Velocity (PG95 RSL)", |
| 155 | +) |
| 156 | + |
| 157 | +# Bonan2019 Fig. 6.4a (No RSL Model) |
| 158 | +save_profile( |
| 159 | + param_set, |
| 160 | + sc, |
| 161 | + Unstable_L_MOs, |
| 162 | + Z, |
| 163 | + FT(0), |
| 164 | + UF.MomentumTransport(), |
| 165 | + uft, |
| 166 | + SurfaceFluxes.FDScheme(), |
| 167 | + NoRSL, |
| 168 | + u_star_unstable, |
| 169 | + d; |
| 170 | + xlims = (0, 4), |
| 171 | + ylims = (15, 50), |
| 172 | + fig_prefix = "Fig6.4a", |
| 173 | + title = "Vertical Profile of Wind Velocity (No RSL Model)", |
| 174 | +) |
| 175 | + |
| 176 | +# Bonan2019 Fig. 6.4b (With PG95 RSL) |
| 177 | +save_profile( |
| 178 | + param_set, |
| 179 | + sc, |
| 180 | + Unstable_L_MOs, |
| 181 | + Z, |
| 182 | + θ_sfc, |
| 183 | + UF.HeatTransport(), |
| 184 | + uft, |
| 185 | + SurfaceFluxes.FDScheme(), |
| 186 | + PhysickRSL, |
| 187 | + θ_star_unstable, |
| 188 | + d; |
| 189 | + xlims = (-8, 0), |
| 190 | + ylims = (15, 50), |
| 191 | + xlabel = "θ - θ_sfc", |
| 192 | + fig_prefix = "Fig6.4b_canopy", |
| 193 | + title = "Vertical Profile of Temperature (PG95 RSL)", |
| 194 | +) |
| 195 | + |
| 196 | +# Bonan2019 Fig. 6.4b (No RSL Model) |
| 197 | +save_profile( |
| 198 | + param_set, |
| 199 | + sc, |
| 200 | + Unstable_L_MOs, |
| 201 | + Z, |
| 202 | + θ_sfc, |
| 203 | + UF.HeatTransport(), |
| 204 | + uft, |
| 205 | + SurfaceFluxes.FDScheme(), |
| 206 | + NoRSL, |
| 207 | + θ_star_unstable, |
| 208 | + d; |
| 209 | + xlims = (-8, 0), |
| 210 | + ylims = (15, 50), |
| 211 | + xlabel = "θ- θ_sfc", |
| 212 | + fig_prefix = "Fig6.4b", |
| 213 | + title = "Vertical Profile of Temperature (No RSL Model)", |
| 214 | +) |
| 215 | + |
| 216 | +# Bonan2019 Fig. 6.4c (With PG95 RSL) |
| 217 | +save_profile( |
| 218 | + param_set, |
| 219 | + sc, |
| 220 | + Stable_L_MOs, |
| 221 | + Z, |
| 222 | + FT(0), |
| 223 | + UF.MomentumTransport(), |
| 224 | + uft, |
| 225 | + SurfaceFluxes.FDScheme(), |
| 226 | + PhysickRSL, |
| 227 | + u_star_stable, |
| 228 | + d; |
| 229 | + xlims = (0, 4), |
| 230 | + ylims = (15, 50), |
| 231 | + fig_prefix = "Fig6.4c_canopy", |
| 232 | + title = "Vertical Profile of Wind Velocity (PG95 RSL)", |
| 233 | +) |
| 234 | + |
| 235 | +# Bonan2019 Fig. 6.4c (No RSL Model) |
| 236 | +save_profile( |
| 237 | + param_set, |
| 238 | + sc, |
| 239 | + Stable_L_MOs, |
| 240 | + Z, |
| 241 | + FT(0), |
| 242 | + UF.MomentumTransport(), |
| 243 | + uft, |
| 244 | + SurfaceFluxes.FDScheme(), |
| 245 | + NoRSL, |
| 246 | + u_star_stable, |
| 247 | + d; |
| 248 | + xlims = (0, 4), |
| 249 | + ylims = (15, 50), |
| 250 | + fig_prefix = "Fig6.4c", |
| 251 | + title = "Vertical Profile of Wind Velocity (No RSL Model)", |
| 252 | +) |
| 253 | + |
| 254 | +# Bonan2019 Fig. 6.4d (With PG95 RSL) |
| 255 | +save_profile( |
| 256 | + param_set, |
| 257 | + sc, |
| 258 | + Stable_L_MOs, |
| 259 | + Z, |
| 260 | + θ_sfc, |
| 261 | + UF.HeatTransport(), |
| 262 | + uft, |
| 263 | + SurfaceFluxes.FDScheme(), |
| 264 | + PhysickRSL, |
| 265 | + θ_star_stable, |
| 266 | + d; |
| 267 | + xlims = (0, 2), |
| 268 | + ylims = (15, 50), |
| 269 | + xlabel = "θ-θ_sfc", |
| 270 | + fig_prefix = "Fig6.4d_canopy", |
| 271 | + title = "Vertical Profile of Temperature (PG95 RSL)", |
| 272 | +) |
| 273 | + |
| 274 | +# Bonan2019 Fig. 6.4d (No RSL Model) |
| 275 | +save_profile( |
| 276 | + param_set, |
| 277 | + sc, |
| 278 | + Stable_L_MOs, |
| 279 | + Z, |
| 280 | + θ_sfc, |
| 281 | + UF.HeatTransport(), |
| 282 | + uft, |
| 283 | + SurfaceFluxes.FDScheme(), |
| 284 | + NoRSL, |
| 285 | + θ_star_stable, |
| 286 | + d; |
| 287 | + xlims = (0, 2), |
| 288 | + ylims = (15, 50), |
| 289 | + xlabel = "θ-θ_sfc", |
| 290 | + fig_prefix = "Fig6.4d", |
| 291 | + title = "Vertical Profile of Temperature (No RSL Model)", |
| 292 | +) |
0 commit comments