diff test/SbpOperators/volumeops/laplace/laplace_test.jl @ 975:5be8e25c81b3 feature/tensormapping_application_promotion

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 15 Mar 2022 07:37:11 +0100
parents 47425442bbc5
children 7bf3121c6864 1ba8a398af9c
line wrap: on
line diff
--- a/test/SbpOperators/volumeops/laplace/laplace_test.jl	Mon Mar 14 08:48:02 2022 +0100
+++ b/test/SbpOperators/volumeops/laplace/laplace_test.jl	Tue Mar 15 07:37:11 2022 +0100
@@ -4,25 +4,25 @@
 using Sbplib.Grids
 using Sbplib.LazyTensors
 
+# Default stencils (4th order)
+operator_path = sbp_operators_path()*"standard_diagonal.toml"
+stencil_set = read_stencil_set(operator_path; order=4)
+inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
+closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
+g_1D = EquidistantGrid(101, 0.0, 1.)
+g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.))
+
 @testset "Laplace" begin
-    g_1D = EquidistantGrid(101, 0.0, 1.)
-    g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.))
     @testset "Constructors" begin
-        stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4)
-        inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
-        closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
         @testset "1D" begin
-            L = laplace(g_1D, inner_stencil, closure_stencils)
-            @test L == second_derivative(g_1D, inner_stencil, closure_stencils)
-            @test L isa TensorMapping{T,1,1}  where T
+            Δ = laplace(g_1D, inner_stencil, closure_stencils)
+            @test Laplace(g_1D, stencil_set) == Laplace(Δ, stencil_set)
+            @test Laplace(g_1D, stencil_set) isa TensorMapping{T,1,1}  where T
         end
         @testset "3D" begin
-            L = laplace(g_3D, inner_stencil, closure_stencils)
-            @test L isa TensorMapping{T,3,3} where T
-            Dxx = second_derivative(g_3D, inner_stencil, closure_stencils, 1)
-            Dyy = second_derivative(g_3D, inner_stencil, closure_stencils, 2)
-            Dzz = second_derivative(g_3D, inner_stencil, closure_stencils, 3)
-            @test L == Dxx + Dyy + Dzz
+            Δ = laplace(g_3D, inner_stencil, closure_stencils)
+            @test Laplace(g_3D, stencil_set) == Laplace(Δ,stencil_set)
+            @test Laplace(g_3D, stencil_set) isa TensorMapping{T,3,3} where T
         end
     end
 
@@ -42,30 +42,44 @@
         # 2nd order interior stencil, 1st order boundary stencil,
         # implies that L*v should be exact for binomials up to order 2.
         @testset "2nd order" begin
-            stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2)
-            inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
-            closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
-            L = laplace(g_3D, inner_stencil, closure_stencils)
-            @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9
-            @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9
-            @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9
-            @test L*v ≈ Δv rtol = 5e-2 norm = l2
+            stencil_set = read_stencil_set(operator_path; order=2)
+            Δ = Laplace(g_3D, stencil_set)
+            @test Δ*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9
+            @test Δ*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9
+            @test Δ*polynomials[3] ≈ polynomials[1] atol = 5e-9
+            @test Δ*v ≈ Δv rtol = 5e-2 norm = l2
         end
 
         # 4th order interior stencil, 2nd order boundary stencil,
         # implies that L*v should be exact for binomials up to order 3.
         @testset "4th order" begin
-            stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4)
-            inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"])
-            closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"])
-            L = laplace(g_3D, inner_stencil, closure_stencils)
+            stencil_set = read_stencil_set(operator_path; order=4)
+            Δ = Laplace(g_3D, stencil_set)
             # NOTE: high tolerances for checking the "exact" differentiation
             # due to accumulation of round-off errors/cancellation errors?
-            @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9
-            @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9
-            @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9
-            @test L*polynomials[4] ≈ polynomials[2] atol = 5e-9
-            @test L*v ≈ Δv rtol = 5e-4 norm = l2
+            @test Δ*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9
+            @test Δ*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9
+            @test Δ*polynomials[3] ≈ polynomials[1] atol = 5e-9
+            @test Δ*polynomials[4] ≈ polynomials[2] atol = 5e-9
+            @test Δ*v ≈ Δv rtol = 5e-4 norm = l2
         end
     end
 end
+
+@testset "laplace" begin
+    @testset "1D" begin
+        Δ = laplace(g_1D, inner_stencil, closure_stencils)
+        @test Δ == second_derivative(g_1D, inner_stencil, closure_stencils)
+        @test Δ isa TensorMapping{T,1,1}  where T
+    end
+    @testset "3D" begin
+        Δ = laplace(g_3D, inner_stencil, closure_stencils)
+        @test Δ isa TensorMapping{T,3,3} where T
+        Dxx = second_derivative(g_3D, inner_stencil, closure_stencils, 1)
+        Dyy = second_derivative(g_3D, inner_stencil, closure_stencils, 2)
+        Dzz = second_derivative(g_3D, inner_stencil, closure_stencils, 3)
+        @test Δ == Dxx + Dyy + Dzz
+        @test Δ isa TensorMapping{T,3,3} where T
+    end
+end
+