Debian Codegraph @

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

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file newdrvd.f
3 c* @author Michael Holst
4 c* @brief Driver for the Newton solver.
5 c* @version $Id: newdrvd.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 newdriv(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* driver for a screaming inexact-newton-multilevel solver.
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*,'% NEWDRIV: 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*,'% NEWDRIV: 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*,'% NEWDRIV: real work space must be: ',iretot
123 print*,'% NEWDRIV: 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 newdriv2(iparm,rparm,nx,ny,nz,u,iwork(k_iz),
145 3 rwork(k_w1),rwork(k_w2),
146 5 iwork(k_ipc),rwork(k_rpc),
147 6 rwork(k_pc),rwork(k_ac),rwork(k_cc),rwork(k_fc),
148 8 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 newdriv2(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 newton's method, combined with a linear
161 c* multigrid iteration, to solve the following 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 multigrid 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(u) is a possibly nonlinear function of the
181 c* unknown u, and varies (possibly discontinuously) with the
182 c* spatial position also.
183 c*
184 c* user inputs:
185 c*
186 c* the user must provide the coefficients of the differential
187 c* operator, some initial parameter settings in an integer and a
188 c* real parameter array, and various work arrays.
189 c*
190 c* author: michael holst
191 c* *********************************************************************
192 implicit none
193 c*
194 c* *** input parameters ***
195 integer iparm(*),ipc(*),iz(*)
196 double precision rparm(*),rpc(*),pc(*),ac(*),cc(*),fc(*)
197 double precision u(*),w1(*),w2(*)
198 double precision xf(*),yf(*),zf(*),gxcf(*),gycf(*),gzcf(*)
199 double precision a1cf(*),a2cf(*),a3cf(*),ccf(*),fcf(*),tcf(*)
200 c*
201 c* *** misc variables ***
202 integer mgkey,nlev,itmax,iok,iinfo,istop,ipkey,nu1,nu2
203 integer nx,ny,nz,ilev,ido,iters,ierror,nlev_real,ibound
204 integer mgprol,mgcoar,mgsolv,mgdisc,mgsmoo,mode
205 double precision epsiln,epsmac,errtol,omegal,omegan
206 double precision bf,oh,tsetupf,tsetupc,tsolve
207 c*
208 c* *** decode the iparm array ***
209 nlev = iparm(6)
210 nu1 = iparm(7)
211 nu2 = iparm(8)
212 mgkey = iparm(9)
213 itmax = iparm(10)
214 istop = iparm(11)
215 iinfo = iparm(12)
216 ipkey = iparm(14)
217 mgprol = iparm(17)
218 mgcoar = iparm(18)
219 mgdisc = iparm(19)
220 mgsmoo = iparm(20)
221 mgsolv = iparm(21)
222 errtol = rparm(1)
223 omegal = rparm(9)
224 omegan = rparm(10)
225 c*
226 c* *** intitialize the iteration timer ***
227 call prtstp(0,-99,0.0d0,0.0d0,0.0d0)
228 c*
229 c* *** build the multigrid data structure in iz ***
230 call buildstr (nx,ny,nz,nlev,iz)
231 c*
232 c* *** start timer ***
233 call tstart(bf,oh)
234 c*
235 c* *** build op and rhs on fine grid ***
236 ido = 0
237 call buildops (nx,ny,nz,nlev,ipkey,iinfo,ido,iz,
238 2 mgprol,mgcoar,mgsolv,mgdisc,
239 3 ipc,rpc,pc,ac,cc,fc,
240 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
241 c*
242 c* *** stop timer ***
243 call tstop(bf,oh,tsetupf)
244 print*,'% NEWDRIV2: fine problem setup time: ',tsetupf
245 c*
246 c* *** start timer ***
247 call tstart(bf,oh)
248 c*
249 c* *** build op and rhs on all coarse grids ***
250 ido = 1
251 call buildops (nx,ny,nz,nlev,ipkey,iinfo,ido,iz,
252 2 mgprol,mgcoar,mgsolv,mgdisc,
253 3 ipc,rpc,pc,ac,cc,fc,
254 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
255 c*
256 c* *** stop timer ***
257 call tstop(bf,oh,tsetupc)
258 print*,'% NEWDRIV2: coarse problem setup time: ',tsetupc
259 c*
260 c* ******************************************************************
261 c* *** this overwrites the rhs array provided by pde specification
262 c* ****** compute an algebraically produced rhs for the given tcf ***
263 mode = 1
264 if ((istop .eq. 4) .or. (istop .eq. 5)) then
265 call buildALG (nx,ny,nz,mode,nlev,iz,
266 2 ipc,rpc,ac,cc,ccf,tcf,fc,fcf)
267 endif
268 c* ******************************************************************
269 c*
270 c* *** determine machine epsilon ***
271 epsiln = epsmac(0)
272 c*
273 c* *** impose zero dirichlet boundary conditions (now in source fcn) ***
274 call fbound00(nx,ny,nz,u)
275 c*
276 c* *** MATLAB ***
277 print*,' new = [ '
278 c*
279 c* *** start timer ***
280 call tstart(bf,oh)
281 c*
282 c* *** call specified multigrid method ***
283 nlev_real = nlev
284 iok = 1
285 ilev = 1
286 if (mgkey .eq. 0) then
287 call newton(nx,ny,nz,u,iz,ccf,fcf,w1,w2,
288 2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv,
289 3 iok,iinfo,epsiln,errtol,omegan,nu1,nu2,mgsmoo,
290 4 a1cf,a2cf,a3cf,
291 5 ipc,rpc,pc,ac,cc,fc,tcf)
292 else if (mgkey .eq. 1) then
293 call fnewton(nx,ny,nz,u,iz,ccf,fcf,w1,w2,
294 2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv,
295 3 iok,iinfo,epsiln,errtol,omegan,nu1,nu2,mgsmoo,
296 4 a1cf,a2cf,a3cf,
297 5 ipc,rpc,pc,ac,cc,fc,tcf)
298 else
299 print*,'% NEWDRIV2: bad mgkey given '
300 endif
301 c*
302 c* *** stop timer ***
303 call tstop(bf,oh,tsolve)
304 print*,'% NEWDRIV2: solve time: ',tsolve
305 c*
306 c* *** MATLAB ***
307 write(*,100) 'new_sf',tsetupf,'new_sc',tsetupc,
308 2 'new_st',(tsetupf+tsetupc),'new_so',tsolve
309 100 format(' ];',4(' ',a7,'=',1pe9.3,';'))
310 c*
311 c* *** restore boundary conditions ***
312 ibound = 1
313 call fbound(ibound,nx,ny,nz,u,gxcf,gycf,gzcf)
314 c*
315 c* *** return and end ***
316 return
317 end