derkf.f 33 KB

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