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

Commit 7761916

Browse files
committed
removed PartiallyComposed
1 parent 1b7dc2f commit 7761916

File tree

3 files changed

+16
-86
lines changed

3 files changed

+16
-86
lines changed

src/derivative_operators/BC_operators.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Robin, General, and in general Neumann, Dirichlet and Bridge BCs are all affine
88
"""
99
abstract type AffineBC{T} <: AtomicBC{T} end
1010

11+
struct NeumannBC{N} end
12+
struct Neumann0BC{N} end
13+
struct DirichletBC{N} end
14+
struct Dirichlet0BC{N} end
1115
"""
1216
q = PeriodicBC{T}()
1317

src/derivative_operators/multi_dim_bc_operators.jl

Lines changed: 9 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -54,61 +54,6 @@ struct ComposedMultiDimBC{T, B<:AtomicBC{T}, N,M} <: MultiDimensionalBC{T, N}
5454
BCs::Vector{Array{B, M}}
5555
end
5656

57-
struct PartiallyComposedMultiDimBC{T,B<:Union{MultiDimDirectionalBC, Nothing},N, is_extended} <:MultiDimensionalBC{T,N}
58-
BCs::Vector{B}
59-
end
60-
61-
numextended
62-
63-
64-
function Base._:+(BCs::MultiDimDirectionalBC{T}...) where T
65-
D = getaxis.(BCs)
66-
BCs = BCs[sortperm([D...])]
67-
B = typeof.(BCs)
68-
dimensionalities = ndims.(BCs)
69-
for n in dimensionalities[2:end]
70-
@assert dimensionalites[1] == n "There are "
71-
72-
for d in D
73-
@assert length(setdiff(D, d)) == (N-1) "There are multiple boundary conditions that extend along $d - make sure every dimension has a unique extension"
74-
end
75-
is_extended = falses(length(ndims(BCs[1]))
76-
is_extended[D] .= true
77-
A = Vector{Union{B..., Nothing}}(undef, ndims(BCs[1]))
78-
A[!is_extended] .= Nothing()
79-
for (i,BC) in enumerate(BCs)
80-
A[is_extended][i] = BC
81-
end
82-
return PartiallyComposedMultiDimBC{T, eltype(A), N, is_extended}(A)
83-
end
84-
85-
86-
function Base.:+(Q::PartiallyComposedMultiDimBC{T,B,N,L}, Q1::MultiDimDirectionalBC{T, B2, D, N, M}) where {T,D, B1, B2,N,M,L}
87-
new_BCs = Q.BCs
88-
new_BCs[D] = Q1
89-
is_extended = L
90-
is_extended[D] = true
91-
@assert !(getaxis(Q1) in getaxis.(Q.BCs)) "BCs should all extend along a unique axis"
92-
return PartiallyComposedMultiDimBC{T,eltype(new_BCs), N,is_extended}(new_BCs)
93-
94-
end
95-
96-
Base.:+(Q1::MultiDimDirectionalBC, Q::PartiallyComposedMultiDimBC) = +(Q,Q1)
97-
98-
function Base.:+(Q1::PartiallyComposedMultiDimBC{T,B1,N,L1} Q2::PartiallyComposedMultiDimBC{T,B2,N,L2}) where {T,B1,B2,N,L1,L2}
99-
new_BCs = deepcopy(Q1.BCs)
100-
Lnew = L1 .| L2
101-
for (i,q) in enumerate(Q2.BCs)
102-
if q <: MultiDimensionalBC
103-
if new_BCs[i] <: Nothing
104-
new_BCs[i] = q
105-
else
106-
throw("BCs should all extend along a unique axis")
107-
end
108-
end
109-
end
110-
return PartiallyComposedMultiDimBC{T,Union{B1,B2}, N, Lnew}(new_BCs)
111-
end
11257

11358
"""
11459
A multiple dimensional BC, supporting arbitrary BCs at each boundary point.
@@ -139,10 +84,7 @@ For Neumann0BC, please use
13984
where T is the element type of the domain to be extended
14085
"""
14186
struct MultiDimBC{N} end
142-
struct NeumannBC{N} end
143-
struct Neumann0BC{N} end
144-
struct DirichletBC{N} end
145-
struct Dirichlet0BC{N} end
87+
14688

14789
MultiDimBC{dim}(BC::Array{B,N}) where {N, B<:AtomicBC, dim} = MultiDimDirectionalBC{gettype(BC[1]), B, dim, N+1, N}(BC)
14890
#s should be size of the domain
@@ -153,25 +95,25 @@ MultiDimBC{dim}(BC::B, s) where {B<:AtomicBC, dim} = MultiDimDirectionalBC{gett
15395
MultiDimBC(BC::B, s) where {B<:AtomicBC} = Tuple([MultiDimDirectionalBC{gettype(BC), B, dim, length(s), length(s)-1}(fill(BC, s[setdiff(1:length(s), dim)])) for dim in 1:length(s)])
15496

15597
# Additional constructors for cases when the BC is the same for all boundarties
156-
PeriodicBC{dim}(T,s) where T = MultiDimBC{dim}(PeriodicBC(T), s)
157-
PeriodicBC(T,s) where T = MultiDimBC(PeriodicBC(T), s)
98+
PeriodicBC{dim}(T,s) where dim = MultiDimBC{dim}(PeriodicBC(T), s)
99+
PeriodicBC(T,s) = MultiDimBC(PeriodicBC(T), s)
158100

159-
NeumannBC{dim}::NTuple{2,T}, dx, order, s) where T = RobinBC{dim}((zero(T), one(T), α[1]), (zero(T), one(T), α[2]), dx, order, s)
101+
NeumannBC{dim}::NTuple{2,T}, dx, order, s) where {T,dim} = RobinBC{dim}((zero(T), one(T), α[1]), (zero(T), one(T), α[2]), dx, order, s)
160102
NeumannBC::NTuple{2,T}, dxyz, order, s) where T = RobinBC((zero(T), one(T), α[1]), (zero(T), one(T), α[2]), dxyz, order, s)
161103

