Skip to content

A rework for the advection module that (should) improve WENO performance #4434

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

Draft
wants to merge 197 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
197 commits
Select commit Hold shift + click to select a range
b07b4e5
FMA
simone-silvestri Apr 16, 2025
1506eed
muladd
simone-silvestri Apr 16, 2025
885e724
add stencils
simone-silvestri Apr 16, 2025
3354386
good stencils
simone-silvestri Apr 16, 2025
ce9d408
start with this
simone-silvestri Apr 16, 2025
d9a2348
thins kind of works
simone-silvestri Apr 16, 2025
52b332a
start with this
simone-silvestri Apr 16, 2025
362764a
optimize
simone-silvestri Apr 16, 2025
a671d18
finished
simone-silvestri Apr 16, 2025
dc3935b
remove it
simone-silvestri Apr 17, 2025
483f44a
remove them
simone-silvestri Apr 17, 2025
f897264
fix
simone-silvestri Apr 17, 2025
bcbdd9c
correct validation
simone-silvestri Apr 17, 2025
b1e5a54
keep these as is
simone-silvestri Apr 17, 2025
93564a1
this works!
simone-silvestri Apr 17, 2025
4f98cdb
Merge remote-tracking branch 'origin/ss/remove-stretched-coeffs' into…
simone-silvestri Apr 17, 2025
fcae428
don't need this
simone-silvestri Apr 17, 2025
3b4cd39
go ahead
simone-silvestri Apr 17, 2025
9304947
remove redundant loop
simone-silvestri Apr 17, 2025
8e32bc1
this works! NICE!
simone-silvestri Apr 17, 2025
6cf1a0f
Merge branch 'main' into ss/remove-stretched-coeffs
simone-silvestri Apr 17, 2025
cfff4c4
flat fluxes
simone-silvestri Apr 17, 2025
0998550
Merge branch 'ss/remove-stretched-coeffs' of github.com:CliMA/Oceanan…
simone-silvestri Apr 17, 2025
3a3213f
flat fluxes
simone-silvestri Apr 17, 2025
5d5ec46
again flat stuff
simone-silvestri Apr 17, 2025
c6762b7
flat interpolations
simone-silvestri Apr 17, 2025
e3e1c72
biased to symmetric
simone-silvestri Apr 17, 2025
af62962
change symmetric
simone-silvestri Apr 17, 2025
390967e
just use this
simone-silvestri Apr 17, 2025
a6c534e
Merge remote-tracking branch 'origin/ss/remove-stretched-coeffs' into…
simone-silvestri Apr 17, 2025
4854689
love this
simone-silvestri Apr 17, 2025
472790f
just test it as is?
simone-silvestri Apr 17, 2025
8aab10c
soooo much simpler
simone-silvestri Apr 17, 2025
91d1a90
add a comment
simone-silvestri Apr 17, 2025
e3345ff
remove also this one
simone-silvestri Apr 17, 2025
5df779f
adapt order
simone-silvestri Apr 17, 2025
af586bd
fixed weno vector invariant
simone-silvestri Apr 17, 2025
84da70e
Merge remote-tracking branch 'origin/ss/remove-stretched-coeffs' into…
simone-silvestri Apr 17, 2025
39c5c2c
make sure the FT is correct
simone-silvestri Apr 17, 2025
5452cb8
a little clarity
simone-silvestri Apr 17, 2025
08ee0c2
add a comment
simone-silvestri Apr 17, 2025
5067e9b
start this
simone-silvestri Apr 17, 2025
2e94c44
adding some fallbacks
simone-silvestri Apr 17, 2025
4cad6eb
just immersed to go!
simone-silvestri Apr 17, 2025
0600e08
amazing
simone-silvestri Apr 17, 2025
20f2ef8
try it like this
simone-silvestri Apr 17, 2025
95cec39
remove this as well
simone-silvestri Apr 17, 2025
d707b12
no buffer scheme!
simone-silvestri Apr 17, 2025
74e96b9
test it like this
simone-silvestri Apr 17, 2025
953f26f
small fix
simone-silvestri Apr 17, 2025
f32b7fd
test with random
simone-silvestri Apr 17, 2025
424535b
add the val here
simone-silvestri Apr 17, 2025
0c1f11f
this should work now?
simone-silvestri Apr 17, 2025
dff2745
just make it work for now
simone-silvestri Apr 17, 2025
6cd21c1
remove this
simone-silvestri Apr 17, 2025
ebe429c
test stuff
simone-silvestri Apr 17, 2025
dcc2a3c
remove ord
simone-silvestri Apr 17, 2025
af3f08b
better
simone-silvestri Apr 17, 2025
89918be
Merge branch 'main' into ss/remove-stretched-coeffs
simone-silvestri Apr 17, 2025
365ce4c
let's go
simone-silvestri Apr 17, 2025
4806bf4
more bugfix
simone-silvestri Apr 17, 2025
7305ade
remove unused stuff
simone-silvestri Apr 17, 2025
bf8f021
might try like this
simone-silvestri Apr 17, 2025
3be592f
remove abiguity
simone-silvestri Apr 17, 2025
c70a0d8
not sure but try it like this
simone-silvestri Apr 17, 2025
b3363c7
ok this seems to work
simone-silvestri Apr 17, 2025
6263c84
Update src/Advection/adapt_advection_order.jl
simone-silvestri Apr 17, 2025
064eaeb
Merge branch 'main' into ss/remove-stretched-coeffs
simone-silvestri Apr 17, 2025
413abd7
removed all runtime dispatch
simone-silvestri Apr 17, 2025
22b8145
remove also the bias
simone-silvestri Apr 17, 2025
5527fe6
more updates
simone-silvestri Apr 17, 2025
5488817
try it out
simone-silvestri Apr 17, 2025
44bb8e3
try like this for the moment
simone-silvestri Apr 17, 2025
51edbf9
back to how it was
simone-silvestri Apr 17, 2025
743740b
more changes
simone-silvestri Apr 17, 2025
6e2db1c
maybe try this?
simone-silvestri Apr 17, 2025
79ecf95
try like this
simone-silvestri Apr 17, 2025
bafbc02
try JS weno
simone-silvestri Apr 17, 2025
338cbab
try again with zweno
simone-silvestri Apr 17, 2025
721640f
this should be the same as before?
simone-silvestri Apr 17, 2025
3ebb5f0
back to before
simone-silvestri Apr 17, 2025
89e1c13
this is the whole shabang?
simone-silvestri Apr 17, 2025
ee6c409
not used anymore
simone-silvestri Apr 17, 2025
c07aa85
this should work egegiously
simone-silvestri Apr 17, 2025
a2caeaf
this should never be required?
simone-silvestri Apr 17, 2025
d8a09cd
disambiguation
simone-silvestri Apr 17, 2025
1a6f052
fix upwind first order
simone-silvestri Apr 17, 2025
160977c
correct reduced order
simone-silvestri Apr 17, 2025
2905b92
this should work
simone-silvestri Apr 17, 2025
630690f
bugfix
simone-silvestri Apr 17, 2025
06d5867
Merge branch 'ss/remove-stretched-coeffs' of github.com:CliMA/Oceanan…
simone-silvestri Apr 17, 2025
7624703
another bugfix
simone-silvestri Apr 17, 2025
9273b68
this should work now
simone-silvestri Apr 17, 2025
c4d0e62
this should work
simone-silvestri Apr 17, 2025
51b245c
ok tests should pass
simone-silvestri Apr 18, 2025
1e2459c
Merge remote-tracking branch 'origin/ss/remove-stretched-coeffs' into…
simone-silvestri Apr 18, 2025
9113cb6
need to figure this out a bit
simone-silvestri Apr 18, 2025
c743c86
add smoothness 6
simone-silvestri Apr 18, 2025
372ff8a
unify
simone-silvestri Apr 20, 2025
de79e7a
Merge remote-tracking branch 'origin/main' into ss/optimize-weno
simone-silvestri Apr 21, 2025
5c1e159
some changes
simone-silvestri Apr 21, 2025
6914d78
remove stuff
simone-silvestri Apr 21, 2025
77ba861
correct
simone-silvestri Apr 21, 2025
453277b
fix it
simone-silvestri Apr 21, 2025
30af263
this should work
simone-silvestri Apr 21, 2025
5ee703c
add the grid
simone-silvestri Apr 21, 2025
f521b52
remove this
simone-silvestri Apr 21, 2025
3c62954
add test
simone-silvestri Apr 22, 2025
81c5896
try like this
simone-silvestri Apr 22, 2025
b43a160
try like this
simone-silvestri Apr 22, 2025
ba1f01f
only one division
simone-silvestri Apr 22, 2025
d35f65c
known at compile time
simone-silvestri Apr 22, 2025
1991aa7
looks better now
simone-silvestri Apr 22, 2025
492490b
use fastmath in correct places
simone-silvestri Apr 22, 2025
3da3fe3
this should not give a nothing
simone-silvestri Apr 22, 2025
672607b
update
simone-silvestri Apr 22, 2025
55d745a
more correction
simone-silvestri Apr 22, 2025
eeee9d7
add
simone-silvestri Apr 22, 2025
5525c25
up to 9th order
simone-silvestri Apr 22, 2025
f8f2fe0
add some comments
simone-silvestri Apr 22, 2025
825118b
make sure we also account for the immersed boundary
simone-silvestri Apr 22, 2025
2415fd7
accounting fo an immersed boundary
simone-silvestri Apr 22, 2025
ab4f0e2
add commenr
simone-silvestri Apr 22, 2025
34aabb0
try with randoms
simone-silvestri Apr 22, 2025
8548855
gotta try like this?
simone-silvestri Apr 22, 2025
6cec08b
remove all the ifelses
simone-silvestri Apr 22, 2025
8545dd9
add fastmath decorator
simone-silvestri Apr 22, 2025
2ea6182
let's go!
simone-silvestri Apr 22, 2025
18e4b1e
these are not required
simone-silvestri Apr 22, 2025
9623a75
chenage if with ifelse
simone-silvestri Apr 22, 2025
939a7fe
forgot the `r`
simone-silvestri Apr 22, 2025
5a2210c
remove 11th order WENO
simone-silvestri Apr 22, 2025
46c7406
add comment
simone-silvestri Apr 22, 2025
f2fc7c5
cleanup a bit
simone-silvestri Apr 22, 2025
64648fe
cleanup more
simone-silvestri Apr 22, 2025
c86585e
add a comment
simone-silvestri Apr 22, 2025
7a557ff
comment
simone-silvestri Apr 22, 2025
4d3bb89
let's test this as well
simone-silvestri Apr 22, 2025
2771e83
some comments
simone-silvestri Apr 22, 2025
fb4dc44
done!
simone-silvestri Apr 22, 2025
76a548c
good comment
simone-silvestri Apr 22, 2025
9dc9d3b
comment
simone-silvestri Apr 22, 2025
198e2f9
align orders
simone-silvestri Apr 22, 2025
826d1c1
small comment
simone-silvestri Apr 22, 2025
9f05b87
change name
simone-silvestri Apr 22, 2025
e848dbb
go ahead
simone-silvestri Apr 22, 2025
759d3c0
clearer
simone-silvestri Apr 22, 2025
bac291e
small fix
simone-silvestri Apr 22, 2025
71a7228
remove high high order
simone-silvestri Apr 22, 2025
3078cdd
remove WENO 11th
simone-silvestri Apr 22, 2025
a9f8062
Add newton_div utility
glwagner Apr 22, 2025
7e17421
add a comment
glwagner Apr 22, 2025
dd547c8
Use newton_div in WENO
glwagner Apr 22, 2025
80ce48f
import
glwagner Apr 22, 2025
7152538
unify epsilons
glwagner Apr 22, 2025
aed2ac2
short circuit all-F32 div
glwagner Apr 22, 2025
91aa66d
Merge branch 'main' into newton-div
navidcy Apr 22, 2025
6ee3c3e
Update src/Utils/newton_div.jl
glwagner Apr 22, 2025
70ebd05
Update src/Utils/newton_div.jl
glwagner Apr 22, 2025
ac43795
Update src/Utils/newton_div.jl
glwagner Apr 22, 2025
b1a9c94
Update src/Utils/newton_div.jl
glwagner Apr 22, 2025
3ed606c
Merge branch 'main' into ss/optimize-weno
simone-silvestri Apr 22, 2025
1415298
remove 12th order
simone-silvestri Apr 22, 2025
d115c81
Merge branch 'ss/optimize-weno' of github.com:CliMA/Oceananigans.jl i…
simone-silvestri Apr 22, 2025
dc5ba56
remove 12th order
simone-silvestri Apr 22, 2025
6dfd3f2
fix it
simone-silvestri Apr 22, 2025
07e4c06
formatting
simone-silvestri Apr 22, 2025
a3535be
bugfix
simone-silvestri Apr 22, 2025
6dc5cdf
another bugfix
simone-silvestri Apr 22, 2025
c7e0041
try using float32
simone-silvestri Apr 22, 2025
8aa7125
reshuffle
simone-silvestri Apr 23, 2025
12225ce
preparing for removing division
simone-silvestri Apr 23, 2025
6a2009e
add fast math
simone-silvestri Apr 23, 2025
068d4dd
Merge branch 'ss/optimize-weno' of github.com:CliMA/Oceananigans.jl i…
simone-silvestri Apr 23, 2025
f6b9a64
Merge branch 'main' into ss/optimize-weno
simone-silvestri Apr 23, 2025
6f644e1
Merge branch 'main' into ss/optimize-weno
simone-silvestri Apr 23, 2025
2f8486c
Merge branch 'main' into ss/optimize-weno
simone-silvestri Apr 24, 2025
6907eab
Merge branch 'main' into ss/optimize-weno
simone-silvestri Apr 25, 2025
d2cebe4
just this
simone-silvestri Apr 25, 2025
107701e
Merge branch 'main' into ss/optimize-weno
simone-silvestri Apr 25, 2025
effacc3
make it work
simone-silvestri Apr 25, 2025
5109858
merge main
simone-silvestri Apr 25, 2025
6e73cb5
adding epsilon
simone-silvestri Apr 25, 2025
d8c3fb6
Merge branch 'ss/optimize-weno' of github.com:CliMA/Oceananigans.jl i…
simone-silvestri Apr 25, 2025
7b89480
Merge branch 'ss/optimize-weno' of github.com:CliMA/Oceananigans.jl i…
simone-silvestri Apr 25, 2025
772e07b
remember the reduced order
simone-silvestri Apr 25, 2025
3fdf27e
will this work?
simone-silvestri Apr 25, 2025
83e1779
fast math for smoothness
simone-silvestri Apr 26, 2025
7d31cff
should go here
simone-silvestri Apr 26, 2025
2e191b1
lower precision smoothness operation
simone-silvestri Apr 26, 2025
5127665
do not need this
simone-silvestri Apr 26, 2025
5a4ebe9
this does not help
simone-silvestri Apr 26, 2025
80ba59d
cast all to single precision
simone-silvestri Apr 26, 2025
c22c59c
this unfortunately breaks stuff
simone-silvestri Apr 26, 2025
36b5f72
Merge branch 'main' into ss/optimize-weno
simone-silvestri Apr 27, 2025
16e6050
Merge branch 'main' into ss/optimize-weno
simone-silvestri May 6, 2025
69f164a
Merge branch 'main' into ss/optimize-weno
simone-silvestri May 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Advection/Advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import Base: show, summary, Callable
import Oceananigans.Grids: required_halo_size_x, required_halo_size_y, required_halo_size_z
import Oceananigans.Architectures: on_architecture

