Mercurial > repos > public > sbplib_julia
annotate test/SbpOperators/volumeops/laplace/laplace_test.jl @ 1651:707fc9761c2b feature/sbp_operators/laplace_curvilinear
Merge feature/grids/manifolds
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 26 Jun 2024 12:47:26 +0200 |
parents | 0685d97ebcb0 b74e1a21265f |
children | a63278c25c40 |
rev | line source |
---|---|
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
1 using Test |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
2 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
3 using Sbplib.SbpOperators |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
4 using Sbplib.Grids |
732
6114274447f5
Add missing using and imports in test files
Jonatan Werpers <jonatan@werpers.com>
parents:
728
diff
changeset
|
5 using Sbplib.LazyTensors |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
6 |
1588 | 7 using StaticArrays |
8 | |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
9 @testset "Laplace" begin |
1285
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
10 # Default stencils (4th order) |
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
11 operator_path = sbp_operators_path()*"standard_diagonal.toml" |
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
12 stencil_set = read_stencil_set(operator_path; order=4) |
1529
43aaf710463e
Change to signature of equidistant_grid to same style as many array methods.
Jonatan Werpers <jonatan@werpers.com>
parents:
1291
diff
changeset
|
13 g_1D = equidistant_grid(0.0, 1., 101) |
43aaf710463e
Change to signature of equidistant_grid to same style as many array methods.
Jonatan Werpers <jonatan@werpers.com>
parents:
1291
diff
changeset
|
14 g_3D = equidistant_grid((0.0, -1.0, 0.0), (1., 1., 1.), 51, 101, 52) |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
15 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
16 @testset "Constructors" begin |
750
f88b2117dc69
Merge in default
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
732
diff
changeset
|
17 @testset "1D" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
18 @test Laplace(g_1D, stencil_set) == Laplace(laplace(g_1D, stencil_set), stencil_set) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
19 @test Laplace(g_1D, stencil_set) isa LazyTensor{Float64,1,1} |
750
f88b2117dc69
Merge in default
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
732
diff
changeset
|
20 end |
f88b2117dc69
Merge in default
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
732
diff
changeset
|
21 @testset "3D" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
22 @test Laplace(g_3D, stencil_set) == Laplace(laplace(g_3D, stencil_set),stencil_set) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
23 @test Laplace(g_3D, stencil_set) isa LazyTensor{Float64,3,3} |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
24 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
25 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
26 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
27 # Exact differentiation is measured point-wise. In other cases |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
28 # the error is measured in the l2-norm. |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
29 @testset "Accuracy" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
30 l2(v) = sqrt(prod(spacing.(g_3D.grids))*sum(v.^2)); |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
31 polynomials = () |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
32 maxOrder = 4; |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
33 for i = 0:maxOrder-1 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
34 f_i(x,y,z) = 1/factorial(i)*(y^i + x^i + z^i) |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
35 polynomials = (polynomials...,eval_on(g_3D,f_i)) |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
36 end |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
37 # v = eval_on(g_3D, (x,y,z) -> sin(x) + cos(y) + exp(z)) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
38 # Δv = eval_on(g_3D,(x,y,z) -> -sin(x) - cos(y) + exp(z)) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
39 |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
40 v = eval_on(g_3D, x̄ -> sin(x̄[1]) + cos(x̄[2]) + exp(x̄[3])) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
41 Δv = eval_on(g_3D, x̄ -> -sin(x̄[1]) - cos(x̄[2]) + exp(x̄[3])) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
42 @inferred v[1,2,3] |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
43 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
44 # 2nd order interior stencil, 1st order boundary stencil, |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
45 # implies that L*v should be exact for binomials up to order 2. |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
46 @testset "2nd order" begin |
1018
5ec49dd2c7c4
Reintroduce read_stencil_set
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
990
diff
changeset
|
47 stencil_set = read_stencil_set(operator_path; order=2) |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
48 Δ = Laplace(g_3D, stencil_set) |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
49 @test Δ*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
50 @test Δ*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
51 @test Δ*polynomials[3] ≈ polynomials[1] atol = 5e-9 |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
52 @test Δ*v ≈ Δv rtol = 5e-2 norm = l2 |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
53 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
54 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
55 # 4th order interior stencil, 2nd order boundary stencil, |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
56 # implies that L*v should be exact for binomials up to order 3. |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
57 @testset "4th order" begin |
1018
5ec49dd2c7c4
Reintroduce read_stencil_set
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
990
diff
changeset
|
58 stencil_set = read_stencil_set(operator_path; order=4) |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
59 Δ = Laplace(g_3D, stencil_set) |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
60 # NOTE: high tolerances for checking the "exact" differentiation |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
61 # due to accumulation of round-off errors/cancellation errors? |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
62 @test Δ*polynomials[1] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
63 @test Δ*polynomials[2] ≈ zeros(Float64, size(g_3D)...) atol = 5e-9 |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
64 @test Δ*polynomials[3] ≈ polynomials[1] atol = 5e-9 |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
65 @test Δ*polynomials[4] ≈ polynomials[2] atol = 5e-9 |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
66 @test Δ*v ≈ Δv rtol = 5e-4 norm = l2 |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
67 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
68 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
69 end |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
70 |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
71 @testset "laplace" begin |
1285
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
72 operator_path = sbp_operators_path()*"standard_diagonal.toml" |
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
73 stencil_set = read_stencil_set(operator_path; order=4) |
1529
43aaf710463e
Change to signature of equidistant_grid to same style as many array methods.
Jonatan Werpers <jonatan@werpers.com>
parents:
1291
diff
changeset
|
74 g_1D = equidistant_grid(0.0, 1., 101) |
43aaf710463e
Change to signature of equidistant_grid to same style as many array methods.
Jonatan Werpers <jonatan@werpers.com>
parents:
1291
diff
changeset
|
75 g_3D = equidistant_grid((0.0, -1.0, 0.0), (1., 1., 1.), 51, 101, 52) |
1285
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
76 |
1559
43e6acbefdd1
Rename testsets and add one for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents:
1529
diff
changeset
|
77 @testset "EquidistantGrid" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
78 Δ = laplace(g_1D, stencil_set) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
79 @test Δ == second_derivative(g_1D, stencil_set) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
80 @test Δ isa LazyTensor{Float64,1,1} |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
81 end |
1559
43e6acbefdd1
Rename testsets and add one for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents:
1529
diff
changeset
|
82 @testset "TensorGrid" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
83 Δ = laplace(g_3D, stencil_set) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
84 @test Δ isa LazyTensor{Float64,3,3} |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
85 Dxx = second_derivative(g_3D, stencil_set, 1) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
86 Dyy = second_derivative(g_3D, stencil_set, 2) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
87 Dzz = second_derivative(g_3D, stencil_set, 3) |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
88 @test Δ == Dxx + Dyy + Dzz |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
89 @test Δ isa LazyTensor{Float64,3,3} |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
90 end |
1559
43e6acbefdd1
Rename testsets and add one for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents:
1529
diff
changeset
|
91 |
43e6acbefdd1
Rename testsets and add one for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents:
1529
diff
changeset
|
92 @testset "MappedGrid" begin |
1588 | 93 c = Chart(unitsquare()) do (ξ,η) |
94 @SVector[2ξ + η*(1-η), 3η+(1+η/2)*ξ^2] | |
95 end | |
1590
62cb622cbe6b
Fix typo in test jacobian
Jonatan Werpers <jonatan@werpers.com>
parents:
1588
diff
changeset
|
96 Grids.jacobian(c::typeof(c), (ξ,η)) = @SMatrix[2 1-2η; (2+η)*ξ 3+ξ^2/2] |
1588 | 97 |
1647
0685d97ebcb0
Start adding test for laplace on mapped grid
Jonatan Werpers <jonatan@werpers.com>
parents:
1590
diff
changeset
|
98 g = equidistant_grid(c, 30,30) |
1588 | 99 |
100 @test laplace(g, stencil_set) isa LazyTensor{<:Any,2,2} | |
101 | |
1647
0685d97ebcb0
Start adding test for laplace on mapped grid
Jonatan Werpers <jonatan@werpers.com>
parents:
1590
diff
changeset
|
102 f((x,y)) = sin(4(x + y)) |
0685d97ebcb0
Start adding test for laplace on mapped grid
Jonatan Werpers <jonatan@werpers.com>
parents:
1590
diff
changeset
|
103 Δf((x,y)) = -16sin(4(x + y)) |
0685d97ebcb0
Start adding test for laplace on mapped grid
Jonatan Werpers <jonatan@werpers.com>
parents:
1590
diff
changeset
|
104 gf = map(f,g) |
1588 | 105 |
106 Δ = laplace(g, stencil_set) | |
107 | |
108 @test collect(Δ*gf) isa Array{<:Any,2} | |
1647
0685d97ebcb0
Start adding test for laplace on mapped grid
Jonatan Werpers <jonatan@werpers.com>
parents:
1590
diff
changeset
|
109 @test Δ*gf ≈ map(Δf, g) |
1559
43e6acbefdd1
Rename testsets and add one for mapped grids
Jonatan Werpers <jonatan@werpers.com>
parents:
1529
diff
changeset
|
110 end |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
111 end |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
112 |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
113 @testset "sat_tensors" begin |
1615
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
114 # TODO: The following tests should be implemented |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
115 # 1. Symmetry D'H == H'D (test_broken below) |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
116 # 2. Test eigenvalues of and/or solution to Poisson |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
117 # 3. Test tuning of Dirichlet conditions |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
118 # |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
119 # These tests are likely easiest to implement once |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
120 # we have support for generating matrices from tensors. |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
121 |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
122 operator_path = sbp_operators_path()*"standard_diagonal.toml" |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
123 orders = (2,4) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
124 tols = (5e-2,5e-4) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
125 sz = (201,401) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
126 g = equidistant_grid((0.,0.), (1.,1.), sz...) |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
127 |
1615
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
128 # Verify implementation of sat_tensors by testing accuracy and symmetry (TODO) |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
129 # of the operator D = Δ + SAT, where SAT is the tensor composition of the |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
130 # operators from sat_tensor. Note that SAT*u should approximate 0 for the |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
131 # conditions chosen. |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
132 |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
133 @testset "Dirichlet" begin |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
134 for (o, tol) ∈ zip(orders,tols) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
135 stencil_set = read_stencil_set(operator_path; order=o) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
136 Δ = Laplace(g, stencil_set) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
137 H = inner_product(g, stencil_set) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
138 u = collect(eval_on(g, (x,y) -> sin(π*x)sin(2*π*y))) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
139 Δu = collect(eval_on(g, (x,y) -> -5*π^2*sin(π*x)sin(2*π*y))) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
140 D = Δ |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
141 for id ∈ boundary_identifiers(g) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
142 D = D + foldl(∘, sat_tensors(Δ, g, DirichletCondition(0., id))) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
143 end |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
144 e = D*u .- Δu |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
145 # Accuracy |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
146 @test sqrt(sum(H*e.^2)) ≈ 0 atol = tol |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
147 # Symmetry |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
148 r = randn(size(u)) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
149 @test_broken (D'∘H - H∘D)*r .≈ 0 atol = 1e-13 # TODO: Need to implement apply_transpose for D. |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
150 end |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
151 end |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
152 |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
153 @testset "Neumann" begin |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
154 @testset "Dirichlet" begin |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
155 for (o, tol) ∈ zip(orders,tols) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
156 stencil_set = read_stencil_set(operator_path; order=o) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
157 Δ = Laplace(g, stencil_set) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
158 H = inner_product(g, stencil_set) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
159 u = collect(eval_on(g, (x,y) -> cos(π*x)cos(2*π*y))) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
160 Δu = collect(eval_on(g, (x,y) -> -5*π^2*cos(π*x)cos(2*π*y))) |
1613
15488c889a50
Fix variable name
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1603
diff
changeset
|
161 D = Δ |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
162 for id ∈ boundary_identifiers(g) |
1613
15488c889a50
Fix variable name
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1603
diff
changeset
|
163 D = D + foldl(∘, sat_tensors(Δ, g, NeumannCondition(0., id))) |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
164 end |
1613
15488c889a50
Fix variable name
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1603
diff
changeset
|
165 e = D*u .- Δu |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
166 # Accuracy |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
167 @test sqrt(sum(H*e.^2)) ≈ 0 atol = tol |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
168 # Symmetry |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
169 r = randn(size(u)) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
170 @test_broken (D'∘H - H∘D)*r .≈ 0 atol = 1e-13 # TODO: Need to implement apply_transpose for D. |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
171 end |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
172 end |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
173 end |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
174 end |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
175 |