ddeabm.f 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. *DECK DDEABM
  2. SUBROUTINE DDEABM (DF, NEQ, T, Y, TOUT, INFO, RTOL, ATOL, IDID,
  3. + RWORK, LRW, IWORK, LIW, RPAR, IPAR)
  4. C***BEGIN PROLOGUE DDEABM
  5. C***PURPOSE Solve an initial value problem in ordinary differential
  6. C equations using an Adams-Bashforth method.
  7. C***LIBRARY SLATEC (DEPAC)
  8. C***CATEGORY I1A1B
  9. C***TYPE DOUBLE PRECISION (DEABM-S, DDEABM-D)
  10. C***KEYWORDS ADAMS-BASHFORTH METHOD, DEPAC, INITIAL VALUE PROBLEMS,
  11. C ODE, ORDINARY DIFFERENTIAL EQUATIONS, PREDICTOR-CORRECTOR
  12. C***AUTHOR Shampine, L. F., (SNLA)
  13. C Watts, H. A., (SNLA)
  14. C***DESCRIPTION
  15. C
  16. C This is the Adams code in the package of differential equation
  17. C solvers DEPAC, consisting of the codes DDERKF, DDEABM, and DDEBDF.
  18. C Design of the package was by L. F. Shampine and H. A. Watts.
  19. C It is documented in
  20. C SAND79-2374 , DEPAC - Design of a User Oriented Package of ODE
  21. C Solvers.
  22. C DDEABM is a driver for a modification of the code ODE written by
  23. C L. F. Shampine and M. K. Gordon
  24. C Sandia Laboratories
  25. C Albuquerque, New Mexico 87185
  26. C
  27. C **********************************************************************
  28. C * ABSTRACT *
  29. C ************
  30. C
  31. C Subroutine DDEABM uses the Adams-Bashforth-Moulton
  32. C Predictor-Corrector formulas of orders one through twelve to
  33. C integrate a system of NEQ first order ordinary differential
  34. C equations of the form
  35. C DU/DX = DF(X,U)
  36. C when the vector Y(*) of initial values for U(*) at X=T is given.
  37. C The subroutine integrates from T to TOUT. It is easy to continue the
  38. C integration to get results at additional TOUT. This is the interval
  39. C mode of operation. It is also easy for the routine to return with
  40. C the solution at each intermediate step on the way to TOUT. This is
  41. C the intermediate-output mode of operation.
  42. C
  43. C DDEABM uses subprograms DDES, DSTEPS, DINTP, DHSTRT, DHVNRM,
  44. C D1MACH, and the error handling routine XERMSG. The only machine
  45. C dependent parameters to be assigned appear in D1MACH.
  46. C
  47. C **********************************************************************
  48. C * Description of The Arguments To DDEABM (An Overview) *
  49. C **********************************************************************
  50. C
  51. C The Parameters are
  52. C
  53. C DF -- This is the name of a subroutine which you provide to
  54. C define the differential equations.
  55. C
  56. C NEQ -- This is the number of (first order) differential
  57. C equations to be integrated.
  58. C
  59. C T -- This is a DOUBLE PRECISION value of the independent
  60. C variable.
  61. C
  62. C Y(*) -- This DOUBLE PRECISION array contains the solution
  63. C components at T.
  64. C
  65. C TOUT -- This is a DOUBLE PRECISION point at which a solution is
  66. C desired.
  67. C
  68. C INFO(*) -- The basic task of the code is to integrate the
  69. C differential equations from T to TOUT and return an
  70. C answer at TOUT. INFO(*) is an INTEGER array which is used
  71. C to communicate exactly how you want this task to be
  72. C carried out.
  73. C
  74. C RTOL, ATOL -- These DOUBLE PRECISION quantities represent
  75. C relative and absolute error tolerances which you
  76. C provide to indicate how accurately you wish the
  77. C solution to be computed. You may choose them to be
  78. C both scalars or else both vectors.
  79. C
  80. C IDID -- This scalar quantity is an indicator reporting what
  81. C the code did. You must monitor this INTEGER variable to
  82. C decide what action to take next.
  83. C
  84. C RWORK(*), LRW -- RWORK(*) is a DOUBLE PRECISION work array of
  85. C length LRW which provides the code with needed storage
  86. C space.
  87. C
  88. C IWORK(*), LIW -- IWORK(*) is an INTEGER work array of length LIW
  89. C which provides the code with needed storage space and an
  90. C across call flag.
  91. C
  92. C RPAR, IPAR -- These are DOUBLE PRECISION and INTEGER parameter
  93. C arrays which you can use for communication between your
  94. C calling program and the DF subroutine.
  95. C
  96. C Quantities which are used as input items are
  97. C NEQ, T, Y(*), TOUT, INFO(*),
  98. C RTOL, ATOL, RWORK(1), LRW and LIW.
  99. C
  100. C Quantities which may be altered by the code are
  101. C T, Y(*), INFO(1), RTOL, ATOL,
  102. C IDID, RWORK(*) and IWORK(*).
  103. C
  104. C **********************************************************************
  105. C * INPUT -- What To Do On The First Call To DDEABM *
  106. C **********************************************************************
  107. C
  108. C The first call of the code is defined to be the start of each new
  109. C problem. Read through the descriptions of all the following items,
  110. C provide sufficient storage space for designated arrays, set
  111. C appropriate variables for the initialization of the problem, and
  112. C give information about how you want the problem to be solved.
  113. C
  114. C
  115. C DF -- Provide a subroutine of the form
  116. C DF(X,U,UPRIME,RPAR,IPAR)
  117. C to define the system of first order differential equations
  118. C which is to be solved. For the given values of X and the
  119. C vector U(*)=(U(1),U(2),...,U(NEQ)) , the subroutine must
  120. C evaluate the NEQ components of the system of differential
  121. C equations DU/DX=DF(X,U) and store the derivatives in the
  122. C array UPRIME(*), that is, UPRIME(I) = * DU(I)/DX * for
  123. C equations I=1,...,NEQ.
  124. C
  125. C Subroutine DF must NOT alter X or U(*). You must declare
  126. C the name df in an external statement in your program that
  127. C calls DDEABM. You must dimension U and UPRIME in DF.
  128. C
  129. C RPAR and IPAR are DOUBLE PRECISION and INTEGER parameter
  130. C arrays which you can use for communication between your
  131. C calling program and subroutine DF. They are not used or
  132. C altered by DDEABM. If you do not need RPAR or IPAR,
  133. C ignore these parameters by treating them as dummy
  134. C arguments. If you do choose to use them, dimension them in
  135. C your calling program and in DF as arrays of appropriate
  136. C length.
  137. C
  138. C NEQ -- Set it to the number of differential equations.
  139. C (NEQ .GE. 1)
  140. C
  141. C T -- Set it to the initial point of the integration.
  142. C You must use a program variable for T because the code
  143. C changes its value.
  144. C
  145. C Y(*) -- Set this vector to the initial values of the NEQ solution
  146. C components at the initial point. You must dimension Y at
  147. C least NEQ in your calling program.
  148. C
  149. C TOUT -- Set it to the first point at which a solution
  150. C is desired. You can take TOUT = T, in which case the code
  151. C will evaluate the derivative of the solution at T and
  152. C return. Integration either forward in T (TOUT .GT. T) or
  153. C backward in T (TOUT .LT. T) is permitted.
  154. C
  155. C The code advances the solution from T to TOUT using
  156. C step sizes which are automatically selected so as to
  157. C achieve the desired accuracy. If you wish, the code will
  158. C return with the solution and its derivative following
  159. C each intermediate step (intermediate-output mode) so that
  160. C you can monitor them, but you still must provide TOUT in
  161. C accord with the basic aim of the code.
  162. C
  163. C The first step taken by the code is a critical one
  164. C because it must reflect how fast the solution changes near
  165. C the initial point. The code automatically selects an
  166. C initial step size which is practically always suitable for
  167. C the problem. By using the fact that the code will not step
  168. C past TOUT in the first step, you could, if necessary,
  169. C restrict the length of the initial step size.
  170. C
  171. C For some problems it may not be permissible to integrate
  172. C past a point TSTOP because a discontinuity occurs there
  173. C or the solution or its derivative is not defined beyond
  174. C TSTOP. When you have declared a TSTOP point (see INFO(4)
  175. C and RWORK(1)), you have told the code not to integrate
  176. C past TSTOP. In this case any TOUT beyond TSTOP is invalid
  177. C input.
  178. C
  179. C INFO(*) -- Use the INFO array to give the code more details about
  180. C how you want your problem solved. This array should be
  181. C dimensioned of length 15 to accommodate other members of
  182. C DEPAC or possible future extensions, though DDEABM uses
  183. C only the first four entries. You must respond to all of
  184. C the following items which are arranged as questions. The
  185. C simplest use of the code corresponds to answering all
  186. C questions as YES ,i.e. setting ALL entries of INFO to 0.
  187. C
  188. C INFO(1) -- This parameter enables the code to initialize
  189. C itself. You must set it to indicate the start of every
  190. C new problem.
  191. C
  192. C **** Is this the first call for this problem ...
  193. C YES -- set INFO(1) = 0
  194. C NO -- not applicable here.
  195. C See below for continuation calls. ****
  196. C
  197. C INFO(2) -- How much accuracy you want of your solution
  198. C is specified by the error tolerances RTOL and ATOL.
  199. C The simplest use is to take them both to be scalars.
  200. C To obtain more flexibility, they can both be vectors.
  201. C The code must be told your choice.
  202. C
  203. C **** Are both error tolerances RTOL, ATOL scalars ...
  204. C YES -- set INFO(2) = 0
  205. C and input scalars for both RTOL and ATOL
  206. C NO -- set INFO(2) = 1
  207. C and input arrays for both RTOL and ATOL ****
  208. C
  209. C INFO(3) -- The code integrates from T in the direction
  210. C of TOUT by steps. If you wish, it will return the
  211. C computed solution and derivative at the next
  212. C intermediate step (the intermediate-output mode) or
  213. C TOUT, whichever comes first. This is a good way to
  214. C proceed if you want to see the behavior of the solution.
  215. C If you must have solutions at a great many specific
  216. C TOUT points, this code will compute them efficiently.
  217. C
  218. C **** Do you want the solution only at
  219. C TOUT (and not at the next intermediate step) ...
  220. C YES -- set INFO(3) = 0
  221. C NO -- set INFO(3) = 1 ****
  222. C
  223. C INFO(4) -- To handle solutions at a great many specific
  224. C values TOUT efficiently, this code may integrate past
  225. C TOUT and interpolate to obtain the result at TOUT.
  226. C Sometimes it is not possible to integrate beyond some
  227. C point TSTOP because the equation changes there or it is
  228. C not defined past TSTOP. Then you must tell the code
  229. C not to go past.
  230. C
  231. C **** Can the integration be carried out without any
  232. C Restrictions on the independent variable T ...
  233. C YES -- set INFO(4)=0
  234. C NO -- set INFO(4)=1
  235. C and define the stopping point TSTOP by
  236. C setting RWORK(1)=TSTOP ****
  237. C
  238. C RTOL, ATOL -- You must assign relative (RTOL) and absolute (ATOL)
  239. C error tolerances to tell the code how accurately you want
  240. C the solution to be computed. They must be defined as
  241. C program variables because the code may change them. You
  242. C have two choices --
  243. C Both RTOL and ATOL are scalars. (INFO(2)=0)
  244. C Both RTOL and ATOL are vectors. (INFO(2)=1)
  245. C In either case all components must be non-negative.
  246. C
  247. C The tolerances are used by the code in a local error test
  248. C at each step which requires roughly that
  249. C ABS(LOCAL ERROR) .LE. RTOL*ABS(Y)+ATOL
  250. C for each vector component.
  251. C (More specifically, a Euclidean norm is used to measure
  252. C the size of vectors, and the error test uses the magnitude
  253. C of the solution at the beginning of the step.)
  254. C
  255. C The true (global) error is the difference between the true
  256. C solution of the initial value problem and the computed
  257. C approximation. Practically all present day codes,
  258. C including this one, control the local error at each step
  259. C and do not even attempt to control the global error
  260. C directly. Roughly speaking, they produce a solution Y(T)
  261. C which satisfies the differential equations with a
  262. C residual R(T), DY(T)/DT = DF(T,Y(T)) + R(T) ,
  263. C and, almost always, R(T) is bounded by the error
  264. C tolerances. Usually, but not always, the true accuracy of
  265. C the computed Y is comparable to the error tolerances. This
  266. C code will usually, but not always, deliver a more accurate
  267. C solution if you reduce the tolerances and integrate again.
  268. C By comparing two such solutions you can get a fairly
  269. C reliable idea of the true error in the solution at the
  270. C bigger tolerances.
  271. C
  272. C Setting ATOL=0.D0 results in a pure relative error test on
  273. C that component. Setting RTOL=0. results in a pure absolute
  274. C error test on that component. A mixed test with non-zero
  275. C RTOL and ATOL corresponds roughly to a relative error
  276. C test when the solution component is much bigger than ATOL
  277. C and to an absolute error test when the solution component
  278. C is smaller than the threshold ATOL.
  279. C
  280. C Proper selection of the absolute error control parameters
  281. C ATOL requires you to have some idea of the scale of the
  282. C solution components. To acquire this information may mean
  283. C that you will have to solve the problem more than once. In
  284. C the absence of scale information, you should ask for some
  285. C relative accuracy in all the components (by setting RTOL
  286. C values non-zero) and perhaps impose extremely small
  287. C absolute error tolerances to protect against the danger of
  288. C a solution component becoming zero.
  289. C
  290. C The code will not attempt to compute a solution at an
  291. C accuracy unreasonable for the machine being used. It will
  292. C advise you if you ask for too much accuracy and inform
  293. C you as to the maximum accuracy it believes possible.
  294. C
  295. C RWORK(*) -- Dimension this DOUBLE PRECISION work array of length
  296. C LRW in your calling program.
  297. C
  298. C RWORK(1) -- If you have set INFO(4)=0, you can ignore this
  299. C optional input parameter. Otherwise you must define a
  300. C stopping point TSTOP by setting RWORK(1) = TSTOP.
  301. C (for some problems it may not be permissible to integrate
  302. C past a point TSTOP because a discontinuity occurs there
  303. C or the solution or its derivative is not defined beyond
  304. C TSTOP.)
  305. C
  306. C LRW -- Set it to the declared length of the RWORK array.
  307. C You must have LRW .GE. 130+21*NEQ
  308. C
  309. C IWORK(*) -- Dimension this INTEGER work array of length LIW in
  310. C your calling program.
  311. C
  312. C LIW -- Set it to the declared length of the IWORK array.
  313. C You must have LIW .GE. 51
  314. C
  315. C RPAR, IPAR -- These are parameter arrays, of DOUBLE PRECISION and
  316. C INTEGER type, respectively. You can use them for
  317. C communication between your program that calls DDEABM and
  318. C the DF subroutine. They are not used or altered by
  319. C DDEABM. If you do not need RPAR or IPAR, ignore these
  320. C parameters by treating them as dummy arguments. If you do
  321. C choose to use them, dimension them in your calling program
  322. C and in DF as arrays of appropriate length.
  323. C
  324. C **********************************************************************
  325. C * OUTPUT -- After Any Return From DDEABM *
  326. C **********************************************************************
  327. C
  328. C The principal aim of the code is to return a computed solution at
  329. C TOUT, although it is also possible to obtain intermediate results
  330. C along the way. To find out whether the code achieved its goal
  331. C or if the integration process was interrupted before the task was
  332. C completed, you must check the IDID parameter.
  333. C
  334. C
  335. C T -- The solution was successfully advanced to the
  336. C output value of T.
  337. C
  338. C Y(*) -- Contains the computed solution approximation at T.
  339. C You may also be interested in the approximate derivative
  340. C of the solution at T. It is contained in
  341. C RWORK(21),...,RWORK(20+NEQ).
  342. C
  343. C IDID -- Reports what the code did
  344. C
  345. C *** Task Completed ***
  346. C Reported by positive values of IDID
  347. C
  348. C IDID = 1 -- A step was successfully taken in the
  349. C intermediate-output mode. The code has not
  350. C yet reached TOUT.
  351. C
  352. C IDID = 2 -- The integration to TOUT was successfully
  353. C completed (T=TOUT) by stepping exactly to TOUT.
  354. C
  355. C IDID = 3 -- The integration to TOUT was successfully
  356. C completed (T=TOUT) by stepping past TOUT.
  357. C Y(*) is obtained by interpolation.
  358. C
  359. C *** Task Interrupted ***
  360. C Reported by negative values of IDID
  361. C
  362. C IDID = -1 -- A large amount of work has been expended.
  363. C (500 steps attempted)
  364. C
  365. C IDID = -2 -- The error tolerances are too stringent.
  366. C
  367. C IDID = -3 -- The local error test cannot be satisfied
  368. C because you specified a zero component in ATOL
  369. C and the corresponding computed solution
  370. C component is zero. Thus, a pure relative error
  371. C test is impossible for this component.
  372. C
  373. C IDID = -4 -- The problem appears to be stiff.
  374. C
  375. C IDID = -5,-6,-7,..,-32 -- Not applicable for this code
  376. C but used by other members of DEPAC or possible
  377. C future extensions.
  378. C
  379. C *** Task Terminated ***
  380. C Reported by the value of IDID=-33
  381. C
  382. C IDID = -33 -- The code has encountered trouble from which
  383. C it cannot recover. A message is printed
  384. C explaining the trouble and control is returned
  385. C to the calling program. For example, this occurs
  386. C when invalid input is detected.
  387. C
  388. C RTOL, ATOL -- These quantities remain unchanged except when
  389. C IDID = -2. In this case, the error tolerances have been
  390. C increased by the code to values which are estimated to be
  391. C appropriate for continuing the integration. However, the
  392. C reported solution at T was obtained using the input values
  393. C of RTOL and ATOL.
  394. C
  395. C RWORK, IWORK -- Contain information which is usually of no
  396. C interest to the user but necessary for subsequent calls.
  397. C However, you may find use for
  398. C
  399. C RWORK(11)--which contains the step size H to be
  400. C attempted on the next step.
  401. C
  402. C RWORK(12)--if the tolerances have been increased by the
  403. C code (IDID = -2) , they were multiplied by the
  404. C value in RWORK(12).
  405. C
  406. C RWORK(13)--Which contains the current value of the
  407. C independent variable, i.e. the farthest point
  408. C integration has reached. This will be different
  409. C from T only when interpolation has been
  410. C performed (IDID=3).
  411. C
  412. C RWORK(20+I)--Which contains the approximate derivative
  413. C of the solution component Y(I). In DDEABM, it
  414. C is obtained by calling subroutine DF to
  415. C evaluate the differential equation using T and
  416. C Y(*) when IDID=1 or 2, and by interpolation
  417. C when IDID=3.
  418. C
  419. C **********************************************************************
  420. C * INPUT -- What To Do To Continue The Integration *
  421. C * (calls after the first) *
  422. C **********************************************************************
  423. C
  424. C This code is organized so that subsequent calls to continue the
  425. C integration involve little (if any) additional effort on your
  426. C part. You must monitor the IDID parameter in order to determine
  427. C what to do next.
  428. C
  429. C Recalling that the principal task of the code is to integrate
  430. C from T to TOUT (the interval mode), usually all you will need
  431. C to do is specify a new TOUT upon reaching the current TOUT.
  432. C
  433. C Do not alter any quantity not specifically permitted below,
  434. C in particular do not alter NEQ, T, Y(*), RWORK(*), IWORK(*) or
  435. C the differential equation in subroutine DF. Any such alteration
  436. C constitutes a new problem and must be treated as such, i.e.
  437. C you must start afresh.
  438. C
  439. C You cannot change from vector to scalar error control or vice
  440. C versa (INFO(2)) but you can change the size of the entries of
  441. C RTOL, ATOL. Increasing a tolerance makes the equation easier
  442. C to integrate. Decreasing a tolerance will make the equation
  443. C harder to integrate and should generally be avoided.
  444. C
  445. C You can switch from the intermediate-output mode to the
  446. C interval mode (INFO(3)) or vice versa at any time.
  447. C
  448. C If it has been necessary to prevent the integration from going
  449. C past a point TSTOP (INFO(4), RWORK(1)), keep in mind that the
  450. C code will not integrate to any TOUT beyond the currently
  451. C specified TSTOP. Once TSTOP has been reached you must change
  452. C the value of TSTOP or set INFO(4)=0. You may change INFO(4)
  453. C or TSTOP at any time but you must supply the value of TSTOP in
  454. C RWORK(1) whenever you set INFO(4)=1.
  455. C
  456. C The parameter INFO(1) is used by the code to indicate the
  457. C beginning of a new problem and to indicate whether integration
  458. C is to be continued. You must input the value INFO(1) = 0
  459. C when starting a new problem. You must input the value
  460. C INFO(1) = 1 if you wish to continue after an interrupted task.
  461. C Do not set INFO(1) = 0 on a continuation call unless you
  462. C want the code to restart at the current T.
  463. C
  464. C *** Following A Completed Task ***
  465. C If
  466. C IDID = 1, call the code again to continue the integration
  467. C another step in the direction of TOUT.
  468. C
  469. C IDID = 2 or 3, define a new TOUT and call the code again.
  470. C TOUT must be different from T. You cannot change
  471. C the direction of integration without restarting.
  472. C
  473. C *** Following An Interrupted Task ***
  474. C To show the code that you realize the task was
  475. C interrupted and that you want to continue, you
  476. C must take appropriate action and reset INFO(1) = 1
  477. C If
  478. C IDID = -1, the code has attempted 500 steps.
  479. C If you want to continue, set INFO(1) = 1 and
  480. C call the code again. An additional 500 steps
  481. C will be allowed.
  482. C
  483. C IDID = -2, the error tolerances RTOL, ATOL have been
  484. C increased to values the code estimates appropriate
  485. C for continuing. You may want to change them
  486. C yourself. If you are sure you want to continue
  487. C with relaxed error tolerances, set INFO(1)=1 and
  488. C call the code again.
  489. C
  490. C IDID = -3, a solution component is zero and you set the
  491. C corresponding component of ATOL to zero. If you
  492. C are sure you want to continue, you must first
  493. C alter the error criterion to use positive values
  494. C for those components of ATOL corresponding to zero
  495. C solution components, then set INFO(1)=1 and call
  496. C the code again.
  497. C
  498. C IDID = -4, the problem appears to be stiff. It is very
  499. C inefficient to solve such problems with DDEABM.
  500. C The code DDEBDF in DEPAC handles this task
  501. C efficiently. If you are absolutely sure you want
  502. C to continue with DDEABM, set INFO(1)=1 and call
  503. C the code again.
  504. C
  505. C IDID = -5,-6,-7,..,-32 --- cannot occur with this code
  506. C but used by other members of DEPAC or possible
  507. C future extensions.
  508. C
  509. C *** Following A Terminated Task ***
  510. C If
  511. C IDID = -33, you cannot continue the solution of this
  512. C problem. An attempt to do so will result in your
  513. C run being terminated.
  514. C
  515. C **********************************************************************
  516. C *Long Description:
  517. C
  518. C **********************************************************************
  519. C * DEPAC Package Overview *
  520. C **********************************************************************
  521. C
  522. C .... You have a choice of three differential equation solvers from
  523. C .... DEPAC. The following brief descriptions are meant to aid you in
  524. C .... choosing the most appropriate code for your problem.
  525. C
  526. C .... DDERKF is a fifth order Runge-Kutta code. It is the simplest of
  527. C .... the three choices, both algorithmically and in the use of the
  528. C .... code. DDERKF is primarily designed to solve non-stiff and
  529. C .... mildly stiff differential equations when derivative evaluations
  530. C .... are not expensive. It should generally not be used to get high
  531. C .... accuracy results nor answers at a great many specific points.
  532. C .... Because DDERKF has very low overhead costs, it will usually
  533. C .... result in the least expensive integration when solving
  534. C .... problems requiring a modest amount of accuracy and having
  535. C .... equations that are not costly to evaluate. DDERKF attempts to
  536. C .... discover when it is not suitable for the task posed.
  537. C
  538. C .... DDEABM is a variable order (one through twelve) Adams code.
  539. C .... Its complexity lies somewhere between that of DDERKF and
  540. C .... DDEBDF. DDEABM is primarily designed to solve non-stiff and
  541. C .... mildly stiff differential equations when derivative evaluations
  542. C .... are expensive, high accuracy results are needed or answers at
  543. C .... many specific points are required. DDEABM attempts to discover
  544. C .... when it is not suitable for the task posed.
  545. C
  546. C .... DDEBDF is a variable order (one through five) backward
  547. C .... differentiation formula code. it is the most complicated of
  548. C .... the three choices. DDEBDF is primarily designed to solve stiff
  549. C .... differential equations at crude to moderate tolerances.
  550. C .... If the problem is very stiff at all, DDERKF and DDEABM will be
  551. C .... quite inefficient compared to DDEBDF. However, DDEBDF will be
  552. C .... inefficient compared to DDERKF and DDEABM on non-stiff problems
  553. C .... because it uses much more storage, has a much larger overhead,
  554. C .... and the low order formulas will not give high accuracies
  555. C .... efficiently.
  556. C
  557. C .... The concept of stiffness cannot be described in a few words.
  558. C .... If you do not know the problem to be stiff, try either DDERKF
  559. C .... or DDEABM. Both of these codes will inform you of stiffness
  560. C .... when the cost of solving such problems becomes important.
  561. C
  562. C *********************************************************************
  563. C
  564. C***REFERENCES L. F. Shampine and H. A. Watts, DEPAC - design of a user
  565. C oriented package of ODE solvers, Report SAND79-2374,
  566. C Sandia Laboratories, 1979.
  567. C***ROUTINES CALLED DDES, XERMSG
  568. C***REVISION HISTORY (YYMMDD)
  569. C 820301 DATE WRITTEN
  570. C 890531 Changed all specific intrinsics to generic. (WRB)
  571. C 890831 Modified array declarations. (WRB)
  572. C 891006 Cosmetic changes to prologue. (WRB)
  573. C 891024 Changed references from DVNORM to DHVNRM. (WRB)
  574. C 891024 REVISION DATE from Version 3.2
  575. C 891214 Prologue converted to Version 4.0 format. (BAB)
  576. C 900510 Convert XERRWV calls to XERMSG calls. (RWC)
  577. C 920501 Reformatted the REFERENCES section. (WRB)
  578. C***END PROLOGUE DDEABM
  579. C
  580. INTEGER IALPHA, IBETA, IDELSN, IDID, IFOURU, IG, IHOLD,
  581. 1 INFO, IP, IPAR, IPHI, IPSI, ISIG, ITOLD, ITSTAR, ITWOU,
  582. 2 IV, IW, IWORK, IWT, IYP, IYPOUT, IYY, LIW, LRW, NEQ
  583. DOUBLE PRECISION ATOL, RPAR, RTOL, RWORK, T, TOUT, Y
  584. LOGICAL START,PHASE1,NORND,STIFF,INTOUT
  585. C
  586. DIMENSION Y(*),INFO(15),RTOL(*),ATOL(*),RWORK(*),IWORK(*),
  587. 1 RPAR(*),IPAR(*)
  588. C
  589. CHARACTER*8 XERN1
  590. CHARACTER*16 XERN3
  591. C
  592. EXTERNAL DF
  593. C
  594. C CHECK FOR AN APPARENT INFINITE LOOP
  595. C
  596. C***FIRST EXECUTABLE STATEMENT DDEABM
  597. IF ( INFO(1) .EQ. 0 ) IWORK(LIW) = 0
  598. IF (IWORK(LIW) .GE. 5) THEN
  599. IF (T .EQ. RWORK(21 + NEQ)) THEN
  600. WRITE (XERN3, '(1PE15.6)') T
  601. CALL XERMSG ('SLATEC', 'DDEABM',
  602. * 'AN APPARENT INFINITE LOOP HAS BEEN DETECTED.$$' //
  603. * 'YOU HAVE MADE REPEATED CALLS AT T = ' // XERN3 //
  604. * ' AND THE INTEGRATION HAS NOT ADVANCED. CHECK THE ' //
  605. * 'WAY YOU HAVE SET PARAMETERS FOR THE CALL TO THE ' //
  606. * 'CODE, PARTICULARLY INFO(1).', 13, 2)
  607. RETURN
  608. ENDIF
  609. ENDIF
  610. C
  611. C CHECK LRW AND LIW FOR SUFFICIENT STORAGE ALLOCATION
  612. C
  613. IDID=0
  614. IF (LRW .LT. 130+21*NEQ) THEN
  615. WRITE (XERN1, '(I8)') LRW
  616. CALL XERMSG ('SLATEC', 'DDEABM', 'THE LENGTH OF THE RWORK ' //
  617. * 'ARRAY MUST BE AT LEAST 130 + 21*NEQ.$$' //
  618. * 'YOU HAVE CALLED THE CODE WITH LRW = ' // XERN1, 1, 1)
  619. IDID=-33
  620. ENDIF
  621. C
  622. IF (LIW .LT. 51) THEN
  623. WRITE (XERN1, '(I8)') LIW
  624. CALL XERMSG ('SLATEC', 'DDEABM', 'THE LENGTH OF THE IWORK ' //
  625. * 'ARRAY MUST BE AT LEAST 51.$$YOU HAVE CALLED THE CODE ' //
  626. * 'WITH LIW = ' // XERN1, 2, 1)
  627. IDID=-33
  628. ENDIF
  629. C
  630. C COMPUTE THE INDICES FOR THE ARRAYS TO BE STORED IN THE WORK ARRAY
  631. C
  632. IYPOUT = 21
  633. ITSTAR = NEQ + 21
  634. IYP = 1 + ITSTAR
  635. IYY = NEQ + IYP
  636. IWT = NEQ + IYY
  637. IP = NEQ + IWT
  638. IPHI = NEQ + IP
  639. IALPHA = (NEQ*16) + IPHI
  640. IBETA = 12 + IALPHA
  641. IPSI = 12 + IBETA
  642. IV = 12 + IPSI
  643. IW = 12 + IV
  644. ISIG = 12 + IW
  645. IG = 13 + ISIG
  646. IGI = 13 + IG
  647. IXOLD = 11 + IGI
  648. IHOLD = 1 + IXOLD
  649. ITOLD = 1 + IHOLD
  650. IDELSN = 1 + ITOLD
  651. ITWOU = 1 + IDELSN
  652. IFOURU = 1 + ITWOU
  653. C
  654. RWORK(ITSTAR) = T
  655. IF (INFO(1) .EQ. 0) GO TO 50
  656. START = IWORK(21) .NE. (-1)
  657. PHASE1 = IWORK(22) .NE. (-1)
  658. NORND = IWORK(23) .NE. (-1)
  659. STIFF = IWORK(24) .NE. (-1)
  660. INTOUT = IWORK(25) .NE. (-1)
  661. C
  662. 50 CALL DDES(DF,NEQ,T,Y,TOUT,INFO,RTOL,ATOL,IDID,RWORK(IYPOUT),
  663. 1 RWORK(IYP),RWORK(IYY),RWORK(IWT),RWORK(IP),RWORK(IPHI),
  664. 2 RWORK(IALPHA),RWORK(IBETA),RWORK(IPSI),RWORK(IV),
  665. 3 RWORK(IW),RWORK(ISIG),RWORK(IG),RWORK(IGI),RWORK(11),
  666. 4 RWORK(12),RWORK(13),RWORK(IXOLD),RWORK(IHOLD),
  667. 5 RWORK(ITOLD),RWORK(IDELSN),RWORK(1),RWORK(ITWOU),
  668. 5 RWORK(IFOURU),START,PHASE1,NORND,STIFF,INTOUT,IWORK(26),
  669. 6 IWORK(27),IWORK(28),IWORK(29),IWORK(30),IWORK(31),
  670. 7 IWORK(32),IWORK(33),IWORK(34),IWORK(35),IWORK(45),
  671. 8 RPAR,IPAR)
  672. C
  673. IWORK(21) = -1
  674. IF (START) IWORK(21) = 1
  675. IWORK(22) = -1
  676. IF (PHASE1) IWORK(22) = 1
  677. IWORK(23) = -1
  678. IF (NORND) IWORK(23) = 1
  679. IWORK(24) = -1
  680. IF (STIFF) IWORK(24) = 1
  681. IWORK(25) = -1
  682. IF (INTOUT) IWORK(25) = 1
  683. C
  684. IF (IDID .NE. (-2)) IWORK(LIW) = IWORK(LIW) + 1
  685. IF (T .NE. RWORK(ITSTAR)) IWORK(LIW) = 0
  686. C
  687. RETURN
  688. END