Debian Codegraph @

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

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file cgmgdrvd.f
3 c* @author Michael Holst
4 c* @brief Driver for CG preconditioned with MG.
5 c* @version $Id: cgmgdrvd.f,v 1.2 2010/08/12 05:45:32 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 cgmgdriv(iparm,rparm,iwork,rwork,u,
61 2 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
62 c* *********************************************************************
63 c* purpose:
64 c*
65 c* multilevel preconditioned cg driver
66 c*
67 c* author: michael holst
68 c* *********************************************************************
69 implicit none
70 c*
71 c* *** input parameters ***
72 integer iparm(*),iwork(*)
73 double precision rparm(*),rwork(*),u(*)
74 double precision xf(*),yf(*),zf(*),gxcf(*),gycf(*),gzcf(*)
75 double precision a1cf(*),a2cf(*),a3cf(*),ccf(*),fcf(*),tcf(*)
76 c*
77 c* *** variables returned from mgsz ***
78 integer nxc,nyc,nzc,nf,nc,narr,narrc,n_rpc
79 integer n_iz,n_ipc,iretot,iintot
80 c*
81 c* *** misc variables ***
82 integer nrwk,niwk,nx,ny,nz,nlev,ierror,maxlev,mxlv
83 integer mgcoar,mgdisc,mgsolv
84 integer k_iz,k_w1,k_w2
85 integer k_ipc,k_rpc,k_ac,k_cc,k_fc,k_pc
86 c*
87 c* *** decode some parameters ***
88 nrwk = iparm(1)
89 niwk = iparm(2)
90 nx = iparm(3)
91 ny = iparm(4)
92 nz = iparm(5)
93 nlev = iparm(6)
94 c*
95 c* *** some checks on input ***
96 if ((nlev.le.0).or.(nx.le.0).or.(ny.le.0).or.(nz.le.0)) then
97 print*,'% CGMGDRIV: nx,ny,nz, and nlev must be positive...'
98 ierror = -1
99 iparm(51) = ierror
100 return
101 endif
102 mxlv = maxlev(nx,ny,nz)
103 if (nlev.gt.mxlv) then
104 print*,'% CGMGDRIV: max levels for your grid size is: ',mxlv
105 ierror = -2
106 iparm(51) = ierror
107 return
108 endif
109 c*
110 c* *** basic grid sizes, etc. ***
111 mgcoar = iparm(18)
112 mgdisc = iparm(19)
113 mgsolv = iparm(21)
114 call mgsz(mgcoar,mgdisc,mgsolv,nx,ny,nz,nlev,nxc,nyc,nzc,
115 2 nf,nc,narr,narrc,n_rpc,n_iz,n_ipc,iretot,iintot)
116 c*
117 c* *** allocate space for two additional work vectors ***
118 iretot = iretot + 2*nf
119 c*
120 c* *** some more checks on input ***
121 if ((nrwk.lt.iretot) .or. (niwk.lt.iintot)) then
122 print*,'% CGMGDRIV: real work space must be: ',iretot
123 print*,'% CGMGDRIV: integer work space must be: ',iintot
124 ierror = -3
125 iparm(51) = ierror
126 return
127 endif
128 c*
129 c* *** split up the integer work array ***
130 k_iz = 1
131 k_ipc = k_iz + n_iz
132 c*
133 c* *** split up the real work array ***
134 k_rpc = 1
135 k_cc = k_rpc + n_rpc
136 k_fc = k_cc + narr
137 k_w1 = k_fc + narr
138 k_w2 = k_w1 + nf
139 k_pc = k_w2 + nf
140 k_ac = k_pc + 27*narrc
141 c* ***k_ac_after = 4*nf + 14*narrc
142 c*
143 c* *** call the multigrid driver ***
144 call cgmgdriv2(iparm,rparm,nx,ny,nz,u,iwork(k_iz),
145 2 rwork(k_w1),rwork(k_w2),
146 3 iwork(k_ipc),rwork(k_rpc),
147 4 rwork(k_pc),rwork(k_ac),rwork(k_cc),rwork(k_fc),
148 5 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
149 c*
150 c* *** return and end ***
151 return
152 end
153 subroutine cgmgdriv2(iparm,rparm,nx,ny,nz,u,iz,
154 2 w1,w2,
155 3 ipc,rpc,pc,ac,cc,fc,
156 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
157 c* *********************************************************************
158 c* purpose:
159 c*
160 c* this routine uses a conjugate gradient iteration combined with a
161 c* multigrid v-cycle preconditioner to solve the three-dimensional,
162 c* 2nd order elliptic partial differential equation:
163 c*
164 c* lu = f, u in omega
165 c* u = g, u on boundary of omega
166 c* where
167 c*
168 c* omega = [xmin,xmax]x[ymin,ymax]x[zmin,zmax]
169 c*
170 c* the code requires the operator in the form:
171 c*
172 c* - \nabla \cdot (a \nabla u) + c u = f
173 c*
174 c* with
175 c*
176 c* a(x,y,z),f(x,y,z), scalar functions (possibly discontinuous)
177 c* on omega. (discontinuities must be along fine grid lines).
178 c* boundary function g(x,y,z) is smooth on boundary of omega.
179 c*
180 c* the function c(x,y,z) and varies (possibly discontinuously)
181 c* with the spatial position.
182 c*
183 c* user inputs:
184 c*
185 c* the user must provide the coefficients of the differential
186 c* operator, some initial parameter settings in an integer and a
187 c* real parameter array, and various work arrays.
188 c*
189 c* author: michael holst
190 c* *********************************************************************
191 implicit none
192 c*
193 c* *** input parameters ***
194 integer iparm(*),ipc(*),iz(*)
195 double precision rparm(*),rpc(*),pc(*),ac(*),cc(*),fc(*)
196 double precision u(*),w1(*),w2(*)
197 double precision xf(*),yf(*),zf(*),gxcf(*),gycf(*),gzcf(*)
198 double precision a1cf(*),a2cf(*),a3cf(*),ccf(*),fcf(*),tcf(*)
199 c*
200 c* *** misc variables ***
201 integer mgkey,nlev,itmax,iok,iinfo,istop,ipkey,nu1,nu2
202 integer nx,ny,nz,ilev,ido,iters,ierror,nlev_real,ibound
203 integer mgprol,mgcoar,mgsolv,mgdisc,mgsmoo,mode
204 double precision epsiln,epsmac,errtol,omegal,omegan
205 double precision bf,oh,tsetupf,tsetupc,tsolve
206 c*
207 c* *** decode the iparm array ***
208 nlev = iparm(6)
209 nu1 = iparm(7)
210 nu2 = iparm(8)
211 mgkey = iparm(9)
212 itmax = iparm(10)
213 istop = iparm(11)
214 iinfo = iparm(12)
215 ipkey = iparm(14)
216 mgprol = iparm(17)
217 mgcoar = iparm(18)
218 mgdisc = iparm(19)
219 mgsmoo = iparm(20)
220 mgsolv = iparm(21)
221 errtol = rparm(1)
222 omegal = rparm(9)
223 omegan = rparm(10)
224 c*
225 c* *** intitialize the iteration timer ***
226 call prtstp(0,-99,0.0d0,0.0d0,0.0d0)
227 c*
228 c* *** build the multigrid data structure in iz ***
229 call buildstr (nx,ny,nz,nlev,iz)
230 c*
231 c* *** start timer ***
232 call tstart(bf,oh)
233 c*
234 c* *** build op and rhs on fine grid ***
235 ido = 0
236 call buildops (nx,ny,nz,nlev,ipkey,iinfo,ido,iz,
237 2 mgprol,mgcoar,mgsolv,mgdisc,
238 3 ipc,rpc,pc,ac,cc,fc,
239 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
240 c*
241 c* *** stop timer ***
242 call tstop(bf,oh,tsetupf)
243 print*,'% CGMGDRIV2: fine problem setup time: ',tsetupf
244 c*
245 c* *** start timer ***
246 call tstart(bf,oh)
247 c*
248 c* *** build op and rhs on all coarse grids ***
249 ido = 1
250 call buildops (nx,ny,nz,nlev,ipkey,iinfo,ido,iz,
251 2 mgprol,mgcoar,mgsolv,mgdisc,
252 3 ipc,rpc,pc,ac,cc,fc,
253 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
254 c*
255 c* *** stop timer ***
256 call tstop(bf,oh,tsetupc)
257 print*,'% CGMGDRIV2: coarse problem setup time: ',tsetupc
258 c*
259 c* ******************************************************************
260 c* *** this overwrites the rhs array provided by pde specification
261 c* ****** compute an algebraically produced rhs for the given tcf ***
262 mode = 0
263 if ((istop .eq. 4) .or. (istop .eq. 5)) then
264 call buildALG (nx,ny,nz,mode,nlev,iz,
265 2 ipc,rpc,ac,cc,ccf,tcf,fc,fcf)
266 endif
267 c* ******************************************************************
268 c*
269 c* *** determine machine epsilon ***
270 epsiln = epsmac(0)
271 c*
272 c* *** impose zero dirichlet boundary conditions (now in source fcn) ***
273 call fbound00(nx,ny,nz,u)
274 c*
275 c* *** MATLAB ***
276 print*,' cgmg = [ '
277 c*
278 c* *** start timer ***
279 call tstart(bf,oh)
280 c*
281 c* *** call specified multigrid method ***
282 nlev_real = nlev
283 iok = 1
284 ilev = 1
285 if (mgkey .eq. 0) then
286 call cgmg(nx,ny,nz,u,iz,ccf,fcf,w1,w2,
287 2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv,
288 3 iok,iinfo,epsiln,errtol,omegal,nu1,nu2,mgsmoo,
289 4 a1cf,a2cf,a3cf,
290 5 ipc,rpc,pc,ac,cc,fc,tcf)
291 else if (mgkey .eq. 1) then
292 call fcgmg(nx,ny,nz,u,iz,ccf,fcf,w1,w2,
293 2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv,
294 3 iok,iinfo,epsiln,errtol,omegal,nu1,nu2,mgsmoo,
295 4 a1cf,a2cf,a3cf,
296 5 ipc,rpc,pc,ac,cc,fc,tcf)
297 else
298 print*,'% CGMGDRIV2: bad mgkey given '
299 endif
300 c*
301 c* *** stop timer ***
302 call tstop(bf,oh,tsolve)
303 print*,'% CGMGDRIV2: solve time: ',tsolve
304 c*
305 c* *** MATLAB ***
306 write(*,100) 'cgmg_sf',tsetupf,'cgmg_sc',tsetupc,
307 2 'cgmg_st',(tsetupf+tsetupc),'cgmg_so',tsolve
308 100 format(' ];',4(' ',a7,'=',1pe9.3,';'))
309 c*
310 c* *** restore boundary conditions ***
311 ibound = 1
312 call fbound(ibound,nx,ny,nz,u,gxcf,gycf,gzcf)
313 c*
314 c* *** return and end ***
315 return
316 end