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

Commit be10288

Browse files
authored
Merge pull request #16 from JuliaDiffEq/master
rebase
2 parents 2606a28 + 803938c commit be10288

19 files changed

+867
-387
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.jl.*.cov
33
*.jl.mem
44
deps/deps.jl
5+
Manifest.toml

Project.toml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
name = "DiffEqOperators"
2-
uuid = "9fdde737-9c7f-55bf-ade8-46b3f136cc48"
3-
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
4-
version = "v3.5.0"
5-
6-
[deps]
7-
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
8-
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
9-
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
10-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
11-
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
12-
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
13-
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
14-
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
15-
16-
17-
[compat]
18-
julia = "1"
19-
DiffEqBase = ">= 1.19.0"
1+
name = "DiffEqOperators"
2+
uuid = "9fdde737-9c7f-55bf-ade8-46b3f136cc48"
3+
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>"]
4+
version = "4.0.0"
5+
6+
[deps]
7+
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
8+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
9+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
10+
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
11+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
12+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
13+
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
14+
15+
[compat]
16+
DiffEqBase = ">= 5.19.0"
17+
julia = "1"
18+
19+
[extras]
20+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
21+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
22+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
23+
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
24+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
25+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
26+
27+
[targets]
28+
test = ["FillArrays", "ForwardDiff", "OrdinaryDiffEq", "SafeTestsets", "SpecialFunctions", "Test"]

src/DiffEqOperators.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@ abstract type AbstractDerivativeOperator{T} <: AbstractDiffEqLinearOperator{T} e
1010
abstract type AbstractDiffEqCompositeOperator{T} <: AbstractDiffEqLinearOperator{T} end
1111
abstract type AbstractMatrixFreeOperator{T} <: AbstractDiffEqLinearOperator{T} end
1212

13-
### Common default methods for the operators
14-
include("common_defaults.jl")
15-
16-
### Basic Operators
17-
include("basic_operators.jl")
18-
1913
### Matrix-free Operators
2014
include("matrixfree_operators.jl")
2115
include("jacvec_operators.jl")
2216

17+
### Boundary Padded Arrays
18+
include("boundary_padded_arrays.jl")
19+
2320
### Boundary Operators
2421
include("derivative_operators/BC_operators.jl")
22+
include("derivative_operators/multi_dim_bc_operators.jl")
2523

2624
### Derivative Operators
2725
include("derivative_operators/fornberg.jl")
@@ -37,16 +35,18 @@ include("derivative_operators/derivative_operator_functions.jl")
3735
include("composite_operators.jl")
3836

3937
# The (u,p,t) and (du,u,p,t) interface
40-
for T in [DiffEqScalar, DiffEqArrayOperator, FactorizedDiffEqArrayOperator, DiffEqIdentity,
41-
DiffEqScaledOperator, DiffEqOperatorCombination, DiffEqOperatorComposition]
38+
for T in [DiffEqScaledOperator, DiffEqOperatorCombination, DiffEqOperatorComposition]
4239
(L::T)(u,p,t) = (update_coefficients!(L,u,p,t); L * u)
4340
(L::T)(du,u,p,t) = (update_coefficients!(L,u,p,t); mul!(du,L,u))
4441
end
4542

4643
export MatrixFreeOperator
47-
export DiffEqScalar, DiffEqArrayOperator, DiffEqIdentity, JacVecOperator, getops
44+
export JacVecOperator, getops
4845
export AbstractDerivativeOperator, DerivativeOperator,
4946
CenteredDifference, UpwindDifference
50-
export RobinBC, GeneralBC
47+
export DirichletBC, Dirichlet0BC, NeumannBC, Neumann0BC, RobinBC, GeneralBC, MultiDimBC, PeriodicBC,
48+
MultiDimDirectionalBC, ComposedMultiDimBC,
49+
compose, decompose, perpsize
50+
5151
export GhostDerivativeOperator
5252
end # module

src/basic_operators.jl

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

