-
Notifications
You must be signed in to change notification settings - Fork 191
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
One-sided upwind reconstruction #3658
Conversation
@inline C★(::WENO{6}, ::Val{2}) = 100/231 | ||
@inline C★(::WENO{6}, ::Val{3}) = 25/77 | ||
@inline C★(::WENO{6}, ::Val{4}) = 5/77 | ||
@inline C★(::WENO{6}, ::Val{5}) = 1/462 |
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 a name change?
src/Advection/weno_interpolants.jl
Outdated
|
||
for stencil in 0:buffer-1 | ||
@eval @inline biased_β(ψ, scheme::WENO{$buffer, FT}, ::Val{$stencil}) where FT = | ||
smoothness_sum(scheme, ψ, FT.($(smoothness_coefficients(Val(buffer), Val(stencil))))) |
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.
it may be better to use map
vs broadcasting where this is easy, I think this could affect precompilation time
end | ||
end | ||
end | ||
@inline function biased_weno_weights(ijk, scheme::WENO{N, FT}, bias, dir, ::VelocityStencil, u, v) where {N, FT} |
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.
here bias
is a boolean where true
means left biased and false
means right biased? is that right? I think it makes sense to document this.
src/Advection/weno_interpolants.jl
Outdated
@@ -364,62 +371,51 @@ end | |||
# Calculation of WENO reconstructed value v⋆ = ∑ᵣ(wᵣv̂ᵣ) | |||
for buffer in [2, 3, 4, 5, 6] | |||
@eval begin | |||
@inline stencil_sum(scheme::WENO{$buffer}, ψ, w, func, cT, val, idx, loc) = @inbounds $(metaprogrammed_stencil_sum(buffer)) | |||
@inline stencil_sum(scheme::WENO{$buffer}, bias, ψ, w, cT, val, idx, loc) = @inbounds $(metaprogrammed_stencil_sum(buffer)) |
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.
following the breadcrumbs of this argument bias
leads here but I don't understand how this works in the end.
src/Advection/weno_interpolants.jl
Outdated
@inline S₂₆(S, left_bias) = @inbounds ifelse(left_bias, (S[4], S[5], S[6], S[7], S[8], S[9]), (S[9], S[8], S[7], S[6], S[5], S[4])) | ||
@inline S₃₆(S, left_bias) = @inbounds ifelse(left_bias, (S[3], S[4], S[5], S[6], S[7], S[8]), (S[10], S[9], S[8], S[7], S[6], S[5])) | ||
@inline S₄₆(S, left_bias) = @inbounds ifelse(left_bias, (S[2], S[3], S[4], S[5], S[6], S[7]), (S[11], S[10], S[9], S[8], S[7], S[6])) | ||
@inline S₅₆(S, left_bias) = @inbounds ifelse(left_bias, (S[1], S[2], S[3], S[4], S[5], S[6]), (S[12], S[11], S[10], S[9], S[8], S[7])) |
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.
left_bias
is a much clearer argument name than bias
. So left_bias == true
is left biased and false
means right-biased?
A few comments:
|
I have changed the |
Global ocean benchmarks (from prototype_omip_simulation.jl) using tracer_advection = TracerAdvection(WENO(; order = 7), WENO(; order =7), Centered())
momentum_advection = WENOVectorInvariant() On Main![]() On this branch![]() |
@inbounds ifelse(left_bias, $(calc_reconstruction_stencil(buffer, :left, :x, true)), | ||
$(calc_reconstruction_stencil(buffer, :right, :x, true))) | ||
@inline inner_biased_interpolate_xᶠᵃᵃ(i, j, k, grid, ::UX{$buffer, FT}, bias, ψ::Function, idx, loc, args...) where FT = | ||
@inbounds ifelse(bias == LeftBias(), $(calc_reconstruction_stencil(buffer, :left, :x, true)), |
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.
@inbounds ifelse(bias == LeftBias(), $(calc_reconstruction_stencil(buffer, :left, :x, true)), | |
@inbounds ifelse(bias isa LeftBias, $(calc_reconstruction_stencil(buffer, :left, :x, true)), |
not a necessary change, but saves a few characters and might be easier to read
Yet another optimization for upwind stencil computations.
The pattern in Oceananigans to perform upwind reconstruction is roughly:
This means that we are always performing the reconstruction twice. This is not a huge problem for linear reconstruction schemes (
UpwindBiased
) but leads to register blowup forWENO
schemes that are extremely heavy to compute.This PR aims to push the
left
-right
choice inside the reconstruction function by realizing that the only difference between left and right reconstruction is how the data is organized in the stencil.In this way, only one reconstruction is required significantly reducing register pressure, and consequently, computation time.
This follows the same pattern found in SpeedyWeather.jl
Some benchmarks are implemented in the NESAPOceananigans.jl repository.
Here are some timing tests on main with a NON-Immersed grid (launching julia with
julia --project="environments/main" --check-bounds=no
)The counterpart using the new branch
julia --project="environments/one_sided_branch" --check-bounds=no
P.S. some vestigial code not used is being removed as part of this PR because not beneficial (in terms of both accuracy and performance) that is