Mercurial > repos > public > sbplib_julia
changeset 832:00f6bbdcd73a operator_storage_array_of_table
Review: Include latest changes
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 12 Jan 2022 15:54:21 +0100 |
parents | cdc2b5ebf7cb (current diff) 760c11e81fd4 (diff) |
children | 454ba1efa644 |
files | |
diffstat | 12 files changed, 373 insertions(+), 119 deletions(-) [+] |
line wrap: on
line diff
--- a/Manifest.toml Wed Sep 22 13:09:46 2021 +0200 +++ b/Manifest.toml Wed Jan 12 15:54:21 2022 +0100 @@ -1,41 +1,59 @@ # This file is machine-generated - editing it directly is not advised -[[Adapt]] +julia_version = "1.7.0" +manifest_format = "2.0" + +[[deps.Adapt]] deps = ["LinearAlgebra"] git-tree-sha1 = "84918055d15b3114ede17ac6a7182f68870c16f7" uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" version = "3.3.1" -[[Dates]] +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.CompilerSupportLibraries_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" + +[[deps.Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" -[[Libdl]] +[[deps.Libdl]] uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" -[[LinearAlgebra]] -deps = ["Libdl"] +[[deps.LinearAlgebra]] +deps = ["Libdl", "libblastrampoline_jll"] uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -[[OffsetArrays]] +[[deps.OffsetArrays]] deps = ["Adapt"] -git-tree-sha1 = "2bf78c5fd7fa56d2bbf1efbadd45c1b8789e6f57" +git-tree-sha1 = "043017e0bdeff61cfbb7afeb558ab29536bbb5ed" uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "1.10.2" +version = "1.10.8" -[[Printf]] +[[deps.OpenBLAS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] +uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" + +[[deps.Printf]] deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" -[[TOML]] +[[deps.TOML]] deps = ["Dates"] uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -[[TiledIteration]] +[[deps.TiledIteration]] deps = ["OffsetArrays"] -git-tree-sha1 = "52c5f816857bfb3291c7d25420b1f4aca0a74d18" +git-tree-sha1 = "5683455224ba92ef59db72d10690690f4a8dc297" uuid = "06e1c1a7-607b-532d-9fad-de7d9aa2abac" -version = "0.3.0" +version = "0.3.1" -[[Unicode]] +[[deps.Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.libblastrampoline_jll]] +deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] +uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
--- a/Notes.md Wed Sep 22 13:09:46 2021 +0200 +++ b/Notes.md Wed Jan 12 15:54:21 2022 +0100 @@ -53,6 +53,19 @@ * Remove order as a table name and put it as a variable. +### Parsing +At the moment the only parsing that can be done at the top level is conversion +from the toml file to a dict of strings. This forces the user to dig through +the dictionary and apply the correct parsing methods for the different parts, +e.g. `parse_stencil` or `parse_tuple`. While very flexible there is a tight +coupling between what is written in the file and what code is run to make data +in the file usable. While this coupling is hard to avoid it should be made +explicit. This could be done by putting a reference to a parsing function in +the operator-storage format or somehow specifying the type of each object. +This mechanism should be extensible without changing the package. Perhaps +there could be a way to register parsing functions or object types for the +toml. + ## Variable second derivative
--- a/src/SbpOperators/boundaryops/boundary_operator.jl Wed Sep 22 13:09:46 2021 +0200 +++ b/src/SbpOperators/boundaryops/boundary_operator.jl Wed Jan 12 15:54:21 2022 +0100 @@ -9,7 +9,7 @@ of `IdentityMappings` in orthogonal coordinate directions, e.g for `Dim=3`, the boundary restriction operator in the y-direction direction is `Ix⊗op⊗Iz`. """ -function boundary_operator(grid::EquidistantGrid{Dim,T}, closure_stencil::Stencil{T}, boundary::CartesianBoundary) where {Dim,T} +function boundary_operator(grid::EquidistantGrid{Dim,T}, closure_stencil, boundary::CartesianBoundary) where {Dim,T} #TODO:Check that dim(boundary) <= Dim? # Create 1D boundary operator
--- a/src/SbpOperators/boundaryops/boundary_restriction.jl Wed Sep 22 13:09:46 2021 +0200 +++ b/src/SbpOperators/boundaryops/boundary_restriction.jl Wed Jan 12 15:54:21 2022 +0100 @@ -9,7 +9,10 @@ On a one-dimensional `grid`, `e` is a `BoundaryOperator`. On a multi-dimensional `grid`, `e` is the inflation of a `BoundaryOperator`. Also see the documentation of `SbpOperators.boundary_operator(...)` for more details. """ -boundary_restriction(grid::EquidistantGrid, closure_stencil, boundary::CartesianBoundary) = SbpOperators.boundary_operator(grid, closure_stencil, boundary) +function boundary_restriction(grid::EquidistantGrid, closure_stencil, boundary::CartesianBoundary) + converted_stencil = convert(Stencil{eltype(grid)}, closure_stencil) + return SbpOperators.boundary_operator(grid, converted_stencil, boundary) +end boundary_restriction(grid::EquidistantGrid{1}, closure_stencil, region::Region) = boundary_restriction(grid, closure_stencil, CartesianBoundary{1,typeof(region)}()) export boundary_restriction
--- a/src/SbpOperators/readoperator.jl Wed Sep 22 13:09:46 2021 +0200 +++ b/src/SbpOperators/readoperator.jl Wed Jan 12 15:54:21 2022 +0100 @@ -4,7 +4,8 @@ export get_stencil_set export parse_stencil -export parse_rational +export parse_scalar +export parse_tuple export sbp_operators_path @@ -32,6 +33,7 @@ # Parsing as rationals is intentional, allows preserving exactness, which can be lowered using converts or promotions later. # TODO: readoperator.jl file name? # TODO: Remove references to toml for dict-input arguments +# TODO: Documetning the format: Allows representing rationals as strings """ read_stencil_set(fn; filters) @@ -85,6 +87,8 @@ return Stencil(weights..., center = toml["c"]) end +parse_stencil(T, toml) = Stencil{T}(parse_stencil(toml)) + function check_stencil_toml(toml) if !(toml isa Dict || toml isa Vector{String}) throw(ArgumentError("the TOML for a stencil must be a vector of strings or a table.")) @@ -107,9 +111,29 @@ end end -function parse_rational(str) - expr = Meta.parse(replace(str, "/"=>"//")) - return eval(:(Rational($expr))) + +function parse_scalar(toml) + try + return parse_rational(toml) + catch e + throw(ArgumentError("must be a number or a string representing a number.")) + end +end + +function parse_tuple(toml) + if !(toml isa Array) + throw(ArgumentError("argument must be an array")) + end + return Tuple(parse_scalar.(toml)) +end + +function parse_rational(toml) + if toml isa String + expr = Meta.parse(replace(toml, "/"=>"//")) + return eval(:(Rational($expr))) + else + return Rational(toml) + end end sbp_operators_path() = (@__DIR__) * "/operators/"
--- a/src/SbpOperators/stencil.jl Wed Sep 22 13:09:46 2021 +0200 +++ b/src/SbpOperators/stencil.jl Wed Jan 12 15:54:21 2022 +0100 @@ -22,6 +22,12 @@ return Stencil(range, weights) end +function Stencil{T}(s::Stencil) where T + return Stencil(s.range, T.(s.weights)) +end + +Base.convert(::Type{Stencil{T}}, stencil) where T = Stencil{T}(stencil) + function CenteredStencil(weights::Vararg) if iseven(length(weights)) throw(ArgumentError("a centered stencil must have an odd number of weights."))
--- a/test/Manifest.toml Wed Sep 22 13:09:46 2021 +0200 +++ b/test/Manifest.toml Wed Jan 12 15:54:21 2022 +0100 @@ -1,144 +1,264 @@ # This file is machine-generated - editing it directly is not advised -[[Artifacts]] -deps = ["Pkg"] -git-tree-sha1 = "c30985d8821e0cd73870b17b0ed0ce6dc44cb744" +julia_version = "1.7.0" +manifest_format = "2.0" + +[[deps.ArgTools]] +uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" + +[[deps.Artifacts]] uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" -version = "1.3.0" -[[Base64]] +[[deps.Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" -[[CompilerSupportLibraries_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "8e695f735fca77e9708e795eda62afdb869cbb70" +[[deps.ChainRulesCore]] +deps = ["Compat", "LinearAlgebra", "SparseArrays"] +git-tree-sha1 = "4c26b4e9e91ca528ea212927326ece5918a04b47" +uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" +version = "1.11.2" + +[[deps.ChangesOfVariables]] +deps = ["ChainRulesCore", "LinearAlgebra", "Test"] +git-tree-sha1 = "bf98fa45a0a4cee295de98d4c1462be26345b9a1" +uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0" +version = "0.1.2" + +[[deps.Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "44c37b4636bc54afac5c574d2d02b625349d6582" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "3.41.0" + +[[deps.CompilerSupportLibraries_jll]] +deps = ["Artifacts", "Libdl"] uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" -version = "0.3.4+0" -[[Dates]] +[[deps.Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" -[[DeepDiffs]] +[[deps.DeepDiffs]] git-tree-sha1 = "9824894295b62a6a4ab6adf1c7bf337b3a9ca34c" uuid = "ab62b9b5-e342-54a8-a765-a90f495de1a6" version = "1.2.0" -[[DiffRules]] -deps = ["NaNMath", "Random", "SpecialFunctions"] -git-tree-sha1 = "eb0c34204c8410888844ada5359ac8b96292cfd1" +[[deps.DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[deps.DiffRules]] +deps = ["LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"] +git-tree-sha1 = "9bc5dac3c8b6706b58ad5ce24cffd9861f07c94f" uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" -version = "1.0.1" +version = "1.9.0" -[[Distributed]] +[[deps.Distributed]] deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" -[[Glob]] +[[deps.DocStringExtensions]] +deps = ["LibGit2"] +git-tree-sha1 = "b19534d1895d702889b219c382a6e18010797f0b" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.8.6" + +[[deps.Downloads]] +deps = ["ArgTools", "LibCURL", "NetworkOptions"] +uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" + +[[deps.Glob]] git-tree-sha1 = "4df9f7e06108728ebf00a0a11edee4b29a482bb2" uuid = "c27321d9-0574-5035-807b-f59d2c89b15c" version = "1.3.0" -[[InteractiveUtils]] +[[deps.InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" -[[JLLWrappers]] -git-tree-sha1 = "7cec881362e5b4e367ff0279dd99a06526d51a55" +[[deps.InverseFunctions]] +deps = ["Test"] +git-tree-sha1 = "a7254c0acd8e62f1ac75ad24d5db43f5f19f3c65" +uuid = "3587e190-3f89-42d0-90ee-14403ec27112" +version = "0.1.2" + +[[deps.IrrationalConstants]] +git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151" +uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" +version = "0.1.1" + +[[deps.JLLWrappers]] +deps = ["Preferences"] +git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e" uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" -version = "1.1.2" +version = "1.3.0" + +[[deps.LibCURL]] +deps = ["LibCURL_jll", "MozillaCACerts_jll"] +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" -[[LibGit2]] -deps = ["Printf"] +[[deps.LibCURL_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] +uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" + +[[deps.LibGit2]] +deps = ["Base64", "NetworkOptions", "Printf", "SHA"] uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" -[[Libdl]] +[[deps.LibSSH2_jll]] +deps = ["Artifacts", "Libdl", "MbedTLS_jll"] +uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" + +[[deps.Libdl]] uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" -[[LinearAlgebra]] -deps = ["Libdl"] +[[deps.LinearAlgebra]] +deps = ["Libdl", "libblastrampoline_jll"] uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -[[Logging]] +[[deps.LogExpFunctions]] +deps = ["ChainRulesCore", "ChangesOfVariables", "DocStringExtensions", "InverseFunctions", "IrrationalConstants", "LinearAlgebra"] +git-tree-sha1 = "e5718a00af0ab9756305a0392832c8952c7426c1" +uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" +version = "0.3.6" + +[[deps.Logging]] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" -[[Markdown]] +[[deps.Markdown]] deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" -[[NaNMath]] -git-tree-sha1 = "c84c576296d0e2fbb3fc134d3e09086b3ea617cd" +[[deps.MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" + +[[deps.Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[deps.MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" + +[[deps.NaNMath]] +git-tree-sha1 = "f755f36b19a5116bb580de457cda0c140153f283" uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" -version = "0.3.4" +version = "0.3.6" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" -[[OpenSpecFun_jll]] +[[deps.OpenBLAS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] +uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" + +[[deps.OpenLibm_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "05823500-19ac-5b8b-9628-191a04bc5112" + +[[deps.OpenSpecFun_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "9db77584158d0ab52307f8c04f8e7c08ca76b5b3" +git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1" uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" -version = "0.5.3+4" +version = "0.5.5+0" -[[Pkg]] -deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +[[deps.Pkg]] +deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -[[Printf]] +[[deps.Preferences]] +deps = ["TOML"] +git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a" +uuid = "21216c6a-2e73-6563-6e65-726566657250" +version = "1.2.2" + +[[deps.Printf]] deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" -[[REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets"] +[[deps.REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" -[[Random]] -deps = ["Serialization"] +[[deps.Random]] +deps = ["SHA", "Serialization"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -[[Requires]] +[[deps.Requires]] deps = ["UUIDs"] -git-tree-sha1 = "28faf1c963ca1dc3ec87f166d92982e3c4a1f66d" +git-tree-sha1 = "8f82019e525f4d5c669692772a6f4b0a58b06a6a" uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "1.1.0" +version = "1.2.0" -[[SHA]] +[[deps.SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" -[[Serialization]] +[[deps.Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" -[[Sockets]] +[[deps.SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[deps.Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" -[[SpecialFunctions]] -deps = ["OpenSpecFun_jll"] -git-tree-sha1 = "d8d8b8a9f4119829410ecd706da4cc8594a1e020" +[[deps.SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[deps.SpecialFunctions]] +deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"] +git-tree-sha1 = "e08890d19787ec25029113e88c34ec20cac1c91e" uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "0.10.3" +version = "2.0.0" -[[TOML]] +[[deps.Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[deps.TOML]] deps = ["Dates"] -git-tree-sha1 = "d0ac7eaad0fb9f6ba023a1d743edca974ae637c4" uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -version = "1.0.0" -[[Test]] -deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +[[deps.Tar]] +deps = ["ArgTools", "SHA"] +uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" + +[[deps.Test]] +deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -[[TestSetExtensions]] +[[deps.TestSetExtensions]] deps = ["DeepDiffs", "Distributed", "Test"] git-tree-sha1 = "3a2919a78b04c29a1a57b05e1618e473162b15d0" uuid = "98d24dd4-01ad-11ea-1b02-c9a08f80db04" version = "2.0.0" -[[Tullio]] -deps = ["DiffRules", "LinearAlgebra", "Requires"] -git-tree-sha1 = "b27ec3ce782f69c1c24f373bfb6aa60300ed57c7" +[[deps.Tullio]] +deps = ["ChainRulesCore", "DiffRules", "LinearAlgebra", "Requires"] +git-tree-sha1 = "0288b7a395fc412952baf756fac94e4f28bfec65" uuid = "bc48ee85-29a4-5162-ae0b-a64e1601d4bc" -version = "0.2.8" +version = "0.3.2" -[[UUIDs]] +[[deps.UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" -[[Unicode]] +[[deps.Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" + +[[deps.libblastrampoline_jll]] +deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] +uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" + +[[deps.nghttp2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" + +[[deps.p7zip_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
--- a/test/SbpOperators/boundaryops/boundary_restriction_test.jl Wed Sep 22 13:09:46 2021 +0200 +++ b/test/SbpOperators/boundaryops/boundary_restriction_test.jl Wed Jan 12 15:54:21 2022 +0100 @@ -17,13 +17,13 @@ @testset "1D" begin e_l = boundary_restriction(g_1D,e_closure,Lower()) @test e_l == boundary_restriction(g_1D,e_closure,CartesianBoundary{1,Lower}()) - @test e_l == BoundaryOperator(g_1D,e_closure,Lower()) + @test e_l == BoundaryOperator(g_1D,Stencil{Float64}(e_closure),Lower()) @test e_l isa BoundaryOperator{T,Lower} where T @test e_l isa TensorMapping{T,0,1} where T e_r = boundary_restriction(g_1D,e_closure,Upper()) @test e_r == boundary_restriction(g_1D,e_closure,CartesianBoundary{1,Upper}()) - @test e_r == BoundaryOperator(g_1D,e_closure,Upper()) + @test e_r == BoundaryOperator(g_1D,Stencil{Float64}(e_closure),Upper()) @test e_r isa BoundaryOperator{T,Upper} where T @test e_r isa TensorMapping{T,0,1} where T end
--- a/test/SbpOperators/readoperator_test.jl Wed Sep 22 13:09:46 2021 +0200 +++ b/test/SbpOperators/readoperator_test.jl Wed Jan 12 15:54:21 2022 +0100 @@ -5,16 +5,6 @@ import Sbplib.SbpOperators.Stencil - -@testset "parse_rational" begin - @test SbpOperators.parse_rational("1") isa Rational - @test SbpOperators.parse_rational("1") == 1//1 - @test SbpOperators.parse_rational("1/2") isa Rational - @test SbpOperators.parse_rational("1/2") == 1//2 - @test SbpOperators.parse_rational("37/13") isa Rational - @test SbpOperators.parse_rational("37/13") == 37//13 -end - @testset "readoperator" begin toml_str = """ [meta] @@ -111,5 +101,72 @@ Stencil(-4//43, 59//43, -110//43, 59//43, -4//43, 0//1; center=3), Stencil(-1//49, 0//1, 59//49, -118//49, 64//49, -4//49; center=4), ] + + + @test parse_stencil(Float64, TOML.parse(toml)["s1"]) == CenteredStencil(-1/12, 4/3, -5/2, 4/3, -1/12) + @test parse_stencil(Float64, TOML.parse(toml)["s2"]) == Stencil(2/1, -5/1, 4/1, -1/1, 0/1, 0/1; center=1) + @test parse_stencil(Float64, TOML.parse(toml)["s3"]) == Stencil(1/1, -2/1, 1/1, 0/1, 0/1, 0/1; center=2) + end + + @testset "parse_scalar" begin + toml = TOML.parse(""" + a1 = 1 + a2 = 1.5 + a3 = 1.0 + a4 = 10 + a5 = "1/2" + a6 = "1.5" + + e1 = [1,2,3] + e2 = "a string value" + """) + + @test parse_scalar(toml["a1"]) == 1//1 + @test parse_scalar(toml["a2"]) == 3//2 + @test parse_scalar(toml["a3"]) == 1//1 + @test parse_scalar(toml["a4"]) == 10//1 + @test parse_scalar(toml["a5"]) == 1//2 + @test parse_scalar(toml["a6"]) == 3//2 + + @test_throws ArgumentError parse_scalar(toml["e1"]) + @test_throws ArgumentError parse_scalar(toml["e2"]) + end + + @testset "parse_tuple" begin + toml = TOML.parse(""" + t1 = [1,3,4] + t2 = ["1/2","3/4","2/1"] + + e1 = "not a tuple" + e2.a="1" + e3 = 1 + e4 = ["1/2","3/4","not a number"] + """) + + @test parse_tuple(toml["t1"]) == (1//1,3//1,4//1) + @test parse_tuple(toml["t2"]) == (1//2,3//4,2//1) + + @test_throws ArgumentError parse_tuple(toml["e1"]) + @test_throws ArgumentError parse_tuple(toml["e2"]) + @test_throws ArgumentError parse_tuple(toml["e3"]) + @test_throws ArgumentError parse_tuple(toml["e4"]) end end + +@testset "parse_rational" begin + @test SbpOperators.parse_rational("1") isa Rational + @test SbpOperators.parse_rational("1") == 1//1 + @test SbpOperators.parse_rational("1/2") isa Rational + @test SbpOperators.parse_rational("1/2") == 1//2 + @test SbpOperators.parse_rational("37/13") isa Rational + @test SbpOperators.parse_rational("37/13") == 37//13 + + @test SbpOperators.parse_rational(0.5) isa Rational + @test SbpOperators.parse_rational(0.5) == 1//2 + + @test SbpOperators.parse_rational("0.5") isa Rational + @test SbpOperators.parse_rational("0.5") == 1//2 + + @test SbpOperators.parse_rational(2) isa Rational + @test SbpOperators.parse_rational(2) == 2//1 +end
--- a/test/SbpOperators/stencil_test.jl Wed Sep 22 13:09:46 2021 +0200 +++ b/test/SbpOperators/stencil_test.jl Wed Jan 12 15:54:21 2022 +0100 @@ -15,4 +15,17 @@ @test CenteredStencil(1,2,3,4,5) == Stencil((-2, 2), (1,2,3,4,5)) @test_throws ArgumentError CenteredStencil(1,2,3,4) + + # Changing the type of the weights + @test Stencil{Float64}(Stencil(1,2,3,4,5; center=2)) == Stencil(1.,2.,3.,4.,5.; center=2) + @test Stencil{Float64}(CenteredStencil(1,2,3,4,5)) == CenteredStencil(1.,2.,3.,4.,5.) + @test Stencil{Int}(Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1,2,3,4,5; center=2) + @test Stencil{Rational}(Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1//1,2//1,3//1,4//1,5//1; center=2) + + @testset "convert" begin + @test convert(Stencil{Float64}, Stencil(1,2,3,4,5; center=2)) == Stencil(1.,2.,3.,4.,5.; center=2) + @test convert(Stencil{Float64}, CenteredStencil(1,2,3,4,5)) == CenteredStencil(1.,2.,3.,4.,5.) + @test convert(Stencil{Int}, Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1,2,3,4,5; center=2) + @test convert(Stencil{Rational}, Stencil(1.,2.,3.,4.,5.; center=2)) == Stencil(1//1,2//1,3//1,4//1,5//1; center=2) + end end
--- a/test/SbpOperators/volumeops/inner_products/inner_product_test.jl Wed Sep 22 13:09:46 2021 +0200 +++ b/test/SbpOperators/volumeops/inner_products/inner_product_test.jl Wed Jan 12 15:54:21 2022 +0100 @@ -15,8 +15,8 @@ integral(H,v) = sum(H*v) @testset "inner_product" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) @testset "0D" begin H = inner_product(EquidistantGrid{Float64}(), quadrature_interior, quadrature_closure) @test H == IdentityMapping{Float64}() @@ -38,8 +38,8 @@ @testset "Sizes" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) @testset "1D" begin H = inner_product(g_1D, quadrature_interior, quadrature_closure) @test domain_size(H) == size(g_1D) @@ -63,8 +63,8 @@ @testset "2nd order" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) H = inner_product(g_1D, quadrature_interior, quadrature_closure) for i = 1:2 @test integral(H,v[i]) ≈ v[i+1][end] - v[i+1][1] rtol = 1e-14 @@ -74,8 +74,8 @@ @testset "4th order" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) H = inner_product(g_1D, quadrature_interior, quadrature_closure) for i = 1:4 @test integral(H,v[i]) ≈ v[i+1][end] - v[i+1][1] rtol = 1e-14 @@ -90,16 +90,16 @@ u = evalOn(g_2D,(x,y)->sin(x)+cos(y)) @testset "2nd order" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) H = inner_product(g_2D, quadrature_interior, quadrature_closure) @test integral(H,v) ≈ b*Lx*Ly rtol = 1e-13 @test integral(H,u) ≈ π rtol = 1e-4 end @testset "4th order" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) H = inner_product(g_2D, quadrature_interior, quadrature_closure) @test integral(H,v) ≈ b*Lx*Ly rtol = 1e-13 @test integral(H,u) ≈ π rtol = 1e-8
--- a/test/SbpOperators/volumeops/inner_products/inverse_inner_product_test.jl Wed Sep 22 13:09:46 2021 +0200 +++ b/test/SbpOperators/volumeops/inner_products/inverse_inner_product_test.jl Wed Jan 12 15:54:21 2022 +0100 @@ -13,8 +13,8 @@ g_2D = EquidistantGrid((77,66), (0.0, 0.0), (Lx,Ly)) @testset "inverse_inner_product" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) @testset "0D" begin Hi = inverse_inner_product(EquidistantGrid{Float64}(), quadrature_interior, quadrature_closure) @test Hi == IdentityMapping{Float64}() @@ -35,8 +35,8 @@ @testset "Sizes" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) @testset "1D" begin Hi = inverse_inner_product(g_1D, quadrature_interior, quadrature_closure) @test domain_size(Hi) == size(g_1D) @@ -55,8 +55,8 @@ u = evalOn(g_1D,x->x^3-x^2+1) @testset "2nd order" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) H = inner_product(g_1D, quadrature_interior, quadrature_closure) Hi = inverse_inner_product(g_1D, quadrature_interior, quadrature_closure) @test Hi*H*v ≈ v rtol = 1e-15 @@ -64,8 +64,8 @@ end @testset "4th order" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) H = inner_product(g_1D, quadrature_interior, quadrature_closure) Hi = inverse_inner_product(g_1D, quadrature_interior, quadrature_closure) @test Hi*H*v ≈ v rtol = 1e-15 @@ -77,8 +77,8 @@ u = evalOn(g_2D,(x,y)->x*y + x^5 - sqrt(y)) @testset "2nd order" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) H = inner_product(g_2D, quadrature_interior, quadrature_closure) Hi = inverse_inner_product(g_2D, quadrature_interior, quadrature_closure) @test Hi*H*v ≈ v rtol = 1e-15 @@ -86,8 +86,8 @@ end @testset "4th order" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) - quadrature_interior = parse_rational(stencil_set["H"]["inner"]) - quadrature_closure = parse_rational.(stencil_set["H"]["closure"]) + quadrature_interior = parse_scalar(stencil_set["H"]["inner"]) + quadrature_closure = parse_tuple(stencil_set["H"]["closure"]) H = inner_product(g_2D, quadrature_interior, quadrature_closure) Hi = inverse_inner_product(g_2D, quadrature_interior, quadrature_closure) @test Hi*H*v ≈ v rtol = 1e-15