Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

Commit c87afaf

Browse files
Merge pull request #507 from SciML/upstream_duals
Make dual types concrete and strip out the rest of MOL
2 parents 6bbe541 + d051879 commit c87afaf

File tree

11 files changed

+17
-229
lines changed

11 files changed

+17
-229
lines changed

Project.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
1313
LazyBandedMatrices = "d7e5e226-e90b-4449-9968-0f923699bf6f"
1414
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1515
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
16-
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1716
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
1817
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
1918
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
@@ -23,7 +22,6 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2322
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
2423
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2524
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
26-
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
2725

2826
[compat]
2927
BandedMatrices = "0.15.11, 0.16"
@@ -34,19 +32,18 @@ ForwardDiff = "0.10"
3432
LazyArrays = "0.17, 0.18, 0.19, 0.20, 0.21, 0.22"
3533
LazyBandedMatrices = "0.5, 0.6, 0.7"
3634
LoopVectorization = "0.12"
37-
ModelingToolkit = "7, 8"
3835
NNlib = "0.6, 0.7"
3936
NonlinearSolve = "0.3.7"
4037
Requires = "1"
4138
RuntimeGeneratedFunctions = "0.4, 0.5"
4239
SciMLBase = "1.11"
4340
SparseDiffTools = "1.17"
4441
StaticArrays = "0.10, 0.11, 0.12, 1.0"
45-
SymbolicUtils = "0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18"
4642
julia = "1.6"
4743

4844
[extras]
4945
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
46+
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
5047
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
5148
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
5249
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -56,4 +53,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5653
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
5754

5855
[targets]
59-
test = ["FillArrays", "OrdinaryDiffEq", "Parameters", "Random", "SafeTestsets", "SpecialFunctions", "Test", "Zygote"]
56+
test = ["FillArrays", "LinearSolve", "OrdinaryDiffEq", "Parameters", "Random", "SafeTestsets", "SpecialFunctions", "Test", "Zygote"]

docs/src/index.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# DiffEqOperators.jl
22

33
DiffEqOperators.jl is a package for finite difference discretization of partial
4-
differential equations. It serves two purposes:
4+
differential equations. It is for building fast lazy operators for high order
5+
non-uniform finite differences.
56

