Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
2e6a5ea
ciao?
simone-silvestri Jul 23, 2026
45ce1cd
improve barotropic solver
simone-silvestri Jul 23, 2026
8d297a1
fix variance dissipation
simone-silvestri Jul 23, 2026
166c9fb
fix dissipation
simone-silvestri Jul 23, 2026
42a5870
correct weights
simone-silvestri Jul 27, 2026
60fdf2f
better averaging kernels
simone-silvestri Jul 27, 2026
296f51c
quadratic slow stepping
simone-silvestri Jul 31, 2026
dd2be93
ssp rk3
simone-silvestri Aug 17, 2026
79def30
ready to try it out
simone-silvestri Aug 17, 2026
78eda65
Merge remote-tracking branch 'origin/main' into ss/sm05-barotropic
simone-silvestri Aug 19, 2026
1b9052c
improve efficiency of the RK barotropic substepper
simone-silvestri Aug 20, 2026
8ecfe0c
more speedup improvement of the RK3Scheme
simone-silvestri Aug 20, 2026
105c81a
improve the tests
simone-silvestri Aug 20, 2026
d6a95da
fix AIVA
simone-silvestri Aug 22, 2026
e474e23
fix tests and compact the PR
simone-silvestri Aug 25, 2026
5de2996
Merge branch 'ss/sm05-barotropic' of github.com:CliMA/Oceananigans.jl…
simone-silvestri Aug 25, 2026
dbbc195
Merge remote-tracking branch 'origin/main' into ss/sm05-barotropic
simone-silvestri Aug 27, 2026
a24d450
Merge remote-tracking branch 'origin/main' into ss/sm05-barotropic
simone-silvestri Aug 28, 2026
a3f1ad2
Merge remote-tracking branch 'origin/main' into ss/sm05-barotropic
simone-silvestri Sep 1, 2026
8ca0f02
new boundary scheme
simone-silvestri Sep 4, 2026
525162a
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 5, 2026
085b557
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 5, 2026
8a93b64
add correct ConservativeRegridding
simone-silvestri Sep 5, 2026
e744105
centered scheme
simone-silvestri Sep 5, 2026
86331ac
Update src/Advection/boundary_weno_scheme.jl
simone-silvestri Sep 5, 2026
2e93176
Update src/Advection/boundary_weno_scheme.jl
simone-silvestri Sep 5, 2026
02b7f11
Update src/Advection/boundary_weno_scheme.jl
simone-silvestri Sep 5, 2026
b4ba15c
paramters in constructor
simone-silvestri Sep 5, 2026
f072d8a
Merge branch 'ss/immersed-boundary-reconstruction' of github.com:CliM…
simone-silvestri Sep 5, 2026
7542565
restart CI
simone-silvestri Sep 5, 2026
d7dd513
correct the path
simone-silvestri Sep 5, 2026
dfff145
try passing CWENOZ as a default
simone-silvestri Sep 5, 2026
5e13ab1
no buffer scheme
simone-silvestri Sep 5, 2026
2a52fa9
change the API to remove DecreasingOrderAdvectionScheme
simone-silvestri Sep 5, 2026
bbeda20
fixes and back to centered default
simone-silvestri Sep 5, 2026
eb8fbb1
change this
simone-silvestri Sep 5, 2026
eb8ee47
Merge remote-tracking branch 'origin/ss/immersed-boundary-reconstruct…
simone-silvestri Sep 5, 2026
c70b49d
Merge remote-tracking branch 'origin/main' into ss/sm05-barotropic
simone-silvestri Sep 5, 2026
2211352
fix adaptive impliciti advection
simone-silvestri Sep 5, 2026
e615ab4
try improving performance
simone-silvestri Sep 6, 2026
4b45783
revert
simone-silvestri Sep 6, 2026
a89a808
let's see if this fold reduces run time
simone-silvestri Sep 6, 2026
a795516
speed up cwenoz
simone-silvestri Sep 7, 2026
8bfeadf
revert the
simone-silvestri Sep 7, 2026
3a4b283
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 7, 2026
4728e20
remove whitespace
simone-silvestri Sep 7, 2026
7389e86
small fix
simone-silvestri Sep 8, 2026
8a0888c
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 8, 2026
81fe886
remove the conservativeregridding pin
simone-silvestri Sep 8, 2026
8cb3d71
Merge branch 'ss/immersed-boundary-reconstruction' of github.com:CliM…
simone-silvestri Sep 8, 2026
de84c7e
improve boundary scheme
simone-silvestri Sep 8, 2026
23a7258
Merge branch 'ss/immersed-boundary-reconstruction' of github.com:CliM…
simone-silvestri Sep 8, 2026
8811bb8
Merge remote-tracking branch 'origin/ss/immersed-boundary-reconstruct…
simone-silvestri Sep 8, 2026
ec4e366
higher order SSP
simone-silvestri Sep 8, 2026
aa7e873
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 9, 2026
ecbf823
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 9, 2026
18b4d5b
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 9, 2026
0c8106a
optimize
simone-silvestri Sep 12, 2026
db1c6e6
improve
simone-silvestri Sep 12, 2026
e9cd2a2
use a new reconstruction type that looks into the ghost cells
simone-silvestri Sep 14, 2026
f857ae5
Merge branch 'ss/immersed-boundary-reconstruction' of github.com:CliM…
simone-silvestri Sep 14, 2026
ff2b520
correct a bit the performance
simone-silvestri Sep 14, 2026
fff6c3d
Update topologically_conditional_interpolation.jl
simone-silvestri Sep 14, 2026
f5eecb9
Apply suggestion from @simone-silvestri
simone-silvestri Sep 14, 2026
330d756
Merge remote-tracking branch 'origin/ss/immersed-boundary-reconstruct…
simone-silvestri Sep 14, 2026
b3a37e5
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 14, 2026
f7846e8
Refactor GhostCells constructor and add adapt methods
simone-silvestri Sep 14, 2026
0fd1729
reduce the diff
simone-silvestri Sep 14, 2026
580f35a
Merge branch 'ss/immersed-boundary-reconstruction' of github.com:CliM…
simone-silvestri Sep 14, 2026
deec5d1
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 14, 2026
8ce7ba7
Merge branch 'main' into ss/sm05-barotropic
simone-silvestri Sep 14, 2026
3391a0d
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 14, 2026
7242ddb
let's generalize
simone-silvestri Sep 15, 2026
fc4c1b5
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 15, 2026
4277e8b
remove whitespaces and ambiguities
simone-silvestri Sep 15, 2026
87926d8
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 16, 2026
4b25a4a
Merge remote-tracking branch 'origin/main' into ss/immersed-boundary-…
giordano Sep 25, 2026
737a648
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Sep 27, 2026
e3c3057
Merge remote-tracking branch 'origin/main' into ss/sm05-barotropic
simone-silvestri Oct 1, 2026
e0e613d
fix problems
simone-silvestri Oct 3, 2026
be0efc3
fix test
simone-silvestri Oct 3, 2026
2955347
merge main
simone-silvestri Oct 5, 2026
f6b6827
change formualtion
simone-silvestri Oct 11, 2026
ffc2de0
Merge remote-tracking branch 'origin/main' into ss/immersed-boundary-…
simone-silvestri Oct 11, 2026
d972e26
last face index
simone-silvestri Oct 12, 2026
1c4b848
merge main in
simone-silvestri Oct 12, 2026
0ee76bb
update
simone-silvestri Oct 13, 2026
216db46
fix
simone-silvestri Oct 13, 2026
21d0a35
add a test
simone-silvestri Oct 13, 2026
f9e2414
some fixes to clean up
simone-silvestri Oct 13, 2026
cf7173d
more improvements
simone-silvestri Oct 13, 2026
62bb051
merge the new boundary reconstruction
simone-silvestri Oct 13, 2026
d07b09c
Merge branch 'main' into ss/immersed-boundary-reconstruction
simone-silvestri Oct 13, 2026
2259779
Delete test/.CondaPkg/pixi.lock
simone-silvestri Oct 13, 2026
cc6553a
Delete test/.CondaPkg/.gitignore
simone-silvestri Oct 13, 2026
74ca3e2
Delete test/.CondaPkg/.gitattributes
simone-silvestri Oct 13, 2026
b626d23
Delete run_distributed_pipeline_cpu.sh
simone-silvestri Oct 13, 2026
852305b
Delete test.jl
simone-silvestri Oct 13, 2026
052bdc5
fix dissipation
simone-silvestri Oct 13, 2026
889e1f4
speed up reconstruction
simone-silvestri Oct 14, 2026
b07fe2a
Merge branch 'ss/immersed-boundary-reconstruction' of github.com:CliM…
simone-silvestri Oct 14, 2026
6ddbcf7
merge
simone-silvestri Oct 14, 2026
77f36e9
remove precompilation
simone-silvestri Oct 14, 2026
d643930
divide by substeps
simone-silvestri Oct 14, 2026
acfa7ca
set it to default
simone-silvestri Oct 15, 2026
a931049
merge remote ghostcells
simone-silvestri Oct 15, 2026
b64b3c7
Fix BCS
simone-silvestri Oct 18, 2026
49c9c43
introduce side topologies
simone-silvestri Oct 18, 2026
a17e628
introduce sides topology
simone-silvestri Oct 19, 2026
9bd7a86
Merge branch 'main' into ss/sides-topology
simone-silvestri Oct 19, 2026
c5f9585
introduce an Open topology
simone-silvestri Oct 19, 2026
999a71f
Merge branch 'main' into ss/sides-topology
simone-silvestri Oct 19, 2026
0a040fd
fix regression tests
simone-silvestri Oct 19, 2026
d40e093
other fixes
simone-silvestri Oct 19, 2026
64d83ba
Merge branch 'ss/sides-topology' into ss/open-sides
simone-silvestri Oct 19, 2026
0eb14d3
rework open boundaries
simone-silvestri Oct 19, 2026
cdfbc8a
use ConservativeRegridding fixes
simone-silvestri Oct 19, 2026
e0aad5c
remove unused storage
simone-silvestri Oct 19, 2026
f3a8fa3
Merge branch 'ss/open-sides' into ss/open-state-steps
simone-silvestri Oct 19, 2026
7875811
fix memory issues
simone-silvestri Oct 19, 2026
01bd187
restart CI
simone-silvestri Oct 19, 2026
10117c5
fix indices
simone-silvestri Oct 19, 2026
cb683b7
Update Project.toml
simone-silvestri Oct 19, 2026
647c118
Merge branch 'ss/sides-topology' into ss/open-sides
simone-silvestri Oct 19, 2026
4c3b162
Merge branch 'ss/open-sides' into ss/open-state-steps
simone-silvestri Oct 19, 2026
e6afab5
restart CI
simone-silvestri Oct 19, 2026
e2934a8
introduce an Open topology
simone-silvestri Oct 19, 2026
27d1063
other fixes
simone-silvestri Oct 19, 2026
16c678d
use ConservativeRegridding fixes
simone-silvestri Oct 19, 2026
566d302
rework open boundaries
simone-silvestri Oct 19, 2026
804262c
remove unused storage
simone-silvestri Oct 19, 2026
959974b
fix memory issues
simone-silvestri Oct 19, 2026
dc45544
fix indices
simone-silvestri Oct 19, 2026
d476ba3
Rework Oceananigans' boundary treatment for advection
simone-silvestri Oct 19, 2026
f6ee262
Merge branch 'ss/open-sides' of github.com:CliMA/Oceananigans.jl into…
simone-silvestri Oct 19, 2026
107b56a
Merge branch 'ss/open-state-steps' of github.com:CliMA/Oceananigans.j…
simone-silvestri Oct 19, 2026
b599294
remember to inline
simone-silvestri Oct 19, 2026
942c2f5
compute smoothness stencils after
simone-silvestri Oct 20, 2026
4d62b80
small orders first
simone-silvestri Oct 20, 2026
9c2a21a
as it was before
simone-silvestri Oct 20, 2026
d49685c
some register changes
simone-silvestri Oct 20, 2026
85ad868
Merge remote-tracking branch 'origin/main' into ss/sides-topology
simone-silvestri Oct 20, 2026
9605c19
Merge branch 'ss/sides-topology' into ss/open-sides
simone-silvestri Oct 20, 2026
c5a2f30
Merge branch 'ss/open-sides' into ss/open-state-steps
simone-silvestri Oct 20, 2026
c281da7
Merge branch 'ss/open-state-steps' into ss/advection-boundary-scheme
simone-silvestri Oct 20, 2026
8ec4a0b
Merge branch 'ss/sides-topology' into ss/open-sides
simone-silvestri Oct 20, 2026
f91e4f0
Merge remote-tracking branch 'origin/main' into ss/open-state-steps
simone-silvestri Oct 20, 2026
d271c43
Merge remote-tracking branch 'origin/main' into ss/advection-boundary…
simone-silvestri Oct 20, 2026
98e019c
remove extra registers
simone-silvestri Oct 20, 2026
9ff3e40
Restore main's degree trigonometry and strip trailing whitespace
simone-silvestri Oct 20, 2026
4b77e23
Merge branch 'ss/open-sides' into ss/open-state-steps
simone-silvestri Oct 20, 2026
faff352
Merge branch 'ss/open-state-steps' into ss/advection-boundary-scheme
simone-silvestri Oct 20, 2026
c4d1d30
add this to make tests pass
simone-silvestri Oct 20, 2026
b57e208
Merge branch 'ss/sides-topology' into ss/open-sides
simone-silvestri Oct 20, 2026
2dddb67
Merge branch 'ss/open-sides' into ss/open-state-steps
simone-silvestri Oct 20, 2026
8150ef8
Merge branch 'ss/open-state-steps' into ss/advection-boundary-scheme
simone-silvestri Oct 20, 2026
7235284
remove advection changes
simone-silvestri Oct 21, 2026
54a92ec
stretched WENO
simone-silvestri Oct 21, 2026
17849c2
merge main
simone-silvestri Oct 21, 2026
d3479f4
merge main
simone-silvestri Oct 21, 2026
42351d2
merge main
simone-silvestri Oct 22, 2026
b706a03
merge main
simone-silvestri Oct 22, 2026
2b3aa74
correct the topology
simone-silvestri Oct 22, 2026
0444342
merge main
simone-silvestri Oct 22, 2026
5a3b51d
merge main
simone-silvestri Oct 22, 2026
5e81133
Merge branch 'ss/open-sides' into ss/open-state-steps
simone-silvestri Oct 22, 2026
1a74589
Merge branch 'ss/open-state-steps' into ss/advection-boundary-scheme
simone-silvestri Oct 22, 2026
ecd59ba
reciprocal boundary spacing
simone-silvestri Oct 22, 2026
09e60fc
merge main
simone-silvestri Oct 28, 2026
a496e30
merge main
simone-silvestri Oct 28, 2026
35cb832
correct the sequence
simone-silvestri Oct 28, 2026
d5d1007
fix the tests
simone-silvestri Oct 28, 2026
a827045
Update src/BoundaryConditions/update_boundary_conditions.jl
simone-silvestri Oct 28, 2026
4208c1c
change name to the storage
simone-silvestri Oct 28, 2026
8a12bcd
Merge branch 'ss/open-state-steps' of github.com:CliMA/Oceananigans.j…
simone-silvestri Oct 28, 2026
45837a3
correct tests
simone-silvestri Oct 29, 2026
c58a4bb
fix reactant
simone-silvestri Oct 29, 2026
8cdd3f2
fix reciprocals
simone-silvestri Oct 29, 2026
ac2b2ec
merge main
simone-silvestri Oct 29, 2026
1c687ec
change the API
simone-silvestri Oct 29, 2026
c1d99fb
Merge branch 'main' into ss/advection-boundary-scheme
simone-silvestri Oct 30, 2026
13c4801
merge main
simone-silvestri Nov 3, 2026
75be743
correct
simone-silvestri Nov 3, 2026
b6d7e6c
merge main
simone-silvestri Nov 3, 2026
a74175b
merge speedup branch
simone-silvestri Nov 3, 2026
4d27d18
merge stretched branch
simone-silvestri Nov 3, 2026
865e5a2
merge main
simone-silvestri Nov 6, 2026
2858a43
change ss/sm05-barotropic
simone-silvestri Nov 6, 2026
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
4 changes: 2 additions & 2 deletions src/Advection/Advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using Oceananigans.Utils: StaticStridesOffsetArray

