Mercurial > repos > public > sbplib_julia
view test/SbpOperators/boundaryops/boundary_operator_test.jl @ 1107:f80e69b0566b refactor/sbpoperators/inflation
Remove 2D tests from boundary_operator_test
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 09 Jun 2022 07:24:11 +0200 |
parents | 0ba4609605d4 |
children | 6b24dc2d7b11 |
line wrap: on
line source
using Test using Sbplib.LazyTensors using Sbplib.SbpOperators using Sbplib.Grids using Sbplib.RegionIndices import Sbplib.SbpOperators.Stencil import Sbplib.SbpOperators.BoundaryOperator @testset "BoundaryOperator" begin closure_stencil = Stencil(2.,1.,3.; center = 1) g_1D = EquidistantGrid(11, 0.0, 1.0) g_2D = EquidistantGrid((11,15), (0.0, 0.0), (1.0,1.0)) @testset "Constructors" begin @testset "1D" begin # TODO: Remove these testsets op_l = BoundaryOperator{Lower}(closure_stencil,size(g_1D)[1]) @test op_l == BoundaryOperator(g_1D,closure_stencil,Lower()) @test op_l isa LazyTensor{T,0,1} where T op_r = BoundaryOperator{Upper}(closure_stencil,size(g_1D)[1]) # TBD: Is this constructor really needed? looks weird! @test op_r == BoundaryOperator(g_1D,closure_stencil,Upper()) @test op_r isa LazyTensor{T,0,1} where T end end op_l = BoundaryOperator(g_1D, closure_stencil, Lower()) op_r = BoundaryOperator(g_1D, closure_stencil, Upper()) @testset "Sizes" begin @testset "1D" begin @test domain_size(op_l) == (11,) @test domain_size(op_r) == (11,) @test range_size(op_l) == () @test range_size(op_r) == () end end @testset "Application" begin @testset "1D" begin v = evalOn(g_1D,x->1+x^2) u = fill(3.124) @test (op_l*v)[] == 2*v[1] + v[2] + 3*v[3] @test (op_r*v)[] == 2*v[end] + v[end-1] + 3*v[end-2] @test (op_r*v)[1] == 2*v[end] + v[end-1] + 3*v[end-2] @test op_l'*u == [2*u[]; u[]; 3*u[]; zeros(8)] @test op_r'*u == [zeros(8); 3*u[]; u[]; 2*u[]] v = evalOn(g_1D, x->1. +x*im) @test (op_l*v)[] isa ComplexF64 u = fill(1. +im) @test (op_l'*u)[1] isa ComplexF64 @test (op_l'*u)[5] isa ComplexF64 @test (op_l'*u)[11] isa ComplexF64 end @testset "Regions" begin u = fill(3.124) @test (op_l'*u)[Index(1,Lower)] == 2*u[] @test (op_l'*u)[Index(2,Lower)] == u[] @test (op_l'*u)[Index(6,Interior)] == 0 @test (op_l'*u)[Index(10,Upper)] == 0 @test (op_l'*u)[Index(11,Upper)] == 0 @test (op_r'*u)[Index(1,Lower)] == 0 @test (op_r'*u)[Index(2,Lower)] == 0 @test (op_r'*u)[Index(6,Interior)] == 0 @test (op_r'*u)[Index(10,Upper)] == u[] @test (op_r'*u)[Index(11,Upper)] == 2*u[] end end @testset "Inferred" begin v = ones(Float64, 11) u = fill(1.) @inferred apply(op_l, v) @inferred apply(op_r, v) @inferred apply_transpose(op_l, u, 4) @inferred apply_transpose(op_l, u, Index(1,Lower)) @inferred apply_transpose(op_l, u, Index(2,Lower)) @inferred apply_transpose(op_l, u, Index(6,Interior)) @inferred apply_transpose(op_l, u, Index(10,Upper)) @inferred apply_transpose(op_l, u, Index(11,Upper)) @inferred apply_transpose(op_r, u, 4) @inferred apply_transpose(op_r, u, Index(1,Lower)) @inferred apply_transpose(op_r, u, Index(2,Lower)) @inferred apply_transpose(op_r, u, Index(6,Interior)) @inferred apply_transpose(op_r, u, Index(10,Upper)) @inferred apply_transpose(op_r, u, Index(11,Upper)) end end