From 786dae61b1edafd87658012bd711e4b92472e443 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Fri, 22 Nov 2024 11:19:42 -0800 Subject: [PATCH 1/5] fix positivity preserving WENO --- .../positivity_preserving_tracer_advection_operators.jl | 2 ++ src/Advection/weno_reconstruction.jl | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/Advection/positivity_preserving_tracer_advection_operators.jl b/src/Advection/positivity_preserving_tracer_advection_operators.jl index 550504f4d6..c6a6a0a608 100644 --- a/src/Advection/positivity_preserving_tracer_advection_operators.jl +++ b/src/Advection/positivity_preserving_tracer_advection_operators.jl @@ -7,6 +7,8 @@ const ε₂ = 1e-20 # Here in the future we can easily add UpwindBiased const BoundPreservingScheme = PositiveWENO +@inline div_Uc(i, j, k, grid, advection::BoundPreservingScheme, U, ::ZeroField) = zero(grid) + # Is this immersed-boundary safe without having to extend it in ImmersedBoundaries.jl? I think so... (velocity on immmersed boundaries is masked to 0) @inline function div_Uc(i, j, k, grid, advection::BoundPreservingScheme, U, c) diff --git a/src/Advection/weno_reconstruction.jl b/src/Advection/weno_reconstruction.jl index 541583dec0..465474a194 100644 --- a/src/Advection/weno_reconstruction.jl +++ b/src/Advection/weno_reconstruction.jl @@ -104,6 +104,10 @@ function WENO(FT::DataType=Float64; mod(order, 2) == 0 && throw(ArgumentError("WENO reconstruction scheme is defined only for odd orders")) + if !isnothing(bounds) + @warn "Bounds preserving WENO is experimental and not tested. Use with caution." + end + if order < 3 # WENO(order=1) is equivalent to UpwindBiased(order=1) return UpwindBiased(FT; order=1) From 9a6678b71b10182547d9bf3f3e1911caa40c13d5 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Fri, 22 Nov 2024 12:20:54 -0800 Subject: [PATCH 2/5] add a test --- test/test_immersed_advection.jl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/test_immersed_advection.jl b/test/test_immersed_advection.jl index dc36776b6a..759b34d8c0 100644 --- a/test/test_immersed_advection.jl +++ b/test/test_immersed_advection.jl @@ -12,7 +12,8 @@ using Oceananigans.Advection: _biased_interpolate_yᵃᶠᵃ, FluxFormAdvection -advection_schemes = [Centered, UpwindBiased, WENO] +linear_advection_schemes = [Centered, UpwindBiased] +advection_schemes = [linear_advection_schemes... WENO] @inline advective_order(buffer, ::Type{Centered}) = buffer * 2 @inline advective_order(buffer, AdvectionType) = buffer * 2 - 1 @@ -103,12 +104,19 @@ for arch in archs mask_immersed_field!(c) fill_halo_regions!(c) - for adv in advection_schemes, buffer in [1, 2, 3, 4, 5] + for adv in linear_advection_schemes, buffer in [1, 2, 3, 4, 5] scheme = adv(order = advective_order(buffer, adv)) @info " Testing immersed tracer reconstruction [$(typeof(arch)), $(summary(scheme))]" run_tracer_interpolation_test(c, ibg, scheme) end + + for buffer in [2, 3, 4, 5], bounds in (nothing, (0, 1)) + scheme = WENO(order = advective_order(buffer, adv), bounds) + + @info " Testing immersed tracer reconstruction [$(typeof(arch)), $(summary(scheme))]" + run_tracer_interpolation_test(c, ibg, scheme) + end end @testset "Immersed tracer conservation" begin From 8d79d8bb0ce5b571ac08facff0327a7e746d268d Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Fri, 22 Nov 2024 12:32:55 -0800 Subject: [PATCH 3/5] Update src/Advection/weno_reconstruction.jl Co-authored-by: Gregory L. Wagner --- src/Advection/weno_reconstruction.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Advection/weno_reconstruction.jl b/src/Advection/weno_reconstruction.jl index 465474a194..23d2208077 100644 --- a/src/Advection/weno_reconstruction.jl +++ b/src/Advection/weno_reconstruction.jl @@ -105,7 +105,7 @@ function WENO(FT::DataType=Float64; mod(order, 2) == 0 && throw(ArgumentError("WENO reconstruction scheme is defined only for odd orders")) if !isnothing(bounds) - @warn "Bounds preserving WENO is experimental and not tested. Use with caution." + @warn "Bounds preserving WENO is experimental." end if order < 3 From a5030eee95f20631b1d1fa630fe274200cf73d60 Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Fri, 22 Nov 2024 15:45:29 -0800 Subject: [PATCH 4/5] fix tests --- test/test_immersed_advection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_immersed_advection.jl b/test/test_immersed_advection.jl index 759b34d8c0..9adfdd8bc2 100644 --- a/test/test_immersed_advection.jl +++ b/test/test_immersed_advection.jl @@ -112,7 +112,7 @@ for arch in archs end for buffer in [2, 3, 4, 5], bounds in (nothing, (0, 1)) - scheme = WENO(order = advective_order(buffer, adv), bounds) + scheme = WENO(order = advective_order(buffer, WENO), bounds) @info " Testing immersed tracer reconstruction [$(typeof(arch)), $(summary(scheme))]" run_tracer_interpolation_test(c, ibg, scheme) From 227bc7d2d9551ee78116b3ca0a6ba1dabc90995f Mon Sep 17 00:00:00 2001 From: Simone Silvestri Date: Fri, 22 Nov 2024 21:02:17 -0800 Subject: [PATCH 5/5] fix tests --- test/test_immersed_advection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_immersed_advection.jl b/test/test_immersed_advection.jl index 9adfdd8bc2..3136987208 100644 --- a/test/test_immersed_advection.jl +++ b/test/test_immersed_advection.jl @@ -112,7 +112,7 @@ for arch in archs end for buffer in [2, 3, 4, 5], bounds in (nothing, (0, 1)) - scheme = WENO(order = advective_order(buffer, WENO), bounds) + scheme = WENO(; order = advective_order(buffer, WENO), bounds) @info " Testing immersed tracer reconstruction [$(typeof(arch)), $(summary(scheme))]" run_tracer_interpolation_test(c, ibg, scheme)