GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
dnsk.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 dnsk(X,Y,YPRIME,NEQ,RES,PSOL,WT,RPAR,IPAR,
6 * SAVR,DELTA,E,WM,IWM,CJ,SQRTN,RSQRTN,EPLIN,EPCON,
7 * S,CONFAC,TOLNEW,MULDEL,MAXIT,IRES,IERSL,IERNEW)
8C
9C***BEGIN PROLOGUE DNSK
10C***REFER TO DDASPK
11C***DATE WRITTEN 891219 (YYMMDD)
12C***REVISION DATE 900926 (YYMMDD)
13C***REVISION DATE 950126 (YYMMDD)
14C
15C
16C-----------------------------------------------------------------------
17C***DESCRIPTION
18C
19C DNSK solves a nonlinear system of
20C algebraic equations of the form
21C G(X,Y,YPRIME) = 0 for the unknown Y.
22C
23C The method used is a modified Newton scheme.
24C
25C The parameters represent
26C
27C X -- Independent variable.
28C Y -- Solution vector.
29C YPRIME -- Derivative of solution vector.
30C NEQ -- Number of unknowns.
31C RES -- External user-supplied subroutine
32C to evaluate the residual. See RES description
33C in DDASPK prologue.
34C PSOL -- External user-supplied routine to solve
35C a linear system using preconditioning.
36C See explanation inside DDASPK.
37C WT -- Vector of weights for error criterion.
38C RPAR,IPAR -- Real and integer arrays used for communication
39C between the calling program and external user
40C routines. They are not altered within DASPK.
41C SAVR -- Work vector for DNSK of length NEQ.
42C DELTA -- Work vector for DNSK of length NEQ.
43C E -- Error accumulation vector for DNSK of length NEQ.
44C WM,IWM -- Real and integer arrays storing
45C matrix information such as the matrix
46C of partial derivatives, permutation
47C vector, and various other information.
48C CJ -- Parameter always proportional to 1/H (step size).
49C SQRTN -- Square root of NEQ.
50C RSQRTN -- reciprical of square root of NEQ.
51C EPLIN -- Tolerance for linear system solver.
52C EPCON -- Tolerance to test for convergence of the Newton
53C iteration.
54C S -- Used for error convergence tests.
55C In the Newton iteration: S = RATE/(1.D0-RATE),
56C where RATE is the estimated rate of convergence
57C of the Newton iteration.
58C
59C The closer RATE is to 0., the faster the Newton
60C iteration is converging; the closer RATE is to 1.,
61C the slower the Newton iteration is converging.
62C
63C The calling routine sends the initial value
64C of S to the Newton iteration.
65C CONFAC -- A residual scale factor to improve convergence.
66C TOLNEW -- Tolerance on the norm of Newton correction in
67C alternative Newton convergence test.
68C MULDEL -- A flag indicating whether or not to multiply
69C DELTA by CONFAC.
70C 0 ==> do not scale DELTA by CONFAC.
71C 1 ==> scale DELTA by CONFAC.
72C MAXIT -- Maximum allowed number of Newton iterations.
73C IRES -- Error flag returned from RES. See RES description
74C in DDASPK prologue. If IRES = -1, then IERNEW
75C will be set to 1.
76C If IRES < -1, then IERNEW will be set to -1.
77C IERSL -- Error flag for linear system solver.
78C See IERSL description in subroutine DSLVK.
79C If IERSL = 1, then IERNEW will be set to 1.
80C If IERSL < 0, then IERNEW will be set to -1.
81C IERNEW -- Error flag for Newton iteration.
82C 0 ==> Newton iteration converged.
83C 1 ==> recoverable error inside Newton iteration.
84C -1 ==> unrecoverable error inside Newton iteration.
85C-----------------------------------------------------------------------
86C
87C***ROUTINES CALLED
88C RES, DSLVK, DDWNRM
89C
90C***END PROLOGUE DNSK
91C
92C
93 IMPLICIT DOUBLE PRECISION(a-h,o-z)
94 dimension y(*),yprime(*),wt(*),delta(*),e(*),savr(*)
95 dimension wm(*),iwm(*), rpar(*),ipar(*)
96 EXTERNAL res, psol
97C
98 parameter(lnni=19, lnre=12)
99C
100C Initialize Newton counter M and accumulation vector E.
101C
102 m = 0
103 DO 100 i=1,neq
104100 e(i) = 0.0d0
105C
106C Corrector loop.
107C
108300 CONTINUE
109 iwm(lnni) = iwm(lnni) + 1
110C
111C If necessary, multiply residual by convergence factor.
112C
113 IF (muldel .EQ. 1) THEN
114 DO 320 i = 1,neq
115320 delta(i) = delta(i) * confac
116 ENDIF
117C
118C Save residual in SAVR.
119C
120 DO 340 i = 1,neq
121340 savr(i) = delta(i)
122C
123C Compute a new iterate. Store the correction in DELTA.
124C
125 CALL dslvk (neq, y, x, yprime, savr, delta, wt, wm, iwm,
126 * res, ires, psol, iersl, cj, eplin, sqrtn, rsqrtn, rhok,
127 * rpar, ipar)
128 IF (ires .NE. 0 .OR. iersl .NE. 0) GO TO 380
129C
130C Update Y, E, and YPRIME.
131C
132 DO 360 i=1,neq
133 y(i) = y(i) - delta(i)
134 e(i) = e(i) - delta(i)
135360 yprime(i) = yprime(i) - cj*delta(i)
136C
137C Test for convergence of the iteration.
138C
139 delnrm = ddwnrm(neq,delta,wt,rpar,ipar)
140 IF (delnrm .LE. tolnew) GO TO 370
141 IF (m .EQ. 0) THEN
142 oldnrm = delnrm
143 ELSE
144 rate = (delnrm/oldnrm)**(1.0d0/m)
145 IF (rate .GT. 0.9d0) GO TO 380
146 s = rate/(1.0d0 - rate)
147 ENDIF
148 IF (s*delnrm .LE. epcon) GO TO 370
149C
150C The corrector has not yet converged. Update M and test whether
151C the maximum number of iterations have been tried.
152C
153 m = m + 1
154 IF (m .GE. maxit) GO TO 380
155C
156C Evaluate the residual, and go back to do another iteration.
157C
158 iwm(lnre) = iwm(lnre) + 1
159 CALL res(x,y,yprime,cj,delta,ires,rpar,ipar)
160 IF (ires .LT. 0) GO TO 380
161 GO TO 300
162C
163C The iteration has converged.
164C
165370 RETURN
166C
167C The iteration has not converged. Set IERNEW appropriately.
168C
169380 CONTINUE
170 IF (ires .LE. -2 .OR. iersl .LT. 0) THEN
171 iernew = -1
172 ELSE
173 iernew = 1
174 ENDIF
175 RETURN
176C
177C
178C------END OF SUBROUTINE DNSK-------------------------------------------
179 END
double precision function ddwnrm(neq, v, rwt, rpar, ipar)
Definition ddwnrm.f:6
subroutine dnsk(x, y, yprime, neq, res, psol, wt, rpar, ipar, savr, delta, e, wm, iwm, cj, sqrtn, rsqrtn, eplin, epcon, s, confac, tolnew, muldel, maxit, ires, iersl, iernew)
Definition dnsk.f:8
subroutine dslvk(neq, y, tn, yprime, savr, x, ewt, wm, iwm, res, ires, psol, iersl, cj, eplin, sqrtn, rsqrtn, rhok, rpar, ipar)
Definition dslvk.f:8