-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve design of nonorographic gravity wave parameterization #3191
Conversation
src/parameterized_tendencies/gravity_wave_drag/non_orographic_gravity_wave.jl
Outdated
Show resolved
Hide resolved
src/parameterized_tendencies/gravity_wave_drag/non_orographic_gravity_wave.jl
Outdated
Show resolved
Hide resolved
src/parameterized_tendencies/gravity_wave_drag/non_orographic_gravity_wave.jl
Show resolved
Hide resolved
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) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) | |
) |
The form B0 = @. sign(c_hat0) ...
points B0
to new memory. the form I suggested will mutate B0
in-place
function reduce_fun1(a, b) | ||
return ifelse(a[1] < b[1], a, b) | ||
end | ||
|
||
function reduce_fun2(a, b) | ||
return ifelse(b[1] < 0, a, b) | ||
end | ||
|
||
function reduce_fun3(a, b) | ||
return ifelse(a[1] > 0, b, a) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function reduce_fun1(a, b) | |
return ifelse(a[1] < b[1], a, b) | |
end | |
function reduce_fun2(a, b) | |
return ifelse(b[1] < 0, a, b) | |
end | |
function reduce_fun3(a, b) | |
return ifelse(a[1] > 0, b, a) | |
end | |
@inline reduce_fun1(a, b) = ifelse(a[1] < b[1], a, b) | |
@inline reduce_fun2(a, b) = ifelse(b[1] < 0, a, b) | |
@inline reduce_fun3(a, b) = ifelse(a[1] > 0, b, a) |
artifacts/Artifacts.toml
Outdated
[topo-info] | ||
git-tree-sha1 = "9970989c13c2ad015ab5738d42fd9f5b320f1451" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to add this to the commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not, let's remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few suggestions, but this is a good step forward.
3d65dc9
to
2d0612e
Compare
2d0612e
to
d688218
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good step forward. @charleskawczynski @dennisYatunin Could you take a look again?
src/parameterized_tendencies/gravity_wave_drag/non_orographic_gravity_wave.jl
Show resolved
Hide resolved
@inline reduce_fun1(a, b) = ifelse(a[1] < b[1], a, b) | ||
@inline reduce_fun2(a, b) = ifelse(b[1] < 0, a, b) | ||
@inline reduce_fun3(a, b) = ifelse(a[1] > 0, b, a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you come up with some more informative names for these functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
end | ||
source_level = source_level_z.:2 | ||
|
||
Operators.column_mapreduce!(sign, +, damp_level, ᶜz) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dennisYatunin Would something like @. damp_level = Spaces.nlevels(axes(ᶜz))
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it and found that @. damp_level = Spaces.nlevels(axes(ᶜz)) could not work, but we can use fill!(damp_level, Spaces.nlevels(axes(ᶜz))) instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, damp_level .= Spaces.nlevels(axes(ᶜz))
or fill!(damp_level, Spaces.nlevels(axes(ᶜz))
would be better here
@@ -388,3 +446,7 @@ end | |||
function calc_intermitency(ρ_source_level, source_ampl, nk, Bsum) | |||
return (source_ampl / ρ_source_level / nk) / Bsum | |||
end | |||
|
|||
@inline reduce_fun1(a, b) = ifelse(a[1] < b[1], a, b) | |||
@inline reduce_fun2(a, b) = ifelse(b[1] < 0, a, b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@inline reduce_fun2(a, b) = ifelse(b[1] < 0, a, b) | |
@inline reduce_fun2(a, b) = ifelse(b[1] <= 0, a, b) |
(I think this is exactly the same as the previous logic, although it probably doesn't matter much)
|
||
@inline reduce_fun1(a, b) = ifelse(a[1] < b[1], a, b) | ||
@inline reduce_fun2(a, b) = ifelse(b[1] < 0, a, b) | ||
@inline reduce_fun3(a, b) = ifelse(a[1] > 0, b, a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@inline reduce_fun3(a, b) = ifelse(a[1] > 0, b, a) | |
@inline reduce_fun3(a, b) = ifelse(a[1] >= 0, b, a) |
append!(ᶜρ, ᶜρ[end] * ᶜρ[end] / ᶜρ[end - 1]) | ||
append!(ᶜbf, ᶜbf[end]) | ||
append!(ᶜz, FT(2) * ᶜz[end] - ᶜz[end - 1]) | ||
ᶜu = vcat(old_ᶜu, FT(2) * old_ᶜu[end] - old_ᶜu[end - 1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to note, vcat
is not really fixing the issue here, but the change is fine.
Please feel free to rebase and merge, thanks! |
Purpose
Part of #897
To-do
getindex
.Fields.bycolumn
andparent
.non_orographic_gravity_wave_forcing
function to be a pointwise function.Content
append!
Fields.bycolumn
andparent
.findlast
andfindfirst
non_orographic_gravity_wave_forcing
to be purely functional .