Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/volumeops/derivatives/first_derivative_test.jl @ 1854:654a2b7e6824 tooling/benchmarks
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 11 Jan 2025 10:19:47 +0100 |
parents | 471a948cd2b2 |
children |
comparison
equal
deleted
inserted
replaced
1378:2b5480e2d4bf | 1854:654a2b7e6824 |
---|---|
1 using Test | 1 using Test |
2 | 2 |
3 | 3 |
4 using Sbplib.SbpOperators | 4 using Diffinitive.SbpOperators |
5 using Sbplib.Grids | 5 using Diffinitive.Grids |
6 using Sbplib.LazyTensors | 6 using Diffinitive.LazyTensors |
7 | 7 |
8 using Sbplib.SbpOperators: closure_size, Stencil, VolumeOperator | 8 using Diffinitive.SbpOperators: closure_size, Stencil, VolumeOperator |
9 | |
10 """ | |
11 monomial(x,k) | |
12 | |
13 Evaluates ``x^k/k!` with the convetion that it is ``0`` for all ``k<0``. | |
14 Has the property that ``d/dx monomial(x,k) = monomial(x,k-1)`` | |
15 """ | |
16 function monomial(x,k) | |
17 if k < 0 | |
18 return zero(x) | |
19 end | |
20 x^k/factorial(k) | |
21 end | |
22 | 9 |
23 @testset "first_derivative" begin | 10 @testset "first_derivative" begin |
24 @testset "Constructors" begin | 11 @testset "Constructors" begin |
25 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) | 12 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) |
26 | 13 |
27 g₁ = equidistant_grid(11, 0., 1.) | 14 g₁ = equidistant_grid(0., 1., 11) |
28 g₂ = equidistant_grid((11,14), (0.,1.), (1.,3.)) | 15 g₂ = equidistant_grid((0.,1.), (1.,3.), 11, 14) |
29 | 16 |
30 @test first_derivative(g₁, stencil_set) isa LazyTensor{Float64,1,1} | 17 @test first_derivative(g₁, stencil_set) isa LazyTensor{Float64,1,1} |
31 @test first_derivative(g₂, stencil_set, 2) isa LazyTensor{Float64,2,2} | 18 @test first_derivative(g₂, stencil_set, 2) isa LazyTensor{Float64,2,2} |
32 | 19 |
33 interior_stencil = CenteredStencil(-1,0,1) | 20 interior_stencil = CenteredStencil(-1,0,1) |
36 @test first_derivative(g₁, interior_stencil, closure_stencils) isa LazyTensor{Float64,1,1} | 23 @test first_derivative(g₁, interior_stencil, closure_stencils) isa LazyTensor{Float64,1,1} |
37 end | 24 end |
38 | 25 |
39 @testset "Accuracy conditions" begin | 26 @testset "Accuracy conditions" begin |
40 N = 20 | 27 N = 20 |
41 g = equidistant_grid(N, 0//1,2//1) | 28 g = equidistant_grid(0//1, 2//1, N) |
29 | |
30 monomial(x,k) = k < 0 ? zero(x) : x^k/factorial(k) | |
42 @testset for order ∈ [2,4] | 31 @testset for order ∈ [2,4] |
43 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) | 32 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) |
44 D₁ = first_derivative(g, stencil_set) | 33 D₁ = first_derivative(g, stencil_set) |
45 | 34 |
46 @testset "boundary x^$k" for k ∈ 0:order÷2 | 35 @testset "boundary x^$k" for k ∈ 0:order÷2 |
66 end | 55 end |
67 end | 56 end |
68 | 57 |
69 @testset "Accuracy on function" begin | 58 @testset "Accuracy on function" begin |
70 @testset "1D" begin | 59 @testset "1D" begin |
71 g = equidistant_grid(30, 0.,1.) | 60 g = equidistant_grid(0., 1., 30) |
72 v = eval_on(g, x->exp(x)) | 61 v = eval_on(g, x->exp(x)) |
73 @testset for (order, tol) ∈ [(2, 6e-3),(4, 2e-4)] | 62 @testset for (order, tol) ∈ [(2, 6e-3),(4, 2e-4)] |
74 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) | 63 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) |
75 D₁ = first_derivative(g, stencil_set) | 64 D₁ = first_derivative(g, stencil_set) |
76 | 65 |
77 @test D₁*v ≈ v rtol=tol | 66 @test D₁*v ≈ v rtol=tol |
78 end | 67 end |
79 end | 68 end |
80 | 69 |
81 @testset "2D" begin | 70 @testset "2D" begin |
82 g = equidistant_grid((30,60), (0.,0.),(1.,2.)) | 71 g = equidistant_grid((0.,0.),(1.,2.), 30, 60) |
83 v = eval_on(g, (x,y)->exp(0.8x+1.2*y)) | 72 v = eval_on(g, (x,y)->exp(0.8x+1.2*y)) |
84 @testset for (order, tol) ∈ [(2, 6e-3),(4, 3e-4)] | 73 @testset for (order, tol) ∈ [(2, 6e-3),(4, 3e-4)] |
85 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) |
86 Dx = first_derivative(g, stencil_set, 1) | 75 Dx = first_derivative(g, stencil_set, 1) |
87 Dy = first_derivative(g, stencil_set, 2) | 76 Dy = first_derivative(g, stencil_set, 2) |