Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/SbpOperators_test.jl @ 711:df88aee35bb9 feature/selectable_tests
Switch to _test.jl suffix
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Sat, 20 Feb 2021 20:45:40 +0100 |
| parents | test/SbpOperators/testSbpOperators.jl@48a61e085e60 |
| children | 11a444d6fc93 |
comparison
equal
deleted
inserted
replaced
| 710:44fa9a171557 | 711:df88aee35bb9 |
|---|---|
| 1 using Test | |
| 2 using Sbplib.SbpOperators | |
| 3 using Sbplib.Grids | |
| 4 using Sbplib.RegionIndices | |
| 5 using Sbplib.LazyTensors | |
| 6 using LinearAlgebra | |
| 7 using TOML | |
| 8 | |
| 9 import Sbplib.SbpOperators.Stencil | |
| 10 import Sbplib.SbpOperators.VolumeOperator | |
| 11 import Sbplib.SbpOperators.volume_operator | |
| 12 import Sbplib.SbpOperators.BoundaryOperator | |
| 13 import Sbplib.SbpOperators.boundary_operator | |
| 14 import Sbplib.SbpOperators.even | |
| 15 import Sbplib.SbpOperators.odd | |
| 16 | |
| 17 | |
| 18 @testset "SbpOperators" begin | |
| 19 | |
| 20 @testset "Stencil" begin | |
| 21 s = Stencil((-2,2), (1.,2.,2.,3.,4.)) | |
| 22 @test s isa Stencil{Float64, 5} | |
| 23 | |
| 24 @test eltype(s) == Float64 | |
| 25 @test SbpOperators.scale(s, 2) == Stencil((-2,2), (2.,4.,4.,6.,8.)) | |
| 26 | |
| 27 @test Stencil(1,2,3,4; center=1) == Stencil((0, 3),(1,2,3,4)) | |
| 28 @test Stencil(1,2,3,4; center=2) == Stencil((-1, 2),(1,2,3,4)) | |
| 29 @test Stencil(1,2,3,4; center=4) == Stencil((-3, 0),(1,2,3,4)) | |
| 30 | |
| 31 @test CenteredStencil(1,2,3,4,5) == Stencil((-2, 2), (1,2,3,4,5)) | |
| 32 @test_throws ArgumentError CenteredStencil(1,2,3,4) | |
| 33 end | |
| 34 | |
| 35 @testset "parse_rational" begin | |
| 36 @test SbpOperators.parse_rational("1") isa Rational | |
| 37 @test SbpOperators.parse_rational("1") == 1//1 | |
| 38 @test SbpOperators.parse_rational("1/2") isa Rational | |
| 39 @test SbpOperators.parse_rational("1/2") == 1//2 | |
| 40 @test SbpOperators.parse_rational("37/13") isa Rational | |
| 41 @test SbpOperators.parse_rational("37/13") == 37//13 | |
| 42 end | |
| 43 | |
| 44 @testset "readoperator" begin | |
| 45 toml_str = """ | |
| 46 [meta] | |
| 47 type = "equidistant" | |
| 48 | |
| 49 [order2] | |
| 50 H.inner = ["1"] | |
| 51 | |
| 52 D1.inner_stencil = ["-1/2", "0", "1/2"] | |
| 53 D1.closure_stencils = [ | |
| 54 ["-1", "1"], | |
| 55 ] | |
| 56 | |
| 57 d1.closure = ["-3/2", "2", "-1/2"] | |
| 58 | |
| 59 [order4] | |
| 60 H.closure = ["17/48", "59/48", "43/48", "49/48"] | |
| 61 | |
| 62 D2.inner_stencil = ["-1/12","4/3","-5/2","4/3","-1/12"] | |
| 63 D2.closure_stencils = [ | |
| 64 [ "2", "-5", "4", "-1", "0", "0"], | |
| 65 [ "1", "-2", "1", "0", "0", "0"], | |
| 66 [ "-4/43", "59/43", "-110/43", "59/43", "-4/43", "0"], | |
| 67 [ "-1/49", "0", "59/49", "-118/49", "64/49", "-4/49"], | |
| 68 ] | |
| 69 """ | |
| 70 | |
| 71 parsed_toml = TOML.parse(toml_str) | |
| 72 @testset "get_stencil" begin | |
| 73 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil") == Stencil(-1/2, 0., 1/2, center=2) | |
| 74 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=1) == Stencil(-1/2, 0., 1/2; center=1) | |
| 75 @test get_stencil(parsed_toml, "order2", "D1", "inner_stencil", center=3) == Stencil(-1/2, 0., 1/2; center=3) | |
| 76 | |
| 77 @test get_stencil(parsed_toml, "order2", "H", "inner") == Stencil(1.; center=1) | |
| 78 | |
| 79 @test_throws AssertionError get_stencil(parsed_toml, "meta", "type") | |
| 80 @test_throws AssertionError get_stencil(parsed_toml, "order2", "D1", "closure_stencils") | |
| 81 end | |
| 82 | |
| 83 @testset "get_stencils" begin | |
| 84 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(1,)) == (Stencil(-1., 1., center=1),) | |
| 85 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=(2,)) == (Stencil(-1., 1., center=2),) | |
| 86 @test get_stencils(parsed_toml, "order2", "D1", "closure_stencils", centers=[2]) == (Stencil(-1., 1., center=2),) | |
| 87 | |
| 88 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=[1,1,1,1]) == ( | |
| 89 Stencil( 2., -5., 4., -1., 0., 0., center=1), | |
| 90 Stencil( 1., -2., 1., 0., 0., 0., center=1), | |
| 91 Stencil( -4/43, 59/43, -110/43, 59/43, -4/43, 0., center=1), | |
| 92 Stencil( -1/49, 0., 59/49, -118/49, 64/49, -4/49, center=1), | |
| 93 ) | |
| 94 | |
| 95 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(4,2,3,1)) == ( | |
| 96 Stencil( 2., -5., 4., -1., 0., 0., center=4), | |
| 97 Stencil( 1., -2., 1., 0., 0., 0., center=2), | |
| 98 Stencil( -4/43, 59/43, -110/43, 59/43, -4/43, 0., center=3), | |
| 99 Stencil( -1/49, 0., 59/49, -118/49, 64/49, -4/49, center=1), | |
| 100 ) | |
| 101 | |
| 102 @test get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=1:4) == ( | |
| 103 Stencil( 2., -5., 4., -1., 0., 0., center=1), | |
| 104 Stencil( 1., -2., 1., 0., 0., 0., center=2), | |
| 105 Stencil( -4/43, 59/43, -110/43, 59/43, -4/43, 0., center=3), | |
| 106 Stencil( -1/49, 0., 59/49, -118/49, 64/49, -4/49, center=4), | |
| 107 ) | |
| 108 | |
| 109 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3)) | |
| 110 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "closure_stencils",centers=(1,2,3,5,4)) | |
| 111 @test_throws AssertionError get_stencils(parsed_toml, "order4", "D2", "inner_stencil",centers=(1,2)) | |
| 112 end | |
| 113 | |
| 114 @testset "get_tuple" begin | |
| 115 @test get_tuple(parsed_toml, "order2", "d1", "closure") == (-3/2, 2, -1/2) | |
| 116 | |
| 117 @test_throws AssertionError get_tuple(parsed_toml, "meta", "type") | |
| 118 end | |
| 119 end | |
| 120 | |
| 121 @testset "VolumeOperator" begin | |
| 122 inner_stencil = CenteredStencil(1/4, 2/4, 1/4) | |
| 123 closure_stencils = (Stencil(1/2, 1/2; center=1), Stencil(0.,1.; center=2)) | |
| 124 g_1D = EquidistantGrid(11,0.,1.) | |
| 125 g_2D = EquidistantGrid((11,12),(0.,0.),(1.,1.)) | |
| 126 g_3D = EquidistantGrid((11,12,10),(0.,0.,0.),(1.,1.,1.)) | |
| 127 @testset "Constructors" begin | |
| 128 @testset "1D" begin | |
| 129 op = VolumeOperator(inner_stencil,closure_stencils,(11,),even) | |
| 130 @test op == VolumeOperator(g_1D,inner_stencil,closure_stencils,even) | |
| 131 @test op == volume_operator(g_1D,inner_stencil,closure_stencils,even,1) | |
| 132 @test op isa TensorMapping{T,1,1} where T | |
| 133 end | |
| 134 @testset "2D" begin | |
| 135 op_x = volume_operator(g_2D,inner_stencil,closure_stencils,even,1) | |
| 136 op_y = volume_operator(g_2D,inner_stencil,closure_stencils,even,2) | |
| 137 Ix = IdentityMapping{Float64}((11,)) | |
| 138 Iy = IdentityMapping{Float64}((12,)) | |
| 139 @test op_x == VolumeOperator(inner_stencil,closure_stencils,(11,),even)⊗Iy | |
| 140 @test op_y == Ix⊗VolumeOperator(inner_stencil,closure_stencils,(12,),even) | |
| 141 @test op_x isa TensorMapping{T,2,2} where T | |
| 142 @test op_y isa TensorMapping{T,2,2} where T | |
| 143 end | |
| 144 @testset "3D" begin | |
| 145 op_x = volume_operator(g_3D,inner_stencil,closure_stencils,even,1) | |
| 146 op_y = volume_operator(g_3D,inner_stencil,closure_stencils,even,2) | |
| 147 op_z = volume_operator(g_3D,inner_stencil,closure_stencils,even,3) | |
| 148 Ix = IdentityMapping{Float64}((11,)) | |
| 149 Iy = IdentityMapping{Float64}((12,)) | |
| 150 Iz = IdentityMapping{Float64}((10,)) | |
| 151 @test op_x == VolumeOperator(inner_stencil,closure_stencils,(11,),even)⊗Iy⊗Iz | |
| 152 @test op_y == Ix⊗VolumeOperator(inner_stencil,closure_stencils,(12,),even)⊗Iz | |
| 153 @test op_z == Ix⊗Iy⊗VolumeOperator(inner_stencil,closure_stencils,(10,),even) | |
| 154 @test op_x isa TensorMapping{T,3,3} where T | |
| 155 @test op_y isa TensorMapping{T,3,3} where T | |
| 156 @test op_z isa TensorMapping{T,3,3} where T | |
| 157 end | |
| 158 end | |
| 159 | |
| 160 @testset "Sizes" begin | |
| 161 @testset "1D" begin | |
| 162 op = volume_operator(g_1D,inner_stencil,closure_stencils,even,1) | |
| 163 @test range_size(op) == domain_size(op) == size(g_1D) | |
| 164 end | |
| 165 | |
| 166 @testset "2D" begin | |
| 167 op_x = volume_operator(g_2D,inner_stencil,closure_stencils,even,1) | |
| 168 op_y = volume_operator(g_2D,inner_stencil,closure_stencils,even,2) | |
| 169 @test range_size(op_y) == domain_size(op_y) == | |
| 170 range_size(op_x) == domain_size(op_x) == size(g_2D) | |
| 171 end | |
| 172 @testset "3D" begin | |
| 173 op_x = volume_operator(g_3D,inner_stencil,closure_stencils,even,1) | |
| 174 op_y = volume_operator(g_3D,inner_stencil,closure_stencils,even,2) | |
| 175 op_z = volume_operator(g_3D,inner_stencil,closure_stencils,even,3) | |
| 176 @test range_size(op_z) == domain_size(op_z) == | |
| 177 range_size(op_y) == domain_size(op_y) == | |
| 178 range_size(op_x) == domain_size(op_x) == size(g_3D) | |
| 179 end | |
| 180 end | |
| 181 | |
| 182 op_x = volume_operator(g_2D,inner_stencil,closure_stencils,even,1) | |
| 183 op_y = volume_operator(g_2D,inner_stencil,closure_stencils,odd,2) | |
| 184 v = zeros(size(g_2D)) | |
| 185 Nx = size(g_2D)[1] | |
| 186 Ny = size(g_2D)[2] | |
| 187 for i = 1:Nx | |
| 188 v[i,:] .= i | |
| 189 end | |
| 190 rx = copy(v) | |
| 191 rx[1,:] .= 1.5 | |
| 192 rx[Nx,:] .= (2*Nx-1)/2 | |
| 193 ry = copy(v) | |
| 194 ry[:,Ny-1:Ny] = -v[:,Ny-1:Ny] | |
| 195 | |
| 196 @testset "Application" begin | |
| 197 @test op_x*v ≈ rx rtol = 1e-14 | |
| 198 @test op_y*v ≈ ry rtol = 1e-14 | |
| 199 end | |
| 200 | |
| 201 @testset "Regions" begin | |
| 202 @test (op_x*v)[Index(1,Lower),Index(3,Interior)] ≈ rx[1,3] rtol = 1e-14 | |
| 203 @test (op_x*v)[Index(2,Lower),Index(3,Interior)] ≈ rx[2,3] rtol = 1e-14 | |
| 204 @test (op_x*v)[Index(6,Interior),Index(3,Interior)] ≈ rx[6,3] rtol = 1e-14 | |
| 205 @test (op_x*v)[Index(10,Upper),Index(3,Interior)] ≈ rx[10,3] rtol = 1e-14 | |
| 206 @test (op_x*v)[Index(11,Upper),Index(3,Interior)] ≈ rx[11,3] rtol = 1e-14 | |
| 207 | |
| 208 @test_throws BoundsError (op_x*v)[Index(3,Lower),Index(3,Interior)] | |
| 209 @test_throws BoundsError (op_x*v)[Index(9,Upper),Index(3,Interior)] | |
| 210 | |
| 211 @test (op_y*v)[Index(3,Interior),Index(1,Lower)] ≈ ry[3,1] rtol = 1e-14 | |
| 212 @test (op_y*v)[Index(3,Interior),Index(2,Lower)] ≈ ry[3,2] rtol = 1e-14 | |
| 213 @test (op_y*v)[Index(3,Interior),Index(6,Interior)] ≈ ry[3,6] rtol = 1e-14 | |
| 214 @test (op_y*v)[Index(3,Interior),Index(11,Upper)] ≈ ry[3,11] rtol = 1e-14 | |
| 215 @test (op_y*v)[Index(3,Interior),Index(12,Upper)] ≈ ry[3,12] rtol = 1e-14 | |
| 216 | |
| 217 @test_throws BoundsError (op_y*v)[Index(3,Interior),Index(10,Upper)] | |
| 218 @test_throws BoundsError (op_y*v)[Index(3,Interior),Index(3,Lower)] | |
| 219 end | |
| 220 | |
| 221 @testset "Inferred" begin | |
| 222 @inferred apply(op_x, v,1,1) | |
| 223 @inferred apply(op_x, v, Index(1,Lower),Index(1,Lower)) | |
| 224 @inferred apply(op_x, v, Index(6,Interior),Index(1,Lower)) | |
| 225 @inferred apply(op_x, v, Index(11,Upper),Index(1,Lower)) | |
| 226 | |
| 227 @inferred apply(op_y, v,1,1) | |
| 228 @inferred apply(op_y, v, Index(1,Lower),Index(1,Lower)) | |
| 229 @inferred apply(op_y, v, Index(1,Lower),Index(6,Interior)) | |
| 230 @inferred apply(op_y, v, Index(1,Lower),Index(11,Upper)) | |
| 231 end | |
| 232 | |
| 233 end | |
| 234 | |
| 235 @testset "SecondDerivative" begin | |
| 236 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 237 Lx = 3.5 | |
| 238 Ly = 3. | |
| 239 g_1D = EquidistantGrid(121, 0.0, Lx) | |
| 240 g_2D = EquidistantGrid((121,123), (0.0, 0.0), (Lx, Ly)) | |
| 241 | |
| 242 @testset "Constructors" begin | |
| 243 @testset "1D" begin | |
| 244 Dₓₓ = second_derivative(g_1D,op.innerStencil,op.closureStencils) | |
| 245 @test Dₓₓ == second_derivative(g_1D,op.innerStencil,op.closureStencils,1) | |
| 246 @test Dₓₓ isa VolumeOperator | |
| 247 end | |
| 248 @testset "2D" begin | |
| 249 Dₓₓ = second_derivative(g_2D,op.innerStencil,op.closureStencils,1) | |
| 250 D2 = second_derivative(g_1D,op.innerStencil,op.closureStencils) | |
| 251 I = IdentityMapping{Float64}(size(g_2D)[2]) | |
| 252 @test Dₓₓ == D2⊗I | |
| 253 @test Dₓₓ isa TensorMapping{T,2,2} where T | |
| 254 end | |
| 255 end | |
| 256 | |
| 257 # Exact differentiation is measured point-wise. In other cases | |
| 258 # the error is measured in the l2-norm. | |
| 259 @testset "Accuracy" begin | |
| 260 @testset "1D" begin | |
| 261 l2(v) = sqrt(spacing(g_1D)[1]*sum(v.^2)); | |
| 262 monomials = () | |
| 263 maxOrder = 4; | |
| 264 for i = 0:maxOrder-1 | |
| 265 f_i(x) = 1/factorial(i)*x^i | |
| 266 monomials = (monomials...,evalOn(g_1D,f_i)) | |
| 267 end | |
| 268 v = evalOn(g_1D,x -> sin(x)) | |
| 269 vₓₓ = evalOn(g_1D,x -> -sin(x)) | |
| 270 | |
| 271 # 2nd order interior stencil, 1nd order boundary stencil, | |
| 272 # implies that L*v should be exact for monomials up to order 2. | |
| 273 @testset "2nd order" begin | |
| 274 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
| 275 Dₓₓ = second_derivative(g_1D,op.innerStencil,op.closureStencils) | |
| 276 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 | |
| 277 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 | |
| 278 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10 | |
| 279 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-2 norm = l2 | |
| 280 end | |
| 281 | |
| 282 # 4th order interior stencil, 2nd order boundary stencil, | |
| 283 # implies that L*v should be exact for monomials up to order 3. | |
| 284 @testset "4th order" begin | |
| 285 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 286 Dₓₓ = second_derivative(g_1D,op.innerStencil,op.closureStencils) | |
| 287 # NOTE: high tolerances for checking the "exact" differentiation | |
| 288 # due to accumulation of round-off errors/cancellation errors? | |
| 289 @test Dₓₓ*monomials[1] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 | |
| 290 @test Dₓₓ*monomials[2] ≈ zeros(Float64,size(g_1D)...) atol = 5e-10 | |
| 291 @test Dₓₓ*monomials[3] ≈ monomials[1] atol = 5e-10 | |
| 292 @test Dₓₓ*monomials[4] ≈ monomials[2] atol = 5e-10 | |
| 293 @test Dₓₓ*v ≈ vₓₓ rtol = 5e-4 norm = l2 | |
| 294 end | |
| 295 end | |
| 296 | |
| 297 @testset "2D" begin | |
| 298 l2(v) = sqrt(prod(spacing(g_2D))*sum(v.^2)); | |
| 299 binomials = () | |
| 300 maxOrder = 4; | |
| 301 for i = 0:maxOrder-1 | |
| 302 f_i(x,y) = 1/factorial(i)*y^i + x^i | |
| 303 binomials = (binomials...,evalOn(g_2D,f_i)) | |
| 304 end | |
| 305 v = evalOn(g_2D, (x,y) -> sin(x)+cos(y)) | |
| 306 v_yy = evalOn(g_2D,(x,y) -> -cos(y)) | |
| 307 | |
| 308 # 2nd order interior stencil, 1st order boundary stencil, | |
| 309 # implies that L*v should be exact for binomials up to order 2. | |
| 310 @testset "2nd order" begin | |
| 311 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
| 312 Dyy = second_derivative(g_2D,op.innerStencil,op.closureStencils,2) | |
| 313 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 | |
| 314 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 | |
| 315 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9 | |
| 316 @test Dyy*v ≈ v_yy rtol = 5e-2 norm = l2 | |
| 317 end | |
| 318 | |
| 319 # 4th order interior stencil, 2nd order boundary stencil, | |
| 320 # implies that L*v should be exact for binomials up to order 3. | |
| 321 @testset "4th order" begin | |
| 322 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 323 Dyy = second_derivative(g_2D,op.innerStencil,op.closureStencils,2) | |
| 324 # NOTE: high tolerances for checking the "exact" differentiation | |
| 325 # due to accumulation of round-off errors/cancellation errors? | |
| 326 @test Dyy*binomials[1] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 | |
| 327 @test Dyy*binomials[2] ≈ zeros(Float64,size(g_2D)...) atol = 5e-9 | |
| 328 @test Dyy*binomials[3] ≈ evalOn(g_2D,(x,y)->1.) atol = 5e-9 | |
| 329 @test Dyy*binomials[4] ≈ evalOn(g_2D,(x,y)->y) atol = 5e-9 | |
| 330 @test Dyy*v ≈ v_yy rtol = 5e-4 norm = l2 | |
| 331 end | |
| 332 end | |
| 333 end | |
| 334 end | |
| 335 | |
| 336 @testset "Laplace" begin | |
| 337 g_1D = EquidistantGrid(101, 0.0, 1.) | |
| 338 g_3D = EquidistantGrid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) | |
| 339 @testset "Constructors" begin | |
| 340 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 341 @testset "1D" begin | |
| 342 L = laplace(g_1D, op.innerStencil, op.closureStencils) | |
| 343 @test L == second_derivative(g_1D, op.innerStencil, op.closureStencils) | |
| 344 @test L isa TensorMapping{T,1,1} where T | |
| 345 end | |
| 346 @testset "3D" begin | |
| 347 L = laplace(g_3D, op.innerStencil, op.closureStencils) | |
| 348 @test L isa TensorMapping{T,3,3} where T | |
| 349 Dxx = second_derivative(g_3D, op.innerStencil, op.closureStencils,1) | |
| 350 Dyy = second_derivative(g_3D, op.innerStencil, op.closureStencils,2) | |
| 351 Dzz = second_derivative(g_3D, op.innerStencil, op.closureStencils,3) | |
| 352 @test L == Dxx + Dyy + Dzz | |
| 353 end | |
| 354 end | |
| 355 | |
| 356 # Exact differentiation is measured point-wise. In other cases | |
| 357 # the error is measured in the l2-norm. | |
| 358 @testset "Accuracy" begin | |
| 359 l2(v) = sqrt(prod(spacing(g_3D))*sum(v.^2)); | |
| 360 polynomials = () | |
| 361 maxOrder = 4; | |
| 362 for i = 0:maxOrder-1 | |
| 363 f_i(x,y,z) = 1/factorial(i)*(y^i + x^i + z^i) | |
| 364 polynomials = (polynomials...,evalOn(g_3D,f_i)) | |
| 365 end | |
| 366 v = evalOn(g_3D, (x,y,z) -> sin(x) + cos(y) + exp(z)) | |
| 367 Δv = evalOn(g_3D,(x,y,z) -> -sin(x) - cos(y) + exp(z)) | |
| 368 | |
| 369 # 2nd order interior stencil, 1st order boundary stencil, | |
| 370 # implies that L*v should be exact for binomials up to order 2. | |
| 371 @testset "2nd order" begin | |
| 372 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
| 373 L = laplace(g_3D,op.innerStencil,op.closureStencils) | |
| 374 @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | |
| 375 @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | |
| 376 @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9 | |
| 377 @test L*v ≈ Δv rtol = 5e-2 norm = l2 | |
| 378 end | |
| 379 | |
| 380 # 4th order interior stencil, 2nd order boundary stencil, | |
| 381 # implies that L*v should be exact for binomials up to order 3. | |
| 382 @testset "4th order" begin | |
| 383 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 384 L = laplace(g_3D,op.innerStencil,op.closureStencils) | |
| 385 # NOTE: high tolerances for checking the "exact" differentiation | |
| 386 # due to accumulation of round-off errors/cancellation errors? | |
| 387 @test L*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | |
| 388 @test L*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 | |
| 389 @test L*polynomials[3] ≈ polynomials[1] atol = 5e-9 | |
| 390 @test L*polynomials[4] ≈ polynomials[2] atol = 5e-9 | |
| 391 @test L*v ≈ Δv rtol = 5e-4 norm = l2 | |
| 392 end | |
| 393 end | |
| 394 end | |
| 395 | |
| 396 @testset "Diagonal-stencil inner_product" begin | |
| 397 Lx = π/2. | |
| 398 Ly = Float64(π) | |
| 399 Lz = 1. | |
| 400 g_1D = EquidistantGrid(77, 0.0, Lx) | |
| 401 g_2D = EquidistantGrid((77,66), (0.0, 0.0), (Lx,Ly)) | |
| 402 g_3D = EquidistantGrid((10,10, 10), (0.0, 0.0, 0.0), (Lx,Ly,Lz)) | |
| 403 integral(H,v) = sum(H*v) | |
| 404 @testset "inner_product" begin | |
| 405 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 406 @testset "0D" begin | |
| 407 H = inner_product(EquidistantGrid{Float64}(),op.quadratureClosure) | |
| 408 @test H == IdentityMapping{Float64}() | |
| 409 @test H isa TensorMapping{T,0,0} where T | |
| 410 end | |
| 411 @testset "1D" begin | |
| 412 H = inner_product(g_1D,op.quadratureClosure) | |
| 413 inner_stencil = CenteredStencil(1.) | |
| 414 @test H == inner_product(g_1D,op.quadratureClosure,inner_stencil) | |
| 415 @test H isa TensorMapping{T,1,1} where T | |
| 416 end | |
| 417 @testset "2D" begin | |
| 418 H = inner_product(g_2D,op.quadratureClosure) | |
| 419 H_x = inner_product(restrict(g_2D,1),op.quadratureClosure) | |
| 420 H_y = inner_product(restrict(g_2D,2),op.quadratureClosure) | |
| 421 @test H == H_x⊗H_y | |
| 422 @test H isa TensorMapping{T,2,2} where T | |
| 423 end | |
| 424 end | |
| 425 | |
| 426 @testset "Sizes" begin | |
| 427 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 428 @testset "1D" begin | |
| 429 H = inner_product(g_1D,op.quadratureClosure) | |
| 430 @test domain_size(H) == size(g_1D) | |
| 431 @test range_size(H) == size(g_1D) | |
| 432 end | |
| 433 @testset "2D" begin | |
| 434 H = inner_product(g_2D,op.quadratureClosure) | |
| 435 @test domain_size(H) == size(g_2D) | |
| 436 @test range_size(H) == size(g_2D) | |
| 437 end | |
| 438 end | |
| 439 | |
| 440 @testset "Accuracy" begin | |
| 441 @testset "1D" begin | |
| 442 v = () | |
| 443 for i = 0:4 | |
| 444 f_i(x) = 1/factorial(i)*x^i | |
| 445 v = (v...,evalOn(g_1D,f_i)) | |
| 446 end | |
| 447 u = evalOn(g_1D,x->sin(x)) | |
| 448 | |
| 449 @testset "2nd order" begin | |
| 450 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
| 451 H = inner_product(g_1D,op.quadratureClosure) | |
| 452 for i = 1:2 | |
| 453 @test integral(H,v[i]) ≈ v[i+1][end] - v[i+1][1] rtol = 1e-14 | |
| 454 end | |
| 455 @test integral(H,u) ≈ 1. rtol = 1e-4 | |
| 456 end | |
| 457 | |
| 458 @testset "4th order" begin | |
| 459 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 460 H = inner_product(g_1D,op.quadratureClosure) | |
| 461 for i = 1:4 | |
| 462 @test integral(H,v[i]) ≈ v[i+1][end] - v[i+1][1] rtol = 1e-14 | |
| 463 end | |
| 464 @test integral(H,u) ≈ 1. rtol = 1e-8 | |
| 465 end | |
| 466 end | |
| 467 | |
| 468 @testset "2D" begin | |
| 469 b = 2.1 | |
| 470 v = b*ones(Float64, size(g_2D)) | |
| 471 u = evalOn(g_2D,(x,y)->sin(x)+cos(y)) | |
| 472 @testset "2nd order" begin | |
| 473 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
| 474 H = inner_product(g_2D,op.quadratureClosure) | |
| 475 @test integral(H,v) ≈ b*Lx*Ly rtol = 1e-13 | |
| 476 @test integral(H,u) ≈ π rtol = 1e-4 | |
| 477 end | |
| 478 @testset "4th order" begin | |
| 479 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 480 H = inner_product(g_2D,op.quadratureClosure) | |
| 481 @test integral(H,v) ≈ b*Lx*Ly rtol = 1e-13 | |
| 482 @test integral(H,u) ≈ π rtol = 1e-8 | |
| 483 end | |
| 484 end | |
| 485 end | |
| 486 end | |
| 487 | |
| 488 @testset "Diagonal-stencil inverse_inner_product" begin | |
| 489 Lx = π/2. | |
| 490 Ly = Float64(π) | |
| 491 g_1D = EquidistantGrid(77, 0.0, Lx) | |
| 492 g_2D = EquidistantGrid((77,66), (0.0, 0.0), (Lx,Ly)) | |
| 493 @testset "inverse_inner_product" begin | |
| 494 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 495 @testset "0D" begin | |
| 496 Hi = inverse_inner_product(EquidistantGrid{Float64}(),op.quadratureClosure) | |
| 497 @test Hi == IdentityMapping{Float64}() | |
| 498 @test Hi isa TensorMapping{T,0,0} where T | |
| 499 end | |
| 500 @testset "1D" begin | |
| 501 Hi = inverse_inner_product(g_1D, op.quadratureClosure); | |
| 502 inner_stencil = CenteredStencil(1.) | |
| 503 closures = () | |
| 504 for i = 1:length(op.quadratureClosure) | |
| 505 closures = (closures...,Stencil(op.quadratureClosure[i].range,1.0./op.quadratureClosure[i].weights)) | |
| 506 end | |
| 507 @test Hi == inverse_inner_product(g_1D,closures,inner_stencil) | |
| 508 @test Hi isa TensorMapping{T,1,1} where T | |
| 509 end | |
| 510 @testset "2D" begin | |
| 511 Hi = inverse_inner_product(g_2D,op.quadratureClosure) | |
| 512 Hi_x = inverse_inner_product(restrict(g_2D,1),op.quadratureClosure) | |
| 513 Hi_y = inverse_inner_product(restrict(g_2D,2),op.quadratureClosure) | |
| 514 @test Hi == Hi_x⊗Hi_y | |
| 515 @test Hi isa TensorMapping{T,2,2} where T | |
| 516 end | |
| 517 end | |
| 518 | |
| 519 @testset "Sizes" begin | |
| 520 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 521 @testset "1D" begin | |
| 522 Hi = inverse_inner_product(g_1D,op.quadratureClosure) | |
| 523 @test domain_size(Hi) == size(g_1D) | |
| 524 @test range_size(Hi) == size(g_1D) | |
| 525 end | |
| 526 @testset "2D" begin | |
| 527 Hi = inverse_inner_product(g_2D,op.quadratureClosure) | |
| 528 @test domain_size(Hi) == size(g_2D) | |
| 529 @test range_size(Hi) == size(g_2D) | |
| 530 end | |
| 531 end | |
| 532 | |
| 533 @testset "Accuracy" begin | |
| 534 @testset "1D" begin | |
| 535 v = evalOn(g_1D,x->sin(x)) | |
| 536 u = evalOn(g_1D,x->x^3-x^2+1) | |
| 537 @testset "2nd order" begin | |
| 538 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
| 539 H = inner_product(g_1D,op.quadratureClosure) | |
| 540 Hi = inverse_inner_product(g_1D,op.quadratureClosure) | |
| 541 @test Hi*H*v ≈ v rtol = 1e-15 | |
| 542 @test Hi*H*u ≈ u rtol = 1e-15 | |
| 543 end | |
| 544 @testset "4th order" begin | |
| 545 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 546 H = inner_product(g_1D,op.quadratureClosure) | |
| 547 Hi = inverse_inner_product(g_1D,op.quadratureClosure) | |
| 548 @test Hi*H*v ≈ v rtol = 1e-15 | |
| 549 @test Hi*H*u ≈ u rtol = 1e-15 | |
| 550 end | |
| 551 end | |
| 552 @testset "2D" begin | |
| 553 v = evalOn(g_2D,(x,y)->sin(x)+cos(y)) | |
| 554 u = evalOn(g_2D,(x,y)->x*y + x^5 - sqrt(y)) | |
| 555 @testset "2nd order" begin | |
| 556 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
| 557 H = inner_product(g_2D,op.quadratureClosure) | |
| 558 Hi = inverse_inner_product(g_2D,op.quadratureClosure) | |
| 559 @test Hi*H*v ≈ v rtol = 1e-15 | |
| 560 @test Hi*H*u ≈ u rtol = 1e-15 | |
| 561 end | |
| 562 @testset "4th order" begin | |
| 563 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 564 H = inner_product(g_2D,op.quadratureClosure) | |
| 565 Hi = inverse_inner_product(g_2D,op.quadratureClosure) | |
| 566 @test Hi*H*v ≈ v rtol = 1e-15 | |
| 567 @test Hi*H*u ≈ u rtol = 1e-15 | |
| 568 end | |
| 569 end | |
| 570 end | |
| 571 end | |
| 572 | |
| 573 @testset "BoundaryOperator" begin | |
| 574 closure_stencil = Stencil((0,2), (2.,1.,3.)) | |
| 575 g_1D = EquidistantGrid(11, 0.0, 1.0) | |
| 576 g_2D = EquidistantGrid((11,15), (0.0, 0.0), (1.0,1.0)) | |
| 577 | |
| 578 @testset "Constructors" begin | |
| 579 @testset "1D" begin | |
| 580 op_l = BoundaryOperator{Lower}(closure_stencil,size(g_1D)[1]) | |
| 581 @test op_l == BoundaryOperator(g_1D,closure_stencil,Lower()) | |
| 582 @test op_l == boundary_operator(g_1D,closure_stencil,CartesianBoundary{1,Lower}()) | |
| 583 @test op_l isa TensorMapping{T,0,1} where T | |
| 584 | |
| 585 op_r = BoundaryOperator{Upper}(closure_stencil,size(g_1D)[1]) | |
| 586 @test op_r == BoundaryOperator(g_1D,closure_stencil,Upper()) | |
| 587 @test op_r == boundary_operator(g_1D,closure_stencil,CartesianBoundary{1,Upper}()) | |
| 588 @test op_r isa TensorMapping{T,0,1} where T | |
| 589 end | |
| 590 | |
| 591 @testset "2D" begin | |
| 592 e_w = boundary_operator(g_2D,closure_stencil,CartesianBoundary{1,Upper}()) | |
| 593 @test e_w isa InflatedTensorMapping | |
| 594 @test e_w isa TensorMapping{T,1,2} where T | |
| 595 end | |
| 596 end | |
| 597 | |
| 598 op_l = boundary_operator(g_1D, closure_stencil, CartesianBoundary{1,Lower}()) | |
| 599 op_r = boundary_operator(g_1D, closure_stencil, CartesianBoundary{1,Upper}()) | |
| 600 | |
| 601 op_w = boundary_operator(g_2D, closure_stencil, CartesianBoundary{1,Lower}()) | |
| 602 op_e = boundary_operator(g_2D, closure_stencil, CartesianBoundary{1,Upper}()) | |
| 603 op_s = boundary_operator(g_2D, closure_stencil, CartesianBoundary{2,Lower}()) | |
| 604 op_n = boundary_operator(g_2D, closure_stencil, CartesianBoundary{2,Upper}()) | |
| 605 | |
| 606 @testset "Sizes" begin | |
| 607 @testset "1D" begin | |
| 608 @test domain_size(op_l) == (11,) | |
| 609 @test domain_size(op_r) == (11,) | |
| 610 | |
| 611 @test range_size(op_l) == () | |
| 612 @test range_size(op_r) == () | |
| 613 end | |
| 614 | |
| 615 @testset "2D" begin | |
| 616 @test domain_size(op_w) == (11,15) | |
| 617 @test domain_size(op_e) == (11,15) | |
| 618 @test domain_size(op_s) == (11,15) | |
| 619 @test domain_size(op_n) == (11,15) | |
| 620 | |
| 621 @test range_size(op_w) == (15,) | |
| 622 @test range_size(op_e) == (15,) | |
| 623 @test range_size(op_s) == (11,) | |
| 624 @test range_size(op_n) == (11,) | |
| 625 end | |
| 626 end | |
| 627 | |
| 628 @testset "Application" begin | |
| 629 @testset "1D" begin | |
| 630 v = evalOn(g_1D,x->1+x^2) | |
| 631 u = fill(3.124) | |
| 632 @test (op_l*v)[] == 2*v[1] + v[2] + 3*v[3] | |
| 633 @test (op_r*v)[] == 2*v[end] + v[end-1] + 3*v[end-2] | |
| 634 @test (op_r*v)[1] == 2*v[end] + v[end-1] + 3*v[end-2] | |
| 635 @test op_l'*u == [2*u[]; u[]; 3*u[]; zeros(8)] | |
| 636 @test op_r'*u == [zeros(8); 3*u[]; u[]; 2*u[]] | |
| 637 end | |
| 638 | |
| 639 @testset "2D" begin | |
| 640 v = rand(size(g_2D)...) | |
| 641 u = fill(3.124) | |
| 642 @test op_w*v ≈ 2*v[1,:] + v[2,:] + 3*v[3,:] rtol = 1e-14 | |
| 643 @test op_e*v ≈ 2*v[end,:] + v[end-1,:] + 3*v[end-2,:] rtol = 1e-14 | |
| 644 @test op_s*v ≈ 2*v[:,1] + v[:,2] + 3*v[:,3] rtol = 1e-14 | |
| 645 @test op_n*v ≈ 2*v[:,end] + v[:,end-1] + 3*v[:,end-2] rtol = 1e-14 | |
| 646 | |
| 647 | |
| 648 g_x = rand(size(g_2D)[1]) | |
| 649 g_y = rand(size(g_2D)[2]) | |
| 650 | |
| 651 G_w = zeros(Float64, size(g_2D)...) | |
| 652 G_w[1,:] = 2*g_y | |
| 653 G_w[2,:] = g_y | |
| 654 G_w[3,:] = 3*g_y | |
| 655 | |
| 656 G_e = zeros(Float64, size(g_2D)...) | |
| 657 G_e[end,:] = 2*g_y | |
| 658 G_e[end-1,:] = g_y | |
| 659 G_e[end-2,:] = 3*g_y | |
| 660 | |
| 661 G_s = zeros(Float64, size(g_2D)...) | |
| 662 G_s[:,1] = 2*g_x | |
| 663 G_s[:,2] = g_x | |
| 664 G_s[:,3] = 3*g_x | |
| 665 | |
| 666 G_n = zeros(Float64, size(g_2D)...) | |
| 667 G_n[:,end] = 2*g_x | |
| 668 G_n[:,end-1] = g_x | |
| 669 G_n[:,end-2] = 3*g_x | |
| 670 | |
| 671 @test op_w'*g_y == G_w | |
| 672 @test op_e'*g_y == G_e | |
| 673 @test op_s'*g_x == G_s | |
| 674 @test op_n'*g_x == G_n | |
| 675 end | |
| 676 | |
| 677 @testset "Regions" begin | |
| 678 u = fill(3.124) | |
| 679 @test (op_l'*u)[Index(1,Lower)] == 2*u[] | |
| 680 @test (op_l'*u)[Index(2,Lower)] == u[] | |
| 681 @test (op_l'*u)[Index(6,Interior)] == 0 | |
| 682 @test (op_l'*u)[Index(10,Upper)] == 0 | |
| 683 @test (op_l'*u)[Index(11,Upper)] == 0 | |
| 684 | |
| 685 @test (op_r'*u)[Index(1,Lower)] == 0 | |
| 686 @test (op_r'*u)[Index(2,Lower)] == 0 | |
| 687 @test (op_r'*u)[Index(6,Interior)] == 0 | |
| 688 @test (op_r'*u)[Index(10,Upper)] == u[] | |
| 689 @test (op_r'*u)[Index(11,Upper)] == 2*u[] | |
| 690 end | |
| 691 end | |
| 692 | |
| 693 @testset "Inferred" begin | |
| 694 v = ones(Float64, 11) | |
| 695 u = fill(1.) | |
| 696 | |
| 697 @inferred apply(op_l, v) | |
| 698 @inferred apply(op_r, v) | |
| 699 | |
| 700 @inferred apply_transpose(op_l, u, 4) | |
| 701 @inferred apply_transpose(op_l, u, Index(1,Lower)) | |
| 702 @inferred apply_transpose(op_l, u, Index(2,Lower)) | |
| 703 @inferred apply_transpose(op_l, u, Index(6,Interior)) | |
| 704 @inferred apply_transpose(op_l, u, Index(10,Upper)) | |
| 705 @inferred apply_transpose(op_l, u, Index(11,Upper)) | |
| 706 | |
| 707 @inferred apply_transpose(op_r, u, 4) | |
| 708 @inferred apply_transpose(op_r, u, Index(1,Lower)) | |
| 709 @inferred apply_transpose(op_r, u, Index(2,Lower)) | |
| 710 @inferred apply_transpose(op_r, u, Index(6,Interior)) | |
| 711 @inferred apply_transpose(op_r, u, Index(10,Upper)) | |
| 712 @inferred apply_transpose(op_r, u, Index(11,Upper)) | |
| 713 end | |
| 714 | |
| 715 end | |
| 716 | |
| 717 @testset "boundary_restriction" begin | |
| 718 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 719 g_1D = EquidistantGrid(11, 0.0, 1.0) | |
| 720 g_2D = EquidistantGrid((11,15), (0.0, 0.0), (1.0,1.0)) | |
| 721 | |
| 722 @testset "boundary_restriction" begin | |
| 723 @testset "1D" begin | |
| 724 e_l = boundary_restriction(g_1D,op.eClosure,Lower()) | |
| 725 @test e_l == boundary_restriction(g_1D,op.eClosure,CartesianBoundary{1,Lower}()) | |
| 726 @test e_l == BoundaryOperator(g_1D,op.eClosure,Lower()) | |
| 727 @test e_l isa BoundaryOperator{T,Lower} where T | |
| 728 @test e_l isa TensorMapping{T,0,1} where T | |
| 729 | |
| 730 e_r = boundary_restriction(g_1D,op.eClosure,Upper()) | |
| 731 @test e_r == boundary_restriction(g_1D,op.eClosure,CartesianBoundary{1,Upper}()) | |
| 732 @test e_r == BoundaryOperator(g_1D,op.eClosure,Upper()) | |
| 733 @test e_r isa BoundaryOperator{T,Upper} where T | |
| 734 @test e_r isa TensorMapping{T,0,1} where T | |
| 735 end | |
| 736 | |
| 737 @testset "2D" begin | |
| 738 e_w = boundary_restriction(g_2D,op.eClosure,CartesianBoundary{1,Upper}()) | |
| 739 @test e_w isa InflatedTensorMapping | |
| 740 @test e_w isa TensorMapping{T,1,2} where T | |
| 741 end | |
| 742 end | |
| 743 | |
| 744 @testset "Application" begin | |
| 745 @testset "1D" begin | |
| 746 e_l = boundary_restriction(g_1D, op.eClosure, CartesianBoundary{1,Lower}()) | |
| 747 e_r = boundary_restriction(g_1D, op.eClosure, CartesianBoundary{1,Upper}()) | |
| 748 | |
| 749 v = evalOn(g_1D,x->1+x^2) | |
| 750 u = fill(3.124) | |
| 751 | |
| 752 @test (e_l*v)[] == v[1] | |
| 753 @test (e_r*v)[] == v[end] | |
| 754 @test (e_r*v)[1] == v[end] | |
| 755 end | |
| 756 | |
| 757 @testset "2D" begin | |
| 758 e_w = boundary_restriction(g_2D, op.eClosure, CartesianBoundary{1,Lower}()) | |
| 759 e_e = boundary_restriction(g_2D, op.eClosure, CartesianBoundary{1,Upper}()) | |
| 760 e_s = boundary_restriction(g_2D, op.eClosure, CartesianBoundary{2,Lower}()) | |
| 761 e_n = boundary_restriction(g_2D, op.eClosure, CartesianBoundary{2,Upper}()) | |
| 762 | |
| 763 v = rand(11, 15) | |
| 764 u = fill(3.124) | |
| 765 | |
| 766 @test e_w*v == v[1,:] | |
| 767 @test e_e*v == v[end,:] | |
| 768 @test e_s*v == v[:,1] | |
| 769 @test e_n*v == v[:,end] | |
| 770 end | |
| 771 end | |
| 772 end | |
| 773 | |
| 774 @testset "normal_derivative" begin | |
| 775 g_1D = EquidistantGrid(11, 0.0, 1.0) | |
| 776 g_2D = EquidistantGrid((11,12), (0.0, 0.0), (1.0,1.0)) | |
| 777 @testset "normal_derivative" begin | |
| 778 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 779 @testset "1D" begin | |
| 780 d_l = normal_derivative(g_1D, op.dClosure, Lower()) | |
| 781 @test d_l == normal_derivative(g_1D, op.dClosure, CartesianBoundary{1,Lower}()) | |
| 782 @test d_l isa BoundaryOperator{T,Lower} where T | |
| 783 @test d_l isa TensorMapping{T,0,1} where T | |
| 784 end | |
| 785 @testset "2D" begin | |
| 786 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 787 d_w = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Lower}()) | |
| 788 d_n = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Upper}()) | |
| 789 Ix = IdentityMapping{Float64}((size(g_2D)[1],)) | |
| 790 Iy = IdentityMapping{Float64}((size(g_2D)[2],)) | |
| 791 d_l = normal_derivative(restrict(g_2D,1),op.dClosure,Lower()) | |
| 792 d_r = normal_derivative(restrict(g_2D,2),op.dClosure,Upper()) | |
| 793 @test d_w == d_l⊗Iy | |
| 794 @test d_n == Ix⊗d_r | |
| 795 @test d_w isa TensorMapping{T,1,2} where T | |
| 796 @test d_n isa TensorMapping{T,1,2} where T | |
| 797 end | |
| 798 end | |
| 799 @testset "Accuracy" begin | |
| 800 v = evalOn(g_2D, (x,y)-> x^2 + (y-1)^2 + x*y) | |
| 801 v∂x = evalOn(g_2D, (x,y)-> 2*x + y) | |
| 802 v∂y = evalOn(g_2D, (x,y)-> 2*(y-1) + x) | |
| 803 # TODO: Test for higher order polynomials? | |
| 804 @testset "2nd order" begin | |
| 805 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=2) | |
| 806 d_w = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Lower}()) | |
| 807 d_e = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Upper}()) | |
| 808 d_s = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Lower}()) | |
| 809 d_n = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Upper}()) | |
| 810 | |
| 811 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 | |
| 812 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 | |
| 813 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 | |
| 814 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 | |
| 815 end | |
| 816 | |
| 817 @testset "4th order" begin | |
| 818 op = read_D2_operator(sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
| 819 d_w = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Lower}()) | |
| 820 d_e = normal_derivative(g_2D, op.dClosure, CartesianBoundary{1,Upper}()) | |
| 821 d_s = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Lower}()) | |
| 822 d_n = normal_derivative(g_2D, op.dClosure, CartesianBoundary{2,Upper}()) | |
| 823 | |
| 824 @test d_w*v ≈ v∂x[1,:] atol = 1e-13 | |
| 825 @test d_e*v ≈ -v∂x[end,:] atol = 1e-13 | |
| 826 @test d_s*v ≈ v∂y[:,1] atol = 1e-13 | |
| 827 @test d_n*v ≈ -v∂y[:,end] atol = 1e-13 | |
| 828 end | |
| 829 end | |
| 830 end | |
| 831 | |
| 832 end |
