Mercurial > repos > public > sbplib_julia
annotate test/SbpOperators/volumeops/laplace/laplace_test.jl @ 1983:730c9848ad0b feature/grids/geometry_functions
Update docstring for check_transfiniteinterpolation
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 26 Feb 2025 22:50:52 +0100 |
parents | 471a948cd2b2 |
children | f3d7e2d7a43f |
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 |
1726
471a948cd2b2
Rename project from Sbplib to Diffinitive
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1615
diff
changeset
|
3 using Diffinitive.SbpOperators |
471a948cd2b2
Rename project from Sbplib to Diffinitive
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1615
diff
changeset
|
4 using Diffinitive.Grids |
471a948cd2b2
Rename project from Sbplib to Diffinitive
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1615
diff
changeset
|
5 using Diffinitive.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 |
1615
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
92 # TODO: The following tests should be implemented |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
93 # 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
|
94 # 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
|
95 # 3. Test tuning of Dirichlet conditions |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
96 # |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
97 # These tests are likely easiest to implement once |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
98 # we have support for generating matrices from tensors. |
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
99 |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 |
1615
b74e1a21265f
Add todos to test
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1613
diff
changeset
|
106 # 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
|
107 # 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
|
108 # 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
|
109 # conditions chosen. |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
110 |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
111 @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
|
112 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
|
113 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
|
114 Δ = 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
|
115 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
|
116 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
|
117 Δ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
|
118 D = Δ |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
119 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
|
120 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
|
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 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
|
123 # Accuracy |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
124 @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
|
125 # Symmetry |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
126 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
|
127 @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
|
128 end |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
129 end |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
130 |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
131 @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
|
132 @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
|
133 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
|
134 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
|
135 Δ = 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
|
136 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
|
137 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
|
138 Δ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
|
139 D = Δ |
1598
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
140 for id ∈ boundary_identifiers(g) |
1613
15488c889a50
Fix variable name
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1603
diff
changeset
|
141 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
|
142 end |
1613
15488c889a50
Fix variable name
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1603
diff
changeset
|
143 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
|
144 # Accuracy |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
145 @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
|
146 # Symmetry |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
147 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
|
148 @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
|
149 end |
19cdec9c21cb
Implement and test sat_tensors for Dirichlet and Neumann conditions
Vidar Stiernström <vidar.stiernstrom@gmail.com>
parents:
1594
diff
changeset
|
150 end |
1485
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
151 end |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
152 end |
e96ee7d7ac9c
Test sat_tensors for Laplace w. Neumann conditions
Vidar Stiernström <vidar.stiernstrom@it.uu.se>
parents:
1291
diff
changeset
|
153 |