using Oceananigans.Grids: XFlatGrid, YFlatGrid, ZFlatGrid

abstract type AbstractAdvectionScheme{B, FT} end
abstract type AbstractCenteredAdvectionScheme{B, FT} <: AbstractAdvectionScheme{B, FT} end
abstract type AbstractUpwindBiasedAdvectionScheme{B, FT} <: AbstractAdvectionScheme{B, FT} end
Expand All @@ -52,11 +54,11 @@ abstract type AbstractUpwindBiasedAdvectionScheme{B, FT} <: AbstractAdvectionSch
# are constructed via metaprogramming. (The `advection_buffer` is the width of
# the halo region required for an advection scheme on a non-immersed-boundary grid.)
# An upper limit of `advection_buffer = 6` means we can build advection schemes up to
# `Centered(order=12`) and `UpwindBiased(order=11)`. The list can be extended in order to
# `Centered(order=10`) and `UpwindBiased(order=9)`. The list can be extended in order to
# compile schemes with higher orders; for example `advection_buffers = [1, 2, 3, 4, 5, 6, 8]`
# will compile schemes for `advection_buffer=8` and thus `Centered(order=16)` and `UpwindBiased(order=15)`.
# Note that it is not possible to compile schemes for `advection_buffer = 41` or higher.
const advection_buffers = [1, 2, 3, 4, 5, 6]
const advection_buffers = [1, 2, 3, 4, 5]

