Mercurial > repos > public > sbplib_julia
comparison test/SbpOperators/volumeops/derivatives/first_derivative_test.jl @ 985:1b4f31ae114f
Merge feature/first_derivative
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Wed, 16 Mar 2022 18:32:59 +0100 |
| parents | 5bfc03cf3ba7 |
| children | 7bf3121c6864 1ba8a398af9c e00eb000346e |
comparison
equal
deleted
inserted
replaced
| 970:a52bd2f1126c | 985:1b4f31ae114f |
|---|---|
| 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, 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 | |
| 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, 1) isa VolumeOperator | |
| 38 @test first_derivative(g₂, interior_stencil, closure_stencils, 2) isa TensorMapping{Float64,2,2} | |
| 39 end | |
| 40 | |
| 41 @testset "Accuracy conditions" begin | |
| 42 N = 20 | |
| 43 g = EquidistantGrid(N, 0//1,2//1) | |
| 44 @testset for order ∈ [2,4] | |
| 45 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) | |
| 46 D₁ = first_derivative(g, stencil_set, 1) | |
| 47 | |
| 48 @testset "boundary x^$k" for k ∈ 0:order÷2 | |
| 49 v = evalOn(g, x->monomial(x,k)) | |
| 50 | |
| 51 @testset for i ∈ 1:closure_size(D₁) | |
| 52 x, = points(g)[i] | |
| 53 @test (D₁*v)[i] == monomial(x,k-1) | |
| 54 end | |
| 55 | |
| 56 @testset for i ∈ (N-closure_size(D₁)+1):N | |
| 57 x, = points(g)[i] | |
| 58 @test (D₁*v)[i] == monomial(x,k-1) | |
| 59 end | |
| 60 end | |
| 61 | |
| 62 @testset "interior x^$k" for k ∈ 0:order | |
| 63 v = evalOn(g, x->monomial(x,k)) | |
| 64 | |
| 65 x, = points(g)[10] | |
| 66 @test (D₁*v)[10] == monomial(x,k-1) | |
| 67 end | |
| 68 end | |
| 69 end | |
| 70 | |
| 71 @testset "Accuracy on function" begin | |
| 72 g = EquidistantGrid(30, 0.,1.) | |
| 73 v = evalOn(g, x->exp(x)) | |
| 74 @testset for (order, tol) ∈ [(2, 6e-3),(4, 2e-4)] | |
| 75 stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) | |
| 76 D₁ = first_derivative(g, stencil_set, 1) | |
| 77 | |
| 78 @test D₁*v ≈ v rtol=tol | |
| 79 end | |
| 80 end | |
| 81 end | |
| 82 |
