Skip to content

Commit 6b8b656

Browse files
committed
update examples and add to the Pkg.test()
1 parent 2a7284a commit 6b8b656

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

examples/cvode_Roberts_dns.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function f(t, y, ydot, user_data)
99
ydot[1] = -0.04*y[1] + 1.0e4*y[2]*y[3]
1010
ydot[3] = 3.0e7*y[2]*y[2]
1111
ydot[2] = -ydot[1] - ydot[3]
12-
return Int32(0)
12+
return Cint(0)
1313
end
1414

1515

@@ -20,7 +20,7 @@ function g(t, y, gout, user_data)
2020
gout = Sundials.asarray(gout, (2,))
2121
gout[1] = y[1] - 0.0001
2222
gout[2] = y[3] - 0.01
23-
return Int32(0)
23+
return Cint(0)
2424
end
2525

2626
## Jacobian routine. Compute J(t,y) = df/dy.
@@ -89,21 +89,21 @@ abstol = [1e-8, 1e-14, 1e-6]
8989
cvode_mem = Sundials.CVodeCreate(Sundials.CV_BDF, Sundials.CV_NEWTON)
9090
flag = Sundials.CVodeInit(cvode_mem, f, t0, y)
9191
flag = Sundials.CVodeSVtolerances(cvode_mem, reltol, abstol)
92-
flag = Sundials.CVodeRootInit(cvode_mem, 2, g)
92+
flag = Sundials.CVodeRootInit(cvode_mem, Cint(2), g)
9393
flag = Sundials.CVDense(cvode_mem, neq)
9494
## flag = Sundials.CVDlsSetDenseJacFn(cvode_mem, Jac) # works, but clunky, see above
9595

9696
iout = 0
9797
tout = t1
9898

99-
rootsfound = round(Int32,[0, 0])
99+
rootsfound = zeros(Cint, 2)
100100
t = [t0]
101101

102102
while true
103103
flag = Sundials.CVode(cvode_mem, tout, y, t, Sundials.CV_NORMAL)
104104
println("T = ", tout, ", Y = ", y)
105105
if flag == Sundials.CV_ROOT_RETURN
106-
flagr = Sundials.CVodeGetRootInfo(cvode_mem, pointer(rootsfound))
106+
flagr = Sundials.CVodeGetRootInfo(cvode_mem, rootsfound)
107107
println("roots = ", rootsfound)
108108
end
109109
if flag == Sundials.CV_SUCCESS

examples/ida_Roberts_dns.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function resrob(tres, yy, yp, rr, user_data)
4343
rval[2] = -rval[1] - 3.0e7*yval[2]*yval[2] - ypval[2]
4444
rval[1] -= ypval[1]
4545
rval[3] = yval[1] + yval[2] + yval[3] - 1.0
46-
return Int32(0) # indicates normal return
46+
return Cint(0) # indicates normal return
4747
end
4848

4949
## Root function routine. Compute functions g_i(t,y) for i = 0,1.
@@ -52,7 +52,7 @@ function grob(t, yy, yp, gout, user_data)
5252
gval = Sundials.asarray(gout, (2,))
5353
gval[1] = yval[1] - 0.0001
5454
gval[2] = yval[3] - 0.01
55-
return Int32(0) # indicates normal return
55+
return Cint(0) # indicates normal return
5656
end
5757

