Skip to content

Commit 8b74b25

Browse files
push new test
1 parent 0e2e49f commit 8b74b25

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1515
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1616
SimpleNonlinearSolve = "727e6d20-b764-4bd8-a329-72de5adea6c7"
1717
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
18+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1819
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
1920
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
2021
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
@@ -40,7 +41,8 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
4041
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
4142
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
4243
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
44+
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
4345
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4446

4547
[targets]
46-
test = ["BenchmarkTools", "SafeTestsets", "Pkg", "Test", "ForwardDiff", "StaticArrays"]
48+
test = ["BenchmarkTools", "SafeTestsets", "Pkg", "Test", "ForwardDiff", "StaticArrays", "Symbolics"]

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ const is_APPVEYOR = Sys.iswindows() && haskey(ENV, "APPVEYOR")
99

1010
if GROUP == "All" || GROUP == "Core"
1111
@time @safetestset "Basic Tests + Some AD" begin include("basictests.jl") end
12+
@time @safetestset "Sparsity Tests" begin include("sparse.jl") end
1213
end end

test/sparse.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using NonlinearSolve, LinearAlgebra, SparseArrays
2+
3+
const N = 32
4+
const xyd_brusselator = range(0,stop=1,length=N)
5+
brusselator_f(x, y) = (((x-0.3)^2 + (y-0.6)^2) <= 0.1^2) * 5.
6+
limit(a, N) = a == N+1 ? 1 : a == 0 ? N : a
7+
function brusselator_2d_loop(du, u, p)
8+
A, B, alpha, dx = p
9+
alpha = alpha/dx^2
10+
@inbounds for I in CartesianIndices((N, N))
11+
i, j = Tuple(I)
12+
x, y = xyd_brusselator[I[1]], xyd_brusselator[I[2]]
13+
ip1, im1, jp1, jm1 = limit(i+1, N), limit(i-1, N), limit(j+1, N), limit(j-1, N)
14+
du[i,j,1] = alpha*(u[im1,j,1] + u[ip1,j,1] + u[i,jp1,1] + u[i,jm1,1] - 4u[i,j,1]) +
15+
B + u[i,j,1]^2*u[i,j,2] - (A + 1)*u[i,j,1] + brusselator_f(x, y)
16+
du[i,j,2] = alpha*(u[im1,j,2] + u[ip1,j,2] + u[i,jp1,2] + u[i,jm1,2] - 4u[i,j,2]) +
17+
A*u[i,j,1] - u[i,j,1]^2*u[i,j,2]
18+
end
19+
end
20+
p = (3.4, 1., 10., step(xyd_brusselator))
21+
22+
function init_brusselator_2d(xyd)
23+
N = length(xyd)
24+
u = zeros(N, N, 2)
25+
for I in CartesianIndices((N, N))
26+
x = xyd[I[1]]
27+
y = xyd[I[2]]
28+
u[I,1] = 22*(y*(1-y))^(3/2)
29+
u[I,2] = 27*(x*(1-x))^(3/2)
30+
end
31+
u
32+
end
33+
u0 = init_brusselator_2d(xyd_brusselator)
34+
prob_brusselator_2d = NonlinearProblem(brusselator_2d_loop,u0,p)
35+
sol = solve(prob_brusselator_2d, NewtonRaphson())
36+
37+
using Symbolics
38+
du0 = copy(u0)
39+
jac_sparsity = Symbolics.jacobian_sparsity((du,u)->brusselator_2d_loop(du,u,p),du0,u0)
40+
41+
f = NonlinearFunction(brusselator_2d_loop;jac_prototype=float.(jac_sparsity))
42+
prob_brusselator_2d = NonlinearProblem(f,u0,p)
43+
sol = solve(prob_brusselator_2d, NewtonRaphson())

0 commit comments

Comments
 (0)