dderkf.f 33 KB

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