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

Commit 4036f95

Browse files
committed
changed multilayerBC and compose
1 parent 840c926 commit 4036f95

File tree

3 files changed

+88
-9
lines changed

3 files changed

+88
-9
lines changed

src/derivative_operators/.logo

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[?25l[?7l██████████████████ ████████
2+
██████████████████ ████████
3+
██████████████████ ████████
4+
██████████████████ ████████
5+
████████ ████████
6+
████████ ████████ ████████
7+
████████ ████████ ████████
8+
████████ ████████ ████████
9+
████████ ████████ ████████
10+
████████ ████████ ████████
11+
████████ ████████ ████████
12+
████████ ████████ ████████
13+
████████ ████████ ████████
14+
████████ ████████ ████████
15+
zander@Arcadia
16+
--------------
17+
OS: Manjaro Linux x86_64
18+
Host: N56VM 1.0
19+
Kernel: 4.19.66-1-MANJARO
20+
Uptime: 5 days, 23 hours, 35 mins
21+
Packages: 1133 (pacman)
22+
Shell: zsh 5.7.1
23+
Resolution: 1920x1080
24+
WM: i3
25+
Theme: Adapta-Nokto-Eta-Maia [GTK2], solarized-dark-gtk [GTK3]
26+
Icons: Papirus-Adapta-Nokto-Maia [GTK2/3]
27+
Terminal: guake
28+
CPU: Intel i7-3610QM (8) @ 3.300GHz
29+
GPU: Intel 3rd Gen Core processor Graphics Controller
30+
GPU: NVIDIA GeForce GT 620M/630M/635M/640M LE
31+
Memory: 2199MiB / 7861MiB
32+
33+
        
34+
35+

src/derivative_operators/multi_dim_bc_operators.jl

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,44 @@ 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<:MultiDimDirectionalBC,N,L} <:MultiDimensionalBC{T,N}
58+
BCs::Vector{B}
59+
end
60+
61+
function Base.:+(Q1::MultiDimDirectionalBC{T,B1,D1,N,M}, Q2::MultiDimDirectionalBC{T,B2,D2,N,M}) where {T,B1, B2,D1,D2,N,M}
62+
@assert D1 != D2 "BCs should all extend along a unique axis"
63+
return PartiallyComposedMultiDimBC{T,Union{typeof(Q1),typeof(Q2)}, N,2}(Array[Q1,Q2])
64+
end
65+
66+
function Base.:+(Q1::MultiDimDirectionalBC{T,B1,D1,2,1}, Q2:: MultiDimDirectionalBC{T,B2,D2,2,1}) where {T,B1,B2,D1,D2}
67+
return compose(Q1,Q2)
68+
end
69+
70+
function Base.:+(Q::PartiallyComposedMultiDimBC{T,B,N,L}, Q1::MultiDimDirectionalBC) where {T,B,N,M,L}
71+
new_BCs = vcat(Q.BCs,Q1)
72+
if L+1 == N
73+
return compose(new_BCs...)
74+
elseif !(getaxis(Q1) in getaxis.(Q.BCs))
75+
return PartiallyComposedMultiDimBC{T,eltype(new_BCs), N,L-1}(new_BCs)
76+
else
77+
throw("BCs should all extend along a unique axis")
78+
end
79+
end
80+
81+
Base.:+(Q1::MultiDimDirectionalBC, Q::PartiallyComposedMultiDimBC) = +(Q,Q1)
82+
83+
function Base.:+(Q1::PartiallyComposedMultiDimBC{T,B1,N,L1} Q2::PartiallyComposedMultiDimBC{T,B2,N,L2) where {T,B1,B2,N,L1,L2}
84+
new_BCs = vcat(Q1.BCs, Q2.BCs)
85+
if L1 + L2 < N
86+
@assert length(setdiff(1:N, getaxis.(new_BCs))) == (N-L1-L2) "BCs should all extend along a unique axis"
87+
return PartiallyComposedMultiDimBC{T,Union{B1,B2}, N, L1+ L2}(new_BCs)
88+
elseif L1+L2 == N
89+
return compose(new_BCs...)
90+
else
91+
throw("Too many supplied BCs for the number of dimensions")
92+
end
93+
end
94+
5795
"""
5896
A multiple dimensional BC, supporting arbitrary BCs at each boundary point.
5997
To construct an arbitrary BC, pass an Array of BCs with dimension `N-1`, if `N` is the dimensionality of your domain `u`
@@ -82,15 +120,16 @@ For Neumann0BC, please use
82120
Qx, Qy, Qz... = Neumann0BC(T::Type, (dx::Vector, dy::Vector, dz::Vector ...), approximation_order, size(u))
83121
where T is the element type of the domain to be extended
84122
"""
85-
MultiDimBC(BC::Array{B,N}, dim::Integer) where {N, B<:AtomicBC} = MultiDimDirectionalBC{gettype(BC[1]), B, dim, N+1, N}(BC)
123+
struct MultiDimBC{N} end
124+
MultiDimBC{dim}(BC::Array{B,N}) where {N, B<:AtomicBC, dim} = MultiDimDirectionalBC{gettype(BC[1]), B, dim, N+1, N}(BC)
86125
#s should be size of the domain
87-
MultiDimBC(BC::B, s, dim::Integer) where {B<:AtomicBC} = MultiDimDirectionalBC{gettype(BC), B, dim, length(s), length(s)-1}(fill(BC, s[setdiff(1:length(s), dim)]))
126+
MultiDimBC{dim}(BC::B, s) where {B<:AtomicBC, dim} = MultiDimDirectionalBC{gettype(BC), B, dim, length(s), length(s)-1}(fill(BC, s[setdiff(1:length(s), dim)]))
88127

89128
#Extra constructor to make a set of BC operators that extend an atomic BC Operator to the whole domain
90129
#Only valid in the uniform grid case!
91130
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)])
92131

