Debian Codegraph @

debian/external_deps/fetk/punc/src/pmg/src_f77/ncgd.f

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file ncgd.f
3 c* @author Michael Holst
4 c* @brief Nonlinear (Fletcher-Reeves) variation of (Hestenes-Stiefel) CG.
5 c* @version $Id: ncgd.f,v 1.2 2010/08/12 05:45:35 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 ncghs(nx,ny,nz,ipc,rpc,ac,cc,fc,x,p,ap,r,zk,zkp1,tmp,
61 2 itmax,iters,errtol,omega,iresid,iadjoint)
62 c* *********************************************************************
63 c* purpose:
64 c*
65 c* solves the a(x)=b using nonlinar conjugate gradients (fletcher-reeves).
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
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 zk(nx,ny,nz),zkp1(nx,ny,nz),tmp(nx,ny,nz)
75 double precision rhok1,rhok2,alpha,beta,xdot
76 c*
77 cmdir 0 0
78 c*
79 c* *** setup for the looping ***
80 iters = 0
81 if ((iters .ge. itmax) .and. (iresid .eq. 0)) goto 99
82 call nmresid(nx,ny,nz,ipc,rpc,ac,cc,fc,x,r,zk)
83 if (iters .ge. itmax) goto 99
84 30 continue
85 c*
86 c* *** compute/check the current stopping test ***
87 rhok2 = xdot(nx,ny,nz,r,r)
88 rsnrm = dsqrt(rhok2)
89 if (rsnrm .le. errtol) goto 99
90 if (iters .ge. itmax) goto 99
91 c*
92 c* *** form new direction vector from old one and residual ***
93 if (iters .eq. 0) then
94 call xcopy(nx,ny,nz,r,p)
95 else
96 beta = rhok2 / rhok1
97 call xaxpy(nx,ny,nz,((1.0d0)/beta),r,p)
98 call xscal(nx,ny,nz,beta,p)
99 endif
100 c*
101 c* *** nonlinear case: do a line search ***
102 c* *** (note: "ap,zk,zkp1" passed back from line search as desired) ***
103 call xcopy(nx,ny,nz,r,tmp)
104 call linesearch(nx,ny,nz,alpha,
105 2 ipc,rpc,ac,cc,fc,p,x,tmp,ap,zk,zkp1)
106 c*
107 c* *** save rhok2 for next iteration ***
108 rhok1 = rhok2
109 c*
110 c* *** update solution in direction p of length alpha ***
111 call xaxpy(nx,ny,nz,alpha,p,x)
112 c*
113 c* *** update residual ***
114 call xaxpy(nx,ny,nz,(-alpha),ap,r)
115 call xaxpy(nx,ny,nz,(1.0d0),zk,r)
116 call xaxpy(nx,ny,nz,(-1.0d0),zkp1,r)
117 c*
118 c* *** some bookkeeping ***
119 iters = iters + 1
120 goto 30
121 c*
122 c* *** return and end ***
123 99 continue
124 return
125 end