Mercurial > repos > public > sbplib_julia
changeset 884:d228d1b26729 feature/variable_derivatives
Add tests for application
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 28 Jan 2022 10:37:57 +0100 |
parents | 61f5850ca456 |
children | 1051d211c2d9 |
files | src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl test/SbpOperators/volumeops/derivatives/second_derivative_variable_test.jl |
diffstat | 2 files changed, 22 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl Fri Jan 21 13:20:33 2022 +0100 +++ b/src/SbpOperators/volumeops/derivatives/second_derivative_variable.jl Fri Jan 28 10:37:57 2022 +0100 @@ -47,18 +47,20 @@ LazyTensors.domain_size(op::SecondDerivativeVariable) = op.size function LazyTensors.apply(op::SecondDerivativeVariable{T}, v::AbstractVector{T}, i::Index{Lower}) where T - return @inbounds apply_stencil(op.closure_stencils[Int(i)], v, Int(i)) + return @inbounds apply_stencil(op.closure_stencils[Int(i)], op.coefficient, v, Int(i)) end function LazyTensors.apply(op::SecondDerivativeVariable{T}, v::AbstractVector{T}, i::Index{Interior}) where T - return apply_stencil(op.inner_stencil, v, Int(i)) + return apply_stencil(op.inner_stencil, op.coefficient, v, Int(i)) end function LazyTensors.apply(op::SecondDerivativeVariable{T}, v::AbstractVector{T}, i::Index{Upper}) where T - return @inbounds Int(op.parity)*apply_stencil_backwards(op.closure_stencils[op.size[1]-Int(i)+1], v, Int(i)) + return @inbounds apply_stencil_backwards(op.closure_stencils[op.size[1]-Int(i)+1], op.coefficient, v, Int(i)) end function LazyTensors.apply(op::SecondDerivativeVariable{T}, v::AbstractVector{T}, i) where T r = getregion(i, closure_size(op), op.size[1]) return LazyTensors.apply(op, v, Index(i, r)) end + +# TODO: Rename SecondDerivativeVariable -> VariableSecondDerivative
--- a/test/SbpOperators/volumeops/derivatives/second_derivative_variable_test.jl Fri Jan 21 13:20:33 2022 +0100 +++ b/test/SbpOperators/volumeops/derivatives/second_derivative_variable_test.jl Fri Jan 28 10:37:57 2022 +0100 @@ -11,10 +11,9 @@ g = EquidistantGrid(11, 0., 1.) c = [ 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66] - interior_stencil = CenteredNestedStencil((-1/2, -1/2, 0.),( 1/2, 1., 1/2),( 0., -1/2, -1/2)) + interior_stencil = CenteredNestedStencil((1/2, 1/2, 0.),(-1/2, -1., -1/2),( 0., 1/2, 1/2)) closure_stencils = [ - NestedStencil(( 1/2, 1/2, 0.),(-1/2, -1/2, 0.), center = 1), - NestedStencil((-1/2, -1/2, 0.),( 1/2, 1., 1/2), center = 2), + NestedStencil(( 2., -1., 0.),(-3., 1., 0.), (1., 0., 0.), center = 1), ] @testset "Constructors" begin @@ -24,13 +23,26 @@ @testset "sizes" begin D₂ᶜ = SecondDerivativeVariable(g, c, interior_stencil, closure_stencils) - @test closure_size(D₂ᶜ) == 2 + @test closure_size(D₂ᶜ) == 1 @test range_size(D₂ᶜ) == (11,) @test domain_size(D₂ᶜ) == (11,) end @testset "application" begin - # @test D₂(c)*v = + + function apply_to_functions(;v,c) + g = EquidistantGrid(11, 0., 10.) # h = 1 + c̄ = evalOn(g,c) + v̄ = evalOn(g,v) + + D₂ᶜ = SecondDerivativeVariable(g, c̄, interior_stencil, closure_stencils) + return D₂ᶜ*v̄ + end + + @test apply_to_functions(v=x->1., c=x->-1.) == zeros(11) + @test apply_to_functions(v=x->1., c=x->-x) == zeros(11) + @test apply_to_functions(v=x->x, c=x-> 1.) == zeros(11) + @test apply_to_functions(v=x->x, c=x->-x) == -ones(11) end end