GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ddstp.f
Go to the documentation of this file.
1C Work performed under the auspices of the U.S. Department of Energy
2C by Lawrence Livermore National Laboratory under contract number
3C W-7405-Eng-48.
4C
5 SUBROUTINE ddstp(X,Y,YPRIME,NEQ,RES,JAC,PSOL,H,WT,VT,
6 * JSTART,IDID,RPAR,IPAR,PHI,SAVR,DELTA,E,WM,IWM,
7 * ALPHA,BETA,GAMMA,PSI,SIGMA,CJ,CJOLD,HOLD,S,HMIN,UROUND,
8 * EPLI,SQRTN,RSQRTN,EPCON,IPHASE,JCALC,JFLG,K,KOLD,NS,NONNEG,
9 * NTYPE,NLS)
10C
11C***BEGIN PROLOGUE DDSTP
12C***REFER TO DDASPK
13C***DATE WRITTEN 890101 (YYMMDD)
14C***REVISION DATE 900926 (YYMMDD)
15C***REVISION DATE 940909 (YYMMDD) (Reset PSI(1), PHI(*,2) at 690)
16C
17C
18C-----------------------------------------------------------------------
19C***DESCRIPTION
20C
21C DDSTP solves a system of differential/algebraic equations of
22C the form G(X,Y,YPRIME) = 0, for one step (normally from X to X+H).
23C
24C The methods used are modified divided difference, fixed leading
25C coefficient forms of backward differentiation formulas.
26C The code adjusts the stepsize and order to control the local error
27C per step.
28C
29C
30C The parameters represent
31C X -- Independent variable.
32C Y -- Solution vector at X.
33C YPRIME -- Derivative of solution vector
34C after successful step.
35C NEQ -- Number of equations to be integrated.
36C RES -- External user-supplied subroutine
37C to evaluate the residual. See RES description
38C in DDASPK prologue.
39C JAC -- External user-supplied routine to update
40C Jacobian or preconditioner information in the
41C nonlinear solver. See JAC description in DDASPK
42C prologue.
43C PSOL -- External user-supplied routine to solve
44C a linear system using preconditioning.
45C (This is optional). See PSOL in DDASPK prologue.
46C H -- Appropriate step size for next step.
47C Normally determined by the code.
48C WT -- Vector of weights for error criterion used in Newton test.
49C VT -- Masked vector of weights used in error test.
50C JSTART -- Integer variable set 0 for
51C first step, 1 otherwise.
52C IDID -- Completion code returned from the nonlinear solver.
53C See IDID description in DDASPK prologue.
54C RPAR,IPAR -- Real and integer parameter arrays that
55C are used for communication between the
56C calling program and external user routines.
57C They are not altered by DNSK
58C PHI -- Array of divided differences used by
59C DDSTP. The length is NEQ*(K+1), where
60C K is the maximum order.
61C SAVR -- Work vector for DDSTP of length NEQ.
62C DELTA,E -- Work vectors for DDSTP of length NEQ.
63C WM,IWM -- Real and integer arrays storing
64C information required by the linear solver.
65C
66C The other parameters are information
67C which is needed internally by DDSTP to
68C continue from step to step.
69C
70C-----------------------------------------------------------------------
71C***ROUTINES CALLED
72C NLS, DDWNRM, DDATRP
73C
74C***END PROLOGUE DDSTP
75C
76C
77 IMPLICIT DOUBLE PRECISION(a-h,o-z)
78 dimension y(*),yprime(*),wt(*),vt(*)
79 dimension phi(neq,*),savr(*),delta(*),e(*)
80 dimension wm(*),iwm(*)
81 dimension psi(*),alpha(*),beta(*),gamma(*),sigma(*)
82 dimension rpar(*),ipar(*)
83 EXTERNAL res, jac, psol, nls
84C
85 parameter(lmxord=3)
86 parameter(lnst=11, letf=14, lcfn=15)
87C
88C
89C-----------------------------------------------------------------------
90C BLOCK 1.
91C Initialize. On the first call, set
92C the order to 1 and initialize
93C other variables.
94C-----------------------------------------------------------------------
95C
96C Initializations for all calls
97C
98 xold=x
99 ncf=0
100 nef=0
101 IF(jstart .NE. 0) GO TO 120
102C
103C If this is the first step, perform
104C other initializations
105C
106 k=1
107 kold=0
108 hold=0.0d0
109 psi(1)=h
110 cj = 1.d0/h
111 iphase = 0
112 ns=0
113120 CONTINUE
114C
115C
116C
117C
118C
119C-----------------------------------------------------------------------
120C BLOCK 2
121C Compute coefficients of formulas for
122C this step.
123C-----------------------------------------------------------------------
124200 CONTINUE
125 kp1=k+1
126 kp2=k+2
127 km1=k-1
128 IF(h.NE.hold.OR.k .NE. kold) ns = 0
129 ns=min0(ns+1,kold+2)
130 nsp1=ns+1
131 IF(kp1 .LT. ns)GO TO 230
132C
133 beta(1)=1.0d0
134 alpha(1)=1.0d0
135 temp1=h
136 gamma(1)=0.0d0
137 sigma(1)=1.0d0
138 DO 210 i=2,kp1
139 temp2=psi(i-1)
140 psi(i-1)=temp1
141 beta(i)=beta(i-1)*psi(i-1)/temp2
142 temp1=temp2+h
143 alpha(i)=h/temp1
144 sigma(i)=(i-1)*sigma(i-1)*alpha(i)
145 gamma(i)=gamma(i-1)+alpha(i-1)/h
146210 CONTINUE
147 psi(kp1)=temp1
148230 CONTINUE
149C
150C Compute ALPHAS, ALPHA0
151C
152 alphas = 0.0d0
153 alpha0 = 0.0d0
154 DO 240 i = 1,k
155 alphas = alphas - 1.0d0/i
156 alpha0 = alpha0 - alpha(i)
157240 CONTINUE
158C
159C Compute leading coefficient CJ
160C
161 cjlast = cj
162 cj = -alphas/h
163C
164C Compute variable stepsize error coefficient CK
165C
166 ck = abs(alpha(kp1) + alphas - alpha0)
167 ck = max(ck,alpha(kp1))
168C
169C Change PHI to PHI STAR
170C
171 IF(kp1 .LT. nsp1) GO TO 280
172 DO 270 j=nsp1,kp1
173 DO 260 i=1,neq
174260 phi(i,j)=beta(j)*phi(i,j)
175270 CONTINUE
176280 CONTINUE
177C
178C Update time
179C
180 x=x+h
181C
182C Initialize IDID to 1
183C
184 idid = 1
185C
186C
187C
188C
189C
190C-----------------------------------------------------------------------
191C BLOCK 3
192C Call the nonlinear system solver to obtain the solution and
193C derivative.
194C-----------------------------------------------------------------------
195C
196 CALL nls(x,y,yprime,neq,
197 * res,jac,psol,h,wt,jstart,idid,rpar,ipar,phi,gamma,
198 * savr,delta,e,wm,iwm,cj,cjold,cjlast,s,
199 * uround,epli,sqrtn,rsqrtn,epcon,jcalc,jflg,kp1,
200 * nonneg,ntype,iernls)
201C
202 IF(iernls .NE. 0)GO TO 600
203C
204C
205C
206C
207C
208C-----------------------------------------------------------------------
209C BLOCK 4
210C Estimate the errors at orders K,K-1,K-2
211C as if constant stepsize was used. Estimate
212C the local error at order K and test
213C whether the current step is successful.
214C-----------------------------------------------------------------------
215C
216C Estimate errors at orders K,K-1,K-2
217C
218 enorm = ddwnrm(neq,e,vt,rpar,ipar)
219 erk = sigma(k+1)*enorm
220 terk = (k+1)*erk
221 est = erk
222 knew=k
223 IF(k .EQ. 1)GO TO 430
224 DO 405 i = 1,neq
225405 delta(i) = phi(i,kp1) + e(i)
226 erkm1=sigma(k)*ddwnrm(neq,delta,vt,rpar,ipar)
227 terkm1 = k*erkm1
228 IF(k .GT. 2)GO TO 410
229 IF(terkm1 .LE. 0.5*terk)GO TO 420
230 GO TO 430
231410 CONTINUE
232 DO 415 i = 1,neq
233415 delta(i) = phi(i,k) + delta(i)
234 erkm2=sigma(k-1)*ddwnrm(neq,delta,vt,rpar,ipar)
235 terkm2 = (k-1)*erkm2
236 IF(max(terkm1,terkm2).GT.terk)GO TO 430
237C
238C Lower the order
239C
240420 CONTINUE
241 knew=k-1
242 est = erkm1
243C
244C
245C Calculate the local error for the current step
246C to see if the step was successful
247C
248430 CONTINUE
249 err = ck * enorm
250 IF(err .GT. 1.0d0)GO TO 600
251C
252C
253C
254C
255C
256C-----------------------------------------------------------------------
257C BLOCK 5
258C The step is successful. Determine
259C the best order and stepsize for
260C the next step. Update the differences
261C for the next step.
262C-----------------------------------------------------------------------
263 idid=1
264 iwm(lnst)=iwm(lnst)+1
265 kdiff=k-kold
266 kold=k
267 hold=h
268C
269C
270C Estimate the error at order K+1 unless
271C already decided to lower order, or
272C already using maximum order, or
273C stepsize not constant, or
274C order raised in previous step
275C
276 IF(knew.EQ.km1.OR.k.EQ.iwm(lmxord))iphase=1
277 IF(iphase .EQ. 0)GO TO 545
278 IF(knew.EQ.km1)GO TO 540
279 IF(k.EQ.iwm(lmxord)) GO TO 550
280 IF(kp1.GE.ns.OR.kdiff.EQ.1)GO TO 550
281 DO 510 i=1,neq
282510 delta(i)=e(i)-phi(i,kp2)
283 erkp1 = (1.0d0/(k+2))*ddwnrm(neq,delta,vt,rpar,ipar)
284 terkp1 = (k+2)*erkp1
285 IF(k.GT.1)GO TO 520
286 IF(terkp1.GE.0.5d0*terk)GO TO 550
287 GO TO 530
288520 IF(terkm1.LE.min(terk,terkp1))GO TO 540
289 IF(terkp1.GE.terk.OR.k.EQ.iwm(lmxord))GO TO 550
290C
291C Raise order
292C
293530 k=kp1
294 est = erkp1
295 GO TO 550
296C
297C Lower order
298C
299540 k=km1
300 est = erkm1
301 GO TO 550
302C
303C If IPHASE = 0, increase order by one and multiply stepsize by
304C factor two
305C
306545 k = kp1
307 hnew = h*2.0d0
308 h = hnew
309 GO TO 575
310C
311C
312C Determine the appropriate stepsize for
313C the next step.
314C
315550 hnew=h
316 temp2=k+1
317 r=(2.0d0*est+0.0001d0)**(-1.0d0/temp2)
318 IF(r .LT. 2.0d0) GO TO 555
319 hnew = 2.0d0*h
320 GO TO 560
321555 IF(r .GT. 1.0d0) GO TO 560
322 r = max(0.5d0,min(0.9d0,r))
323 hnew = h*r
324560 h=hnew
325C
326C
327C Update differences for next step
328C
329575 CONTINUE
330 IF(kold.EQ.iwm(lmxord))GO TO 585
331 DO 580 i=1,neq
332580 phi(i,kp2)=e(i)
333585 CONTINUE
334 DO 590 i=1,neq
335590 phi(i,kp1)=phi(i,kp1)+e(i)
336 DO 595 j1=2,kp1
337 j=kp1-j1+1
338 DO 595 i=1,neq
339595 phi(i,j)=phi(i,j)+phi(i,j+1)
340 jstart = 1
341 RETURN
342C
343C
344C
345C
346C
347C-----------------------------------------------------------------------
348C BLOCK 6
349C The step is unsuccessful. Restore X,PSI,PHI
350C Determine appropriate stepsize for
351C continuing the integration, or exit with
352C an error flag if there have been many
353C failures.
354C-----------------------------------------------------------------------
355600 iphase = 1
356C
357C Restore X,PHI,PSI
358C
359 x=xold
360 IF(kp1.LT.nsp1)GO TO 630
361 DO 620 j=nsp1,kp1
362 temp1=1.0d0/beta(j)
363 DO 610 i=1,neq
364610 phi(i,j)=temp1*phi(i,j)
365620 CONTINUE
366630 CONTINUE
367 DO 640 i=2,kp1
368640 psi(i-1)=psi(i)-h
369C
370C
371C Test whether failure is due to nonlinear solver
372C or error test
373C
374 IF(iernls .EQ. 0)GO TO 660
375 iwm(lcfn)=iwm(lcfn)+1
376C
377C
378C The nonlinear solver failed to converge.
379C Determine the cause of the failure and take appropriate action.
380C If IERNLS .LT. 0, then return. Otherwise, reduce the stepsize
381C and try again, unless too many failures have occurred.
382C
383 IF (iernls .LT. 0) GO TO 675
384 ncf = ncf + 1
385 r = 0.25d0
386 h = h*r
387 IF (ncf .LT. 10 .AND. abs(h) .GE. hmin) GO TO 690
388 IF (idid .EQ. 1) idid = -7
389 IF (nef .GE. 3) idid = -9
390 GO TO 675
391C
392C
393C The nonlinear solver converged, and the cause
394C of the failure was the error estimate
395C exceeding the tolerance.
396C
397660 nef=nef+1
398 iwm(letf)=iwm(letf)+1
399 IF (nef .GT. 1) GO TO 665
400C
401C On first error test failure, keep current order or lower
402C order by one. Compute new stepsize based on differences
403C of the solution.
404C
405 k = knew
406 temp2 = k + 1
407 r = 0.90d0*(2.0d0*est+0.0001d0)**(-1.0d0/temp2)
408 r = max(0.25d0,min(0.9d0,r))
409 h = h*r
410 IF (abs(h) .GE. hmin) GO TO 690
411 idid = -6
412 GO TO 675
413C
414C On second error test failure, use the current order or
415C decrease order by one. Reduce the stepsize by a factor of
416C one quarter.
417C
418665 IF (nef .GT. 2) GO TO 670
419 k = knew
420 r = 0.25d0
421 h = r*h
422 IF (abs(h) .GE. hmin) GO TO 690
423 idid = -6
424 GO TO 675
425C
426C On third and subsequent error test failures, set the order to
427C one, and reduce the stepsize by a factor of one quarter.
428C
429670 k = 1
430 r = 0.25d0
431 h = r*h
432 IF (abs(h) .GE. hmin) GO TO 690
433 idid = -6
434 GO TO 675
435C
436C
437C
438C
439C For all crashes, restore Y to its last value,
440C interpolate to find YPRIME at last X, and return.
441C
442C Before returning, verify that the user has not set
443C IDID to a nonnegative value. If the user has set IDID
444C to a nonnegative value, then reset IDID to be -7, indicating
445C a failure in the nonlinear system solver.
446C
447675 CONTINUE
448 CALL ddatrp(x,x,y,yprime,neq,k,phi,psi)
449 jstart = 1
450 IF (idid .GE. 0) idid = -7
451 RETURN
452C
453C
454C Go back and try this step again.
455C If this is the first step, reset PSI(1) and rescale PHI(*,2).
456C
457690 IF (kold .EQ. 0) THEN
458 psi(1) = h
459 DO 695 i = 1,neq
460695 phi(i,2) = r*phi(i,2)
461 ENDIF
462 GO TO 200
463C
464C------END OF SUBROUTINE DDSTP------------------------------------------
465 END
charNDArray max(char d, const charNDArray &m)
Definition chNDArray.cc:230
charNDArray min(char d, const charNDArray &m)
Definition chNDArray.cc:207
subroutine ddatrp(x, xout, yout, ypout, neq, kold, phi, psi)
Definition ddatrp.f:2
subroutine ddstp(x, y, yprime, neq, res, jac, psol, h, wt, vt, jstart, idid, rpar, ipar, phi, savr, delta, e, wm, iwm, alpha, beta, gamma, psi, sigma, cj, cjold, hold, s, hmin, uround, epli, sqrtn, rsqrtn, epcon, iphase, jcalc, jflg, k, kold, ns, nonneg, ntype, nls)
Definition ddstp.f:10
double precision function ddwnrm(neq, v, rwt, rpar, ipar)
Definition ddwnrm.f:6
function gamma(x)
Definition gamma.f:3
double psi(double z)