changeset 1027:d44cb983cfa4 feature/dissipation_operators

Add tests for StencilOperatorDistinctClosures
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 22 Mar 2022 08:02:59 +0100
parents 29ac38ba0744
children 62e80e8cc743
files test/SbpOperators/volumeops/derivatives/dissipation_test.jl test/SbpOperators/volumeops/stencil_operator_distinct_closures_test.jl
diffstat 2 files changed, 59 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/SbpOperators/volumeops/derivatives/dissipation_test.jl	Tue Mar 22 08:02:23 2022 +0100
+++ b/test/SbpOperators/volumeops/derivatives/dissipation_test.jl	Tue Mar 22 08:02:59 2022 +0100
@@ -30,8 +30,8 @@
     g = EquidistantGrid(20, 0., 11.)
     D,Dᵀ = dissipation(g, 1)
 
-    @test D isa LazyTensor{Float64,1,1} where T
-    @test Dᵀ isa LazyTensor{Float64,1,1} where T
+    @test_broken D isa LazyTensor{Float64,1,1} where T
+    @test_broken Dᵀ isa LazyTensor{Float64,1,1} where T
 
      @testset "Accuracy conditions" begin
         N = 20
@@ -43,7 +43,7 @@
                 v = evalOn(g, x->monomial(x,k))
 
                 x, = points(g)[10]
-                @test (D*v)[10] == monomial(x,k-1)
+                @test_broken (D*v)[10] == monomial(x,k-1)
             end
 
             # Test Dᵀ works backwards and interior forwards
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/SbpOperators/volumeops/stencil_operator_distinct_closures_test.jl	Tue Mar 22 08:02:59 2022 +0100
@@ -0,0 +1,56 @@
+using Test
+
+using Sbplib.SbpOperators
+using Sbplib.Grids
+# using Sbplib.RegionIndices
+using Sbplib.LazyTensors
+
+import Sbplib.SbpOperators.Stencil
+import Sbplib.SbpOperators.StencilOperatorDistinctClosures
+import Sbplib.SbpOperators.stencil_operator_distinct_closures
+
+@testset "stencil_operator_distinct_closures" begin
+end
+
+@testset "StencilOperatorDistinctClosures" begin
+    g = EquidistantGrid(11, 0., 1.)
+
+    lower_closure = (
+        Stencil(-1,1,0, center=1),
+        Stencil(-2,2,0, center=2),
+    )
+
+    inner_stencil = Stencil(-3,3, center=1)
+
+    upper_closure = (
+        Stencil(4,-4,4, center=1),
+        Stencil(0,-5,5, center=2),
+        Stencil(0,-6,6, center=3),
+    )
+
+    A = StencilOperatorDistinctClosures(g, inner_stencil, lower_closure, upper_closure)
+    @test A isa LazyTensor{T,1,1} where T
+
+    @test SbpOperators.lower_closure_size(A) == 2
+    @test SbpOperators.upper_closure_size(A) == 3
+
+    @test domain_size(A) == (11,)
+    @test range_size(A) == (11,)
+
+    v = rand(11)
+    @testset "apply" begin
+        # Lower closure
+        @test LazyTensors.apply(A, v, 1) ≈ 1*(-v[1] + v[2])
+        @test LazyTensors.apply(A, v, 2) ≈ 2*(-v[1] + v[2])
+
+        # Interior
+        @test LazyTensors.apply(A, v, 3) ≈ 3*(-v[3] + v[4])
+        @test LazyTensors.apply(A, v, 4) ≈ 3*(-v[4] + v[5])
+        @test LazyTensors.apply(A, v, 8) ≈ 3*(-v[8] + v[9])
+
+        # Upper closure
+        @test LazyTensors.apply(A, v,  9) ≈ 4*(v[9] - v[10] + v[11])
+        @test LazyTensors.apply(A, v, 10) ≈ 5*(     - v[10] + v[11])
+        @test LazyTensors.apply(A, v, 11) ≈ 6*(     - v[10] + v[11])
+    end
+end