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

Commit a46d128

Browse files
committed
pulled upstream changes
2 parents 2c4700f + c034ccf commit a46d128

24 files changed

+1811
-436
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.1.0"
5+
6+
[deps]
7+
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
8+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
9+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
10+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
11+
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
12+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
13+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
14+
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
15+
16+
[compat]
17+
DiffEqBase = ">= 5.19.0"
18+
julia = "1"
19+
20+
[extras]
21+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
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", "OrdinaryDiffEq", "SafeTestsets", "SpecialFunctions", "Test"]

src/DiffEqOperators.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ 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+
### Utilities
18+
include("utils.jl")
19+
20+
### Boundary Padded Arrays
21+
include("boundary_padded_arrays.jl")
22+
2323
### Boundary Operators
2424
include("derivative_operators/BC_operators.jl")
25+
include("derivative_operators/multi_dim_bc_operators.jl")
2526

2627
### Derivative Operators
2728
include("derivative_operators/fornberg.jl")
@@ -37,16 +38,18 @@ include("derivative_operators/derivative_operator_functions.jl")
3738
include("composite_operators.jl")
3839

3940
# The (u,p,t) and (du,u,p,t) interface
40-
for T in [DiffEqScalar, DiffEqArrayOperator, FactorizedDiffEqArrayOperator, DiffEqIdentity,
41-
DiffEqScaledOperator, DiffEqOperatorCombination, DiffEqOperatorComposition]
41+
for T in [DiffEqScaledOperator, DiffEqOperatorCombination, DiffEqOperatorComposition]
4242
(L::T)(u,p,t) = (update_coefficients!(L,u,p,t); L * u)
4343
(L::T)(du,u,p,t) = (update_coefficients!(L,u,p,t); mul!(du,L,u))
4444
end
4545

4646
export MatrixFreeOperator
47-
export DiffEqScalar, DiffEqArrayOperator, DiffEqIdentity, JacVecOperator, getops
47+
export JacVecOperator, getops
4848
export AbstractDerivativeOperator, DerivativeOperator,
4949
CenteredDifference, UpwindDifference
50-
export RobinBC, GeneralBC
50+
export DirichletBC, Dirichlet0BC, NeumannBC, Neumann0BC, RobinBC, GeneralBC, MultiDimBC, PeriodicBC,
51+
MultiDimDirectionalBC, ComposedMultiDimBC,
52+
compose, decompose, perpsize
53+
5154
export GhostDerivativeOperator
5255
end # module

src/basic_operators.jl

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

src/boundary_padded_arrays.jl

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

src/common_defaults.jl

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

0 commit comments

Comments
 (0)