GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
dnsik.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 dnsik(X,Y,YPRIME,NEQ,ICOPT,ID,RES,PSOL,WT,RPAR,IPAR,
6 * SAVR,DELTA,R,YIC,YPIC,PWK,WM,IWM,CJ,SQRTN,RSQRTN,EPLIN,EPCON,
7 * RATEMX,MAXIT,STPTOL,ICNFLG,ICNSTR,IERNEW)
8C
9C***BEGIN PROLOGUE DNSIK
10C***REFER TO DDASPK
11C***DATE WRITTEN 940701 (YYMMDD)
12C***REVISION DATE 950714 (YYMMDD)
13C
14C
15C-----------------------------------------------------------------------
16C***DESCRIPTION
17C
18C DNSIK solves a nonlinear system of algebraic equations of the
19C form G(X,Y,YPRIME) = 0 for the unknown parts of Y and YPRIME in
20C the initial conditions.
21C
22C The method used is a Newton scheme combined with a linesearch
23C algorithm, using Krylov iterative linear system methods.
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 ICOPT -- Initial condition option chosen (1 or 2).
32C ID -- Array of dimension NEQ, which must be initialized
33C if ICOPT = 1. See DDASIC.
34C RES -- External user-supplied subroutine
35C to evaluate the residual. See RES description
36C in DDASPK prologue.
37C PSOL -- External user-supplied routine to solve
38C a linear system using preconditioning.
39C See explanation inside DDASPK.
40C WT -- Vector of weights for error criterion.
41C RPAR,IPAR -- Real and integer arrays used for communication
42C between the calling program and external user
43C routines. They are not altered within DASPK.
44C SAVR -- Work vector for DNSIK of length NEQ.
45C DELTA -- Residual vector on entry, and work vector of
46C length NEQ for DNSIK.
47C R -- Work vector for DNSIK of length NEQ.
48C YIC,YPIC -- Work vectors for DNSIK, each of length NEQ.
49C PWK -- Work vector for DNSIK of length NEQ.
50C WM,IWM -- Real and integer arrays storing
51C matrix information such as the matrix
52C of partial derivatives, permutation
53C vector, and various other information.
54C CJ -- Matrix parameter = 1/H (ICOPT = 1) or 0 (ICOPT = 2).
55C SQRTN -- Square root of NEQ.
56C RSQRTN -- reciprical of square root of NEQ.
57C EPLIN -- Tolerance for linear system solver.
58C EPCON -- Tolerance to test for convergence of the Newton
59C iteration.
60C RATEMX -- Maximum convergence rate for which Newton iteration
61C is considered converging.
62C MAXIT -- Maximum allowed number of Newton iterations.
63C STPTOL -- Tolerance used in calculating the minimum lambda
64C value allowed.
65C ICNFLG -- Integer scalar. If nonzero, then constraint
66C violations in the proposed new approximate solution
67C will be checked for, and the maximum step length
68C will be adjusted accordingly.
69C ICNSTR -- Integer array of length NEQ containing flags for
70C checking constraints.
71C IERNEW -- Error flag for Newton iteration.
72C 0 ==> Newton iteration converged.
73C 1 ==> failed to converge, but RATE .lt. 1.
74C 2 ==> failed to converge, RATE .gt. RATEMX.
75C 3 ==> other recoverable error.
76C -1 ==> unrecoverable error inside Newton iteration.
77C-----------------------------------------------------------------------
78C
79C***ROUTINES CALLED
80C DFNRMK, DSLVK, DDWNRM, DLINSK, DCOPY
81C
82C***END PROLOGUE DNSIK
83C
84C
85 IMPLICIT DOUBLE PRECISION(a-h,o-z)
86 dimension y(*),yprime(*),wt(*),id(*),delta(*),r(*),savr(*)
87 dimension yic(*),ypic(*),pwk(*),wm(*),iwm(*), rpar(*),ipar(*)
88 dimension icnstr(*)
89 EXTERNAL res, psol
90C
91 parameter(lnni=19, lnps=21, llocwp=29, llciwp=30)
92 parameter(llsoff=35, lstol=14)
93C
94C
95C Initializations. M is the Newton iteration counter.
96C
97 lsoff = iwm(llsoff)
98 m = 0
99 rate = 1.0d0
100 lwp = iwm(llocwp)
101 liwp = iwm(llciwp)
102 rlx = 0.4d0
103C
104C Save residual in SAVR.
105C
106 CALL dcopy (neq, delta, 1, savr, 1)
107C
108C Compute norm of (P-inverse)*(residual).
109C
110 CALL dfnrmk (neq, y, x, yprime, savr, r, cj, wt, sqrtn, rsqrtn,
111 * res, ires, psol, 1, ier, fnrm, eplin, wm(lwp), iwm(liwp),
112 * pwk, rpar, ipar)
113 iwm(lnps) = iwm(lnps) + 1
114 IF (ier .NE. 0) THEN
115 iernew = 3
116 RETURN
117 ENDIF
118C
119C Return now if residual norm is .le. EPCON.
120C
121 IF (fnrm .LE. epcon) RETURN
122C
123C Newton iteration loop.
124C
125300 CONTINUE
126 iwm(lnni) = iwm(lnni) + 1
127C
128C Compute a new step vector DELTA.
129C
130 CALL dslvk (neq, y, x, yprime, savr, delta, wt, wm, iwm,
131 * res, ires, psol, iersl, cj, eplin, sqrtn, rsqrtn, rhok,
132 * rpar, ipar)
133 IF (ires .NE. 0 .OR. iersl .NE. 0) GO TO 390
134C
135C Get norm of DELTA. Return now if DELTA is zero.
136C
137 delnrm = ddwnrm(neq,delta,wt,rpar,ipar)
138 IF (delnrm .EQ. 0.0d0) RETURN
139C
140C Call linesearch routine for global strategy and set RATE.
141C
142 oldfnm = fnrm
143C
144 CALL dlinsk (neq, y, x, yprime, savr, cj, delta, delnrm, wt,
145 * sqrtn, rsqrtn, lsoff, stptol, iret, res, ires, psol, wm, iwm,
146 * rhok, fnrm, icopt, id, wm(lwp), iwm(liwp), r, eplin, yic, ypic,
147 * pwk, icnflg, icnstr, rlx, rpar, ipar)
148C
149 rate = fnrm/oldfnm
150C
151C Check for error condition from linesearch.
152 IF (iret .NE. 0) GO TO 390
153C
154C Test for convergence of the iteration, and return or loop.
155C
156 IF (fnrm .LE. epcon) RETURN
157C
158C The iteration has not yet converged. Update M.
159C Test whether the maximum number of iterations have been tried.
160C
161 m=m+1
162 IF(m .GE. maxit) GO TO 380
163C
164C Copy the residual SAVR to DELTA and loop for another iteration.
165C
166 CALL dcopy (neq, savr, 1, delta, 1)
167 GO TO 300
168C
169C The maximum number of iterations was done. Set IERNEW and return.
170C
171380 IF (rate .LE. ratemx) THEN
172 iernew = 1
173 ELSE
174 iernew = 2
175 ENDIF
176 RETURN
177C
178390 IF (ires .LE. -2 .OR. iersl .LT. 0) THEN
179 iernew = -1
180 ELSE
181 iernew = 3
182 IF (ires .EQ. 0 .AND. iersl .EQ. 1 .AND. m .GE. 2
183 1 .AND. rate .LT. 1.0d0) iernew = 1
184 ENDIF
185 RETURN
186C
187C
188C----------------------- END OF SUBROUTINE DNSIK------------------------
189 END
double precision function ddwnrm(neq, v, rwt, rpar, ipar)
Definition ddwnrm.f:6
subroutine dfnrmk(neq, y, t, yprime, savr, r, cj, wt, sqrtn, rsqrtn, res, ires, psol, irin, ier, fnorm, eplin, wp, iwp, pwk, rpar, ipar)
Definition dfnrmk.f:8
subroutine dlinsk(neq, y, t, yprime, savr, cj, p, pnrm, wt, sqrtn, rsqrtn, lsoff, stptol, iret, res, ires, psol, wm, iwm, rhok, fnrm, icopt, id, wp, iwp, r, eplin, ynew, ypnew, pwk, icnflg, icnstr, rlx, rpar, ipar)
Definition dlinsk.f:9
subroutine dnsik(x, y, yprime, neq, icopt, id, res, psol, wt, rpar, ipar, savr, delta, r, yic, ypic, pwk, wm, iwm, cj, sqrtn, rsqrtn, eplin, epcon, ratemx, maxit, stptol, icnflg, icnstr, iernew)
Definition dnsik.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