Mercurial > repos > public > sbplib_julia
changeset 595:03ef4d4740ab refactor/toml_operator_format
Add a constructor for Stencil where you can specify the center of the stencil
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 02 Dec 2020 17:10:18 +0100 |
parents | cc86b920531a |
children | a9744aa5e235 |
files | src/SbpOperators/stencil.jl test/testSbpOperators.jl |
diffstat | 2 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl Wed Dec 02 15:26:13 2020 +0100 +++ b/src/SbpOperators/stencil.jl Wed Dec 02 17:10:18 2020 +0100 @@ -9,6 +9,18 @@ end """ + Stencil(weights::NTuple; center::Int) + +Create a stencil with the given weights with element `center` as the center of the stencil. +""" +function Stencil(weights::NTuple; center::Int) + N = length(weights) + range = (1, N) .- center + + return Stencil(range, weights) +end + +""" scale(s::Stencil, a) Scale the weights of the stencil `s` with `a` and return a new stencil.
--- a/test/testSbpOperators.jl Wed Dec 02 15:26:13 2020 +0100 +++ b/test/testSbpOperators.jl Wed Dec 02 17:10:18 2020 +0100 @@ -13,6 +13,10 @@ @test eltype(s) == Float64 @test SbpOperators.scale(s, 2) == SbpOperators.Stencil((-2,2), (2.,4.,4.,6.,8.)) + + @test SbpOperators.Stencil((1,2,3,4), center=1) == SbpOperators.Stencil((0, 3),(1,2,3,4)) + @test SbpOperators.Stencil((1,2,3,4), center=2) == SbpOperators.Stencil((-1, 2),(1,2,3,4)) + @test SbpOperators.Stencil((1,2,3,4), center=4) == SbpOperators.Stencil((-3, 0),(1,2,3,4)) end # @testset "apply_quadrature" begin