Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/volumeops/derivatives/first_derivative_test.jl @ 1359:646027afe74b bugfix/lazytensors
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 20 May 2023 14:33:25 +0200 |
parents | 356ec6a72974 |
children | 43aaf710463e |
comparison
equal
deleted
inserted
replaced
1299:4c0bc52e170f | 1359:646027afe74b |
---|---|
22 | 22 |
23 @testset "first_derivative" begin | 23 @testset "first_derivative" begin |
24 @testset "Constructors" begin | 24 @testset "Constructors" begin |
25 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) | 25 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) |
26 | 26 |
27 g₁ = EquidistantGrid(11, 0., 1.) | 27 g₁ = equidistant_grid(11, 0., 1.) |
28 g₂ = EquidistantGrid((11,14), (0.,1.), (1.,3.)) | 28 g₂ = equidistant_grid((11,14), (0.,1.), (1.,3.)) |
29 | 29 |
30 @test first_derivative(g₁, stencil_set, 1) isa LazyTensor{Float64,1,1} | 30 @test first_derivative(g₁, stencil_set) isa LazyTensor{Float64,1,1} |
31 @test first_derivative(g₂, stencil_set, 2) isa LazyTensor{Float64,2,2} | 31 @test first_derivative(g₂, stencil_set, 2) isa LazyTensor{Float64,2,2} |
32 @test first_derivative(g₁, stencil_set, 1) == first_derivative(g₁, stencil_set) | |
33 | 32 |
34 interior_stencil = CenteredStencil(-1,0,1) | 33 interior_stencil = CenteredStencil(-1,0,1) |
35 closure_stencils = [Stencil(-1,1, center=1)] | 34 closure_stencils = [Stencil(-1,1, center=1)] |
36 | 35 |
37 @test first_derivative(g₁, interior_stencil, closure_stencils, 1) isa LazyTensor{Float64,1,1} | 36 @test first_derivative(g₁, interior_stencil, closure_stencils) isa LazyTensor{Float64,1,1} |
38 @test first_derivative(g₁, interior_stencil, closure_stencils, 1) isa VolumeOperator | |
39 @test first_derivative(g₁, interior_stencil, closure_stencils, 1) == first_derivative(g₁, interior_stencil, closure_stencils) | |
40 @test first_derivative(g₂, interior_stencil, closure_stencils, 2) isa LazyTensor{Float64,2,2} | |
41 end | 37 end |
42 | 38 |
43 @testset "Accuracy conditions" begin | 39 @testset "Accuracy conditions" begin |
44 N = 20 | 40 N = 20 |
45 g = EquidistantGrid(N, 0//1,2//1) | 41 g = equidistant_grid(N, 0//1,2//1) |
46 @testset for order ∈ [2,4] | 42 @testset for order ∈ [2,4] |
47 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) | 43 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) |
48 D₁ = first_derivative(g, stencil_set, 1) | 44 D₁ = first_derivative(g, stencil_set) |
49 | 45 |
50 @testset "boundary x^$k" for k ∈ 0:order÷2 | 46 @testset "boundary x^$k" for k ∈ 0:order÷2 |
51 v = evalOn(g, x->monomial(x,k)) | 47 v = eval_on(g, x->monomial(x,k)) |
52 | 48 |
53 @testset for i ∈ 1:closure_size(D₁) | 49 @testset for i ∈ 1:closure_size(D₁) |
54 x, = points(g)[i] | 50 x, = g[i] |
55 @test (D₁*v)[i] == monomial(x,k-1) | 51 @test (D₁*v)[i] == monomial(x,k-1) |
56 end | 52 end |
57 | 53 |
58 @testset for i ∈ (N-closure_size(D₁)+1):N | 54 @testset for i ∈ (N-closure_size(D₁)+1):N |
59 x, = points(g)[i] | 55 x, = g[i] |
60 @test (D₁*v)[i] == monomial(x,k-1) | 56 @test (D₁*v)[i] == monomial(x,k-1) |
61 end | 57 end |
62 end | 58 end |
63 | 59 |
64 @testset "interior x^$k" for k ∈ 0:order | 60 @testset "interior x^$k" for k ∈ 0:order |
65 v = evalOn(g, x->monomial(x,k)) | 61 v = eval_on(g, x->monomial(x,k)) |
66 | 62 |
67 x, = points(g)[10] | 63 x, = g[10] |
68 @test (D₁*v)[10] == monomial(x,k-1) | 64 @test (D₁*v)[10] == monomial(x,k-1) |
69 end | 65 end |
70 end | 66 end |
71 end | 67 end |
72 | 68 |
73 @testset "Accuracy on function" begin | 69 @testset "Accuracy on function" begin |
74 # 1D | 70 @testset "1D" begin |
75 g = EquidistantGrid(30, 0.,1.) | 71 g = equidistant_grid(30, 0.,1.) |
76 v = evalOn(g, x->exp(x)) | 72 v = eval_on(g, x->exp(x)) |
77 @testset for (order, tol) ∈ [(2, 6e-3),(4, 2e-4)] | 73 @testset for (order, tol) ∈ [(2, 6e-3),(4, 2e-4)] |
78 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) | 74 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) |
79 D₁ = first_derivative(g, stencil_set, 1) | 75 D₁ = first_derivative(g, stencil_set) |
80 | 76 |
81 @test D₁*v ≈ v rtol=tol | 77 @test D₁*v ≈ v rtol=tol |
78 end | |
82 end | 79 end |
83 | 80 |
84 # 2D | 81 @testset "2D" begin |
85 g = EquidistantGrid((30,60), (0.,0.),(1.,2.)) | 82 g = equidistant_grid((30,60), (0.,0.),(1.,2.)) |
86 v = evalOn(g, (x,y)->exp(0.8x+1.2*y)) | 83 v = eval_on(g, (x,y)->exp(0.8x+1.2*y)) |
87 @testset for (order, tol) ∈ [(2, 6e-3),(4, 3e-4)] | 84 @testset for (order, tol) ∈ [(2, 6e-3),(4, 3e-4)] |
88 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) | 85 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) |
89 Dx = first_derivative(g, stencil_set, 1) | 86 Dx = first_derivative(g, stencil_set, 1) |
90 Dy = first_derivative(g, stencil_set, 2) | 87 Dy = first_derivative(g, stencil_set, 2) |
91 | 88 |
92 @test Dx*v ≈ 0.8v rtol=tol | 89 @test Dx*v ≈ 0.8v rtol=tol |
93 @test Dy*v ≈ 1.2v rtol=tol | 90 @test Dy*v ≈ 1.2v rtol=tol |
91 end | |
94 end | 92 end |
95 end | 93 end |
96 end | 94 end |
97 | 95 |