Skip to content

Commit 006e1b4

Browse files
refactor: make newton_div type names less verbose
1 parent 63f8fc2 commit 006e1b4

5 files changed

Lines changed: 30 additions & 30 deletions

File tree

ext/OceananigansCUDAExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ end
137137
@inline UT.sync_device!(::CUDABackend) = CUDA.synchronize()
138138

139139
# Use faster versions of `newton_div` on Nvidia GPUs
140-
CUDA.@device_override UT.newton_div(::Type{UT.BackendOptimizedNewtonDiv}, a, b) = a * fast_inv_cuda(b)
140+
CUDA.@device_override UT.newton_div(::Type{UT.BackendOptimizedDivision}, a, b) = a * fast_inv_cuda(b)
141141

142142
function fast_inv_cuda(a::Float64)
143143
# Get the approximate reciprocal

src/Advection/vector_invariant_advection.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ julia> using Oceananigans
193193
194194
julia> WENOVectorInvariant()
195195
WENOVectorInvariant{5, Float64}(vorticity_order=9, vertical_order=5)
196-
├── vorticity_scheme: WENO{5, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=9)
196+
├── vorticity_scheme: WENO{5, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=9)
197197
├── vorticity_stencil: Oceananigans.Advection.VelocityStencil
198-
├── vertical_advection_scheme: WENO{3, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=5)
199-
├── kinetic_energy_gradient_scheme: WENO{3, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=5)
200-
├── divergence_scheme: WENO{3, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=5)
198+
├── vertical_advection_scheme: WENO{3, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=5)
199+
├── kinetic_energy_gradient_scheme: WENO{3, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=5)
200+
├── divergence_scheme: WENO{3, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=5)
201201
└── upwinding: OnlySelfUpwinding
202202
```
203203
"""

src/Advection/weno_reconstruction.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Arguments
3232
Keyword arguments
3333
=================
3434
- `weight_computation`: The type of approximate division to used when computing WENO weights.
35-
Default: `Oceananigans.Utils.NewtonDivWithConversion{Float32}`
35+
Default: `Oceananigans.Utils.ConvertingDivision{Float32}`
3636
- `order`: The order of the WENO advection scheme. Default: 5
3737
- `bounds` (experimental): Whether to use bounds-preserving WENO, which produces a reconstruction
3838
that attempts to restrict a quantity to lie between a `bounds` tuple.
@@ -51,8 +51,8 @@ To build the default 5th-order scheme:
5151
julia> using Oceananigans
5252
5353
julia> WENO()
54-
WENO{3, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=5)
55-
├── buffer_scheme: WENO{2, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=3)
54+
WENO{3, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=5)
55+
├── buffer_scheme: WENO{2, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=3)
5656
│ └── buffer_scheme: Centered(order=2)
5757
└── advecting_velocity_scheme: Centered(order=4)
5858
```
@@ -62,10 +62,10 @@ yet minimally-dissipative advection scheme):
6262
6363
```jldoctest weno
6464
julia> WENO(order=9)
65-
WENO{5, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=9)
66-
├── buffer_scheme: WENO{4, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=7)
67-
│ └── buffer_scheme: WENO{3, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=5)
68-
│ └── buffer_scheme: WENO{2, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=3)
65+
WENO{5, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=9)
66+
├── buffer_scheme: WENO{4, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=7)
67+
│ └── buffer_scheme: WENO{3, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=5)
68+
│ └── buffer_scheme: WENO{2, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=3)
6969
│ └── buffer_scheme: Centered(order=2)
7070
└── advecting_velocity_scheme: Centered(order=8)
7171
```
@@ -75,34 +75,34 @@ which uses `Centered(order=2)` as the innermost buffer scheme:
7575
7676
```jldoctest weno
7777
julia> WENO(order=9, minimum_buffer_upwind_order=5)
78-
WENO{5, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=9)
79-
├── buffer_scheme: WENO{4, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=7)
80-
│ └── buffer_scheme: WENO{3, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=5)
78+
WENO{5, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=9)
79+
├── buffer_scheme: WENO{4, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=7)
80+
│ └── buffer_scheme: WENO{3, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=5)
8181
│ └── buffer_scheme: Centered(order=2)
8282
└── advecting_velocity_scheme: Centered(order=8)
8383
```
8484
8585
```jldoctest weno
8686
julia> WENO(order=9, bounds=(0, 1))
87-
WENO{5, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=9, bounds=(0.0, 1.0))
88-
├── buffer_scheme: WENO{4, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=7, bounds=(0.0, 1.0))
89-
│ └── buffer_scheme: WENO{3, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=5, bounds=(0.0, 1.0))
90-
│ └── buffer_scheme: WENO{2, Float64, Oceananigans.Utils.NewtonDivWithConversion{Float32}}(order=3, bounds=(0.0, 1.0))
87+
WENO{5, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=9, bounds=(0.0, 1.0))
88+
├── buffer_scheme: WENO{4, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=7, bounds=(0.0, 1.0))
89+
│ └── buffer_scheme: WENO{3, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=5, bounds=(0.0, 1.0))
90+
│ └── buffer_scheme: WENO{2, Float64, Oceananigans.Utils.ConvertingDivision{Float32}}(order=3, bounds=(0.0, 1.0))
9191
│ └── buffer_scheme: Centered(order=2)
9292
└── advecting_velocity_scheme: Centered(order=8)
9393
```
9494
9595
To build a WENO scheme that uses approximate division on a GPU to execute faster:
9696
```jldoctest weno
97-
julia> WENO(;weight_computation=Oceananigans.Utils.BackendOptimizedNewtonDiv)
98-
WENO{3, Float64, Oceananigans.Utils.BackendOptimizedNewtonDiv}(order=5)
99-
├── buffer_scheme: WENO{2, Float64, Oceananigans.Utils.BackendOptimizedNewtonDiv}(order=3)
97+
julia> WENO(;weight_computation=Oceananigans.Utils.BackendOptimizedDivision)
98+
WENO{3, Float64, Oceananigans.Utils.BackendOptimizedDivision}(order=5)
99+
├── buffer_scheme: WENO{2, Float64, Oceananigans.Utils.BackendOptimizedDivision}(order=3)
100100
│ └── buffer_scheme: Centered(order=2)
101101
└── advecting_velocity_scheme: Centered(order=4)
102102
```
103103
"""
104104
function WENO(FT::DataType=Oceananigans.defaults.FloatType;
105-
weight_computation::DataType=Oceananigans.Utils.NewtonDivWithConversion{Float32},
105+
weight_computation::DataType=Oceananigans.Utils.ConvertingDivision{Float32},
106106
order = 5,
107107
buffer_scheme = DecreasingOrderAdvectionScheme(),
108108
bounds = nothing,

src/Utils/Utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export seconds_to_nanosecond, period_to_seconds, time_difference_seconds, add_ti
1111
export TimeInterval, IterationInterval, WallTimeInterval, SpecifiedTimes, AndSchedule, OrSchedule, ConsecutiveIterations
1212
export apply_regionally!, construct_regionally, @apply_regionally, MultiRegionObject
1313
export isregional, getregion, _getregion, regions, sync_device!
14-
export newton_div, NoNewtonDiv, NewtonDivWithConversion, BackendOptimizedNewtonDiv
14+
export newton_div, NormalDivision, ConvertingDivision, BackendOptimizedDivision
1515
export TabulatedFunction
1616
export interpolator, _interpolate
1717
export ϕ₁, ϕ₂, ϕ₃, ϕ₄, ϕ₅, ϕ₆, ϕ₇, ϕ₈

src/Utils/newton_div.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ abstract type NewtonDivConfig end
88
"""
99
Configuration selecting regular, full-precision division.
1010
"""
11-
struct NoNewtonDiv <: NewtonDivConfig end
11+
struct NormalDivision <: NewtonDivConfig end
1212

1313
"""
1414
Configuration selecting approximate division via one Newton iteration.
1515
The reciprocal `1/b` is first evaluated in a lower-precision type `FT`
1616
to obtain a fast initial guess, then refined with a single Newton step
1717
in the original precision.
1818
"""
19-
struct NewtonDivWithConversion{FT} <: NewtonDivConfig end
19+
struct ConvertingDivision{FT} <: NewtonDivConfig end
2020

2121
"""
2222
Configuration selecting a backend-optimized implementation of approximate division.
2323
The actual algorithm may differ across CPU and different GPU backends.
2424
"""
25-
struct BackendOptimizedNewtonDiv <: NewtonDivConfig end
25+
struct BackendOptimizedDivision <: NewtonDivConfig end
2626

2727
"""
2828
newton_div(::Type{T}, a, b)
@@ -31,7 +31,7 @@ Compute an approximate division `a/b` using a method specified by selector type
3131
"""
3232
function newton_div end
3333

34-
@inline function newton_div(::Type{NewtonDivWithConversion{inv_FT}}, a, b::FT) where {inv_FT, FT}
34+
@inline function newton_div(::Type{ConvertingDivision{inv_FT}}, a, b::FT) where {inv_FT, FT}
3535
# Low precision division:
3636
b_low = convert(inv_FT, b)
3737
inv_b = Base.FastMath.inv_fast(b_low)
@@ -46,7 +46,7 @@ function newton_div end
4646
end
4747

4848
# Case of matching precisions
49-
@inline newton_div(::Type{NewtonDivWithConversion{FT}}, a, b::FT) where FT = a * Base.FastMath.inv_fast(b)
49+
@inline newton_div(::Type{ConvertingDivision{FT}}, a, b::FT) where FT = a * Base.FastMath.inv_fast(b)
5050

5151
# Exact division if requested
52-
@inline newton_div(::Type{NoNewtonDiv}, a, b) = a / b
52+
@inline newton_div(::Type{NormalDivision}, a, b) = a / b

0 commit comments

Comments
 (0)