Skip to content
This repository was archived by the owner on Jul 19, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
fe48925
First go at Higher dim BCs, up to 3D.
xtalax Jun 17, 2019
3e334e9
some fixes
xtalax Jun 17, 2019
5d50e06
3rd order robin and General test
xtalax Jun 17, 2019
c218693
More type tree diversification and array like operations for Boundary…
xtalax Jun 17, 2019
c25e2c5
More type tree diversification and array like operations for Boundary…
xtalax Jun 17, 2019
c5c5b8c
GeneralBC fixes
xtalax Jun 17, 2019
ace5ef3
vim
xtalax Jul 4, 2019
44effda
vim
xtalax Jul 4, 2019
a97edd1
Merge branch 'BC-Dev' into dev-bc
xtalax Jul 4, 2019
575434f
added getindex and fixed type information
xtalax Jul 6, 2019
53df121
added getindex and fixed type information
xtalax Jul 6, 2019
f54fa23
fixed above
xtalax Jul 6, 2019
7a06bb9
a hash sign
xtalax Jul 6, 2019
b0d5c84
Added tests, got them passing, changed interface of AffineBC and subt…
xtalax Jul 7, 2019
c9e3432
tests passing
xtalax Jul 7, 2019
e26ecc7
Added tests up to 3D, fixed MixedBC
xtalax Jul 7, 2019
44d2a8a
Added Extension for MultiDimensionalPeriodicBC
xtalax Jul 7, 2019
14377d5
addressed the function subtypes directly in InteractiveUtils, added s…
xtalax Jul 8, 2019
fe12102
Split the BCs up so that they only act along one dimension
xtalax Jul 8, 2019
ba468fd
tests passing
xtalax Jul 8, 2019
4d7e610
more constructors
xtalax Jul 8, 2019
46c6300
BridgeBC, a 1 ended BC that must be composed in a MixedArray to be valid
xtalax Jul 8, 2019
12fb57f
Dirichlet0 and Neumann0 constructors, simplified interface for BridgeBC
xtalax Jul 8, 2019
3141e1b
end
xtalax Jul 8, 2019
0c7524e
fixes
xtalax Jul 8, 2019
e1fbd40
Comments and exports
xtalax Jul 8, 2019
8c12114
Re added the combined Q as ComposedBoundaryPaddedArray
xtalax Jul 8, 2019
559ae9e
Re added the combined Q as ComposedBoundaryPaddedArray
xtalax Jul 8, 2019
08ba0b1
.
xtalax Jul 8, 2019
8d33fa6
Changed Test for generic operator validation - FiniteDifference no lo…
xtalax Jul 9, 2019
c0aa111
''
xtalax Jul 9, 2019
ef940fa
Added tests for ComposedPaddedArrays and ComposedBCs, some fixes
xtalax Jul 11, 2019
5f492cc
fixed some strange broadcast outputs
xtalax Jul 11, 2019
091ffdd
removed an @show that was spamming the repl
xtalax Jul 13, 2019
786b0ff
Added Concretizations for everything, Changed BridgeBC so that they a…
xtalax Jul 15, 2019
c147c3f
Made the concretization of the PeriodicBC consistent
xtalax Jul 15, 2019
0689ff5
marked broken jacvec test
xtalax Jul 15, 2019
b353c5f
Robin was working after all, error in hand calculations
xtalax Jul 15, 2019
42013b6
Allowed non uniform grid for robin/general, updated MultiDimBC constr…
xtalax Jul 16, 2019
92ccfe2
Added BandedMatrix Concretizations for all BC operators
xtalax Jul 16, 2019
b6adfa2
Merge pull request #10 from JuliaDiffEq/master
xtalax Jul 16, 2019
8702746
Merge pull request #11 from xtalax/master
xtalax Jul 16, 2019
4668ff5
trying to do something about this jacvec test
xtalax Jul 16, 2019
5942688
commented out problem jacvec tests
xtalax Jul 16, 2019
d3206e8
Yingbo Ma's fix for the jacvec tests - now uncommented
xtalax Jul 17, 2019
d9d26d0
Merge branch 'master' into SplitBC-dev
xtalax Jul 17, 2019
8020e9e
Change robin/general interface for uniform grid, depreciate old synta…
xtalax Jul 17, 2019
9e30f82
Merge branch 'SplitBC-dev' of https://github.com/xtalax/DiffEqOperato…
xtalax Jul 17, 2019
76a47db
moved boundary padded arrays to their own file, put concretizations i…
xtalax Jul 20, 2019
e30575a
added tests for BridgeBC
xtalax Aug 1, 2019
2606a28
Merge pull request #12 from JuliaDiffEq/master
xtalax Aug 1, 2019
fa54e80
Merge pull request #13 from xtalax/master
xtalax Aug 1, 2019
47af0e1
Get tests passing for BridgeBC, fix some issues
xtalax Aug 1, 2019
2a3885f
split out multi dimensional BCs in to their own file for readability
xtalax Aug 1, 2019
14cdde9
add include
xtalax Aug 1, 2019
c7ad2f7
moved perpsize
xtalax Aug 1, 2019
bc05268
slicemul now fully N dimensional - BC operators work up to any N
xtalax Aug 2, 2019
ecb8393
reduce size of needlessly large arrays in the BoundaryPaddedArray test
xtalax Aug 2, 2019
45ebabf
spruced up the extra bridge BC constructors to work to N dimensions
xtalax Aug 2, 2019
cf1ae68
some fixes
xtalax Aug 2, 2019
07c4210
Pulled out BridgeBC in to its own branch, since it was causing proble…
xtalax Aug 2, 2019
055bec1
also removed MixedBC to other branch
xtalax Aug 2, 2019
af86556
exports
xtalax Aug 2, 2019
da3514e
cleaned up an unused function
xtalax Aug 2, 2019
7b0b7fd
readded tests for ComposedBoundaryPaddedArray, added CartesianIndex g…
xtalax Aug 2, 2019
8a2dce3
Got tests passing
xtalax Aug 4, 2019
e415be3
Merge branch 'bridge-bc' into SplitBC-dev
xtalax Aug 4, 2019
f0251a2
overwrite erroneous merge
xtalax Aug 4, 2019
fdaca9e
"
xtalax Aug 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/DiffEqOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ include("basic_operators.jl")
include("matrixfree_operators.jl")
include("jacvec_operators.jl")

