Mercurial > repos > public > sbplib_julia
changeset 1059:4d06642174ec feature/nested_stencils
Add scale method for nested stencils
(grafted from 004324d7ed3561aded3ff49905bb26e2c359bd63)
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 10 Feb 2022 11:26:28 +0100 |
parents | c4f71d6f2d63 |
children | ff0e819f2075 |
files | src/SbpOperators/stencil.jl test/SbpOperators/stencil_test.jl |
diffstat | 2 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl Thu Feb 10 10:57:00 2022 +0100 +++ b/src/SbpOperators/stencil.jl Thu Feb 10 11:26:28 2022 +0100 @@ -112,6 +112,13 @@ Base.eltype(::NestedStencil{T}) where T = T +function scale(ns::NestedStencil, a) + range = ns.s.range + weights = ns.s.weights + + return NestedStencil(Stencil(range, scale.(weights,a))) +end + function flip(ns::NestedStencil) s_flip = flip(ns.s) return NestedStencil(Stencil(s_flip.range, flip.(s_flip.weights)))
--- a/test/SbpOperators/stencil_test.jl Thu Feb 10 10:57:00 2022 +0100 +++ b/test/SbpOperators/stencil_test.jl Thu Feb 10 11:26:28 2022 +0100 @@ -64,6 +64,11 @@ end end + @testset "scale" begin + ns = NestedStencil((-1,1,0),(-1,0,1),(0,-1,1), center=2) + @test SbpOperators.scale(ns, 2) == NestedStencil((-2,2,0),(-2,0,2),(0,-2,2), center=2) + 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)