From bfc53b289268e4195ba2272aabc486b4a021b216 Mon Sep 17 00:00:00 2001 From: xtalax Date: Thu, 9 Feb 2023 14:00:38 +0000 Subject: [PATCH 01/10] upgrade Symbolics and SymbolicUtils --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index d32e1742a..7ae88b948 100644 --- a/Project.toml +++ b/Project.toml @@ -31,8 +31,8 @@ OrdinaryDiffEq = "6" SafeTestsets = "0.0.1" SciMLBase = "1.57" StaticArrays = "1" -SymbolicUtils = "0.19, 1" -Symbolics = "4, 5" +SymbolicUtils = "1" +Symbolics = "5" TermInterface = "0.2, 0.3" julia = "1.6" From 8a53f66941581441afc243e8dedaae765135dff9 Mon Sep 17 00:00:00 2001 From: xtalax Date: Thu, 9 Feb 2023 14:01:01 +0000 Subject: [PATCH 02/10] upgrade mtk --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 7ae88b948..db8818b1b 100644 --- a/Project.toml +++ b/Project.toml @@ -26,7 +26,7 @@ DomainSets = "0.5, 0.6" IfElse = "0.1" Interpolations = "0.14" Latexify = "0.15" -ModelingToolkit = "8.22" +ModelingToolkit = "8" OrdinaryDiffEq = "6" SafeTestsets = "0.0.1" SciMLBase = "1.57" From 8ac6c5a7088572274c7969d5fff28ee7b63d039e Mon Sep 17 00:00:00 2001 From: xtalax Date: Thu, 9 Feb 2023 14:02:09 +0000 Subject: [PATCH 03/10] revert --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index db8818b1b..b06bc0871 100644 --- a/Project.toml +++ b/Project.toml @@ -32,7 +32,7 @@ SafeTestsets = "0.0.1" SciMLBase = "1.57" StaticArrays = "1" SymbolicUtils = "1" -Symbolics = "5" +Symbolics = "4, 5" TermInterface = "0.2, 0.3" julia = "1.6" From a7f547b82d84820618f7c91f5766c87b4eead2a3 Mon Sep 17 00:00:00 2001 From: xtalax Date: Thu, 9 Feb 2023 14:41:58 +0000 Subject: [PATCH 04/10] update bounds --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index b06bc0871..db8818b1b 100644 --- a/Project.toml +++ b/Project.toml @@ -32,7 +32,7 @@ SafeTestsets = "0.0.1" SciMLBase = "1.57" StaticArrays = "1" SymbolicUtils = "1" -Symbolics = "4, 5" +Symbolics = "5" TermInterface = "0.2, 0.3" julia = "1.6" From e44fb379f2ee0d2d1b6c0ef652df2ebd226a1597 Mon Sep 17 00:00:00 2001 From: xtalax Date: Thu, 9 Feb 2023 15:07:08 +0000 Subject: [PATCH 05/10] fix errors --- src/MOL_symbolic_utils.jl | 12 ++++-------- src/discretization/discretize_vars.jl | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/MOL_symbolic_utils.jl b/src/MOL_symbolic_utils.jl index 4695cddaa..74b2913f1 100644 --- a/src/MOL_symbolic_utils.jl +++ b/src/MOL_symbolic_utils.jl @@ -90,17 +90,13 @@ subs_alleqs!(eqs, rules) = map!(eq -> substitute(eq.lhs, rules) ~ substitute(eq. find all the dependent variables given by depvar_ops in an expression """ function get_depvars(eq, depvar_ops) - S = Symbolics - SU = SymbolicUtils depvars = Set() - if eq isa Num - eq = eq.val - end - if S.istree(eq) - if eq isa Term && any(u -> isequal(operation(eq), u), depvar_ops) + eq = safe_unwrap(eq) + if istree(eq) + if any(u -> isequal(operation(eq), u), depvar_ops) push!(depvars, eq) else - for o in map(x -> get_depvars(x, depvar_ops), SU.arguments(eq)) + for o in map(x -> get_depvars(x, depvar_ops), arguments(eq)) union!(depvars, o) end end diff --git a/src/discretization/discretize_vars.jl b/src/discretization/discretize_vars.jl index 9e57a6b19..6f75312d3 100644 --- a/src/discretization/discretize_vars.jl +++ b/src/discretization/discretize_vars.jl @@ -129,7 +129,7 @@ function DiscreteSpace(vars, discretization::MOLFiniteDifference{G}) where {G} depvarsdisc = map(depvars) do u op = SymbolicUtils.operation(u) - if op isa SymbolicUtils.Term{SymbolicUtils.FnType{Tuple,Real},Nothing} + if op isa SymbolicUtils.BasicSymbolic{SymbolicUtils.FnType{Tuple, Real}} sym = Symbol(string(op)) else sym = nameof(op) From fc931d5808eddd58aed1a0e910d70f479946a061 Mon Sep 17 00:00:00 2001 From: xtalax Date: Fri, 10 Feb 2023 15:26:47 +0000 Subject: [PATCH 06/10] fix test --- test/components/interiormap_test.jl | 25 ++++--------------- test/runtests.jl | 38 ++++++++++++++--------------- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/test/components/interiormap_test.jl b/test/components/interiormap_test.jl index c6aa11673..65c4808a5 100644 --- a/test/components/interiormap_test.jl +++ b/test/components/interiormap_test.jl @@ -37,12 +37,8 @@ const bigint = div(typemax(Int), 2) s = MethodOfLines.DiscreteSpace(v, disc) m = MethodOfLines.buildmatrix(pde, s) - if VERSION >= v"1.7" - @test m == [2+bigint 0 1; 0 2+bigint 1; 1 1 2+bigint] # Test the matrix is the identity matrix - else - @test m == [1 2+bigint 0; 1 0 2+bigint; 2+bigint 1 1] - end + @test m == [1 2+bigint 0; 1 0 2+bigint; 2+bigint 1 1] end @testset "Test 00a: recognize relevant variable for equations, time undefined, multiple choices" begin @@ -77,11 +73,8 @@ end s = MethodOfLines.DiscreteSpace(v, disc) m = MethodOfLines.buildmatrix(pde, s) - if VERSION >= v"1.7" - @test m == [2 0 2; 0 3 3; 4 4 4] # Test the matrix is the identity matrix - else - @test m == [2 2 0; 3 0 3; 4 4 4] - end + + @test m == [2 2 0; 3 0 3; 4 4 4] end # @testset "Test 00b: recognize relevant variable for equations, time undefined, mixed derivatives, multiple choices" begin @@ -116,12 +109,8 @@ end s = MethodOfLines.DiscreteSpace(v, disc) m = MethodOfLines.buildmatrix(pde, s) - if VERSION >= v"1.7" - @test m == [2 0 1; 0 3 3; 5 5 4] # Test the matrix is the identity matrix - else - @test m == [1 2 0; 3 0 3; 4 5 5] - end + @test m == [1 2 0; 3 0 3; 4 5 5] end @testset "Test 00c: recognize relevant variable for equations, time undefined, ranking important" begin @@ -156,12 +145,8 @@ end s = MethodOfLines.DiscreteSpace(v, disc) m = MethodOfLines.buildmatrix(pde, s) - if VERSION >= v"1.7" - @test m == [2 2 0; 1 0 1; 0 1 2] - else - @test m == [0 2 2; 1 1 0; 2 0 1] - end + @test m == [0 2 2; 1 1 0; 2 0 1] end @testset "Test 01a: Build variable mapping - one right choice simple" begin diff --git a/test/runtests.jl b/test/runtests.jl index 1b7597110..05d2aa01b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,6 +7,25 @@ const is_TRAVIS = haskey(ENV, "TRAVIS") # Start Test Script @time begin + if GROUP == "All" || GROUP == "Components" + @time @safetestset "MOLFiniteDifference Utils" begin + include("utils_test.jl") + end + @time @safetestset "Discretization of space and grid types" begin + include("components/DiscreteSpace.jl") + end + @time @safetestset "Variable PDE mapping and interior construction" begin + include("components/interiormap_test.jl") + end + @time @safetestset "Fornberg" begin + include("components/MOLfornberg_weights.jl") + end + @time @safetestset "ODEFunction" begin + include("components/ODEFunction_test.jl") + end + #@time @safetestset "Finite Difference Schemes" begin include("components/finite_diff_schemes.jl") end + end + if GROUP == "All" || GROUP == "Integrals" @time @safetestset "MOLFiniteDifference Interface: Integrals" begin include("pde_systems/MOL_1D_Integration.jl") @@ -31,25 +50,6 @@ const is_TRAVIS = haskey(ENV, "TRAVIS") end end - if GROUP == "All" || GROUP == "Components" - #@time @safetestset "Test for regression against original code" begin include("regression_test.jl") end - @time @safetestset "MOLFiniteDifference Utils" begin - include("utils_test.jl") - end - @time @safetestset "Discretization of space and grid types" begin - include("components/DiscreteSpace.jl") - end - @time @safetestset "Variable PDE mapping and interior construction" begin - include("components/interiormap_test.jl") - end - @time @safetestset "Fornberg" begin - include("components/MOLfornberg_weights.jl") - end - @time @safetestset "ODEFunction" begin - include("components/ODEFunction_test.jl") - end - #@time @safetestset "Finite Difference Schemes" begin include("components/finite_diff_schemes.jl") end - end if GROUP == "All" || GROUP == "Nonlinear_Diffusion" @time @safetestset "MOLFiniteDifference Interface: 1D Non-Linear Diffusion" begin From 7b2a77ce163e956776faf65379cd4c17d547863f Mon Sep 17 00:00:00 2001 From: xtalax Date: Fri, 10 Feb 2023 15:44:39 +0000 Subject: [PATCH 07/10] fix test 1.6 --- test/components/interiormap_test.jl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/test/components/interiormap_test.jl b/test/components/interiormap_test.jl index 65c4808a5..5b9241d46 100644 --- a/test/components/interiormap_test.jl +++ b/test/components/interiormap_test.jl @@ -37,8 +37,12 @@ const bigint = div(typemax(Int), 2) s = MethodOfLines.DiscreteSpace(v, disc) m = MethodOfLines.buildmatrix(pde, s) + if VERSION >= v"1.7" + @test m == [1 2+bigint 0; 1 0 2+bigint; 2+bigint 1 1] + else + @test m == [0 2+bigint 1; 2+bigint 0 1; 2+bigint 1 1] # Test the matrix is the identity matrix + end - @test m == [1 2+bigint 0; 1 0 2+bigint; 2+bigint 1 1] end @testset "Test 00a: recognize relevant variable for equations, time undefined, multiple choices" begin @@ -73,8 +77,11 @@ end s = MethodOfLines.DiscreteSpace(v, disc) m = MethodOfLines.buildmatrix(pde, s) - - @test m == [2 2 0; 3 0 3; 4 4 4] + if VERSION >= v"1.7" + @test m == [2 2 0; 3 0 3; 4 4 4] + else + @test m == [0 2 2; 3 0 3; 4 4 4] + end end # @testset "Test 00b: recognize relevant variable for equations, time undefined, mixed derivatives, multiple choices" begin @@ -109,8 +116,12 @@ end s = MethodOfLines.DiscreteSpace(v, disc) m = MethodOfLines.buildmatrix(pde, s) + if VERSION >= v"1.7" + @test m == [2 0 1; 0 3 3; 5 5 4] # Test the matrix is the identity matrix + else + @test m == [0 2 1; 3 0 3; 5 5 4] + end - @test m == [1 2 0; 3 0 3; 4 5 5] end @testset "Test 00c: recognize relevant variable for equations, time undefined, ranking important" begin @@ -145,8 +156,12 @@ end s = MethodOfLines.DiscreteSpace(v, disc) m = MethodOfLines.buildmatrix(pde, s) + if VERSION >= v"1.7" + @test m == [0 2 2; 1 1 0; 2 0 1] + else + @test m == [2 2 0; 0 1 1; 1 0 2] + end - @test m == [0 2 2; 1 1 0; 2 0 1] end @testset "Test 01a: Build variable mapping - one right choice simple" begin From f8e89e176c40449a824d892227d23b572161796b Mon Sep 17 00:00:00 2001 From: xtalax Date: Fri, 10 Feb 2023 15:48:50 +0000 Subject: [PATCH 08/10] more fixes --- .../schemes/nonlinear_laplacian/nonlinear_laplacian.jl | 6 +++--- test/components/interiormap_test.jl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/discretization/schemes/nonlinear_laplacian/nonlinear_laplacian.jl b/src/discretization/schemes/nonlinear_laplacian/nonlinear_laplacian.jl index 32fc91a60..d97ca7886 100644 --- a/src/discretization/schemes/nonlinear_laplacian/nonlinear_laplacian.jl +++ b/src/discretization/schemes/nonlinear_laplacian/nonlinear_laplacian.jl @@ -72,13 +72,13 @@ function cartesian_nonlinear_laplacian(expr, II, derivweights, s::DiscreteSpace, end @inline function generate_nonlinlap_rules(II::CartesianIndex, s::DiscreteSpace, depvars, derivweights::DifferentialDiscretizer, bcmap, indexmap, terms) - rules = reduce(safe_vcat, [vec([@rule *(~~c, $(Differential(x))(*(~~a, $(Differential(x))(u), ~~b)), ~~d) => *(~c..., cartesian_nonlinear_laplacian(*(a..., b...), Idx(II, s, u, indexmap), derivweights, s, filter_interfaces(bcmap[operation(u)][x]), depvars, x, u), ~d...) for x in params(u, s)]) for u in depvars], init = []) + rules = reduce(safe_vcat, [vec([@rule *(~~c, $(Differential(x))(*(~~a, $(Differential(x))(u), ~~b)), ~~d) => *(~c..., cartesian_nonlinear_laplacian(*(~a..., ~b...), Idx(II, s, u, indexmap), derivweights, s, filter_interfaces(bcmap[operation(u)][x]), depvars, x, u), ~d...) for x in params(u, s)]) for u in depvars], init = []) - rules = safe_vcat(rules, reduce(safe_vcat, [vec([@rule $(Differential(x))(*(~~a, $(Differential(x))(u), ~~b)) => cartesian_nonlinear_laplacian(*(a..., b...), Idx(II, s, u, indexmap), derivweights, s, filter_interfaces(bcmap[operation(u)][x]), depvars, x, u) for x in params(u, s)]) for u in depvars], init = [])) + rules = safe_vcat(rules, reduce(safe_vcat, [vec([@rule $(Differential(x))(*(~~a, $(Differential(x))(u), ~~b)) => cartesian_nonlinear_laplacian(*(~a..., ~b...), Idx(II, s, u, indexmap), derivweights, s, filter_interfaces(bcmap[operation(u)][x]), depvars, x, u) for x in params(u, s)]) for u in depvars], init = [])) rules = safe_vcat(rules, reduce(safe_vcat, [vec([@rule ($(Differential(x))($(Differential(x))(u) / ~a)) => cartesian_nonlinear_laplacian(1 / ~a, Idx(II, s, u, indexmap), derivweights, s, filter_interfaces(bcmap[operation(u)][x]), depvars, x, u) for x in params(u, s)]) for u in depvars], init = [])) - rules = safe_vcat(rules, reduce(safe_vcat, [vec([@rule *(~~b, ($(Differential(x))($(Differential(x))(u) / ~a)), ~~c) => *(b..., c..., cartesian_nonlinear_laplacian(1 / ~a, Idx(II, s, u, indexmap), derivweights, s, filter_interfaces(bcmap[operation(u)][x]), depvars, x, u)) for x in params(u, s)]) for u in depvars], init = [])) + rules = safe_vcat(rules, reduce(safe_vcat, [vec([@rule *(~~b, ($(Differential(x))($(Differential(x))(u) / ~a)), ~~c) => *(~b..., ~c..., cartesian_nonlinear_laplacian(1 / ~a, Idx(II, s, u, indexmap), derivweights, s, filter_interfaces(bcmap[operation(u)][x]), depvars, x, u)) for x in params(u, s)]) for u in depvars], init = [])) nonlinlap_rules = [] for t in terms diff --git a/test/components/interiormap_test.jl b/test/components/interiormap_test.jl index 5b9241d46..87d1e0584 100644 --- a/test/components/interiormap_test.jl +++ b/test/components/interiormap_test.jl @@ -117,7 +117,7 @@ end m = MethodOfLines.buildmatrix(pde, s) if VERSION >= v"1.7" - @test m == [2 0 1; 0 3 3; 5 5 4] # Test the matrix is the identity matrix + @test m == [1 2 0; 3 0 3; 4 5 5] else @test m == [0 2 1; 3 0 3; 5 5 4] end From c5070c2b1843a4d43e01c7dda05907cc2658d2eb Mon Sep 17 00:00:00 2001 From: xtalax Date: Fri, 10 Feb 2023 16:07:34 +0000 Subject: [PATCH 09/10] typo --- test/components/interiormap_test.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/components/interiormap_test.jl b/test/components/interiormap_test.jl index 87d1e0584..57a9a84c3 100644 --- a/test/components/interiormap_test.jl +++ b/test/components/interiormap_test.jl @@ -40,7 +40,7 @@ const bigint = div(typemax(Int), 2) if VERSION >= v"1.7" @test m == [1 2+bigint 0; 1 0 2+bigint; 2+bigint 1 1] else - @test m == [0 2+bigint 1; 2+bigint 0 1; 2+bigint 1 1] # Test the matrix is the identity matrix + @test m == [0 2+bigint 1; 2+bigint 0 1; 1 1 2+bigint] # Test the matrix is the identity matrix end end From cda1380ee2f2bec39e04f23c3d30a02fdd2aab55 Mon Sep 17 00:00:00 2001 From: xtalax Date: Fri, 10 Feb 2023 16:37:08 +0000 Subject: [PATCH 10/10] fix docs --- docs/src/tutorials/PIDE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/tutorials/PIDE.md b/docs/src/tutorials/PIDE.md index a553fe1bd..d7ff40226 100644 --- a/docs/src/tutorials/PIDE.md +++ b/docs/src/tutorials/PIDE.md @@ -56,6 +56,8 @@ To have an integral over the whole domain, be sure to wrap the integral in an au Due to a limitation, the whole domain integral needs to have the same arguments as the integrand, but is constant in x. To use it in an equation one dimension lower, use a boundary value like integral(t, 0.0) ```@example integrals2 +using MethodOfLines, ModelingToolkit, DomainSets + @parameters t, x @variables integrand(..) integral(..) Dt = Differential(t)