Debian Codegraph @

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

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file ngsdrvd.f
3 c* @author Michael Holst
4 c* @brief Driver for the nonlinear Gauss-Seidel iteration.
5 c* @version $Id: ngsdrvd.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 ngsrbdriv(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 linear/nonlinear red/black gauss-seidel iteration.
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 iretot,iintot
79 c*
80 c* *** misc variables ***
81 integer nrwk,niwk,nx,ny,nz,nlev,ierror,n
82 integer k_iz,k_w0
83 integer k_ipc,k_rpc,k_ac,k_cc,k_fc
84 integer n_iz,n_ipc,n_rpc
85 c*
86 c* *** decode some parameters ***
87 nrwk = iparm(1)
88 niwk = iparm(2)
89 nx = iparm(3)
90 ny = iparm(4)
91 nz = iparm(5)
92 nlev = iparm(6)
93 n = nx * ny * nz
94 n_iz = 10*(nlev+1)
95 n_ipc = 100*(nlev+1)
96 n_rpc = 100*(nlev+1)
97 c*
98 c* *** compute required work array sizes ***
99 iintot = n_iz + n_ipc
100 iretot = n_rpc + (3*n) + (4*n)
101 c*
102 c* *** some more checks on input ***
103 if ((nrwk.lt.iretot) .or. (niwk.lt.iintot)) then
104 print*,'% NGSRBDRIV: real work space must be: ',iretot
105 print*,'% NGSRBDRIV: integer work space must be: ',iintot
106 ierror = -3
107 iparm(51) = ierror
108 return
109 endif
110 c*
111 c* *** iwork offsets ***
112 k_iz = 1
113 k_ipc = k_iz + n_iz
114 c*
115 c* *** rwork offsets ***
116 k_rpc = 1
117 k_cc = k_rpc + n_rpc
118 k_fc = k_cc + n
119 k_w0 = k_fc + n
120 k_ac = k_w0 + n
121 c* ***k_ac_after = k_ac + 4*n
122 c*
123 c* *** call the multigrid driver ***
124 call ngsrbdriv2(iparm,rparm,nx,ny,nz,u,iwork(k_iz),
125 2 rwork(k_w0),
126 3 iwork(k_ipc),rwork(k_rpc),
127 4 rwork(k_ac),rwork(k_cc),rwork(k_fc),
128 5 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
129 c*
130 c* *** return and end ***
131 return
132 end
133 subroutine ngsrbdriv2(iparm,rparm,nx,ny,nz,u,iz,
134 2 w0,
135 3 ipc,rpc,ac,cc,fc,
136 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
137 c* *********************************************************************
138 c* purpose:
139 c*
140 c* driver for a linear/nonlinear red/black gauss-seidel iteration.
141 c*
142 c* author: michael holst
143 c* *********************************************************************
144 implicit none
145 c*
146 c* *** input parameters ***
147 integer iparm(*),ipc(*),iz(*)
148 double precision rparm(*),rpc(*)
149 double precision u(*),w0(*),ac(*),cc(*),fc(*)
150 double precision xf(*),yf(*),zf(*),gxcf(*),gycf(*),gzcf(*)
151 double precision a1cf(*),a2cf(*),a3cf(*),ccf(*),fcf(*),tcf(*)
152 c*
153 c* *** misc variables ***
154 integer mgkey,nlev,itmax,iok,iinfo,istop,ipkey,nu1,nu2
155 integer nx,ny,nz,ilev,ido,iters,ierror,ibound,mode
156 integer mgprol,mgcoar,mgsolv,mgdisc
157 double precision epsiln,epsmac,errtol,omegal,omegan
158 double precision pc_dumm
159 double precision bf,oh,tsetupf,tsetupc,tsolve
160 c*
161 c* *** decode the iparm array ***
162 nlev = iparm(6)
163 nu1 = iparm(7)
164 nu2 = iparm(8)
165 mgkey = iparm(9)
166 itmax = iparm(10)
167 istop = iparm(11)
168 iinfo = iparm(12)
169 ipkey = iparm(14)
170 mode = iparm(16)
171 mgprol = iparm(17)
172 mgcoar = iparm(18)
173 mgdisc = iparm(19)
174 mgsolv = iparm(21)
175 errtol = rparm(1)
176 omegal = rparm(9)
177 omegan = rparm(10)
178 c*
179 c* *** intitialize the iteration timer ***
180 call prtstp(0,-99,0.0d0,0.0d0,0.0d0)
181 c*
182 c* *** build the multigrid data structure in iz ***
183 call buildstr (nx,ny,nz,nlev,iz)
184 c*
185 c* *** start timer ***
186 call tstart(bf,oh)
187 c*
188 c* *** build op and rhs on fine grid ***
189 ido = 0
190 call buildops (nx,ny,nz,nlev,ipkey,iinfo,ido,iz,
191 2 mgprol,mgcoar,mgsolv,mgdisc,
192 3 ipc,rpc,pc_dumm,ac,cc,fc,
193 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
194 c*
195 c* *** stop timer ***
196 call tstop(bf,oh,tsetupf)
197 print*,'% NGSRBDRIV2: fine problem setup time: ',tsetupf
198 tsetupc = 0.0d0
199 c*
200 c* ******************************************************************
201 c* *** this overwrites the rhs array provided by pde specification
202 c* ****** compute an algebraically produced rhs for the given tcf ***
203 if ((istop .eq. 4) .or. (istop .eq. 5)) then
204 if ((mode .eq. 1) .or. (mode .eq. 2)) then
205 call nmatvec(nx,ny,nz,ipc,rpc,ac,cc,tcf,fc,w0)
206 else
207 call matvec(nx,ny,nz,ipc,rpc,ac,cc,tcf,fc)
208 endif
209 endif
210 c* ******************************************************************
211 c*
212 c* *** determine machine epsilon ***
213 epsiln = epsmac(0)
214 c*
215 c* *** impose zero dirichlet boundary conditions (now in source fcn) ***
216 call fbound00(nx,ny,nz,u)
217 c*
218 c* *** MATLAB ***
219 print*,' gsrb = [ '
220 c*
221 c* *** start timer ***
222 call tstart(bf,oh)
223 c*
224 c* *** call specified multigrid method ***
225 if ((mode .eq. 0) .or. (mode .eq. 2)) then
226 print*,'% NGSRBDRIV2: linear mode...'
227 iok = 1
228 ilev = 1
229 call gsrbgo(nx,ny,nz,u,w0,a1cf,a2cf,
230 2 istop,itmax,iters,ierror,
231 3 iok,iinfo,epsiln,errtol,omegal,
232 4 ipc,rpc,ac,cc,fc,tcf)
233 endif
234 if ((mode .eq. 1) .or. (mode .eq. 2)) then
235 print*,'% NGSRBDRIV2: nonlinear mode...'
236 iok = 1
237 ilev = 1
238 call ngsrbgo(nx,ny,nz,u,w0,a1cf,a2cf,
239 2 istop,itmax,iters,ierror,
240 3 iok,iinfo,epsiln,errtol,omegan,
241 4 ipc,rpc,ac,cc,fc,tcf)
242 endif
243 c*
244 c* *** stop timer ***
245 call tstop(bf,oh,tsolve)
246 print*,'% NGSRBDRIV2: solve time: ',tsolve
247 c*
248 c* *** MATLAB ***
249 write(*,100) 'gsrb_sf',tsetupf,'gsrb_sc',tsetupc,
250 2 'gsrb_st',(tsetupf+tsetupc),'gsrb_so',tsolve
251 100 format(' ];',4(' ',a7,'=',1pe9.3,';'))
252 c*
253 c* *** restore boundary conditions ***
254 ibound = 1
255 call fbound(ibound,nx,ny,nz,u,gxcf,gycf,gzcf)
256 c*
257 c* *** return and end ***
258 return
259 end
260 subroutine ngsrbgo(nx,ny,nz,x,r,w1,w2,
261 2 istop,itmax,iters,ierror,
262 3 iok,iinfo,epsiln,errtol,omega,
263 4 ipc,rpc,ac,cc,fc,tru)
264 c* *********************************************************************
265 c* purpose:
266 c*
267 c* a nonlinear red/black gauss-seidel iteration.
268 c*
269 c* author: michael holst
270 c* *********************************************************************
271 implicit none
272 c*
273 c* *** other declarations ***
274 integer ipc(*),iok,iinfo
275 integer itmax,iters,ierror
276 integer iresid,iadjoint,istop,itmax_s,iters_s
277 integer nx,ny,nz
278 double precision omega,errtol,epsiln,errtol_s,omega_s
279 double precision rsden,rsnrm,orsnrm,xnrm1,xnrm2,xdot
280 double precision x(*),r(*),w1(*),w2(*)
281 double precision rpc(*),ac(*),cc(*),fc(*),tru(*)
282 c*
283 c* *** do some i/o if requested ***
284 if (iinfo.ne.0) then
285 write(6,100)'% NGSRBGO: starting:',nx,ny,nz
286 100 format(a,(2x,' [',i3,',',i3,',',i3,'] '))
287 endif
288 c*
289 c* *** initial wall clock ***
290 call prtini(istop)
291 call prtstp(iok,-1,0.0d0,0.0d0,0.0d0)
292 c*
293 c* **************************************************************
294 c* *** note: if (iok.ne.0) then: use a stopping test. ***
295 c* *** else: use just the itmax to stop iteration. ***
296 c* **************************************************************
297 c* *** istop=0 most efficient (whatever it is) ***
298 c* *** istop=1 relative residual ***
299 c* *** istop=2 rms difference of successive iterates ***
300 c* *** istop=3 relative true error (provided for testing) ***
301 c* **************************************************************
302 c*
303 c* *** compute denominator for stopping criterion ***
304 if (istop .eq. 0) then
305 rsden = 1.0d0
306 elseif (istop .eq. 1) then
307 c* *** compute initial residual with zero initial guess ***
308 c* *** this is analogous to the linear case where one can ***
309 c* *** simply take norm of rhs for a zero initial guess ***
310 call azeros(nx,ny,nz,w1)
311 call nmresid(nx,ny,nz,ipc,rpc,ac,cc,fc,w1,r,w2)
312 rsden = xnrm1(nx,ny,nz,r)
313 elseif (istop .eq. 2) then
314 rsden = dsqrt(dble(nx*ny*nz))
315 elseif (istop .eq. 3) then
316 rsden = xnrm2(nx,ny,nz,tru)
317 elseif (istop .eq. 4) then
318 rsden = xnrm2(nx,ny,nz,tru)
319 elseif (istop .eq. 5) then
320 call nmatvec(nx,ny,nz,ipc,rpc,ac,cc,tru,w1,w2)
321 rsden = dsqrt(xdot(nx,ny,nz,tru,w1))
322 else
323 print*,'% NGSRBGO: bad istop value... '
324 endif
325 if (rsden.eq.0.0d0) then
326 rsden = 1.0d0
327 print*,'% NGSRBGO: rhs is zero '
328 endif
329 rsnrm = rsden
330 orsnrm = rsnrm
331 call prtstp (iok,0,rsnrm,rsden,orsnrm)
332 c*
333 c* *** setup for the looping ***
334 iters = 0
335 30 continue
336 iters = iters + 10
337 c*
338 c* *** save iterate if stop test will use it on next iter ***
339 if (istop .eq. 2) call xcopy(nx,ny,nz,x,tru)
340 c*
341 c* *** do 10 iterations ***
342 iresid = 1
343 iadjoint = 0
344 errtol_s = 0.0d0
345 itmax_s = 10
346 omega_s = omega
347 call ngsrb(nx,ny,nz,ipc,rpc,ac,cc,fc,x,w1,w2,r,
348 2 itmax_s,iters_s,errtol_s,omega_s,iresid,iadjoint)
349 c*
350 c* *** compute/check the current stopping test ***
351 orsnrm = rsnrm
352 if (istop .eq. 0) then
353 rsnrm = xnrm1(nx,ny,nz,r)
354 elseif (istop .eq. 1) then
355 rsnrm = xnrm1(nx,ny,nz,r)
356 elseif (istop .eq. 2) then
357 call xcopy(nx,ny,nz,tru,w1)
358 call xaxpy(nx,ny,nz,(-1.0d0),x,w1)
359 rsnrm = xnrm1(nx,ny,nz,w1)
360 elseif (istop .eq. 3) then
361 call xcopy(nx,ny,nz,tru,w1)
362 call xaxpy(nx,ny,nz,(-1.0d0),x,w1)
363 rsnrm = xnrm2(nx,ny,nz,w1)
364 elseif (istop .eq. 4) then
365 call xcopy(nx,ny,nz,tru,w1)
366 call xaxpy(nx,ny,nz,(-1.0d0),x,w1)
367 rsnrm = xnrm2(nx,ny,nz,w1)
368 elseif (istop .eq. 5) then
369 call xcopy(nx,ny,nz,tru,w1)
370 call xaxpy(nx,ny,nz,(-1.0d0),x,w1)
371 call nmatvec(nx,ny,nz,ipc,rpc,ac,cc,w1,w2,r)
372 rsnrm = dsqrt(xdot(nx,ny,nz,w1,w2))
373 else
374 print*,'% NGSRBGO: bad istop value... '
375 endif
376 call prtstp (iok,iters,rsnrm,rsden,orsnrm)
377 if ((rsnrm/rsden) .le. errtol) goto 99
378 if (iters .ge. itmax) goto 99
379 goto 30
380 c*
381 c* *** return and end ***
382 99 continue
383 return
384 end
385 subroutine gsrbgo(nx,ny,nz,x,r,w1,w2,
386 2 istop,itmax,iters,ierror,
387 3 iok,iinfo,epsiln,errtol,omega,
388 4 ipc,rpc,ac,cc,fc,tru)
389 c* *********************************************************************
390 c* purpose:
391 c*
392 c* a linear red/black gauss-seidel iteration.
393 c*
394 c* author: michael holst
395 c* *********************************************************************
396 implicit none
397 c*
398 c* *** other declarations ***
399 integer ipc(*),iok,iinfo
400 integer itmax,iters,ierror
401 integer iresid,iadjoint,istop,itmax_s,iters_s
402 integer nx,ny,nz
403 double precision omega,errtol,epsiln,errtol_s,omega_s
404 double precision rsden,rsnrm,orsnrm,xnrm1,xnrm2,xdot
405 double precision x(*),r(*),w1(*),w2(*)
406 double precision rpc(*),ac(*),cc(*),fc(*),tru(*)
407 c*
408 c* *** do some i/o if requested ***
409 if (iinfo.ne.0) then
410 write(6,100)'% GSRBGO: starting: ',nx,ny,nz
411 100 format(a,(2x,' [',i3,',',i3,',',i3,'] '))
412 endif
413 c*
414 c* *** initial wall clock ***
415 call prtini(istop)
416 call prtstp(iok,-1,0.0d0,0.0d0,0.0d0)
417 c*
418 c* **************************************************************
419 c* *** note: if (iok.ne.0) then: use a stopping test. ***
420 c* *** else: use just the itmax to stop iteration. ***
421 c* **************************************************************
422 c* *** istop=0 most efficient (whatever it is) ***
423 c* *** istop=1 relative residual ***
424 c* *** istop=2 rms difference of successive iterates ***
425 c* *** istop=3 relative true error (provided for testing) ***
426 c* **************************************************************
427 c*
428 c* *** compute denominator for stopping criterion ***
429 if (istop .eq. 0) then
430 rsden = 1.0d0
431 elseif (istop .eq. 1) then
432 rsden = xnrm1(nx,ny,nz,fc)
433 elseif (istop .eq. 2) then
434 rsden = dsqrt(dble(nx*ny*nz))
435 elseif (istop .eq. 3) then
436 rsden = xnrm2(nx,ny,nz,tru)
437 elseif (istop .eq. 4) then
438 rsden = xnrm2(nx,ny,nz,tru)
439 elseif (istop .eq. 5) then
440 call matvec(nx,ny,nz,ipc,rpc,ac,cc,tru,w1)
441 rsden = dsqrt(xdot(nx,ny,nz,tru,w1))
442 else
443 print*,'% GSRBGO: bad istop value... '
444 endif
445 if (rsden.eq.0.0d0) then
446 rsden = 1.0d0
447 print*,'% GSRBGO: rhs is zero '
448 endif
449 rsnrm = rsden
450 orsnrm = rsnrm
451 call prtstp (iok,0,rsnrm,rsden,orsnrm)
452 c*
453 c* *** setup for the looping ***
454 iters = 0
455 30 continue
456 iters = iters + 10
457 c*
458 c* *** save iterate if stop test will use it on next iter ***
459 if (istop .eq. 2) call xcopy(nx,ny,nz,x,tru)
460 c*
461 c* *** do 10 iterations ***
462 iresid = 1
463 iadjoint = 0
464 errtol_s = 0.0d0
465 itmax_s = 10
466 omega_s = omega
467 call gsrb(nx,ny,nz,ipc,rpc,ac,cc,fc,x,w1,w2,r,
468 2 itmax_s,iters_s,errtol_s,omega_s,iresid,iadjoint)
469 c*
470 c* *** compute/check the current stopping test ***
471 orsnrm = rsnrm
472 if (istop .eq. 0) then
473 rsnrm = xnrm1(nx,ny,nz,r)
474 elseif (istop .eq. 1) then
475 rsnrm = xnrm1(nx,ny,nz,r)
476 elseif (istop .eq. 2) then
477 call xcopy(nx,ny,nz,tru,w1)
478 call xaxpy(nx,ny,nz,(-1.0d0),x,w1)
479 rsnrm = xnrm1(nx,ny,nz,w1)
480 elseif (istop .eq. 3) then
481 call xcopy(nx,ny,nz,tru,w1)
482 call xaxpy(nx,ny,nz,(-1.0d0),x,w1)
483 rsnrm = xnrm2(nx,ny,nz,w1)
484 elseif (istop .eq. 4) then
485 call xcopy(nx,ny,nz,tru,w1)
486 call xaxpy(nx,ny,nz,(-1.0d0),x,w1)
487 rsnrm = xnrm2(nx,ny,nz,w1)
488 elseif (istop .eq. 5) then
489 call xcopy(nx,ny,nz,tru,w1)
490 call xaxpy(nx,ny,nz,(-1.0d0),x,w1)
491 call matvec(nx,ny,nz,ipc,rpc,ac,cc,w1,w2)
492 rsnrm = dsqrt(xdot(nx,ny,nz,w1,w2))
493 else
494 print*,'% GSRBGO: bad istop value... '
495 endif
496 call prtstp (iok,iters,rsnrm,rsden,orsnrm)
497 if ((rsnrm/rsden) .le. errtol) goto 99
498 if (iters .ge. itmax) goto 99
499 goto 30
500 c*
501 c* *** return and end ***
502 99 continue
503 return
504 end