162-
DirichletBC{dim}(αl::T, αr::T, s) where T = RobinBC{dim}((one(T), zero(T), αl), (one(T), zero(T), αr), [ones(T, si) for si in s], 2.0, s)
104+
DirichletBC{dim}(αl::T, αr::T, s) where {T,dim} = RobinBC{dim}((one(T), zero(T), αl), (one(T), zero(T), αr), [ones(T, si) for si in s], 2.0, s)
163105
DirichletBC(αl::T, αr::T, s) where T = RobinBC((one(T), zero(T), αl), (one(T), zero(T), αr), [ones(T, si) for si in s], 2.0, s)
164106

165-
Dirichlet0BC{dim}(T::Type, s) = DirichletBC{dim}(zero(T), zero(T), s)
107+
Dirichlet0BC{dim}(T::Type, s) where {dim} = DirichletBC{dim}(zero(T), zero(T), s)
166108
Dirichlet0BC(T::Type, s) = DirichletBC(zero(T), zero(T), s)
167109

168-
Neumann0BC{dim}(T::Type, dx, order, s) = NeumannBC{dim}((zero(T), zero(T)), dx, order, s)
110+
Neumann0BC{dim}(T::Type, dx, order, s) where {dim} = NeumannBC{dim}((zero(T), zero(T)), dx, order, s)
169111
Neumann0BC(T::Type, dxyz, order, s) = NeumannBC((zero(T), zero(T)), dxyz, order, s)
170112

171-
RobinBC{dim}(l::NTuple{3,T}, r::NTuple{3,T}, dx, order, s) where {T} = MultiDimBC{dim}(RobinBC(l, r, dx, order), s)
113+
RobinBC{dim}(l::NTuple{3,T}, r::NTuple{3,T}, dx, order, s) where {T,dim} = MultiDimBC{dim}(RobinBC(l, r, dx, order), s)
172114
RobinBC(l::NTuple{3,T}, r::NTuple{3,T}, dxyz, order, s) where {T} = Tuple([MultiDimDirectionalBC{T, RobinBC{T}, dim, length(s), length(s)-1}(fill(RobinBC(l, r, dxyz[dim], order), perpindex(s,dim))) for dim in 1:length(s)])
173115

