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

Commit 07c4210

Browse files
committed
Pulled out BridgeBC in to its own branch, since it was causing problems and is not strictly nessecary
1 parent 45ebabf commit 07c4210

File tree

5 files changed

+7
-261
lines changed

5 files changed

+7
-261
lines changed

src/DiffEqOperators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export MatrixFreeOperator
5151
export DiffEqScalar, DiffEqArrayOperator, DiffEqIdentity, JacVecOperator, getops
5252
export AbstractDerivativeOperator, DerivativeOperator,
5353
CenteredDifference, UpwindDifference
54-
export DirichletBC, Dirichlet0BC, NeumannBC, Neumann0BC, RobinBC, GeneralBC, MixedBC, MultiDimBC, PeriodicBC, BridgeBC,
54+
export DirichletBC, Dirichlet0BC, NeumannBC, Neumann0BC, RobinBC, GeneralBC, MixedBC, MultiDimBC, PeriodicBC,
5555
MultiDimDirectionalBC, ComposedMultiDimBC,
5656
compose, decompose, perpsize
5757

src/derivative_operators/BC_operators.jl

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ struct GeneralBC{T} <:AffineBC{T}
153153
end
154154
end
155155

156-
157-
158156
"""
159157
Quick and dirty way to allow mixed boundary types on each end of an array - may be cleaner and more versatile to split up left and right boundaries going forward
160158
MixedBC(lowerBC, upperBC) is the interface.
@@ -170,12 +168,6 @@ struct MixedBC{T, R, S} <: AtomicBC{T}
170168
end
171169
end
172170

173-
function Base.:*(Q::MixedBC, u::AbstractVector)
174-
lower = Q.lower*u
175-
upper = Q.upper*u
176-
return BoundaryPaddedVector(lower.l, upper.r, u)
177-
end
178-
179171
#implement Neumann and Dirichlet as special cases of RobinBC
180172
NeumannBC::AbstractVector{T}, dx::Union{AbstractVector{T}, T}, order = 1) where T = RobinBC([zero(T), one(T), α[1]], [zero(T), one(T), α[2]], dx, order)
181173
DirichletBC(αl::T, αr::T) where T = RobinBC([one(T), zero(T), αl], [one(T), zero(T), αr], 1.0, 2.0 )
@@ -186,92 +178,7 @@ Neumann0BC(dx::Union{AbstractVector{T}, T}, order = 1) where T = NeumannBC([zero
186178
# other acceptable argument signatures
187179
#RobinBC(al::T, bl::T, cl::T, dx_l::T, ar::T, br::T, cr::T, dx_r::T, order = 1) where T = RobinBC([al,bl, cl], [ar, br, cr], dx_l, order)
188180

189-
"""
190-
BridgeBC(u_low::AbstractArray{T,N}, u_up::AbstractArray{T,N}, indslow, indsup) # A different view in to 2 diffferent arrays on each end of the boundary, indslow is an iterable of indicies that index u_low, which extends the lower index end. Analogous for u_up and indsup with the upper boundary.
191-
192-
BridgeBC(u::AbstractArray{T,N}, inds) # The same view in to some array u at the index inds extends the boundary
193-
194-
-------------------------------------------------------------------------------------
195-
196-
Allows seperate domains governed by seperate equations to be bridged together with a boundary condition.
197-
"""
198-
struct BridgeBC{T,N,I} <: AffineBC{T}
199-
a_l::Vector{T} #Dummy vectors so that AffineBC methods still work
200-
b_l::SubArray{T,0,Array{T,N},NTuple{N,I},true}
201-
a_r::Vector{T}
202-
b_r::SubArray{T,0,Array{T,N},NTuple{N,I},true}
203-
end
204-
205-
BridgeBC(u::AbstractArray, inds) = BridgeBC(u, inds, u, inds)
206-
207-
function BridgeBC(u_low::AbstractArray{T,N}, indslow, u_up::AbstractArray{T,N}, indsup) where {T, N}
208-
@assert length(indslow) == N
209-
@assert length(indsup) == N
210-
@assert mapreduce(x -> typeof(x) <: Integer, (&), indslow)
211-
@assert mapreduce(x -> typeof(x) <: Integer, (&), indsup)
212-
213-
BridgeBC{T, length(indslow), eltype(indslow)}(zeros(T,1), view(u_low, indslow...), zeros(T,1), view(u_up, indsup...))
214-
end
215-
216-
"""
217-
Q1, Q2 = BridgeBC(bc1::AtomicBC, u1::AbstractArray{T,1}, hilo1::String, hilo2::String, u2::AbstractArray{T,1}, bc2::AtomicBC)
218-
-------------------------------------------------------------------------------------
219-
Creates two BC operators that join array `u1` to `u2` at the `hilo1` end ("high" or "low" index end), and joins `u2` to `u1` with simalar settings given in `hilo2`.
220-
The ends of `u1` and `u2` that are not connected will use the boundary conditions `bc1` and `bc2` respectively.
221-
222-
Use `Q1` to extend `u1` and `Q2` to extend `u2`.
223-
224-
When using these with a time/space stepping solve, please use elementwise equals on your u1 and u2 to avoid the need to create new BC operators each time, as follows:
225-
u_t1 .= L*Q*u_t0
226-
-----------------------------------------------------------------------------------
227-
Connecting two multi dimensional Arrays:
228-
Q1, Q2 = BridgeBC(bc1::MultiDimDirectionalBC, u1::AbstractArray{T,N}, dim1::Int, hilo1::String, dim2::Int, hilo2::String, u2::AbstractArray{T,N}, bc2::MultiDimDirectionalBC)
229-
-----------------------------------------------------------------------------------
230-
231-
Creates two BC operators that join array `u1` to `u2` at the `hilo1` end ("high" or "low" index end) of dimension `dim1`, and joins `u2` to `u1` with simalar settings given in `hilo2` and `dim2`.
232-
The ends of `u1` and `u2` that are not connected will use the boundary conditions `bc1` and `bc2` respectively.
233-
234-
Drop `dim1` and `dim2` when your `u1` and `u2` are vectors.
235-
236-
Use `Q1` to extend `u1` and `Q2` to extend `u2`.
237-
238-
When using these with a time/space stepping solve, please use elementwise equals on your u1 and u2 to avoid the need to create new BC operators each time, as follows:
239-
u_t1 .= L*Q*u_t0
240-
"""
241-
function BridgeBCBridgeBC(bc1::AtomicBC, u1::AbstractArray{T,1}, hilo1::String, hilo2::String, u2::AbstractArray{T,1}, bc2::AtomicBC) where T
242-
if hilo1 == "low"
243-
view1 = view(u1, 1)
244-
if hilo2 == "low"
245-
view2 = view(u2, 1)
246-
BC1 = MixedBC(BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view2, zeros(T, 1), view2), bc1)
247-
BC2 = MixedBC(BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view1, zeros(T, 1), view1), bc2)
248-
elseif hilo2 == "high"
249-
view2 = view(u2, length(u2))
250-
BC1 = MixedBC(BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view2, zeros(T, 1), view2), bc1)
251-
BC2 = MixedBC(bc2, BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view1, zeros(T, 1), view1))
252-
else
253-
throw("hilo2 not recognized, please use \"high\" to connect u1 to u2 along the upper index of dim2 of u2 or \"low\" to connect along the lower index end")
254-
end
255-
elseif hilo1 == "high"
256-
view1 = view(u1, length(u1))
257-
if hilo2 == "low"
258-
view2 = view(u2, 1)
259-
BC1 = MixedBC(bc1, BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view2, zeros(T, 1), view2))
260-
BC2 = MixedBC(BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view1, zeros(T, 1), view1), bc2)
261-
elseif hilo2 == "high"
262-
view2 = view(u2, length(u2))
263-
BC1 = MixedBC(bc1, BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view2, zeros(T, 1), view2))
264-
BC2 = MixedBC(bc2, BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view1, zeros(T, 1), view1))
265-
else
266-
throw("hilo2 not recognized, please use \"high\" to connect u1 to u2 along the upper index of dim2 of u2 or \"low\" to connect along the lower index end")
267-
end
268-
else
269-
throw("hilo1 not recognized, please use \"high\" to connect u1 to u2 along the upper index of dim1 of u1 or \"low\" to connect along the lower index end")
270-
end
271-
return (BC1, BC2)
272-
end
273-
274-
Base.:*(Q::BridgeBC{T,I,N}, u::AbstractVector{T}) where {T, I, N} = BoundaryPaddedVector{T, typeof(u)}(Q.b_l[1], Q.b_r[1], u)
181+
Base.:*(Q::MixedBC, u::AbstractVector) = BoundaryPaddedVector((Q.lower*u).l, (Q.upper*u).r, u)
275182
Base.:*(Q::AffineBC, u::AbstractVector) = BoundaryPaddedVector(Q.a_l u[1:length(Q.a_l)] + Q.b_l, Q.a_r u[(end-length(Q.a_r)+1):end] + Q.b_r, u)
276183
Base.:*(Q::PeriodicBC, u::AbstractVector) = BoundaryPaddedVector(u[end], u[1], u)
277184

src/derivative_operators/multi_dim_bc_operators.jl

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ end
1414
function slice_rmul(A::AbstractDiffEqLinearOperator, u::AbstractArray{T,N}, dim::Int) where {T,N}
1515
@assert N != 1
1616
u_temp = similar(u)
17-
pre = axes(u)[1:dim-1]
18-
post = axes(u)[dim+1:end]
19-
_slice_rmul!(u_temp, A, u, dim, pre, post)
17+
_slice_rmul!(u_temp, A, u, dim, axes(u)[1:dim-1], axes(u)[dim+1:end])
2018
return u_temp
2119
end
2220

23-
@noinline function _slice_rmul!(lower::Array{T, M}, upper::Array{T, M}, A::AbstractArray{B,M}, u::AbstractArray{T,N}, dim::Int, pre, post) where {T,B,N,M}
21+
@noinline function _slice_rmul!(lower::AbstractArray, upper::AbstractArray, A::AbstractArray{B,M}, u::AbstractArray{T,N}, dim::Int, pre, post) where {T,B,N,M}
2422
for J in CartesianIndices(post)
2523
for I in CartesianIndices(pre)
2624
tmp = A[I,J]*u[I, :, J]
@@ -32,11 +30,10 @@ end
3230

3331
function slice_rmul(A::AbstractArray{B,M}, u::AbstractArray{T,N}, dim::Int) where {T, B, N,M}
3432
@assert N != 1
33+
@assert M == N-1
3534
lower = zeros(T,perpsize(u,dim))
3635
upper = zeros(T,perpsize(u,dim))
37-
pre = axes(u)[1:dim-1]
38-
post = axes(u)[dim+1:end]
39-
_slice_rmul!(lower, upper, A, u, dim, pre, post)
36+
_slice_rmul!(lower, upper, A, u, dim, axes(u)[1:dim-1], axes(u)[dim+1:end])
4037
return (lower, upper)
4138
end
4239

@@ -100,73 +97,6 @@ GeneralBC(αl::AbstractVector{T}, αr::AbstractVector{T}, dxyz, order, s) where
10097

10198
perpsize(A::AbstractArray{T,N}, dim::Integer) where {T,N} = size(A)[setdiff(1:N, dim)] #the size of A perpendicular to dim
10299

103-
# Constructors for Bridge BC to make it easier to join domains together. See docs on BrigeBC in BC_operators.jl for info on usage
104-
function BridgeBC(bc1::MultiDimDirectionalBC, u1::AbstractArray{T,N}, dim1::Int, hilo1::String, dim2::Int, hilo2::String, u2::AbstractArray{T,N}, bc2::MultiDimDirectionalBC) where {T, N}
105-
@assert 1 dim1 N "dim1 must be 1≤dim1≤N, got dim1 = $dim1"
106-
@assert 1 dim1 N "dim2 must be 1≤dim1≤N, got dim1 = $dim1"
107-
s1 = perpsize(u1, dim1) #
108-
s2 = perpsize(u2, dim2)
109-
@assert s1 == s2 "Arrays must be same size along boundary to be joined, got boundary sizes u1 = $s1, u2 = $s2"
110-
if hilo1 == "low"
111-
view1 = selectdim(u1, dim1, 1)
112-
if hilo2 == "low"
113-
BC1 = Array{MixedBC{T, BridgeBC{T, N, eltype(s1)}, getboundarytype(bc1)}}(undef, s1...)
114-
BC2 = Array{MixedBC{T, BridgeBC{T, N, eltype(s2)}, getboundarytype(bc2)}}(undef, s2...)
115-
view2 = selectdim(u2, dim2, 1)
116-
R = CartesianIndices(BC1)
117-
for I in R
118-
BC1[I] = MixedBC(BridgeBC{T, N, eltype(s1)}(zeros(T, 1), view(view2, I), zeros(T, 1), view(view2, I)), bc1.BCs[I])
119-
BC2[I] = MixedBC(BridgeBC{T, N, eltype(s1)}(zeros(T, 1), view(view1, I), zeros(T, 1), view(view1, I)), bc2.BCs[I])
120-
end
121-
elseif hilo2 == "high"
122-
BC1 = Array{MixedBC{T, BridgeBC{T, N, eltype(s1)}, getboundarytype(bc1)}}(undef, s1...)
123-
BC2 = Array{MixedBC{T, getboundarytype(bc2), BridgeBC{T, N, eltype(s2)}}}(undef, s2...)
124-
view2 = selectdim(u2, dim2, size(u2)[dim2])
125-
R = CartesianIndices(BC1)
126-
for I in R
127-
BC1[I] = MixedBC(BridgeBC{T, N, eltype(s1)}(zeros(T, 1), view(view2, I), zeros(T, 1), view(view2, I)), bc1.BCs[I])
128-
BC2[I] = MixedBC(bc2.BCs[I], BridgeBC{T, N, eltype(s1)}(zeros(T, 1), view(view1, I), zeros(T, 1), view(view1, I)))
129-
end
130-
else
131-
throw(ArgumentError("hilo2 not recognized, please use \"high\" to connect u1 to u2 along the upper index of dim2 of u2 or \"low\" to connect along the lower index end"))
132-
end
133-
elseif hilo1 == "high"
134-
view1 = selectdim(u1, dim1, size(u1)[dim1])
135-
if hilo2 == "low"
136-
BC1 = Array{MixedBC{T, getboundarytype(bc1), BridgeBC{T, N, eltype(s1)}}}(undef, s1...)
137-
BC2 = Array{MixedBC{T, BridgeBC{T, N, eltype(s2)}, getboundarytype(bc2)}}(undef, s2...)
138-
view2 = selectdim(u2, dim2, 1)
139-
R = CartesianIndices(BC1)
140-
for I in R
141-
BC1[I] = MixedBC(bc1.BCs[I], BridgeBC{T, N, eltype(s1)}(zeros(T, 1), view(view2, I), zeros(T, 1), view(view2, I)))
142-
BC2[I] = MixedBC(BridgeBC{T, N, eltype(s1)}(zeros(T, 1), view(view1, I), zeros(T, 1), view(view1, I)), bc2.BCs[I])
143-
end
144-
elseif hilo2 == "high"
145-
BC1 = Array{MixedBC{T, getboundarytype(bc1), BridgeBC{T, N, eltype(s1)}}}(undef, s1...)
146-
BC2 = Array{MixedBC{T, getboundarytype(bc2), BridgeBC{T, N, eltype(s2)}}}(undef, s2...)
147-
view2 = selectdim(u2, dim2, size(u2)[dim2])
148-
R = CartesianIndices(BC1)
149-
for I in R
150-
BC1[I] = MixedBC(bc1.BCs[I], BridgeBC{T, N, eltype(s1)}(zeros(T, 1), view(view2, I), zeros(T, 1), view(view2, I)))
151-
BC2[I] = MixedBC(bc2.BCs[I], BridgeBC{T, N, eltype(s1)}(zeros(T, 1), view(view1, I), zeros(T, 1), view(view1, I)))
152-
end
153-
else
154-
throw(ArgumentError("hilo2 not recognized, please use \"high\" to connect u1 to u2 along the upper index of dim2 of u2 or \"low\" to connect along the lower index end"))
155-
end
156-
else
157-
throw("hilo1 not recognized, please use \"high\" to connect u1 to u2 along the upper index of dim1 of u1 or \"low\" to connect along the lower index end")
158-
end
159-
return (MultiDimBC(BC1, dim1), MultiDimBC(BC2, dim2))
160-
end
161-
162-
"""
163-
Q1, Q2 = BridgeBC(bc1::MultiDimDirectionalBC, u1::AbstractArray, dim1::Int, dim2::Int, u2::AbstractArray, bc2::MultiDimDirectionalBC)
164-
Create BC operators that connect `u1` to `u2`, at the high index end of `dim1` for `u1`, and the low index end of `dim2` for `u2`.
165-
`bc1` and `bc2` are then the boundary conditions at the unconnected ends of `u1` and `u2` respectively.
166-
"""
167-
BridgeBC(bc1::MultiDimDirectionalBC, u1::AbstractArray, dim1::Int, dim2::Int, u2::AbstractArray, bc2::MultiDimDirectionalBC) = BridgeBC(u1, dim1, "high", bc1, u2, dim2, "low", bc2)
168-
169-
170100
"""
171101
Q = compose(BCs...)
172102

test/bridge_bc.jl

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

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Base: isapprox
33

44
@time @safetestset "Basic Operators Interface" begin include("basic_operators_interface.jl") end
55
@time @safetestset "Robin Boundary Condition Operators" begin include("robin.jl") end
6-
@time @safetestset "Validate BridgeBC and its constructors" begin include("bridge_bc.jl") end
6+
#@time @safetestset "Validate BridgeBC and its constructors" begin include("bridge_bc.jl") end
77
@time @safetestset "JacVec Operators Interface" begin include("jacvec_operators.jl") end
88
@time @safetestset "Composite Operators Interface" begin include("composite_operators_interface.jl") end
99
@time @safetestset "BC and Coefficient Compositions" begin include("bc_coeff_compositions.jl") end

0 commit comments

Comments
 (0)