@inline Base.eltype(::AbstractAdvectionScheme{<:Any, FT}) where FT = FT

Expand Down
7 changes: 4 additions & 3 deletions src/Advection/adapt_advection_order.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,22 @@ function adapt_advection_order(advection::Centered{B}, N::Int, grid::AbstractGri
if N >= B
return advection
else
return Centered(; order=2N)
return Centered(grid; order=2N)
end
end

function adapt_advection_order(advection::UpwindBiased{B}, N::Int, grid::AbstractGrid) where B
if N >= B
return advection
else
return UpwindBiased(; order=2N-1)
return UpwindBiased(grid; order=2N-1)
end
end

function adapt_advection_order(advection::WENO{B}, N::Int, grid::AbstractGrid) where B
if N >= B
return advection
else
return WENO(order=2N-1)
return WENO(grid; order=2N-1)
end
end
102 changes: 58 additions & 44 deletions src/Advection/centered_reconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,78 @@

Centered reconstruction scheme.
"""
struct Centered{N, FT, CA} <: AbstractCenteredAdvectionScheme{N, FT}
"advection scheme used near boundaries"
buffer_scheme :: CA

Centered{N, FT}(buffer_scheme::CA) where {N, FT, CA} = new{N, FT, CA}(buffer_scheme)
end
struct Centered{N, FT} <: AbstractCenteredAdvectionScheme{N, FT} end

function Centered(FT::DataType=Oceananigans.defaults.FloatType; grid = nothing, order = 2)

if !(grid isa Nothing)
FT = eltype(grid)
end

# Enforce the grid type if a grid is provided
FT = grid isa Nothing ? FT : eltype(grid)

mod(order, 2) != 0 && throw(ArgumentError("Centered reconstruction scheme is defined only for even orders"))

N = Int(order ÷ 2)
if N > 1
buffer_scheme = Centered(FT; grid, order = order - 2)
else
buffer_scheme = nothing
end
return Centered{N, FT}(buffer_scheme)
N = Int(order ÷ 2)
return Centered{N, FT}()
end

Base.summary(a::Centered{N}) where N = string("Centered(order=", 2N, ")")

Base.show(io::IO, a::Centered{N, FT}) where {N, FT} =
print(io, summary(a), " \n",
" Boundary scheme: ", "\n",
" └── ", summary(a.buffer_scheme))


Adapt.adapt_structure(to, scheme::Centered{N, FT}) where {N, FT} = Centered{N, FT}(Adapt.adapt(to, scheme.buffer_scheme))

on_architecture(to, scheme::Centered{N, FT}) where {N, FT} = Centered{N, FT}(on_architecture(to, scheme.buffer_scheme))
Base.show(io::IO, a::Centered{N, FT}) where {N, FT} = summary(a)

# Useful aliases
Centered(grid, FT::DataType=Float64; kwargs...) = Centered(FT; grid, kwargs...)

const ACAS = AbstractCenteredAdvectionScheme

# left and right biased for Centered reconstruction are just symmetric!
@inline biased_interpolate_xᶠᵃᵃ(i, j, k, grid, scheme::ACAS, bias, args...) = symmetric_interpolate_xᶠᵃᵃ(i, j, k, grid, scheme, args...)
@inline biased_interpolate_yᵃᶠᵃ(i, j, k, grid, scheme::ACAS, bias, args...) = symmetric_interpolate_yᵃᶠᵃ(i, j, k, grid, scheme, args...)
@inline biased_interpolate_zᵃᵃᶠ(i, j, k, grid, scheme::ACAS, bias, args...) = symmetric_interpolate_zᵃᵃᶠ(i, j, k, grid, scheme, args...)
@inline biased_interpolate_xᶜᵃᵃ(i, j, k, grid, scheme::ACAS, bias, args...) = symmetric_interpolate_xᶜᵃᵃ(i, j, k, grid, scheme, args...)
@inline biased_interpolate_yᵃᶜᵃ(i, j, k, grid, scheme::ACAS, bias, args...) = symmetric_interpolate_yᵃᶜᵃ(i, j, k, grid, scheme, args...)
@inline biased_interpolate_zᵃᵃᶜ(i, j, k, grid, scheme::ACAS, bias, args...) = symmetric_interpolate_zᵃᵃᶜ(i, j, k, grid, scheme, args...)

# uniform centered reconstruction
for buffer in advection_buffers, FT in fully_supported_float_types
@eval begin
@inline symmetric_interpolate_xᶠᵃᵃ(i, j, k, grid, ::Centered{$buffer, $FT}, ψ, args...) = @inbounds @muladd $(calc_reconstruction_stencil(FT, buffer, :symmetric, :x, false))
@inline symmetric_interpolate_yᵃᶠᵃ(i, j, k, grid, ::Centered{$buffer, $FT}, ψ, args...) = @inbounds @muladd $(calc_reconstruction_stencil(FT, buffer, :symmetric, :y, false))
@inline symmetric_interpolate_zᵃᵃᶠ(i, j, k, grid, ::Centered{$buffer, $FT}, ψ, args...) = @inbounds @muladd $(calc_reconstruction_stencil(FT, buffer, :symmetric, :z, false))

@inline symmetric_interpolate_xᶠᵃᵃ(i, j, k, grid, ::Centered{$buffer, $FT}, ψ::Callable, args...) = @inbounds @muladd $(calc_reconstruction_stencil(FT, buffer, :symmetric, :x, true))
@inline symmetric_interpolate_yᵃᶠᵃ(i, j, k, grid, ::Centered{$buffer, $FT}, ψ::Callable, args...) = @inbounds @muladd $(calc_reconstruction_stencil(FT, buffer, :symmetric, :y, true))
@inline symmetric_interpolate_zᵃᵃᶠ(i, j, k, grid, ::Centered{$buffer, $FT}, ψ::Callable, args...) = @inbounds @muladd $(calc_reconstruction_stencil(FT, buffer, :symmetric, :z, true))
@inline _biased_interpolate_xᶠᵃᵃ(i, j, k, grid, scheme::ACAS, bias, c, args...) = _symmetric_interpolate_xᶠᵃᵃ(i, j, k, grid, scheme, c, args...)
@inline _biased_interpolate_yᵃᶠᵃ(i, j, k, grid, scheme::ACAS, bias, c, args...) = _symmetric_interpolate_yᵃᶠᵃ(i, j, k, grid, scheme, c, args...)
@inline _biased_interpolate_zᵃᵃᶠ(i, j, k, grid, scheme::ACAS, bias, c, args...) = _symmetric_interpolate_zᵃᵃᶠ(i, j, k, grid, scheme, c, args...)
@inline _biased_interpolate_xᶜᵃᵃ(i, j, k, grid, scheme::ACAS, bias, c, args...) = _symmetric_interpolate_xᶜᵃᵃ(i, j, k, grid, scheme, c, args...)
@inline _biased_interpolate_yᵃᶜᵃ(i, j, k, grid, scheme::ACAS, bias, c, args...) = _symmetric_interpolate_yᵃᶜᵃ(i, j, k, grid, scheme, c, args...)
@inline _biased_interpolate_zᵃᵃᶜ(i, j, k, grid, scheme::ACAS, bias, c, args...) = _symmetric_interpolate_zᵃᵃᶜ(i, j, k, grid, scheme, c, args...)

for (side, dir) in zip((:ᶠᵃᵃ, :ᵃᶠᵃ, :ᵃᵃᶠ), (:x, :y, :z))
for (F, bool) in zip((:Any, :(Base.Callable)), (false, true))
for FT in fully_supported_float_types
interp = Symbol(:symmetric_interpolate_, dir, side)
@eval begin
@inline $interp(i, j, k, grid, ::Centered{1, $FT}, red_order::Int, ψ::$F, args...) = @muladd $(stencil_reconstruction(FT, 1, :symmetric, dir, bool))

@inline function $interp(i, j, k, grid, ::Centered{2, $FT}, red_order::Int, ψ::$F, args...)
@muladd ifelse(red_order==1,
$(stencil_reconstruction(FT, 1, :symmetric, dir, bool)),
$(stencil_reconstruction(FT, 2, :symmetric, dir, bool)))
end

@inline function $interp(i, j, k, grid, ::Centered{3, $FT}, red_order::Int, ψ::$F, args...)
@muladd ifelse(red_order==1,
$(stencil_reconstruction(FT, 1, :symmetric, dir, bool)),
ifelse(red_order==2,
$(stencil_reconstruction(FT, 2, :symmetric, dir, bool)),
$(stencil_reconstruction(FT, 3, :symmetric, dir, bool))))
end

@inline function $interp(i, j, k, grid, ::Centered{4, $FT}, red_order::Int, ψ::$F, args...)
@muladd ifelse(red_order==1,
$(stencil_reconstruction(FT, 1, :symmetric, dir, bool)),
ifelse(red_order==2,
$(stencil_reconstruction(FT, 2, :symmetric, dir, bool)),
ifelse(red_order==3,
$(stencil_reconstruction(FT, 3, :symmetric, dir, bool)),
$(stencil_reconstruction(FT, 4, :symmetric, dir, bool)))))
end

@inline function $interp(i, j, k, grid, ::Centered{5, $FT}, red_order::Int, ψ::$F, args...)
@muladd ifelse(red_order==1,
$(stencil_reconstruction(FT, 1, :symmetric, dir, bool)),
ifelse(red_order==2,
$(stencil_reconstruction(FT, 2, :symmetric, dir, bool)),
ifelse(red_order==3,
$(stencil_reconstruction(FT, 3, :symmetric, dir, bool)),
ifelse(red_order==4,
$(stencil_reconstruction(FT, 4, :symmetric, dir, bool)),
$(stencil_reconstruction(FT, 5, :symmetric, dir, bool))))))
end
end
end
end
end
26 changes: 11 additions & 15 deletions src/Advection/flat_advective_fluxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,15 @@ FlatGrids = [:XFG, :YFG, :ZFG, :XFG, :YFG, :ZFG]
for (dir, GridType) in zip((:xᶠᵃᵃ, :yᵃᶠᵃ, :zᵃᵃᶠ, :xᶜᵃᵃ, :yᵃᶜᵃ, :zᵃᵃᶜ), FlatGrids)
alt_symm_interp = Symbol(:_symmetric_interpolate_, dir)
alt_biased_interp = Symbol(:_biased_interpolate_, dir)
@eval begin
@inline $alt_symm_interp(i, j, k, grid::$GridType, ::HOADV, ψ, args...) = @inbounds ψ[i, j, k]
@inline $alt_symm_interp(i, j, k, grid::$GridType, ::LOADV, ψ, args...) = @inbounds ψ[i, j, k]
@inline $alt_symm_interp(i, j, k, grid::$GridType, ::HOADV, ψ::Callable, args...) = @inbounds ψ(i, j, k, grid, args...)
@inline $alt_symm_interp(i, j, k, grid::$GridType, ::LOADV, ψ::Callable, args...) = @inbounds ψ(i, j, k, grid, args...)
@inline $alt_symm_interp(i, j, k, grid::$GridType, ::HOADV, ψ::Callable, ::AS, args...) = @inbounds ψ(i, j, k, grid, args...)
@inline $alt_symm_interp(i, j, k, grid::$GridType, ::LOADV, ψ::Callable, ::AS, args...) = @inbounds ψ(i, j, k, grid, args...)

@inline $alt_biased_interp(i, j, k, grid::$GridType, ::HOADV, ψ, args...) = @inbounds ψ[i, j, k]
@inline $alt_biased_interp(i, j, k, grid::$GridType, ::LOADV, ψ, args...) = @inbounds ψ[i, j, k]
@inline $alt_biased_interp(i, j, k, grid::$GridType, ::HOADV, bias, ψ::Callable, args...) = ψ(i, j, k, grid, args...)
@inline $alt_biased_interp(i, j, k, grid::$GridType, ::LOADV, bias, ψ::Callable, args...) = ψ(i, j, k, grid, args...)
@inline $alt_biased_interp(i, j, k, grid::$GridType, ::HOADV, bias, ψ::Callable, ::AS, args...) = ψ(i, j, k, grid, args...)
@inline $alt_biased_interp(i, j, k, grid::$GridType, ::LOADV, bias, ψ::Callable, ::AS, args...) = ψ(i, j, k, grid, args...)
for Scheme in [:Centered, :UpwindBiased, :WENO]
@eval begin
@inline $alt_symm_interp(i, j, k, grid::$GridType, ::$Scheme, ψ, args...) = @inbounds ψ[i, j, k]
@inline $alt_symm_interp(i, j, k, grid::$GridType, ::$Scheme, ψ::Callable, args...) = @inbounds ψ(i, j, k, grid, args...)
@inline $alt_symm_interp(i, j, k, grid::$GridType, ::$Scheme, ψ::Callable, ::AS, args...) = @inbounds ψ(i, j, k, grid, args...)

@inline $alt_biased_interp(i, j, k, grid::$GridType, ::$Scheme, ψ, args...) = @inbounds ψ[i, j, k]
@inline $alt_biased_interp(i, j, k, grid::$GridType, ::$Scheme, bias, ψ::Callable, args...) = ψ(i, j, k, grid, args...)
@inline $alt_biased_interp(i, j, k, grid::$GridType, ::$Scheme, bias, ψ::Callable, ::AS, args...) = ψ(i, j, k, grid, args...)
end
end
end
end
Loading