| 1 |
c* /////////////////////////////////////////////////////////////////////////// |
| 2 |
c* @file cgd.f |
| 3 |
c* @author Michael Holst |
| 4 |
c* @brief Classical (Hestenes-Stiefel) Conjugate Gradient Method. |
| 5 |
c* @version $Id: cgd.f,v 1.2 2010/08/12 05:45:31 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 cghs(nx,ny,nz,ipc,rpc,ac,cc,fc,x,p,ap,r, |
| 61 |
2 itmax,iters,errtol,omega,iresid,iadjoint) |
| 62 |
c* ********************************************************************* |
| 63 |
c* purpose: |
| 64 |
c* |
| 65 |
c* this routine solves the spd ax=b using conjugate gradients (cghs). |
| 66 |
c* |
| 67 |
c* author: michael holst |
| 68 |
c* ********************************************************************* |
| 69 |
implicit none |
| 70 |
integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz |
| 71 |
double precision omega,errtol,rsnrm,pAp,denom,xnrm2 |
| 72 |
double precision rpc(*),ac(nx,ny,nz,*),fc(nx,ny,nz),cc(nx,ny,nz) |
| 73 |
double precision x(nx,ny,nz),r(nx,ny,nz),p(nx,ny,nz),ap(nx,ny,nz) |
| 74 |
double precision rhok1,rhok2,alpha,beta,xdot |
| 75 |
c* |
| 76 |
cmdir 0 0 |
| 77 |
c* |
| 78 |
c* *** setup for the looping *** |
| 79 |
iters = 0 |
| 80 |
if ((iters .ge. itmax) .and. (iresid .eq. 0)) goto 99 |
| 81 |
call mresid(nx,ny,nz,ipc,rpc,ac,cc,fc,x,r) |
| 82 |
denom = xnrm2(nx,ny,nz,r) |
| 83 |
if (denom .eq. 0.0e0) goto 99 |
| 84 |
if (iters .ge. itmax) goto 99 |
| 85 |
30 continue |
| 86 |
c* |
| 87 |
c* *** compute/check the current stopping test *** |
| 88 |
rhok2 = xdot(nx,ny,nz,r,r) |
| 89 |
rsnrm = dsqrt(rhok2) |
| 90 |
c* ******print*,'% CGHS: iters, rsnrm = ',iters,rsnrm/denom |
| 91 |
if (rsnrm/denom .le. errtol) goto 99 |
| 92 |
if (iters .ge. itmax) goto 99 |
| 93 |
c* |
| 94 |
c* *** form new direction vector from old one and residual *** |
| 95 |
if (iters .eq. 0) then |
| 96 |
call xcopy(nx,ny,nz,r,p) |
| 97 |
else |
| 98 |
beta = rhok2 / rhok1 |
| 99 |
call xaxpy(nx,ny,nz,((1.0d0)/beta),r,p) |
| 100 |
call xscal(nx,ny,nz,beta,p) |
| 101 |
endif |
| 102 |
c* |
| 103 |
c* *** linear case: alpha which minimizes energy norm of error *** |
| 104 |
call matvec(nx,ny,nz,ipc,rpc,ac,cc,p,ap) |
| 105 |
pAp = xdot(nx,ny,nz,p,ap) |
| 106 |
alpha = rhok2 / pAp |
| 107 |
c* |
| 108 |
c* *** save rhok2 for next iteration *** |
| 109 |
rhok1 = rhok2 |
| 110 |
c* |
| 111 |
c* *** update solution in direction p of length alpha *** |
| 112 |
call xaxpy(nx,ny,nz,alpha,p,x) |
| 113 |
c* |
| 114 |
c* *** update residual *** |
| 115 |
call xaxpy(nx,ny,nz,(-alpha),ap,r) |
| 116 |
c* |
| 117 |
c* *** some bookkeeping *** |
| 118 |
iters = iters + 1 |
| 119 |
goto 30 |
| 120 |
c* |
| 121 |
c* *** return and end *** |
| 122 |
99 continue |
| 123 |
return |
| 124 |
end |
| 125 |
|