Skip to content

Commit 7316917

Browse files
glwagnernavidcy
andauthored
Dont adapt Flat direction advection scheme plus better summary for FluxFormAdvection (#3908)
* Dont adapt Flat directions plus better summary for FluxFormAdvection * Update docs --------- Co-authored-by: Navid C. Constantinou <[email protected]>
1 parent 771b879 commit 7316917

12 files changed

+76
-59
lines changed

docs/src/model_setup/boundary_conditions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ julia> model = NonhydrostaticModel(; grid, boundary_conditions=(u=no_slip_field_
4343
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
4444
├── grid: 16×16×16 RectilinearGrid{Float64, Periodic, Bounded, Bounded} on CPU with 3×3×3 halo
4545
├── timestepper: RungeKutta3TimeStepper
46-
├── advection scheme: Centered reconstruction order 2
46+
├── advection scheme: Centered(order=2)
4747
├── tracers: ()
4848
├── closure: Nothing
4949
├── buoyancy: Nothing
@@ -405,7 +405,7 @@ julia> model = NonhydrostaticModel(grid=grid, boundary_conditions=(u=u_bcs, c=c_
405405
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
406406
├── grid: 16×16×16 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
407407
├── timestepper: RungeKutta3TimeStepper
408-
├── advection scheme: Centered reconstruction order 2
408+
├── advection scheme: Centered(order=2)
409409
├── tracers: c
410410
├── closure: Nothing
411411
├── buoyancy: Nothing

docs/src/model_setup/buoyancy_and_equation_of_state.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ julia> model = NonhydrostaticModel(; grid, buoyancy=nothing)
2929
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
3030
├── grid: 8×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
3131
├── timestepper: RungeKutta3TimeStepper
32-
├── advection scheme: Centered reconstruction order 2
32+
├── advection scheme: Centered(order=2)
3333
├── tracers: ()
3434
├── closure: Nothing
3535
├── buoyancy: Nothing
@@ -44,7 +44,7 @@ julia> model = NonhydrostaticModel(; grid)
4444
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
4545
├── grid: 8×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
4646
├── timestepper: RungeKutta3TimeStepper
47-
├── advection scheme: Centered reconstruction order 2
47+
├── advection scheme: Centered(order=2)
4848
├── tracers: ()
4949
├── closure: Nothing
5050
├── buoyancy: Nothing
@@ -78,7 +78,7 @@ julia> model = NonhydrostaticModel(; grid, buoyancy=BuoyancyTracer(), tracers=:b
7878
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
7979
├── grid: 8×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
8080
├── timestepper: RungeKutta3TimeStepper
81-
├── advection scheme: Centered reconstruction order 2
81+
├── advection scheme: Centered(order=2)
8282
├── tracers: b
8383
├── closure: Nothing
8484
├── buoyancy: BuoyancyTracer with ĝ = NegativeZDirection()
@@ -99,7 +99,7 @@ HydrostaticFreeSurfaceModel{CPU, RectilinearGrid}(time = 0 seconds, iteration =
9999
│ └── solver: FFTImplicitFreeSurfaceSolver
100100
├── advection scheme:
101101
│ ├── momentum: Vector Invariant, Dimension-by-dimension reconstruction
102-
│ └── b: Centered reconstruction order 2
102+
│ └── b: Centered(order=2)
103103
└── coriolis: Nothing
104104
```
105105

@@ -119,7 +119,7 @@ julia> model = NonhydrostaticModel(; grid, buoyancy=SeawaterBuoyancy(), tracers=
119119
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
120120
├── grid: 8×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
121121
├── timestepper: RungeKutta3TimeStepper
122-
├── advection scheme: Centered reconstruction order 2
122+
├── advection scheme: Centered(order=2)
123123
├── tracers: (T, S)
124124
├── closure: Nothing
125125
├── buoyancy: SeawaterBuoyancy with g=9.80665 and LinearEquationOfState(thermal_expansion=0.000167, haline_contraction=0.00078) with ĝ = NegativeZDirection()
@@ -140,8 +140,8 @@ HydrostaticFreeSurfaceModel{CPU, RectilinearGrid}(time = 0 seconds, iteration =
140140
│ └── solver: FFTImplicitFreeSurfaceSolver
141141
├── advection scheme:
142142
│ ├── momentum: Vector Invariant, Dimension-by-dimension reconstruction
143-
│ ├── T: Centered reconstruction order 2
144-
│ └── S: Centered reconstruction order 2
143+
│ ├── T: Centered(order=2)
144+
│ └── S: Centered(order=2)
145145
└── coriolis: Nothing
146146
```
147147

@@ -158,7 +158,7 @@ julia> model = NonhydrostaticModel(; grid, buoyancy, tracers=(:T, :S))
158158
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
159159
├── grid: 8×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
160160
├── timestepper: RungeKutta3TimeStepper
161-
├── advection scheme: Centered reconstruction order 2
161+
├── advection scheme: Centered(order=2)
162162
├── tracers: (T, S)
163163
├── closure: Nothing
164164
├── buoyancy: SeawaterBuoyancy with g=1.3 and LinearEquationOfState(thermal_expansion=0.000167, haline_contraction=0.00078) with ĝ = NegativeZDirection()
@@ -239,7 +239,7 @@ julia> model = NonhydrostaticModel(; grid, buoyancy, tracers=:b)
239239
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
240240
├── grid: 8×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
241241
├── timestepper: RungeKutta3TimeStepper
242-
├── advection scheme: Centered reconstruction order 2
242+
├── advection scheme: Centered(order=2)
243243
├── tracers: b
244244
├── closure: Nothing
245245
├── buoyancy: BuoyancyTracer with ĝ = (0.0, 0.707107, 0.707107)

docs/src/model_setup/lagrangian_particles.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ model = NonhydrostaticModel(grid=grid, particles=lagrangian_particles)
4444
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
4545
├── grid: 10×10×10 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
4646
├── timestepper: RungeKutta3TimeStepper
47-
├── advection scheme: Centered reconstruction order 2
47+
├── advection scheme: Centered(order=2)
4848
├── tracers: ()
4949
├── closure: Nothing
5050
├── buoyancy: Nothing

docs/src/model_setup/tracers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ julia> model = NonhydrostaticModel(; grid)
1616
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
1717
├── grid: 16×16×16 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
1818
├── timestepper: RungeKutta3TimeStepper
19-
├── advection scheme: Centered reconstruction order 2
19+
├── advection scheme: Centered(order=2)
2020
├── tracers: ()
2121
├── closure: Nothing
2222
├── buoyancy: Nothing
@@ -31,7 +31,7 @@ julia> model = NonhydrostaticModel(; grid, tracers=(:T, :S))
3131
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
3232
├── grid: 16×16×16 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
3333
├── timestepper: RungeKutta3TimeStepper
34-
├── advection scheme: Centered reconstruction order 2
34+
├── advection scheme: Centered(order=2)
3535
├── tracers: (T, S)
3636
├── closure: Nothing
3737
├── buoyancy: Nothing
@@ -66,7 +66,7 @@ julia> model = NonhydrostaticModel(; grid, tracers=(:T, :S, :C₁, :CO₂, :nitr
6666
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
6767
├── grid: 16×16×16 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 3×3×3 halo
6868
├── timestepper: RungeKutta3TimeStepper
69-
├── advection scheme: Centered reconstruction order 2
69+
├── advection scheme: Centered(order=2)
7070
├── tracers: (T, S, C₁, CO₂, nitrogen)
7171
├── closure: Nothing
7272
├── buoyancy: Nothing

src/Advection/adapt_advection_order.jl

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ function adapt_advection_order(advection, grid::AbstractGrid)
2020
advection_y = y_advection(advection)
2121
advection_z = z_advection(advection)
2222

23-
new_advection_x = adapt_advection_order(advection_x, size(grid, 1), grid)
24-
new_advection_y = adapt_advection_order(advection_y, size(grid, 2), grid)
25-
new_advection_z = adapt_advection_order(advection_z, size(grid, 3), grid)
23+
tx = topology(grid, 1)()
24+
ty = topology(grid, 2)()
25+
tz = topology(grid, 3)()
26+
27+
# Note: no adaptation in Flat directions.
28+
new_advection_x = adapt_advection_order(tx, advection_x, size(grid, 1), grid)
29+
new_advection_y = adapt_advection_order(ty, advection_y, size(grid, 2), grid)
30+
new_advection_z = adapt_advection_order(tz, advection_z, size(grid, 3), grid)
2631

2732
# Check that we indeed changed the advection operator
2833
changed_x = new_advection_x != advection_x
@@ -45,7 +50,6 @@ function adapt_advection_order(advection, grid::AbstractGrid)
4550
return ifelse(changed_advection, new_advection, advection)
4651
end
4752

48-
4953
x_advection(flux_form::FluxFormAdvection) = flux_form.x
5054
y_advection(flux_form::FluxFormAdvection) = flux_form.y
5155
z_advection(flux_form::FluxFormAdvection) = flux_form.z
@@ -54,10 +58,15 @@ x_advection(advection) = advection
5458
y_advection(advection) = advection
5559
z_advection(advection) = advection
5660

61+
# Don't adapt advection in Flat directions
62+
adapt_advection_order(topo, advection, N, grid) = adapt_advection_order(advection, N, grid)
63+
adapt_advection_order(::Flat, advection, N, grid) = advection
64+
5765
# For the moment, we do not adapt the advection order for the VectorInvariant advection scheme
5866
adapt_advection_order(advection::VectorInvariant, grid::AbstractGrid) = advection
5967
adapt_advection_order(advection::Nothing, grid::AbstractGrid) = nothing
6068
adapt_advection_order(advection::Nothing, N::Int, grid::AbstractGrid) = nothing
69+
adapt_advection_order(advection, N, grid) = advection
6170

6271
#####
6372
##### Directional adapt advection order
@@ -67,23 +76,26 @@ function adapt_advection_order(advection::Centered{B}, N::Int, grid::AbstractGri
6776
if N >= B
6877
return advection
6978
else
70-
return Centered(; order = 2N)
79+
return Centered(; order=2N)
7180
end
7281
end
7382

7483
function adapt_advection_order(advection::UpwindBiased{B}, N::Int, grid::AbstractGrid) where B
7584
if N >= B
7685
return advection
7786
else
78-
return UpwindBiased(; order = 2N - 1)
87+
return UpwindBiased(; order=2N-1)
7988
end
8089
end
8190

8291
"""
8392
new_weno_scheme(grid, order, bounds, XT, YT, ZT)
8493
85-
Constructs a new WENO scheme based on the given parameters. `XT`, `YT`, and `ZT` is the type of the precomputed weno coefficients in the
86-
x-direction, y-direction and z-direction. A _non-stretched_ WENO scheme has `T` equal to `Nothing` everywhere. In case of a non-stretched WENO scheme,
94+
Constructs a new WENO scheme based on the given parameters.
95+
`XT`, `YT`, and `ZT` is the type of the precomputed weno coefficients in the
96+
x-direction, y-direction and z-direction.
97+
A _non-stretched_ WENO scheme has `T` equal to `Nothing` everywhere.
98+
In case of a non-stretched WENO scheme,
8799
we rebuild the advection without passing the grid information, otherwise we use the grid to account for stretched directions.
88100
"""
89101
new_weno_scheme(::WENO, grid, order, bounds, ::Type{Nothing}, ::Type{Nothing}, ::Type{Nothing},) = WENO(; order, bounds)
@@ -93,6 +105,7 @@ function adapt_advection_order(advection::WENO{B, FT, XT, YT, ZT}, N::Int, grid:
93105
if N >= B
94106
return advection
95107
else
96-
return new_weno_scheme(advection, grid, 2N - 1, advection.bounds, XT, YT, ZT)
108+
return new_weno_scheme(advection, grid, 2N-1, advection.bounds, XT, YT, ZT)
97109
end
98-
end
110+
end
111+

src/Advection/centered_reconstruction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function Centered(FT::DataType = Float64; grid = nothing, order = 2)
5858
return Centered{N, FT}(coefficients..., buffer_scheme)
5959
end
6060

61-
Base.summary(a::Centered{N}) where N = string("Centered reconstruction order ", N*2)
61+
Base.summary(a::Centered{N}) where N = string("Centered(order=", 2N, ")")
6262

6363
Base.show(io::IO, a::Centered{N, FT, XT, YT, ZT}) where {N, FT, XT, YT, ZT} =
6464
print(io, summary(a), " \n",

src/Advection/flux_form_advection.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ function FluxFormAdvection(x_advection, y_advection, z_advection)
2626
return FluxFormAdvection{H, FT}(x_advection, y_advection, z_advection)
2727
end
2828

29+
Base.summary(scheme::FluxFormAdvection) = string("FluxFormAdvection(x=",
30+
summary(scheme.x), ", y=",
31+
summary(scheme.y), ", z=",
32+
summary(scheme.z), ")")
33+
2934
Base.show(io::IO, scheme::FluxFormAdvection) =
30-
print(io, "FluxFormAdvection with reconstructions: ", " \n",
35+
print(io, "FluxFormAdvection with direction-based reconstructions:", " \n",
3136
" ├── x: ", summary(scheme.x), "\n",
3237
" ├── y: ", summary(scheme.y), "\n",
3338
" └── z: ", summary(scheme.z))

src/Advection/upwind_biased_reconstruction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function UpwindBiased(FT::DataType = Float64; grid = nothing, order = 3)
6565
return UpwindBiased{N, FT}(coefficients..., buffer_scheme, advecting_velocity_scheme)
6666
end
6767

68-
Base.summary(a::UpwindBiased{N}) where N = string("Upwind Biased reconstruction order ", N*2-1)
68+
Base.summary(a::UpwindBiased{N}) where N = string("UpwindBiased(order=", 2N-1, ")")
6969

7070
Base.show(io::IO, a::UpwindBiased{N, FT, XT, YT, ZT}) where {N, FT, XT, YT, ZT} =
7171
print(io, summary(a), " \n",

src/Advection/vector_invariant_advection.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,16 @@ Vector Invariant, Dimension-by-dimension reconstruction
8888
julia> using Oceananigans
8989
9090
julia> VectorInvariant(vorticity_scheme = WENO(), vertical_scheme = WENO(order = 3))
91-
Vector Invariant, Dimension-by-dimension reconstruction
92-
Vorticity flux scheme:
93-
├── WENO reconstruction order 5
91+
Vector Invariant, Dimension-by-dimension reconstruction
92+
Vorticity flux scheme:
93+
├── WENO(order=5)
9494
└── smoothness ζ: Oceananigans.Advection.VelocityStencil()
95-
Vertical advection / Divergence flux scheme:
96-
├── WENO reconstruction order 3
97-
└── upwinding treatment: OnlySelfUpwinding
98-
KE gradient and Divergence flux cross terms reconstruction:
99-
└── Centered reconstruction order 2
100-
Smoothness measures:
95+
Vertical advection / Divergence flux scheme:
96+
├── WENO(order=3)
97+
└── upwinding treatment: OnlySelfUpwinding
98+
KE gradient and Divergence flux cross terms reconstruction:
99+
└── Centered(order=2)
100+
Smoothness measures:
101101
├── smoothness δU: FunctionStencil f = divergence_smoothness
102102
├── smoothness δV: FunctionStencil f = divergence_smoothness
103103
├── smoothness δu²: FunctionStencil f = u_smoothness

src/Advection/weno_reconstruction.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ Examples
5858
julia> using Oceananigans
5959
6060
julia> WENO()
61-
WENO reconstruction order 5
62-
Boundary scheme:
63-
└── WENO reconstruction order 3
64-
Symmetric scheme:
65-
└── Centered reconstruction order 4
61+
WENO(order=5)
62+
Boundary scheme:
63+
└── WENO(order=3)
64+
Symmetric scheme:
65+
└── Centered(order=4)
6666
Directions:
67-
├── X regular
68-
├── Y regular
67+
├── X regular
68+
├── Y regular
6969
└── Z regular
7070
```
7171
@@ -82,14 +82,14 @@ julia> grid = RectilinearGrid(size = (Nx, Nz), halo = (4, 4), topology=(Periodic
8282
x = (0, Lx), z = chebychev_spaced_z_faces);
8383
8484
julia> WENO(grid; order=7)
85-
WENO reconstruction order 7
86-
Boundary scheme:
87-
└── WENO reconstruction order 5
88-
Symmetric scheme:
89-
└── Centered reconstruction order 6
85+
WENO(order=7)
86+
Boundary scheme:
87+
└── WENO(order=5)
88+
Symmetric scheme:
89+
└── Centered(order=6)
9090
Directions:
91-
├── X regular
92-
├── Y regular
91+
├── X regular
92+
├── Y regular
9393
└── Z stretched
9494
```
9595
"""
@@ -105,14 +105,13 @@ function WENO(FT::DataType=Float64;
105105
mod(order, 2) == 0 && throw(ArgumentError("WENO reconstruction scheme is defined only for odd orders"))
106106

107107
if order < 3
108-
# WENO(order = 1) is equivalent to UpwindBiased(order = 1)
109-
return UpwindBiased(FT; order = 1)
108+
# WENO(order=1) is equivalent to UpwindBiased(order=1)
109+
return UpwindBiased(FT; order=1)
110110
else
111-
N = Int((order + 1) ÷ 2)
112-
111+
N = Int((order + 1) ÷ 2)
113112
weno_coefficients = compute_reconstruction_coefficients(grid, FT, :WENO; order = N)
114113
advecting_velocity_scheme = Centered(FT; grid, order = order - 1)
115-
buffer_scheme = WENO(FT; grid, order = order - 2, bounds)
114+
buffer_scheme = WENO(FT; grid, order=order-2, bounds)
116115
end
117116

118117
return WENO{N, FT}(weno_coefficients..., bounds, buffer_scheme, advecting_velocity_scheme)
@@ -127,7 +126,7 @@ WENOFifthOrder(grid=nothing, FT::DataType=Float64; kwargs...) = WENO(grid, FT;
127126
# Flavours of WENO
128127
const PositiveWENO = WENO{<:Any, <:Any, <:Any, <:Any, <:Any, <:Tuple}
129128

130-
Base.summary(a::WENO{N}) where N = string("WENO reconstruction order ", N*2-1)
129+
Base.summary(a::WENO{N}) where N = string("WENO(order=", N*2-1, ")")
131130

132131
Base.show(io::IO, a::WENO{N, FT, RX, RY, RZ, PP}) where {N, FT, RX, RY, RZ, PP} =
133132
print(io, summary(a), " \n",

src/BuoyancyModels/buoyancy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ model = NonhydrostaticModel(; grid, buoyancy, tracers=:b)
3232
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
3333
├── grid: 1×8×8 RectilinearGrid{Float64, Periodic, Periodic, Bounded} on CPU with 1×3×3 halo
3434
├── timestepper: RungeKutta3TimeStepper
35-
├── advection scheme: Centered reconstruction order 2
35+
├── advection scheme: Centered(order=2)
3636
├── tracers: b
3737
├── closure: Nothing
3838
├── buoyancy: BuoyancyTracer with ĝ = (0.0, -0.707107, -0.707107)

src/Models/seawater_density.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ julia> model = NonhydrostaticModel(; grid, buoyancy, tracers)
8282
NonhydrostaticModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
8383
├── grid: 1×1×100 RectilinearGrid{Float64, Flat, Flat, Bounded} on CPU with 0×0×3 halo
8484
├── timestepper: RungeKutta3TimeStepper
85-
├── advection scheme: Centered reconstruction order 2
85+
├── advection scheme: Centered(order=2)
8686
├── tracers: (T, S)
8787
├── closure: Nothing
8888
├── buoyancy: SeawaterBuoyancy with g=9.80665 and BoussinesqEquationOfState{Float64} with ĝ = NegativeZDirection()

0 commit comments

Comments
 (0)