using Oceananigans: Oceananigans, fully_supported_float_types
using Oceananigans.Architectures: Architectures, architecture, on_architecture, CPU
using Oceananigans.Grids: Grids, AbstractGrid, Center, Face, Flat, with_halo, horizontally_extended_interior_kernel_parameters,
using Oceananigans.Grids: Grids, AbstractGrid, Center, Face, Flat, horizontally_extended_interior_kernel_parameters,
required_halo_size_x, required_halo_size_y, required_halo_size_z,
XFlatGrid, YFlatGrid, ZFlatGrid
using Oceananigans.ImmersedBoundaries: ImmersedBoundaryGrid
Expand Down Expand Up @@ -67,7 +67,7 @@ include("centered_reconstruction.jl")
include("upwind_biased_reconstruction.jl")
include("weno_reconstruction.jl")
include("weno_interpolants.jl")
include("stretched_weno_smoothness.jl")
include("stretched_weno.jl")
include("multi_dimensional_reconstruction.jl")
include("vector_invariant_upwinding.jl")
include("vector_invariant_advection.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/Advection/adapt_advection_order.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ function adapt_advection_order(advection::WENO{B}, N::Int, grid::AbstractGrid) w
if N >= B
return advection
else
return WENO(eltype(grid); order=2N-1)
return WENO(eltype(grid); order=2N-1, stretched=something(advection.coefficients, false))
end
end
5 changes: 4 additions & 1 deletion src/Advection/adaptive_implicit_vertical_advection.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Oceananigans.Operators: Δz⁻¹ᶜᶜᶜ, Δz⁻¹ᶜᶜᶠ, Δz⁻¹ᶠᶜᶠ, Δz⁻¹ᶜᶠᶠ, Az_qᶜᶜᶠ, Azᶜᶜᶠ, ℑxᶠᵃᵃ, ℑyᵃᶠᵃ
using Oceananigans.Grids: Center, Face
using Oceananigans.BoundaryConditions: BoundaryConditions, _unwrap_for_gpu
using Oceananigans.TimeSteppers: SplitRungeKuttaTimeStepper, RungeKutta3TimeStepper
using Oceananigans.TimeSteppers: SplitRungeKuttaTimeStepper, SSPRungeKuttaTimeStepper, RungeKutta3TimeStepper
using Oceananigans.Utils: foreach_name

const AVID = AdaptiveVerticallyImplicitDiscretization
Expand Down Expand Up @@ -164,6 +164,9 @@ end
return Δt / timestepper.β[nstage]
end

# Every SSP stage is a forward-Euler step over the full Δt, so the next substep has the same Δτ.
@inline adaptive_advection_timestep(timestepper::SSPRungeKuttaTimeStepper, clock) = clock.last_stage_Δt

@inline sum_rk3_coefficients(ts, ::Val{1}) = ts.γ¹
@inline sum_rk3_coefficients(ts, ::Val{2}) = ts.γ² + ts.ζ²
@inline sum_rk3_coefficients(ts, ::Val{3}) = ts.γ³ + ts.ζ³
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ end
@inline without_bounds_preservation(scheme) = scheme

@inline function without_bounds_preservation(scheme::WENO{N, FT, WCT}) where {N, FT, WCT}
return WENO{N, FT, WCT}(nothing, scheme.buffer_scheme, scheme.advecting_velocity_scheme, scheme.time_discretization)
return WENO{N, FT, WCT}(nothing, scheme.buffer_scheme, scheme.advecting_velocity_scheme, scheme.time_discretization, scheme.coefficients)
end

#####
Expand Down
6 changes: 4 additions & 2 deletions src/Advection/materialize_advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ materialize_advection(weno::WENO{N, FT, WCT}, grid) where {N, FT, WCT} =
WENO{N, FT, WCT}(materialize_bounds(weno.bounds, grid),
materialize_advection(without_bounds_preservation(weno.buffer_scheme), grid),
materialize_advection(weno.advecting_velocity_scheme, grid),
weno.time_discretization)
weno.time_discretization,
materialize_coefficients(weno.coefficients, weno, grid))

