00001 SUBROUTINE DLSODE (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, 00002 1 ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, MF) 00003 EXTERNAL F, JAC 00004 INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF 00005 DOUBLE PRECISION Y, T, TOUT, RTOL, ATOL, RWORK 00006 DIMENSION NEQ(*), Y(*), RTOL(*), ATOL(*), RWORK(LRW), IWORK(LIW) 00007 C----------------------------------------------------------------------- 00008 C THIS IS THE MARCH 30, 1987 VERSION OF 00009 C LSODE.. LIVERMORE SOLVER FOR ORDINARY DIFFERENTIAL EQUATIONS. 00010 C THIS VERSION IS IN DOUBLE PRECISION. 00011 C 00012 C LSODE SOLVES THE INITIAL VALUE PROBLEM FOR STIFF OR NONSTIFF 00013 C SYSTEMS OF FIRST ORDER ODE-S, 00014 C DY/DT = F(T,Y) , OR, IN COMPONENT FORM, 00015 C DY(I)/DT = F(I) = F(I,T,Y(1),Y(2),...,Y(NEQ)) (I = 1,...,NEQ). 00016 C LSODE IS A PACKAGE BASED ON THE GEAR AND GEARB PACKAGES, AND ON THE 00017 C OCTOBER 23, 1978 VERSION OF THE TENTATIVE ODEPACK USER INTERFACE 00018 C STANDARD, WITH MINOR MODIFICATIONS. 00019 C----------------------------------------------------------------------- 00020 C REFERENCE.. 00021 C ALAN C. HINDMARSH, ODEPACK, A SYSTEMATIZED COLLECTION OF ODE 00022 C SOLVERS, IN SCIENTIFIC COMPUTING, R. S. STEPLEMAN ET AL. (EDS.), 00023 C NORTH-HOLLAND, AMSTERDAM, 1983, PP. 55-64. 00024 C----------------------------------------------------------------------- 00025 C AUTHOR AND CONTACT.. ALAN C. HINDMARSH, 00026 C COMPUTING AND MATHEMATICS RESEARCH DIV., L-316 00027 C LAWRENCE LIVERMORE NATIONAL LABORATORY 00028 C LIVERMORE, CA 94550. 00029 C----------------------------------------------------------------------- 00030 C SUMMARY OF USAGE. 00031 C 00032 C COMMUNICATION BETWEEN THE USER AND THE LSODE PACKAGE, FOR NORMAL 00033 C SITUATIONS, IS SUMMARIZED HERE. THIS SUMMARY DESCRIBES ONLY A SUBSET 00034 C OF THE FULL SET OF OPTIONS AVAILABLE. SEE THE FULL DESCRIPTION FOR 00035 C DETAILS, INCLUDING OPTIONAL COMMUNICATION, NONSTANDARD OPTIONS, 00036 C AND INSTRUCTIONS FOR SPECIAL SITUATIONS. SEE ALSO THE EXAMPLE 00037 C PROBLEM (WITH PROGRAM AND OUTPUT) FOLLOWING THIS SUMMARY. 00038 C 00039 C A. FIRST PROVIDE A SUBROUTINE OF THE FORM.. 00040 C SUBROUTINE F (NEQ, T, Y, YDOT, IERR) 00041 C DIMENSION Y(NEQ), YDOT(NEQ) 00042 C WHICH SUPPLIES THE VECTOR FUNCTION F BY LOADING YDOT(I) WITH F(I). 00043 C 00044 C B. NEXT DETERMINE (OR GUESS) WHETHER OR NOT THE PROBLEM IS STIFF. 00045 C STIFFNESS OCCURS WHEN THE JACOBIAN MATRIX DF/DY HAS AN EIGENVALUE 00046 C WHOSE REAL PART IS NEGATIVE AND LARGE IN MAGNITUDE, COMPARED TO THE 00047 C RECIPROCAL OF THE T SPAN OF INTEREST. IF THE PROBLEM IS NONSTIFF, 00048 C USE A METHOD FLAG MF = 10. IF IT IS STIFF, THERE ARE FOUR STANDARD 00049 C CHOICES FOR MF, AND LSODE REQUIRES THE JACOBIAN MATRIX IN SOME FORM. 00050 C THIS MATRIX IS REGARDED EITHER AS FULL (MF = 21 OR 22), 00051 C OR BANDED (MF = 24 OR 25). IN THE BANDED CASE, LSODE REQUIRES TWO 00052 C HALF-BANDWIDTH PARAMETERS ML AND MU. THESE ARE, RESPECTIVELY, THE 00053 C WIDTHS OF THE LOWER AND UPPER PARTS OF THE BAND, EXCLUDING THE MAIN 00054 C DIAGONAL. THUS THE BAND CONSISTS OF THE LOCATIONS (I,J) WITH 00055 C I-ML .LE. J .LE. I+MU, AND THE FULL BANDWIDTH IS ML+MU+1. 00056 C 00057 C C. IF THE PROBLEM IS STIFF, YOU ARE ENCOURAGED TO SUPPLY THE JACOBIAN 00058 C DIRECTLY (MF = 21 OR 24), BUT IF THIS IS NOT FEASIBLE, LSODE WILL 00059 C COMPUTE IT INTERNALLY BY DIFFERENCE QUOTIENTS (MF = 22 OR 25). 00060 C IF YOU ARE SUPPLYING THE JACOBIAN, PROVIDE A SUBROUTINE OF THE FORM.. 00061 C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD) 00062 C DIMENSION Y(NEQ), PD(NROWPD,NEQ) 00063 C WHICH SUPPLIES DF/DY BY LOADING PD AS FOLLOWS.. 00064 C FOR A FULL JACOBIAN (MF = 21), LOAD PD(I,J) WITH DF(I)/DY(J), 00065 C THE PARTIAL DERIVATIVE OF F(I) WITH RESPECT TO Y(J). (IGNORE THE 00066 C ML AND MU ARGUMENTS IN THIS CASE.) 00067 C FOR A BANDED JACOBIAN (MF = 24), LOAD PD(I-J+MU+1,J) WITH 00068 C DF(I)/DY(J), I.E. LOAD THE DIAGONAL LINES OF DF/DY INTO THE ROWS OF 00069 C PD FROM THE TOP DOWN. 00070 C IN EITHER CASE, ONLY NONZERO ELEMENTS NEED BE LOADED. 00071 C 00072 C D. WRITE A MAIN PROGRAM WHICH CALLS SUBROUTINE LSODE ONCE FOR 00073 C EACH POINT AT WHICH ANSWERS ARE DESIRED. THIS SHOULD ALSO PROVIDE 00074 C FOR POSSIBLE USE OF LOGICAL UNIT 6 FOR OUTPUT OF ERROR MESSAGES 00075 C BY LSODE. ON THE FIRST CALL TO LSODE, SUPPLY ARGUMENTS AS FOLLOWS.. 00076 C F = NAME OF SUBROUTINE FOR RIGHT-HAND SIDE VECTOR F. 00077 C THIS NAME MUST BE DECLARED EXTERNAL IN CALLING PROGRAM. 00078 C NEQ = NUMBER OF FIRST ORDER ODE-S. 00079 C Y = ARRAY OF INITIAL VALUES, OF LENGTH NEQ. 00080 C T = THE INITIAL VALUE OF THE INDEPENDENT VARIABLE. 00081 C TOUT = FIRST POINT WHERE OUTPUT IS DESIRED (.NE. T). 00082 C ITOL = 1 OR 2 ACCORDING AS ATOL (BELOW) IS A SCALAR OR ARRAY. 00083 C RTOL = RELATIVE TOLERANCE PARAMETER (SCALAR). 00084 C ATOL = ABSOLUTE TOLERANCE PARAMETER (SCALAR OR ARRAY). 00085 C THE ESTIMATED LOCAL ERROR IN Y(I) WILL BE CONTROLLED SO AS 00086 C TO BE ROUGHLY LESS (IN MAGNITUDE) THAN 00087 C EWT(I) = RTOL*ABS(Y(I)) + ATOL IF ITOL = 1, OR 00088 C EWT(I) = RTOL*ABS(Y(I)) + ATOL(I) IF ITOL = 2. 00089 C THUS THE LOCAL ERROR TEST PASSES IF, IN EACH COMPONENT, 00090 C EITHER THE ABSOLUTE ERROR IS LESS THAN ATOL (OR ATOL(I)), 00091 C OR THE RELATIVE ERROR IS LESS THAN RTOL. 00092 C USE RTOL = 0.0 FOR PURE ABSOLUTE ERROR CONTROL, AND 00093 C USE ATOL = 0.0 (OR ATOL(I) = 0.0) FOR PURE RELATIVE ERROR 00094 C CONTROL. CAUTION.. ACTUAL (GLOBAL) ERRORS MAY EXCEED THESE 00095 C LOCAL TOLERANCES, SO CHOOSE THEM CONSERVATIVELY. 00096 C ITASK = 1 FOR NORMAL COMPUTATION OF OUTPUT VALUES OF Y AT T = TOUT. 00097 C ISTATE = INTEGER FLAG (INPUT AND OUTPUT). SET ISTATE = 1. 00098 C IOPT = 0 TO INDICATE NO OPTIONAL INPUTS USED. 00099 C RWORK = REAL WORK ARRAY OF LENGTH AT LEAST.. 00100 C 20 + 16*NEQ FOR MF = 10, 00101 C 22 + 9*NEQ + NEQ**2 FOR MF = 21 OR 22, 00102 C 22 + 10*NEQ + (2*ML + MU)*NEQ FOR MF = 24 OR 25. 00103 C LRW = DECLARED LENGTH OF RWORK (IN USER-S DIMENSION). 00104 C IWORK = INTEGER WORK ARRAY OF LENGTH AT LEAST.. 00105 C 20 FOR MF = 10, 00106 C 20 + NEQ FOR MF = 21, 22, 24, OR 25. 00107 C IF MF = 24 OR 25, INPUT IN IWORK(1),IWORK(2) THE LOWER 00108 C AND UPPER HALF-BANDWIDTHS ML,MU. 00109 C LIW = DECLARED LENGTH OF IWORK (IN USER-S DIMENSION). 00110 C JAC = NAME OF SUBROUTINE FOR JACOBIAN MATRIX (MF = 21 OR 24). 00111 C IF USED, THIS NAME MUST BE DECLARED EXTERNAL IN CALLING 00112 C PROGRAM. IF NOT USED, PASS A DUMMY NAME. 00113 C MF = METHOD FLAG. STANDARD VALUES ARE.. 00114 C 10 FOR NONSTIFF (ADAMS) METHOD, NO JACOBIAN USED. 00115 C 21 FOR STIFF (BDF) METHOD, USER-SUPPLIED FULL JACOBIAN. 00116 C 22 FOR STIFF METHOD, INTERNALLY GENERATED FULL JACOBIAN. 00117 C 24 FOR STIFF METHOD, USER-SUPPLIED BANDED JACOBIAN. 00118 C 25 FOR STIFF METHOD, INTERNALLY GENERATED BANDED JACOBIAN. 00119 C NOTE THAT THE MAIN PROGRAM MUST DECLARE ARRAYS Y, RWORK, IWORK, 00120 C AND POSSIBLY ATOL. 00121 C 00122 C E. THE OUTPUT FROM THE FIRST CALL (OR ANY CALL) IS.. 00123 C Y = ARRAY OF COMPUTED VALUES OF Y(T) VECTOR. 00124 C T = CORRESPONDING VALUE OF INDEPENDENT VARIABLE (NORMALLY TOUT). 00125 C ISTATE = 2 IF LSODE WAS SUCCESSFUL, NEGATIVE OTHERWISE. 00126 C -1 MEANS EXCESS WORK DONE ON THIS CALL (PERHAPS WRONG MF). 00127 C -2 MEANS EXCESS ACCURACY REQUESTED (TOLERANCES TOO SMALL). 00128 C -3 MEANS ILLEGAL INPUT DETECTED (SEE PRINTED MESSAGE). 00129 C -4 MEANS REPEATED ERROR TEST FAILURES (CHECK ALL INPUTS). 00130 C -5 MEANS REPEATED CONVERGENCE FAILURES (PERHAPS BAD JACOBIAN 00131 C SUPPLIED OR WRONG CHOICE OF MF OR TOLERANCES). 00132 C -6 MEANS ERROR WEIGHT BECAME ZERO DURING PROBLEM. (SOLUTION 00133 C COMPONENT I VANISHED, AND ATOL OR ATOL(I) = 0.) 00134 C -13 MEANS EXIT REQUESTED IN USER-SUPPLIED FUNCTION. 00135 C 00136 C F. TO CONTINUE THE INTEGRATION AFTER A SUCCESSFUL RETURN, SIMPLY 00137 C RESET TOUT AND CALL LSODE AGAIN. NO OTHER PARAMETERS NEED BE RESET. 00138 C 00139 C----------------------------------------------------------------------- 00140 C EXAMPLE PROBLEM. 00141 C 00142 C THE FOLLOWING IS A SIMPLE EXAMPLE PROBLEM, WITH THE CODING 00143 C NEEDED FOR ITS SOLUTION BY LSODE. THE PROBLEM IS FROM CHEMICAL 00144 C KINETICS, AND CONSISTS OF THE FOLLOWING THREE RATE EQUATIONS.. 00145 C DY1/DT = -.04*Y1 + 1.E4*Y2*Y3 00146 C DY2/DT = .04*Y1 - 1.E4*Y2*Y3 - 3.E7*Y2**2 00147 C DY3/DT = 3.E7*Y2**2 00148 C ON THE INTERVAL FROM T = 0.0 TO T = 4.E10, WITH INITIAL CONDITIONS 00149 C Y1 = 1.0, Y2 = Y3 = 0. THE PROBLEM IS STIFF. 00150 C 00151 C THE FOLLOWING CODING SOLVES THIS PROBLEM WITH LSODE, USING MF = 21 00152 C AND PRINTING RESULTS AT T = .4, 4., ..., 4.E10. IT USES 00153 C ITOL = 2 AND ATOL MUCH SMALLER FOR Y2 THAN Y1 OR Y3 BECAUSE 00154 C Y2 HAS MUCH SMALLER VALUES. 00155 C AT THE END OF THE RUN, STATISTICAL QUANTITIES OF INTEREST ARE 00156 C PRINTED (SEE OPTIONAL OUTPUTS IN THE FULL DESCRIPTION BELOW). 00157 C 00158 C EXTERNAL FEX, JEX 00159 C DOUBLE PRECISION ATOL, RTOL, RWORK, T, TOUT, Y 00160 C DIMENSION Y(3), ATOL(3), RWORK(58), IWORK(23) 00161 C NEQ = 3 00162 C Y(1) = 1.D0 00163 C Y(2) = 0.D0 00164 C Y(3) = 0.D0 00165 C T = 0.D0 00166 C TOUT = .4D0 00167 C ITOL = 2 00168 C RTOL = 1.D-4 00169 C ATOL(1) = 1.D-6 00170 C ATOL(2) = 1.D-10 00171 C ATOL(3) = 1.D-6 00172 C ITASK = 1 00173 C ISTATE = 1 00174 C IOPT = 0 00175 C LRW = 58 00176 C LIW = 23 00177 C MF = 21 00178 C DO 40 IOUT = 1,12 00179 C CALL LSODE(FEX,NEQ,Y,T,TOUT,ITOL,RTOL,ATOL,ITASK,ISTATE, 00180 C 1 IOPT,RWORK,LRW,IWORK,LIW,JEX,MF) 00181 C WRITE(6,20)T,Y(1),Y(2),Y(3) 00182 C 20 FORMAT(7H AT T =,E12.4,6H Y =,3E14.6) 00183 C IF (ISTATE .LT. 0) GO TO 80 00184 C 40 TOUT = TOUT*10.D0 00185 C WRITE(6,60)IWORK(11),IWORK(12),IWORK(13) 00186 C 60 FORMAT(/12H NO. STEPS =,I4,11H NO. F-S =,I4,11H NO. J-S =,I4) 00187 C STOP 00188 C 80 WRITE(6,90)ISTATE 00189 C 90 FORMAT(///22H ERROR HALT.. ISTATE =,I3) 00190 C STOP 00191 C END 00192 C 00193 C SUBROUTINE FEX (NEQ, T, Y, YDOT) 00194 C DOUBLE PRECISION T, Y, YDOT 00195 C DIMENSION Y(3), YDOT(3) 00196 C YDOT(1) = -.04D0*Y(1) + 1.D4*Y(2)*Y(3) 00197 C YDOT(3) = 3.D7*Y(2)*Y(2) 00198 C YDOT(2) = -YDOT(1) - YDOT(3) 00199 C RETURN 00200 C END 00201 C 00202 C SUBROUTINE JEX (NEQ, T, Y, ML, MU, PD, NRPD) 00203 C DOUBLE PRECISION PD, T, Y 00204 C DIMENSION Y(3), PD(NRPD,3) 00205 C PD(1,1) = -.04D0 00206 C PD(1,2) = 1.D4*Y(3) 00207 C PD(1,3) = 1.D4*Y(2) 00208 C PD(2,1) = .04D0 00209 C PD(2,3) = -PD(1,3) 00210 C PD(3,2) = 6.D7*Y(2) 00211 C PD(2,2) = -PD(1,2) - PD(3,2) 00212 C RETURN 00213 C END 00214 C 00215 C THE OUTPUT OF THIS PROGRAM (ON A CDC-7600 IN SINGLE PRECISION) 00216 C IS AS FOLLOWS.. 00217 C 00218 C AT T = 4.0000E-01 Y = 9.851726E-01 3.386406E-05 1.479357E-02 00219 C AT T = 4.0000E+00 Y = 9.055142E-01 2.240418E-05 9.446344E-02 00220 C AT T = 4.0000E+01 Y = 7.158050E-01 9.184616E-06 2.841858E-01 00221 C AT T = 4.0000E+02 Y = 4.504846E-01 3.222434E-06 5.495122E-01 00222 C AT T = 4.0000E+03 Y = 1.831701E-01 8.940379E-07 8.168290E-01 00223 C AT T = 4.0000E+04 Y = 3.897016E-02 1.621193E-07 9.610297E-01 00224 C AT T = 4.0000E+05 Y = 4.935213E-03 1.983756E-08 9.950648E-01 00225 C AT T = 4.0000E+06 Y = 5.159269E-04 2.064759E-09 9.994841E-01 00226 C AT T = 4.0000E+07 Y = 5.306413E-05 2.122677E-10 9.999469E-01 00227 C AT T = 4.0000E+08 Y = 5.494529E-06 2.197824E-11 9.999945E-01 00228 C AT T = 4.0000E+09 Y = 5.129458E-07 2.051784E-12 9.999995E-01 00229 C AT T = 4.0000E+10 Y = -7.170586E-08 -2.868234E-13 1.000000E+00 00230 C 00231 C NO. STEPS = 330 NO. F-S = 405 NO. J-S = 69 00232 C----------------------------------------------------------------------- 00233 C FULL DESCRIPTION OF USER INTERFACE TO LSODE. 00234 C 00235 C THE USER INTERFACE TO LSODE CONSISTS OF THE FOLLOWING PARTS. 00236 C 00237 C I. THE CALL SEQUENCE TO SUBROUTINE LSODE, WHICH IS A DRIVER 00238 C ROUTINE FOR THE SOLVER. THIS INCLUDES DESCRIPTIONS OF BOTH 00239 C THE CALL SEQUENCE ARGUMENTS AND OF USER-SUPPLIED ROUTINES. 00240 C FOLLOWING THESE DESCRIPTIONS IS A DESCRIPTION OF 00241 C OPTIONAL INPUTS AVAILABLE THROUGH THE CALL SEQUENCE, AND THEN 00242 C A DESCRIPTION OF OPTIONAL OUTPUTS (IN THE WORK ARRAYS). 00243 C 00244 C II. DESCRIPTIONS OF OTHER ROUTINES IN THE LSODE PACKAGE THAT MAY BE 00245 C (OPTIONALLY) CALLED BY THE USER. THESE PROVIDE THE ABILITY TO 00246 C ALTER ERROR MESSAGE HANDLING, SAVE AND RESTORE THE INTERNAL 00247 C COMMON, AND OBTAIN SPECIFIED DERIVATIVES OF THE SOLUTION Y(T). 00248 C 00249 C III. DESCRIPTIONS OF COMMON BLOCKS TO BE DECLARED IN OVERLAY 00250 C OR SIMILAR ENVIRONMENTS, OR TO BE SAVED WHEN DOING AN INTERRUPT 00251 C OF THE PROBLEM AND CONTINUED SOLUTION LATER. 00252 C 00253 C IV. DESCRIPTION OF TWO ROUTINES IN THE LSODE PACKAGE, EITHER OF 00254 C WHICH THE USER MAY REPLACE WITH HIS OWN VERSION, IF DESIRED. 00255 C THESE RELATE TO THE MEASUREMENT OF ERRORS. 00256 C 00257 C----------------------------------------------------------------------- 00258 C PART I. CALL SEQUENCE. 00259 C 00260 C THE CALL SEQUENCE PARAMETERS USED FOR INPUT ONLY ARE 00261 C F, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, IOPT, LRW, LIW, JAC, MF, 00262 C AND THOSE USED FOR BOTH INPUT AND OUTPUT ARE 00263 C Y, T, ISTATE. 00264 C THE WORK ARRAYS RWORK AND IWORK ARE ALSO USED FOR CONDITIONAL AND 00265 C OPTIONAL INPUTS AND OPTIONAL OUTPUTS. (THE TERM OUTPUT HERE REFERS 00266 C TO THE RETURN FROM SUBROUTINE LSODE TO THE USER-S CALLING PROGRAM.) 00267 C 00268 C THE LEGALITY OF INPUT PARAMETERS WILL BE THOROUGHLY CHECKED ON THE 00269 C INITIAL CALL FOR THE PROBLEM, BUT NOT CHECKED THEREAFTER UNLESS A 00270 C CHANGE IN INPUT PARAMETERS IS FLAGGED BY ISTATE = 3 ON INPUT. 00271 C 00272 C THE DESCRIPTIONS OF THE CALL ARGUMENTS ARE AS FOLLOWS. 00273 C 00274 C F = THE NAME OF THE USER-SUPPLIED SUBROUTINE DEFINING THE 00275 C ODE SYSTEM. THE SYSTEM MUST BE PUT IN THE FIRST-ORDER 00276 C FORM DY/DT = F(T,Y), WHERE F IS A VECTOR-VALUED FUNCTION 00277 C OF THE SCALAR T AND THE VECTOR Y. SUBROUTINE F IS TO 00278 C COMPUTE THE FUNCTION F. IT IS TO HAVE THE FORM 00279 C SUBROUTINE F (NEQ, T, Y, YDOT) 00280 C DIMENSION Y(1), YDOT(1) 00281 C WHERE NEQ, T, AND Y ARE INPUT, AND THE ARRAY YDOT = F(T,Y) 00282 C IS OUTPUT. Y AND YDOT ARE ARRAYS OF LENGTH NEQ. 00283 C (IN THE DIMENSION STATEMENT ABOVE, 1 IS A DUMMY 00284 C DIMENSION.. IT CAN BE REPLACED BY ANY VALUE.) 00285 C SUBROUTINE F SHOULD NOT ALTER Y(1),...,Y(NEQ). 00286 C F MUST BE DECLARED EXTERNAL IN THE CALLING PROGRAM. 00287 C 00288 C SUBROUTINE F MAY ACCESS USER-DEFINED QUANTITIES IN 00289 C NEQ(2),... AND/OR IN Y(NEQ(1)+1),... IF NEQ IS AN ARRAY 00290 C (DIMENSIONED IN F) AND/OR Y HAS LENGTH EXCEEDING NEQ(1). 00291 C SEE THE DESCRIPTIONS OF NEQ AND Y BELOW. 00292 C 00293 C IF QUANTITIES COMPUTED IN THE F ROUTINE ARE NEEDED 00294 C EXTERNALLY TO LSODE, AN EXTRA CALL TO F SHOULD BE MADE 00295 C FOR THIS PURPOSE, FOR CONSISTENT AND ACCURATE RESULTS. 00296 C IF ONLY THE DERIVATIVE DY/DT IS NEEDED, USE INTDY INSTEAD. 00297 C 00298 C NEQ = THE SIZE OF THE ODE SYSTEM (NUMBER OF FIRST ORDER 00299 C ORDINARY DIFFERENTIAL EQUATIONS). USED ONLY FOR INPUT. 00300 C NEQ MAY BE DECREASED, BUT NOT INCREASED, DURING THE PROBLEM. 00301 C IF NEQ IS DECREASED (WITH ISTATE = 3 ON INPUT), THE 00302 C REMAINING COMPONENTS OF Y SHOULD BE LEFT UNDISTURBED, IF 00303 C THESE ARE TO BE ACCESSED IN F AND/OR JAC. 00304 C 00305 C NORMALLY, NEQ IS A SCALAR, AND IT IS GENERALLY REFERRED TO 00306 C AS A SCALAR IN THIS USER INTERFACE DESCRIPTION. HOWEVER, 00307 C NEQ MAY BE AN ARRAY, WITH NEQ(1) SET TO THE SYSTEM SIZE. 00308 C (THE LSODE PACKAGE ACCESSES ONLY NEQ(1).) IN EITHER CASE, 00309 C THIS PARAMETER IS PASSED AS THE NEQ ARGUMENT IN ALL CALLS 00310 C TO F AND JAC. HENCE, IF IT IS AN ARRAY, LOCATIONS 00311 C NEQ(2),... MAY BE USED TO STORE OTHER INTEGER DATA AND PASS 00312 C IT TO F AND/OR JAC. SUBROUTINES F AND/OR JAC MUST INCLUDE 00313 C NEQ IN A DIMENSION STATEMENT IN THAT CASE. 00314 C 00315 C Y = A REAL ARRAY FOR THE VECTOR OF DEPENDENT VARIABLES, OF 00316 C LENGTH NEQ OR MORE. USED FOR BOTH INPUT AND OUTPUT ON THE 00317 C FIRST CALL (ISTATE = 1), AND ONLY FOR OUTPUT ON OTHER CALLS. 00318 C ON THE FIRST CALL, Y MUST CONTAIN THE VECTOR OF INITIAL 00319 C VALUES. ON OUTPUT, Y CONTAINS THE COMPUTED SOLUTION VECTOR, 00320 C EVALUATED AT T. IF DESIRED, THE Y ARRAY MAY BE USED 00321 C FOR OTHER PURPOSES BETWEEN CALLS TO THE SOLVER. 00322 C 00323 C THIS ARRAY IS PASSED AS THE Y ARGUMENT IN ALL CALLS TO 00324 C F AND JAC. HENCE ITS LENGTH MAY EXCEED NEQ, AND LOCATIONS 00325 C Y(NEQ+1),... MAY BE USED TO STORE OTHER REAL DATA AND 00326 C PASS IT TO F AND/OR JAC. (THE LSODE PACKAGE ACCESSES ONLY 00327 C Y(1),...,Y(NEQ).) 00328 C 00329 C T = THE INDEPENDENT VARIABLE. ON INPUT, T IS USED ONLY ON THE 00330 C FIRST CALL, AS THE INITIAL POINT OF THE INTEGRATION. 00331 C ON OUTPUT, AFTER EACH CALL, T IS THE VALUE AT WHICH A 00332 C COMPUTED SOLUTION Y IS EVALUATED (USUALLY THE SAME AS TOUT). 00333 C ON AN ERROR RETURN, T IS THE FARTHEST POINT REACHED. 00334 C 00335 C TOUT = THE NEXT VALUE OF T AT WHICH A COMPUTED SOLUTION IS DESIRED. 00336 C USED ONLY FOR INPUT. 00337 C 00338 C WHEN STARTING THE PROBLEM (ISTATE = 1), TOUT MAY BE EQUAL 00339 C TO T FOR ONE CALL, THEN SHOULD .NE. T FOR THE NEXT CALL. 00340 C FOR THE INITIAL T, AN INPUT VALUE OF TOUT .NE. T IS USED 00341 C IN ORDER TO DETERMINE THE DIRECTION OF THE INTEGRATION 00342 C (I.E. THE ALGEBRAIC SIGN OF THE STEP SIZES) AND THE ROUGH 00343 C SCALE OF THE PROBLEM. INTEGRATION IN EITHER DIRECTION 00344 C (FORWARD OR BACKWARD IN T) IS PERMITTED. 00345 C 00346 C IF ITASK = 2 OR 5 (ONE-STEP MODES), TOUT IS IGNORED AFTER 00347 C THE FIRST CALL (I.E. THE FIRST CALL WITH TOUT .NE. T). 00348 C OTHERWISE, TOUT IS REQUIRED ON EVERY CALL. 00349 C 00350 C IF ITASK = 1, 3, OR 4, THE VALUES OF TOUT NEED NOT BE 00351 C MONOTONE, BUT A VALUE OF TOUT WHICH BACKS UP IS LIMITED 00352 C TO THE CURRENT INTERNAL T INTERVAL, WHOSE ENDPOINTS ARE 00353 C TCUR - HU AND TCUR (SEE OPTIONAL OUTPUTS, BELOW, FOR 00354 C TCUR AND HU). 00355 C 00356 C ITOL = AN INDICATOR FOR THE TYPE OF ERROR CONTROL. SEE 00357 C DESCRIPTION BELOW UNDER ATOL. USED ONLY FOR INPUT. 00358 C 00359 C RTOL = A RELATIVE ERROR TOLERANCE PARAMETER, EITHER A SCALAR OR 00360 C AN ARRAY OF LENGTH NEQ. SEE DESCRIPTION BELOW UNDER ATOL. 00361 C INPUT ONLY. 00362 C 00363 C ATOL = AN ABSOLUTE ERROR TOLERANCE PARAMETER, EITHER A SCALAR OR 00364 C AN ARRAY OF LENGTH NEQ. INPUT ONLY. 00365 C 00366 C THE INPUT PARAMETERS ITOL, RTOL, AND ATOL DETERMINE 00367 C THE ERROR CONTROL PERFORMED BY THE SOLVER. THE SOLVER WILL 00368 C CONTROL THE VECTOR E = (E(I)) OF ESTIMATED LOCAL ERRORS 00369 C IN Y, ACCORDING TO AN INEQUALITY OF THE FORM 00370 C RMS-NORM OF ( E(I)/EWT(I) ) .LE. 1, 00371 C WHERE EWT(I) = RTOL(I)*ABS(Y(I)) + ATOL(I), 00372 C AND THE RMS-NORM (ROOT-MEAN-SQUARE NORM) HERE IS 00373 C RMS-NORM(V) = SQRT(SUM V(I)**2 / NEQ). HERE EWT = (EWT(I)) 00374 C IS A VECTOR OF WEIGHTS WHICH MUST ALWAYS BE POSITIVE, AND 00375 C THE VALUES OF RTOL AND ATOL SHOULD ALL BE NON-NEGATIVE. 00376 C THE FOLLOWING TABLE GIVES THE TYPES (SCALAR/ARRAY) OF 00377 C RTOL AND ATOL, AND THE CORRESPONDING FORM OF EWT(I). 00378 C 00379 C ITOL RTOL ATOL EWT(I) 00380 C 1 SCALAR SCALAR RTOL*ABS(Y(I)) + ATOL 00381 C 2 SCALAR ARRAY RTOL*ABS(Y(I)) + ATOL(I) 00382 C 3 ARRAY SCALAR RTOL(I)*ABS(Y(I)) + ATOL 00383 C 4 ARRAY ARRAY RTOL(I)*ABS(Y(I)) + ATOL(I) 00384 C 00385 C WHEN EITHER OF THESE PARAMETERS IS A SCALAR, IT NEED NOT 00386 C BE DIMENSIONED IN THE USER-S CALLING PROGRAM. 00387 C 00388 C IF NONE OF THE ABOVE CHOICES (WITH ITOL, RTOL, AND ATOL 00389 C FIXED THROUGHOUT THE PROBLEM) IS SUITABLE, MORE GENERAL 00390 C ERROR CONTROLS CAN BE OBTAINED BY SUBSTITUTING 00391 C USER-SUPPLIED ROUTINES FOR THE SETTING OF EWT AND/OR FOR 00392 C THE NORM CALCULATION. SEE PART IV BELOW. 00393 C 00394 C IF GLOBAL ERRORS ARE TO BE ESTIMATED BY MAKING A REPEATED 00395 C RUN ON THE SAME PROBLEM WITH SMALLER TOLERANCES, THEN ALL 00396 C COMPONENTS OF RTOL AND ATOL (I.E. OF EWT) SHOULD BE SCALED 00397 C DOWN UNIFORMLY. 00398 C 00399 C ITASK = AN INDEX SPECIFYING THE TASK TO BE PERFORMED. 00400 C INPUT ONLY. ITASK HAS THE FOLLOWING VALUES AND MEANINGS. 00401 C 1 MEANS NORMAL COMPUTATION OF OUTPUT VALUES OF Y(T) AT 00402 C T = TOUT (BY OVERSHOOTING AND INTERPOLATING). 00403 C 2 MEANS TAKE ONE STEP ONLY AND RETURN. 00404 C 3 MEANS STOP AT THE FIRST INTERNAL MESH POINT AT OR 00405 C BEYOND T = TOUT AND RETURN. 00406 C 4 MEANS NORMAL COMPUTATION OF OUTPUT VALUES OF Y(T) AT 00407 C T = TOUT BUT WITHOUT OVERSHOOTING T = TCRIT. 00408 C TCRIT MUST BE INPUT AS RWORK(1). TCRIT MAY BE EQUAL TO 00409 C OR BEYOND TOUT, BUT NOT BEHIND IT IN THE DIRECTION OF 00410 C INTEGRATION. THIS OPTION IS USEFUL IF THE PROBLEM 00411 C HAS A SINGULARITY AT OR BEYOND T = TCRIT. 00412 C 5 MEANS TAKE ONE STEP, WITHOUT PASSING TCRIT, AND RETURN. 00413 C TCRIT MUST BE INPUT AS RWORK(1). 00414 C 00415 C NOTE.. IF ITASK = 4 OR 5 AND THE SOLVER REACHES TCRIT 00416 C (WITHIN ROUNDOFF), IT WILL RETURN T = TCRIT (EXACTLY) TO 00417 C INDICATE THIS (UNLESS ITASK = 4 AND TOUT COMES BEFORE TCRIT, 00418 C IN WHICH CASE ANSWERS AT T = TOUT ARE RETURNED FIRST). 00419 C 00420 C ISTATE = AN INDEX USED FOR INPUT AND OUTPUT TO SPECIFY THE 00421 C THE STATE OF THE CALCULATION. 00422 C 00423 C ON INPUT, THE VALUES OF ISTATE ARE AS FOLLOWS. 00424 C 1 MEANS THIS IS THE FIRST CALL FOR THE PROBLEM 00425 C (INITIALIZATIONS WILL BE DONE). SEE NOTE BELOW. 00426 C 2 MEANS THIS IS NOT THE FIRST CALL, AND THE CALCULATION 00427 C IS TO CONTINUE NORMALLY, WITH NO CHANGE IN ANY INPUT 00428 C PARAMETERS EXCEPT POSSIBLY TOUT AND ITASK. 00429 C (IF ITOL, RTOL, AND/OR ATOL ARE CHANGED BETWEEN CALLS 00430 C WITH ISTATE = 2, THE NEW VALUES WILL BE USED BUT NOT 00431 C TESTED FOR LEGALITY.) 00432 C 3 MEANS THIS IS NOT THE FIRST CALL, AND THE 00433 C CALCULATION IS TO CONTINUE NORMALLY, BUT WITH 00434 C A CHANGE IN INPUT PARAMETERS OTHER THAN 00435 C TOUT AND ITASK. CHANGES ARE ALLOWED IN 00436 C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF, ML, MU, 00437 C AND ANY OF THE OPTIONAL INPUTS EXCEPT H0. 00438 C (SEE IWORK DESCRIPTION FOR ML AND MU.) 00439 C NOTE.. A PRELIMINARY CALL WITH TOUT = T IS NOT COUNTED 00440 C AS A FIRST CALL HERE, AS NO INITIALIZATION OR CHECKING OF 00441 C INPUT IS DONE. (SUCH A CALL IS SOMETIMES USEFUL FOR THE 00442 C PURPOSE OF OUTPUTTING THE INITIAL CONDITIONS.) 00443 C THUS THE FIRST CALL FOR WHICH TOUT .NE. T REQUIRES 00444 C ISTATE = 1 ON INPUT. 00445 C 00446 C ON OUTPUT, ISTATE HAS THE FOLLOWING VALUES AND MEANINGS. 00447 C 1 MEANS NOTHING WAS DONE, AS TOUT WAS EQUAL TO T WITH 00448 C ISTATE = 1 ON INPUT. (HOWEVER, AN INTERNAL COUNTER WAS 00449 C SET TO DETECT AND PREVENT REPEATED CALLS OF THIS TYPE.) 00450 C 2 MEANS THE INTEGRATION WAS PERFORMED SUCCESSFULLY. 00451 C -1 MEANS AN EXCESSIVE AMOUNT OF WORK (MORE THAN MXSTEP 00452 C STEPS) WAS DONE ON THIS CALL, BEFORE COMPLETING THE 00453 C REQUESTED TASK, BUT THE INTEGRATION WAS OTHERWISE 00454 C SUCCESSFUL AS FAR AS T. (MXSTEP IS AN OPTIONAL INPUT 00455 C AND IS NORMALLY 500.) TO CONTINUE, THE USER MAY 00456 C SIMPLY RESET ISTATE TO A VALUE .GT. 1 AND CALL AGAIN 00457 C (THE EXCESS WORK STEP COUNTER WILL BE RESET TO 0). 00458 C IN ADDITION, THE USER MAY INCREASE MXSTEP TO AVOID 00459 C THIS ERROR RETURN (SEE BELOW ON OPTIONAL INPUTS). 00460 C -2 MEANS TOO MUCH ACCURACY WAS REQUESTED FOR THE PRECISION 00461 C OF THE MACHINE BEING USED. THIS WAS DETECTED BEFORE 00462 C COMPLETING THE REQUESTED TASK, BUT THE INTEGRATION 00463 C WAS SUCCESSFUL AS FAR AS T. TO CONTINUE, THE TOLERANCE 00464 C PARAMETERS MUST BE RESET, AND ISTATE MUST BE SET 00465 C TO 3. THE OPTIONAL OUTPUT TOLSF MAY BE USED FOR THIS 00466 C PURPOSE. (NOTE.. IF THIS CONDITION IS DETECTED BEFORE 00467 C TAKING ANY STEPS, THEN AN ILLEGAL INPUT RETURN 00468 C (ISTATE = -3) OCCURS INSTEAD.) 00469 C -3 MEANS ILLEGAL INPUT WAS DETECTED, BEFORE TAKING ANY 00470 C INTEGRATION STEPS. SEE WRITTEN MESSAGE FOR DETAILS. 00471 C NOTE.. IF THE SOLVER DETECTS AN INFINITE LOOP OF CALLS 00472 C TO THE SOLVER WITH ILLEGAL INPUT, IT WILL CAUSE 00473 C THE RUN TO STOP. 00474 C -4 MEANS THERE WERE REPEATED ERROR TEST FAILURES ON 00475 C ONE ATTEMPTED STEP, BEFORE COMPLETING THE REQUESTED 00476 C TASK, BUT THE INTEGRATION WAS SUCCESSFUL AS FAR AS T. 00477 C THE PROBLEM MAY HAVE A SINGULARITY, OR THE INPUT 00478 C MAY BE INAPPROPRIATE. 00479 C -5 MEANS THERE WERE REPEATED CONVERGENCE TEST FAILURES ON 00480 C ONE ATTEMPTED STEP, BEFORE COMPLETING THE REQUESTED 00481 C TASK, BUT THE INTEGRATION WAS SUCCESSFUL AS FAR AS T. 00482 C THIS MAY BE CAUSED BY AN INACCURATE JACOBIAN MATRIX, 00483 C IF ONE IS BEING USED. 00484 C -6 MEANS EWT(I) BECAME ZERO FOR SOME I DURING THE 00485 C INTEGRATION. PURE RELATIVE ERROR CONTROL (ATOL(I)=0.0) 00486 C WAS REQUESTED ON A VARIABLE WHICH HAS NOW VANISHED. 00487 C THE INTEGRATION WAS SUCCESSFUL AS FAR AS T. 00488 C 00489 C NOTE.. SINCE THE NORMAL OUTPUT VALUE OF ISTATE IS 2, 00490 C IT DOES NOT NEED TO BE RESET FOR NORMAL CONTINUATION. 00491 C ALSO, SINCE A NEGATIVE INPUT VALUE OF ISTATE WILL BE 00492 C REGARDED AS ILLEGAL, A NEGATIVE OUTPUT VALUE REQUIRES THE 00493 C USER TO CHANGE IT, AND POSSIBLY OTHER INPUTS, BEFORE 00494 C CALLING THE SOLVER AGAIN. 00495 C 00496 C IOPT = AN INTEGER FLAG TO SPECIFY WHETHER OR NOT ANY OPTIONAL 00497 C INPUTS ARE BEING USED ON THIS CALL. INPUT ONLY. 00498 C THE OPTIONAL INPUTS ARE LISTED SEPARATELY BELOW. 00499 C IOPT = 0 MEANS NO OPTIONAL INPUTS ARE BEING USED. 00500 C DEFAULT VALUES WILL BE USED IN ALL CASES. 00501 C IOPT = 1 MEANS ONE OR MORE OPTIONAL INPUTS ARE BEING USED. 00502 C 00503 C RWORK = A REAL WORKING ARRAY (DOUBLE PRECISION). 00504 C THE LENGTH OF RWORK MUST BE AT LEAST 00505 C 20 + NYH*(MAXORD + 1) + 3*NEQ + LWM WHERE 00506 C NYH = THE INITIAL VALUE OF NEQ, 00507 C MAXORD = 12 (IF METH = 1) OR 5 (IF METH = 2) (UNLESS A 00508 C SMALLER VALUE IS GIVEN AS AN OPTIONAL INPUT), 00509 C LWM = 0 IF MITER = 0, 00510 C LWM = NEQ**2 + 2 IF MITER IS 1 OR 2, 00511 C LWM = NEQ + 2 IF MITER = 3, AND 00512 C LWM = (2*ML+MU+1)*NEQ + 2 IF MITER IS 4 OR 5. 00513 C (SEE THE MF DESCRIPTION FOR METH AND MITER.) 00514 C THUS IF MAXORD HAS ITS DEFAULT VALUE AND NEQ IS CONSTANT, 00515 C THIS LENGTH IS.. 00516 C 20 + 16*NEQ FOR MF = 10, 00517 C 22 + 16*NEQ + NEQ**2 FOR MF = 11 OR 12, 00518 C 22 + 17*NEQ FOR MF = 13, 00519 C 22 + 17*NEQ + (2*ML+MU)*NEQ FOR MF = 14 OR 15, 00520 C 20 + 9*NEQ FOR MF = 20, 00521 C 22 + 9*NEQ + NEQ**2 FOR MF = 21 OR 22, 00522 C 22 + 10*NEQ FOR MF = 23, 00523 C 22 + 10*NEQ + (2*ML+MU)*NEQ FOR MF = 24 OR 25. 00524 C THE FIRST 20 WORDS OF RWORK ARE RESERVED FOR CONDITIONAL 00525 C AND OPTIONAL INPUTS AND OPTIONAL OUTPUTS. 00526 C 00527 C THE FOLLOWING WORD IN RWORK IS A CONDITIONAL INPUT.. 00528 C RWORK(1) = TCRIT = CRITICAL VALUE OF T WHICH THE SOLVER 00529 C IS NOT TO OVERSHOOT. REQUIRED IF ITASK IS 00530 C 4 OR 5, AND IGNORED OTHERWISE. (SEE ITASK.) 00531 C 00532 C LRW = THE LENGTH OF THE ARRAY RWORK, AS DECLARED BY THE USER. 00533 C (THIS WILL BE CHECKED BY THE SOLVER.) 00534 C 00535 C IWORK = AN INTEGER WORK ARRAY. THE LENGTH OF IWORK MUST BE AT LEAST 00536 C 20 IF MITER = 0 OR 3 (MF = 10, 13, 20, 23), OR 00537 C 20 + NEQ OTHERWISE (MF = 11, 12, 14, 15, 21, 22, 24, 25). 00538 C THE FIRST FEW WORDS OF IWORK ARE USED FOR CONDITIONAL AND 00539 C OPTIONAL INPUTS AND OPTIONAL OUTPUTS. 00540 C 00541 C THE FOLLOWING 2 WORDS IN IWORK ARE CONDITIONAL INPUTS.. 00542 C IWORK(1) = ML THESE ARE THE LOWER AND UPPER 00543 C IWORK(2) = MU HALF-BANDWIDTHS, RESPECTIVELY, OF THE 00544 C BANDED JACOBIAN, EXCLUDING THE MAIN DIAGONAL. 00545 C THE BAND IS DEFINED BY THE MATRIX LOCATIONS 00546 C (I,J) WITH I-ML .LE. J .LE. I+MU. ML AND MU 00547 C MUST SATISFY 0 .LE. ML,MU .LE. NEQ-1. 00548 C THESE ARE REQUIRED IF MITER IS 4 OR 5, AND 00549 C IGNORED OTHERWISE. ML AND MU MAY IN FACT BE 00550 C THE BAND PARAMETERS FOR A MATRIX TO WHICH 00551 C DF/DY IS ONLY APPROXIMATELY EQUAL. 00552 C 00553 C LIW = THE LENGTH OF THE ARRAY IWORK, AS DECLARED BY THE USER. 00554 C (THIS WILL BE CHECKED BY THE SOLVER.) 00555 C 00556 C NOTE.. THE WORK ARRAYS MUST NOT BE ALTERED BETWEEN CALLS TO LSODE 00557 C FOR THE SAME PROBLEM, EXCEPT POSSIBLY FOR THE CONDITIONAL AND 00558 C OPTIONAL INPUTS, AND EXCEPT FOR THE LAST 3*NEQ WORDS OF RWORK. 00559 C THE LATTER SPACE IS USED FOR INTERNAL SCRATCH SPACE, AND SO IS 00560 C AVAILABLE FOR USE BY THE USER OUTSIDE LSODE BETWEEN CALLS, IF 00561 C DESIRED (BUT NOT FOR USE BY F OR JAC). 00562 C 00563 C JAC = THE NAME OF THE USER-SUPPLIED ROUTINE (MITER = 1 OR 4) TO 00564 C COMPUTE THE JACOBIAN MATRIX, DF/DY, AS A FUNCTION OF 00565 C THE SCALAR T AND THE VECTOR Y. IT IS TO HAVE THE FORM 00566 C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD) 00567 C DIMENSION Y(1), PD(NROWPD,1) 00568 C WHERE NEQ, T, Y, ML, MU, AND NROWPD ARE INPUT AND THE ARRAY 00569 C PD IS TO BE LOADED WITH PARTIAL DERIVATIVES (ELEMENTS OF 00570 C THE JACOBIAN MATRIX) ON OUTPUT. PD MUST BE GIVEN A FIRST 00571 C DIMENSION OF NROWPD. T AND Y HAVE THE SAME MEANING AS IN 00572 C SUBROUTINE F. (IN THE DIMENSION STATEMENT ABOVE, 1 IS A 00573 C DUMMY DIMENSION.. IT CAN BE REPLACED BY ANY VALUE.) 00574 C IN THE FULL MATRIX CASE (MITER = 1), ML AND MU ARE 00575 C IGNORED, AND THE JACOBIAN IS TO BE LOADED INTO PD IN 00576 C COLUMNWISE MANNER, WITH DF(I)/DY(J) LOADED INTO PD(I,J). 00577 C IN THE BAND MATRIX CASE (MITER = 4), THE ELEMENTS 00578 C WITHIN THE BAND ARE TO BE LOADED INTO PD IN COLUMNWISE 00579 C MANNER, WITH DIAGONAL LINES OF DF/DY LOADED INTO THE ROWS 00580 C OF PD. THUS DF(I)/DY(J) IS TO BE LOADED INTO PD(I-J+MU+1,J). 00581 C ML AND MU ARE THE HALF-BANDWIDTH PARAMETERS (SEE IWORK). 00582 C THE LOCATIONS IN PD IN THE TWO TRIANGULAR AREAS WHICH 00583 C CORRESPOND TO NONEXISTENT MATRIX ELEMENTS CAN BE IGNORED 00584 C OR LOADED ARBITRARILY, AS THEY ARE OVERWRITTEN BY LSODE. 00585 C JAC NEED NOT PROVIDE DF/DY EXACTLY. A CRUDE 00586 C APPROXIMATION (POSSIBLY WITH A SMALLER BANDWIDTH) WILL DO. 00587 C IN EITHER CASE, PD IS PRESET TO ZERO BY THE SOLVER, 00588 C SO THAT ONLY THE NONZERO ELEMENTS NEED BE LOADED BY JAC. 00589 C EACH CALL TO JAC IS PRECEDED BY A CALL TO F WITH THE SAME 00590 C ARGUMENTS NEQ, T, AND Y. THUS TO GAIN SOME EFFICIENCY, 00591 C INTERMEDIATE QUANTITIES SHARED BY BOTH CALCULATIONS MAY BE 00592 C SAVED IN A USER COMMON BLOCK BY F AND NOT RECOMPUTED BY JAC, 00593 C IF DESIRED. ALSO, JAC MAY ALTER THE Y ARRAY, IF DESIRED. 00594 C JAC MUST BE DECLARED EXTERNAL IN THE CALLING PROGRAM. 00595 C SUBROUTINE JAC MAY ACCESS USER-DEFINED QUANTITIES IN 00596 C NEQ(2),... AND/OR IN Y(NEQ(1)+1),... IF NEQ IS AN ARRAY 00597 C (DIMENSIONED IN JAC) AND/OR Y HAS LENGTH EXCEEDING NEQ(1). 00598 C SEE THE DESCRIPTIONS OF NEQ AND Y ABOVE. 00599 C 00600 C MF = THE METHOD FLAG. USED ONLY FOR INPUT. THE LEGAL VALUES OF 00601 C MF ARE 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, AND 25. 00602 C MF HAS DECIMAL DIGITS METH AND MITER.. MF = 10*METH + MITER. 00603 C METH INDICATES THE BASIC LINEAR MULTISTEP METHOD.. 00604 C METH = 1 MEANS THE IMPLICIT ADAMS METHOD. 00605 C METH = 2 MEANS THE METHOD BASED ON BACKWARD 00606 C DIFFERENTIATION FORMULAS (BDF-S). 00607 C MITER INDICATES THE CORRECTOR ITERATION METHOD.. 00608 C MITER = 0 MEANS FUNCTIONAL ITERATION (NO JACOBIAN MATRIX 00609 C IS INVOLVED). 00610 C MITER = 1 MEANS CHORD ITERATION WITH A USER-SUPPLIED 00611 C FULL (NEQ BY NEQ) JACOBIAN. 00612 C MITER = 2 MEANS CHORD ITERATION WITH AN INTERNALLY 00613 C GENERATED (DIFFERENCE QUOTIENT) FULL JACOBIAN 00614 C (USING NEQ EXTRA CALLS TO F PER DF/DY VALUE). 00615 C MITER = 3 MEANS CHORD ITERATION WITH AN INTERNALLY 00616 C GENERATED DIAGONAL JACOBIAN APPROXIMATION. 00617 C (USING 1 EXTRA CALL TO F PER DF/DY EVALUATION). 00618 C MITER = 4 MEANS CHORD ITERATION WITH A USER-SUPPLIED 00619 C BANDED JACOBIAN. 00620 C MITER = 5 MEANS CHORD ITERATION WITH AN INTERNALLY 00621 C GENERATED BANDED JACOBIAN (USING ML+MU+1 EXTRA 00622 C CALLS TO F PER DF/DY EVALUATION). 00623 C IF MITER = 1 OR 4, THE USER MUST SUPPLY A SUBROUTINE JAC 00624 C (THE NAME IS ARBITRARY) AS DESCRIBED ABOVE UNDER JAC. 00625 C FOR OTHER VALUES OF MITER, A DUMMY ARGUMENT CAN BE USED. 00626 C----------------------------------------------------------------------- 00627 C OPTIONAL INPUTS. 00628 C 00629 C THE FOLLOWING IS A LIST OF THE OPTIONAL INPUTS PROVIDED FOR IN THE 00630 C CALL SEQUENCE. (SEE ALSO PART II.) FOR EACH SUCH INPUT VARIABLE, 00631 C THIS TABLE LISTS ITS NAME AS USED IN THIS DOCUMENTATION, ITS 00632 C LOCATION IN THE CALL SEQUENCE, ITS MEANING, AND THE DEFAULT VALUE. 00633 C THE USE OF ANY OF THESE INPUTS REQUIRES IOPT = 1, AND IN THAT 00634 C CASE ALL OF THESE INPUTS ARE EXAMINED. A VALUE OF ZERO FOR ANY 00635 C OF THESE OPTIONAL INPUTS WILL CAUSE THE DEFAULT VALUE TO BE USED. 00636 C THUS TO USE A SUBSET OF THE OPTIONAL INPUTS, SIMPLY PRELOAD 00637 C LOCATIONS 5 TO 10 IN RWORK AND IWORK TO 0.0 AND 0 RESPECTIVELY, AND 00638 C THEN SET THOSE OF INTEREST TO NONZERO VALUES. 00639 C 00640 C NAME LOCATION MEANING AND DEFAULT VALUE 00641 C 00642 C H0 RWORK(5) THE STEP SIZE TO BE ATTEMPTED ON THE FIRST STEP. 00643 C THE DEFAULT VALUE IS DETERMINED BY THE SOLVER. 00644 C 00645 C HMAX RWORK(6) THE MAXIMUM ABSOLUTE STEP SIZE ALLOWED. 00646 C THE DEFAULT VALUE IS INFINITE. 00647 C 00648 C HMIN RWORK(7) THE MINIMUM ABSOLUTE STEP SIZE ALLOWED. 00649 C THE DEFAULT VALUE IS 0. (THIS LOWER BOUND IS NOT 00650 C ENFORCED ON THE FINAL STEP BEFORE REACHING TCRIT 00651 C WHEN ITASK = 4 OR 5.) 00652 C 00653 C MAXORD IWORK(5) THE MAXIMUM ORDER TO BE ALLOWED. THE DEFAULT 00654 C VALUE IS 12 IF METH = 1, AND 5 IF METH = 2. 00655 C IF MAXORD EXCEEDS THE DEFAULT VALUE, IT WILL 00656 C BE REDUCED TO THE DEFAULT VALUE. 00657 C IF MAXORD IS CHANGED DURING THE PROBLEM, IT MAY 00658 C CAUSE THE CURRENT ORDER TO BE REDUCED. 00659 C 00660 C MXSTEP IWORK(6) MAXIMUM NUMBER OF (INTERNALLY DEFINED) STEPS 00661 C ALLOWED DURING ONE CALL TO THE SOLVER. 00662 C THE DEFAULT VALUE IS 500. 00663 C 00664 C MXHNIL IWORK(7) MAXIMUM NUMBER OF MESSAGES PRINTED (PER PROBLEM) 00665 C WARNING THAT T + H = T ON A STEP (H = STEP SIZE). 00666 C THIS MUST BE POSITIVE TO RESULT IN A NON-DEFAULT 00667 C VALUE. THE DEFAULT VALUE IS 10. 00668 C----------------------------------------------------------------------- 00669 C OPTIONAL OUTPUTS. 00670 C 00671 C AS OPTIONAL ADDITIONAL OUTPUT FROM LSODE, THE VARIABLES LISTED 00672 C BELOW ARE QUANTITIES RELATED TO THE PERFORMANCE OF LSODE 00673 C WHICH ARE AVAILABLE TO THE USER. THESE ARE COMMUNICATED BY WAY OF 00674 C THE WORK ARRAYS, BUT ALSO HAVE INTERNAL MNEMONIC NAMES AS SHOWN. 00675 C EXCEPT WHERE STATED OTHERWISE, ALL OF THESE OUTPUTS ARE DEFINED 00676 C ON ANY SUCCESSFUL RETURN FROM LSODE, AND ON ANY RETURN WITH 00677 C ISTATE = -1, -2, -4, -5, OR -6. ON AN ILLEGAL INPUT RETURN 00678 C (ISTATE = -3), THEY WILL BE UNCHANGED FROM THEIR EXISTING VALUES 00679 C (IF ANY), EXCEPT POSSIBLY FOR TOLSF, LENRW, AND LENIW. 00680 C ON ANY ERROR RETURN, OUTPUTS RELEVANT TO THE ERROR WILL BE DEFINED, 00681 C AS NOTED BELOW. 00682 C 00683 C NAME LOCATION MEANING 00684 C 00685 C HU RWORK(11) THE STEP SIZE IN T LAST USED (SUCCESSFULLY). 00686 C 00687 C HCUR RWORK(12) THE STEP SIZE TO BE ATTEMPTED ON THE NEXT STEP. 00688 C 00689 C TCUR RWORK(13) THE CURRENT VALUE OF THE INDEPENDENT VARIABLE 00690 C WHICH THE SOLVER HAS ACTUALLY REACHED, I.E. THE 00691 C CURRENT INTERNAL MESH POINT IN T. ON OUTPUT, TCUR 00692 C WILL ALWAYS BE AT LEAST AS FAR AS THE ARGUMENT 00693 C T, BUT MAY BE FARTHER (IF INTERPOLATION WAS DONE). 00694 C 00695 C TOLSF RWORK(14) A TOLERANCE SCALE FACTOR, GREATER THAN 1.0, 00696 C COMPUTED WHEN A REQUEST FOR TOO MUCH ACCURACY WAS 00697 C DETECTED (ISTATE = -3 IF DETECTED AT THE START OF 00698 C THE PROBLEM, ISTATE = -2 OTHERWISE). IF ITOL IS 00699 C LEFT UNALTERED BUT RTOL AND ATOL ARE UNIFORMLY 00700 C SCALED UP BY A FACTOR OF TOLSF FOR THE NEXT CALL, 00701 C THEN THE SOLVER IS DEEMED LIKELY TO SUCCEED. 00702 C (THE USER MAY ALSO IGNORE TOLSF AND ALTER THE 00703 C TOLERANCE PARAMETERS IN ANY OTHER WAY APPROPRIATE.) 00704 C 00705 C NST IWORK(11) THE NUMBER OF STEPS TAKEN FOR THE PROBLEM SO FAR. 00706 C 00707 C NFE IWORK(12) THE NUMBER OF F EVALUATIONS FOR THE PROBLEM SO FAR. 00708 C 00709 C NJE IWORK(13) THE NUMBER OF JACOBIAN EVALUATIONS (AND OF MATRIX 00710 C LU DECOMPOSITIONS) FOR THE PROBLEM SO FAR. 00711 C 00712 C NQU IWORK(14) THE METHOD ORDER LAST USED (SUCCESSFULLY). 00713 C 00714 C NQCUR IWORK(15) THE ORDER TO BE ATTEMPTED ON THE NEXT STEP. 00715 C 00716 C IMXER IWORK(16) THE INDEX OF THE COMPONENT OF LARGEST MAGNITUDE IN 00717 C THE WEIGHTED LOCAL ERROR VECTOR ( E(I)/EWT(I) ), 00718 C ON AN ERROR RETURN WITH ISTATE = -4 OR -5. 00719 C 00720 C LENRW IWORK(17) THE LENGTH OF RWORK ACTUALLY REQUIRED. 00721 C THIS IS DEFINED ON NORMAL RETURNS AND ON AN ILLEGAL 00722 C INPUT RETURN FOR INSUFFICIENT STORAGE. 00723 C 00724 C LENIW IWORK(18) THE LENGTH OF IWORK ACTUALLY REQUIRED. 00725 C THIS IS DEFINED ON NORMAL RETURNS AND ON AN ILLEGAL 00726 C INPUT RETURN FOR INSUFFICIENT STORAGE. 00727 C 00728 C THE FOLLOWING TWO ARRAYS ARE SEGMENTS OF THE RWORK ARRAY WHICH 00729 C MAY ALSO BE OF INTEREST TO THE USER AS OPTIONAL OUTPUTS. 00730 C FOR EACH ARRAY, THE TABLE BELOW GIVES ITS INTERNAL NAME, 00731 C ITS BASE ADDRESS IN RWORK, AND ITS DESCRIPTION. 00732 C 00733 C NAME BASE ADDRESS DESCRIPTION 00734 C 00735 C YH 21 THE NORDSIECK HISTORY ARRAY, OF SIZE NYH BY 00736 C (NQCUR + 1), WHERE NYH IS THE INITIAL VALUE 00737 C OF NEQ. FOR J = 0,1,...,NQCUR, COLUMN J+1 00738 C OF YH CONTAINS HCUR**J/FACTORIAL(J) TIMES 00739 C THE J-TH DERIVATIVE OF THE INTERPOLATING 00740 C POLYNOMIAL CURRENTLY REPRESENTING THE SOLUTION, 00741 C EVALUATED AT T = TCUR. 00742 C 00743 C ACOR LENRW-NEQ+1 ARRAY OF SIZE NEQ USED FOR THE ACCUMULATED 00744 C CORRECTIONS ON EACH STEP, SCALED ON OUTPUT 00745 C TO REPRESENT THE ESTIMATED LOCAL ERROR IN Y 00746 C ON THE LAST STEP. THIS IS THE VECTOR E IN 00747 C THE DESCRIPTION OF THE ERROR CONTROL. IT IS 00748 C DEFINED ONLY ON A SUCCESSFUL RETURN FROM LSODE. 00749 C 00750 C----------------------------------------------------------------------- 00751 C PART II. OTHER ROUTINES CALLABLE. 00752 C 00753 C THE FOLLOWING ARE OPTIONAL CALLS WHICH THE USER MAY MAKE TO 00754 C GAIN ADDITIONAL CAPABILITIES IN CONJUNCTION WITH LSODE. 00755 C (THE ROUTINES XSETUN AND XSETF ARE DESIGNED TO CONFORM TO THE 00756 C SLATEC ERROR HANDLING PACKAGE.) 00757 C 00758 C FORM OF CALL FUNCTION 00759 C CALL XSETUN(LUN) SET THE LOGICAL UNIT NUMBER, LUN, FOR 00760 C OUTPUT OF MESSAGES FROM LSODE, IF 00761 C THE DEFAULT IS NOT DESIRED. 00762 C THE DEFAULT VALUE OF LUN IS 6. 00763 C 00764 C CALL XSETF(MFLAG) SET A FLAG TO CONTROL THE PRINTING OF 00765 C MESSAGES BY LSODE. 00766 C MFLAG = 0 MEANS DO NOT PRINT. (DANGER.. 00767 C THIS RISKS LOSING VALUABLE INFORMATION.) 00768 C MFLAG = 1 MEANS PRINT (THE DEFAULT). 00769 C 00770 C EITHER OF THE ABOVE CALLS MAY BE MADE AT 00771 C ANY TIME AND WILL TAKE EFFECT IMMEDIATELY. 00772 C 00773 C CALL SRCOM(RSAV,ISAV,JOB) SAVES AND RESTORES THE CONTENTS OF 00774 C THE INTERNAL COMMON BLOCKS USED BY 00775 C LSODE (SEE PART III BELOW). 00776 C RSAV MUST BE A REAL ARRAY OF LENGTH 218 00777 C OR MORE, AND ISAV MUST BE AN INTEGER 00778 C ARRAY OF LENGTH 41 OR MORE. 00779 C JOB=1 MEANS SAVE COMMON INTO RSAV/ISAV. 00780 C JOB=2 MEANS RESTORE COMMON FROM RSAV/ISAV. 00781 C SRCOM IS USEFUL IF ONE IS 00782 C INTERRUPTING A RUN AND RESTARTING 00783 C LATER, OR ALTERNATING BETWEEN TWO OR 00784 C MORE PROBLEMS SOLVED WITH LSODE. 00785 C 00786 C CALL INTDY(,,,,,) PROVIDE DERIVATIVES OF Y, OF VARIOUS 00787 C (SEE BELOW) ORDERS, AT A SPECIFIED POINT T, IF 00788 C DESIRED. IT MAY BE CALLED ONLY AFTER 00789 C A SUCCESSFUL RETURN FROM LSODE. 00790 C 00791 C THE DETAILED INSTRUCTIONS FOR USING INTDY ARE AS FOLLOWS. 00792 C THE FORM OF THE CALL IS.. 00793 C 00794 C CALL INTDY (T, K, RWORK(21), NYH, DKY, IFLAG) 00795 C 00796 C THE INPUT PARAMETERS ARE.. 00797 C 00798 C T = VALUE OF INDEPENDENT VARIABLE WHERE ANSWERS ARE DESIRED 00799 C (NORMALLY THE SAME AS THE T LAST RETURNED BY LSODE). 00800 C FOR VALID RESULTS, T MUST LIE BETWEEN TCUR - HU AND TCUR. 00801 C (SEE OPTIONAL OUTPUTS FOR TCUR AND HU.) 00802 C K = INTEGER ORDER OF THE DERIVATIVE DESIRED. K MUST SATISFY 00803 C 0 .LE. K .LE. NQCUR, WHERE NQCUR IS THE CURRENT ORDER 00804 C (SEE OPTIONAL OUTPUTS). THE CAPABILITY CORRESPONDING 00805 C TO K = 0, I.E. COMPUTING Y(T), IS ALREADY PROVIDED 00806 C BY LSODE DIRECTLY. SINCE NQCUR .GE. 1, THE FIRST 00807 C DERIVATIVE DY/DT IS ALWAYS AVAILABLE WITH INTDY. 00808 C RWORK(21) = THE BASE ADDRESS OF THE HISTORY ARRAY YH. 00809 C NYH = COLUMN LENGTH OF YH, EQUAL TO THE INITIAL VALUE OF NEQ. 00810 C 00811 C THE OUTPUT PARAMETERS ARE.. 00812 C 00813 C DKY = A REAL ARRAY OF LENGTH NEQ CONTAINING THE COMPUTED VALUE 00814 C OF THE K-TH DERIVATIVE OF Y(T). 00815 C IFLAG = INTEGER FLAG, RETURNED AS 0 IF K AND T WERE LEGAL, 00816 C -1 IF K WAS ILLEGAL, AND -2 IF T WAS ILLEGAL. 00817 C ON AN ERROR RETURN, A MESSAGE IS ALSO WRITTEN. 00818 C----------------------------------------------------------------------- 00819 C PART III. COMMON BLOCKS. 00820 C 00821 C IF LSODE IS TO BE USED IN AN OVERLAY SITUATION, THE USER 00822 C MUST DECLARE, IN THE PRIMARY OVERLAY, THE VARIABLES IN.. 00823 C (1) THE CALL SEQUENCE TO LSODE, 00824 C (2) THE INTERNAL COMMON BLOCK 00825 C /LS0001/ OF LENGTH 257 (218 DOUBLE PRECISION WORDS 00826 C FOLLOWED BY 39 INTEGER WORDS), 00827 C 00828 C IF LSODE IS USED ON A SYSTEM IN WHICH THE CONTENTS OF INTERNAL 00829 C COMMON BLOCKS ARE NOT PRESERVED BETWEEN CALLS, THE USER SHOULD 00830 C DECLARE THE ABOVE TWO COMMON BLOCKS IN HIS MAIN PROGRAM TO INSURE 00831 C THAT THEIR CONTENTS ARE PRESERVED. 00832 C 00833 C IF THE SOLUTION OF A GIVEN PROBLEM BY LSODE IS TO BE INTERRUPTED 00834 C AND THEN LATER CONTINUED, SUCH AS WHEN RESTARTING AN INTERRUPTED RUN 00835 C OR ALTERNATING BETWEEN TWO OR MORE PROBLEMS, THE USER SHOULD SAVE, 00836 C FOLLOWING THE RETURN FROM THE LAST LSODE CALL PRIOR TO THE 00837 C INTERRUPTION, THE CONTENTS OF THE CALL SEQUENCE VARIABLES AND THE 00838 C INTERNAL COMMON BLOCKS, AND LATER RESTORE THESE VALUES BEFORE THE 00839 C NEXT LSODE CALL FOR THAT PROBLEM. TO SAVE AND RESTORE THE COMMON 00840 C BLOCKS, USE SUBROUTINE SRCOM (SEE PART II ABOVE). 00841 C 00842 C----------------------------------------------------------------------- 00843 C PART IV. OPTIONALLY REPLACEABLE SOLVER ROUTINES. 00844 C 00845 C BELOW ARE DESCRIPTIONS OF TWO ROUTINES IN THE LSODE PACKAGE WHICH 00846 C RELATE TO THE MEASUREMENT OF ERRORS. EITHER ROUTINE CAN BE 00847 C REPLACED BY A USER-SUPPLIED VERSION, IF DESIRED. HOWEVER, SINCE SUCH 00848 C A REPLACEMENT MAY HAVE A MAJOR IMPACT ON PERFORMANCE, IT SHOULD BE 00849 C DONE ONLY WHEN ABSOLUTELY NECESSARY, AND ONLY WITH GREAT CAUTION. 00850 C (NOTE.. THE MEANS BY WHICH THE PACKAGE VERSION OF A ROUTINE IS 00851 C SUPERSEDED BY THE USER-S VERSION MAY BE SYSTEM-DEPENDENT.) 00852 C 00853 C (A) EWSET. 00854 C THE FOLLOWING SUBROUTINE IS CALLED JUST BEFORE EACH INTERNAL 00855 C INTEGRATION STEP, AND SETS THE ARRAY OF ERROR WEIGHTS, EWT, AS 00856 C DESCRIBED UNDER ITOL/RTOL/ATOL ABOVE.. 00857 C SUBROUTINE EWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT) 00858 C WHERE NEQ, ITOL, RTOL, AND ATOL ARE AS IN THE LSODE CALL SEQUENCE, 00859 C YCUR CONTAINS THE CURRENT DEPENDENT VARIABLE VECTOR, AND 00860 C EWT IS THE ARRAY OF WEIGHTS SET BY EWSET. 00861 C 00862 C IF THE USER SUPPLIES THIS SUBROUTINE, IT MUST RETURN IN EWT(I) 00863 C (I = 1,...,NEQ) A POSITIVE QUANTITY SUITABLE FOR COMPARING ERRORS 00864 C IN Y(I) TO. THE EWT ARRAY RETURNED BY EWSET IS PASSED TO THE 00865 C VNORM ROUTINE (SEE BELOW), AND ALSO USED BY LSODE IN THE COMPUTATION 00866 C OF THE OPTIONAL OUTPUT IMXER, THE DIAGONAL JACOBIAN APPROXIMATION, 00867 C AND THE INCREMENTS FOR DIFFERENCE QUOTIENT JACOBIANS. 00868 C 00869 C IN THE USER-SUPPLIED VERSION OF EWSET, IT MAY BE DESIRABLE TO USE 00870 C THE CURRENT VALUES OF DERIVATIVES OF Y. DERIVATIVES UP TO ORDER NQ 00871 C ARE AVAILABLE FROM THE HISTORY ARRAY YH, DESCRIBED ABOVE UNDER 00872 C OPTIONAL OUTPUTS. IN EWSET, YH IS IDENTICAL TO THE YCUR ARRAY, 00873 C EXTENDED TO NQ + 1 COLUMNS WITH A COLUMN LENGTH OF NYH AND SCALE 00874 C FACTORS OF H**J/FACTORIAL(J). ON THE FIRST CALL FOR THE PROBLEM, 00875 C GIVEN BY NST = 0, NQ IS 1 AND H IS TEMPORARILY SET TO 1.0. 00876 C THE QUANTITIES NQ, NYH, H, AND NST CAN BE OBTAINED BY INCLUDING 00877 C IN EWSET THE STATEMENTS.. 00878 C DOUBLE PRECISION H, RLS 00879 C COMMON /LS0001/ RLS(218),ILS(39) 00880 C NQ = ILS(35) 00881 C NYH = ILS(14) 00882 C NST = ILS(36) 00883 C H = RLS(212) 00884 C THUS, FOR EXAMPLE, THE CURRENT VALUE OF DY/DT CAN BE OBTAINED AS 00885 C YCUR(NYH+I)/H (I=1,...,NEQ) (AND THE DIVISION BY H IS 00886 C UNNECESSARY WHEN NST = 0). 00887 C 00888 C (B) VNORM. 00889 C THE FOLLOWING IS A REAL FUNCTION ROUTINE WHICH COMPUTES THE WEIGHTED 00890 C ROOT-MEAN-SQUARE NORM OF A VECTOR V.. 00891 C D = VNORM (N, V, W) 00892 C WHERE.. 00893 C N = THE LENGTH OF THE VECTOR, 00894 C V = REAL ARRAY OF LENGTH N CONTAINING THE VECTOR, 00895 C W = REAL ARRAY OF LENGTH N CONTAINING WEIGHTS, 00896 C D = SQRT( (1/N) * SUM(V(I)*W(I))**2 ). 00897 C VNORM IS CALLED WITH N = NEQ AND WITH W(I) = 1.0/EWT(I), WHERE 00898 C EWT IS AS SET BY SUBROUTINE EWSET. 00899 C 00900 C IF THE USER SUPPLIES THIS FUNCTION, IT SHOULD RETURN A NON-NEGATIVE 00901 C VALUE OF VNORM SUITABLE FOR USE IN THE ERROR CONTROL IN LSODE. 00902 C NONE OF THE ARGUMENTS SHOULD BE ALTERED BY VNORM. 00903 C FOR EXAMPLE, A USER-SUPPLIED VNORM ROUTINE MIGHT.. 00904 C -SUBSTITUTE A MAX-NORM OF (V(I)*W(I)) FOR THE RMS-NORM, OR 00905 C -IGNORE SOME COMPONENTS OF V IN THE NORM, WITH THE EFFECT OF 00906 C SUPPRESSING THE ERROR CONTROL ON THOSE COMPONENTS OF Y. 00907 C----------------------------------------------------------------------- 00908 C----------------------------------------------------------------------- 00909 C OTHER ROUTINES IN THE LSODE PACKAGE. 00910 C 00911 C IN ADDITION TO SUBROUTINE LSODE, THE LSODE PACKAGE INCLUDES THE 00912 C FOLLOWING SUBROUTINES AND FUNCTION ROUTINES.. 00913 C INTDY COMPUTES AN INTERPOLATED VALUE OF THE Y VECTOR AT T = TOUT. 00914 C STODE IS THE CORE INTEGRATOR, WHICH DOES ONE STEP OF THE 00915 C INTEGRATION AND THE ASSOCIATED ERROR CONTROL. 00916 C CFODE SETS ALL METHOD COEFFICIENTS AND TEST CONSTANTS. 00917 C PREPJ COMPUTES AND PREPROCESSES THE JACOBIAN MATRIX J = DF/DY 00918 C AND THE NEWTON ITERATION MATRIX P = I - H*L0*J. 00919 C SOLSY MANAGES SOLUTION OF LINEAR SYSTEM IN CHORD ITERATION. 00920 C EWSET SETS THE ERROR WEIGHT VECTOR EWT BEFORE EACH STEP. 00921 C VNORM COMPUTES THE WEIGHTED R.M.S. NORM OF A VECTOR. 00922 C SRCOM IS A USER-CALLABLE ROUTINE TO SAVE AND RESTORE 00923 C THE CONTENTS OF THE INTERNAL COMMON BLOCKS. 00924 C DGETRF AND DGETRS ARE ROUTINES FROM LAPACK FOR SOLVING FULL 00925 C SYSTEMS OF LINEAR ALGEBRAIC EQUATIONS. 00926 C DGBTRF AND DGBTRS ARE ROUTINES FROM LAPACK FOR SOLVING BANDED 00927 C LINEAR SYSTEMS. 00928 C DAXPY, DSCAL, IDAMAX, AND DDOT ARE BASIC LINEAR ALGEBRA MODULES 00929 C (BLAS) USED BY THE ABOVE LINPACK ROUTINES. 00930 C D1MACH COMPUTES THE UNIT ROUNDOFF IN A MACHINE-INDEPENDENT MANNER. 00931 C XERRWD, XSETUN, AND XSETF HANDLE THE PRINTING OF ALL ERROR 00932 C MESSAGES AND WARNINGS. XERRWD IS MACHINE-DEPENDENT. 00933 C NOTE.. VNORM, IDAMAX, DDOT, AND D1MACH ARE FUNCTION ROUTINES. 00934 C ALL THE OTHERS ARE SUBROUTINES. 00935 C 00936 C THE INTRINSIC AND EXTERNAL ROUTINES USED BY LSODE ARE.. 00937 C DABS, DMAX1, DMIN1, DBLE, MAX0, MIN0, MOD, DSIGN, DSQRT, AND WRITE. 00938 C 00939 C A BLOCK DATA SUBPROGRAM IS ALSO INCLUDED WITH THE PACKAGE, 00940 C FOR LOADING SOME OF THE VARIABLES IN INTERNAL COMMON. 00941 C 00942 C----------------------------------------------------------------------- 00943 C THE FOLLOWING CARD IS FOR OPTIMIZED COMPILATION ON LLNL COMPILERS. 00944 CLLL. OPTIMIZE 00945 C----------------------------------------------------------------------- 00946 EXTERNAL PREPJ, SOLSY 00947 INTEGER ILLIN, INIT, LYH, LEWT, LACOR, LSAVF, LWM, LIWM, 00948 1 MXSTEP, MXHNIL, NHNIL, NTREP, NSLAST, NYH, IOWNS 00949 INTEGER ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, METH, MITER, 00950 1 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU 00951 INTEGER I, I1, I2, IFLAG, IMXER, KGO, LF0, 00952 1 LENIW, LENRW, LENWM, ML, MORD, MU, MXHNL0, MXSTP0 00953 DOUBLE PRECISION ROWNS, 00954 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND 00955 DOUBLE PRECISION ATOLI, AYI, BIG, EWTI, H0, HMAX, HMX, RH, RTOLI, 00956 1 TCRIT, TDIST, TNEXT, TOL, TOLSF, TP, SIZE, SUM, W0, 00957 2 D1MACH, VNORM 00958 DIMENSION MORD(2) 00959 LOGICAL IHIT 00960 C----------------------------------------------------------------------- 00961 C THE FOLLOWING INTERNAL COMMON BLOCK CONTAINS 00962 C (A) VARIABLES WHICH ARE LOCAL TO ANY SUBROUTINE BUT WHOSE VALUES MUST 00963 C BE PRESERVED BETWEEN CALLS TO THE ROUTINE (OWN VARIABLES), AND 00964 C (B) VARIABLES WHICH ARE COMMUNICATED BETWEEN SUBROUTINES. 00965 C THE STRUCTURE OF THE BLOCK IS AS FOLLOWS.. ALL REAL VARIABLES ARE 00966 C LISTED FIRST, FOLLOWED BY ALL INTEGERS. WITHIN EACH TYPE, THE 00967 C VARIABLES ARE GROUPED WITH THOSE LOCAL TO SUBROUTINE LSODE FIRST, 00968 C THEN THOSE LOCAL TO SUBROUTINE STODE, AND FINALLY THOSE USED 00969 C FOR COMMUNICATION. THE BLOCK IS DECLARED IN SUBROUTINES 00970 C LSODE, INTDY, STODE, PREPJ, AND SOLSY. GROUPS OF VARIABLES ARE 00971 C REPLACED BY DUMMY ARRAYS IN THE COMMON DECLARATIONS IN ROUTINES 00972 C WHERE THOSE VARIABLES ARE NOT USED. 00973 C----------------------------------------------------------------------- 00974 COMMON /LS0001/ ROWNS(209), 00975 1 CCMAX, EL0, H, HMIN, HMXI, HU, RC, TN, UROUND, 00976 2 ILLIN, INIT, LYH, LEWT, LACOR, LSAVF, LWM, LIWM, 00977 3 MXSTEP, MXHNIL, NHNIL, NTREP, NSLAST, NYH, IOWNS(6), 00978 4 ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, METH, MITER, 00979 5 MAXORD, MAXCOR, MSBP, MXNCF, N, NQ, NST, NFE, NJE, NQU 00980 C 00981 DATA MORD(1),MORD(2)/12,5/, MXSTP0/500/, MXHNL0/10/ 00982 C----------------------------------------------------------------------- 00983 C BLOCK A. 00984 C THIS CODE BLOCK IS EXECUTED ON EVERY CALL. 00985 C IT TESTS ISTATE AND ITASK FOR LEGALITY AND BRANCHES APPROPRIATELY. 00986 C IF ISTATE .GT. 1 BUT THE FLAG INIT SHOWS THAT INITIALIZATION HAS 00987 C NOT YET BEEN DONE, AN ERROR RETURN OCCURS. 00988 C IF ISTATE = 1 AND TOUT = T, JUMP TO BLOCK G AND RETURN IMMEDIATELY. 00989 C----------------------------------------------------------------------- 00990 IF (ISTATE .LT. 1 .OR. ISTATE .GT. 3) GO TO 601 00991 IF (ITASK .LT. 1 .OR. ITASK .GT. 5) GO TO 602 00992 IF (ISTATE .EQ. 1) GO TO 10 00993 IF (INIT .EQ. 0) GO TO 603 00994 IF (ISTATE .EQ. 2) GO TO 200 00995 GO TO 20 00996 10 INIT = 0 00997 IF (TOUT .EQ. T) GO TO 430 00998 20 NTREP = 0 00999 C----------------------------------------------------------------------- 01000 C BLOCK B. 01001 C THE NEXT CODE BLOCK IS EXECUTED FOR THE INITIAL CALL (ISTATE = 1), 01002 C OR FOR A CONTINUATION CALL WITH PARAMETER CHANGES (ISTATE = 3). 01003 C IT CONTAINS CHECKING OF ALL INPUTS AND VARIOUS INITIALIZATIONS. 01004 C 01005 C FIRST CHECK LEGALITY OF THE NON-OPTIONAL INPUTS NEQ, ITOL, IOPT, 01006 C MF, ML, AND MU. 01007 C----------------------------------------------------------------------- 01008 IF (NEQ(1) .LE. 0) GO TO 604 01009 IF (ISTATE .EQ. 1) GO TO 25 01010 IF (NEQ(1) .GT. N) GO TO 605 01011 25 N = NEQ(1) 01012 IF (ITOL .LT. 1 .OR. ITOL .GT. 4) GO TO 606 01013 IF (IOPT .LT. 0 .OR. IOPT .GT. 1) GO TO 607 01014 METH = MF/10 01015 MITER = MF - 10*METH 01016 IF (METH .LT. 1 .OR. METH .GT. 2) GO TO 608 01017 IF (MITER .LT. 0 .OR. MITER .GT. 5) GO TO 608 01018 IF (MITER .LE. 3) GO TO 30 01019 ML = IWORK(1) 01020 MU = IWORK(2) 01021 IF (ML .LT. 0 .OR. ML .GE. N) GO TO 609 01022 IF (MU .LT. 0 .OR. MU .GE. N) GO TO 610 01023 30 CONTINUE 01024 C NEXT PROCESS AND CHECK THE OPTIONAL INPUTS. -------------------------- 01025 IF (IOPT .EQ. 1) GO TO 40 01026 MAXORD = MORD(METH) 01027 MXSTEP = MXSTP0 01028 MXHNIL = MXHNL0 01029 IF (ISTATE .EQ. 1) H0 = 0.0D0 01030 HMXI = 0.0D0 01031 HMIN = 0.0D0 01032 GO TO 60 01033 40 MAXORD = IWORK(5) 01034 IF (MAXORD .LT. 0) GO TO 611 01035 IF (MAXORD .EQ. 0) MAXORD = 100 01036 MAXORD = MIN0(MAXORD,MORD(METH)) 01037 MXSTEP = IWORK(6) 01038 IF (MXSTEP .LT. 0) GO TO 612 01039 IF (MXSTEP .EQ. 0) MXSTEP = MXSTP0 01040 MXHNIL = IWORK(7) 01041 IF (MXHNIL .LT. 0) GO TO 613 01042 IF (MXHNIL .EQ. 0) MXHNIL = MXHNL0 01043 IF (ISTATE .NE. 1) GO TO 50 01044 H0 = RWORK(5) 01045 IF ((TOUT - T)*H0 .LT. 0.0D0) GO TO 614 01046 50 HMAX = RWORK(6) 01047 IF (HMAX .LT. 0.0D0) GO TO 615 01048 HMXI = 0.0D0 01049 IF (HMAX .GT. 0.0D0) HMXI = 1.0D0/HMAX 01050 HMIN = RWORK(7) 01051 IF (HMIN .LT. 0.0D0) GO TO 616 01052 C----------------------------------------------------------------------- 01053 C SET WORK ARRAY POINTERS AND CHECK LENGTHS LRW AND LIW. 01054 C POINTERS TO SEGMENTS OF RWORK AND IWORK ARE NAMED BY PREFIXING L TO 01055 C THE NAME OF THE SEGMENT. E.G., THE SEGMENT YH STARTS AT RWORK(LYH). 01056 C SEGMENTS OF RWORK (IN ORDER) ARE DENOTED YH, WM, EWT, SAVF, ACOR. 01057 C----------------------------------------------------------------------- 01058 60 LYH = 21 01059 IF (ISTATE .EQ. 1) NYH = N 01060 LWM = LYH + (MAXORD + 1)*NYH 01061 IF (MITER .EQ. 0) LENWM = 0 01062 IF (MITER .EQ. 1 .OR. MITER .EQ. 2) LENWM = N*N + 2 01063 IF (MITER .EQ. 3) LENWM = N + 2 01064 IF (MITER .GE. 4) LENWM = (2*ML + MU + 1)*N + 2 01065 LEWT = LWM + LENWM 01066 LSAVF = LEWT + N 01067 LACOR = LSAVF + N 01068 LENRW = LACOR + N - 1 01069 IWORK(17) = LENRW 01070 LIWM = 1 01071 LENIW = 20 + N 01072 IF (MITER .EQ. 0 .OR. MITER .EQ. 3) LENIW = 20 01073 IWORK(18) = LENIW 01074 IF (LENRW .GT. LRW) GO TO 617 01075 IF (LENIW .GT. LIW) GO TO 618 01076 C CHECK RTOL AND ATOL FOR LEGALITY. ------------------------------------ 01077 RTOLI = RTOL(1) 01078 ATOLI = ATOL(1) 01079 DO 70 I = 1,N 01080 IF (ITOL .GE. 3) RTOLI = RTOL(I) 01081 IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) 01082 IF (RTOLI .LT. 0.0D0) GO TO 619 01083 IF (ATOLI .LT. 0.0D0) GO TO 620 01084 70 CONTINUE 01085 IF (ISTATE .EQ. 1) GO TO 100 01086 C IF ISTATE = 3, SET FLAG TO SIGNAL PARAMETER CHANGES TO STODE. -------- 01087 JSTART = -1 01088 IF (NQ .LE. MAXORD) GO TO 90 01089 C MAXORD WAS REDUCED BELOW NQ. COPY YH(*,MAXORD+2) INTO SAVF. --------- 01090 DO 80 I = 1,N 01091 80 RWORK(I+LSAVF-1) = RWORK(I+LWM-1) 01092 C RELOAD WM(1) = RWORK(LWM), SINCE LWM MAY HAVE CHANGED. --------------- 01093 90 IF (MITER .GT. 0) RWORK(LWM) = DSQRT(UROUND) 01094 IF (N .EQ. NYH) GO TO 200 01095 C NEQ WAS REDUCED. ZERO PART OF YH TO AVOID UNDEFINED REFERENCES. ----- 01096 I1 = LYH + L*NYH 01097 I2 = LYH + (MAXORD + 1)*NYH - 1 01098 IF (I1 .GT. I2) GO TO 200 01099 DO 95 I = I1,I2 01100 95 RWORK(I) = 0.0D0 01101 GO TO 200 01102 C----------------------------------------------------------------------- 01103 C BLOCK C. 01104 C THE NEXT BLOCK IS FOR THE INITIAL CALL ONLY (ISTATE = 1). 01105 C IT CONTAINS ALL REMAINING INITIALIZATIONS, THE INITIAL CALL TO F, 01106 C AND THE CALCULATION OF THE INITIAL STEP SIZE. 01107 C THE ERROR WEIGHTS IN EWT ARE INVERTED AFTER BEING LOADED. 01108 C----------------------------------------------------------------------- 01109 100 UROUND = D1MACH(4) 01110 TN = T 01111 IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 110 01112 TCRIT = RWORK(1) 01113 IF ((TCRIT - TOUT)*(TOUT - T) .LT. 0.0D0) GO TO 625 01114 IF (H0 .NE. 0.0D0 .AND. (T + H0 - TCRIT)*H0 .GT. 0.0D0) 01115 1 H0 = TCRIT - T 01116 110 JSTART = 0 01117 IF (MITER .GT. 0) RWORK(LWM) = DSQRT(UROUND) 01118 NHNIL = 0 01119 NST = 0 01120 NJE = 0 01121 NSLAST = 0 01122 HU = 0.0D0 01123 NQU = 0 01124 CCMAX = 0.3D0 01125 MAXCOR = 3 01126 MSBP = 20 01127 MXNCF = 10 01128 C INITIAL CALL TO F. (LF0 POINTS TO YH(*,2).) ------------------------- 01129 LF0 = LYH + NYH 01130 IERR = 0 01131 CALL F (NEQ, T, Y, RWORK(LF0), IERR) 01132 IF (IERR .LT. 0) THEN 01133 ISTATE = -13 01134 RETURN 01135 ENDIF 01136 NFE = 1 01137 C LOAD THE INITIAL VALUE VECTOR IN YH. --------------------------------- 01138 DO 115 I = 1,N 01139 115 RWORK(I+LYH-1) = Y(I) 01140 C LOAD AND INVERT THE EWT ARRAY. (H IS TEMPORARILY SET TO 1.0.) ------- 01141 NQ = 1 01142 H = 1.0D0 01143 CALL EWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) 01144 DO 120 I = 1,N 01145 IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 621 01146 120 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) 01147 C----------------------------------------------------------------------- 01148 C THE CODING BELOW COMPUTES THE STEP SIZE, H0, TO BE ATTEMPTED ON THE 01149 C FIRST STEP, UNLESS THE USER HAS SUPPLIED A VALUE FOR THIS. 01150 C FIRST CHECK THAT TOUT - T DIFFERS SIGNIFICANTLY FROM ZERO. 01151 C A SCALAR TOLERANCE QUANTITY TOL IS COMPUTED, AS MAX(RTOL(I)) 01152 C IF THIS IS POSITIVE, OR MAX(ATOL(I)/ABS(Y(I))) OTHERWISE, ADJUSTED 01153 C SO AS TO BE BETWEEN 100*UROUND AND 1.0E-3. 01154 C THEN THE COMPUTED VALUE H0 IS GIVEN BY.. 01155 C NEQ 01156 C H0**2 = TOL / ( W0**-2 + (1/NEQ) * SUM ( F(I)/YWT(I) )**2 ) 01157 C 1 01158 C WHERE W0 = MAX ( ABS(T), ABS(TOUT) ), 01159 C F(I) = I-TH COMPONENT OF INITIAL VALUE OF F, 01160 C YWT(I) = EWT(I)/TOL (A WEIGHT FOR Y(I)). 01161 C THE SIGN OF H0 IS INFERRED FROM THE INITIAL VALUES OF TOUT AND T. 01162 C----------------------------------------------------------------------- 01163 IF (H0 .NE. 0.0D0) GO TO 180 01164 TDIST = DABS(TOUT - T) 01165 W0 = DMAX1(DABS(T),DABS(TOUT)) 01166 IF (TDIST .LT. 2.0D0*UROUND*W0) GO TO 622 01167 TOL = RTOL(1) 01168 IF (ITOL .LE. 2) GO TO 140 01169 DO 130 I = 1,N 01170 130 TOL = DMAX1(TOL,RTOL(I)) 01171 140 IF (TOL .GT. 0.0D0) GO TO 160 01172 ATOLI = ATOL(1) 01173 DO 150 I = 1,N 01174 IF (ITOL .EQ. 2 .OR. ITOL .EQ. 4) ATOLI = ATOL(I) 01175 AYI = DABS(Y(I)) 01176 IF (AYI .NE. 0.0D0) TOL = DMAX1(TOL,ATOLI/AYI) 01177 150 CONTINUE 01178 160 TOL = DMAX1(TOL,100.0D0*UROUND) 01179 TOL = DMIN1(TOL,0.001D0) 01180 SUM = VNORM (N, RWORK(LF0), RWORK(LEWT)) 01181 SUM = 1.0D0/(TOL*W0*W0) + TOL*SUM**2 01182 H0 = 1.0D0/DSQRT(SUM) 01183 H0 = DMIN1(H0,TDIST) 01184 H0 = DSIGN(H0,TOUT-T) 01185 C ADJUST H0 IF NECESSARY TO MEET HMAX BOUND. --------------------------- 01186 180 RH = DABS(H0)*HMXI 01187 IF (RH .GT. 1.0D0) H0 = H0/RH 01188 C LOAD H WITH H0 AND SCALE YH(*,2) BY H0. ------------------------------ 01189 H = H0 01190 DO 190 I = 1,N 01191 190 RWORK(I+LF0-1) = H0*RWORK(I+LF0-1) 01192 GO TO 270 01193 C----------------------------------------------------------------------- 01194 C BLOCK D. 01195 C THE NEXT CODE BLOCK IS FOR CONTINUATION CALLS ONLY (ISTATE = 2 OR 3) 01196 C AND IS TO CHECK STOP CONDITIONS BEFORE TAKING A STEP. 01197 C----------------------------------------------------------------------- 01198 200 NSLAST = NST 01199 GO TO (210, 250, 220, 230, 240), ITASK 01200 210 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 01201 CALL INTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) 01202 IF (IFLAG .NE. 0) GO TO 627 01203 T = TOUT 01204 GO TO 420 01205 220 TP = TN - HU*(1.0D0 + 100.0D0*UROUND) 01206 IF ((TP - TOUT)*H .GT. 0.0D0) GO TO 623 01207 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 01208 GO TO 400 01209 230 TCRIT = RWORK(1) 01210 IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 01211 IF ((TCRIT - TOUT)*H .LT. 0.0D0) GO TO 625 01212 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 245 01213 CALL INTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) 01214 IF (IFLAG .NE. 0) GO TO 627 01215 T = TOUT 01216 GO TO 420 01217 240 TCRIT = RWORK(1) 01218 IF ((TN - TCRIT)*H .GT. 0.0D0) GO TO 624 01219 245 HMX = DABS(TN) + DABS(H) 01220 IHIT = DABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX 01221 IF (IHIT) GO TO 400 01222 TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) 01223 IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 01224 H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) 01225 IF (ISTATE .EQ. 2) JSTART = -2 01226 C----------------------------------------------------------------------- 01227 C BLOCK E. 01228 C THE NEXT BLOCK IS NORMALLY EXECUTED FOR ALL CALLS AND CONTAINS 01229 C THE CALL TO THE ONE-STEP CORE INTEGRATOR STODE. 01230 C 01231 C THIS IS A LOOPING POINT FOR THE INTEGRATION STEPS. 01232 C 01233 C FIRST CHECK FOR TOO MANY STEPS BEING TAKEN, UPDATE EWT (IF NOT AT 01234 C START OF PROBLEM), CHECK FOR TOO MUCH ACCURACY BEING REQUESTED, AND 01235 C CHECK FOR H BELOW THE ROUNDOFF LEVEL IN T. 01236 C----------------------------------------------------------------------- 01237 250 CONTINUE 01238 IF ((NST-NSLAST) .GE. MXSTEP) GO TO 500 01239 CALL EWSET (N, ITOL, RTOL, ATOL, RWORK(LYH), RWORK(LEWT)) 01240 DO 260 I = 1,N 01241 IF (RWORK(I+LEWT-1) .LE. 0.0D0) GO TO 510 01242 260 RWORK(I+LEWT-1) = 1.0D0/RWORK(I+LEWT-1) 01243 270 TOLSF = UROUND*VNORM (N, RWORK(LYH), RWORK(LEWT)) 01244 IF (TOLSF .LE. 1.0D0) GO TO 280 01245 TOLSF = TOLSF*2.0D0 01246 IF (NST .EQ. 0) GO TO 626 01247 GO TO 520 01248 280 IF ((TN + H) .NE. TN) GO TO 290 01249 NHNIL = NHNIL + 1 01250 IF (NHNIL .GT. MXHNIL) GO TO 290 01251 CALL XERRWD('LSODE-- WARNING..INTERNAL T (=R1) AND H (=R2) ARE', 01252 1 50, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01253 CALL XERRWD( 01254 1 ' SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP ', 01255 1 60, 101, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01256 CALL XERRWD(' (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY', 01257 1 50, 101, 0, 0, 0, 0, 2, TN, H) 01258 IF (NHNIL .LT. MXHNIL) GO TO 290 01259 CALL XERRWD('LSODE-- ABOVE WARNING HAS BEEN ISSUED I1 TIMES. ', 01260 1 50, 102, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01261 CALL XERRWD(' IT WILL NOT BE ISSUED AGAIN FOR THIS PROBLEM', 01262 1 50, 102, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) 01263 290 CONTINUE 01264 C----------------------------------------------------------------------- 01265 C CALL STODE(NEQ,Y,YH,NYH,YH,EWT,SAVF,ACOR,WM,IWM,F,JAC,PREPJ,SOLSY) 01266 C----------------------------------------------------------------------- 01267 IERR = 0 01268 CALL STODE (NEQ, Y, RWORK(LYH), NYH, RWORK(LYH), RWORK(LEWT), 01269 1 RWORK(LSAVF), RWORK(LACOR), RWORK(LWM), IWORK(LIWM), 01270 2 F, JAC, PREPJ, SOLSY, IERR) 01271 IF (IERR .LT. 0) THEN 01272 ISTATE = -13 01273 RETURN 01274 ENDIF 01275 KGO = 1 - KFLAG 01276 GO TO (300, 530, 540), KGO 01277 C----------------------------------------------------------------------- 01278 C BLOCK F. 01279 C THE FOLLOWING BLOCK HANDLES THE CASE OF A SUCCESSFUL RETURN FROM THE 01280 C CORE INTEGRATOR (KFLAG = 0). TEST FOR STOP CONDITIONS. 01281 C----------------------------------------------------------------------- 01282 300 INIT = 1 01283 GO TO (310, 400, 330, 340, 350), ITASK 01284 C ITASK = 1. IF TOUT HAS BEEN REACHED, INTERPOLATE. ------------------- 01285 310 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 250 01286 CALL INTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) 01287 T = TOUT 01288 GO TO 420 01289 C ITASK = 3. JUMP TO EXIT IF TOUT WAS REACHED. ------------------------ 01290 330 IF ((TN - TOUT)*H .GE. 0.0D0) GO TO 400 01291 GO TO 250 01292 C ITASK = 4. SEE IF TOUT OR TCRIT WAS REACHED. ADJUST H IF NECESSARY. 01293 340 IF ((TN - TOUT)*H .LT. 0.0D0) GO TO 345 01294 CALL INTDY (TOUT, 0, RWORK(LYH), NYH, Y, IFLAG) 01295 T = TOUT 01296 GO TO 420 01297 345 HMX = DABS(TN) + DABS(H) 01298 IHIT = DABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX 01299 IF (IHIT) GO TO 400 01300 TNEXT = TN + H*(1.0D0 + 4.0D0*UROUND) 01301 IF ((TNEXT - TCRIT)*H .LE. 0.0D0) GO TO 250 01302 H = (TCRIT - TN)*(1.0D0 - 4.0D0*UROUND) 01303 JSTART = -2 01304 GO TO 250 01305 C ITASK = 5. SEE IF TCRIT WAS REACHED AND JUMP TO EXIT. --------------- 01306 350 HMX = DABS(TN) + DABS(H) 01307 IHIT = DABS(TN - TCRIT) .LE. 100.0D0*UROUND*HMX 01308 C----------------------------------------------------------------------- 01309 C BLOCK G. 01310 C THE FOLLOWING BLOCK HANDLES ALL SUCCESSFUL RETURNS FROM LSODE. 01311 C IF ITASK .NE. 1, Y IS LOADED FROM YH AND T IS SET ACCORDINGLY. 01312 C ISTATE IS SET TO 2, THE ILLEGAL INPUT COUNTER IS ZEROED, AND THE 01313 C OPTIONAL OUTPUTS ARE LOADED INTO THE WORK ARRAYS BEFORE RETURNING. 01314 C IF ISTATE = 1 AND TOUT = T, THERE IS A RETURN WITH NO ACTION TAKEN, 01315 C EXCEPT THAT IF THIS HAS HAPPENED REPEATEDLY, THE RUN IS TERMINATED. 01316 C----------------------------------------------------------------------- 01317 400 DO 410 I = 1,N 01318 410 Y(I) = RWORK(I+LYH-1) 01319 T = TN 01320 IF (ITASK .NE. 4 .AND. ITASK .NE. 5) GO TO 420 01321 IF (IHIT) T = TCRIT 01322 420 ISTATE = 2 01323 ILLIN = 0 01324 RWORK(11) = HU 01325 RWORK(12) = H 01326 RWORK(13) = TN 01327 IWORK(11) = NST 01328 IWORK(12) = NFE 01329 IWORK(13) = NJE 01330 IWORK(14) = NQU 01331 IWORK(15) = NQ 01332 RETURN 01333 C 01334 430 NTREP = NTREP + 1 01335 IF (NTREP .LT. 5) RETURN 01336 CALL XERRWD( 01337 1 'LSODE-- REPEATED CALLS WITH ISTATE = 1 AND TOUT = T (=R1) ', 01338 1 60, 301, 0, 0, 0, 0, 1, T, 0.0D0) 01339 GO TO 800 01340 C----------------------------------------------------------------------- 01341 C BLOCK H. 01342 C THE FOLLOWING BLOCK HANDLES ALL UNSUCCESSFUL RETURNS OTHER THAN 01343 C THOSE FOR ILLEGAL INPUT. FIRST THE ERROR MESSAGE ROUTINE IS CALLED. 01344 C IF THERE WAS AN ERROR TEST OR CONVERGENCE TEST FAILURE, IMXER IS SET. 01345 C THEN Y IS LOADED FROM YH, T IS SET TO TN, AND THE ILLEGAL INPUT 01346 C COUNTER ILLIN IS SET TO 0. THE OPTIONAL OUTPUTS ARE LOADED INTO 01347 C THE WORK ARRAYS BEFORE RETURNING. 01348 C----------------------------------------------------------------------- 01349 C THE MAXIMUM NUMBER OF STEPS WAS TAKEN BEFORE REACHING TOUT. ---------- 01350 500 CALL XERRWD('LSODE-- AT CURRENT T (=R1), MXSTEP (=I1) STEPS ', 01351 1 50, 201, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01352 CALL XERRWD(' TAKEN ON THIS CALL BEFORE REACHING TOUT ', 01353 1 50, 201, 0, 1, MXSTEP, 0, 1, TN, 0.0D0) 01354 ISTATE = -1 01355 GO TO 580 01356 C EWT(I) .LE. 0.0 FOR SOME I (NOT AT START OF PROBLEM). ---------------- 01357 510 EWTI = RWORK(LEWT+I-1) 01358 CALL XERRWD('LSODE-- AT T (=R1), EWT(I1) HAS BECOME R2 .LE. 0.', 01359 1 50, 202, 0, 1, I, 0, 2, TN, EWTI) 01360 ISTATE = -6 01361 GO TO 580 01362 C TOO MUCH ACCURACY REQUESTED FOR MACHINE PRECISION. ------------------- 01363 520 CALL XERRWD('LSODE-- AT T (=R1), TOO MUCH ACCURACY REQUESTED ', 01364 1 50, 203, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01365 CALL XERRWD(' FOR PRECISION OF MACHINE.. SEE TOLSF (=R2) ', 01366 1 50, 203, 0, 0, 0, 0, 2, TN, TOLSF) 01367 RWORK(14) = TOLSF 01368 ISTATE = -2 01369 GO TO 580 01370 C KFLAG = -1. ERROR TEST FAILED REPEATEDLY OR WITH ABS(H) = HMIN. ----- 01371 530 CALL XERRWD('LSODE-- AT T(=R1) AND STEP SIZE H(=R2), THE ERROR', 01372 1 50, 204, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01373 CALL XERRWD(' TEST FAILED REPEATEDLY OR WITH ABS(H) = HMIN', 01374 1 50, 204, 0, 0, 0, 0, 2, TN, H) 01375 ISTATE = -4 01376 GO TO 560 01377 C KFLAG = -2. CONVERGENCE FAILED REPEATEDLY OR WITH ABS(H) = HMIN. ---- 01378 540 CALL XERRWD('LSODE-- AT T (=R1) AND STEP SIZE H (=R2), THE ', 01379 1 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01380 CALL XERRWD(' CORRECTOR CONVERGENCE FAILED REPEATEDLY ', 01381 1 50, 205, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01382 CALL XERRWD(' OR WITH ABS(H) = HMIN ', 01383 1 30, 205, 0, 0, 0, 0, 2, TN, H) 01384 ISTATE = -5 01385 C COMPUTE IMXER IF RELEVANT. ------------------------------------------- 01386 560 BIG = 0.0D0 01387 IMXER = 1 01388 DO 570 I = 1,N 01389 SIZE = DABS(RWORK(I+LACOR-1)*RWORK(I+LEWT-1)) 01390 IF (BIG .GE. SIZE) GO TO 570 01391 BIG = SIZE 01392 IMXER = I 01393 570 CONTINUE 01394 IWORK(16) = IMXER 01395 C SET Y VECTOR, T, ILLIN, AND OPTIONAL OUTPUTS. ------------------------ 01396 580 DO 590 I = 1,N 01397 590 Y(I) = RWORK(I+LYH-1) 01398 T = TN 01399 ILLIN = 0 01400 RWORK(11) = HU 01401 RWORK(12) = H 01402 RWORK(13) = TN 01403 IWORK(11) = NST 01404 IWORK(12) = NFE 01405 IWORK(13) = NJE 01406 IWORK(14) = NQU 01407 IWORK(15) = NQ 01408 RETURN 01409 C----------------------------------------------------------------------- 01410 C BLOCK I. 01411 C THE FOLLOWING BLOCK HANDLES ALL ERROR RETURNS DUE TO ILLEGAL INPUT 01412 C (ISTATE = -3), AS DETECTED BEFORE CALLING THE CORE INTEGRATOR. 01413 C FIRST THE ERROR MESSAGE ROUTINE IS CALLED. THEN IF THERE HAVE BEEN 01414 C 5 CONSECUTIVE SUCH RETURNS JUST BEFORE THIS CALL TO THE SOLVER, 01415 C THE RUN IS HALTED. 01416 C----------------------------------------------------------------------- 01417 601 CALL XERRWD('LSODE-- ISTATE (=I1) ILLEGAL ', 01418 1 30, 1, 0, 1, ISTATE, 0, 0, 0.0D0, 0.0D0) 01419 GO TO 700 01420 602 CALL XERRWD('LSODE-- ITASK (=I1) ILLEGAL ', 01421 1 30, 2, 0, 1, ITASK, 0, 0, 0.0D0, 0.0D0) 01422 GO TO 700 01423 603 CALL XERRWD('LSODE-- ISTATE .GT. 1 BUT LSODE NOT INITIALIZED ', 01424 1 50, 3, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01425 GO TO 700 01426 604 CALL XERRWD('LSODE-- NEQ (=I1) .LT. 1 ', 01427 1 30, 4, 0, 1, NEQ(1), 0, 0, 0.0D0, 0.0D0) 01428 GO TO 700 01429 605 CALL XERRWD('LSODE-- ISTATE = 3 AND NEQ INCREASED (I1 TO I2) ', 01430 1 50, 5, 0, 2, N, NEQ(1), 0, 0.0D0, 0.0D0) 01431 GO TO 700 01432 606 CALL XERRWD('LSODE-- ITOL (=I1) ILLEGAL ', 01433 1 30, 6, 0, 1, ITOL, 0, 0, 0.0D0, 0.0D0) 01434 GO TO 700 01435 607 CALL XERRWD('LSODE-- IOPT (=I1) ILLEGAL ', 01436 1 30, 7, 0, 1, IOPT, 0, 0, 0.0D0, 0.0D0) 01437 GO TO 700 01438 608 CALL XERRWD('LSODE-- MF (=I1) ILLEGAL ', 01439 1 30, 8, 0, 1, MF, 0, 0, 0.0D0, 0.0D0) 01440 GO TO 700 01441 609 CALL XERRWD('LSODE-- ML (=I1) ILLEGAL.. .LT.0 OR .GE.NEQ (=I2)', 01442 1 50, 9, 0, 2, ML, NEQ(1), 0, 0.0D0, 0.0D0) 01443 GO TO 700 01444 610 CALL XERRWD('LSODE-- MU (=I1) ILLEGAL.. .LT.0 OR .GE.NEQ (=I2)', 01445 1 50, 10, 0, 2, MU, NEQ(1), 0, 0.0D0, 0.0D0) 01446 GO TO 700 01447 611 CALL XERRWD('LSODE-- MAXORD (=I1) .LT. 0 ', 01448 1 30, 11, 0, 1, MAXORD, 0, 0, 0.0D0, 0.0D0) 01449 GO TO 700 01450 612 CALL XERRWD('LSODE-- MXSTEP (=I1) .LT. 0 ', 01451 1 30, 12, 0, 1, MXSTEP, 0, 0, 0.0D0, 0.0D0) 01452 GO TO 700 01453 613 CALL XERRWD('LSODE-- MXHNIL (=I1) .LT. 0 ', 01454 1 30, 13, 0, 1, MXHNIL, 0, 0, 0.0D0, 0.0D0) 01455 GO TO 700 01456 614 CALL XERRWD('LSODE-- TOUT (=R1) BEHIND T (=R2) ', 01457 1 40, 14, 0, 0, 0, 0, 2, TOUT, T) 01458 CALL XERRWD(' INTEGRATION DIRECTION IS GIVEN BY H0 (=R1) ', 01459 1 50, 14, 0, 0, 0, 0, 1, H0, 0.0D0) 01460 GO TO 700 01461 615 CALL XERRWD('LSODE-- HMAX (=R1) .LT. 0.0 ', 01462 1 30, 15, 0, 0, 0, 0, 1, HMAX, 0.0D0) 01463 GO TO 700 01464 616 CALL XERRWD('LSODE-- HMIN (=R1) .LT. 0.0 ', 01465 1 30, 16, 0, 0, 0, 0, 1, HMIN, 0.0D0) 01466 GO TO 700 01467 617 CALL XERRWD( 01468 1 'LSODE-- RWORK LENGTH NEEDED, LENRW (=I1), EXCEEDS LRW (=I2)', 01469 1 60, 17, 0, 2, LENRW, LRW, 0, 0.0D0, 0.0D0) 01470 GO TO 700 01471 618 CALL XERRWD( 01472 1 'LSODE-- IWORK LENGTH NEEDED, LENIW (=I1), EXCEEDS LIW (=I2)', 01473 1 60, 18, 0, 2, LENIW, LIW, 0, 0.0D0, 0.0D0) 01474 GO TO 700 01475 619 CALL XERRWD('LSODE-- RTOL(I1) IS R1 .LT. 0.0 ', 01476 1 40, 19, 0, 1, I, 0, 1, RTOLI, 0.0D0) 01477 GO TO 700 01478 620 CALL XERRWD('LSODE-- ATOL(I1) IS R1 .LT. 0.0 ', 01479 1 40, 20, 0, 1, I, 0, 1, ATOLI, 0.0D0) 01480 GO TO 700 01481 621 EWTI = RWORK(LEWT+I-1) 01482 CALL XERRWD('LSODE-- EWT(I1) IS R1 .LE. 0.0 ', 01483 1 40, 21, 0, 1, I, 0, 1, EWTI, 0.0D0) 01484 GO TO 700 01485 622 CALL XERRWD( 01486 1 'LSODE-- TOUT (=R1) TOO CLOSE TO T(=R2) TO START INTEGRATION', 01487 1 60, 22, 0, 0, 0, 0, 2, TOUT, T) 01488 GO TO 700 01489 623 CALL XERRWD( 01490 1 'LSODE-- ITASK = I1 AND TOUT (=R1) BEHIND TCUR - HU (= R2) ', 01491 1 60, 23, 0, 1, ITASK, 0, 2, TOUT, TP) 01492 GO TO 700 01493 624 CALL XERRWD( 01494 1 'LSODE-- ITASK = 4 OR 5 AND TCRIT (=R1) BEHIND TCUR (=R2) ', 01495 1 60, 24, 0, 0, 0, 0, 2, TCRIT, TN) 01496 GO TO 700 01497 625 CALL XERRWD( 01498 1 'LSODE-- ITASK = 4 OR 5 AND TCRIT (=R1) BEHIND TOUT (=R2) ', 01499 1 60, 25, 0, 0, 0, 0, 2, TCRIT, TOUT) 01500 GO TO 700 01501 626 CALL XERRWD('LSODE-- AT START OF PROBLEM, TOO MUCH ACCURACY ', 01502 1 50, 26, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01503 CALL XERRWD( 01504 1 ' REQUESTED FOR PRECISION OF MACHINE.. SEE TOLSF (=R1) ', 01505 1 60, 26, 0, 0, 0, 0, 1, TOLSF, 0.0D0) 01506 RWORK(14) = TOLSF 01507 GO TO 700 01508 627 CALL XERRWD('LSODE-- TROUBLE FROM INTDY. ITASK = I1, TOUT = R1', 01509 1 50, 27, 0, 1, ITASK, 0, 1, TOUT, 0.0D0) 01510 C 01511 700 IF (ILLIN .EQ. 5) GO TO 710 01512 ILLIN = ILLIN + 1 01513 ISTATE = -3 01514 RETURN 01515 710 CALL XERRWD('LSODE-- REPEATED OCCURRENCES OF ILLEGAL INPUT ', 01516 1 50, 302, 0, 0, 0, 0, 0, 0.0D0, 0.0D0) 01517 C 01518 800 CALL XERRWD('LSODE-- RUN ABORTED.. APPARENT INFINITE LOOP ', 01519 1 50, 303, 2, 0, 0, 0, 0, 0.0D0, 0.0D0) 01520 RETURN 01521 C----------------------- END OF SUBROUTINE LSODE ----------------------- 01522 END