5858
## Define the Jacobian function. BROKEN - JJ is wrong
@@ -69,7 +69,7 @@ function jacrob(Neq, tt, cj, yy, yp, resvec,
6969
JJ[1,3] = 1.0e4*yval[2]
7070
JJ[2,3] = -1.0e4*yval[2]
7171
JJ[3,3] = 1.0
72-
return Int32(0) # indicates normal return
72+
return Cint(0) # indicates normal return
7373
end
7474

7575
neq = 3
@@ -86,7 +86,7 @@ retval = Sundials.IDAInit(mem, resrob, t0, yy, yp)
8686
retval = Sundials.IDASVtolerances(mem, rtol, avtol)
8787

8888
## Call IDARootInit to specify the root function grob with 2 components
89-
retval = Sundials.IDARootInit(mem, 2, grob)
89+
retval = Sundials.IDARootInit(mem, Cint(2), grob)
9090

9191
## Call IDADense and set up the linear solver.
9292
retval = Sundials.IDADense(mem, neq)
@@ -95,13 +95,13 @@ retval = Sundials.IDADense(mem, neq)
9595
iout = 0
9696
tout = tout1
9797
tret = [1.0]
98-
rootsfound = round(Int32,[0, 0])
98+
rootsfound = zeros(Cint, 2)
9999

100100
while true
101101
retval = Sundials.IDASolve(mem, tout, tret, yy, yp, Sundials.IDA_NORMAL)
102102
println("T = ", tout, ", Y = ", yy)
103103
if retval == Sundials.IDA_ROOT_RETURN
104-
retvalr = Sundials.IDAGetRootInfo(mem, pointer(rootsfound))
104+
retvalr = Sundials.IDAGetRootInfo(mem, rootsfound)
105105
println("roots = ", rootsfound)
106106
end
107107
if retval == Sundials.IDA_SUCCESS

examples/kinsol_mkinTest.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Adapted from sundialsTB/kinsol/examples_ser/mkinTest_nds.m
2-
2+
33
## %mkinTest_dns - KINSOL example problem (serial, dense)
44
## % Simple test problem for the Dense linear solver in KINSOL
55
## % This example solves the system
@@ -18,7 +18,7 @@ function sysfn(y_in, fy_in, a_in)
1818
fy = Sundials.asarray(fy_in)
1919
fy[1] = y[1]^2 + y[2]^2 - 1.0
2020
fy[2] = y[2] - y[1]^2
21-
return Int32(0) # indicates normal return
21+
return Cint(0) # indicates normal return
2222
end
2323

2424
## Initialize problem
@@ -32,7 +32,7 @@ flag = Sundials.KINInit(kmem, sysfn, y)
3232
flag = Sundials.KINDense(kmem, neq)
3333
## Solve problem
3434
scale = ones(neq)
35-
strategy = 1 # KIN_LINESEARCH
35+
strategy = Sundials.KIN_LINESEARCH
3636
flag = Sundials.KINSol(kmem,
3737
y,
3838
strategy,
@@ -43,7 +43,3 @@ println("Solution: ", y)
4343
residual = ones(2)
4444
sysfn(y, residual, [1,2])
4545
println("Residual: ", residual)
46-
47-
Sundials.KINFree([kmem])
48-
49-

test/runtests.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ using Sundials
22
using Base.Test
33

44
# run cvode example
5-
println("== start cvode example")
5+
println("== start cvode Roberts example (simplified)")
66
include("../examples/cvode_Roberts_simplified.jl")
77

88
println("result at t=$(t[end]):")
99
println(res[end,:], "\n")
1010

11+
println("== start cvode Roberts example")
12+
include("../examples/cvode_Roberts_dns.jl")
1113

1214
# run ida examples
13-
println("== start ida_Roberts example")
15+
println("== start ida_Roberts example (simplified)")
1416
include("../examples/ida_Roberts_simplified.jl")
1517

18+
println("== start ida_Roberts example")
19+
include("../examples/ida_Roberts_dns.jl")
20+
1621
println("result at t=$(t[end]):")
1722
println(yout[end,:], "\n")
1823

@@ -23,7 +28,7 @@ println("result at t=$(t[end]):")
2328
println(yout[end,:], "\n")
2429

2530
# run kinsol example
26-
println("== start kinsol example")
31+
println("== start kinsol example (simplified)")
2732
include("../examples/kinsol_mkin_simplified.jl")
2833

2934
println("solution:")
@@ -33,4 +38,7 @@ sysfn(res, residual)
3338
println("residual:")
3439
println(residual, "\n")
3540

41+
println("== start kinsol example")
42+
include("../examples/kinsol_mkinTest.jl")
43+
3644
@test abs(minimum(residual)) < 1e-5

0 commit comments

Comments
 (0)