function materialize_advection(weno::WENO{N, FT, Nothing}, grid) where {N, FT}
WTC = default_weno_weight_computation(architecture(grid))
return WENO{N, FT, WTC}(materialize_bounds(weno.bounds, grid),
materialize_advection(without_bounds_preservation(weno.buffer_scheme), grid),
materialize_advection(weno.advecting_velocity_scheme, grid),
weno.time_discretization)
weno.time_discretization,
materialize_coefficients(weno.coefficients, weno, grid))
end

materialize_advection(scheme::UpwindBiased{N, FT}, grid) where {N, FT} =
Expand Down
122 changes: 0 additions & 122 deletions src/Advection/reconstruction_coefficients.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Oceananigans.Grids: ξnodes, ηnodes, rnodes

# Generic reconstruction methods valid for all reconstruction schemes
# Unroll the functions to pass the coordinates in case of a stretched grid
""" same as [`symmetric_interpolate_xᶠᵃᵃ`](@ref) but on `Center`s instead of `Face`s """
Expand Down Expand Up @@ -163,123 +161,3 @@ julia> calc_reconstruction_stencil(Float32, 3, :left, :x)
end
return Expr(:call, :+, stencil_full...)
end

#####
##### Shenanigans for stretched directions
#####

@inline function reconstruction_stencil(buffer, shift, dir, func::Bool = false)
N = buffer * 2
order = shift == :symmetric ? N : N - 1
if shift != :symmetric
N = N .- 1
end
rng = 1:N
if shift == :right
rng = rng .+ 1
end
stencil_full = Vector(undef, N)
for (idx, n) in enumerate(rng)
c = n - buffer - 1
if func
stencil_full[idx] = dir == :x ?
:(ψ(i + $c, j, k, grid, args...)) :
dir == :y ?
:(ψ(i, j + $c, k, grid, args...)) :
:(ψ(i, j, k + $c, grid, args...))
else
stencil_full[idx] = dir == :x ?
:(ψ[i + $c, j, k]) :
dir == :y ?
:(ψ[i, j + $c, k]) :
:(ψ[i, j, k + $c])
end
end
return :($(reverse(stencil_full)...),)
end

