isdomn.f 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. *DECK ISDOMN
  2. INTEGER FUNCTION ISDOMN (N, B, X, NELT, IA, JA, A, ISYM, MSOLVE,
  3. + NSAVE, ITOL, TOL, ITMAX, ITER, ERR, IERR, IUNIT, R, Z, P, AP,
  4. + EMAP, DZ, CSAV, RWORK, IWORK, AK, BNRM, SOLNRM)
  5. C***BEGIN PROLOGUE ISDOMN
  6. C***SUBSIDIARY
  7. C***PURPOSE Preconditioned Orthomin Stop Test.
  8. C This routine calculates the stop test for the Orthomin
  9. C iteration scheme. It returns a non-zero if the error
  10. C estimate (the type of which is determined by ITOL) is
  11. C less than the user specified tolerance TOL.
  12. C***LIBRARY SLATEC (SLAP)
  13. C***CATEGORY D2A4, D2B4
  14. C***TYPE DOUBLE PRECISION (ISSOMN-S, ISDOMN-D)
  15. C***KEYWORDS ITERATIVE PRECONDITION, NON-SYMMETRIC LINEAR SYSTEM,
  16. C ORTHOMIN, SLAP, SPARSE, STOP TEST
  17. C***AUTHOR Greenbaum, Anne, (Courant Institute)
  18. C Seager, Mark K., (LLNL)
  19. C Lawrence Livermore National Laboratory
  20. C PO BOX 808, L-60
  21. C Livermore, CA 94550 (510) 423-3141
  22. C seager@llnl.gov
  23. C***DESCRIPTION
  24. C
  25. C *Usage:
  26. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM, NSAVE, ITOL, ITMAX
  27. C INTEGER ITER, IERR, IUNIT, IWORK(USER DEFINED)
  28. C DOUBLE PRECISION B(N), X(N), A(NELT), TOL, ERR, R(N), Z(N)
  29. C DOUBLE PRECISION P(N,0:NSAVE), AP(N,0:NSAVE), EMAP(N,0:NSAVE)
  30. C DOUBLE PRECISION DZ(N), CSAV(NSAVE), RWORK(USER DEFINED), AK
  31. C DOUBLE PRECISION BNRM, SOLNRM
  32. C EXTERNAL MSOLVE
  33. C
  34. C IF( ISDOMN(N, B, X, NELT, IA, JA, A, ISYM, MSOLVE, NSAVE,
  35. C $ ITOL, TOL, ITMAX, ITER, ERR, IERR, IUNIT, R, Z, P, AP,
  36. C $ EMAP, DZ, CSAV, RWORK, IWORK, AK, BNRM, SOLNRM)
  37. C $ .NE.0 ) THEN ITERATION CONVERGED
  38. C
  39. C *Arguments:
  40. C N :IN Integer.
  41. C Order of the matrix.
  42. C B :IN Double Precision B(N).
  43. C Right-hand side vector.
  44. C X :IN Double Precision X(N).
  45. C On input X is your initial guess for solution vector.
  46. C On output X is the final approximate solution.
  47. C NELT :IN Integer.
  48. C Number of Non-Zeros stored in A.
  49. C IA :IN Integer IA(NELT).
  50. C JA :IN Integer JA(NELT).
  51. C A :IN Double Precision A(NELT).
  52. C These arrays should hold the matrix A in either the SLAP
  53. C Triad format or the SLAP Column format. See "Description"
  54. C in the DSDOMN or DSLUOM prologue.
  55. C ISYM :IN Integer.
  56. C Flag to indicate symmetric storage format.
  57. C If ISYM=0, all non-zero entries of the matrix are stored.
  58. C If ISYM=1, the matrix is symmetric, and only the upper
  59. C or lower triangle of the matrix is stored.
  60. C MSOLVE :EXT External.
  61. C Name of a routine which solves a linear system MZ = R for
  62. C Z given R with the preconditioning matrix M (M is supplied via
  63. C RWORK and IWORK arrays). The name of the MSOLVE routine must
  64. C be declared external in the calling program. The calling
  65. C sequence to MSOLVE is:
  66. C CALL MSOLVE(N, R, Z, NELT, IA, JA, A, ISYM, RWORK, IWORK)
  67. C Where N is the number of unknowns, R is the right-hand side
  68. C vector and Z is the solution upon return. NELT, IA, JA, A and
  69. C ISYM are defined as above. RWORK is a double precision array
  70. C that can be used to pass necessary preconditioning information
  71. C and/or workspace to MSOLVE. IWORK is an integer work array
  72. C for the same purpose as RWORK.
  73. C NSAVE :IN Integer.
  74. C Number of direction vectors to save and orthogonalize against.
  75. C ITOL :IN Integer.
  76. C Flag to indicate type of convergence criterion.
  77. C If ITOL=1, iteration stops when the 2-norm of the residual
  78. C divided by the 2-norm of the right-hand side is less than TOL.
  79. C If ITOL=2, iteration stops when the 2-norm of M-inv times the
  80. C residual divided by the 2-norm of M-inv times the right hand
  81. C side is less than TOL, where M-inv is the inverse of the
  82. C diagonal of A.
  83. C ITOL=11 is often useful for checking and comparing different
  84. C routines. For this case, the user must supply the "exact"
  85. C solution or a very accurate approximation (one with an error
  86. C much less than TOL) through a common block,
  87. C COMMON /DSLBLK/ SOLN( )
  88. C If ITOL=11, iteration stops when the 2-norm of the difference
  89. C between the iterative approximation and the user-supplied
  90. C solution divided by the 2-norm of the user-supplied solution
  91. C is less than TOL. Note that this requires the user to set up
  92. C the "COMMON /DSLBLK/ SOLN(LENGTH)" in the calling routine.
  93. C The routine with this declaration should be loaded before the
  94. C stop test so that the correct length is used by the loader.
  95. C This procedure is not standard Fortran and may not work
  96. C correctly on your system (although it has worked on every
  97. C system the authors have tried). If ITOL is not 11 then this
  98. C common block is indeed standard Fortran.
  99. C TOL :IN Double Precision.
  100. C Convergence criterion, as described above.
  101. C ITMAX :IN Integer.
  102. C Maximum number of iterations.
  103. C ITER :IN Integer.
  104. C Current iteration count. (Must be zero on first call.)
  105. C ERR :OUT Double Precision.
  106. C Error estimate of error in final approximate solution, as
  107. C defined by ITOL.
  108. C IERR :OUT Integer.
  109. C Error flag. IERR is set to 3 if ITOL is not one of the
  110. C acceptable values, see above.
  111. C IUNIT :IN Integer.
  112. C Unit number on which to write the error at each iteration,
  113. C if this is desired for monitoring convergence. If unit
  114. C number is 0, no writing will occur.
  115. C R :IN Double Precision R(N).
  116. C The residual R = B-AX.
  117. C Z :WORK Double Precision Z(N).
  118. C P :IN Double Precision P(N,0:NSAVE).
  119. C Workspace used to hold the conjugate direction vector(s).
  120. C AP :IN Double Precision AP(N,0:NSAVE).
  121. C Workspace used to hold the matrix A times the P vector(s).
  122. C EMAP :IN Double Precision EMAP(N,0:NSAVE).
  123. C Workspace used to hold M-inv times the AP vector(s).
  124. C DZ :WORK Double Precision DZ(N).
  125. C Workspace.
  126. C CSAV :DUMMY Double Precision CSAV(NSAVE)
  127. C Reserved for future use.
  128. C RWORK :WORK Double Precision RWORK(USER DEFINED).
  129. C Double Precision array that can be used for workspace in
  130. C MSOLVE.
  131. C IWORK :WORK Integer IWORK(USER DEFINED).
  132. C Integer array that can be used for workspace in MSOLVE.
  133. C AK :IN Double Precision.
  134. C Current iterate Orthomin iteration parameter.
  135. C BNRM :OUT Double Precision.
  136. C Current solution B-norm, if ITOL = 1 or 2.
  137. C SOLNRM :OUT Double Precision.
  138. C True solution norm, if ITOL = 11.
  139. C
  140. C *Function Return Values:
  141. C 0 : Error estimate (determined by ITOL) is *NOT* less than the
  142. C specified tolerance, TOL. The iteration must continue.
  143. C 1 : Error estimate (determined by ITOL) is less than the
  144. C specified tolerance, TOL. The iteration can be considered
  145. C complete.
  146. C
  147. C *Cautions:
  148. C This routine will attempt to write to the Fortran logical output
  149. C unit IUNIT, if IUNIT .ne. 0. Thus, the user must make sure that
  150. C this logical unit is attached to a file or terminal before calling
  151. C this routine with a non-zero value for IUNIT. This routine does
  152. C not check for the validity of a non-zero IUNIT unit number.
  153. C
  154. C***SEE ALSO DOMN, DSDOMN, DSLUOM
  155. C***ROUTINES CALLED D1MACH, DNRM2
  156. C***COMMON BLOCKS DSLBLK
  157. C***REVISION HISTORY (YYMMDD)
  158. C 890404 DATE WRITTEN
  159. C 890404 Previous REVISION DATE
  160. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  161. C 890922 Numerous changes to prologue to make closer to SLATEC
  162. C standard. (FNF)
  163. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  164. C 891003 Removed C***REFER TO line, per MKS.
  165. C 910411 Prologue converted to Version 4.0 format. (BAB)
  166. C 910502 Removed MSOLVE from ROUTINES CALLED list. (FNF)
  167. C 910506 Made subsidiary to DOMN. (FNF)
  168. C 920407 COMMON BLOCK renamed DSLBLK. (WRB)
  169. C 920511 Added complete declaration section. (WRB)
  170. C 920930 Corrected to not print AK when ITER=0. (FNF)
  171. C 921026 Changed 1.0E10 to D1MACH(2) and corrected D to E in
  172. C output format. (FNF)
  173. C 921113 Corrected C***CATEGORY line. (FNF)
  174. C***END PROLOGUE ISDOMN
  175. C .. Scalar Arguments ..
  176. DOUBLE PRECISION AK, BNRM, ERR, SOLNRM, TOL
  177. INTEGER IERR, ISYM, ITER, ITMAX, ITOL, IUNIT, N, NELT, NSAVE
  178. C .. Array Arguments ..
  179. DOUBLE PRECISION A(NELT), AP(N,0:NSAVE), B(N), CSAV(NSAVE),
  180. + DZ(N), EMAP(N,0:NSAVE), P(N,0:NSAVE), R(N),
  181. + RWORK(*), X(N), Z(N)
  182. INTEGER IA(NELT), IWORK(*), JA(NELT)
  183. C .. Subroutine Arguments ..
  184. EXTERNAL MSOLVE
  185. C .. Arrays in Common ..
  186. DOUBLE PRECISION SOLN(1)
  187. C .. Local Scalars ..
  188. INTEGER I
  189. C .. External Functions ..
  190. DOUBLE PRECISION D1MACH, DNRM2
  191. EXTERNAL D1MACH, DNRM2
  192. C .. Common blocks ..
  193. COMMON /DSLBLK/ SOLN
  194. C***FIRST EXECUTABLE STATEMENT ISDOMN
  195. ISDOMN = 0
  196. C
  197. IF( ITOL.EQ.1 ) THEN
  198. C err = ||Residual||/||RightHandSide|| (2-Norms).
  199. IF(ITER .EQ. 0) BNRM = DNRM2(N, B, 1)
  200. ERR = DNRM2(N, R, 1)/BNRM
  201. ELSE IF( ITOL.EQ.2 ) THEN
  202. C -1 -1
  203. C err = ||M Residual||/||M RightHandSide|| (2-Norms).
  204. IF(ITER .EQ. 0) THEN
  205. CALL MSOLVE(N, B, DZ, NELT, IA, JA, A, ISYM, RWORK, IWORK)
  206. BNRM = DNRM2(N, DZ, 1)
  207. ENDIF
  208. ERR = DNRM2(N, Z, 1)/BNRM
  209. ELSE IF( ITOL.EQ.11 ) THEN
  210. C err = ||x-TrueSolution||/||TrueSolution|| (2-Norms).
  211. IF(ITER .EQ. 0) SOLNRM = DNRM2(N, SOLN, 1)
  212. DO 10 I = 1, N
  213. DZ(I) = X(I) - SOLN(I)
  214. 10 CONTINUE
  215. ERR = DNRM2(N, DZ, 1)/SOLNRM
  216. ELSE
  217. C
  218. C If we get here ITOL is not one of the acceptable values.
  219. ERR = D1MACH(2)
  220. IERR = 3
  221. ENDIF
  222. C
  223. IF(IUNIT .NE. 0) THEN
  224. IF( ITER.EQ.0 ) THEN
  225. WRITE(IUNIT,1000) NSAVE, N, ITOL
  226. WRITE(IUNIT,1010) ITER, ERR
  227. ELSE
  228. WRITE(IUNIT,1010) ITER, ERR, AK
  229. ENDIF
  230. ENDIF
  231. IF(ERR .LE. TOL) ISDOMN = 1
  232. C
  233. RETURN
  234. 1000 FORMAT(' Preconditioned Orthomin(',I3,') for ',
  235. $ 'N, ITOL = ',I5, I5,
  236. $ /' ITER',' Error Estimate',' Alpha')
  237. 1010 FORMAT(1X,I4,1X,D16.7,1X,D16.7)
  238. C------------- LAST LINE OF ISDOMN FOLLOWS ----------------------------
  239. END