### Boundary Padded Arrays
include("boundary_padded_arrays.jl")

### Boundary Operators
include("derivative_operators/BC_operators.jl")
include("derivative_operators/multi_dim_bc_operators.jl")

### Derivative Operators
include("derivative_operators/fornberg.jl")
Expand All @@ -47,6 +51,9 @@ export MatrixFreeOperator
export DiffEqScalar, DiffEqArrayOperator, DiffEqIdentity, JacVecOperator, getops
export AbstractDerivativeOperator, DerivativeOperator,
CenteredDifference, UpwindDifference
export RobinBC, GeneralBC
export DirichletBC, Dirichlet0BC, NeumannBC, Neumann0BC, RobinBC, GeneralBC, MultiDimBC, PeriodicBC,
MultiDimDirectionalBC, ComposedMultiDimBC,
compose, decompose, perpsize

export GhostDerivativeOperator
end # module
157 changes: 157 additions & 0 deletions src/boundary_padded_arrays.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Boundary Padded Arrays
abstract type AbstractBoundaryPaddedArray{T, N} <: AbstractArray{T, N} end

"""
A vector type that extends a vector u with ghost points at either end
"""
struct BoundaryPaddedVector{T,T2 <: AbstractVector{T}} <: AbstractBoundaryPaddedArray{T, 1}
l::T
r::T
u::T2
end
Base.length(Q::BoundaryPaddedVector) = length(Q.u) + 2
Base.size(Q::BoundaryPaddedVector) = (length(Q.u) + 2,)
Base.lastindex(Q::BoundaryPaddedVector) = Base.length(Q)

function Base.getindex(Q::BoundaryPaddedVector,i)
if i == 1
return Q.l
elseif i == length(Q)
return Q.r
else
return Q.u[i-1]
end
end

"""
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

"""
struct BoundaryPaddedArray{T, D, N, M, V<:AbstractArray{T, N}, B<: AbstractArray{T, M}} <: AbstractBoundaryPaddedArray{T,N}
lower::B #an array of dimension M = N-1, used to extend the lower index boundary
upper::B #Ditto for the upper index boundary
u::V
end

getaxis(Q::BoundaryPaddedArray{T,D,N,M,V,B}) where {T,D,N,M,V,B} = D

function Base.size(Q::BoundaryPaddedArray)
S = [size(Q.u)...]
S[getaxis(Q)] += 2
return Tuple(S)
end