6-
1. Building fast lazy operators for high order non-uniform finite differences.
7-
2. Automated finite difference discretization of symbolically-defined PDEs.
7+
!!! note
8+
9+
For automated finite difference discretization of symbolically-defined PDEs,
10+
see [MethodOfLines.jl](https://github.com/SciML/MethodOfLines.jl).
811

9-
#### Note: (2) is still a work in progress!
1012

1113
For the operators, both centered and
1214
[upwind](https://en.wikipedia.org/wiki/Upwind_scheme) operators are provided,

docs/src/symbolic/molfinitedifference.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/DiffEqOperators.jl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using SciMLBase: AbstractDiffEqLinearOperator, AbstractDiffEqCompositeOperator,
99
import SciMLBase: getops
1010
using SparseDiffTools
1111
using SparseArrays, ForwardDiff, BandedMatrices, NNlib, LazyArrays, BlockBandedMatrices, LoopVectorization
12-
using LazyBandedMatrices, ModelingToolkit
12+
using LazyBandedMatrices
1313
using RuntimeGeneratedFunctions
1414
using Requires
1515
RuntimeGeneratedFunctions.init(@__MODULE__)
@@ -56,9 +56,6 @@ include("docstrings.jl")
5656
### Concretizations
5757
include("derivative_operators/concretization.jl")
5858

59-
### MOL
60-
include("MOLFiniteDifference/MOL_discretization.jl")
61-
6259
# The (u,p,t) and (du,u,p,t) interface
6360
for T in [DiffEqScaledOperator, DiffEqOperatorCombination, DiffEqOperatorComposition, GhostDerivativeOperator]
6461
(L::T)(u,p,t) = (update_coefficients!(L,u,p,t); L * u)
@@ -82,9 +79,7 @@ export DirichletBC, Dirichlet0BC, NeumannBC, Neumann0BC, RobinBC, GeneralBC, Mul
8279
MultiDimDirectionalBC, ComposedMultiDimBC
8380
export compose, decompose, perpsize, square_norm, square_norm!, dot_product, dot_product!, cross_product,
8481
cross_product!
85-
export discretize, symbolic_discretize
8682

8783
export GhostDerivativeOperator
88-
export MOLFiniteDifference, center_align, edge_align
8984
export BoundaryConditionError
9085
end # module

src/MOLFiniteDifference/MOL_discretization.jl

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/jacvec_operators.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ mutable struct JacVecOperator{T,F,T1,T2,uType,P,tType,O} <:
4242
opnorm = true,
4343
) where {T}
4444
if autodiff
45-
cache1 = ForwardDiff.Dual{SparseDiffTools.DeivVecTag}.(u, u)
46-
cache2 = ForwardDiff.Dual{SparseDiffTools.DeivVecTag}.(u, u)
45+
cache1 = ForwardDiff.Dual{typeof(ForwardDiff.Tag(SparseDiffTools.DeivVecTag(),eltype(u))),eltype(u),1}.(u, ForwardDiff.Partials.(tuple.(u)))
46+
cache2 = ForwardDiff.Dual{typeof(ForwardDiff.Tag(SparseDiffTools.DeivVecTag(),eltype(u))),eltype(u),1}.(u, ForwardDiff.Partials.(tuple.(u)))
4747
else
4848
cache1 = similar(u)
4949
cache2 = similar(u)

src/utils.jl

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using SymbolicUtils
2-
31
"""
42
A function that creates a tuple of CartesianIndices of unit length and `N` dimensions, one pointing along each dimension.
53
"""
@@ -22,61 +20,6 @@ function cartesian_to_linear(I::CartesianIndex, s) #Not sure if there is a buil
2220
return out
2321
end
2422

25-
# Counts the Differential operators for given variable x. This is used to determine
26-
# the order of a PDE.
27-
function count_differentials(term, x::Symbolics.Symbolic)
28-
S = Symbolics
29-
SU = SymbolicUtils
30-
if !S.istree(term)
31-
return 0
32-
else
33-
op = SU.operation(term)
34-
count_children = sum(map(arg -> count_differentials(arg, x), SU.arguments(term)))
35-
if op isa Differential && op.x === x
36-
return 1 + count_children
37-
end
38-
return count_children
39-
end
40-
end
41-
42-
# return list of differential orders in the equation
43-
function differential_order(eq, x::Symbolics.Symbolic)
44-
S = Symbolics
45-
SU = SymbolicUtils
46-
orders = Set{Int}()
47-
if S.istree(eq)
48-
op = SU.operation(eq)
49-
if op isa Differential
50-
push!(orders, count_differentials(eq, x))
51-
else
52-
for o in map(ch -> differential_order(ch, x), SU.arguments(eq))
53-
union!(orders, o)
54-
end
55-
end
56-
end
57-
return filter(!iszero, orders)
58-
end
59-
60-
# find all the dependent variables given by depvar_ops in an expression
61-
function get_depvars(eq,depvar_ops)
62-
S = Symbolics
63-
SU = SymbolicUtils
64-
depvars = Set()
65-
if eq isa Num
66-
eq = eq.val
67-
end
68-
if S.istree(eq)
69-
if eq isa Term && any(u->isequal(operation(eq),u),depvar_ops)
70-
push!(depvars, eq)
71-
else
72-
for o in map(x->get_depvars(x,depvar_ops), SU.arguments(eq))
73-
union!(depvars, o)
74-
end
75-
end
76-
end
77-
depvars
78-
end
79-
8023
add_dims(A::AbstractArray, n::Int; dims::Int = 1) = cat(ndims(A) + n, A, dims = dims)
8124

8225
""

test/Misc/jacvec_integration_test.jl

Lines changed: 0 additions & 48 deletions
This file was deleted.

test/Misc/jacvec_operators.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using DiffEqBase,
2-
DiffEqOperators, ForwardDiff, LinearAlgebra, SparseDiffTools, Test
2+
DiffEqOperators, ForwardDiff, LinearAlgebra, SparseDiffTools, Test, LinearSolve
33
const A = rand(300, 300)
44
f(du, u) = mul!(du, A, u)
55
f(u) = A * u
66
x = rand(300)
77
v = rand(300)
88
du = similar(x)
99

10-
cache1 = ForwardDiff.Dual{SparseDiffTools.DeivVecTag}.(x, v)
11-
cache2 = ForwardDiff.Dual{SparseDiffTools.DeivVecTag}.(x, v)
10+
cache1 = ForwardDiff.Dual{typeof(ForwardDiff.Tag(SparseDiffTools.DeivVecTag(),eltype(x))),eltype(x),1}.(x, ForwardDiff.Partials.(tuple.(reshape(v, size(x)))))
11+
cache2 = ForwardDiff.Dual{typeof(ForwardDiff.Tag(SparseDiffTools.DeivVecTag(),eltype(x))),eltype(x),1}.(x, ForwardDiff.Partials.(tuple.(reshape(v, size(x)))))
1212
@test num_jacvec!(du, f, x, v) ForwardDiff.jacobian(f, similar(x), x) * v rtol =
1313
1e-6
1414
@test num_jacvec!(du, f, x, v, similar(v), similar(v))
@@ -81,13 +81,11 @@ ff2 = ODEFunction(
8181
jac_prototype = JacVecOperator{Float64}(lorenz, u0, autodiff = false),
8282
)
8383

84-
8584
for ff in [ff1, ff2]
8685
prob = ODEProblem(ff, u0, tspan)
8786
@test solve(prob, TRBDF2()).retcode == :Success
88-
@test solve(prob, TRBDF2(linsolve = LinSolveGMRES())).retcode == :Success
87+
@test solve(prob, TRBDF2(linsolve = KrylovJL_GMRES())).retcode == :Success
8988
@test solve(prob, Exprb32()).retcode == :Success
90-
@test_broken sol = solve(prob, Rosenbrock23())
91-
@test_broken sol =
92-
solve(prob, Rosenbrock23(linsolve = LinSolveGMRES(tol = 1e-10)))
89+
@test sol = solve(prob, Rosenbrock23()).retcode == :Success
90+
@test sol = solve(prob, Rosenbrock23(linsolve = KrylovJL_GMRES())).retcode == :Success
9391
end

test/Misc/utils.jl

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,9 @@
11
using Test, LinearAlgebra
22
using DiffEqOperators
3-
using ModelingToolkit
43

54
@testset "utility functions" begin
65
@test DiffEqOperators.unit_indices(2) == (CartesianIndex(1,0), CartesianIndex(0,1))
76
@test DiffEqOperators.add_dims(zeros(2,2), ndims(zeros(2,2)) + 2) == [6. 6.; 0. 0.; 0. 0.]
87
@test DiffEqOperators.perpindex(collect(1:5), 3) == [1, 2, 4, 5]
98
@test DiffEqOperators.perpsize(zeros(2,2,3,2), 3) == (2, 2, 2)
109
end
11-
12-
@testset "count differentials 1D" begin
13-
@parameters t x
14-
@variables u(..)
15-
Dt = Differential(t)
16-
17-
Dx = Differential(x)
18-
eq = Dt(u(t,x)) ~ -Dx(u(t,x))
19-
@test first(DiffEqOperators.differential_order(eq.rhs, x.val)) == 1
20-
@test isempty(DiffEqOperators.differential_order(eq.rhs, t.val))
21-
@test first(DiffEqOperators.differential_order(eq.lhs, t.val)) == 1
22-
@test isempty(DiffEqOperators.differential_order(eq.lhs, x.val))
23-
24-
Dxx = Differential(x)^2
25-
eq = Dt(u(t,x)) ~ Dxx(u(t,x))
26-
@test first(DiffEqOperators.differential_order(eq.rhs, x.val)) == 2
27-
@test isempty(DiffEqOperators.differential_order(eq.rhs, t.val))
28-
@test first(DiffEqOperators.differential_order(eq.lhs, t.val)) == 1
29-
@test isempty(DiffEqOperators.differential_order(eq.lhs, x.val))
30-
31-
Dxxxx = Differential(x)^4
32-
eq = Dt(u(t,x)) ~ -Dxxxx(u(t,x))
33-
@test first(DiffEqOperators.differential_order(eq.rhs, x.val)) == 4
34-
@test isempty(DiffEqOperators.differential_order(eq.rhs, t.val))
35-
@test first(DiffEqOperators.differential_order(eq.lhs, t.val)) == 1
36-
@test isempty(DiffEqOperators.differential_order(eq.lhs, x.val))
37-
end
38-
39-
@testset "count differentials 2D" begin
40-
@parameters t x y
41-
@variables u(..)
42-
Dxx = Differential(x)^2
43-
Dyy = Differential(y)^2
44-
Dt = Differential(t)
45-
46-
eq = Dt(u(t,x,y)) ~ Dxx(u(t,x,y)) + Dyy(u(t,x,y))
47-
@test first(DiffEqOperators.differential_order(eq.rhs, x.val)) == 2
48-
@test first(DiffEqOperators.differential_order(eq.rhs, y.val)) == 2
49-
@test isempty(DiffEqOperators.differential_order(eq.rhs, t.val))
50-
@test first(DiffEqOperators.differential_order(eq.lhs, t.val)) == 1
51-
@test isempty(DiffEqOperators.differential_order(eq.lhs, x.val))
52-
@test isempty(DiffEqOperators.differential_order(eq.lhs, y.val))
53-
end
54-
55-
@testset "count with mixed terms" begin
56-
@parameters t x y
57-
@variables u(..)
58-
Dxx = Differential(x)^2
59-
Dyy = Differential(y)^2
60-
Dx = Differential(x)
61-
Dy = Differential(y)
62-
Dt = Differential(t)
63-
64-
eq = Dt(u(t,x,y)) ~ Dxx(u(t,x,y)) + Dyy(u(t,x,y)) + Dx(Dy(u(t,x,y)))
65-
@test DiffEqOperators.differential_order(eq.rhs, x.val) == Set([2, 1])
66-
@test DiffEqOperators.differential_order(eq.rhs, y.val) == Set([2, 1])
67-
end
68-
69-
@testset "Kuramoto–Sivashinsky equation" begin
70-
@parameters x, t
71-
@variables u(..)
72-
Dt = Differential(t)
73-
Dx = Differential(x)
74-
Dx2 = Differential(x)^2
75-
Dx3 = Differential(x)^3
76-
Dx4 = Differential(x)^4
77-
78-
α = 1
79-
β = 4
80-
γ = 1
81-
eq = Dt(u(x,t)) + u(x,t)*Dx(u(x,t)) + α*Dx2(u(x,t)) + β*Dx3(u(x,t)) + γ*Dx4(u(x,t)) ~ 0
82-
@test DiffEqOperators.differential_order(eq.lhs, x.val) == Set([4, 3, 2, 1])
83-
end

0 commit comments

Comments
 (0)