Debian Codegraph @

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

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file mgdrvd.f
3 c* @author Michael Holst
4 c* @brief Driver for the multigrid routines.
5 c* @version $Id: mgdrvd.f,v 1.2 2010/08/12 05:45:33 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 mgdriv(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 solver 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
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*,'% MGDRIV: 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*,'% MGDRIV: 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* *** some more checks on input ***
118 if ((nrwk.lt.iretot) .or. (niwk.lt.iintot)) then
119 print*,'% MGDRIV: real work space must be: ',iretot
120 print*,'% MGDRIV: integer work space must be: ',iintot
121 ierror = -3
122 iparm(51) = ierror
123 return
124 endif
125 c*
126 c* *** split up the integer work array ***
127 k_iz = 1
128 k_ipc = k_iz + n_iz
129 c*
130 c* *** split up the real work array ***
131 k_rpc = 1
132 k_cc = k_rpc + n_rpc
133 k_fc = k_cc + narr
134 k_pc = k_fc + narr
135 k_ac = k_pc + 27*narrc
136 c* ***k_ac_after = 4*nf + 4*narrc
137 c* ***k_ac_after = 4*nf + 14*narrc
138 c* ***k_ac_after = 14*nf + 14*narrc
139 c*
140 c* *** call the multigrid driver ***
141 call mgdriv2(iparm,rparm,nx,ny,nz,u,iwork(k_iz),
142 2 iwork(k_ipc),rwork(k_rpc),
143 3 rwork(k_pc),rwork(k_ac),rwork(k_cc),rwork(k_fc),
144 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
145 c*
146 c* *** return and end ***
147 return
148 end
149 subroutine mgdriv2(iparm,rparm,nx,ny,nz,u,iz,
150 2 ipc,rpc,pc,ac,cc,fc,
151 3 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
152 c* *********************************************************************
153 c* purpose:
154 c*
155 c* this routine uses a multigrid method to solve the following
156 c* three-dimensional, 2nd order elliptic partial differential
157 c* equation:
158 c*
159 c* lu = f, u in omega
160 c* u = g, u on boundary of omega
161 c* where
162 c*
163 c* omega = [xmin,xmax]x[ymin,ymax]x[zmin,zmax]
164 c*
165 c* the multigrid code requires the operator in the form:
166 c*
167 c* - \nabla \cdot (a \nabla u) + c(u) = f
168 c*
169 c* with
170 c*
171 c* a(x,y,z),f(x,y,z), scalar functions (possibly discontinuous)
172 c* on omega. (discontinuities must be along fine grid lines).
173 c* boundary function g(x,y,z) is smooth on boundary of omega.
174 c*
175 c* the function c(u) is a possibly nonlinear function of the
176 c* unknown u, and varies (possibly discontinuously) with the
177 c* spatial position also.
178 c*
179 c* user inputs:
180 c*
181 c* the user must provide the coefficients of the differential
182 c* operator, some initial parameter settings in an integer and a
183 c* real parameter array, and various work arrays.
184 c*
185 c* author: michael holst
186 c* *********************************************************************
187 implicit none
188 c*
189 c* *** input parameters ***
190 integer iparm(*),ipc(*),iz(50,*)
191 double precision rparm(*),rpc(*),pc(*),ac(*),cc(*),fc(*)
192 double precision u(*)
193 double precision xf(*),yf(*),zf(*),gxcf(*),gycf(*),gzcf(*)
194 double precision a1cf(*),a2cf(*),a3cf(*),ccf(*),fcf(*),tcf(*)
195 c*
196 c* *** misc variables ***
197 integer mgkey,nlev,itmax,iok,iinfo,istop,ipkey,nu1,nu2
198 integer nx,ny,nz,ilev,ido,iters,ierror,nlev_real,ibound
199 integer mgprol,mgcoar,mgsolv,mgdisc,mgsmoo,iperf,mode
200 double precision epsiln,epsmac,errtol,omegal,omegan
201 double precision bf,oh,tsetupf,tsetupc,tsolve
202 c*
203 c* *** more misc variables ***
204 integer itmax_p,iters_p,iok_p,iinfo_p
205 double precision errtol_p,rho_p
206 double precision rho_min,rho_max,rho_min_mod,rho_max_mod
207 integer nxf,nyf,nzf,nxc,nyc,nzc,level,nlevd
208 c*
209 c* *** decode the iparm array ***
210 nlev = iparm(6)
211 nu1 = iparm(7)
212 nu2 = iparm(8)
213 mgkey = iparm(9)
214 itmax = iparm(10)
215 istop = iparm(11)
216 iinfo = iparm(12)
217 ipkey = iparm(14)
218 mode = iparm(16)
219 mgprol = iparm(17)
220 mgcoar = iparm(18)
221 mgdisc = iparm(19)
222 mgsmoo = iparm(20)
223 mgsolv = iparm(21)
224 iperf = iparm(22)
225 errtol = rparm(1)
226 omegal = rparm(9)
227 omegan = rparm(10)
228 c*
229 c* *** intitialize the iteration timer ***
230 call prtstp(0,-99,0.0d0,0.0d0,0.0d0)
231 c*
232 c* *** build the multigrid data structure in iz ***
233 call buildstr (nx,ny,nz,nlev,iz)
234 c*
235 c* *** start timer ***
236 call tstart(bf,oh)
237 c*
238 c* *** build op and rhs on fine grid ***
239 ido = 0
240 call buildops (nx,ny,nz,nlev,ipkey,iinfo,ido,iz,
241 2 mgprol,mgcoar,mgsolv,mgdisc,
242 3 ipc,rpc,pc,ac,cc,fc,
243 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
244 c*
245 c* *** stop timer ***
246 call tstop(bf,oh,tsetupf)
247 print*,'% MGDRIV2: fine problem setup time: ',tsetupf
248 c*
249 c* *** start timer ***
250 call tstart(bf,oh)
251 c*
252 c* *** build op and rhs on all coarse grids ***
253 ido = 1
254 call buildops (nx,ny,nz,nlev,ipkey,iinfo,ido,iz,
255 2 mgprol,mgcoar,mgsolv,mgdisc,
256 3 ipc,rpc,pc,ac,cc,fc,
257 4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf)
258 c*
259 c* *** stop timer ***
260 call tstop(bf,oh,tsetupc)
261 print*,'% MGDRIV2: coarse problem setup time: ',tsetupc
262 c*
263 c* *** determine machine epsilon ***
264 epsiln = epsmac(0)
265 c*
266 c* ******************************************************************
267 c* *** analysis ***
268 c* *** note: we destroy the rhs function "fc" here in "mpower" ***
269 c* ******************************************************************
270 c*
271 c* *** errtol and itmax ***
272 itmax_p = 1000
273 iok_p = 0
274 nlev_real = nlev
275 nlevd = nlev_real
276 c*
277 c* *** finest level initialization ***
278 nxf = nx
279 nyf = ny
280 nzf = nz
281 c*
282 c* *** go down grids: compute max/min eigenvalues of all operators ***
283 do 40 level = 1, nlev_real
284 nlevd = nlev_real - level + 1
285 c*
286 c* *** move down the grids ***
287 if (level .ne. 1) then
288 c*
289 c* *** find new grid size ***
290 call mkcors(1,nxf,nyf,nzf,nxc,nyc,nzc)
291 c*
292 c* *** new grid size ***
293 nxf = nxc
294 nyf = nyc
295 nzf = nzc
296 endif
297 print*,'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
298 2 ,'%%%%%%%%%%'
299 write(6,200)'% MGDRIV2: ANALYSIS==>',nxf,nyf,nzf
300 200 format(a,' [',i3,',',i3,',',i3,'] ')
301 c*
302 c* *** largest eigenvalue of the system matrix A ***
303 if ((iperf .eq. 1) .or. (iperf .eq. 3)) then
304 print*,'% MGDRIV2: power calculating rho(A)...'
305 iters_p = 0
306 iinfo_p = iinfo
307 errtol_p = 1.0e-4
308 call power(nxf,nyf,nzf,iz,level,
309 2 ipc,rpc,ac,cc,
310 3 a1cf,a2cf,a3cf,ccf,
311 4 rho_max,rho_max_mod,errtol_p,itmax_p,iters_p,iinfo_p)
312 print*,'% MGDRIV2: power iters = ',iters_p
313 print*,'% MGDRIV2: power eigmax = ',rho_max
314 print*,'% MGDRIV2: power (MODEL) = ',rho_max_mod
315 c*
316 c* *** smallest eigenvalue of the system matrix A ***
317 print*,'% MGDRIV2: ipower calculating lambda_min(A)...'
318 iters_p = 0
319 iinfo_p = iinfo
320 errtol_p = 1.0e-4
321 call azeros(nxf,nyf,nzf,u)
322 call ipower(nxf,nyf,nzf,u,iz,
323 2 a1cf,a2cf,a3cf,ccf,fcf,
324 3 rho_min,rho_min_mod,errtol_p,itmax_p,iters_p,
325 4 nlevd,level,nlev_real,mgsolv,
326 5 iok_p,iinfo_p,epsiln,errtol,omegal,nu1,nu2,mgsmoo,
327 6 ipc,rpc,pc,ac,cc,tcf)
328 print*,'% MGDRIV2: ipower iters = ',iters_p
329 print*,'% MGDRIV2: ipower eigmin = ',rho_min
330 print*,'% MGDRIV2: ipower (MODEL) = ',rho_min_mod
331 c*
332 c* *** condition number estimate ***
333 print*,'% MGDRIV2: condition number = ',rho_max/rho_min
334 print*,'% MGDRIV2: condition (MODEL) = ',
335 2 rho_max_mod/rho_min_mod
336 endif
337 c*
338 c* *** spectral radius of the multigrid operator M ***
339 c* *** NOTE: due to lack of vectors, we destroy "fc" in mpower... ***
340 if ((iperf .eq. 2) .or. (iperf .eq. 3)) then
341 print*,'% MGDRIV2: mpower calculating rho(M)...'
342 iters_p = 0
343 iinfo_p = iinfo
344 errtol_p = epsiln
345 call azeros(nxf,nyf,nzf,u(iz(1,level)))
346 call mpower(nxf,nyf,nzf,u,iz,
347 2 a1cf,a2cf,a3cf,ccf,fcf,
348 3 rho_p,errtol_p,itmax_p,iters_p,
349 4 nlevd,level,nlev_real,mgsolv,
350 5 iok_p,iinfo_p,epsiln,errtol,omegal,nu1,nu2,mgsmoo,
351 6 ipc,rpc,pc,ac,cc,fc,tcf)
352 print*,'% MGDRIV2: mpower iters = ',iters_p
353 print*,'% MGDRIV2: mpower rho(M) = ',rho_p
354 endif
355 c*
356 c* *** reinitialize the solution function ***
357 call azeros(nxf,nyf,nzf,u(iz(1,level)))
358 c*
359 c* *** next grid ***
360 40 continue
361 print*,'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
362 c*
363 c* *** reinitialize the solution function ***
364 call azeros(nx,ny,nz,u)
365 c*
366 c* ******************************************************************
367 c* *** this overwrites the rhs array provided by pde specification
368 c* ****** compute an algebraically produced rhs for the given tcf ***
369 if ((istop .eq. 4) .or. (istop .eq. 5) .or. (iperf .ne. 0)) then
370 print*,'% MGDRIV2: generating algebraic RHS from your soln...'
371 call buildALG (nx,ny,nz,mode,nlev,iz,
372 2 ipc,rpc,ac,cc,ccf,tcf,fc,fcf)
373 endif
374 c* ******************************************************************
375 c*
376 c* *** impose zero dirichlet boundary conditions (now in source fcn) ***
377 call fbound00(nx,ny,nz,u)
378 c*
379 c* *** MATLAB ***
380 print*,' mg = [ '
381 c*
382 c* *** start timer ***
383 call tstart(bf,oh)
384 c*
385 c* *** call specified multigrid method ***
386 if ((mode .eq. 0) .or. (mode .eq. 2)) then
387 print*,'% MGDRIV2: linear mode...'
388 nlev_real = nlev
389 iok = 1
390 ilev = 1
391 if (mgkey .eq. 0) then
392 call mvcs(nx,ny,nz,u,iz,a1cf,a2cf,a3cf,ccf,
393 2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv,
394 3 iok,iinfo,epsiln,errtol,omegal,nu1,nu2,mgsmoo,
395 4 ipc,rpc,pc,ac,cc,fc,tcf)
396 elseif (mgkey .eq. 1) then
397 call fmvcs(nx,ny,nz,u,iz,a1cf,a2cf,a3cf,ccf,
398 2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv,
399 3 iok,iinfo,epsiln,errtol,omegal,nu1,nu2,mgsmoo,
400 4 ipc,rpc,pc,ac,cc,fc,tcf)
401 else
402 print*,'% MGDRIV2: bad mgkey given... '
403 endif
404 endif
405 if ((mode .eq. 1) .or. (mode .eq. 2)) then
406 print*,'% MGDRIV2: nonlinear mode...'
407 nlev_real = nlev
408 iok = 1
409 ilev = 1
410 if (mgkey .eq. 0) then
411 call mvfas(nx,ny,nz,u,iz,a1cf,a2cf,a3cf,ccf,fcf,
412 2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv,
413 3 iok,iinfo,epsiln,errtol,omegan,nu1,nu2,mgsmoo,
414 4 ipc,rpc,pc,ac,cc,fc,tcf)
415 else if (mgkey .eq. 1) then
416 call fmvfas(nx,ny,nz,u,iz,a1cf,a2cf,a3cf,ccf,fcf,
417 2 istop,itmax,iters,ierror,nlev,ilev,nlev_real,mgsolv,
418 3 iok,iinfo,epsiln,errtol,omegan,nu1,nu2,mgsmoo,
419 4 ipc,rpc,pc,ac,cc,fc,tcf)
420 else
421 print*,'% MGDRIV2: bad mgkey given... '
422 endif
423 endif
424 c*
425 c* *** stop timer ***
426 call tstop(bf,oh,tsolve)
427 print*,'% MGDRIV2: solve time: ',tsolve
428 c*
429 c* *** MATLAB ***
430 write(*,100) 'mg_sf',tsetupf,'mg_sc',tsetupc,
431 2 'mg_st',(tsetupf+tsetupc),'mg_so',tsolve
432 100 format(' ];',4(' ',a7,'=',1pe9.3,';'))
433 c*
434 c* *** restore boundary conditions ***
435 ibound = 1
436 call fbound(ibound,nx,ny,nz,u,gxcf,gycf,gzcf)
437 c*
438 c* *** return and end ***
439 return
440 end
441 subroutine mgsz(mgcoar,mgdisc,mgsolv,nx,ny,nz,nlev,nxc,nyc,nzc,
442 2 nf,nc,narr,narrc,n_rpc,n_iz,n_ipc,iretot,iintot)
443 c* *********************************************************************
444 c* purpose:
445 c*
446 c* this routine computes the required sizes of the real and integer
447 c* work arrays for the multigrid code. these two sizes are a
448 c* (complicated) function of input parameters.
449 c*
450 c* the work arrays must have been declared in the calling program as:
451 c*
452 c* double precision rwork(iretot)
453 c* integer iwork(iintot)
454 c*
455 c* where:
456 c*
457 c* iretot = function_of(mgcoar,mgdisc,mgsolv,nx,ny,nz,nlev)
458 c* iintot = function_of(mgcoar,mgdisc,mgsolv,nx,ny,nz,nlev)
459 c*
460 c* mgcoar = coarsening technique:
461 c* 0=standard discretization
462 c* 1=averaged coefficient + standard discretization
463 c* 2=algebraic galerkin coarsening
464 c*
465 c* mgdisc = discretization technique:
466 c* 0=box method
467 c* 1=fem method
468 c*
469 c* mgsolv = coarse grid solver:
470 c* 0=conjugate gradients
471 c* 1=symmetric banded linpack solver
472 c*
473 c* nx,ny,nz = grid dimensions in each direction,
474 c* including boundary points
475 c*
476 c* nlev = the number of multigrid levels desired for the
477 c* method.
478 c*
479 c* other parameters:
480 c*
481 c* nf = number of unknowns on the finest mesh
482 c* = nx * ny * nz
483 c*
484 c* nc = number of unknowns on the coarsest mesh
485 c*
486 c* narr = storage for one vector on all the meshes
487 c*
488 c* narrc = storage for one vector on all the meshes but the finest
489 c*
490 c* the work arrays rwork and iwork will be chopped into smaller
491 c* pieces according to:
492 c*
493 c* double precision ac(STORE) (system operators on all levels)
494 c* double precision pc(27*narrc) (prol. opers for coarse levels)
495 c* double precision cc(narr),fc(narr) (helmholtz term, rhs -- all levels)
496 c* double precision rpc(100*(nlev+1)) (real info for all levels)
497 c* integer ipc(100*(nlev+1)) (integer info for all levels)
498 c* integer iz(50,nlev+1), (pointers into ac,pc,cc,fc,etc.)
499 c*
500 c* where STORE depends on the discretization, coarsening, and coarse
501 c* grid solver:
502 c*
503 c* STORE = 4*nf + 4*narrc + NBAND*nc (mgdisc=box, mgcoar=stan/harm)
504 c* or = 4*nf + 14*narrc + NBAND*nc (mgdisc=box, mgcoar=gal)
505 c* or = 14*nf + 14*narrc + NBAND*nc (mgdisc=fem, mgcoar=stan/harm/gal)
506 c*
507 c* NBAND = 0 (mgsolv=iterative)
508 c* or = 1+(nxc-2)*(nyc-2) (mgsolv=7-pt banded linpack)
509 c* or = 1+(nxc-2)*(nyc-2)+(nxc-2)+1 (mgsolv=27-pt banded linpack)
510 c*
511 c* author: michael holst
512 c* *********************************************************************
513 implicit none
514 c*
515 c* *** input parameters ***
516 integer mgcoar,mgdisc,mgsolv,nx,ny,nz,nlev
517 c*
518 c* *** parameters: num of different types of arrays in mg code ***
519 integer num_nf,num_narr,num_narrc
520 parameter (num_narr = 2)
521 parameter (num_nf = 0)
522 parameter (num_narrc = 27)
523 c*
524 c* *** variables returned from mgsz ***
525 integer nxc,nyc,nzc,nf,nc,narr,narrc,n_rpc
526 integer n_iz,n_ipc,iretot,iintot
527 c*
528 c* *** misc variables ***
529 integer nc_band,num_band,n_band,nxf,nyf,nzf,level
530 integer num_nf_oper,num_narrc_oper
531 c*
532 c* *** go down grids: compute max/min eigenvalues of all operators ***
533 nf = nx * ny * nz
534 narr = nf
535 nxf = nx
536 nyf = ny
537 nzf = nz
538 nxc = nx
539 nyc = ny
540 nzc = nz
541 do 10 level = 2, nlev
542 c*
543 c* *** find new grid size ***
544 call mkcors(1,nxf,nyf,nzf,nxc,nyc,nzc)
545 c*
546 c* *** new grid size ***
547 nxf = nxc
548 nyf = nyc
549 nzf = nzc
550 c*
551 c* *** add the unknowns on this level to the total ***
552 narr = narr + (nxf * nyf * nzf)
553 10 continue
554 nc = nxc * nyc * nzc
555 narrc = narr - nf
556 c*
557 c* *** box or fem on fine grid? ***
558 if (mgdisc .eq. 0) then
559 num_nf_oper = 4
560 elseif (mgdisc .eq. 1) then
561 num_nf_oper = 14
562 else
563 print*,'% MGSZ: invalid mgdisc parameter...'
564 endif
565 c*
566 c* *** galerkin or standard coarsening? ***
567 if (((mgcoar .eq. 0) .or. (mgcoar .eq. 1))
568 2 .and. (mgdisc .eq. 0)) then
569 num_narrc_oper = 4
570 elseif (mgcoar .eq. 2) then
571 num_narrc_oper = 14
572 else
573 print*,'% MGSZ: invalid mgcoar parameter...'
574 endif
575 c*
576 c* *** symmetric banded linpack storage on coarse grid ***
577 if (mgsolv .eq. 0) then
578 n_band = 0
579 elseif (mgsolv .eq. 1) then
580 if (((mgcoar .eq. 0) .or. (mgcoar .eq. 1))
581 2 .and. (mgdisc .eq. 0)) then
582 num_band = 1 + (nxc-2)*(nyc-2)
583 else
584 num_band = 1 + (nxc-2)*(nyc-2) + (nxc-2) + 1
585 endif
586 nc_band = (nxc-2)*(nyc-2)*(nzc-2)
587 n_band = nc_band * num_band
588 else
589 print*,'% MGSZ: invalid mgsolv parameter...'
590 endif
591 c*
592 c* *** info work array required storage ***
593 n_rpc = 100*(nlev+1)
594 c*
595 c* *** resulting total required real storage for method ***
596 iretot = num_narr*narr
597 2 + (num_nf + num_nf_oper)*nf
598 3 + (num_narrc + num_narrc_oper)*narrc
599 4 + n_band
600 5 + n_rpc
601 c*
602 c* *** the integer storage parameters ***
603 n_iz = 50*(nlev+1)
604 n_ipc = 100*(nlev+1)
605 c*
606 c* *** resulting total required integer storage for method ***
607 iintot = n_iz + n_ipc
608 c*
609 c* *** return and end ***
610 return
611 end
612 subroutine mgsize(mgcoar,mgdisc,mgsolv,nx,ny,nz,nlev)
613 c* *********************************************************************
614 c* purpose:
615 c*
616 c* this routine prints out the required sizes of the real and integer
617 c* work arrays for the multigrid code. these two sizes are a
618 c* (complicated) function of the four input parameters:
619 c*
620 c* nx,ny,nz ==> number of grid points in each grid direction.
621 c* nlev ==> number of multigrid levels to employ.
622 c*
623 c* author: michael holst
624 c* *********************************************************************
625 implicit none
626 c*
627 c* *** input parameters ***
628 integer mgcoar,mgdisc,mgsolv,nx,ny,nz,nlev
629 c*
630 c* *** variables returned from mgsz ***
631 integer nxc,nyc,nzc,nf,nc,narr,narrc,n_rpc
632 integer n_iz,n_ipc,iretot,iintot
633 c*
634 c* *** basic grid sizes, etc. ***
635 call mgsz(mgcoar,mgdisc,mgsolv,nx,ny,nz,nlev,nxc,nyc,nzc,
636 2 nf,nc,narr,narrc,n_rpc,n_iz,n_ipc,iretot,iintot)
637 c*
638 c* *** resulting total required for real/integer storage ***
639 print*,'% MGSIZE: number of unknowns on finest level: ',nf
640 print*,'% MGSIZE: number of unknowns on coarsest level: ',nc
641 print*,'% MGSIZE: storage for a vector on all levels: ',narr
642 print*,'% MGSIZE: storage for a vector on coarse levels: ',narrc
643 print*,'% MGSIZE: REQUIRED floating point array size: ',iretot
644 print*,'% MGSIZE: REQUIRED integer array size: ',iintot
645 c*
646 c* *** return and end ***
647 return
648 end