src/boundary_padded_arrays.jl

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Boundary Padded Arrays
2+
abstract type AbstractBoundaryPaddedArray{T, N} <: AbstractArray{T, N} end
3+
4+
"""
5+
A vector type that extends a vector u with ghost points at either end
6+
"""
7+
struct BoundaryPaddedVector{T,T2 <: AbstractVector{T}} <: AbstractBoundaryPaddedArray{T, 1}
8+
l::T
9+
r::T
10+
u::T2
11+
end
12+
Base.length(Q::BoundaryPaddedVector) = length(Q.u) + 2
13+
Base.size(Q::BoundaryPaddedVector) = (length(Q.u) + 2,)
14+
Base.lastindex(Q::BoundaryPaddedVector) = Base.length(Q)
15+
16+
function Base.getindex(Q::BoundaryPaddedVector,i)
17+
if i == 1
18+
return Q.l
19+
elseif i == length(Q)
20+
return Q.r
21+
else
22+
return Q.u[i-1]
23+
end
24+
end
25+
26+
"""
27+
Higher dimensional generalization of BoundaryPaddedVector, pads an array of dimension N along the dimension D with 2 Arrays of dimension N-1, stored in lower and upper
28+
29+
"""
30+
struct BoundaryPaddedArray{T, D, N, M, V<:AbstractArray{T, N}, B<: AbstractArray{T, M}} <: AbstractBoundaryPaddedArray{T,N}
31+
lower::B #an array of dimension M = N-1, used to extend the lower index boundary
32+
upper::B #Ditto for the upper index boundary
33+
u::V
34+
end
35+
36+
getaxis(Q::BoundaryPaddedArray{T,D,N,M,V,B}) where {T,D,N,M,V,B} = D
37+
38+
function Base.size(Q::BoundaryPaddedArray)
39+
S = [size(Q.u)...]
40+
S[getaxis(Q)] += 2
41+
return Tuple(S)
42+
end
43+
44+
"""
45+
A = compose(padded_arrays::BoundaryPaddedArray...)
46+
47+
-------------------------------------------------------------------------------------
48+
49+
Example:
50+
A = compose(Ax, Ay, Az) # 3D domain
51+
A = compose(Ax, Ay) # 2D Domain
52+
53+
Composes BoundaryPaddedArrays that extend the same u for each different dimension that u has in to a ComposedBoundaryPaddedArray
54+
55+
Ax Ay and Az can be passed in any order, as long as there is exactly one BoundaryPaddedArray that extends each dimension.
56+
"""
57+
function compose(padded_arrays::BoundaryPaddedArray...)
58+
N = ndims(padded_arrays[1])
59+
Ds = getaxis.(padded_arrays)
60+
(length(padded_arrays) == N) || throw(ArgumentError("The padded_arrays must cover every dimension - make sure that the number of padded_arrays is equal to ndims(u)."))
61+
for D in Ds
62+
length(setdiff(Ds, D)) == (N-1) || throw(ArgumentError("There are multiple Arrays that extend along dimension $D - make sure every dimension has a unique extension"))
63+
end
64+
reduce((|), fill(padded_arrays[1].u, (length(padded_arrays),)) .== getfield.(padded_arrays, :u)) || throw(ArgumentError("The padded_arrays do not all extend the same u!"))
65+
padded_arrays = padded_arrays[sortperm([Ds...])]
66+
lower = [padded_array.lower for padded_array in padded_arrays]
67+
upper = [padded_array.upper for padded_array in padded_arrays]
68+
69+
ComposedBoundaryPaddedArray{gettype(padded_arrays[1]),N,N-1,typeof(padded_arrays[1].u),typeof(lower[1])}(lower, upper, padded_arrays[1].u)
70+
end
71+
72+
# Composed BoundaryPaddedArray
73+
74+
struct ComposedBoundaryPaddedArray{T, N, M, V<:AbstractArray{T, N}, B<: AbstractArray{T, M}} <: AbstractBoundaryPaddedArray{T, N}
75+
lower::Vector{B}
76+
upper::Vector{B}
77+
u::V
78+
end
79+
80+
# Aliases
81+
AbstractBoundaryPaddedMatrix{T} = AbstractBoundaryPaddedArray{T,2}
82+
AbstractBoundaryPadded3Tensor{T} = AbstractBoundaryPaddedArray{T,3}
83+
84+
BoundaryPaddedMatrix{T, D, V, B} = BoundaryPaddedArray{T, D, 2, 1, V, B}
85+
BoundaryPadded3Tensor{T, D, V, B} = BoundaryPaddedArray{T, D, 3, 2, V, B}
86+
87+
ComposedBoundaryPaddedMatrix{T,V,B} = ComposedBoundaryPaddedArray{T,2,1,V,B}
88+
ComposedBoundaryPadded3Tensor{T,V,B} = ComposedBoundaryPaddedArray{T,3,2,V,B}
89+
90+
Base.size(Q::ComposedBoundaryPaddedArray) = size(Q.u).+2
91+
92+
"""
93+
Ax, Ay,... = decompose(A::ComposedBoundaryPaddedArray)
94+
95+
-------------------------------------------------------------------------------------
96+
97+
Decomposes a ComposedBoundaryPaddedArray in to components that extend along each dimension individually
98+
"""
99+
decompose(A::ComposedBoundaryPaddedArray) = Tuple([BoundaryPaddedArray{gettype(A), ndims(A), ndims(A)-1, typeof(lower[1])}(A.lower[i], A.upper[i], A.u) for i in 1:ndims(A)])
100+
101+
102+
Base.length(Q::AbstractBoundaryPaddedArray) = reduce((*), size(Q))
103+
Base.firstindex(Q::AbstractBoundaryPaddedArray, d::Int) = 1
104+
Base.lastindex(Q::AbstractBoundaryPaddedArray) = length(Q)
105+
Base.lastindex(Q::AbstractBoundaryPaddedArray, d::Int) = size(Q)[d]
106+
gettype(Q::AbstractBoundaryPaddedArray{T,N}) where {T,N} = T
107+
Base.ndims(Q::AbstractBoundaryPaddedArray{T,N}) where {T,N} = N
108+
109+
add_dim(A::AbstractArray, i) = reshape(A, size(A)...,i)
110+
add_dim(i) = i
111+
112+
function Base.getindex(Q::BoundaryPaddedArray{T,D,N,M,V,B}, _inds::Vararg{Int,N}) where {T,D,N,M,V,B} #supports range and colon indexing!
113+
inds = [_inds...]
114+
S = size(Q)
115+
dim = D
116+
otherinds = inds[setdiff(1:N, dim)]
117+
@assert length(S) == N
118+
if inds[dim] == 1
119+
return Q.lower[otherinds...]
120+
elseif inds[dim] == S[dim]
121+
return Q.upper[otherinds...]
122+
elseif typeof(inds[dim]) <: Integer
123+
inds[dim] = inds[dim] - 1
124+
return Q.u[inds...]
125+
elseif typeof(inds[dim]) == Colon
126+
if mapreduce(x -> typeof(x) != Colon, (|), otherinds)
127+
return vcat(Q.lower[otherinds...], Q.u[inds...], Q.upper[otherinds...])
128+
else
129+
throw("A colon on the extended dim is as yet incompatible with additional colons")
130+
end
131+
elseif typeof(inds[dim]) <: AbstractArray
132+
throw("Range indexing not yet supported!")
133+
end
134+
end
135+
136+
function Base.getindex(Q::ComposedBoundaryPaddedArray{T, N, M, V, B} , inds::Vararg{Int, N}) where {T, N, M, V, B} #as yet no support for range indexing or colon indexing
137+
S = size(Q)
138+
@assert reduce((&), inds .<= S)
139+
for (dim, index) in enumerate(inds)
140+
if index == 1
141+
_inds = inds[setdiff(1:N, dim)]
142+
if (1 _inds) | reduce((|), S[setdiff(1:N, dim)] .== _inds)
143+
return zero(T)
144+
else
145+
return Q.lower[dim][(_inds.-1)...]
146+
end
147+
elseif index == S[dim]
148+
_inds = inds[setdiff(1:N, dim)]
149+
if (1 _inds) | reduce((|), S[setdiff(1:N, dim)] .== _inds)
150+
return zero(T)
151+
else
152+
return Q.upper[dim][(_inds.-1)...]
153+
end
154+
end
155+
end
156+
return Q.u[(inds.-1)...]
157+
end

src/common_defaults.jl

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

0 commit comments

Comments
 (0)