Mercurial > repos > public > sbplib_julia
changeset 1058:c4f71d6f2d63 feature/nested_stencils
Add functions for converting the element type of nested stencils
(grafted from 54e36688dab85d935058d31c82f9ec00f03637ff)
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 10 Feb 2022 10:57:00 +0100 |
parents | 0728e84af0dc |
children | 4d06642174ec |
files | src/SbpOperators/stencil.jl test/SbpOperators/stencil_test.jl |
diffstat | 2 files changed, 17 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl Mon Feb 07 14:34:03 2022 +0100 +++ b/src/SbpOperators/stencil.jl Thu Feb 10 10:57:00 2022 +0100 @@ -102,6 +102,14 @@ return CenteredNestedStencil(inner_stencils...) end + +# Conversion +function NestedStencil{T}(ns::NestedStencil) where T + return NestedStencil(Stencil{Stencil{T}}(ns.s)) +end + +Base.convert(::Type{NestedStencil{T}}, stencil) where T = NestedStencil{T}(stencil) + Base.eltype(::NestedStencil{T}) where T = T function flip(ns::NestedStencil)
--- a/test/SbpOperators/stencil_test.jl Mon Feb 07 14:34:03 2022 +0100 +++ b/test/SbpOperators/stencil_test.jl Thu Feb 10 10:57:00 2022 +0100 @@ -60,11 +60,19 @@ center=1 )) - @testset "Error handling" begin end end + @testset "conversion" begin + ns = NestedStencil((-1,1,0),(-1,0,1),(0,-1,1), center=2) + @test NestedStencil{Float64}(ns) == NestedStencil((-1.,1.,0.),(-1.,0.,1.),(0.,-1.,1.), center=2) + @test NestedStencil{Rational}(ns) == NestedStencil((-1//1,1//1,0//1),(-1//1,0//1,1//1),(0//1,-1//1,1//1), center=2) + + @test convert(NestedStencil{Float64}, ns) == NestedStencil((-1.,1.,0.),(-1.,0.,1.),(0.,-1.,1.), center=2) + @test convert(NestedStencil{Rational}, ns) == NestedStencil((-1//1,1//1,0//1),(-1//1,0//1,1//1),(0//1,-1//1,1//1), center=2) + end + @testset "apply" begin c = [ 1, 3, 6, 10, 15, 21, 28, 36, 45, 55] v = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29]