Skip to content

Commit e23780e

Browse files
format
1 parent 9d57ee3 commit e23780e

File tree

7 files changed

+232
-120
lines changed

7 files changed

+232
-120
lines changed

lib/libsundials_api.jl

Lines changed: 211 additions & 103 deletions
Large diffs are not rendered by default.

src/nvector_wrapper.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ Base.convert(::Type{NVector}, nv::N_Vector) = NVector(nv)
6363
Base.convert(::Type{Vector{realtype}}, nv::NVector) = nv.v
6464
Base.convert(::Type{Vector}, nv::NVector) = nv.v
6565

66-
6766
"""
6867
Base.cconvert(::Type{N_Vector}, v::Vector{realtype}) -> NVector
6968
Base.unsafe_convert(::Type{N_Vector}, nv::NVector) -> N_Vector
@@ -79,7 +78,6 @@ Conversion happens in two steps within ccall:
7978
Base.cconvert(::Type{N_Vector}, v::Vector{realtype}) = convert(NVector, v) # will just return v if v is an NVector
8079
Base.unsafe_convert(::Type{N_Vector}, nv::NVector) = nv.n_v
8180

82-
8381
Base.similar(nv::NVector) = NVector(similar(nv.v))
8482

8583
nvlength(x::N_Vector) = unsafe_load(unsafe_load(convert(Ptr{Ptr{Clong}}, x)))

test/arkstep_Roberts_dns.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ function f(t, y_nv, ydot_nv, user_data)
1111
return Sundials.ARK_SUCCESS
1212
end
1313

14-
f_C = @cfunction(f, Cint, (Sundials.realtype, Sundials.N_Vector, Sundials.N_Vector, Ptr{Cvoid}))
14+
f_C = @cfunction(f, Cint,
15+
(Sundials.realtype, Sundials.N_Vector, Sundials.N_Vector, Ptr{Cvoid}))
1516

1617
neq = 3
1718

test/common_interface/precs.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ u0 = vec(init_brusselator_2d(xyd_brusselator))
5050
prob_ode_brusselator_2d = ODEProblem(brusselator_2d_vec,
5151
u0, (0.0, 11.5), p)
5252

53-
5453
# find Jacobian sparsity pattern
5554
u0_st = SparsityTracing.create_advec(u0)
5655
du_st = similar(u0_st)
@@ -60,19 +59,19 @@ const W = I - 1.0 * jaccache
6059

6160
# setup sparse AD for Jacobian
6261
colors = SparseDiffTools.matrix_colors(jaccache)
63-
const jaccache_fc = SparseDiffTools.ForwardColorJacCache(
64-
nothing, # don't use f to create unique Tag
65-
u0,
66-
colorvec=colors,
67-
sparsity=jaccache,
68-
)
62+
const jaccache_fc = SparseDiffTools.ForwardColorJacCache(nothing, # don't use f to create unique Tag
63+
u0,
64+
colorvec = colors,
65+
sparsity = jaccache)
6966

7067
prectmp = ilu(W; τ = 50.0)
7168
const preccache = Ref(prectmp)
7269

7370
function psetupilu(p, t, u, du, jok, jcurPtr, gamma)
7471
if jok
75-
SparseDiffTools.forwarddiff_color_jacobian!(jaccache, (y, x) -> brusselator_2d_vec(y, x, p, t), u, jaccache_fc)
72+
SparseDiffTools.forwarddiff_color_jacobian!(jaccache,
73+
(y, x) -> brusselator_2d_vec(y, x, p, t),
74+
u, jaccache_fc)
7675
jcurPtr[] = true
7776

7877
# W = I - gamma*J
@@ -97,7 +96,9 @@ prectmp2 = AlgebraicMultigrid.aspreconditioner(AlgebraicMultigrid.ruge_stuben(W;
9796
const preccache2 = Ref(prectmp2)
9897
function psetupamg(p, t, u, du, jok, jcurPtr, gamma)
9998
if jok
100-
SparseDiffTools.forwarddiff_color_jacobian!(jaccache, (y, x) -> brusselator_2d_vec(y, x, p, t), u, jaccache_fc)
99+
SparseDiffTools.forwarddiff_color_jacobian!(jaccache,
100+
(y, x) -> brusselator_2d_vec(y, x, p, t),
101+
u, jaccache_fc)
101102
jcurPtr[] = true
102103

103104
# W = I - gamma*J

test/cvode_Roberts_dns.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function g(t, y_nv, gout_ptr, user_data)
2222
end
2323

2424
g_C = @cfunction(g, Cint,
25-
(Sundials.realtype, Sundials.N_Vector, Ptr{Sundials.realtype}, Ptr{Cvoid}))
25+
(Sundials.realtype, Sundials.N_Vector, Ptr{Sundials.realtype}, Ptr{Cvoid}))
2626

2727
## Jacobian routine. Compute J(t,y) = df/dy.
2828
# broken -- needs a wrapper from Sundials._DlsMat to Matrix and Jac user function wrapper
@@ -64,7 +64,8 @@ function getcfunrob(userfun::T) where {T}
6464
(Sundials.realtype, Sundials.N_Vector, Sundials.N_Vector, Ref{T}))
6565
end
6666

67-
Sundials.@checkflag Sundials.CVodeInit(cvode_mem, getcfunrob(userfun), t1, convert(Sundials.NVector, y0))
67+
Sundials.@checkflag Sundials.CVodeInit(cvode_mem, getcfunrob(userfun), t1,
68+
convert(Sundials.NVector, y0))
6869
Sundials.@checkflag Sundials.CVodeInit(cvode_mem, getcfunrob(userfun), t0, y0)
6970
Sundials.@checkflag Sundials.CVodeSVtolerances(cvode_mem, reltol, abstol)
7071
Sundials.@checkflag Sundials.CVodeRootInit(cvode_mem, 2, g_C)

test/erkstep_nonlin.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ function f(t, y, ydot, user_data)
4545
return Sundials.ARK_SUCCESS
4646
end
4747

48-
f_C = @cfunction(f, Cint, (Sundials.realtype, Sundials.N_Vector, Sundials.N_Vector, Ptr{Cvoid}))
48+
f_C = @cfunction(f, Cint,
49+
(Sundials.realtype, Sundials.N_Vector, Sundials.N_Vector, Ptr{Cvoid}))
4950

5051
mem_ptr = Sundials.ERKStepCreate(f_C, t0, y0)
5152
erkStep_mem = Sundials.Handle(mem_ptr)

test/ida_Roberts_dns.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ function resrob(tres, yy_nv, yp_nv, rr_nv, user_data)
4545
end
4646

4747
resrob_C = @cfunction(resrob, Cint,
48-
(Sundials.realtype, Sundials.N_Vector, Sundials.N_Vector, Sundials.N_Vector, Ptr{Cvoid}))
48+
(Sundials.realtype, Sundials.N_Vector, Sundials.N_Vector,
49+
Sundials.N_Vector, Ptr{Cvoid}))
4950

5051
## Root function routine. Compute functions g_i(t,y) for i = 0,1.
5152
function grob(t, yy_nv, yp_nv, gout_ptr, user_data)
@@ -57,7 +58,8 @@ function grob(t, yy_nv, yp_nv, gout_ptr, user_data)
5758
end
5859

5960
grob_C = @cfunction(grob, Cint,
60-
(Sundials.realtype, Sundials.N_Vector, Sundials.N_Vector, Ptr{Sundials.realtype}, Ptr{Cvoid}))
61+
(Sundials.realtype, Sundials.N_Vector, Sundials.N_Vector,
62+
Ptr{Sundials.realtype}, Ptr{Cvoid}))
6163

6264
## Define the Jacobian function. BROKEN - JJ is wrong
6365
function jacrob(Neq, tt, cj, yy, yp, resvec, JJ, user_data, tempv1, tempv2, tempv3)

0 commit comments

Comments
 (0)