/usr/share/doc/libsundials-serial-dev/examples/ida/fcmix_serial/fidaRoberts_dns-updated.f is in libsundials-serial-dev 2.5.0-3+b3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | c ----------------------------------------------------------------
c $Revision: 1.3 $
c $Date: 2010/12/01 23:04:14 $
c ----------------------------------------------------------------
c This simple example problem for FIDA, due to Robertson, is from
c chemical kinetics, and consists of the following three equations:
c
c dy1/dt = -.04*y1 + 1.e4*y2*y3
c dy2/dt = .04*y1 - 1.e4*y2*y3 - 3.e7*y2**2
c 0 = y1 + y2 + y3 - 1
c
c on the interval from t = 0.0 to t = 4.e10, with initial
c conditions: y1 = 1, y2 = y3 = 0.
c
c While integrating the system, we also employ the rootfinding feature
c to find the points at which y1 = 1.e-4 or at which y3 = 0.01.
c
c The problem is solved using a dense linear solver, with a
c user-supplied Jacobian. Output is printed at
c t = .4, 4, 40, ..., 4e10.
c ----------------------------------------------------------------
c
program fidaRoberts_dns
c
implicit none
c
integer*4 ier, ierroot, info(2)
integer*8 iout(25), ipar
double precision rout(10), rpar
c
integer*4 iatol, nout, jout, itask
integer*4 nst, kused, hused
integer*8 neq, i
double precision t0, t1, rtol, tout, tret
double precision y(3), yp(3), atol(3)
c
data nst/3/, kused/9/, hused/2/
c
c Initialize variables
c
neq = 3
nout = 12
rtol = 1.0d-4
t0 = 0.0d0
t1 = 0.4d0
iatol = 2
itask = 1
c
y(1) = 1.0d0
y(2) = 0.0d0
y(3) = 0.0d0
c
yp(1) = -0.04d0
yp(2) = 0.04d0
yp(3) = 0.0d0
c
atol(1) = 1.0d-6
atol(2) = 1.0d-10
atol(3) = 1.0d-6
c
c Initialize IDA vector environment
c
call fnvinits(2, neq, ier)
if (ier .ne. 0) then
write(6,10) ier
10 format(///' SUNDIALS_ERROR: FNVINITS returned IER = ', i5)
stop
endif
c
call fidamalloc(t0, y, yp, iatol, rtol, atol,
& iout, rout, ipar, rpar, ier)
if (ier .ne. 0) then
write(6,20) ier
20 format(///' SUNDIALS_ERROR: FIDAMALLOC returned IER = ', i5)
stop
endif
c
c Initialize rootfinding problem
call fidarootinit(2, ier)
if (ier .ne. 0) then
write(6,25) ier
25 format(///' SUNDIALS_ERROR: FIDAROOTINIT returned IER = ', i5)
call fidafree
stop
endif
c
c Attach dense linear solver
c
call fidadense(neq, ier)
call fidadensesetjac(1, ier)
c
c Print header
c
call prntintro(rtol, atol, y)
c
tout = t1
c
c
jout = 1
do while(jout .le. nout)
c
call fidasolve(tout, tret, y, yp, itask, ier)
c
write(6,40) tret, (y(i), i = 1,3), iout(nst), iout(kused),
& rout(hused)
40 format(e10.4, 3(1x,e12.4), i5, i3, e12.4)
c
if (ier .lt. 0) then
write(6,50) ier, iout(15)
50 format(///' SUNDIALS_ERROR: FIDASOLVE returned IER = ',i5,/,
1 ' Linear Solver returned IER = ',i5)
call fidarootfree
call fidafree
stop
endif
c
if (ier .eq. 2) then
call fidarootinfo(2, info, ierroot)
if (ierroot .lt. 0) then
write(6,55) ier
55 format(///' SUNDIALS_ERROR: FIDAROOTINFO returned IER = ',
1 i5)
call fidarootfree
call fidafree
stop
endif
write(6,60) (info(i), i = 1,2)
60 format(5x, 'Above is a root, INFO() = ', 2i3)
endif
c
if (ier .eq. 0) then
tout = tout * 10.0d0
jout = jout + 1
endif
c
ENDDO
c
c Print final statistics
c
call prntstats(iout)
c
c Free IDA memory
c
call fidarootfree
call fidafree
c
stop
end
c
c ==========
c
subroutine fidaresfun(tres, y, yp, res, ipar, rpar, reserr)
c
implicit none
c
integer*4 reserr
integer*8 ipar(*)
double precision tres, rpar(*)
double precision y(*), yp(*), res(*)
c
res(1) = -0.04d0*y(1)+1.0d4*y(2)*y(3)
res(2) = -res(1)-3.0d7*y(2)*y(2)-yp(2)
res(1) = res(1)-yp(1)
res(3) = y(1)+y(2)+y(3)-1.0d0
c
reserr = 0
c
return
end
c
c ==========
c
subroutine fidadjac(neq, t, y, yp, r, jac, cj, ewt, h,
1 ipar, rpar, wk1, wk2, wk3, djacerr)
c
implicit none
c
integer*8 neq
integer*8 ipar(*)
integer*4 djacerr
double precision t, h, cj, rpar(*)
double precision y(*), yp(*), r(*), ewt(*), jac(neq,neq)
double precision wk1(*), wk2(*), wk3(*)
c
jac(1,1) = -0.04d0-cj
jac(2,1) = 0.04d0
jac(3,1) = 1.0d0
jac(1,2) = 1.0d4*y(3)
jac(2,2) = -1.0d4*y(3)-6.0d7*y(2)-cj
jac(3,2) = 1.0d0
jac(1,3) = 1.0d4*y(2)
jac(2,3) = -1.0d4*y(2)
jac(3,3) = 1.0d0
c
djacerr = 0
return
end
c
c ==========
c
subroutine fidarootfn(t, y, yp, g, ipar, rpar, ier)
c Fortran routine for rootfinding
implicit none
c
INTEGER*8 ipar(*), ier
double precision t, y(*), yp(*), g(*), rpar(*)
c
g(1) = y(1) - 1.0d-4
g(2) = y(3) - 1.0d-2
ier = 0
return
end
c
c ==========
c
subroutine prntintro(rtol, atol, y)
c
implicit none
c
integer*8 i
double precision rtol, atol(*), y(*)
c
write(6,60) rtol, (atol(i), i = 1,3), (y(i), i = 1,3)
60 format(/'fidaRoberts_dns: Robertson kinetics DAE serial example',
& 'problem for IDA', /,' Three equation chemical',
& 'kinetics problem.', //,
& 'Tolerance parameters: rtol = ', e8.2,
& ' atol = ', 3(1x,e8.2), /,
& 'Initial conditions y0 = (', 3(1x,e8.2), ')', //,
& ' t y1 y2 y3 nst',
& ' k h')
c
return
end
c
c ==========
c
subroutine prntstats(iout)
c
implicit none
c
integer*8 iout(25)
integer*4 nst, reseval, jaceval, nni, ncf, netf, nge
c
data nst/3/, reseval/4/, jaceval/17/, nni/7/, netf/5/,
& ncf/6/, nge/12/
c
write(6,70) iout(nst), iout(reseval), iout(jaceval),
& iout(nni), iout(netf), iout(ncf), iout(nge)
70 format(/'Final Run Statistics:', //,
& 'Number of steps = ', i3, /,
& 'Number of residual evaluations = ', i3, /,
& 'Number of Jacobian evaluations = ', i3, /,
& 'Number of nonlinear iterations = ', i3, /,
& 'Number of error test failures = ', i3, /,
& 'Number of nonlinear conv. failures = ', i3, /,
& 'Number of root function evals. = ', i3)
c
return
end
|