1 SUBROUTINE CONTRL
(XI
, XIOLD
, Z
, DMZ
, RHS
, DELZ
, DELDMZ
,
2 1 DQZ
, DQDMZ
, G
, W
, V
, VALSTR
, SLOPE
, SCALE
, DSCALE
,
3 2 ACCUM
, IPVTG
, INTEGS
, IPVTW
, NFXPNT
, FIXPNT
, IFLAG
,
4 3 FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
)
6 C**********************************************************************
9 C this subroutine is the actual driver. the nonlinear iteration
10 C strategy is controlled here ( see [4] ). upon convergence, errchk
11 C is called to test for satisfaction of the requested tolerances.
15 C check - maximum tolerance value, used as part of criteria for
16 C checking for nonlinear iteration convergence
17 C relax - the relaxation factor for damped newton iteration
18 C relmin - minimum allowable value for relax (otherwise the
19 C jacobian is considered singular).
20 C rlxold - previous relax
21 C rstart - initial value for relax when problem is sensitive
22 C ifrz - number of fixed jacobian iterations
23 C lmtfrz - maximum value for ifrz before performing a reinversion
24 C iter - number of iterations (counted only when jacobian
25 C reinversions are performed).
27 C xiold - previous mesh
28 C ipred = 0 if relax is determined by a correction
29 C = 1 if relax is determined by a prediction
30 C ifreez = 0 if the jacobian is to be updated
31 C = 1 if the jacobian is currently fixed (frozen)
32 C iconv = 0 if no previous convergence has been obtained
33 C = 1 if convergence on a previous mesh has been obtained
34 C icare =-1 no convergence occurred (used for regular problems)
35 C = 0 a regular problem
36 C = 1 a sensitive problem
37 C = 2 used for continuation (see description of ipar(10)
39 C rnorm - norm of rhs (right hand side) for current iteration
40 C rnold - norm of rhs for previous iteration
41 C anscl - scaled norm of newton correction
42 C anfix - scaled norm of newton correction at next step
43 C anorm - scaled norm of a correction obtained with jacobian fixed
44 C nz - number of components of z (see subroutine approx)
45 C ndmz - number of components of dmz (see subroutine approx)
46 C imesh - a control variable for subroutines newmsh and errchk
47 C = 1 the current mesh resulted from mesh selection
48 C or is the initial mesh.
49 C = 2 the current mesh resulted from doubling the
52 C**********************************************************************
54 IMPLICIT REAL*8 (A
-H
,O
-Z
)
55 DIMENSION XI
(1), XIOLD
(1), Z
(1), DMZ
(1), RHS
(1)
56 DIMENSION G
(1), W
(1), V
(1), VALSTR
(1), SLOPE
(1), ACCUM
(1)
57 DIMENSION DELZ
(1), DELDMZ
(1), DQZ
(1), DQDMZ
(1) , FIXPNT
(1)
58 DIMENSION DUMMY
(1), SCALE
(1), DSCALE
(1)
59 DIMENSION INTEGS
(1), IPVTG
(1), IPVTW
(1)
61 COMMON /COLOUT
/ PRECIS
, IOUT
, IPRINT
62 COMMON /COLORD
/ K
, NCOMP
, MSTAR
, KD
, MMAX
, M
(20)
63 COMMON /COLAPR
/ N
, NOLD
, NMAX
, NZ
, NDMZ
64 COMMON /COLMSH
/ MSHFLG
, MSHNUM
, MSHLMT
, MSHALT
65 COMMON /COLSID
/ ZETA
(40), ALEFT
, ARIGHT
, IZETA
, IDUM
66 COMMON /COLNLN
/ NONLIN
, ITER
, LIMIT
, ICARE
, IGUESS
67 COMMON /COLEST
/ TOL
(40), WGTMSH
(40), WGTERR
(40), TOLIN
(40),
68 1 ROOT
(40), JTOL
(40), LTOL
(40), NTOL
70 EXTERNAL FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
72 C... constants for control of nonlinear iteration
78 C... compute the maximum tolerance
82 10 CHECK
= DMAX1
( TOLIN
(I
), CHECK
)
85 IF ( NONLIN
.EQ
. 0 ) ICONV
= 1
90 C... the main iteration begins here .
91 C... loop 20 is executed until error tolerances are satisfied or
92 C... the code fails (due to a singular matrix or storage limitations)
96 C... initialization for a new mesh
99 IF ( NONLIN
.GT
. 0 ) GO TO 50
101 C... the linear case.
102 C... set up and solve equations
104 CALL LSYSLV
(MSING
, XI
, XIOLD
, DUMMY
, DUMMY
, Z
, DMZ
, G
,
105 1 W
, V
, RHS
, DUMMY
, INTEGS
, IPVTG
, IPVTW
, RNORM
, 0,
106 2 FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
)
108 C... check for a singular matrix
110 IF ( MSING
.EQ
. 0 ) GO TO 400
111 30 IF ( MSING
.LT
. 0 ) GO TO 40
112 IF ( IPRINT
.LT
. 1 ) WRITE (IOUT
,495)
114 40 IF ( IPRINT
.LT
. 1 ) WRITE (IOUT
,490)
118 C... iteration loop for nonlinear case
119 C... define the initial relaxation parameter (= relax)
123 C... check for previous convergence and problem sensitivity
125 IF ( ICARE
.EQ
. 1 .OR
. ICARE
.EQ
. (-1) ) RELAX
= RSTART
126 IF ( ICONV
.EQ
. 0 ) GO TO 160
128 C... convergence on a previous mesh has been obtained. thus
129 C... we have a very good initial approximation for the newton
130 C... process. proceed with one full newton and then iterate
131 C... with a fixed jacobian.
135 C... evaluate right hand side and its norm and
136 C... find the first newton correction
138 CALL LSYSLV
(MSING
, XI
, XIOLD
, Z
, DMZ
, DELZ
, DELDMZ
, G
,
139 1 W
, V
, RHS
, DQDMZ
, INTEGS
, IPVTG
, IPVTW
, RNOLD
, 1,
140 2 FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
)
142 IF ( IPRINT
.LT
. 0 ) WRITE(IOUT
,530)
143 IF ( IPRINT
.LT
. 0 ) WRITE (IOUT
,510) ITER
, RNOLD
146 C... solve for the next iterate .
147 C... the value of ifreez determines whether this is a full
148 C... newton step (=0) or a fixed jacobian iteration (=1).
150 60 IF ( IPRINT
.LT
. 0 ) WRITE (IOUT
,510) ITER
, RNORM
152 CALL LSYSLV
(MSING
, XI
, XIOLD
, Z
, DMZ
, DELZ
, DELDMZ
, G
,
153 1 W
, V
, RHS
, DUMMY
, INTEGS
, IPVTG
, IPVTW
, RNORM
,
154 2 3+IFREEZ
, FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
)
156 C... check for a singular matrix
158 70 IF ( MSING
.NE
. 0 ) GO TO 30
159 IF ( IFREEZ
.EQ
. 1 ) GO TO 80
161 C... a full newton step
167 C... update z and dmz , compute new rhs and its norm
170 Z
(I
) = Z
(I
) + DELZ
(I
)
173 DMZ
(I
) = DMZ
(I
) + DELDMZ
(I
)
175 CALL LSYSLV
(MSING
, XI
, XIOLD
, Z
, DMZ
, DELZ
, DELDMZ
, G
,
176 1 W
, V
, RHS
, DUMMY
, INTEGS
, IPVTG
, IPVTW
, RNORM
, 2,
177 2 FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
)
179 C... check monotonicity. if the norm of rhs gets smaller,
180 C... proceed with a fixed jacobian; else proceed cautiously,
181 C... as if convergence has not been obtained before (iconv=0).
183 IF ( RNORM
.LT
. PRECIS
) GO TO 390
184 IF ( RNORM
.GT
. RNOLD
) GO TO 130
185 IF ( IFREEZ
.EQ
. 1 ) GO TO 110
189 C... verify that the linear convergence with fixed jacobian
193 IF ( IFRZ
.GE
. LMTFRZ
) IFREEZ
= 0
194 IF ( RNOLD
.LT
. 4.D0*RNORM
) IFREEZ
= 0
196 C... check convergence (iconv = 1).
200 DO 120 IZ
= INZ
, NZ
, MSTAR
201 IF ( DABS
(DELZ
(IZ
)) .GT
.
202 1 TOLIN
(IT
) * (DABS
(Z
(IZ
)) + 1.D0
)) GO TO 60
205 C... convergence obtained
207 IF ( IPRINT
.LT
. 1 ) WRITE (IOUT
,560) ITER
210 C... convergence of fixed jacobian iteration failed.
212 130 IF ( IPRINT
.LT
. 0 ) WRITE (IOUT
,510) ITER
, RNORM
213 IF ( IPRINT
.LT
. 0 ) WRITE (IOUT
,540)
217 Z
(I
) = Z
(I
) - DELZ
(I
)
220 DMZ
(I
) = DMZ
(I
) - DELDMZ
(I
)
232 C... no previous convergence has been obtained. proceed
233 C... with the damped newton method.
234 C... evaluate rhs and find the first newton correction.
236 160 IF(IPRINT
.LT
. 0) WRITE (IOUT
,500)
237 CALL LSYSLV
(MSING
, XI
, XIOLD
, Z
, DMZ
, DELZ
, DELDMZ
, G
,
238 1 W
, V
, RHS
, DQDMZ
, INTEGS
, IPVTG
, IPVTW
, RNOLD
, 1,
239 2 FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
)
241 C... check for a singular matrix
243 IF ( MSING
.NE
. 0 ) GO TO 30
245 C... bookkeeping for first mesh
247 IF ( IGUESS
.EQ
. 1 ) IGUESS
= 0
249 C... find initial scaling
251 CALL SKALE
(N
, MSTAR
, KD
, Z
, XI
, SCALE
, DSCALE
)
254 C... main iteration loop
257 IF ( ITER
.GE
. LIMIT
) GO TO 430
261 CALL SKALE
(N
, MSTAR
, KD
, Z
, XI
, SCALE
, DSCALE
)
263 C... compute norm of newton correction with new scaling
267 ANSCL
= ANSCL
+ (DELZ
(I
) * SCALE
(I
))**2
270 ANSCL
= ANSCL
+ (DELDMZ
(I
) * DSCALE
(I
))**2
272 ANSCL
= DSQRT
(ANSCL
/ DFLOAT
(NZ
+NDMZ
))
274 C... find a newton direction
276 CALL LSYSLV
(MSING
, XI
, XIOLD
, Z
, DMZ
, DELZ
, DELDMZ
, G
,
277 1 W
, V
, RHS
, DUMMY
, INTEGS
, IPVTG
, IPVTW
, RNORM
, 3,
278 2 FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
)
280 C... check for a singular matrix
282 IF ( MSING
.NE
. 0 ) GO TO 30
284 C... predict relaxation factor for newton step.
288 ANDIF
= ANDIF
+ ((DQZ
(I
) - DELZ
(I
)) * SCALE
(I
))**2
291 ANDIF
= ANDIF
+ ((DQDMZ
(I
) - DELDMZ
(I
)) * DSCALE
(I
))**2
293 ANDIF
= DSQRT
(ANDIF
/DFLOAT
(NZ
+NDMZ
) + PRECIS
)
294 RELAX
= RELAX
* ANSCL
/ ANDIF
295 IF ( RELAX
.GT
. 1.D0
) RELAX
= 1.D0
300 C... determine a new z and dmz and find new rhs and its norm
303 Z
(I
) = Z
(I
) + RELAX
* DELZ
(I
)
306 DMZ
(I
) = DMZ
(I
) + RELAX
* DELDMZ
(I
)
308 250 CALL LSYSLV
(MSING
, XI
, XIOLD
, Z
, DMZ
, DQZ
, DQDMZ
, G
,
309 1 W
, V
, RHS
, DUMMY
, INTEGS
, IPVTG
, IPVTW
, RNORM
, 2,
310 2 FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
)
312 C... compute a fixed jacobian iterate (used to control relax)
314 CALL LSYSLV
(MSING
, XI
, XIOLD
, Z
, DMZ
, DQZ
, DQDMZ
, G
,
315 1 W
, V
, RHS
, DUMMY
, INTEGS
, IPVTG
, IPVTW
, RNORM
, 4,
316 2 FSUB
, DFSUB
, GSUB
, DGSUB
, GUESS
)
318 C... find scaled norms of various terms used to correct relax
323 ANORM
= ANORM
+ (DELZ
(I
) * SCALE
(I
))**2
324 ANFIX
= ANFIX
+ (DQZ
(I
) * SCALE
(I
))**2
327 ANORM
= ANORM
+ (DELDMZ
(I
) * DSCALE
(I
))**2
328 ANFIX
= ANFIX
+ (DQDMZ
(I
) * DSCALE
(I
))**2
330 ANORM
= DSQRT
(ANORM
/ DFLOAT
(NZ
+NDMZ
))
331 ANFIX
= DSQRT
(ANFIX
/ DFLOAT
(NZ
+NDMZ
))
332 IF ( ICOR
.EQ
. 1 ) GO TO 280
333 IF (IPRINT
.LT
. 0) WRITE (IOUT
,520) ITER
, RELAX
, ANORM
,
334 1 ANFIX
, RNOLD
, RNORM
336 280 IF (IPRINT
.LT
. 0) WRITE (IOUT
,550) RELAX
, ANORM
, ANFIX
,
340 C... check for monotonic decrease in delz and deldmz.
342 IF (ANFIX
.LT
.PRECIS
.OR
. RNORM
.LT
.PRECIS
) GO TO 390
343 IF ( ANFIX
.GT
. ANORM
) GO TO 300
345 C... we have a decrease.
346 C... if dqz and dqdmz small, check for convergence
348 IF ( ANFIX
.LE
. CHECK
) GO TO 350
350 C... correct the predicted relax unless the corrected
351 C... value is within 10 percent of the predicted one.
353 IF ( IPRED
.NE
. 1 ) GO TO 170
354 300 IF ( ITER
.GE
. LIMIT
) GO TO 430
356 C... correct the relaxation factor.
359 ARG
= (ANFIX
/ANORM
- 1.D0
) / RELAX
+ 1.D0
360 IF ( ARG
.LT
. 0.D0
) GO TO 170
361 IF (ARG
.LE
. .25D0*RELAX
+.125D0*RELAX**2
) GO TO 310
362 FACTOR
= -1.D0
+ DSQRT
(1.D0
+8.D0
* ARG
)
363 IF ( DABS
(FACTOR
-1.D0
) .LT
. .1D0*FACTOR
) GO TO 170
364 IF ( FACTOR
.LT
. 0.5D0
) FACTOR
= 0.5D0
365 RELAX
= RELAX
/ FACTOR
367 310 IF ( RELAX
.GE
. .9D0
) GO TO 170
370 IF ( RELAX
.LT
. RELMIN
) GO TO 440
371 FACT
= RELAX
- RLXOLD
373 Z
(I
) = Z
(I
) + FACT
* DELZ
(I
)
376 DMZ
(I
) = DMZ
(I
) + FACT
* DELDMZ
(I
)
381 C... check convergence (iconv = 0).
386 DO 360 IZ
= INZ
, NZ
, MSTAR
387 IF ( DABS
(DQZ
(IZ
)) .GT
.
388 1 TOLIN
(IT
) * (DABS
(Z
(IZ
)) + 1.D0
) ) GO TO 170
391 C... convergence obtained
393 IF ( IPRINT
.LT
. 1 ) WRITE (IOUT
,560) ITER
395 C... since convergence obtained, update z and dmz with term
396 C... from the fixed jacobian iteration.
402 DMZ
(I
) = DMZ
(I
) + DQDMZ
(I
)
404 390 IF ( (ANFIX
.LT
. PRECIS
.OR
. RNORM
.LT
. PRECIS
)
405 1 .AND
. IPRINT
.LT
. 1 ) WRITE (IOUT
,560) ITER
407 IF ( ICARE
.EQ
. (-1) ) ICARE
= 0
409 C... if full output has been requested, print values of the
410 C... solution components z at the meshpoints.
412 400 IF ( IPRINT
.GE
. 0 ) GO TO 420
415 410 WRITE(IOUT
,620) (Z
(LJ
), LJ
= J
, NZ
, MSTAR
)
417 C... check for error tolerance satisfaction
420 IF (IMESH
.EQ
. 2) CALL ERRCHK
(XI
, Z
, DMZ
, VALSTR
, IFIN
)
421 IF ( IMESH
.EQ
. 1 .OR
.
422 1 IFIN
.EQ
. 0 .AND
. ICARE
.NE
. 2) GO TO 460
426 C... diagnostics for failure of nonlinear iteration.
428 430 IF ( IPRINT
.LT
. 1 ) WRITE (IOUT
,570) ITER
430 440 IF( IPRINT
.LT
. 1 ) WRITE(IOUT
,580) RELAX
, RELMIN
433 IF ( ICARE
.EQ
. 2 .AND
. NOCONV
.GT
. 1 ) RETURN
434 IF ( ICARE
.EQ
. 0 ) ICARE
= -1
444 C... check safeguards for mesh refinement
447 IF ( ICONV
.EQ
. 0 .OR
. MSHNUM
.GE
. MSHLMT
448 1 .OR
. MSHALT
.GE
. MSHLMT
) IMESH
= 2
449 IF ( MSHALT
.GE
. MSHLMT
.AND
.
450 1 MSHNUM
.LT
. MSHLMT
) MSHALT
= 1
451 CALL NEWMSH
(IMESH
, XI
, XIOLD
, Z
, DMZ
, VALSTR
,
452 1 SLOPE
, ACCUM
, NFXPNT
, FIXPNT
)
454 C... exit if expected n is too large (but may try n=nmax once)
456 IF ( N
.LE
. NMAX
) GO TO 480
459 IF ( ICONV
.EQ
. 0 .AND
. IPRINT
.LT
. 1 ) WRITE (IOUT
,590)
460 IF ( ICONV
.EQ
. 1 .AND
. IPRINT
.LT
. 1 ) WRITE (IOUT
,600)
462 480 IF ( ICONV
.EQ
. 0 ) IMESH
= 1
463 IF ( ICARE
.EQ
. 1 ) ICONV
= 0
465 C ---------------------------------------------------------------
466 490 FORMAT(//35H THE GLOBAL BVP
-MATRIX IS SINGULAR
)
467 495 FORMAT(//40H A LOCAL ELIMINATION MATRIX IS SINGULAR
)
468 500 FORMAT(/30H FULL DAMPED NEWTON ITERATION
,)
469 510 FORMAT(13H ITERATION
= , I3
, 15H NORM
(RHS
) = , D10
.2
)
470 520 FORMAT(13H ITERATION
= ,I3
,22H RELAXATION FACTOR
= ,D10
.2
471 1 /33H NORM OF SCALED RHS CHANGES FROM
,D10
.2
,3H
TO,D10
.2
472 2 /33H NORM OF RHS CHANGES FROM
,D10
.2
,3H
TO,D10
.2
,
474 530 FORMAT(/27H FIXED JACOBIAN ITERATIONS
,)
475 540 FORMAT(/35H
SWITCH TO DAMPED NEWTON ITERATION
,)
476 550 FORMAT(40H RELAXATION FACTOR CORRECTED
TO RELAX
= , D10
.2
477 1 /33H NORM OF SCALED RHS CHANGES FROM
,D10
.2
,3H
TO,D10
.2
478 2 /33H NORM OF RHS CHANGES FROM
,D10
.2
,3H
TO,D10
.2
480 560 FORMAT(/18H CONVERGENCE AFTER
, I3
,11H ITERATIONS
/)
481 570 FORMAT(/22H NO CONVERGENCE AFTER
, I3
, 11H ITERATIONS
/)
482 580 FORMAT(/37H NO CONVERGENCE
. RELAXATION FACTOR
=,D10
.3
483 1 ,24H IS TOO SMALL
(LESS THAN
, D10
.3
, 1H
)/)
484 590 FORMAT(18H
(NO CONVERGENCE
) )
485 600 FORMAT(50H
(PROBABLY TOLERANCES TOO STRINGENT
, OR NMAX TOO
487 610 FORMAT( 19H MESH VALUES
FOR Z
(, I2
, 2H
), )
488 620 FORMAT(1H
, 8D15
.7
)