Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 78f4923

Browse files
committed
update the tests
1 parent 34aaceb commit 78f4923

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

test/global_PDE.jl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using FiniteDiff, LinearAlgebra, Test
2+
using SparsityDetection, SparseArrays
3+
4+
# Define the constants for the PDE
5+
const α₂ = 1.0
6+
const α₃ = 1.0
7+
const β₁ = 1.0
8+
const β₂ = 1.0
9+
const β₃ = 1.0
10+
const r₁ = 1.0
11+
const r₂ = 1.0
12+
const D = 100.0
13+
const γ₁ = 0.1
14+
const γ₂ = 0.1
15+
const γ₃ = 0.1
16+
const N = 8
17+
const X = reshape([i for i in 1:N for j in 1:N],N,N)
18+
const Y = reshape([j for i in 1:N for j in 1:N],N,N)
19+
const α₁ = 1.0.*(X.>=4*N/5)
20+
21+
const Mx = Tridiagonal([1.0 for i in 1:N-1],[-2.0 for i in 1:N],[1.0 for i in 1:N-1])
22+
const My = copy(Mx)
23+
Mx[2,1] = 2.0
24+
Mx[end-1,end] = 2.0
25+
My[1,2] = 2.0
26+
My[end,end-1] = 2.0
27+
28+
# Define the initial condition as normal arrays
29+
u0 = zeros(N,N,3)
30+
31+
const MyA = zeros(N,N);
32+
const AMx = zeros(N,N);
33+
const DA = zeros(N,N);
34+
# Define the discretized PDE as an ODE function
35+
function f(du,u,p,t)
36+
A = @view u[:,:,1]
37+
B = @view u[:,:,2]
38+
C = @view u[:,:,3]
39+
dA = @view du[:,:,1]
40+
dB = @view du[:,:,2]
41+
dC = @view du[:,:,3]
42+
mul!(MyA,My,A)
43+
mul!(AMx,A,Mx)
44+
@. DA = D*(MyA + AMx)
45+
@. dA = DA + α₁ - β₁*A - r₁*A*B + r₂*C
46+
@. dB = α₂ - β₂*B - r₁*A*B + r₂*C
47+
@. dC = α₃ - β₃*C + r₁*A*B - r₂*C
48+
end
49+
50+
input = rand(N,N,3)
51+
output = similar(input)
52+
sparsity_pattern = jacobian_sparsity(f,output,input,nothing,0.0)
53+
jac_sparsity = Float64.(sparse(sparsity_pattern))
54+
55+
function testf2(u)
56+
_u = reshape(u,size(input)...)
57+
du = similar(_u)
58+
f(du,_u,nothing,0.0)
59+
vec(du)
60+
end
61+
findifjac = FiniteDiff.finite_difference_jacobian(testf2,input)
62+
@test all((abs.(findifjac) .> 0) .== (jac_sparsity .> 0))

test/hessian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Term(i...) = TermCombination(Set([Dict(j=>1 for j in i)]))
3636
# copy
3737
@test hesstesttag(x->copy(x)[1], [1,2]) == Term(1)
3838
@test hesstesttag(x->x[:][1], [1,2]) == Term(1)
39-
#@test hesstesttag(x->x[1:1][1], [1,2]) == Term(1)
39+
@test hesstesttag(x->x[1:1][1], [1,2]) == Term(1)
4040

4141
# tests `iterate`
4242
function mysum(x)

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
include("common.jl")
22

33
@testset "Jacobian Sparsity" begin include("jacobian.jl") end
4-
@testset "Hessian sparsity" begin include("hessian.jl") end
54
@testset "Paraboloid example" begin include("paraboloid.jl") end
5+
@testset "PDE with globals" begin include("global_PDE.jl") end
6+
7+
@testset "Hessian sparsity" begin include("hessian.jl") end
68

79
@testset "Exploration" begin include("ifsandbuts.jl") end
810
@testset "Examples" begin include("examples.jl") end

0 commit comments

Comments
 (0)