From 57503113ad3c6a206a3df3d296ee1e0ed3b93a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E8=90=A7=E6=B6=AF?= Date: Fri, 12 Jul 2024 15:00:20 -0700 Subject: [PATCH] revise 1 --- artifacts/Artifacts.toml | 2 + .../non_orographic_gravity_wave.jl | 122 +++++++++++------- .../nogw_test_3d.jl | 2 +- .../nogw_test_mima.jl | 2 +- .../nogw_test_single_column.jl | 2 +- 5 files changed, 80 insertions(+), 50 deletions(-) create mode 100644 artifacts/Artifacts.toml diff --git a/artifacts/Artifacts.toml b/artifacts/Artifacts.toml new file mode 100644 index 00000000000..01b5ad26220 --- /dev/null +++ b/artifacts/Artifacts.toml @@ -0,0 +1,2 @@ +[topo-info] +git-tree-sha1 = "9970989c13c2ad015ab5738d42fd9f5b320f1451" diff --git a/src/parameterized_tendencies/gravity_wave_drag/non_orographic_gravity_wave.jl b/src/parameterized_tendencies/gravity_wave_drag/non_orographic_gravity_wave.jl index a4726fcbaec..761eaba15f9 100644 --- a/src/parameterized_tendencies/gravity_wave_drag/non_orographic_gravity_wave.jl +++ b/src/parameterized_tendencies/gravity_wave_drag/non_orographic_gravity_wave.jl @@ -28,19 +28,19 @@ function non_orographic_gravity_wave_cache( nc = Int(floor(FT(2 * cmax / dc + 1))) c = [FT((n - 1) * dc - cmax) for n in 1:nc] - source_level_z = similar(Fields.level(Y.c.ρ,1),Tuple{FT,FT}) - ᶜlevel = similar(Y.c.ρ,FT) - for i in 1: size(Fields.field_values(Y.c.ρ),4) - fill!(Fields.level(ᶜlevel,i),i); + source_level_z = similar(Fields.level(Y.c.ρ,1), Tuple{FT,FT}) + ᶜlevel = similar(Y.c.ρ, FT) + for i in 1:size(Fields.field_values(Y.c.ρ), 4) + fill!(Fields.level(ᶜlevel,i), i) end - damp_level_z=source_level_z + damp_level_z= source_level_z return (; gw_source_height = source_height, gw_source_ampl = Bt_0 .* ones(FT, axes(Fields.level(Y.c.ρ, 1))), gw_Bw = Bw .* ones(FT, axes(Fields.level(Y.c.ρ, 1))), gw_Bn = Bn .* ones(FT, axes(Fields.level(Y.c.ρ, 1))), gw_B0 = similar(c), - gw_c = c, + gw_c = c, gw_cw = cw .* ones(FT, axes(Fields.level(Y.c.ρ, 1))), gw_cn = cn .* ones(FT, axes(Fields.level(Y.c.ρ, 1))), gw_c0 = c0, @@ -53,10 +53,10 @@ function non_orographic_gravity_wave_cache( source_level = similar(Fields.level(Y.c.ρ, 1)), damp_level = similar(Fields.level(Y.c.ρ, 1)), ᶜlevel, - u_phy=similar(Y.c.ρ), - v_phy=similar(Y.c.ρ), - uforcing=similar(Y.c.ρ), - vforcing=similar(Y.c.ρ), + u_phy = similar(Y.c.ρ), + v_phy = similar(Y.c.ρ), + uforcing = similar(Y.c.ρ), + vforcing = similar(Y.c.ρ), ) end @@ -82,6 +82,13 @@ function non_orographic_gravity_wave_cache( gw_Bw = ones(FT, axes(lat)) .* Bw gw_cn = ones(FT, axes(lat)) .* cn + source_level_z = similar(Fields.level(Y.c.ρ,1), Tuple{FT,FT}) + ᶜlevel = similar(Y.c.ρ, FT) + for i in 1:size(Fields.field_values(Y.c.ρ), 4) + fill!(Fields.level(ᶜlevel,i), i); + end + damp_level_z = source_level_z + # This is GFDL source specs -> a smooth function # source_ampl = @. Bt_0 + # Bt_n * FT(0.5) * (FT(1) + tanh((lat - ϕ0_n) / dϕ_n)) + @@ -123,10 +130,11 @@ function non_orographic_gravity_wave_cache( damp_level_z, source_level = similar(Fields.level(Y.c.ρ, 1)), damp_level = similar(Fields.level(Y.c.ρ, 1)), - u_phy=similar(Y.c.ρ), - v_phy=similar(Y.c.ρ), - uforcing=similar(Y.c.ρ), - vforcing=similar(Y.c.ρ), + ᶜlevel, + u_phy = similar(Y.c.ρ), + v_phy = similar(Y.c.ρ), + uforcing = similar(Y.c.ρ), + vforcing = similar(Y.c.ρ), ) end @@ -141,7 +149,19 @@ function non_orographic_gravity_wave_tendency!( (; ᶜT,) = p.core (; ᶜts) = p.precomputed (; params) = p - (; ᶜdTdz, ᶜbuoyancy_frequency,source_level,source_level_z,damp_level,source_level_z,u_phy,v_phy,uforcing,vforcing,ᶜlevel) = p.non_orographic_gravity_wave + (; + ᶜdTdz, + ᶜbuoyancy_frequency, + source_level, + source_level_z, + damp_level, + damp_level_z, + u_phy, + v_phy, + uforcing, + vforcing, + ᶜlevel, + ) = p.non_orographic_gravity_wave (; model_config) = p.atmos (; gw_source_ampl, @@ -184,10 +204,15 @@ function non_orographic_gravity_wave_tendency!( if model_config isa SingleColumnModel # source level: the index of the level that is closest to the source height - Operators.column_mapreduce!(reduce_fun1, source_level_z, ᶜz, ᶜlevel) do z, level - (abs.(z .- gw_source_height),level) + Operators.column_mapreduce!( + reduce_fun1, + source_level_z, + ᶜz, + ᶜlevel, + ) do z, level + (abs.(z .- gw_source_height), level) end - source_level=source_level_z.:2 + source_level = source_level_z.:2 Operators.column_mapreduce!(sign, +, damp_level, ᶜz) @@ -195,18 +220,28 @@ function non_orographic_gravity_wave_tendency!( (; ᶜp) = p.precomputed # source level: the index of the highest level whose pressure is higher than source pressure - Operators.column_mapreduce!(reduce_fun2, source_level_z, ᶜp, ᶜlevel) do p, level - (p .- gw_source_pressure,level) + Operators.column_mapreduce!( + reduce_fun2, + source_level_z, + ᶜp, + ᶜlevel + ) do p, level + (p .- gw_source_pressure, level) end - source_level=source_level_z.:2 + source_level = source_level_z.:2 # damp level: the index of the lowest level whose pressure is lower than the damp pressure - Operators.column_mapreduce!(reduce_fun3, damp_level_z, ᶜp, ᶜlevel) do p, level - (p .- gw_damp_pressure,level) + Operators.column_mapreduce!( + reduce_fun3, + damp_level_z, + ᶜp, + ᶜlevel + ) do p, level + (p .- gw_damp_pressure, level) end - damp_level=damp_level_z.:2 + damp_level = damp_level_z.:2 end @@ -287,17 +322,20 @@ function non_orographic_gravity_wave_forcing( FT = eltype(old_ᶜz) # add an extra layer above model top so that forcing between the very top # model layer and the upper boundary can be calculated - ᶜu=vcat(old_ᶜu,FT(2) * old_ᶜu[end] - old_ᶜu[end - 1]) - ᶜρ=vcat(old_ᶜρ,old_ᶜρ[end] * old_ᶜρ[end] / old_ᶜρ[end - 1]) - ᶜbf=vcat(old_ᶜbf,old_ᶜbf[end]) - ᶜz=vcat(old_ᶜz,FT(2) * old_ᶜz[end] - old_ᶜz[end - 1]) + ᶜu = vcat(old_ᶜu, FT(2) * old_ᶜu[end] - old_ᶜu[end - 1]) + ᶜρ = vcat(old_ᶜρ, old_ᶜρ[end] * old_ᶜρ[end] / old_ᶜρ[end - 1]) + ᶜbf = vcat(old_ᶜbf, old_ᶜbf[end]) + ᶜz = vcat(old_ᶜz, FT(2) * old_ᶜz[end] - old_ᶜz[end - 1]) # wave spectra and the source amplitude nc = length(c) c_hat0 = c .- ᶜu[source_level] # c0mu0 - B0 =@. sign(c_hat0)* (Bw * exp(-log(2.0) * ((c * flag + c_hat0 * (1 - flag) - c0) / cw)^2)+ Bn *exp(-log(2.0) * ((c * flag + c_hat0 * (1 - flag) - c0) / cn)^2)) + B0 = @. sign(c_hat0) * ( + Bw * exp(-log(2.0) * ((c * flag + c_hat0 * (1 - flag) - c0) / cw)^2) + + Bn * exp(-log(2.0) * ((c * flag + c_hat0 * (1 - flag) - c0) / cn)^2) + ) Bsum = sum(abs.(B0)) if (Bsum == 0.0) @@ -415,30 +453,20 @@ function calc_intermitency(ρ_source_level, source_ampl, nk, Bsum) return (source_ampl / ρ_source_level / nk) / Bsum end -function reduce_fun1(a,b) - return ifelse( - a[1]0, - b, - a, - ) +function reduce_fun3(a, b) + return ifelse(a[1] > 0, b, a) end + diff --git a/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_3d.jl b/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_3d.jl index 95113e1c283..45cbe75b0c5 100644 --- a/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_3d.jl +++ b/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_3d.jl @@ -122,7 +122,7 @@ center_u_zonalave = mean(center_u, dims = 1)[1, :, :, :] center_bf_zonalave = mean(center_bf, dims = 1)[1, :, :, :] center_ρ_zonalave = mean(center_ρ, dims = 1)[1, :, :, :] -B0=similar(params.gw_c) +B0 = similar(params.gw_c) # Jan month = Dates.month.(time) diff --git a/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_mima.jl b/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_mima.jl index 18dea363174..13719a2589f 100644 --- a/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_mima.jl +++ b/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_mima.jl @@ -125,7 +125,7 @@ bf = @. ifelse(bf < 2.5e-5, sqrt(2.5e-5), sqrt(abs(bf))) # compute u/v forcings from convective gravity waves params = non_orographic_gravity_wave(lat, FT) -B0=similar(params.gw_c) +B0 = similar(params.gw_c) # nogw forcing kmax = length(pfull) - 1 diff --git a/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_single_column.jl b/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_single_column.jl index 11b337fad1d..aa98a18a510 100644 --- a/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_single_column.jl +++ b/test/parameterized_tendencies/gravity_wave/non_orographic_gravity_wave/nogw_test_single_column.jl @@ -129,7 +129,7 @@ ENV["GKSwstype"] = "nul" output_dir = "nonorographic_gravity_wave_test_single_column" mkpath(output_dir) -B0=similar(params.gw_c) +B0 = similar(params.gw_c) # Jan Jan_u = mean(center_u_mean[:, month .== 1], dims = 2)[:, 1]