| 1 |
c* /////////////////////////////////////////////////////////////////////////// |
| 2 |
c* @file newtond.f |
| 3 |
c* @author Michael Holst |
| 4 |
c* @brief The main Newton iteration. |
| 5 |
c* @version $Id: newtond.f,v 1.2 2010/08/12 05:45:36 fetk Exp $ |
| 6 |
c* @attention |
| 7 |
c* @verbatim |
| 8 |
c* |
| 9 |
c* PMG -- Parallel algebraic MultiGrid |
| 10 |
c* Copyright (C) 1994-- Michael Holst. |
| 11 |
c* |
| 12 |
c* Michael Holst <[email protected]> |
| 13 |
c* University of California, San Diego |
| 14 |
c* Department of Mathematics, 5739 AP&M |
| 15 |
c* 9500 Gilman Drive, Dept. 0112 |
| 16 |
c* La Jolla, CA 92093-0112 USA |
| 17 |
c* http://math.ucsd.edu/~mholst |
| 18 |
c* |
| 19 |
c* This file is part of PMG. |
| 20 |
c* |
| 21 |
c* PMG is free software; you can redistribute it and/or modify |
| 22 |
c* it under the terms of the GNU General Public License as published by |
| 23 |
c* the Free Software Foundation; either version 2 of the License, or |
| 24 |
c* (at your option) any later version. |
| 25 |
c* |
| 26 |
c* PMG is distributed in the hope that it will be useful, |
| 27 |
c* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 |
c* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 |
c* GNU General Public License for more details. |
| 30 |
c* |
| 31 |
c* You should have received a copy of the GNU General Public License |
| 32 |
c* along with PMG; if not, write to the Free Software |
| 33 |
c* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 34 |
c* |
| 35 |
c* Linking PMG statically or dynamically with other modules is making a |
| 36 |
c* combined work based on PMG. Thus, the terms and conditions of the GNU |
| 37 |
c* General Public License cover the whole combination. |
| 38 |
c* |
| 39 |
c* SPECIAL GPL EXCEPTION |
| 40 |
c* In addition, as a special exception, the copyright holders of PMG |
| 41 |
c* give you permission to combine the PMG program with free software |
| 42 |
c* programs and libraries that are released under the GNU LGPL or with |
| 43 |
c* code included in releases of ISIM, PMV, PyMOL, SMOL, VMD, and Vision. |
| 44 |
c* Such combined software may be linked with PMG and redistributed together |
| 45 |
c* in original or modified form as mere aggregation without requirement that |
| 46 |
c* the entire work be under the scope of the GNU General Public License. |
| 47 |
c* This special exception permission is also extended to any software listed |
| 48 |
c* in the SPECIAL GPL EXCEPTION clauses by the FEtk and APBS libraries. |
| 49 |
c* |
| 50 |
c* Note that people who make modified versions of PMG are not obligated |
| 51 |
c* to grant this special exception for their modified versions; it is |
| 52 |
c* their choice whether to do so. The GNU General Public License gives |
| 53 |
c* permission to release a modified version without this exception; this |
| 54 |
c* exception also makes it possible to release a modified version which |
| 55 |
c* carries forward this exception. |
| 56 |
c* |
| 57 |
c* @endverbatim |
| 58 |
c* /////////////////////////////////////////////////////////////////////////// |
| 59 |
|
| 60 |
subroutine fnewton(nx,ny,nz,x,iz,w0,w1,w2,w3, |
| 61 |
2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv, |
| 62 |
3 iok,iinfo,epsiln,errtol,omega,nu1,nu2,mgsmoo, |
| 63 |
4 cprime,rhs,xtmp, |
| 64 |
5 ipc,rpc,pc,ac,cc,fc,tru) |
| 65 |
c* ********************************************************************* |
| 66 |
c* purpose: |
| 67 |
c* |
| 68 |
c* nested iteration for an inexact-newton-multilevel method. |
| 69 |
c* |
| 70 |
c* author: michael holst |
| 71 |
c* ********************************************************************* |
| 72 |
implicit none |
| 73 |
c* |
| 74 |
c* *** other declarations *** |
| 75 |
integer ipc(*),iz(50,*),iok,ilev,iinfo,nlev,itmax |
| 76 |
integer iters,ierror,level,itmxd,nlevd,iterd,iokd,istop |
| 77 |
integer nx,ny,nz,nxf,nyf,nzf,nxc,nyc,nzc,nlev_real,istpd |
| 78 |
integer nu1,nu2,mgsmoo,mgsolv |
| 79 |
double precision epsiln,errd,errtol,omega |
| 80 |
double precision x(*),w0(*),w1(*),w2(*),w3(*) |
| 81 |
double precision rpc(*),pc(*),ac(*),cc(*),fc(*),tru(*) |
| 82 |
double precision cprime(*),rhs(*),xtmp(*) |
| 83 |
c* |
| 84 |
c* *** recover gridsizes *** |
| 85 |
nxf = nx |
| 86 |
nyf = ny |
| 87 |
nzf = nz |
| 88 |
call mkcors(nlev-1,nxf,nyf,nzf,nxc,nyc,nzc) |
| 89 |
c* |
| 90 |
c* *** move up grids: interpolate solution to finer, do newton *** |
| 91 |
if (iinfo.ne.0) then |
| 92 |
write(6,100)'% FNEWTON: starting:',nxf,nyf,nzf,nxc,nyc,nzc |
| 93 |
100 format(a,2(2x,' [',i3,',',i3,',',i3,'] ')) |
| 94 |
endif |
| 95 |
do 10 level = nlev_real, ilev+1, -1 |
| 96 |
c* |
| 97 |
c* *** call mv cycle *** |
| 98 |
errd = errtol |
| 99 |
itmxd = 1000 |
| 100 |
nlevd = nlev_real - level + 1 |
| 101 |
iterd = 0 |
| 102 |
iokd = iok |
| 103 |
istpd = istop |
| 104 |
call newton(nxc,nyc,nzc,x,iz,w0,w1,w2,w3, |
| 105 |
2 istpd,itmxd,iterd,ierror,nlevd,level,nlev_real,mgsolv, |
| 106 |
3 iokd,iinfo,epsiln,errd,omega,nu1,nu2,mgsmoo, |
| 107 |
4 cprime,rhs,xtmp, |
| 108 |
5 ipc,rpc,pc,ac,cc,fc,tru) |
| 109 |
c* |
| 110 |
c* *** find new grid size *** |
| 111 |
call mkfine(1,nxc,nyc,nzc,nxf,nyf,nzf) |
| 112 |
c* |
| 113 |
c* *** interpolate to next finer grid (use correct bc's) *** |
| 114 |
call interp(nxc,nyc,nzc,nxf,nyf,nzf, |
| 115 |
2 x(iz(1,level)),x(iz(1,level-1)),pc(iz(11,level-1))) |
| 116 |
CZZZ call ninterp(nxc,nyc,nzc,nxf,nyf,nzf, |
| 117 |
CZZZ 2 x(iz(1,level)),x(iz(1,level-1)),pc(iz(11,level-1)), |
| 118 |
CZZZ 3 ipc(iz(5,level-1)),rpc(iz(6,level-1)), |
| 119 |
CZZZ 4 ac(iz(7,level-1)),cc(iz(1,level-1)),fc(iz(1,level-1))) |
| 120 |
c* |
| 121 |
c* *** new grid size *** |
| 122 |
nxc = nxf |
| 123 |
nyc = nyf |
| 124 |
nzc = nzf |
| 125 |
10 continue |
| 126 |
c* |
| 127 |
c* *** call mv cycle *** |
| 128 |
level = ilev |
| 129 |
call newton(nx,ny,nz,x,iz,w0,w1,w2,w3, |
| 130 |
2 istop,itmax,iters,ierror,nlev,level,nlev_real,mgsolv, |
| 131 |
3 iok,iinfo,epsiln,errtol,omega,nu1,nu2,mgsmoo, |
| 132 |
4 cprime,rhs,xtmp, |
| 133 |
5 ipc,rpc,pc,ac,cc,fc,tru) |
| 134 |
c* |
| 135 |
c* *** return and end *** |
| 136 |
return |
| 137 |
end |
| 138 |
subroutine newton(nx,ny,nz,x,iz,w0,w1,w2,w3, |
| 139 |
2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv, |
| 140 |
3 iok,iinfo,epsiln,errtol,omega,nu1,nu2,mgsmoo, |
| 141 |
4 cprime,rhs,xtmp, |
| 142 |
5 ipc,rpc,pc,ac,cc,fc,tru) |
| 143 |
c* ********************************************************************* |
| 144 |
c* purpose: |
| 145 |
c* |
| 146 |
c* inexact-newton-multilevel method. |
| 147 |
c* |
| 148 |
c* author: michael holst |
| 149 |
c* ********************************************************************* |
| 150 |
implicit none |
| 151 |
c* |
| 152 |
c* *** other declarations *** |
| 153 |
integer ipc(*),iz(50,*),iok,ilev,iinfo,nlev,level,lev |
| 154 |
integer itmax,iters,ierror,istop,nu1,nu2,mgsmoo |
| 155 |
integer itmax_s,iters_s,ierror_s,iok_s,iinfo_s,istop_s |
| 156 |
integer nx,ny,nz,nlev_real,mgsolv |
| 157 |
double precision errtol,epsiln,omega,errtol_s,ord,bigc |
| 158 |
double precision rsden,rsnrm,orsnrm,xnrm1,xnrm2,xdot |
| 159 |
double precision x(*),w0(*),w1(*),w2(*),w3(*) |
| 160 |
double precision rpc(*),pc(*),ac(*),cc(*),fc(*),tru(*) |
| 161 |
double precision cprime(*),rhs(*),xtmp(*) |
| 162 |
c* |
| 163 |
c* *** local variables *** |
| 164 |
double precision xnorm_old,xnorm_new,damp,xnorm_med,xnorm_den |
| 165 |
double precision rho_max,rho_min,rho_max_mod,rho_min_mod,errtol_p |
| 166 |
integer iter_d,itmax_d,mode,idamp,ipkey |
| 167 |
integer itmax_p,iters_p,iok_p,iinfo_p |
| 168 |
c* |
| 169 |
c* *** recover level information *** |
| 170 |
level = 1 |
| 171 |
lev = (ilev-1)+level |
| 172 |
c* |
| 173 |
c* *** do some i/o if requested *** |
| 174 |
if (iinfo.ne.0) then |
| 175 |
write(6,100)'% NEWTON: starting: ',nx,ny,nz |
| 176 |
100 format(a,(2x,' [',i3,',',i3,',',i3,'] ')) |
| 177 |
endif |
| 178 |
c* |
| 179 |
c* *** initial wall clock *** |
| 180 |
if (iok.ne.0) then |
| 181 |
call prtini(istop) |
| 182 |
call prtstp(iok,-1,0.0d0,0.0d0,0.0d0) |
| 183 |
endif |
| 184 |
c* |
| 185 |
c* ************************************************************** |
| 186 |
c* *** note: if (iok.ne.0) then: use a stopping test. *** |
| 187 |
c* *** else: use just the itmax to stop iteration. *** |
| 188 |
c* ************************************************************** |
| 189 |
c* *** istop=0 most efficient (whatever it is) *** |
| 190 |
c* *** istop=1 relative residual *** |
| 191 |
c* *** istop=2 rms difference of successive iterates *** |
| 192 |
c* *** istop=3 relative true error (provided for testing) *** |
| 193 |
c* ************************************************************** |
| 194 |
c* |
| 195 |
c* *** compute denominator for stopping criterion *** |
| 196 |
if (istop .eq. 0) then |
| 197 |
rsden = 1.0d0 |
| 198 |
elseif (istop .eq. 1) then |
| 199 |
c* *** compute initial residual with zero initial guess *** |
| 200 |
c* *** this is analogous to the linear case where one can *** |
| 201 |
c* *** simply take norm of rhs for a zero initial guess *** |
| 202 |
call azeros(nx,ny,nz,w1) |
| 203 |
call nmresid(nx,ny,nz, |
| 204 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 205 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 206 |
4 w1,w2,w3) |
| 207 |
rsden = xnrm1(nx,ny,nz,w2) |
| 208 |
elseif (istop .eq. 2) then |
| 209 |
rsden = dsqrt(dble(nx*ny*nz)) |
| 210 |
elseif (istop .eq. 3) then |
| 211 |
rsden = xnrm2(nx,ny,nz,tru(iz(1,lev))) |
| 212 |
elseif (istop .eq. 4) then |
| 213 |
rsden = xnrm2(nx,ny,nz,tru(iz(1,lev))) |
| 214 |
elseif (istop .eq. 5) then |
| 215 |
call nmatvec(nx,ny,nz, |
| 216 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 217 |
3 ac(iz(7,lev)),cc(iz(1,lev)), |
| 218 |
4 tru(iz(1,lev)),w1,w2) |
| 219 |
rsden = dsqrt(xdot(nx,ny,nz,tru(iz(1,lev)),w1)) |
| 220 |
else |
| 221 |
print*,'% NEWTON: bad istop value... ' |
| 222 |
endif |
| 223 |
if (rsden.eq.0.0d0) then |
| 224 |
rsden = 1.0d0 |
| 225 |
print*,'% NEWTON: rhs is zero...' |
| 226 |
endif |
| 227 |
rsnrm = rsden |
| 228 |
orsnrm = rsnrm |
| 229 |
if (iok.ne.0) call prtstp (iok,0,rsnrm,rsden,orsnrm) |
| 230 |
c* |
| 231 |
c* ********************************************************************* |
| 232 |
c* *** begin newton iteration |
| 233 |
c* ********************************************************************* |
| 234 |
c* |
| 235 |
c* *** now compute residual with the initial guess *** |
| 236 |
call nmresid(nx,ny,nz, |
| 237 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 238 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 239 |
4 x(iz(1,lev)),w0,w2) |
| 240 |
xnorm_old = xnrm1(nx,ny,nz,w0) |
| 241 |
if (iok.ne.0) then |
| 242 |
xnorm_den = rsden |
| 243 |
else |
| 244 |
xnorm_den = xnorm_old |
| 245 |
endif |
| 246 |
c* |
| 247 |
c* ********************************************************************* |
| 248 |
c* *** begin the loop |
| 249 |
c* ********************************************************************* |
| 250 |
c* |
| 251 |
c* *** setup for the looping *** |
| 252 |
print*,'% NEWTON: damping enabled...' |
| 253 |
idamp = 1 |
| 254 |
iters = 0 |
| 255 |
30 continue |
| 256 |
iters = iters + 1 |
| 257 |
c* |
| 258 |
c* *** save iterate if stop test will use it on next iter *** |
| 259 |
if (istop .eq. 2) call xcopy(nx,ny,nz,x(iz(1,lev)), |
| 260 |
2 tru(iz(1,lev))) |
| 261 |
c* |
| 262 |
c* *** compute the current jacobian system and rhs *** |
| 263 |
ipkey = ipc(10) |
| 264 |
call getjac (nx,ny,nz,nlev_real,iz,ilev,ipkey, |
| 265 |
2 x,w0,cprime,rhs,cc,pc) |
| 266 |
c* |
| 267 |
c* ***** *** determine number of correct digits in current residual *** |
| 268 |
c* ***** if (lev .eq. 1) then |
| 269 |
c* ***** itmax_s = -idnint(dlog10(xnorm_old/xnorm_den)) |
| 270 |
c* ***** itmax_s = max0(itmax_s,1) |
| 271 |
c* ***** else |
| 272 |
c* ***** itmax_s = 10 |
| 273 |
c* ***** endif |
| 274 |
c* ***** itmax_s = 1000 |
| 275 |
c* ***** print*,'% NEWTON: using itmax_s: ',itmax_s |
| 276 |
c* |
| 277 |
c* *** algorithm 5.3 in the thesis, test version (1') *** |
| 278 |
c* *** global-superlinear convergence *** |
| 279 |
bigc = 1.0d0 |
| 280 |
ord = 2.0d0 |
| 281 |
errtol_s = dmin1((0.9*xnorm_old),(bigc*xnorm_old**ord)) |
| 282 |
print*,'% NEWTON: using errtol_s: ',errtol_s |
| 283 |
c* |
| 284 |
c* *** do a linear multigrid solve of the newton equations *** |
| 285 |
call azeros(nx,ny,nz,xtmp(iz(1,lev))) |
| 286 |
itmax_s = 1000 |
| 287 |
istop_s = 0 |
| 288 |
iters_s = 0 |
| 289 |
ierror_s = 0 |
| 290 |
iok_s = 0 |
| 291 |
iinfo_s = 0 |
| 292 |
if ((iinfo .ge. 2) .and. (ilev .eq. 1)) iok_s = 2 |
| 293 |
call mvcs(nx,ny,nz,xtmp,iz,w0,w1,w2,w3, |
| 294 |
2 istop_s,itmax_s,iters_s,ierror_s, |
| 295 |
3 nlev,ilev,nlev_real,mgsolv, |
| 296 |
4 iok_s,iinfo_s,epsiln,errtol_s,omega,nu1,nu2,mgsmoo, |
| 297 |
5 ipc,rpc,pc,ac,cprime,rhs,tru) |
| 298 |
c* |
| 299 |
c* ************************************************************** |
| 300 |
c* *** note: rhs and cprime are now available as temp vectors *** |
| 301 |
c* ************************************************************** |
| 302 |
c* |
| 303 |
c* *** if damping is still enabled -- doit *** |
| 304 |
if (idamp .eq. 1) then |
| 305 |
c* |
| 306 |
c* *** try the correction *** |
| 307 |
call xcopy(nx,ny,nz,x(iz(1,lev)),w1) |
| 308 |
damp = 1.0d0 |
| 309 |
call xaxpy(nx,ny,nz,damp,xtmp(iz(1,lev)),w1) |
| 310 |
call nmresid(nx,ny,nz, |
| 311 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 312 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 313 |
4 w1,w0,rhs(iz(1,lev))) |
| 314 |
xnorm_new = xnrm1(nx,ny,nz,w0) |
| 315 |
c* |
| 316 |
c* *** damping is still enabled -- doit *** |
| 317 |
damp = 1.0d0 |
| 318 |
iter_d = 0 |
| 319 |
itmax_d = 10 |
| 320 |
mode = 0 |
| 321 |
write(6,110) |
| 322 |
2 'NEWTON: attempting damping: iter_d, relres = ', |
| 323 |
3 iter_d,(xnorm_new/xnorm_den) |
| 324 |
110 format('% ',a,i5,1pe10.2) |
| 325 |
11 continue |
| 326 |
if (iter_d .ge. itmax_d) goto 12 |
| 327 |
if (mode .eq. 0) then |
| 328 |
if (xnorm_new .lt. xnorm_old) mode = 1 |
| 329 |
else |
| 330 |
if (xnorm_new .gt. xnorm_med) goto 12 |
| 331 |
endif |
| 332 |
c* |
| 333 |
c* *** keep old soln and residual around, and its norm *** |
| 334 |
call xcopy(nx,ny,nz,w1,w2) |
| 335 |
call xcopy(nx,ny,nz,w0,w3) |
| 336 |
xnorm_med = xnorm_new |
| 337 |
c* |
| 338 |
c* *** new damped correction, residual, and its norm *** |
| 339 |
call xcopy(nx,ny,nz,x(iz(1,lev)),w1) |
| 340 |
damp = damp / 2.0d0 |
| 341 |
call xaxpy(nx,ny,nz,damp,xtmp(iz(1,lev)),w1) |
| 342 |
call nmresid(nx,ny,nz, |
| 343 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 344 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 345 |
4 w1,w0,rhs(iz(1,lev))) |
| 346 |
xnorm_new = xnrm1(nx,ny,nz,w0) |
| 347 |
c* |
| 348 |
c* *** next iter... *** |
| 349 |
iter_d = iter_d + 1 |
| 350 |
write(6,110) |
| 351 |
2 'NEWTON: attempting damping: iter_d, relres = ', |
| 352 |
3 iter_d,(xnorm_new/xnorm_den) |
| 353 |
goto 11 |
| 354 |
c* |
| 355 |
c* *** accept the previous newton step *** |
| 356 |
12 continue |
| 357 |
call xcopy(nx,ny,nz,w2,x(iz(1,lev))) |
| 358 |
call xcopy(nx,ny,nz,w3,w0) |
| 359 |
xnorm_new = xnorm_med |
| 360 |
xnorm_old = xnorm_new |
| 361 |
write(6,110) |
| 362 |
2 'NEWTON: damping accepted: iter_d, relres = ', |
| 363 |
3 iter_d-1,(xnorm_new/xnorm_den) |
| 364 |
c* |
| 365 |
c* *** determine whether or not to disable damping *** |
| 366 |
if ((iter_d-1) .eq. 0) then |
| 367 |
print*,'% NEWTON: damping disabled...' |
| 368 |
idamp = 0 |
| 369 |
endif |
| 370 |
else |
| 371 |
c* |
| 372 |
c* *** damping is disabled -- accept the newton step *** |
| 373 |
damp = 1.0d0 |
| 374 |
call xaxpy(nx,ny,nz,damp,xtmp(iz(1,lev)),x(iz(1,lev))) |
| 375 |
call nmresid(nx,ny,nz, |
| 376 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 377 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 378 |
4 x(iz(1,lev)),w0,rhs(iz(1,lev))) |
| 379 |
xnorm_new = xnrm1(nx,ny,nz,w0) |
| 380 |
xnorm_old = xnorm_new |
| 381 |
endif |
| 382 |
c* |
| 383 |
c* *** compute/check the current stopping test *** |
| 384 |
if (iok.ne.0) then |
| 385 |
orsnrm = rsnrm |
| 386 |
if (istop .eq. 0) then |
| 387 |
rsnrm = xnorm_new |
| 388 |
elseif (istop .eq. 1) then |
| 389 |
rsnrm = xnorm_new |
| 390 |
elseif (istop .eq. 2) then |
| 391 |
call xcopy(nx,ny,nz,tru(iz(1,lev)),w1) |
| 392 |
call xaxpy(nx,ny,nz,(-1.0d0),x(iz(1,lev)),w1) |
| 393 |
rsnrm = xnrm1(nx,ny,nz,w1) |
| 394 |
elseif (istop .eq. 3) then |
| 395 |
call xcopy(nx,ny,nz,tru(iz(1,lev)),w1) |
| 396 |
call xaxpy(nx,ny,nz,(-1.0d0),x(iz(1,lev)),w1) |
| 397 |
rsnrm = xnrm2(nx,ny,nz,w1) |
| 398 |
elseif (istop .eq. 4) then |
| 399 |
call xcopy(nx,ny,nz,tru(iz(1,lev)),w1) |
| 400 |
call xaxpy(nx,ny,nz,(-1.0d0),x(iz(1,lev)),w1) |
| 401 |
rsnrm = xnrm2(nx,ny,nz,w1) |
| 402 |
elseif (istop .eq. 5) then |
| 403 |
call xcopy(nx,ny,nz,tru(iz(1,lev)),w1) |
| 404 |
call xaxpy(nx,ny,nz,(-1.0d0),x(iz(1,lev)),w1) |
| 405 |
call nmatvec(nx,ny,nz, |
| 406 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 407 |
3 ac(iz(7,lev)),cc(iz(1,lev)), |
| 408 |
4 w1,w2,w3) |
| 409 |
rsnrm = dsqrt(xdot(nx,ny,nz,w1,w2)) |
| 410 |
else |
| 411 |
print*,'% NEWTON: bad istop value... ' |
| 412 |
endif |
| 413 |
call prtstp (iok,iters,rsnrm,rsden,orsnrm) |
| 414 |
if ((rsnrm/rsden) .le. errtol) goto 99 |
| 415 |
endif |
| 416 |
c* |
| 417 |
c* *** check iteration count *** |
| 418 |
if (iters .ge. itmax) goto 99 |
| 419 |
c* |
| 420 |
c* *** main loop *** |
| 421 |
goto 30 |
| 422 |
c* |
| 423 |
c* *** a few things *** |
| 424 |
99 continue |
| 425 |
c* |
| 426 |
c* *** condition estimate of final jacobian *** |
| 427 |
if (iinfo .gt. 2) then |
| 428 |
print*,'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' |
| 429 |
2 ,'%%%%%%%%%%' |
| 430 |
write(6,200)'% NEWTON: JACOBIAN ANALYSIS==>',nx,ny,nz |
| 431 |
200 format(a,' [',i3,',',i3,',',i3,'] ') |
| 432 |
c* |
| 433 |
c* *** largest eigenvalue of the jacobian matrix *** |
| 434 |
print*,'% NEWTON: power calculating rho(JAC)...' |
| 435 |
itmax_p = 1000 |
| 436 |
errtol_p = 1.0e-4 |
| 437 |
iters_p = 0 |
| 438 |
iinfo_p = iinfo |
| 439 |
call power(nx,ny,nz,iz,ilev, |
| 440 |
2 ipc,rpc,ac,cprime, |
| 441 |
3 w0,w1,w2,w3, |
| 442 |
4 rho_max,rho_max_mod,errtol_p,itmax_p,iters_p,iinfo_p) |
| 443 |
print*,'% NEWTON: power iters = ',iters_p |
| 444 |
print*,'% NEWTON: power eigmax = ',rho_max |
| 445 |
print*,'% NEWTON: power (MODEL) = ',rho_max_mod |
| 446 |
c* |
| 447 |
c* *** smallest eigenvalue of the system matrix A *** |
| 448 |
print*,'% NEWTON: ipower calculating lambda_min(JAC)...' |
| 449 |
itmax_p = 1000 |
| 450 |
errtol_p = 1.0e-4 |
| 451 |
iters_p = 0 |
| 452 |
iinfo_p = iinfo |
| 453 |
call azeros(nx,ny,nz,xtmp) |
| 454 |
call ipower(nx,ny,nz,xtmp,iz, |
| 455 |
2 w0,w1,w2,w3,rhs, |
| 456 |
3 rho_min,rho_min_mod,errtol_p,itmax_p,iters_p, |
| 457 |
4 nlev,ilev,nlev_real,mgsolv, |
| 458 |
5 iok_p,iinfo_p,epsiln,errtol,omega,nu1,nu2,mgsmoo, |
| 459 |
6 ipc,rpc,pc,ac,cprime,tru) |
| 460 |
print*,'% NEWTON: ipower iters = ',iters_p |
| 461 |
print*,'% NEWTON: ipower eigmin = ',rho_min |
| 462 |
print*,'% NEWTON: ipower (MODEL) = ',rho_min_mod |
| 463 |
c* |
| 464 |
c* *** condition number estimate *** |
| 465 |
print*,'% NEWTON: condition number = ',rho_max/rho_min |
| 466 |
print*,'% NEWTON: condition (MODEL) = ', |
| 467 |
2 rho_max_mod/rho_min_mod |
| 468 |
print*,'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' |
| 469 |
2 ,'%%%%%%%%%%' |
| 470 |
endif |
| 471 |
c* |
| 472 |
c* *** return and end *** |
| 473 |
return |
| 474 |
end |
| 475 |
subroutine getjac (nx,ny,nz,nlev_real,iz,lev,ipkey, |
| 476 |
2 x,r,cprime,rhs,cc,pc) |
| 477 |
c* ********************************************************************* |
| 478 |
c* purpose: |
| 479 |
c* |
| 480 |
c* form the jacobian system. |
| 481 |
c* |
| 482 |
c* author: michael holst |
| 483 |
c* ********************************************************************* |
| 484 |
implicit none |
| 485 |
integer iz(50,*),nx,ny,nz,nlev_real,lev,level |
| 486 |
integer nxx,nyy,nzz,nxold,nyold,nzold,ipkey |
| 487 |
double precision x(*),r(*),cprime(*),rhs(*),cc(*),pc(*) |
| 488 |
c* |
| 489 |
c* *** setup *** |
| 490 |
nxx = nx |
| 491 |
nyy = ny |
| 492 |
nzz = nz |
| 493 |
c* |
| 494 |
c* *** form the rhs of the newton system -- just current residual *** |
| 495 |
call xcopy(nx,ny,nz,r,rhs(iz(1,lev))) |
| 496 |
c* |
| 497 |
c* *** get nonlinear part of the jacobian operator *** |
| 498 |
call dc_vec(cc(iz(1,lev)),x(iz(1,lev)),cprime(iz(1,lev)), |
| 499 |
2 nx,ny,nz,ipkey) |
| 500 |
c* |
| 501 |
c* *** build the (nlev-1) level operators *** |
| 502 |
do 10 level = lev+1, nlev_real |
| 503 |
nxold = nxx |
| 504 |
nyold = nyy |
| 505 |
nzold = nzz |
| 506 |
call mkcors(1,nxold,nyold,nzold,nxx,nyy,nzz) |
| 507 |
c* |
| 508 |
c* *** make the coarse grid rhs functions *** |
| 509 |
call restrc(nxold,nyold,nzold,nxx,nyy,nzz, |
| 510 |
2 rhs(iz(1,level-1)),rhs(iz(1,level)),pc(iz(11,level-1))) |
| 511 |
c* |
| 512 |
c* *** make the coarse grid helmholtz terms *** |
| 513 |
call restrc(nxold,nyold,nzold,nxx,nyy,nzz, |
| 514 |
2 cprime(iz(1,level-1)),cprime(iz(1,level)), |
| 515 |
3 pc(iz(11,level-1))) |
| 516 |
10 continue |
| 517 |
c* |
| 518 |
c* *** end it *** |
| 519 |
return |
| 520 |
end |