@inline function compute_reconstruction_coefficients(grid, FT, scheme; order)

method = scheme == :Centered ? 1 : scheme == :Upwind ? 2 : 3

if grid isa Nothing
coeff_xᶠᵃᵃ = nothing
coeff_xᶜᵃᵃ = nothing
coeff_yᵃᶠᵃ = nothing
coeff_yᵃᶜᵃ = nothing
coeff_zᵃᵃᶠ = nothing
coeff_zᵃᵃᶜ = nothing
else
arch = architecture(grid)
Hx, Hy, Hz = halo_size(grid)
new_grid = with_halo((Hx+1, Hy+1, Hz+1), grid)

ξᶠᵃᵃ = ξnodes(new_grid, Face(), with_halos=true)
ηᵃᶠᵃ = ηnodes(new_grid, Face(), with_halos=true)
rᵃᵃᶠ = rnodes(new_grid, Face(), with_halos=true)

ξᶜᵃᵃ = ξnodes(new_grid, Center(), with_halos=true)
ηᵃᶜᵃ = ηnodes(new_grid, Center(), with_halos=true)
rᵃᵃᶜ = rnodes(new_grid, Center(), with_halos=true)

coeff_xᶠᵃᵃ = reconstruction_coefficients(FT, ξᶠᵃᵃ, arch, new_grid.Nx, Val(method); order)
coeff_xᶜᵃᵃ = reconstruction_coefficients(FT, ξᶜᵃᵃ, arch, new_grid.Nx, Val(method); order)
coeff_yᵃᶠᵃ = reconstruction_coefficients(FT, ηᵃᶠᵃ, arch, new_grid.Ny, Val(method); order)
coeff_yᵃᶜᵃ = reconstruction_coefficients(FT, ηᵃᶜᵃ, arch, new_grid.Ny, Val(method); order)
coeff_zᵃᵃᶠ = reconstruction_coefficients(FT, rᵃᵃᶠ, arch, new_grid.Nz, Val(method); order)
coeff_zᵃᵃᶜ = reconstruction_coefficients(FT, rᵃᵃᶜ, arch, new_grid.Nz, Val(method); order)
end

