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

Commit e415be3

Browse files
authored
Merge branch 'bridge-bc' into SplitBC-dev
2 parents 8a2dce3 + cf1ae68 commit e415be3

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

src/derivative_operators/BC_operators.jl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,94 @@ Neumann0BC(dx::Union{AbstractVector{T}, T}, order = 1) where T = NeumannBC([zero
165165
# other acceptable argument signatures
166166
#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)
167167

168+
169+
"""
170+
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.
171+
172+
BridgeBC(u::AbstractArray{T,N}, inds) # The same view in to some array u at the index inds extends the boundary
173+
174+
-------------------------------------------------------------------------------------
175+
176+
Allows seperate domains governed by seperate equations to be bridged together with a boundary condition.
177+
"""
178+
struct BridgeBC{T,N,I, L} <: AffineBC{T}
179+
a_l::Vector{T} #Dummy vectors so that AffineBC methods still work
180+
b_l::SubArray{T,0,Array{T,N},NTuple{N,I},L}
181+
a_r::Vector{T}
182+
b_r::SubArray{T,0,Array{T,N},NTuple{N,I},L}
183+
function BridgeBC{T,N,L}(a_l, b_l::Subarray{T,0,Array{T,N},NTuple{N,I}, L}, a_r, b_l::Subarray{T,0,Array{T,N},NTuple{N,I}, L}) where {T, N, L, I} = new{T,N,L,I}(a_l,b_l,a_r,b_r)
184+
end
185+
186+
BridgeBC(u::AbstractArray, inds) = BridgeBC(u, inds, u, inds)
187+
188+
function BridgeBC(u_low::AbstractArray{T,N}, indslow, u_up::AbstractArray{T,N}, indsup) where {T, N}
189+
@assert length(indslow) == N
190+
@assert length(indsup) == N
191+
@assert mapreduce(x -> typeof(x) <: Integer, (&), indslow)
192+
@assert mapreduce(x -> typeof(x) <: Integer, (&), indsup)
193+
BridgeBC{T, length(indslow), eltype(indslow)}(zeros(T,1), view(u_low, indslow...), zeros(T,1), view(u_up, indsup...))
194+
end
195+
196+
"""
197+
Q1, Q2 = BridgeBC(bc1::AtomicBC, u1::AbstractArray{T,1}, hilo1::String, hilo2::String, u2::AbstractArray{T,1}, bc2::AtomicBC)
198+
-------------------------------------------------------------------------------------
199+
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`.
200+
The ends of `u1` and `u2` that are not connected will use the boundary conditions `bc1` and `bc2` respectively.
201+
202+
Use `Q1` to extend `u1` and `Q2` to extend `u2`.
203+
204+
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:
205+
u_t1 .= L*Q*u_t0
206+
-----------------------------------------------------------------------------------
207+
Connecting two multi dimensional Arrays:
208+
Q1, Q2 = BridgeBC(bc1::MultiDimDirectionalBC, u1::AbstractArray{T,N}, dim1::Int, hilo1::String, dim2::Int, hilo2::String, u2::AbstractArray{T,N}, bc2::MultiDimDirectionalBC)
209+
-----------------------------------------------------------------------------------
210+
211+
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`.
212+
The ends of `u1` and `u2` that are not connected will use the boundary conditions `bc1` and `bc2` respectively.
213+
214+
Drop `dim1` and `dim2` when your `u1` and `u2` are vectors.
215+
216+
Use `Q1` to extend `u1` and `Q2` to extend `u2`.
217+
218+
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:
219+
u_t1 .= L*Q*u_t0
220+
"""
221+
function BridgeBCBridgeBC(bc1::AtomicBC, u1::AbstractArray{T,1}, hilo1::String, hilo2::String, u2::AbstractArray{T,1}, bc2::AtomicBC) where T
222+
if hilo1 == "low"
223+
view1 = view(u1, 1)
224+
if hilo2 == "low"
225+
view2 = view(u2, 1)
226+
BC1 = MixedBC(BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view2, zeros(T, 1), view2), bc1)
227+
BC2 = MixedBC(BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view1, zeros(T, 1), view1), bc2)
228+
elseif hilo2 == "high"
229+
view2 = view(u2, length(u2))
230+
BC1 = MixedBC(BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view2, zeros(T, 1), view2), bc1)
231+
BC2 = MixedBC(bc2, BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view1, zeros(T, 1), view1))
232+
else
233+
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")
234+
end
235+
elseif hilo1 == "high"
236+
view1 = view(u1, length(u1))
237+
if hilo2 == "low"
238+
view2 = view(u2, 1)
239+
BC1 = MixedBC(bc1, BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view2, zeros(T, 1), view2))
240+
BC2 = MixedBC(BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view1, zeros(T, 1), view1), bc2)
241+
elseif hilo2 == "high"
242+
view2 = view(u2, length(u2))
243+
BC1 = MixedBC(bc1, BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view2, zeros(T, 1), view2))
244+
BC2 = MixedBC(bc2, BridgeBC{T, 1, eltype(s1)}(zeros(T, 1), view1, zeros(T, 1), view1))
245+
else
246+
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")
247+
end
248+
else
249+
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")
250+
end
251+
return (BC1, BC2)
252+
end
253+
254+
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)
255+
168256
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)
169257
Base.:*(Q::PeriodicBC, u::AbstractVector) = BoundaryPaddedVector(u[end], u[1], u)
170258

src/derivative_operators/multi_dim_bc_operators.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ 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+
1718
_slice_rmul!(u_temp, A, u, dim, CartesianIndices(axes(u)[1:dim-1]), CartesianIndices(axes(u)[(dim+1):end]))
19+
1820
return u_temp
1921
end
2022

2123
@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}
2224
for J in post
2325
for I in pre
26+
2427
tmp = A[I,J]*u[I, :, J]
2528
lower[I,J], upper[I,J] = tmp.l, tmp.r
2629
end
@@ -33,7 +36,9 @@ function slice_rmul(A::AbstractArray{B,M}, u::AbstractArray{T,N}, dim::Int) wher
3336
@assert M == N-1
3437
lower = zeros(T,perpsize(u,dim))
3538
upper = zeros(T,perpsize(u,dim))
39+
3640
_slice_rmul!(lower, upper, A, u, dim, CartesianIndices(axes(u)[1:dim-1]), CartesianIndices(axes(u)[(dim+1):end]))
41+
3742
return (lower, upper)
3843
end
3944

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Base: isapprox
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
66
@time @safetestset "JacVec Operators Interface" begin include("jacvec_operators.jl") end
7+
@time @safetestset "Validate BridgeBC and its constructors" begin include("bridge_bc.jl") end
78
@time @safetestset "Composite Operators Interface" begin include("composite_operators_interface.jl") end
89
@time @safetestset "BC and Coefficient Compositions" begin include("bc_coeff_compositions.jl") end
910
@time @safetestset "Derivative Operators Interface" begin include("derivative_operators_interface.jl") end

0 commit comments

Comments
 (0)