Mercurial > repos > public > sbplib_julia
changeset 964:2ae62dbaf839 feature/laplace_opset
Add method for creating second derivative from a stencil set.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Mon, 14 Mar 2022 10:43:11 +0100 |
parents | 52a0ebad0778 |
children | f7939de85980 |
files | src/SbpOperators/volumeops/derivatives/second_derivative.jl test/SbpOperators/volumeops/derivatives/second_derivative_test.jl |
diffstat | 2 files changed, 22 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/volumeops/derivatives/second_derivative.jl Mon Mar 14 10:16:03 2022 +0100 +++ b/src/SbpOperators/volumeops/derivatives/second_derivative.jl Mon Mar 14 10:43:11 2022 +0100 @@ -16,6 +16,16 @@ h_inv = inverse_spacing(grid)[direction] return SbpOperators.volume_operator(grid, scale(inner_stencil,h_inv^2), scale.(closure_stencils,h_inv^2), even, direction) end -second_derivative(grid::EquidistantGrid{1}, inner_stencil, closure_stencils) = second_derivative(grid,inner_stencil,closure_stencils,1) +second_derivative(grid::EquidistantGrid{1}, inner_stencil::Stencil, closure_stencils) = second_derivative(grid,inner_stencil,closure_stencils,1) + +""" + second_derivative(grid, stencil_set, direction) -# REVIEW: Stencil set method? +Creates a `second_derivative` operator on `grid` along coordinate dimension `direction` given a parsed TOML +`stencil_set`. +""" +function second_derivative(grid::EquidistantGrid, stencil_set, direction) + inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) + closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) + second_derivative(grid,inner_stencil,closure_stencils,direction); +end
--- a/test/SbpOperators/volumeops/derivatives/second_derivative_test.jl Mon Mar 14 10:16:03 2022 +0100 +++ b/test/SbpOperators/volumeops/derivatives/second_derivative_test.jl Mon Mar 14 10:43:11 2022 +0100 @@ -7,7 +7,8 @@ import Sbplib.SbpOperators.VolumeOperator @testset "SecondDerivative" begin - stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) + operator_path = sbp_operators_path()*"standard_diagonal.toml" + stencil_set = read_stencil_set(operator_path; order=4) inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) Lx = 3.5 @@ -17,8 +18,9 @@ @testset "Constructors" begin @testset "1D" begin - Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils) - @test Dₓₓ == second_derivative(g_1D,inner_stencil,closure_stencils,1) + Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils,1) + @test Dₓₓ == second_derivative(g_1D,inner_stencil,closure_stencils) + @test Dₓₓ == second_derivative(g_1D,stencil_set,1) @test Dₓₓ isa VolumeOperator end @testset "2D" begin @@ -26,6 +28,7 @@ D2 = second_derivative(g_1D,inner_stencil,closure_stencils) I = IdentityMapping{Float64}(size(g_2D)[2]) @test Dₓₓ == D2⊗I + @test Dₓₓ == second_derivative(g_2D,stencil_set,1) @test Dₓₓ isa TensorMapping{T,2,2} where T end end @@ -47,7 +50,7 @@ # 2nd order interior stencil, 1nd order boundary stencil, # implies that L*v should be exact for monomials up to order 2. @testset "2nd order" begin - stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) + stencil_set = read_stencil_set(operator_path; order=2) inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils) @@ -60,7 +63,7 @@ # 4th order interior stencil, 2nd order boundary stencil, # implies that L*v should be exact for monomials up to order 3. @testset "4th order" begin - stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) + stencil_set = read_stencil_set(operator_path; order=4) inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) Dₓₓ = second_derivative(g_1D,inner_stencil,closure_stencils) @@ -88,7 +91,7 @@ # 2nd order interior stencil, 1st order boundary stencil, # implies that L*v should be exact for binomials up to order 2. @testset "2nd order" begin - stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) + stencil_set = read_stencil_set(operator_path; order=2) inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) Dyy = second_derivative(g_2D,inner_stencil,closure_stencils,2) @@ -101,7 +104,7 @@ # 4th order interior stencil, 2nd order boundary stencil, # implies that L*v should be exact for binomials up to order 3. @testset "4th order" begin - stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) + stencil_set = read_stencil_set(operator_path; order=4) inner_stencil = parse_stencil(stencil_set["D2"]["inner_stencil"]) closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) Dyy = second_derivative(g_2D,inner_stencil,closure_stencils,2)