return (coeff_xᶠᵃᵃ, coeff_xᶜᵃᵃ, coeff_yᵃᶠᵃ, coeff_yᵃᶜᵃ, coeff_zᵃᵃᶠ, coeff_zᵃᵃᶜ)
end

# Fallbacks for uniform or Flat directions
for val in [1, 2, 3]
@eval begin
@inline reconstruction_coefficients(FT, coord::StaticStridesOffsetArray{<:Any, <:Any, <:Any, <:Any, <:AbstractRange}, arch, N, ::Val{$val}; order) = nothing
@inline reconstruction_coefficients(FT, coord::AbstractRange, arch, N, ::Val{$val}; order) = nothing
@inline reconstruction_coefficients(FT, coord::Nothing, arch, N, ::Val{$val}; order) = nothing
@inline reconstruction_coefficients(FT, coord::Number, arch, N, ::Val{$val}; order) = nothing
end
end

# Stretched reconstruction coefficients for `Centered` schemes
@inline function reconstruction_coefficients(FT, coord, arch, N, ::Val{1}; order)
cpu_coord = on_architecture(CPU(), coord)
r = ((order + 1) ÷ 2) - 1
s = create_reconstruction_coefficients(FT, r, cpu_coord, arch, N; order)
return s
end

# Stretched reconstruction coefficients for `UpwindBiased` schemes
@inline function reconstruction_coefficients(FT, coord, arch, N, ::Val{2}; order)
cpu_coord = on_architecture(CPU(), coord)
rleft = ((order + 1) ÷ 2) - 2
rright = ((order + 1) ÷ 2) - 1
s = []
for r in [rleft, rright]
push!(s, create_reconstruction_coefficients(FT, r, cpu_coord, arch, N; order))
end
return tuple(s...)
end