174-
GeneralBC{dim}(αl::AbstractVector{T}, αr::AbstractVector{T}, dx, order, s) where {T} = MultiDimBC{dim}(GeneralBC(αl, αr, dx, order), s)
116+
GeneralBC{dim}(αl::AbstractVector{T}, αr::AbstractVector{T}, dx, order, s) where {T,dim} = MultiDimBC{dim}(GeneralBC(αl, αr, dx, order), s)
175117
GeneralBC(αl::AbstractVector{T}, αr::AbstractVector{T}, dxyz, order, s) where {T} = Tuple([MultiDimDirectionalBC{T, GeneralBC{T}, dim, length(s), length(s)-1}(fill(GeneralBC(αl, αr, dxyz[dim], order),perpindex(s,dim))) for dim in 1:length(s)])
176118

177119

@@ -231,19 +173,3 @@ function Base.:*(Q::ComposedMultiDimBC{T, B, N, K}, u::AbstractArray{T, N}) wher
231173
out = slice_rmul.(Q.BCs, fill(u, N), 1:N)
232174
return ComposedBoundaryPaddedArray{T, N, K, typeof(u), typeof(out[1][1])}([A[1] for A in out], [A[2] for A in out], u)
233175
end
234-
235-
236-
237-
function Base.:*(Q::PartiallyComposedMultiDimBC{T,B,N,is_extended}, u::AbstractArray{T,N} where {T,N}
238-
lower = Vector{Union{Array{T,N-1}, Nothing}}(undef, N)
239-
upper = Vector{Union{Array{T,N-1}, Nothing}}(undef, N)
240-
for (i,q) in Q.BCs
241-
if !(q <: Nothing)
242-
lower[i], upper[i] = slice_rmul(q, u)
243-
else
244-
lower[i] = Nothing()
245-
upper[i] = Nothing()
246-
end
247-
end
248-
return PartiallyComposedBoundaryPaddedArray{}(lower,upper,u)
249-
end

test/MultiDimBC_test.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A = rand(n,m)
1010

1111
#Create atomic BC
1212
q1 = RobinBC((1.0, 2.0, 3.0), (0.0, -1.0, 2.0), 0.1, 4.0)
13-
q2 = PeriodicBC{Float64}()
13+
q2 = PeriodicBC(Float64)
1414

1515
BCx = vcat(fill(q1, div(m,2)), fill(q2, m-div(m,2))) #The size of BCx has to be all size components *except* for x
1616
BCy = vcat(fill(q1, div(n,2)), fill(q2, n-div(n,2)))
@@ -45,15 +45,15 @@ A = rand(n,m, o)
4545

4646
#Create atomic BC
4747
q1 = RobinBC((1.0, 2.0, 3.0), (0.0, -1.0, 2.0), 0.1, 4.0)
48-
q2 = PeriodicBC{Float64}()
48+
q2 = PeriodicBC(Float64)
4949

5050
BCx = vcat(fill(q1, (div(m,2), o)), fill(q2, (m-div(m,2), o))) #The size of BCx has to be all size components *except* for x
5151
BCy = vcat(fill(q1, (div(n,2), o)), fill(q2, (n-div(n,2), o)))
5252
BCz = fill(Dirichlet0BC(Float64), (n,m))
5353

5454
Qx = MultiDimBC{1}(BCx)
5555
Qy = MultiDimBC{2}(BCy, 2)
56-
Qz = MultiDimBC{3}(Dirichlet0BC(Float64), size(A)) #Test the other constructor
56+
Qz = Dirichlet0BC{3}(size(A)) #Test the other constructor
5757
@test (Qx+Qy+Qz) == compose(Qx,Qy,Qz) #test addition combinations
5858
Qtmp = Qx + Qz
5959
@test Qz+Qx+Qy == Qy+Qtmp

0 commit comments

Comments
 (0)