|
| 1 | +include("dependencies_for_runtests.jl") |
| 2 | + |
| 3 | +using CUDA |
| 4 | + |
| 5 | +# Generate some random points in a single binade [1;2) interval |
| 6 | +function test_data_in_single_binade(::Type{FT}, size) where {FT} |
| 7 | + prng = Random.Xoshiro(44) |
| 8 | + return rand(prng, FT, size) .+ 1.0 |
| 9 | +end |
| 10 | + |
| 11 | +@testset "CPU newton_div: $FT $WCT" for (FT, WCT) in Iterators.product((Float32, Float64), |
| 12 | + (Oceananigans.Utils.NormalDivision, |
| 13 | + Oceananigans.Utils.ConvertingDivision{Float32})) |
| 14 | + test_input = test_data_in_single_binade(FT, 1024) |
| 15 | + |
| 16 | + ref = similar(test_input) |
| 17 | + output = similar(test_input) |
| 18 | + |
| 19 | + ref .= FT(π) ./ test_input |
| 20 | + output .= Oceananigans.Utils.newton_div.(WCT, FT(π), test_input) |
| 21 | + |
| 22 | + @test isapprox(ref, output) |
| 23 | +end |
| 24 | + |
| 25 | +if CUDA.functional() |
| 26 | + |
| 27 | + @testset "CUDA newton_div: $FT" for FT in (Float32, Float64) |
| 28 | + test_input = CuArray(test_data_in_single_binade(FT, 1024)) |
| 29 | + |
| 30 | + WCT = Oceananigans.Utils.BackendOptimizedDivision |
| 31 | + |
| 32 | + ref = similar(test_input) |
| 33 | + output = similar(test_input) |
| 34 | + |
| 35 | + ref .= FT(π) ./ test_input |
| 36 | + output .= Oceananigans.Utils.newton_div.(WCT, FT(π), test_input) |
| 37 | + |
| 38 | + @test isapprox(ref, output) |
| 39 | + end |
| 40 | +end |
| 41 | + |
| 42 | + |
| 43 | +function append_weight_computation_type!(list, weno::WENO{<:Any, <:Any, WCT}) where {WCT} |
| 44 | + push!(list, WCT) |
| 45 | + append_weight_computation_type!(list, weno.buffer_scheme) |
| 46 | +end |
| 47 | +append_weight_computation_type!(::Any, ::Any) = nothing |
| 48 | + |
| 49 | +# Extract all weight computation types from WENO |
| 50 | +# Assumes a non-weno buffer scheme will not have WENO buffer scheme |
| 51 | +function get_weight_computation_from_weno_advection(weno::WENO) |
| 52 | + weight_computation_types = DataType[] |
| 53 | + append_weight_computation_type!(weight_computation_types, weno) |
| 54 | + return weight_computation_types |
| 55 | +end |
| 56 | + |
| 57 | +@testset "Verify WENO schemes construction" begin |
| 58 | + |
| 59 | + # WENO |
| 60 | + weno5 = WENO(order=7; weight_computation=Oceananigans.Utils.NormalDivision) |
| 61 | + weight_computation_types = get_weight_computation_from_weno_advection(weno5) |
| 62 | + @test all(weight_computation_types .== Oceananigans.Utils.NormalDivision) |
| 63 | + |
| 64 | + # Vector Invariant WENO |
| 65 | + vector_weno = WENOVectorInvariant(order=9, weight_computation=Oceananigans.Utils.BackendOptimizedDivision) |
| 66 | + |
| 67 | + for field_name in fieldnames(typeof(vector_weno)) |
| 68 | + field = getfield(vector_weno, field_name) |
| 69 | + if field isa WENO |
| 70 | + weight_computation_types = get_weight_computation_from_weno_advection(field) |
| 71 | + @test all(weight_computation_types .== Oceananigans.Utils.BackendOptimizedDivision) |
| 72 | + end |
| 73 | + end |
| 74 | +end |
0 commit comments