# Stretched reconstruction coefficients for `WENO` schemes
@inline function reconstruction_coefficients(FT, coord, arch, N, ::Val{3}; order)
cpu_coord = on_architecture(CPU(), coord)
s = []
for r in -1:order-1
push!(s, create_reconstruction_coefficients(FT, r, cpu_coord, arch, N; order))
end
return tuple(s...)
end

# general reconstruction coefficients for order `order` and stencil `r` where r
@inline function create_reconstruction_coefficients(FT, r, cpu_coord, arch, N; order)
stencil = NTuple{order, FT}[]
@inbounds begin
for i = 0:N+1
push!(stencil, stencil_coefficients(FT, i, r, cpu_coord, cpu_coord; order))
end
end
return StaticStridesOffsetArray(on_architecture(arch, stencil), -1)
end
84 changes: 84 additions & 0 deletions src/Advection/stretched_weno.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Oceananigans.Grids: ξnodes, ηnodes, rnodes
using Oceananigans.ImmersedBoundaries: underlying_grid

#####
##### WENO on stretched directions: reconstruction coefficients, smoothness indicators and optimal weights computed
##### exactly from the cell widths and tabulated along each direction
#####

# The weights of the averages over the cells between `edges` that give the value at x★ of the polynomial with those averages
function cell_average_weights(edges, x★)
n = length(edges) - 1
averages = [(edges[j+1]^(q+1) - edges[j]^(q+1)) / ((q + 1) * (edges[j+1] - edges[j])) for q in 0:n-1, j in 1:n]
return averages \ [x★^q for q in 0:n-1]
end

