comparison test/SbpOperators/volumeops/derivatives/first_derivative_test.jl @ 982:2a4f36aca2ea feature/variable_derivatives

Merge feature/variable_derivatives
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 15 Mar 2022 21:42:52 +0100
parents b90446eb5f27
children 5bfc03cf3ba7
comparison
equal deleted inserted replaced
981:df562695b1b5 982:2a4f36aca2ea
1 using Test
2
3
4 using Sbplib.SbpOperators
5 using Sbplib.Grids
6 using Sbplib.LazyTensors
7
8 using Sbplib.SbpOperators: closure_size, Stencil
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
23 @testset "first_derivative" begin
24 @testset "Constructors" begin
25 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2)
26
27 g₁ = EquidistantGrid(11, 0., 1.)
28 g₂ = EquidistantGrid((11,14), (0.,1.), (1.,3.))
29
30 @test first_derivative(g₁, stencil_set, 1) isa TensorMapping{Float64,1,1}
31 @test first_derivative(g₂, stencil_set, 2) isa TensorMapping{Float64,2,2}
32
33 interior_stencil = CenteredStencil(-1,0,1)
34 closure_stencils = [Stencil(-1,1, center=1)]
35
36 @test first_derivative(g₁, interior_stencil, closure_stencils, 1) isa TensorMapping{Float64,1,1}
37 @test first_derivative(g₂, interior_stencil, closure_stencils, 2) isa TensorMapping{Float64,2,2}
38 end
39
40 @testset "Accuracy conditions" begin
41 N = 20
42 g = EquidistantGrid(N, 0//1,2//1)
43 @testset for order ∈ [2,4]
44 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order)
45 D₁ = first_derivative(g, stencil_set, 1)
46
47 @testset "boundary x^$k" for k ∈ 0:order÷2
48 v = evalOn(g, x->monomial(x,k))
49
50 @testset for i ∈ 1:closure_size(D₁)
51 x, = points(g)[i]
52 @test (D₁*v)[i] == monomial(x,k-1)
53 end
54
55 @testset for i ∈ (N-closure_size(D₁)+1):N
56 x, = points(g)[i]
57 @test (D₁*v)[i] == monomial(x,k-1)
58 end
59 end
60
61 @testset "interior x^$k" for k ∈ 0:order
62 v = evalOn(g, x->monomial(x,k))
63
64 x, = points(g)[10]
65 @test (D₁*v)[10] == monomial(x,k-1)
66 end
67 end
68 end
69
70 @testset "Accuracy on function" begin
71 g = EquidistantGrid(30, 0.,1.)
72 v = evalOn(g, x->exp(x))
73 @testset for (order, tol) ∈ [(2, 6e-3),(4, 2e-4)]
74 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order)
75 D₁ = first_derivative(g, stencil_set, 1)
76
77 @test D₁*v ≈ v rtol=tol
78 end
79 end
80 end
81