changeset 1032:11767fbb29f4 feature/dissipation_operators

Add padding functions for stencils
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 22 Mar 2022 11:18:57 +0100
parents 0905cec43d2e
children 0cb4c6b15d8e
files src/SbpOperators/stencil.jl test/SbpOperators/stencil_test.jl
diffstat 2 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/SbpOperators/stencil.jl	Tue Mar 22 10:42:19 2022 +0100
+++ b/src/SbpOperators/stencil.jl	Tue Mar 22 11:18:57 2022 +0100
@@ -78,3 +78,18 @@
     end
     return w
 end
+
+
+function left_pad(s::Stencil, N)
+    weights = LazyTensors.left_pad_tuple(s.weights, zero(eltype(s)), N)
+    range = (s.range[1] - (N - length(s.weights)) ,s.range[2])
+
+    return Stencil(range, weights)
+end
+
+function right_pad(s::Stencil, N)
+    weights = LazyTensors.right_pad_tuple(s.weights, zero(eltype(s)), N)
+    range = (s.range[1], s.range[2] + (N - length(s.weights)))
+
+    return Stencil(range, weights)
+end
--- a/test/SbpOperators/stencil_test.jl	Tue Mar 22 10:42:19 2022 +0100
+++ b/test/SbpOperators/stencil_test.jl	Tue Mar 22 11:18:57 2022 +0100
@@ -29,3 +29,19 @@
         @test convert(Stencil{Rational}, Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1//1,2//1,3//1,4//1,5//1; center=2)
     end
 end
+
+@testset "left_pad" begin
+    @test SbpOperators.left_pad(Stencil(1,1, center = 1), 2) == Stencil(1,1, center=1)
+    @test SbpOperators.left_pad(Stencil(1,1, center = 1), 3) == Stencil(0,1,1, center=2)
+    @test SbpOperators.left_pad(Stencil(2,3, center = 2), 4) == Stencil(0,0,2,3, center=4)
+
+    @test SbpOperators.left_pad(Stencil(2.,3., center = 2), 4) == Stencil(0.,0.,2.,3., center=4)
+end
+
+@testset "right_pad" begin
+    @test SbpOperators.right_pad(Stencil(1,1, center = 1), 2) == Stencil(1,1, center=1)
+    @test SbpOperators.right_pad(Stencil(1,1, center = 1), 3) == Stencil(1,1,0, center=1)
+    @test SbpOperators.right_pad(Stencil(2,3, center = 2), 4) == Stencil(2,3,0,0, center=2)
+
+    @test SbpOperators.right_pad(Stencil(2.,3., center = 2), 4) == Stencil(2.,3.,0.,0., center=2)
+end