93-
# Additional constructors for cases when the BC is the same for all boundarties
132+
# Additional constructors for cases when the BC is the same for all boundarties
94133

95134
PeriodicBC{T}(s) where T = MultiDimBC(PeriodicBC{T}(), s)
96135

@@ -158,3 +197,6 @@ function Base.:*(Q::ComposedMultiDimBC{T, B, N, K}, u::AbstractArray{T, N}) wher
158197
out = slice_rmul.(Q.BCs, fill(u, N), 1:N)
159198
return ComposedBoundaryPaddedArray{T, N, K, typeof(u), typeof(out[1][1])}([A[1] for A in out], [A[2] for A in out], u)
160199
end
200+
201+
function Base.:*(Q::PartiallyComposedMultiDimBC, u::AbstractArray{T,N} where {T,N}
202+
return Tuple([MultiDimDirectionalBC

test/MultiDimBC_test.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ BCx = vcat(fill(q1, div(m,2)), fill(q2, m-div(m,2))) #The size of BCx has to be
1616
BCy = vcat(fill(q1, div(n,2)), fill(q2, n-div(n,2)))
1717

1818

19-
Qx = MultiDimBC(BCx, 1)
20-
Qy = MultiDimBC(BCy, 2)
19+
Qx = MultiDimBC{1}(BCx)
20+
Qy = MultiDimBC{2}(BCy)
2121

2222
Ax = Qx*A
2323
Ay = Qy*A
@@ -51,10 +51,12 @@ BCx = vcat(fill(q1, (div(m,2), o)), fill(q2, (m-div(m,2), o))) #The size of BCx
5151
BCy = vcat(fill(q1, (div(n,2), o)), fill(q2, (n-div(n,2), o)))
5252
BCz = fill(Dirichlet0BC(Float64), (n,m))
5353

54-
Qx = MultiDimBC(BCx, 1)
55-
Qy = MultiDimBC(BCy, 2)
56-
Qz = MultiDimBC(Dirichlet0BC(Float64), size(A), 3) #Test the other constructor
57-
54+
Qx = MultiDimBC{1}(BCx)
55+
Qy = MultiDimBC{2}(BCy, 2)
56+
Qz = MultiDimBC{3}(Dirichlet0BC(Float64), size(A)) #Test the other constructor
57+
@test (Qx+Qy+Qz) == compose(Qx,Qy,Qz) #test addition combinations
58+
Qtmp = Qx + Qz
59+
@test Qz+Qx+Qy == Qy+Qtmp
5860
Ax = Qx*A
5961
Ay = Qy*A
6062
Az = Qz*A

0 commit comments

Comments
 (0)