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

Commit 7ed8460

Browse files
add tests
1 parent 8cd1f6b commit 7ed8460

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

src/derivative_operators/BC_operators.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
abstract type AbstractBC{T} end
1+
abstract type AbstractBC{T} <: AbstractDiffEqLinearOperator{T} end
22

33
"""
44
Robin, General, and in general Neumann and Dirichlet BCs are all affine opeartors, meaning that they take the form Qx = Qax + Qb.
@@ -92,13 +92,13 @@ DirichletBC(α::AbstractVector{T}, dx::AbstractVector{T}, order = 1) where T = R
9292
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)
9393

9494
# this is 'boundary padded vector' as opposed to 'boundary padded array' to distinguish it from the n dimensional implementation that will eventually be neeeded
95-
struct BoundaryPaddedVector{T,T2 <: AbstractVector{T}}
95+
struct BoundaryPaddedVector{T,T2 <: AbstractVector{T}} <: AbstractVector{T}
9696
l::T
9797
r::T
9898
u::T2
9999
end
100100

101-
Base.:*(Q::AffineBC, u) = 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)
101+
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)
102102

103103
Base.size(Q::AbstractBC) = (Inf, Inf) #Is this nessecary?
104104
Base.length(Q::BoundaryPaddedVector) = length(Q.u) + 2
@@ -139,4 +139,14 @@ function LinearAlgebra.Array(Q::BoundaryPaddedVector)
139139
return [Q.l; Q.u; Q.r]
140140
end
141141

142-
#TODO: Implement Sparse concretization
142+
function Base.convert(::Type{Array},A::AbstractBC{T}) where T
143+
Array(A)
144+
end
145+
146+
function Base.convert(::Type{SparseMatrixCSC},A::AbstractBC{T}) where T
147+
SparseMatrixCSC(A)
148+
end
149+
150+
function Base.convert(::Type{AbstractMatrix},A::AbstractBC{T}) where T
151+
SparseMatrixCSC(A)
152+
end

test/bc_coeff_compositions.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using LinearAlgebra, DiffEqOperators, Random, Test, BandedMatrices
2+
3+
# Generate random parameters
4+
al = rand()
5+
bl = rand()
6+
cl = rand()
7+
dx_l = rand()
8+
ar = rand()
9+
br = rand()
10+
cr = rand()
11+
dx_r = rand()
12+
13+
Q = RobinBC(al, bl, cl, dx_l, ar, br, cr, dx_r)
14+
N = 20
15+
L = CenteredDifference(4,4, 1.0, N)
16+
L2 = CenteredDifference(2,4, 1.0, N)
17+
18+
function coeff_func(du,u,p,t)
19+
du .= u
20+
end
21+
22+
cL = coeff_func*L
23+
coeffs = rand(N)
24+
DiffEqOperators.update_coefficients!(cL,coeffs,nothing,0.0)
25+
26+
@test cL.coefficients == coeffs
27+
28+
# Fails
29+
u = rand(20)
30+
@test_broken LQ = L*Q
31+
@test_broken LQ*u L*(Q*u)
32+
33+
u = rand(22)
34+
@test (L + L2) * u convert(AbstractMatrix,L + L2) * u (BandedMatrix(L) + BandedMatrix(L2)) * u

test/derivative_operators_interface.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ end
183183
end
184184

185185
@testset "Linear combinations of operators" begin
186-
# Only tests the additional functionality defined in "operator_combination.jl"
187186
N = 10
188187
Random.seed!(0); LA = DiffEqArrayOperator(rand(N,N+2))
189188
LD = CenteredDifference(2,2,1.0,N)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Base: isapprox
55
@time @safetestset "Robin Boundary Condition Operators" begin include("robin.jl") end
66
@time @safetestset "JacVec Operators Interface" begin include("jacvec_operators.jl") end
77
@time @safetestset "Composite Operators Interface" begin include("composite_operators_interface.jl") end
8+
@time @safetestset "BC and Coefficient Compositions" begin include("bc_coeff_compositions.jl")
89
@time @safetestset "Derivative Operators Interface" begin include("derivative_operators_interface.jl") end
910
@time @safetestset "Validate and Compare Generic Operators" begin include("generic_operator_validation.jl") end
1011
#@time @safetestset "2nd order check" begin include("2nd_order_check.jl") end

0 commit comments

Comments
 (0)