Mercurial > repos > public > sbplib_julia
changeset 892:06c510d40ebb feature/variable_derivatives
Add parse_nested_stencil
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 10 Feb 2022 09:58:36 +0100 |
parents | f72cc96a58c6 |
children | 422c9f22cf92 |
files | src/SbpOperators/readoperator.jl test/SbpOperators/readoperator_test.jl |
diffstat | 2 files changed, 33 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SbpOperators/readoperator.jl Tue Feb 08 10:58:31 2022 +0100 +++ b/src/SbpOperators/readoperator.jl Thu Feb 10 09:58:36 2022 +0100 @@ -4,6 +4,7 @@ export get_stencil_set export parse_stencil +export parse_nested_stencil export parse_scalar export parse_tuple @@ -106,6 +107,25 @@ end end + +""" + parse_nested_stencil(parsed_toml) + + +""" +function parse_nested_stencil(parsed_toml) + if parsed_toml isa Array + weights = parse_stencil.(parsed_toml) + return CenteredNestedStencil(weights...) + end + + center = parsed_toml["c"] + weights = parse_tuple.(parsed_toml["s"]) + return NestedStencil(weights...; center) +end + + + """ parse_scalar(parsed_toml)
--- a/test/SbpOperators/readoperator_test.jl Tue Feb 08 10:58:31 2022 +0100 +++ b/test/SbpOperators/readoperator_test.jl Thu Feb 10 09:58:36 2022 +0100 @@ -4,6 +4,7 @@ using Sbplib.SbpOperators import Sbplib.SbpOperators.Stencil +import Sbplib.SbpOperators.NestedStencil @testset "readoperator" begin toml_str = """ @@ -170,3 +171,15 @@ @test SbpOperators.parse_rational(2) isa Rational @test SbpOperators.parse_rational(2) == 2//1 end + +@testset "parse_nested_stencil" begin + toml = TOML.parse(""" + s1 = [["1/2", "1/2", "0"],[ "-1/2", "-1", "-1/2"],["0", "1/2", "1/2"]] + s2 = {s = [[ "2", "-1", "0"],[ "-3", "1", "0"],["1", "0", "0"]], c = 1} + s3 = {s = [[ "2", "-1", "0"],[ "-3", "1", "0"],["1", "0", "0"]], c = 2} + """) + + @test parse_nested_stencil(toml["s1"]) == CenteredNestedStencil((1//2, 1//2, 0//1),( -1//2, -1//1, -1//2),(0//1, 1//2, 1//2)) + @test parse_nested_stencil(toml["s2"]) == NestedStencil((2//1, -1//1, 0//1),( -3//1, 1//1, 0//1),(1//1, 0//1, 0//1), center = 1) + @test parse_nested_stencil(toml["s3"]) == NestedStencil((2//1, -1//1, 0//1),( -3//1, 1//1, 0//1),(1//1, 0//1, 0//1), center = 2) +end