Skip to content

Commit d008964

Browse files
committed
ODE test
1 parent 1c728c4 commit d008964

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

test/runtests.jl

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,54 @@ using Test
44
@testset "LinearSolve.jl" begin
55
using LinearAlgebra
66
n = 100
7-
x = Array(range(start=-1,stop=1,length=n))
8-
uu= @. sin(pi*x)
9-
107
dx = 2/(n-1)
118

12-
AA = Tridiagonal(ones(n-1),-2ones(n),ones(n-1))/(dx*dx)
13-
bb = @. -(pi^2)*uu
9+
xx = Array(range(start=-1,stop=1,length=n))
10+
AA = Tridiagonal(ones(n-1),-2ones(n),ones(n-1))/(dx*dx) # rank-deficient sys
11+
uu = @. sin(pi*xx)
12+
bb = AA * uu #@. -(pi^2)*uu
13+
1414
id = Matrix(I,n,n)
1515
R = id[2:end-1,:]
1616

17-
A = R * AA * R'
17+
x = R * xx
18+
A = R * AA * R' # full rank system
1819
u = R * uu
1920
b = A * u #R * bb
2021

21-
@test isapprox(A*u,b;atol=1e-2)
22-
prob = LinearProblem(A, b)
23-
24-
x = zero(b)
22+
x = zero(b)
23+
prob = LinearProblem(A, b;u0=x)
2524

2625
# Factorization
27-
@test A * solve(prob, LUFactorization();) b
28-
@test A * solve(prob, QRFactorization();) b
29-
@test A * solve(prob, SVDFactorization();) b
30-
31-
# Krylov
32-
@test A * solve(prob, KrylovJL(A, b)) b
33-
34-
# make algorithm callable - interoperable with DiffEq ecosystem
35-
@test A * LUFactorization()(x,A,b) b
36-
@test A * QRFactorization()(x,A,b) b
37-
@test A * SVDFactorization()(x,A,b) b
38-
@test A * KrylovJL()(x,A,b) b
39-
40-
# in place
41-
LUFactorization()(x,A,b)
42-
@test A * x b
43-
QRFactorization()(x,A,b)
44-
@test A * x b
45-
SVDFactorization()(x,A,b)
46-
@test A * x b
47-
KrylovJL()(x,A,b)
48-
@test A * x b
26+
for alg in (:LUFactorization, :QRFactorization, :SVDFactorization,
27+
:KrylovJL)
28+
@eval begin
29+
@test $A * solve($prob, $alg();) $b
30+
$alg()($x,$A,$b)
31+
@test $A * $x $b
32+
end
33+
end
4934

5035
# test on some ODEProblem
51-
# using OrdinaryDiffEq
36+
using OrdinaryDiffEq
37+
using DiffEqProblemLibrary.ODEProblemLibrary
38+
ODEProblemLibrary.importodeproblems()
39+
40+
# add this problem to DiffEqProblemLibrary
41+
# kx = 1
42+
# kt = 1
43+
# ut(x,t) = sin(kx*pi*x)*cos(kt*pi*t)
44+
# ic(x) = ut(x,0.0)
45+
# f(x,t) = ut(x,t)*(kx*pi)^2 - sin(kx*pi*x)*sin(kt*pi*t)*(kt*pi)
46+
# u0 = ic.(x)
47+
# dudt!(du,u,p,t) = -A*u + f.(x,t)
48+
# dt = 0.01
49+
# tspn = (0.0,1.0)
50+
# func = ODEFunction(dudt!)
51+
# prob = ODEProblem(func,u0,tspn)
52+
53+
prob = ODEProblemLibrary.prob_ode_linear
54+
sol = solve(prob, Rodas5(linsolve=SVDFactorization()); saveat=0.1)
55+
@show sol.retcode
56+
5257
end

0 commit comments

Comments
 (0)