GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
dspigm.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 dspigm (NEQ, TN, Y, YPRIME, SAVR, R, WGHT, MAXL,
6 * MAXLP1, KMP, EPLIN, CJ, RES, IRES, NRE, PSOL, NPSL, Z, V,
7 * HES, Q, LGMR, WP, IWP, WK, DL, RHOK, IFLAG, IRST, NRSTS,
8 * RPAR, IPAR)
9C
10C***BEGIN PROLOGUE DSPIGM
11C***DATE WRITTEN 890101 (YYMMDD)
12C***REVISION DATE 900926 (YYMMDD)
13C***REVISION DATE 940927 Removed MNEWT and added RHOK in call list.
14C
15C
16C-----------------------------------------------------------------------
17C***DESCRIPTION
18C
19C This routine solves the linear system A * Z = R using a scaled
20C preconditioned version of the generalized minimum residual method.
21C An initial guess of Z = 0 is assumed.
22C
23C On entry
24C
25C NEQ = Problem size, passed to PSOL.
26C
27C TN = Current Value of T.
28C
29C Y = Array Containing current dependent variable vector.
30C
31C YPRIME = Array Containing current first derivative of Y.
32C
33C SAVR = Array containing current value of G(T,Y,YPRIME).
34C
35C R = The right hand side of the system A*Z = R.
36C R is also used as work space when computing
37C the final approximation and will therefore be
38C destroyed.
39C (R is the same as V(*,MAXL+1) in the call to DSPIGM.)
40C
41C WGHT = The vector of length NEQ containing the nonzero
42C elements of the diagonal scaling matrix.
43C
44C MAXL = The maximum allowable order of the matrix H.
45C
46C MAXLP1 = MAXL + 1, used for dynamic dimensioning of HES.
47C
48C KMP = The number of previous vectors the new vector, VNEW,
49C must be made orthogonal to. (KMP .LE. MAXL.)
50C
51C EPLIN = Tolerance on residuals R-A*Z in weighted rms norm.
52C
53C CJ = Scalar proportional to current value of
54C 1/(step size H).
55C
56C WK = Real work array used by routine DATV and PSOL.
57C
58C DL = Real work array used for calculation of the residual
59C norm RHO when the method is incomplete (KMP.LT.MAXL)
60C and/or when using restarting.
61C
62C WP = Real work array used by preconditioner PSOL.
63C
64C IWP = Integer work array used by preconditioner PSOL.
65C
66C IRST = Method flag indicating if restarting is being
67C performed. IRST .GT. 0 means restarting is active,
68C while IRST = 0 means restarting is not being used.
69C
70C NRSTS = Counter for the number of restarts on the current
71C call to DSPIGM. If NRSTS .GT. 0, then the residual
72C R is already scaled, and so scaling of R is not
73C necessary.
74C
75C
76C On Return
77C
78C Z = The final computed approximation to the solution
79C of the system A*Z = R.
80C
81C LGMR = The number of iterations performed and
82C the current order of the upper Hessenberg
83C matrix HES.
84C
85C NRE = The number of calls to RES (i.e. DATV)
86C
87C NPSL = The number of calls to PSOL.
88C
89C V = The neq by (LGMR+1) array containing the LGMR
90C orthogonal vectors V(*,1) to V(*,LGMR).
91C
92C HES = The upper triangular factor of the QR decomposition
93C of the (LGMR+1) by LGMR upper Hessenberg matrix whose
94C entries are the scaled inner-products of A*V(*,I)
95C and V(*,K).
96C
97C Q = Real array of length 2*MAXL containing the components
98C of the givens rotations used in the QR decomposition
99C of HES. It is loaded in DHEQR and used in DHELS.
100C
101C IRES = Error flag from RES.
102C
103C DL = Scaled preconditioned residual,
104C (D-inverse)*(P-inverse)*(R-A*Z). Only loaded when
105C performing restarts of the Krylov iteration.
106C
107C RHOK = Weighted norm of final preconditioned residual.
108C
109C IFLAG = Integer error flag..
110C 0 Means convergence in LGMR iterations, LGMR.LE.MAXL.
111C 1 Means the convergence test did not pass in MAXL
112C iterations, but the new residual norm (RHO) is
113C .LT. the old residual norm (RNRM), and so Z is
114C computed.
115C 2 Means the convergence test did not pass in MAXL
116C iterations, new residual norm (RHO) .GE. old residual
117C norm (RNRM), and the initial guess, Z = 0, is
118C returned.
119C 3 Means there was a recoverable error in PSOL
120C caused by the preconditioner being out of date.
121C -1 Means there was an unrecoverable error in PSOL.
122C
123C-----------------------------------------------------------------------
124C***ROUTINES CALLED
125C PSOL, DNRM2, DSCAL, DATV, DORTH, DHEQR, DCOPY, DHELS, DAXPY
126C
127C***END PROLOGUE DSPIGM
128C
129 INTEGER NEQ,MAXL,MAXLP1,KMP,IRES,NRE,NPSL,LGMR,IWP,
130 1 IFLAG,IRST,NRSTS,IPAR
131 DOUBLE PRECISION TN,Y,YPRIME,SAVR,R,WGHT,EPLIN,CJ,Z,V,HES,Q,WP,WK,
132 1 dl,rhok,rpar
133 dimension y(*), yprime(*), savr(*), r(*), wght(*), z(*),
134 1 v(neq,*), hes(maxlp1,*), q(*), wp(*), iwp(*), wk(*), dl(*),
135 2 rpar(*), ipar(*)
136 INTEGER I, IER, INFO, IP1, I2, J, K, LL, LLP1
137 DOUBLE PRECISION RNRM,C,DLNRM,PROD,RHO,S,SNORMW,DNRM2,TEM
138 EXTERNAL RES, PSOL
139C
140 ier = 0
141 iflag = 0
142 lgmr = 0
143 npsl = 0
144 nre = 0
145C-----------------------------------------------------------------------
146C The initial guess for Z is 0. The initial residual is therefore
147C the vector R. Initialize Z to 0.
148C-----------------------------------------------------------------------
149 DO 10 i = 1,neq
150 10 z(i) = 0.0d0
151C-----------------------------------------------------------------------
152C Apply inverse of left preconditioner to vector R if NRSTS .EQ. 0.
153C Form V(*,1), the scaled preconditioned right hand side.
154C-----------------------------------------------------------------------
155 IF (nrsts .EQ. 0) THEN
156 CALL psol (neq, tn, y, yprime, savr, wk, cj, wght, wp, iwp,
157 1 r, eplin, ier, rpar, ipar)
158 npsl = 1
159 IF (ier .NE. 0) GO TO 300
160 DO 30 i = 1,neq
161 30 v(i,1) = r(i)*wght(i)
162 ELSE
163 DO 35 i = 1,neq
164 35 v(i,1) = r(i)
165 ENDIF
166C-----------------------------------------------------------------------
167C Calculate norm of scaled vector V(*,1) and normalize it
168C If, however, the norm of V(*,1) (i.e. the norm of the preconditioned
169C residual) is .le. EPLIN, then return with Z=0.
170C-----------------------------------------------------------------------
171 rnrm = dnrm2(neq, v, 1)
172 IF (rnrm .LE. eplin) THEN
173 rhok = rnrm
174 RETURN
175 ENDIF
176 tem = 1.0d0/rnrm
177 CALL dscal (neq, tem, v(1,1), 1)
178C-----------------------------------------------------------------------
179C Zero out the HES array.
180C-----------------------------------------------------------------------
181 DO 65 j = 1,maxl
182 DO 60 i = 1,maxlp1
183 60 hes(i,j) = 0.0d0
184 65 CONTINUE
185C-----------------------------------------------------------------------
186C Main loop to compute the vectors V(*,2) to V(*,MAXL).
187C The running product PROD is needed for the convergence test.
188C-----------------------------------------------------------------------
189 prod = 1.0d0
190 DO 90 ll = 1,maxl
191 lgmr = ll
192C-----------------------------------------------------------------------
193C Call routine DATV to compute VNEW = ABAR*V(LL), where ABAR is
194C the matrix A with scaling and inverse preconditioner factors applied.
195C Call routine DORTH to orthogonalize the new vector VNEW = V(*,LL+1).
196C call routine DHEQR to update the factors of HES.
197C-----------------------------------------------------------------------
198 CALL datv (neq, y, tn, yprime, savr, v(1,ll), wght, z,
199 1 res, ires, psol, v(1,ll+1), wk, wp, iwp, cj, eplin,
200 1 ier, nre, npsl, rpar, ipar)
201 IF (ires .LT. 0) RETURN
202 IF (ier .NE. 0) GO TO 300
203 CALL dorth (v(1,ll+1), v, hes, neq, ll, maxlp1, kmp, snormw)
204 hes(ll+1,ll) = snormw
205 CALL dheqr (hes, maxlp1, ll, q, info, ll)
206 IF (info .EQ. ll) GO TO 120
207C-----------------------------------------------------------------------
208C Update RHO, the estimate of the norm of the residual R - A*ZL.
209C If KMP .LT. MAXL, then the vectors V(*,1),...,V(*,LL+1) are not
210C necessarily orthogonal for LL .GT. KMP. The vector DL must then
211C be computed, and its norm used in the calculation of RHO.
212C-----------------------------------------------------------------------
213 prod = prod*q(2*ll)
214 rho = abs(prod*rnrm)
215 IF ((ll.GT.kmp) .AND. (kmp.LT.maxl)) THEN
216 IF (ll .EQ. kmp+1) THEN
217 CALL dcopy (neq, v(1,1), 1, dl, 1)
218 DO 75 i = 1,kmp
219 ip1 = i + 1
220 i2 = i*2
221 s = q(i2)
222 c = q(i2-1)
223 DO 70 k = 1,neq
224 70 dl(k) = s*dl(k) + c*v(k,ip1)
225 75 CONTINUE
226 ENDIF
227 s = q(2*ll)
228 c = q(2*ll-1)/snormw
229 llp1 = ll + 1
230 DO 80 k = 1,neq
231 80 dl(k) = s*dl(k) + c*v(k,llp1)
232 dlnrm = dnrm2(neq, dl, 1)
233 rho = rho*dlnrm
234 ENDIF
235C-----------------------------------------------------------------------
236C Test for convergence. If passed, compute approximation ZL.
237C If failed and LL .LT. MAXL, then continue iterating.
238C-----------------------------------------------------------------------
239 IF (rho .LE. eplin) GO TO 200
240 IF (ll .EQ. maxl) GO TO 100
241C-----------------------------------------------------------------------
242C Rescale so that the norm of V(1,LL+1) is one.
243C-----------------------------------------------------------------------
244 tem = 1.0d0/snormw
245 CALL dscal (neq, tem, v(1,ll+1), 1)
246 90 CONTINUE
247 100 CONTINUE
248 IF (rho .LT. rnrm) GO TO 150
249 120 CONTINUE
250 iflag = 2
251 DO 130 i = 1,neq
252 130 z(i) = 0.d0
253 RETURN
254 150 iflag = 1
255C-----------------------------------------------------------------------
256C The tolerance was not met, but the residual norm was reduced.
257C If performing restarting (IRST .gt. 0) calculate the residual vector
258C RL and store it in the DL array. If the incomplete version is
259C being used (KMP .lt. MAXL) then DL has already been calculated.
260C-----------------------------------------------------------------------
261 IF (irst .GT. 0) THEN
262 IF (kmp .EQ. maxl) THEN
263C
264C Calculate DL from the V(I)'s.
265C
266 CALL dcopy (neq, v(1,1), 1, dl, 1)
267 maxlm1 = maxl - 1
268 DO 175 i = 1,maxlm1
269 ip1 = i + 1
270 i2 = i*2
271 s = q(i2)
272 c = q(i2-1)
273 DO 170 k = 1,neq
274 170 dl(k) = s*dl(k) + c*v(k,ip1)
275 175 CONTINUE
276 s = q(2*maxl)
277 c = q(2*maxl-1)/snormw
278 DO 180 k = 1,neq
279 180 dl(k) = s*dl(k) + c*v(k,maxlp1)
280 ENDIF
281C
282C Scale DL by RNRM*PROD to obtain the residual RL.
283C
284 tem = rnrm*prod
285 CALL dscal(neq, tem, dl, 1)
286 ENDIF
287C-----------------------------------------------------------------------
288C Compute the approximation ZL to the solution.
289C Since the vector Z was used as work space, and the initial guess
290C of the Newton correction is zero, Z must be reset to zero.
291C-----------------------------------------------------------------------
292 200 CONTINUE
293 ll = lgmr
294 llp1 = ll + 1
295 DO 210 k = 1,llp1
296 210 r(k) = 0.0d0
297 r(1) = rnrm
298 CALL dhels (hes, maxlp1, ll, q, r)
299 DO 220 k = 1,neq
300 220 z(k) = 0.0d0
301 DO 230 i = 1,ll
302 CALL daxpy (neq, r(i), v(1,i), 1, z, 1)
303 230 CONTINUE
304 DO 240 i = 1,neq
305 240 z(i) = z(i)/wght(i)
306C Load RHO into RHOK.
307 rhok = rho
308 RETURN
309C-----------------------------------------------------------------------
310C This block handles error returns forced by routine PSOL.
311C-----------------------------------------------------------------------
312 300 CONTINUE
313 IF (ier .LT. 0) iflag = -1
314 IF (ier .GT. 0) iflag = 3
315C
316 RETURN
317C
318C------END OF SUBROUTINE DSPIGM-----------------------------------------
319 END
subroutine datv(neq, y, tn, yprime, savr, v, wght, yptem, res, ires, psol, z, vtem, wp, iwp, cj, eplin, ier, nre, npsl, rpar, ipar)
Definition datv.f:8
subroutine dhels(a, lda, n, q, b)
Definition dhels.f:6
subroutine dheqr(a, lda, n, q, info, ijob)
Definition dheqr.f:6
subroutine dorth(vnew, v, hes, n, ll, ldhes, kmp, snormw)
Definition dorth.f:6
subroutine dspigm(neq, tn, y, yprime, savr, r, wght, maxl, maxlp1, kmp, eplin, cj, res, ires, nre, psol, npsl, z, v, hes, q, lgmr, wp, iwp, wk, dl, rhok, iflag, irst, nrsts, rpar, ipar)
Definition dspigm.f:9