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

Commit 012b63d

Browse files
Merge pull request #102 from JuliaDiffEq/robin_tests
Robin tests and some fixes to RobinBC
2 parents 602cd38 + 73e7afe commit 012b63d

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

src/derivative_operators/robin_bc_extended.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ end
3232

3333
Base.:*(Q::RobinBC,u) = RobinBCExtended(u, Q.al, Q.bl, Q.cl, Q.dx_l, Q.ar, Q.br, Q.cr, Q.dx_r)
3434
Base.length(Q::RobinBCExtended) = length(Q.u) + 2
35+
Base.size(Q::RobinBCExtended) = (length(Q.u)+2,)
3536
Base.lastindex(Q::RobinBCExtended) = Base.length(Q)
3637

3738
function Base.getindex(Q::RobinBCExtended,i)
@@ -45,8 +46,8 @@ function Base.getindex(Q::RobinBCExtended,i)
4546
end
4647

4748
function LinearAlgebra.Array(Q::RobinBC, N::Int)
48-
Q_L = [(-Q.bl/Q.dx_l)/(Q.al-Q.bl/Q.dx_l) transpose(zeros(N-1)); Diagonal(ones(N)); (Q.br/Q.dx_r)/(Q.ar+Q.br/Q.dx_r) transpose(zeros(N-1))]
49-
Q_b = [Q.cl; zeros(N); Q.cr]
49+
Q_L = [(-Q.bl/Q.dx_l)/(Q.al-Q.bl/Q.dx_l) transpose(zeros(N-1)); Diagonal(ones(N)); transpose(zeros(N-1)) (Q.br/Q.dx_r)/(Q.ar+Q.br/Q.dx_r)]
50+
Q_b = [Q.cl/(Q.al-Q.bl/Q.dx_l); zeros(N); Q.cr/(Q.ar+Q.br/Q.dx_r)]
5051
return (Q_L, Q_b)
5152
end
5253

test/robin.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using LinearAlgebra, DiffEqOperators, Random, Test
2+
3+
# Generate random parameters
4+
al = rand(5)
5+
bl = rand(5)
6+
cl = rand(5)
7+
dx_l = rand(5)
8+
ar = rand(5)
9+
br = rand(5)
10+
cr = rand(5)
11+
dx_r = rand(5)
12+
13+
# Construct 5 arbitrary RobinBC operators
14+
for i in 1:5
15+
Q = RobinBC(al[i], bl[i], cl[i], dx_l[i], ar[i], br[i], cr[i], dx_r[i])
16+
17+
Q_L, Q_b = Array(Q,5i)
18+
19+
#Check that Q_L is is correctly computed
20+
@test Q_L[2:5i+1,1:5i] Array(I, 5i, 5i)
21+
@test Q_L[1,:] [1 / (1-al[i]*dx_l[i]/bl[i]); zeros(5i-1)]
22+
@test Q_L[5i+2,:] [zeros(5i-1); 1 / (1+ar[i]*dx_r[i]/br[i])]
23+
24+
25+
#Check that Q_b is computed correctly
26+
@test Q_b [cl[i]/(al[i]-bl[i]/dx_l[i]); zeros(5i); cr[i]/(ar[i]+br[i]/dx_r[i])]
27+
28+
# Construct the extended operator and check that it correctly extends u to a (5i+2)
29+
# vector, along with encoding boundary condition information.
30+
u = rand(5i)
31+
32+
Qextended = Q*u
33+
CorrectQextended = [(cl[i]-(bl[i]/dx_l[i])*u[1])/(al[i]-bl[i]/dx_l[i]); u; (cr[i]+ (br[i]/dx_r[i])*u[5i])/(ar[i]+br[i]/dx_r[i])]
34+
35+
@test length(Qextended) 5i+2
36+
@test Qextended CorrectQextended
37+
38+
# Check concretization
39+
@test Array(Qextended) CorrectQextended
40+
41+
# Check that Q_L and Q_b correctly compute RobinBCExtended
42+
@test Q_L*u + Q_b CorrectQextended
43+
44+
@test [Qextended[1]; Qextended.u; Qextended[5i+2]] CorrectQextended
45+
46+
end
47+
48+
#TODO: Implement tests for BC's that are contingent on the sign of the coefficient on the operator near the boundary

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using SafeTestsets
22
import Base: isapprox
33

44
@time @safetestset "Basic Operators Interface" begin include("basic_operators_interface.jl") end
5+
@time @safetestset "Robin Boundary Condition Operators" begin include("robin.jl") end
56
@time @safetestset "JacVec Operators Interface" begin include("jacvec_operators.jl") end
67
@time @safetestset "Composite Operators Interface" begin include("composite_operators_interface.jl") end
78

0 commit comments

Comments
 (0)