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

Commit 286302d

Browse files
committed
2 parents 6312d05 + 710492c commit 286302d

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/derivative_operators/BC_operators.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct RobinBC{T, V<:AbstractVector{T}} <: AffineBC{T,V}
2626
b_l::T
2727
a_r::V
2828
b_r::T
29-
function RobinBC(l::AbstractArray{T}, r::AbstractArray{T}, dx::AbstractArray{T}, order::T = one(T)) where {T,V}
29+
function RobinBC(l::AbstractArray{T}, r::AbstractArray{T}, dx::AbstractArray{T}, order = one(T)) where {T}
3030
cl, al, bl = l
3131
cr, ar, br = r
3232
dx_l, dx_r = dx
@@ -57,7 +57,7 @@ struct GeneralBC{T, V<:AbstractVector{T}} <:AffineBC{T,V}
5757
b_l::T
5858
a_r::V
5959
b_r::T
60-
function GeneralBC{T,V}(αl::AbstractArray{T}, αr::AbstractArray{T}, dx::AbstractArray{T}, order::T = one(T)) where {T,V<:AbstractArray}
60+
function GeneralBC(αl::AbstractArray{T}, αr::AbstractArray{T}, dx::AbstractArray{T}, order = 1) where {T}
6161
dx_l, dx_r = dx
6262
nl = length(αl)
6363
nr = length(αr)
@@ -81,7 +81,7 @@ struct GeneralBC{T, V<:AbstractVector{T}} <:AffineBC{T,V}
8181

8282
b_l = -αl[1]/denoml
8383
b_r = -αr[1]/denomr
84-
new{T, V}(a_l,b_l,reverse!(a_r),b_r)
84+
new{T, typeof(a_l)}(a_l,b_l,reverse!(a_r),b_r)
8585
end
8686
end
8787

@@ -93,8 +93,7 @@ DirichletBC(α::AbstractVector{T}, dx::AbstractVector{T}, order) where T = Robin
9393
DirichletBC::AbstractVector{T}, dx::AbstractVector{T}) where T = RobinBC([one(T), zero(T), α[1]], [one(T), zero(T), α[2]], dx)
9494

9595
# other acceptable argument signatures
96-
RobinBC(al::T, bl::T, cl::T, dx_l::T, ar::T, br::T, cr::T, dx_r::T) where T = RobinBC([al,bl,cl], [ar, br, cr], [dx_l, dx_r])
97-
RobinBC(al::T, bl::T, cl::T, dx_l::T, ar::T, br::T, cr::T, dx_r::T, order::T) where T = RobinBC([al,bl,cl], [ar, br, cr], [dx_l, dx_r], order)
96+
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, dx_r], order)
9897

9998
# this is 'boundary padded vector' as opposed to 'boundary padded array' to distinguish it from the n dimensional implementation that will eventually be neeeded
10099
struct BoundaryPaddedVector{T,T2 <: AbstractVector{T}}
@@ -111,7 +110,6 @@ Base.size(Q::BoundaryPaddedVector) = (length(Q),)
111110
Base.lastindex(Q::BoundaryPaddedVector) = Base.length(Q)
112111

113112
function Base.getindex(Q::BoundaryPaddedVector,i)
114-
@show i
115113
if i == 1
116114
return Q.l
117115
elseif i == length(Q)
@@ -122,14 +120,28 @@ function Base.getindex(Q::BoundaryPaddedVector,i)
122120
end
123121

124122
function LinearAlgebra.Array(Q::AffineBC{T,V}, N::Int) where {T,V}
123+
Q_L = [transpose(Q.a_l) transpose(zeros(T, N-length(Q.a_l))); Diagonal(ones(T,N)); transpose(zeros(T, N-length(Q.a_r))) transpose(Q.a_r)]
124+
Q_b = [Q.b_l; zeros(T,N); Q.b_r]
125+
return (Array(Q_L), Q_b)
126+
end
127+
128+
function SparseArrays.SparseMatrixCSC(Q::AffineBC{T,V}, N::Int) where {T,V}
125129
Q_L = [transpose(Q.a_l) transpose(zeros(T, N-length(Q.a_l))); Diagonal(ones(T,N)); transpose(zeros(T, N-length(Q.a_r))) transpose(Q.a_r)]
126130
Q_b = [Q.b_l; zeros(T,N); Q.b_r]
127131
return (Q_L, Q_b)
128132
end
129133

134+
function SparseArrays.sparse(Q::AffineBC{T,V}, N::Int) where {T,V}
135+
SparseMatrixCSC(Q,N)
136+
end
137+
130138
LinearAlgebra.Array(Q::PeriodicBC{T}, N::Int) where T = [transpose(zeros(T, N-1)) one(T); Diagonal(ones(T,N)); one(T) transpose(zeros(T, N-1))]
131139

132140

141+
LinearAlgebra.Array(Q::PeriodicBC{T}, N::Int) where T = Array([transpose(zeros(T, N-1)) one(T); Diagonal(ones(T,N)); one(T) transpose(zeros(T, N-1))])
142+
SparseArrays.SparseMatrixCSC(Q::PeriodicBC{T}, N::Int) where T = [transpose(zeros(T, N-1)) one(T); Diagonal(ones(T,N)); one(T) transpose(zeros(T, N-1))]
143+
SparseArrays.sparse(Q::PeriodicBC{T}, N::Int) where T = SparseMatrixCSC(Q,N)
144+
133145
function LinearAlgebra.Array(Q::BoundaryPaddedVector)
134146
return [Q.l; Q.u; Q.r]
135147
end

test/generic_operator_validation.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ y_im = exp.(π*im*x)
99
yim_ = y_im[2:(end-1)]
1010
y_ = y[2:(end-1)]
1111

12-
13-
14-
for dor in 1:6, aor in 1:8
12+
@test_broken for dor in 1:6, aor in 1:8
1513

1614
D1 = DerivativeOperator{Float64}(dor,aor,dx[1],length(x))
1715
D2 = DiffEqOperators.FiniteDifference{Float64}(dor,aor,dx,length(x))
@@ -41,5 +39,4 @@ for dor in 1:6, aor in 1:8
4139
@test_broken y_imprime1 y_imprime2
4240

4341
#TODO: implement specific tests for the left and right boundary regions, waiting until after update
44-
end
4542
end

0 commit comments

Comments
 (0)