Mercurial > repos > public > sbplib_julia
changeset 586:8e4f86c4bf75 feature/boundary_ops
Merge in default
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 02 Dec 2020 13:19:43 +0100 |
parents | 0e1a95b35999 (current diff) 4aa7fe13a984 (diff) |
children | 6e02c497ccd5 |
files | test/testSbpOperators.jl |
diffstat | 2 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl Wed Dec 02 13:19:14 2020 +0100 +++ b/src/SbpOperators/stencil.jl Wed Dec 02 13:19:43 2020 +0100 @@ -8,6 +8,17 @@ end end +""" + scale(s::Stencil, a) + +Scale the weights of the stencil `s` with `a` and return a new stencil. +""" +function scale(s::Stencil, a) + return Stencil(s.range, a.*s.weights) +end + +Base.eltype(::Stencil{T}) where T = T + function flip(s::Stencil) range = (-s.range[2], -s.range[1]) return Stencil(range, reverse(s.weights)) @@ -16,7 +27,7 @@ # Provides index into the Stencil based on offset for the root element @inline function Base.getindex(s::Stencil, i::Int) @boundscheck if i < s.range[1] || s.range[2] < i - return eltype(s.weights)(0) + return zero(eltype(s)) end return s.weights[1 + i - s.range[1]] end
--- a/test/testSbpOperators.jl Wed Dec 02 13:19:14 2020 +0100 +++ b/test/testSbpOperators.jl Wed Dec 02 13:19:43 2020 +0100 @@ -7,6 +7,14 @@ @testset "SbpOperators" begin +@testset "Stencil" begin + s = SbpOperators.Stencil((-2,2), (1.,2.,2.,3.,4.)) + @test s isa SbpOperators.Stencil{Float64, 5} + + @test eltype(s) == Float64 + @test SbpOperators.scale(s, 2) == SbpOperators.Stencil((-2,2), (2.,4.,4.,6.,8.)) +end + # @testset "apply_quadrature" begin # op = readOperator(sbp_operators_path()*"d2_4th.txt",sbp_operators_path()*"h_4th.txt") # h = 0.5