Mercurial > repos > public > sbplib_julia
annotate test/SbpOperators/volumeops/laplace/laplace_test.jl @ 1603:fca4a01d60c9 feature/boundary_conditions
Remove module BoundaryConditions, moving its content to SbpOperators
author | Vidar Stiernström <vidar.stiernstrom@gmail.com> |
---|---|
date | Tue, 04 Jun 2024 16:46:14 -0700 |
parents | 19cdec9c21cb |
children | 15488c889a50 |
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 |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
7 @testset "Laplace" begin |
1285
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
8 # Default stencils (4th order) |
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
9 operator_path = sbp_operators_path()*"standard_diagonal.toml" |
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
10 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
|
11 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
|
12 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
|
13 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
14 @testset "Constructors" begin |
750
f88b2117dc69
Merge in default
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
732
diff
changeset
|
15 @testset "1D" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
16 @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
|
17 @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
|
18 end |
f88b2117dc69
Merge in default
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
732
diff
changeset
|
19 @testset "3D" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
20 @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
|
21 @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
|
22 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
23 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
24 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
25 # 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
|
26 # the error is measured in the l2-norm. |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
27 @testset "Accuracy" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
28 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
|
29 polynomials = () |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
30 maxOrder = 4; |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
31 for i = 0:maxOrder-1 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
32 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
|
33 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
|
34 end |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
35 # 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
|
36 # Δ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
|
37 |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
38 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
|
39 Δ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
|
40 @inferred v[1,2,3] |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
41 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
42 # 2nd order interior stencil, 1st order boundary stencil, |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
43 # 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
|
44 @testset "2nd order" begin |
1018
5ec49dd2c7c4
Reintroduce read_stencil_set
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
990
diff
changeset
|
45 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
|
46 Δ = 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
|
47 @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
|
48 @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
|
49 @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
|
50 @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
|
51 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
52 |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
53 # 4th order interior stencil, 2nd order boundary stencil, |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
54 # 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
|
55 @testset "4th order" begin |
1018
5ec49dd2c7c4
Reintroduce read_stencil_set
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
990
diff
changeset
|
56 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
|
57 Δ = Laplace(g_3D, stencil_set) |
728
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
58 # NOTE: high tolerances for checking the "exact" differentiation |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
59 # 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
|
60 @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
|
61 @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
|
62 @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
|
63 @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
|
64 @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
|
65 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
66 end |
45966c77cb20
Split tests for SbpOperators over several files
Jonatan Werpers <jonatan@werpers.com>
parents:
diff
changeset
|
67 end |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
68 |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
69 @testset "laplace" begin |
1285
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
70 operator_path = sbp_operators_path()*"standard_diagonal.toml" |
7d52c4835d15
Skip broken testsets
Jonatan Werpers <jonatan@werpers.com>
parents:
1040
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 |
924
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
75 @testset "1D" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
76 Δ = laplace(g_1D, stencil_set) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
77 @test Δ == second_derivative(g_1D, stencil_set) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
78 @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
|
79 end |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
80 @testset "3D" begin |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
81 Δ = laplace(g_3D, stencil_set) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
82 @test Δ isa LazyTensor{Float64,3,3} |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
83 Dxx = second_derivative(g_3D, stencil_set, 1) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
84 Dyy = second_derivative(g_3D, stencil_set, 2) |
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
85 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
|
86 @test Δ == Dxx + Dyy + Dzz |
1291
356ec6a72974
Implement changes in SbpOperators
Jonatan Werpers <jonatan@werpers.com>
parents:
1285
diff
changeset
|
87 @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
|
88 end |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
89 end |
12e8e431b43c
Start restructuring Laplace making it more minimal.
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
872
diff
changeset
|
90 |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
91 @testset "sat_tensors" begin |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
98 # Verify implementation of sat_tesnors by testing accuracy and symmetry (TODO) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
99 # 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
|
100 # 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
|
101 # conditions chosen. |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
102 |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
103 @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
|
104 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
|
105 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
|
106 Δ = 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
|
107 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
|
108 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
|
109 Δ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
|
110 D = Δ |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
111 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
|
112 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
|
113 end |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
114 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
|
115 # Accuracy |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
116 @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
|
117 # Symmetry |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
118 # TODO: # Consider generating the matrices to H and D and test D'H == H'D |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
119 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
|
120 @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
|
121 end |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
122 end |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
123 |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
124 @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
|
125 @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
|
126 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
|
127 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
|
128 Δ = 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
|
129 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
|
130 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
|
131 Δu = collect(eval_on(g, (x,y) -> -5*π^2*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
|
132 op = Δ |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
133 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
|
134 op = op + foldl(∘, sat_tensors(Δ, g, NeumannCondition(0., id))) |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
135 end |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
136 e = op*u .- Δu |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
137 # Accuracy |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
138 @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
|
139 # Symmetry |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
140 # TODO: # Consider generating the matrices to H and D and test D'H == H'D |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
141 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
|
142 @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
|
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 end |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
145 end |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
146 end |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
147 |