# The coefficients of the 2N - 1 cells between the 2N `edges`, reconstructing at the right edge of the anchor cell N
function biased_coefficients(FT, N, edges)
R = Rational{BigInt}
edges = R.(edges)
ξ = (edges .- (edges[N] + edges[N+1]) / 2) ./ (edges[N+1] - edges[N])
candidate(s) = ξ[N-s:2N-s]
weights = [cell_average_weights(candidate(s), R(1, 2)) for s in 0:N-1]

# β is invariant to a constant shift of the stencil, so it is a quadratic form in the first differences
T = [R(i < m) for m in 1:N, i in 1:N-1]
normalization = reference_smoothness_normalization[N - 1]
β = Tuple(FT.(ldlt_smoothness_coefficients(T' * smoothness_matrix(candidate(s)) * T * normalization)) for s in 0:N-1)
p = Tuple(FT.(Tuple(difference_coefficients(weights[s+1], N, s))) for s in 0:N-1)

# The optimal weights combine the candidates into the reconstruction from the whole stencil
A = zeros(R, 2N - 1, N)
for s in 0:N-1, m in 1:N
A[N - s + m - 1, s + 1] = weights[s + 1][m]
end
C★ = (A' * A) \ (A' * cell_average_weights(ξ, R(1, 2)))

return (; p, β, C★ = Tuple(FT.(C★)))
end

# The coefficients at every point of `nodes`, the faces or the centers of a direction with its halos, from the cells
# between consecutive nodes. Stencils that leave the halos reuse the nearest complete one.
function coefficient_table(FT, N, nodes, arch)
entries = map(firstindex(nodes):lastindex(nodes)) do p
p = clamp(p, firstindex(nodes) + N, lastindex(nodes) - N)
left = biased_coefficients(FT, N, [nodes[q] for q in p-N:p+N-1])
right = biased_coefficients(FT, N, [-nodes[q] for q in p+N:-1:p-N+1]) # mirrored
(; left, right)
end
return StaticStridesOffsetArray(on_architecture(arch, entries), firstindex(nodes) - 1)
end

materialize_coefficients(coefficients, scheme, grid) = coefficients

function materialize_coefficients(directions::Tuple, ::WENO{N, FT}, grid) where {N, FT}
arch = architecture(grid)
cpu_grid = on_architecture(CPU(), underlying_grid(grid))

# Flat and uniform directions, and the curvilinear horizontal ones (without ξnodes and ηnodes), keep the constants
function direction_coefficients(direction, nodes)
faces = direction ∈ directions && applicable(nodes, cpu_grid, Face()) ? nodes(cpu_grid, Face(); with_halos = true) : nothing
isnothing(faces) && return nothing
Δ = diff(collect(faces))
all(≈(first(Δ)), Δ) && return nothing
centers = nodes(cpu_grid, Center(); with_halos = true)
return (faces = coefficient_table(FT, N, faces, arch), centers = coefficient_table(FT, N, centers, arch))
end

return NamedTuple{(:x, :y, :z)}(map(direction_coefficients, (:x, :y, :z), (ξnodes, ηnodes, rnodes)))
end

#####
##### Reconstruction with tabulated coefficients
#####

@inline weno_coefficients(c::NamedTuple, ::Val{d}, location, n, bias) where d = weno_coefficients(getfield(c, d), location, n, bias)

@inline function weno_coefficients(c::NamedTuple, ::Val{location}, n, bias) where location
entry = @inbounds getfield(c, location)[n]
return ifelse(bias == LeftBias, entry.left, entry.right)
end

@inline coeff_p(scheme, ::Val{s}, C) where s = @inbounds C.p[s+1]
@inline C★(scheme, ::Val{s}, C) where s = @inbounds C.C★[s+1]
@inline smoothness_indicator(δ, scheme, ::Val{s}, C) where s = smoothness_operation(scheme, δ, @inbounds C.β[s+1])
111 changes: 0 additions & 111 deletions src/Advection/stretched_weno_smoothness.jl

This file was deleted.

Loading
Loading