diff src/SbpOperators/stencil.jl @ 675:1ce3a104afc8 feature/boundary_quads

Merge in default
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 07 Feb 2021 21:28:53 +0100
parents 59a81254fefc
children 9fc6d38da03f
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl	Sat Feb 06 12:04:06 2021 +0100
+++ b/src/SbpOperators/stencil.jl	Sun Feb 07 21:28:53 2021 +0100
@@ -1,3 +1,5 @@
+export CenteredStencil
+
 struct Stencil{T<:Real,N}
     range::Tuple{Int,Int}
     weights::NTuple{N,T}
@@ -13,13 +15,24 @@
 
 Create a stencil with the given weights with element `center` as the center of the stencil.
 """
-function Stencil(weights::NTuple; center::Int)
+function Stencil(weights::Vararg{Number}; center::Int)
     N = length(weights)
     range = (1, N) .- center
 
     return Stencil(range, weights)
 end
 
+function CenteredStencil(weights::Vararg)
+    if iseven(length(weights))
+        throw(ArgumentError("a centered stencil must have an odd number of weights."))
+    end
+
+    r = length(weights) รท 2
+
+    return Stencil((-r, r), weights)
+end
+
+
 """
     scale(s::Stencil, a)