"""
A = compose(padded_arrays::BoundaryPaddedArray...)

-------------------------------------------------------------------------------------

Example:
A = compose(Ax, Ay, Az) # 3D domain
A = compose(Ax, Ay) # 2D Domain

Composes BoundaryPaddedArrays that extend the same u for each different dimension that u has in to a ComposedBoundaryPaddedArray

Ax Ay and Az can be passed in any order, as long as there is exactly one BoundaryPaddedArray that extends each dimension.
"""
function compose(padded_arrays::BoundaryPaddedArray...)
N = ndims(padded_arrays[1])
Ds = getaxis.(padded_arrays)
(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)."))
for D in Ds
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"))
end
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!"))
padded_arrays = padded_arrays[sortperm([Ds...])]
lower = [padded_array.lower for padded_array in padded_arrays]
upper = [padded_array.upper for padded_array in padded_arrays]

ComposedBoundaryPaddedArray{gettype(padded_arrays[1]),N,N-1,typeof(padded_arrays[1].u),typeof(lower[1])}(lower, upper, padded_arrays[1].u)
end

# Composed BoundaryPaddedArray

struct ComposedBoundaryPaddedArray{T, N, M, V<:AbstractArray{T, N}, B<: AbstractArray{T, M}} <: AbstractBoundaryPaddedArray{T, N}
lower::Vector{B}
upper::Vector{B}
u::V
end

# Aliases
AbstractBoundaryPaddedMatrix{T} = AbstractBoundaryPaddedArray{T,2}
AbstractBoundaryPadded3Tensor{T} = AbstractBoundaryPaddedArray{T,3}

BoundaryPaddedMatrix{T, D, V, B} = BoundaryPaddedArray{T, D, 2, 1, V, B}
BoundaryPadded3Tensor{T, D, V, B} = BoundaryPaddedArray{T, D, 3, 2, V, B}

ComposedBoundaryPaddedMatrix{T,V,B} = ComposedBoundaryPaddedArray{T,2,1,V,B}
ComposedBoundaryPadded3Tensor{T,V,B} = ComposedBoundaryPaddedArray{T,3,2,V,B}

Base.size(Q::ComposedBoundaryPaddedArray) = size(Q.u).+2

"""
Ax, Ay,... = decompose(A::ComposedBoundaryPaddedArray)

-------------------------------------------------------------------------------------

Decomposes a ComposedBoundaryPaddedArray in to components that extend along each dimension individually
"""
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)])


Base.length(Q::AbstractBoundaryPaddedArray) = reduce((*), size(Q))
Base.firstindex(Q::AbstractBoundaryPaddedArray, d::Int) = 1
Base.lastindex(Q::AbstractBoundaryPaddedArray) = length(Q)
Base.lastindex(Q::AbstractBoundaryPaddedArray, d::Int) = size(Q)[d]
gettype(Q::AbstractBoundaryPaddedArray{T,N}) where {T,N} = T
Base.ndims(Q::AbstractBoundaryPaddedArray{T,N}) where {T,N} = N

add_dim(A::AbstractArray, i) = reshape(A, size(A)...,i)
add_dim(i) = i

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!
inds = [_inds...]
S = size(Q)
dim = D
otherinds = inds[setdiff(1:N, dim)]
@assert length(S) == N
if inds[dim] == 1
return Q.lower[otherinds...]
elseif inds[dim] == S[dim]
return Q.upper[otherinds...]
elseif typeof(inds[dim]) <: Integer
inds[dim] = inds[dim] - 1
return Q.u[inds...]
elseif typeof(inds[dim]) == Colon
if mapreduce(x -> typeof(x) != Colon, (|), otherinds)
return vcat(Q.lower[otherinds...], Q.u[inds...], Q.upper[otherinds...])
else
throw("A colon on the extended dim is as yet incompatible with additional colons")
end
elseif typeof(inds[dim]) <: AbstractArray
throw("Range indexing not yet supported!")
end
end

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
S = size(Q)
@assert reduce((&), inds .<= S)
for (dim, index) in enumerate(inds)
if index == 1
_inds = inds[setdiff(1:N, dim)]
if (1 ∈ _inds) | reduce((|), S[setdiff(1:N, dim)] .== _inds)
return zero(T)
else
return Q.lower[dim][(_inds.-1)...]
end
elseif index == S[dim]
_inds = inds[setdiff(1:N, dim)]
if (1 ∈ _inds) | reduce((|), S[setdiff(1:N, dim)] .== _inds)
return zero(T)
else
return Q.upper[dim][(_inds.-1)...]
end
end
end
return Q.u[(inds.-1)...]
end
Loading