ddebdf.f 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. *DECK DDEBDF
  2. SUBROUTINE DDEBDF (DF, NEQ, T, Y, TOUT, INFO, RTOL, ATOL, IDID,
  3. + RWORK, LRW, IWORK, LIW, RPAR, IPAR, DJAC)
  4. C***BEGIN PROLOGUE DDEBDF
  5. C***PURPOSE Solve an initial value problem in ordinary differential
  6. C equations using backward differentiation formulas. It is
  7. C intended primarily for stiff problems.
  8. C***LIBRARY SLATEC (DEPAC)
  9. C***CATEGORY I1A2
  10. C***TYPE DOUBLE PRECISION (DEBDF-S, DDEBDF-D)
  11. C***KEYWORDS BACKWARD DIFFERENTIATION FORMULAS, DEPAC,
  12. C INITIAL VALUE PROBLEMS, ODE,
  13. C ORDINARY DIFFERENTIAL EQUATIONS, STIFF
  14. C***AUTHOR Shampine, L. F., (SNLA)
  15. C Watts, H. A., (SNLA)
  16. C***DESCRIPTION
  17. C
  18. C This is the backward differentiation code in the package of
  19. C differential equation solvers DEPAC, consisting of the codes
  20. C DDERKF, DDEABM, and DDEBDF. Design of the package was by
  21. C L. F. Shampine and H. A. Watts. It is documented in
  22. C SAND-79-2374 , DEPAC - Design of a User Oriented Package of ODE
  23. C Solvers.
  24. C DDEBDF is a driver for a modification of the code LSODE written by
  25. C A. C. Hindmarsh
  26. C Lawrence Livermore Laboratory
  27. C Livermore, California 94550
  28. C
  29. C **********************************************************************
  30. C ** DEPAC PACKAGE OVERVIEW **
  31. C **********************************************************************
  32. C
  33. C You have a choice of three differential equation solvers from
  34. C DEPAC. The following brief descriptions are meant to aid you
  35. C in choosing the most appropriate code for your problem.
  36. C
  37. C DDERKF is a fifth order Runge-Kutta code. It is the simplest of
  38. C the three choices, both algorithmically and in the use of the
  39. C code. DDERKF is primarily designed to solve non-stiff and mild-
  40. C ly stiff differential equations when derivative evaluations are
  41. C not expensive. It should generally not be used to get high
  42. C accuracy results nor answers at a great many specific points.
  43. C Because DDERKF has very low overhead costs, it will usually
  44. C result in the least expensive integration when solving
  45. C problems requiring a modest amount of accuracy and having
  46. C equations that are not costly to evaluate. DDERKF attempts to
  47. C discover when it is not suitable for the task posed.
  48. C
  49. C DDEABM is a variable order (one through twelve) Adams code. Its
  50. C complexity lies somewhere between that of DDERKF and DDEBDF.
  51. C DDEABM is primarily designed to solve non-stiff and mildly
  52. C stiff differential equations when derivative evaluations are
  53. C expensive, high accuracy results are needed or answers at
  54. C many specific points are required. DDEABM attempts to discover
  55. C when it is not suitable for the task posed.
  56. C
  57. C DDEBDF is a variable order (one through five) backward
  58. C differentiation formula code. It is the most complicated of
  59. C the three choices. DDEBDF is primarily designed to solve stiff
  60. C differential equations at crude to moderate tolerances.
  61. C If the problem is very stiff at all, DDERKF and DDEABM will be
  62. C quite inefficient compared to DDEBDF. However, DDEBDF will be
  63. C inefficient compared to DDERKF and DDEABM on non-stiff problems
  64. C because it uses much more storage, has a much larger overhead,
  65. C and the low order formulas will not give high accuracies
  66. C efficiently.
  67. C
  68. C The concept of stiffness cannot be described in a few words.
  69. C If you do not know the problem to be stiff, try either DDERKF
  70. C or DDEABM. Both of these codes will inform you of stiffness
  71. C when the cost of solving such problems becomes important.
  72. C
  73. C **********************************************************************
  74. C ** ABSTRACT **
  75. C **********************************************************************
  76. C
  77. C Subroutine DDEBDF uses the backward differentiation formulas of
  78. C orders one through five to integrate a system of NEQ first order
  79. C ordinary differential equations of the form
  80. C DU/DX = DF(X,U)
  81. C when the vector Y(*) of initial values for U(*) at X=T is given.
  82. C The subroutine integrates from T to TOUT. It is easy to continue the
  83. C integration to get results at additional TOUT. This is the interval
  84. C mode of operation. It is also easy for the routine to return with
  85. C the solution at each intermediate step on the way to TOUT. This is
  86. C the intermediate-output mode of operation.
  87. C
  88. C **********************************************************************
  89. C * Description of The Arguments To DDEBDF (An Overview) *
  90. C **********************************************************************
  91. C
  92. C The Parameters are:
  93. C
  94. C DF -- This is the name of a subroutine which you provide to
  95. C define the differential equations.
  96. C
  97. C NEQ -- This is the number of (first order) differential
  98. C equations to be integrated.
  99. C
  100. C T -- This is a DOUBLE PRECISION value of the independent
  101. C variable.
  102. C
  103. C Y(*) -- This DOUBLE PRECISION array contains the solution
  104. C components at T.
  105. C
  106. C TOUT -- This is a DOUBLE PRECISION point at which a solution is
  107. C 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 DOUBLE PRECISION quantities
  116. C represent relative and absolute error tolerances which you
  117. C provide to indicate how accurately you wish the solution
  118. C to be computed. You may choose them to be both scalars
  119. C or else both vectors.
  120. C
  121. C IDID -- This scalar quantity is an indicator reporting what
  122. C the code did. You must monitor this INTEGER variable to
  123. C decide what action to take next.
  124. C
  125. C RWORK(*), LRW -- RWORK(*) is a DOUBLE PRECISION work array of
  126. C length LRW which provides the code with needed storage
  127. C space.
  128. C
  129. C IWORK(*), LIW -- IWORK(*) is an INTEGER work array of length LIW
  130. C which provides the code with needed storage space and an
  131. C across call flag.
  132. C
  133. C RPAR, IPAR -- These are DOUBLE PRECISION and INTEGER parameter
  134. C arrays which you can use for communication between your
  135. C calling program and the DF subroutine (and the DJAC
  136. C subroutine).
  137. C
  138. C DJAC -- This is the name of a subroutine which you may choose to
  139. C provide for defining the Jacobian matrix of partial
  140. C derivatives DF/DU.
  141. C
  142. C Quantities which are used as input items are
  143. C NEQ, T, Y(*), TOUT, INFO(*),
  144. C RTOL, ATOL, RWORK(1), LRW,
  145. C IWORK(1), IWORK(2), and LIW.
  146. C
  147. C Quantities which may be altered by the code are
  148. C T, Y(*), INFO(1), RTOL, ATOL,
  149. C IDID, RWORK(*) and IWORK(*).
  150. C
  151. C **********************************************************************
  152. C * INPUT -- What To Do On The First Call To DDEBDF *
  153. C **********************************************************************
  154. C
  155. C The first call of the code is defined to be the start of each new
  156. C problem. Read through the descriptions of all the following items,
  157. C provide sufficient storage space for designated arrays, set
  158. C appropriate variables for the initialization of the problem, and
  159. C give information about how you want the problem to be solved.
  160. C
  161. C
  162. C DF -- Provide a subroutine of the form
  163. C DF(X,U,UPRIME,RPAR,IPAR)
  164. C to define the system of first order differential equations
  165. C which is to be solved. For the given values of X and the
  166. C vector U(*)=(U(1),U(2),...,U(NEQ)) , the subroutine must
  167. C evaluate the NEQ components of the system of differential
  168. C equations DU/DX=DF(X,U) and store the derivatives in the
  169. C array UPRIME(*), that is, UPRIME(I) = * DU(I)/DX * for
  170. C equations I=1,...,NEQ.
  171. C
  172. C Subroutine DF must not alter X or U(*). You must declare
  173. C the name DF in an external statement in your program that
  174. C calls DDEBDF. You must dimension U and UPRIME in DF.
  175. C
  176. C RPAR and IPAR are DOUBLE PRECISION and INTEGER parameter
  177. C arrays which you can use for communication between your
  178. C calling program and subroutine DF. They are not used or
  179. C altered by DDEBDF. If you do not need RPAR or IPAR,
  180. C ignore these parameters by treating them as dummy
  181. C arguments. If you do choose to use them, dimension them in
  182. C your calling program and in DF as arrays of appropriate
  183. C length.
  184. C
  185. C NEQ -- Set it to the number of differential equations.
  186. C (NEQ .GE. 1)
  187. C
  188. C T -- Set it to the initial point of the integration.
  189. C You must use a program variable for T because the code
  190. C changes its value.
  191. C
  192. C Y(*) -- Set this vector to the initial values of the NEQ solution
  193. C components at the initial point. You must dimension Y at
  194. C least NEQ in your calling program.
  195. C
  196. C TOUT -- Set it to the first point at which a solution is desired.
  197. C You can take TOUT = T, in which case the code
  198. C will evaluate the derivative of the solution at T and
  199. C return. Integration either forward in T (TOUT .GT. T)
  200. C or backward in T (TOUT .LT. T) is permitted.
  201. C
  202. C The code advances the solution from T to TOUT using
  203. C step sizes which are automatically selected so as to
  204. C achieve the desired accuracy. If you wish, the code will
  205. C return with the solution and its derivative following
  206. C each intermediate step (intermediate-output mode) so that
  207. C you can monitor them, but you still must provide TOUT in
  208. C accord with the basic aim of the code.
  209. C
  210. C The first step taken by the code is a critical one
  211. C because it must reflect how fast the solution changes near
  212. C the initial point. The code automatically selects an
  213. C initial step size which is practically always suitable for
  214. C the problem. By using the fact that the code will not
  215. C step past TOUT in the first step, you could, if necessary,
  216. C restrict the length of the initial step size.
  217. C
  218. C For some problems it may not be permissible to integrate
  219. C past a point TSTOP because a discontinuity occurs there
  220. C or the solution or its derivative is not defined beyond
  221. C TSTOP. When you have declared a TSTOP point (see INFO(4)
  222. C and RWORK(1)), you have told the code not to integrate
  223. C past TSTOP. In this case any TOUT beyond TSTOP is invalid
  224. C input.
  225. C
  226. C INFO(*) -- Use the INFO array to give the code more details about
  227. C how you want your problem solved. This array should be
  228. C dimensioned of length 15 to accommodate other members of
  229. C DEPAC or possible future extensions, though DDEBDF uses
  230. C only the first six entries. You must respond to all of
  231. C the following items which are arranged as questions. The
  232. C simplest use of the code corresponds to answering all
  233. C questions as YES ,i.e. setting all entries of INFO to 0.
  234. C
  235. C INFO(1) -- This parameter enables the code to initialize
  236. C itself. You must set it to indicate the start of every
  237. C new problem.
  238. C
  239. C **** Is this the first call for this problem ...
  240. C YES -- Set INFO(1) = 0
  241. C NO -- Not applicable here.
  242. C See below for continuation calls. ****
  243. C
  244. C INFO(2) -- How much accuracy you want of your solution
  245. C is specified by the error tolerances RTOL and ATOL.
  246. C The simplest use is to take them both to be scalars.
  247. C To obtain more flexibility, they can both be vectors.
  248. C The code must be told your choice.
  249. C
  250. C **** Are both error tolerances RTOL, ATOL scalars ...
  251. C YES -- Set INFO(2) = 0
  252. C and input scalars for both RTOL and ATOL
  253. C NO -- Set INFO(2) = 1
  254. C and input arrays for both RTOL and ATOL ****
  255. C
  256. C INFO(3) -- The code integrates from T in the direction
  257. C of TOUT by steps. If you wish, it will return the
  258. C computed solution and derivative at the next
  259. C intermediate step (the intermediate-output mode) or
  260. C TOUT, whichever comes first. This is a good way to
  261. C proceed if you want to see the behavior of the solution.
  262. C If you must have solutions at a great many specific
  263. C TOUT points, this code will compute them efficiently.
  264. C
  265. C **** Do you want the solution only at
  266. C TOUT (and NOT at the next intermediate step) ...
  267. C YES -- Set INFO(3) = 0
  268. C NO -- Set INFO(3) = 1 ****
  269. C
  270. C INFO(4) -- To handle solutions at a great many specific
  271. C values TOUT efficiently, this code may integrate past
  272. C TOUT and interpolate to obtain the result at TOUT.
  273. C Sometimes it is not possible to integrate beyond some
  274. C point TSTOP because the equation changes there or it is
  275. C not defined past TSTOP. Then you must tell the code
  276. C not to go past.
  277. C
  278. C **** Can the integration be carried out without any
  279. C restrictions on the independent variable T ...
  280. C YES -- Set INFO(4)=0
  281. C NO -- Set INFO(4)=1
  282. C and define the stopping point TSTOP by
  283. C setting RWORK(1)=TSTOP ****
  284. C
  285. C INFO(5) -- To solve stiff problems it is necessary to use the
  286. C Jacobian matrix of partial derivatives of the system
  287. C of differential equations. If you do not provide a
  288. C subroutine to evaluate it analytically (see the
  289. C description of the item DJAC in the call list), it will
  290. C be approximated by numerical differencing in this code.
  291. C Although it is less trouble for you to have the code
  292. C compute partial derivatives by numerical differencing,
  293. C the solution will be more reliable if you provide the
  294. C derivatives via DJAC. Sometimes numerical differencing
  295. C is cheaper than evaluating derivatives in DJAC and
  296. C sometimes it is not - this depends on your problem.
  297. C
  298. C If your problem is linear, i.e. has the form
  299. C DU/DX = DF(X,U) = J(X)*U + G(X) for some matrix J(X)
  300. C and vector G(X), the Jacobian matrix DF/DU = J(X).
  301. C Since you must provide a subroutine to evaluate DF(X,U)
  302. C analytically, it is little extra trouble to provide
  303. C subroutine DJAC for evaluating J(X) analytically.
  304. C Furthermore, in such cases, numerical differencing is
  305. C much more expensive than analytic evaluation.
  306. C
  307. C **** Do you want the code to evaluate the partial
  308. C derivatives automatically by numerical differences ...
  309. C YES -- Set INFO(5)=0
  310. C NO -- Set INFO(5)=1
  311. C and provide subroutine DJAC for evaluating the
  312. C Jacobian matrix ****
  313. C
  314. C INFO(6) -- DDEBDF will perform much better if the Jacobian
  315. C matrix is banded and the code is told this. In this
  316. C case, the storage needed will be greatly reduced,
  317. C numerical differencing will be performed more cheaply,
  318. C and a number of important algorithms will execute much
  319. C faster. The differential equation is said to have
  320. C half-bandwidths ML (lower) and MU (upper) if equation I
  321. C involves only unknowns Y(J) with
  322. C I-ML .LE. J .LE. I+MU
  323. C for all I=1,2,...,NEQ. Thus, ML and MU are the widths
  324. C of the lower and upper parts of the band, respectively,
  325. C with the main diagonal being excluded. If you do not
  326. C indicate that the equation has a banded Jacobian,
  327. C the code works with a full matrix of NEQ**2 elements
  328. C (stored in the conventional way). Computations with
  329. C banded matrices cost less time and storage than with
  330. C full matrices if 2*ML+MU .LT. NEQ. If you tell the
  331. C code that the Jacobian matrix has a banded structure and
  332. C you want to provide subroutine DJAC to compute the
  333. C partial derivatives, then you must be careful to store
  334. C the elements of the Jacobian matrix in the special form
  335. C indicated in the description of DJAC.
  336. C
  337. C **** Do you want to solve the problem using a full
  338. C (dense) Jacobian matrix (and not a special banded
  339. C structure) ...
  340. C YES -- Set INFO(6)=0
  341. C NO -- Set INFO(6)=1
  342. C and provide the lower (ML) and upper (MU)
  343. C bandwidths by setting
  344. C IWORK(1)=ML
  345. C IWORK(2)=MU ****
  346. C
  347. C RTOL, ATOL -- You must assign relative (RTOL) and absolute (ATOL)
  348. C error tolerances to tell the code how accurately you want
  349. C the solution to be computed. They must be defined as
  350. C program variables because the code may change them. You
  351. C have two choices --
  352. C Both RTOL and ATOL are scalars. (INFO(2)=0)
  353. C Both RTOL and ATOL are vectors. (INFO(2)=1)
  354. C In either case all components must be non-negative.
  355. C
  356. C The tolerances are used by the code in a local error test
  357. C at each step which requires roughly that
  358. C ABS(LOCAL ERROR) .LE. RTOL*ABS(Y)+ATOL
  359. C for each vector component.
  360. C (More specifically, a root-mean-square norm is used to
  361. C measure the size of vectors, and the error test uses the
  362. C magnitude of the solution at the beginning of the step.)
  363. C
  364. C The true (global) error is the difference between the true
  365. C solution of the initial value problem and the computed
  366. C approximation. Practically all present day codes,
  367. C including this one, control the local error at each step
  368. C and do not even attempt to control the global error
  369. C directly. Roughly speaking, they produce a solution Y(T)
  370. C which satisfies the differential equations with a
  371. C residual R(T), DY(T)/DT = DF(T,Y(T)) + R(T) ,
  372. C and, almost always, R(T) is bounded by the error
  373. C tolerances. Usually, but not always, the true accuracy of
  374. C the computed Y is comparable to the error tolerances. This
  375. C code will usually, but not always, deliver a more accurate
  376. C solution if you reduce the tolerances and integrate again.
  377. C By comparing two such solutions you can get a fairly
  378. C reliable idea of the true error in the solution at the
  379. C bigger tolerances.
  380. C
  381. C Setting ATOL=0. results in a pure relative error test on
  382. C that component. Setting RTOL=0. results in a pure abso-
  383. C lute error test on that component. A mixed test with non-
  384. C zero RTOL and ATOL corresponds roughly to a relative error
  385. C test when the solution component is much bigger than ATOL
  386. C and to an absolute error test when the solution component
  387. C is smaller than the threshold ATOL.
  388. C
  389. C Proper selection of the absolute error control parameters
  390. C ATOL requires you to have some idea of the scale of the
  391. C solution components. To acquire this information may mean
  392. C that you will have to solve the problem more than once. In
  393. C the absence of scale information, you should ask for some
  394. C relative accuracy in all the components (by setting RTOL
  395. C values non-zero) and perhaps impose extremely small
  396. C absolute error tolerances to protect against the danger of
  397. C a solution component becoming zero.
  398. C
  399. C The code will not attempt to compute a solution at an
  400. C accuracy unreasonable for the machine being used. It will
  401. C advise you if you ask for too much accuracy and inform
  402. C you as to the maximum accuracy it believes possible.
  403. C
  404. C RWORK(*) -- Dimension this DOUBLE PRECISION work array of length
  405. C LRW in your calling program.
  406. C
  407. C RWORK(1) -- If you have set INFO(4)=0, you can ignore this
  408. C optional input parameter. Otherwise you must define a
  409. C stopping point TSTOP by setting RWORK(1) = TSTOP.
  410. C (For some problems it may not be permissible to integrate
  411. C past a point TSTOP because a discontinuity occurs there
  412. C or the solution or its derivative is not defined beyond
  413. C TSTOP.)
  414. C
  415. C LRW -- Set it to the declared length of the RWORK array.
  416. C You must have
  417. C LRW .GE. 250+10*NEQ+NEQ**2
  418. C for the full (dense) Jacobian case (when INFO(6)=0), or
  419. C LRW .GE. 250+10*NEQ+(2*ML+MU+1)*NEQ
  420. C for the banded Jacobian case (when INFO(6)=1).
  421. C
  422. C IWORK(*) -- Dimension this INTEGER work array of length LIW in
  423. C your calling program.
  424. C
  425. C IWORK(1), IWORK(2) -- If you have set INFO(6)=0, you can ignore
  426. C these optional input parameters. Otherwise you must define
  427. C the half-bandwidths ML (lower) and MU (upper) of the
  428. C Jacobian matrix by setting IWORK(1) = ML and
  429. C IWORK(2) = MU. (The code will work with a full matrix
  430. C of NEQ**2 elements unless it is told that the problem has
  431. C a banded Jacobian, in which case the code will work with
  432. C a matrix containing at most (2*ML+MU+1)*NEQ elements.)
  433. C
  434. C LIW -- Set it to the declared length of the IWORK array.
  435. C You must have LIW .GE. 56+NEQ.
  436. C
  437. C RPAR, IPAR -- These are parameter arrays, of DOUBLE PRECISION and
  438. C INTEGER type, respectively. You can use them for
  439. C communication between your program that calls DDEBDF and
  440. C the DF subroutine (and the DJAC subroutine). They are not
  441. C used or altered by DDEBDF. If you do not need RPAR or
  442. C IPAR, ignore these parameters by treating them as dummy
  443. C arguments. If you do choose to use them, dimension them in
  444. C your calling program and in DF (and in DJAC) as arrays of
  445. C appropriate length.
  446. C
  447. C DJAC -- If you have set INFO(5)=0, you can ignore this parameter
  448. C by treating it as a dummy argument. (For some compilers
  449. C you may have to write a dummy subroutine named DJAC in
  450. C order to avoid problems associated with missing external
  451. C routine names.) Otherwise, you must provide a subroutine
  452. C of the form
  453. C DJAC(X,U,PD,NROWPD,RPAR,IPAR)
  454. C to define the Jacobian matrix of partial derivatives DF/DU
  455. C of the system of differential equations DU/DX = DF(X,U).
  456. C For the given values of X and the vector
  457. C U(*)=(U(1),U(2),...,U(NEQ)), the subroutine must evaluate
  458. C the non-zero partial derivatives DF(I)/DU(J) for each
  459. C differential equation I=1,...,NEQ and each solution
  460. C component J=1,...,NEQ , and store these values in the
  461. C matrix PD. The elements of PD are set to zero before each
  462. C call to DJAC so only non-zero elements need to be defined.
  463. C
  464. C Subroutine DJAC must not alter X, U(*), or NROWPD. You
  465. C must declare the name DJAC in an external statement in
  466. C your program that calls DDEBDF. NROWPD is the row
  467. C dimension of the PD matrix and is assigned by the code.
  468. C Therefore you must dimension PD in DJAC according to
  469. C DIMENSION PD(NROWPD,1)
  470. C You must also dimension U in DJAC.
  471. C
  472. C The way you must store the elements into the PD matrix
  473. C depends on the structure of the Jacobian which you
  474. C indicated by INFO(6).
  475. C *** INFO(6)=0 -- Full (Dense) Jacobian ***
  476. C When you evaluate the (non-zero) partial derivative
  477. C of equation I with respect to variable J, you must
  478. C store it in PD according to
  479. C PD(I,J) = * DF(I)/DU(J) *
  480. C *** INFO(6)=1 -- Banded Jacobian with ML Lower and MU
  481. C Upper Diagonal Bands (refer to INFO(6) description of
  482. C ML and MU) ***
  483. C When you evaluate the (non-zero) partial derivative
  484. C of equation I with respect to variable J, you must
  485. C store it in PD according to
  486. C IROW = I - J + ML + MU + 1
  487. C PD(IROW,J) = * DF(I)/DU(J) *
  488. C
  489. C RPAR and IPAR are DOUBLE PRECISION and INTEGER parameter
  490. C arrays which you can use for communication between your
  491. C calling program and your Jacobian subroutine DJAC. They
  492. C are not altered by DDEBDF. If you do not need RPAR or
  493. C IPAR, ignore these parameters by treating them as dummy
  494. C arguments. If you do choose to use them, dimension them
  495. C in your calling program and in DJAC as arrays of
  496. C appropriate length.
  497. C
  498. C **********************************************************************
  499. C * OUTPUT -- After any return from DDEBDF *
  500. C **********************************************************************
  501. C
  502. C The principal aim of the code is to return a computed solution at
  503. C TOUT, although it is also possible to obtain intermediate results
  504. C along the way. To find out whether the code achieved its goal
  505. C or if the integration process was interrupted before the task was
  506. C completed, you must check the IDID parameter.
  507. C
  508. C
  509. C T -- The solution was successfully advanced to the
  510. C output value of T.
  511. C
  512. C Y(*) -- Contains the computed solution approximation at T.
  513. C You may also be interested in the approximate derivative
  514. C of the solution at T. It is contained in
  515. C RWORK(21),...,RWORK(20+NEQ).
  516. C
  517. C IDID -- Reports what the code did
  518. C
  519. C *** Task Completed ***
  520. C Reported by positive values of IDID
  521. C
  522. C IDID = 1 -- A step was successfully taken in the
  523. C intermediate-output mode. The code has not
  524. C yet reached TOUT.
  525. C
  526. C IDID = 2 -- The integration to TOUT was successfully
  527. C completed (T=TOUT) by stepping exactly to TOUT.
  528. C
  529. C IDID = 3 -- The integration to TOUT was successfully
  530. C completed (T=TOUT) by stepping past TOUT.
  531. C Y(*) is obtained by interpolation.
  532. C
  533. C *** Task Interrupted ***
  534. C Reported by negative values of IDID
  535. C
  536. C IDID = -1 -- A large amount of work has been expended.
  537. C (500 steps attempted)
  538. C
  539. C IDID = -2 -- The error tolerances are too stringent.
  540. C
  541. C IDID = -3 -- The local error test cannot be satisfied
  542. C because you specified a zero component in ATOL
  543. C and the corresponding computed solution
  544. C component is zero. Thus, a pure relative error
  545. C test is impossible for this component.
  546. C
  547. C IDID = -4,-5 -- Not applicable for this code but used
  548. C by other members of DEPAC.
  549. C
  550. C IDID = -6 -- DDEBDF had repeated convergence test failures
  551. C on the last attempted step.
  552. C
  553. C IDID = -7 -- DDEBDF had repeated error test failures on
  554. C the last attempted step.
  555. C
  556. C IDID = -8,..,-32 -- Not applicable for this code but
  557. C used by other members of DEPAC or possible
  558. C future extensions.
  559. C
  560. C *** Task Terminated ***
  561. C Reported by the value of IDID=-33
  562. C
  563. C IDID = -33 -- The code has encountered trouble from which
  564. C it cannot recover. A message is printed
  565. C explaining the trouble and control is returned
  566. C to the calling program. For example, this
  567. C occurs when invalid input is detected.
  568. C
  569. C RTOL, ATOL -- These quantities remain unchanged except when
  570. C IDID = -2. In this case, the error tolerances have been
  571. C increased by the code to values which are estimated to be
  572. C appropriate for continuing the integration. However, the
  573. C reported solution at T was obtained using the input values
  574. C of RTOL and ATOL.
  575. C
  576. C RWORK, IWORK -- Contain information which is usually of no
  577. C interest to the user but necessary for subsequent calls.
  578. C However, you may find use for
  579. C
  580. C RWORK(11)--which contains the step size H to be
  581. C attempted on the next step.
  582. C
  583. C RWORK(12)--If the tolerances have been increased by the
  584. C code (IDID = -2) , they were multiplied by the
  585. C value in RWORK(12).
  586. C
  587. C RWORK(13)--which contains the current value of the
  588. C independent variable, i.e. the farthest point
  589. C integration has reached. This will be
  590. C different from T only when interpolation has
  591. C been performed (IDID=3).
  592. C
  593. C RWORK(20+I)--which contains the approximate derivative
  594. C of the solution component Y(I). In DDEBDF, it
  595. C is never obtained by calling subroutine DF to
  596. C evaluate the differential equation using T and
  597. C Y(*), except at the initial point of
  598. C integration.
  599. C
  600. C **********************************************************************
  601. C ** INPUT -- What To Do To Continue The Integration **
  602. C ** (calls after the first) **
  603. C **********************************************************************
  604. C
  605. C This code is organized so that subsequent calls to continue the
  606. C integration involve little (if any) additional effort on your
  607. C part. You must monitor the IDID parameter in order to determine
  608. C what to do next.
  609. C
  610. C Recalling that the principal task of the code is to integrate
  611. C from T to TOUT (the interval mode), usually all you will need
  612. C to do is specify a new TOUT upon reaching the current TOUT.
  613. C
  614. C Do not alter any quantity not specifically permitted below,
  615. C in particular do not alter NEQ, T, Y(*), RWORK(*), IWORK(*) or
  616. C the differential equation in subroutine DF. Any such alteration
  617. C constitutes a new problem and must be treated as such, i.e.
  618. C you must start afresh.
  619. C
  620. C You cannot change from vector to scalar error control or vice
  621. C versa (INFO(2)) but you can change the size of the entries of
  622. C RTOL, ATOL. Increasing a tolerance makes the equation easier
  623. C to integrate. Decreasing a tolerance will make the equation
  624. C harder to integrate and should generally be avoided.
  625. C
  626. C You can switch from the intermediate-output mode to the
  627. C interval mode (INFO(3)) or vice versa at any time.
  628. C
  629. C If it has been necessary to prevent the integration from going
  630. C past a point TSTOP (INFO(4), RWORK(1)), keep in mind that the
  631. C code will not integrate to any TOUT beyond the currently
  632. C specified TSTOP. Once TSTOP has been reached you must change
  633. C the value of TSTOP or set INFO(4)=0. You may change INFO(4)
  634. C or TSTOP at any time but you must supply the value of TSTOP in
  635. C RWORK(1) whenever you set INFO(4)=1.
  636. C
  637. C Do not change INFO(5), INFO(6), IWORK(1), or IWORK(2)
  638. C unless you are going to restart the code.
  639. C
  640. C The parameter INFO(1) is used by the code to indicate the
  641. C beginning of a new problem and to indicate whether integration
  642. C is to be continued. You must input the value INFO(1) = 0
  643. C when starting a new problem. You must input the value
  644. C INFO(1) = 1 if you wish to continue after an interrupted task.
  645. C Do not set INFO(1) = 0 on a continuation call unless you
  646. C want the code to restart at the current T.
  647. C
  648. C *** Following a Completed Task ***
  649. C If
  650. C IDID = 1, call the code again to continue the integration
  651. C another step in the direction of TOUT.
  652. C
  653. C IDID = 2 or 3, define a new TOUT and call the code again.
  654. C TOUT must be different from T. You cannot change
  655. C the direction of integration without restarting.
  656. C
  657. C *** Following an Interrupted Task ***
  658. C To show the code that you realize the task was
  659. C interrupted and that you want to continue, you
  660. C must take appropriate action and reset INFO(1) = 1
  661. C If
  662. C IDID = -1, the code has attempted 500 steps.
  663. C If you want to continue, set INFO(1) = 1 and
  664. C call the code again. An additional 500 steps
  665. C will be allowed.
  666. C
  667. C IDID = -2, the error tolerances RTOL, ATOL have been
  668. C increased to values the code estimates appropriate
  669. C for continuing. You may want to change them
  670. C yourself. If you are sure you want to continue
  671. C with relaxed error tolerances, set INFO(1)=1 and
  672. C call the code again.
  673. C
  674. C IDID = -3, a solution component is zero and you set the
  675. C corresponding component of ATOL to zero. If you
  676. C are sure you want to continue, you must first
  677. C alter the error criterion to use positive values
  678. C for those components of ATOL corresponding to zero
  679. C solution components, then set INFO(1)=1 and call
  680. C the code again.
  681. C
  682. C IDID = -4,-5 --- cannot occur with this code but used
  683. C by other members of DEPAC.
  684. C
  685. C IDID = -6, repeated convergence test failures occurred
  686. C on the last attempted step in DDEBDF. An inaccu-
  687. C rate Jacobian may be the problem. If you are
  688. C absolutely certain you want to continue, restart
  689. C the integration at the current T by setting
  690. C INFO(1)=0 and call the code again.
  691. C
  692. C IDID = -7, repeated error test failures occurred on the
  693. C last attempted step in DDEBDF. A singularity in
  694. C the solution may be present. You should re-
  695. C examine the problem being solved. If you are
  696. C absolutely certain you want to continue, restart
  697. C the integration at the current T by setting
  698. C INFO(1)=0 and call the code again.
  699. C
  700. C IDID = -8,..,-32 --- cannot occur with this code but
  701. C used by other members of DDEPAC or possible future
  702. C extensions.
  703. C
  704. C *** Following a Terminated Task ***
  705. C If
  706. C IDID = -33, you cannot continue the solution of this
  707. C problem. An attempt to do so will result in your
  708. C run being terminated.
  709. C
  710. C **********************************************************************
  711. C
  712. C ***** Warning *****
  713. C
  714. C If DDEBDF is to be used in an overlay situation, you must save and
  715. C restore certain items used internally by DDEBDF (values in the
  716. C common block DDEBD1). This can be accomplished as follows.
  717. C
  718. C To save the necessary values upon return from DDEBDF, simply call
  719. C DSVCO(RWORK(22+NEQ),IWORK(21+NEQ)).
  720. C
  721. C To restore the necessary values before the next call to DDEBDF,
  722. C simply call DRSCO(RWORK(22+NEQ),IWORK(21+NEQ)).
  723. C
  724. C***REFERENCES L. F. Shampine and H. A. Watts, DEPAC - design of a user
  725. C oriented package of ODE solvers, Report SAND79-2374,
  726. C Sandia Laboratories, 1979.
  727. C***ROUTINES CALLED DLSOD, XERMSG
  728. C***COMMON BLOCKS DDEBD1
  729. C***REVISION HISTORY (YYMMDD)
  730. C 820301 DATE WRITTEN
  731. C 890831 Modified array declarations. (WRB)
  732. C 891024 Changed references from DVNORM to DHVNRM. (WRB)
  733. C 891024 REVISION DATE from Version 3.2
  734. C 891214 Prologue converted to Version 4.0 format. (BAB)
  735. C 900326 Removed duplicate information from DESCRIPTION section.
  736. C (WRB)
  737. C 900510 Convert XERRWV calls to XERMSG calls, make Prologue comments
  738. C consistent with DEBDF. (RWC)
  739. C 920501 Reformatted the REFERENCES section. (WRB)
  740. C***END PROLOGUE DDEBDF
  741. INTEGER IACOR, IBAND, IBEGIN, ICOMI, ICOMR, IDELSN, IDID, IER,
  742. 1 IEWT, IINOUT, IINTEG, IJAC, ILRW, INFO, INIT,
  743. 2 IOWNS, IPAR, IQUIT, ISAVF, ITOL, ITSTAR, ITSTOP, IWM,
  744. 3 IWORK, IYH, IYPOUT, JSTART, KFLAG, KSTEPS, L, LIW, LRW,
  745. 4 MAXORD, METH, MITER, ML, MU, N, NEQ, NFE, NJE, NQ, NQU,
  746. 5 NST
  747. DOUBLE PRECISION ATOL, EL0, H, HMIN, HMXI, HU, ROWNS, RPAR,
  748. 1 RTOL, RWORK, T, TN, TOLD, TOUT, UROUND, Y
  749. LOGICAL INTOUT
  750. CHARACTER*8 XERN1, XERN2
  751. CHARACTER*16 XERN3
  752. C
  753. DIMENSION Y(*),INFO(15),RTOL(*),ATOL(*),RWORK(*),IWORK(*),
  754. 1 RPAR(*),IPAR(*)
  755. C
  756. COMMON /DDEBD1/ TOLD,ROWNS(210),EL0,H,HMIN,HMXI,HU,TN,UROUND,
  757. 1 IQUIT,INIT,IYH,IEWT,IACOR,ISAVF,IWM,KSTEPS,IBEGIN,
  758. 2 ITOL,IINTEG,ITSTOP,IJAC,IBAND,IOWNS(6),IER,JSTART,
  759. 3 KFLAG,L,METH,MITER,MAXORD,N,NQ,NST,NFE,NJE,NQU
  760. C
  761. EXTERNAL DF, DJAC
  762. C
  763. C CHECK FOR AN APPARENT INFINITE LOOP
  764. C
  765. C***FIRST EXECUTABLE STATEMENT DDEBDF
  766. IF (INFO(1) .EQ. 0) IWORK(LIW) = 0
  767. C
  768. IF (IWORK(LIW).GE. 5) THEN
  769. IF (T .EQ. RWORK(21+NEQ)) THEN
  770. WRITE (XERN3, '(1PE15.6)') T
  771. CALL XERMSG ('SLATEC', 'DDEBDF',
  772. * 'AN APPARENT INFINITE LOOP HAS BEEN DETECTED.$$' //
  773. * 'YOU HAVE MADE REPEATED CALLS AT T = ' // XERN3 //
  774. * ' AND THE INTEGRATION HAS NOT ADVANCED. CHECK THE ' //
  775. * 'WAY YOU HAVE SET PARAMETERS FOR THE CALL TO THE ' //
  776. * 'CODE, PARTICULARLY INFO(1).', 13, 2)
  777. RETURN
  778. ENDIF
  779. ENDIF
  780. C
  781. IDID = 0
  782. C
  783. C CHECK VALIDITY OF INFO PARAMETERS
  784. C
  785. IF (INFO(1) .NE. 0 .AND. INFO(1) .NE. 1) THEN
  786. WRITE (XERN1, '(I8)') INFO(1)
  787. CALL XERMSG ('SLATEC', 'DDEBDF', 'INFO(1) MUST BE SET TO 0 ' //
  788. * 'FOR THE START OF A NEW PROBLEM, AND MUST BE SET TO 1 ' //
  789. * 'FOLLOWING AN INTERRUPTED TASK. YOU ARE ATTEMPTING TO ' //
  790. * 'CONTINUE THE INTEGRATION ILLEGALLY BY CALLING THE ' //
  791. * 'CODE WITH INFO(1) = ' // XERN1, 3, 1)
  792. IDID = -33
  793. ENDIF
  794. C
  795. IF (INFO(2) .NE. 0 .AND. INFO(2) .NE. 1) THEN
  796. WRITE (XERN1, '(I8)') INFO(2)
  797. CALL XERMSG ('SLATEC', 'DDEBDF', 'INFO(2) MUST BE 0 OR 1 ' //
  798. * 'INDICATING SCALAR AND VECTOR ERROR TOLERANCES, ' //
  799. * 'RESPECTIVELY. YOU HAVE CALLED THE CODE WITH INFO(2) = ' //
  800. * XERN1, 4, 1)
  801. IDID = -33
  802. ENDIF
  803. C
  804. IF (INFO(3) .NE. 0 .AND. INFO(3) .NE. 1) THEN
  805. WRITE (XERN1, '(I8)') INFO(3)
  806. CALL XERMSG ('SLATEC', 'DDEBDF', 'INFO(3) MUST BE 0 OR 1 ' //
  807. * 'INDICATING THE INTERVAL OR INTERMEDIATE-OUTPUT MODE OF ' //
  808. * 'INTEGRATION, RESPECTIVELY. YOU HAVE CALLED THE CODE ' //
  809. * 'WITH INFO(3) = ' // XERN1, 5, 1)
  810. IDID = -33
  811. ENDIF
  812. C
  813. IF (INFO(4) .NE. 0 .AND. INFO(4) .NE. 1) THEN
  814. WRITE (XERN1, '(I8)') INFO(4)
  815. CALL XERMSG ('SLATEC', 'DDEBDF', 'INFO(4) MUST BE 0 OR 1 ' //
  816. * 'INDICATING WHETHER OR NOT THE INTEGRATION INTERVAL IS ' //
  817. * 'TO BE RESTRICTED BY A POINT TSTOP. YOU HAVE CALLED ' //
  818. * 'THE CODE WITH INFO(4) = ' // XERN1, 14, 1)
  819. IDID = -33
  820. ENDIF
  821. C
  822. IF (INFO(5) .NE. 0 .AND. INFO(5) .NE. 1) THEN
  823. WRITE (XERN1, '(I8)') INFO(5)
  824. CALL XERMSG ('SLATEC', 'DDEBDF', 'INFO(5) MUST BE 0 OR 1 ' //
  825. * 'INDICATING WHETHER THE CODE IS TOLD TO FORM THE ' //
  826. * 'JACOBIAN MATRIX BY NUMERICAL DIFFERENCING OR YOU ' //
  827. * 'PROVIDE A SUBROUTINE TO EVALUATE IT ANALYTICALLY. ' //
  828. * 'YOU HAVE CALLED THE CODE WITH INFO(5) = ' // XERN1, 15, 1)
  829. IDID = -33
  830. ENDIF
  831. C
  832. IF (INFO(6) .NE. 0 .AND. INFO(6) .NE. 1) THEN
  833. WRITE (XERN1, '(I8)') INFO(6)
  834. CALL XERMSG ('SLATEC', 'DDEBDF', 'INFO(6) MUST BE 0 OR 1 ' //
  835. * 'INDICATING WHETHER THE CODE IS TOLD TO TREAT THE ' //
  836. * 'JACOBIAN AS A FULL (DENSE) MATRIX OR AS HAVING A ' //
  837. * 'SPECIAL BANDED STRUCTURE. YOU HAVE CALLED THE CODE ' //
  838. * 'WITH INFO(6) = ' // XERN1, 16, 1)
  839. IDID = -33
  840. ENDIF
  841. C
  842. ILRW = NEQ
  843. IF (INFO(6) .NE. 0) THEN
  844. C
  845. C CHECK BANDWIDTH PARAMETERS
  846. C
  847. ML = IWORK(1)
  848. MU = IWORK(2)
  849. ILRW = 2*ML + MU + 1
  850. C
  851. IF (ML.LT.0 .OR. ML.GE.NEQ .OR. MU.LT.0 .OR. MU.GE.NEQ) THEN
  852. WRITE (XERN1, '(I8)') ML
  853. WRITE (XERN2, '(I8)') MU
  854. CALL XERMSG ('SLATEC', 'DDEBDF', 'YOU HAVE SET INFO(6) ' //
  855. * '= 1, TELLING THE CODE THAT THE JACOBIAN MATRIX HAS ' //
  856. * 'A SPECIAL BANDED STRUCTURE. HOWEVER, THE LOWER ' //
  857. * '(UPPER) BANDWIDTHS ML (MU) VIOLATE THE CONSTRAINTS ' //
  858. * 'ML,MU .GE. 0 AND ML,MU .LT. NEQ. YOU HAVE CALLED ' //
  859. * 'THE CODE WITH ML = ' // XERN1 // ' AND MU = ' // XERN2,
  860. * 17, 1)
  861. IDID = -33
  862. ENDIF
  863. ENDIF
  864. C
  865. C CHECK LRW AND LIW FOR SUFFICIENT STORAGE ALLOCATION
  866. C
  867. IF (LRW .LT. 250 + (10 + ILRW)*NEQ) THEN
  868. WRITE (XERN1, '(I8)') LRW
  869. IF (INFO(6) .EQ. 0) THEN
  870. CALL XERMSG ('SLATEC', 'DDEBDF', 'LENGTH OF ARRAY RWORK ' //
  871. * 'MUST BE AT LEAST 250 + 10*NEQ + NEQ*NEQ.$$' //
  872. * 'YOU HAVE CALLED THE CODE WITH LRW = ' // XERN1, 1, 1)
  873. ELSE
  874. CALL XERMSG ('SLATEC', 'DDEBDF', 'LENGTH OF ARRAY RWORK ' //
  875. * 'MUST BE AT LEAST 250 + 10*NEQ + (2*ML+MU+1)*NEQ.$$' //
  876. * 'YOU HAVE CALLED THE CODE WITH LRW = ' // XERN1, 18, 1)
  877. ENDIF
  878. IDID = -33
  879. ENDIF
  880. C
  881. IF (LIW .LT. 56 + NEQ) THEN
  882. WRITE (XERN1, '(I8)') LIW
  883. CALL XERMSG ('SLATEC', 'DDEBDF', 'LENGTH OF ARRAY IWORK ' //
  884. * 'BE AT LEAST 56 + NEQ. YOU HAVE CALLED THE CODE WITH ' //
  885. * 'LIW = ' // XERN1, 2, 1)
  886. IDID = -33
  887. ENDIF
  888. C
  889. C COMPUTE THE INDICES FOR THE ARRAYS TO BE STORED IN THE WORK
  890. C ARRAY AND RESTORE COMMON BLOCK DATA
  891. C
  892. ICOMI = 21 + NEQ
  893. IINOUT = ICOMI + 33
  894. C
  895. IYPOUT = 21
  896. ITSTAR = 21 + NEQ
  897. ICOMR = 22 + NEQ
  898. C
  899. IF (INFO(1) .NE. 0) INTOUT = IWORK(IINOUT) .NE. (-1)
  900. C CALL DRSCO(RWORK(ICOMR),IWORK(ICOMI))
  901. C
  902. IYH = ICOMR + 218
  903. IEWT = IYH + 6*NEQ
  904. ISAVF = IEWT + NEQ
  905. IACOR = ISAVF + NEQ
  906. IWM = IACOR + NEQ
  907. IDELSN = IWM + 2 + ILRW*NEQ
  908. C
  909. IBEGIN = INFO(1)
  910. ITOL = INFO(2)
  911. IINTEG = INFO(3)
  912. ITSTOP = INFO(4)
  913. IJAC = INFO(5)
  914. IBAND = INFO(6)
  915. RWORK(ITSTAR) = T
  916. C
  917. CALL DLSOD(DF,NEQ,T,Y,TOUT,RTOL,ATOL,IDID,RWORK(IYPOUT),
  918. 1 RWORK(IYH),RWORK(IYH),RWORK(IEWT),RWORK(ISAVF),
  919. 2 RWORK(IACOR),RWORK(IWM),IWORK(1),DJAC,INTOUT,
  920. 3 RWORK(1),RWORK(12),RWORK(IDELSN),RPAR,IPAR)
  921. C
  922. IWORK(IINOUT) = -1
  923. IF (INTOUT) IWORK(IINOUT) = 1
  924. C
  925. IF (IDID .NE. (-2)) IWORK(LIW) = IWORK(LIW) + 1
  926. IF (T .NE. RWORK(ITSTAR)) IWORK(LIW) = 0
  927. C CALL DSVCO(RWORK(ICOMR),IWORK(ICOMI))
  928. RWORK(11) = H
  929. RWORK(13) = TN
  930. INFO(1) = IBEGIN
  931. C
  932. RETURN
  933. END