| 1 |
c* /////////////////////////////////////////////////////////////////////////// |
| 2 |
c* @file mainsubd.f |
| 3 |
c* @author Michael Holst |
| 4 |
c* @brief Supporting I/O and other routines for main.c and maind.f. |
| 5 |
c* @version $Id: mainsubf.f,v 1.2 2010/08/12 05:53:04 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 readit (iparm,rparm,nx,ny,nz,nlev,nrwk,niwk,key,meth) |
| 61 |
c* ********************************************************************* |
| 62 |
c* purpose: |
| 63 |
c* |
| 64 |
c* this routine reads in some initial values. |
| 65 |
c* |
| 66 |
c* author: michael holst |
| 67 |
c* ********************************************************************* |
| 68 |
implicit none |
| 69 |
integer iparm(*),nrwk,niwk,nx,ny,nz,nlev,nu1,nu2,mgkey |
| 70 |
integer istop,iinfo,key,meth,itmax,ipcon |
| 71 |
integer ipkey,iperf |
| 72 |
integer nonlin,mgprol,mgcoar,mgdisc,mgsmoo,mgsolv |
| 73 |
double precision rparm(*),errtol,omegal,omegan |
| 74 |
c* |
| 75 |
c* *** parameters *** |
| 76 |
integer iread,irite |
| 77 |
parameter (iread=7, irite=8) |
| 78 |
c* |
| 79 |
c* *** if not interactive mode then open i/o files *** |
| 80 |
open(unit=iread, file='in', status='unknown') |
| 81 |
open(unit=irite, file='outt', status='unknown') |
| 82 |
rewind(iread) |
| 83 |
rewind(irite) |
| 84 |
c* |
| 85 |
c* *** input the controling parameters *** |
| 86 |
read (iread,10) |
| 87 |
read (iread,10) |
| 88 |
read (iread,30) nx |
| 89 |
read (iread,30) ny |
| 90 |
read (iread,30) nz |
| 91 |
read (iread,20) errtol |
| 92 |
read (iread,30) itmax |
| 93 |
read (iread,30) istop |
| 94 |
read (iread,30) iinfo |
| 95 |
read (iread,30) ipkey |
| 96 |
read (iread,30) key |
| 97 |
read (iread,30) iperf |
| 98 |
read (iread,10) |
| 99 |
read (iread,10) |
| 100 |
read (iread,10) |
| 101 |
read (iread,30) meth |
| 102 |
read (iread,30) nonlin |
| 103 |
read (iread,30) mgkey |
| 104 |
read (iread,30) nlev |
| 105 |
read (iread,30) nu1 |
| 106 |
read (iread,30) nu2 |
| 107 |
read (iread,30) mgsmoo |
| 108 |
read (iread,30) mgprol |
| 109 |
read (iread,30) mgcoar |
| 110 |
read (iread,30) mgsolv |
| 111 |
read (iread,30) mgdisc |
| 112 |
read (iread,20) omegal |
| 113 |
read (iread,20) omegan |
| 114 |
read (iread,30) ipcon |
| 115 |
c* |
| 116 |
c* *** pack iparm/rparm correctly for desired method *** |
| 117 |
call packmg (iparm,rparm, |
| 118 |
2 nrwk,niwk,nx,ny,nz,nlev,nu1,nu2,mgkey,itmax,istop,ipcon, |
| 119 |
3 nonlin,mgsmoo,mgprol,mgcoar,mgsolv,mgdisc,iinfo,errtol,ipkey, |
| 120 |
4 omegal,omegan,irite,iperf) |
| 121 |
c* |
| 122 |
c* *** do a little output now *** |
| 123 |
write(*,40) '% READIT: done reading input file... ' |
| 124 |
c* |
| 125 |
c* *** format statements *** |
| 126 |
10 format() |
| 127 |
20 format(e10.1) |
| 128 |
30 format(i10) |
| 129 |
40 format (a) |
| 130 |
c* |
| 131 |
c* *** return and end *** |
| 132 |
return |
| 133 |
end |
| 134 |
subroutine packmg (iparm,rparm, |
| 135 |
2 nrwk,niwk,nx,ny,nz,nlev,nu1,nu2,mgkey,itmax,istop,ipcon, |
| 136 |
3 nonlin,mgsmoo,mgprol,mgcoar,mgsolv,mgdisc,iinfo,errtol,ipkey, |
| 137 |
4 omegal,omegan,irite,iperf) |
| 138 |
c* ********************************************************************* |
| 139 |
c* purpose: |
| 140 |
c* |
| 141 |
c* this routine reads in some initial values. |
| 142 |
c* |
| 143 |
c* author: michael holst |
| 144 |
c* ********************************************************************* |
| 145 |
implicit none |
| 146 |
integer iparm(*),nrwk,niwk,nx,ny,nz,nlev,nu1,nu2,mgkey |
| 147 |
integer itmax,istop,ipcon,nonlin,iinfo,irite,ipkey,iperf |
| 148 |
integer mgsmoo,mgprol,mgcoar,mgsolv,mgdisc |
| 149 |
double precision rparm(*),errtol,omegal,omegan |
| 150 |
c* |
| 151 |
c* *** encode iparm parameters *** |
| 152 |
iparm(1) = nrwk |
| 153 |
iparm(2) = niwk |
| 154 |
iparm(3) = nx |
| 155 |
iparm(4) = ny |
| 156 |
iparm(5) = nz |
| 157 |
iparm(6) = nlev |
| 158 |
iparm(7) = nu1 |
| 159 |
iparm(8) = nu2 |
| 160 |
iparm(9) = mgkey |
| 161 |
iparm(10) = itmax |
| 162 |
iparm(11) = istop |
| 163 |
iparm(12) = iinfo |
| 164 |
iparm(13) = irite |
| 165 |
iparm(14) = ipkey |
| 166 |
iparm(15) = ipcon |
| 167 |
iparm(16) = nonlin |
| 168 |
iparm(17) = mgprol |
| 169 |
iparm(18) = mgcoar |
| 170 |
iparm(19) = mgdisc |
| 171 |
iparm(20) = mgsmoo |
| 172 |
iparm(21) = mgsolv |
| 173 |
iparm(22) = iperf |
| 174 |
c* |
| 175 |
c* *** encode rparm parameters *** |
| 176 |
rparm(1) = errtol |
| 177 |
rparm(9) = omegal |
| 178 |
rparm(10) = omegan |
| 179 |
c* |
| 180 |
c* *** return and end *** |
| 181 |
return |
| 182 |
end |
| 183 |
subroutine writit (iparm,rparm,nx,ny,nz,u, |
| 184 |
2 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf,key) |
| 185 |
c* ********************************************************************* |
| 186 |
c* purpose: |
| 187 |
c* |
| 188 |
c* this routine prints out the solution |
| 189 |
c* |
| 190 |
c* author: michael holst |
| 191 |
c* ********************************************************************* |
| 192 |
implicit none |
| 193 |
c* |
| 194 |
c* *** dimensions of parameters *** |
| 195 |
integer iparm(*),nx,ny,nz,key,i,j,k |
| 196 |
double precision rparm(*),xmin,xmax,ymin,ymax,zmin,zmax,hx,hy,hz |
| 197 |
double precision xf(*),yf(*),zf(*) |
| 198 |
double precision u(nx,ny,nz),tcf(nx,ny,nz) |
| 199 |
double precision a1cf(nx,ny,nz),a2cf(nx,ny,nz),a3cf(nx,ny,nz) |
| 200 |
double precision ccf(nx,ny,nz),fcf(nx,ny,nz) |
| 201 |
double precision gxcf (ny,nz,2) |
| 202 |
double precision gycf (nx,nz,2) |
| 203 |
double precision gzcf (nx,ny,2) |
| 204 |
character*20 title |
| 205 |
integer iounit |
| 206 |
parameter (iounit=9) |
| 207 |
c* |
| 208 |
c* *** get some stuff from iparm and rparm *** |
| 209 |
xmin = rparm(3) |
| 210 |
xmax = rparm(4) |
| 211 |
ymin = rparm(5) |
| 212 |
ymax = rparm(6) |
| 213 |
zmin = rparm(7) |
| 214 |
zmax = rparm(8) |
| 215 |
c* |
| 216 |
c* *** compute a few things *** |
| 217 |
hx = (xmax-xmin) / dble(nx-1) |
| 218 |
hy = (ymax-ymin) / dble(ny-1) |
| 219 |
hz = (zmax-zmin) / dble(nz-1) |
| 220 |
title = 'elliptic multigrid' |
| 221 |
c* |
| 222 |
c* *** print out the solution values in the ncsa format *** |
| 223 |
if (key.eq.1) then |
| 224 |
c* |
| 225 |
c* *** open and rewind the file *** |
| 226 |
open(unit=iounit, file='outn', status='unknown') |
| 227 |
rewind(iounit) |
| 228 |
c* |
| 229 |
c* *** write it out *** |
| 230 |
write(iounit,605) title |
| 231 |
write(iounit,600) nx,ny,nz,0.0d0 |
| 232 |
do 10 k = 1, nz |
| 233 |
do 11 j = 1, ny |
| 234 |
do 12 i = 1, nx |
| 235 |
write (iounit,610) u(i,j,k) |
| 236 |
12 continue |
| 237 |
11 continue |
| 238 |
10 continue |
| 239 |
c* |
| 240 |
c* *** close the file *** |
| 241 |
close(iounit) |
| 242 |
c* |
| 243 |
c* *** print out the solution values in a normal format *** |
| 244 |
elseif (key.eq.2) then |
| 245 |
c* |
| 246 |
c* *** open and rewind the file *** |
| 247 |
open(unit=iounit, file='outn', status='unknown') |
| 248 |
rewind(iounit) |
| 249 |
c* |
| 250 |
c* *** write it out *** |
| 251 |
write(iounit,605) title |
| 252 |
write(iounit,600) nx,ny,nz,0.0d0 |
| 253 |
do 20 k = 1, nz |
| 254 |
do 21 j = 1, ny |
| 255 |
do 22 i = 1, nx |
| 256 |
write (iounit,620) xf(i),yf(j),zf(k),u(i,j,k) |
| 257 |
22 continue |
| 258 |
21 continue |
| 259 |
20 continue |
| 260 |
c* |
| 261 |
c* *** close the file *** |
| 262 |
close(iounit) |
| 263 |
c* |
| 264 |
c* *** print out the solution values in a second normal format *** |
| 265 |
elseif (key.eq.3) then |
| 266 |
c* |
| 267 |
c* *** open and rewind the file *** |
| 268 |
open(unit=iounit, file='outn', status='unknown') |
| 269 |
rewind(iounit) |
| 270 |
c* |
| 271 |
c* *** write it out *** |
| 272 |
write(iounit,605) title |
| 273 |
write(iounit,600) nx,ny,nz,0.0d0 |
| 274 |
do 30 k = 1, nz |
| 275 |
do 31 j = 1, ny |
| 276 |
do 32 i = 1, nx |
| 277 |
write (iounit,630) i,j,k,u(i,j,k) |
| 278 |
32 continue |
| 279 |
31 continue |
| 280 |
30 continue |
| 281 |
c* |
| 282 |
c* *** close the file *** |
| 283 |
close(iounit) |
| 284 |
c* |
| 285 |
c* *** print out the solution values to check against true solution *** |
| 286 |
elseif (key.eq.4) then |
| 287 |
c* |
| 288 |
c* *** open and rewind the file *** |
| 289 |
open(unit=iounit, file='outn', status='unknown') |
| 290 |
rewind(iounit) |
| 291 |
c* |
| 292 |
c* *** write it out *** |
| 293 |
do 40 i = 33, 33 |
| 294 |
do 41 j = 33, 33 |
| 295 |
do 42 k = 28, 38 |
| 296 |
write (6,630) i,j,k,u(i,j,k),tcf(i,j,k) |
| 297 |
42 continue |
| 298 |
41 continue |
| 299 |
40 continue |
| 300 |
write(6,*) ' ' |
| 301 |
do 50 i = 1, 1 |
| 302 |
do 51 j = 1, 1 |
| 303 |
do 52 k = 1, 3 |
| 304 |
write (6,630) i,j,k,u(i,j,k),tcf(i,j,k) |
| 305 |
52 continue |
| 306 |
51 continue |
| 307 |
50 continue |
| 308 |
write(6,*) ' ' |
| 309 |
do 60 i = 2, 2 |
| 310 |
do 61 j = 2, 2 |
| 311 |
do 62 k = 2, 4 |
| 312 |
write (6,630) i,j,k,u(i,j,k),tcf(i,j,k) |
| 313 |
62 continue |
| 314 |
61 continue |
| 315 |
60 continue |
| 316 |
c* |
| 317 |
c* *** close the file *** |
| 318 |
close(iounit) |
| 319 |
c* |
| 320 |
c* *** write out some slices only *** |
| 321 |
elseif (key.eq.5) then |
| 322 |
c* |
| 323 |
c* *** re-fill the coefficient arrays since we overwrote them *** |
| 324 |
call fillco (iparm,rparm,nx,ny,nz, |
| 325 |
2 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf) |
| 326 |
c* |
| 327 |
c* *** open and rewind the file *** |
| 328 |
open(unit=iounit, file='outnx.m', status='unknown') |
| 329 |
rewind(iounit) |
| 330 |
c* |
| 331 |
c* *** write it out *** |
| 332 |
write(iounit,650) title |
| 333 |
write(iounit,660) nx |
| 334 |
write(iounit,670) 'xi','yj','zk','x','a','c','f','t' |
| 335 |
write(iounit,605) 'Z = [' |
| 336 |
do 70 k = nz/2, nz/2 |
| 337 |
do 71 j = ny/2, ny/2 |
| 338 |
do 72 i = 1, nx |
| 339 |
write (iounit,640) xf(i),yf(j),zf(k),u(i,j,k), |
| 340 |
2 (a1cf(i,j,k)+a1cf(i+1,j,k) |
| 341 |
3 +a2cf(i,j,k)+a2cf(i,j+1,k) |
| 342 |
4 +a3cf(i,j,k)+a3cf(i,j,k+1))/6.0d0, |
| 343 |
5 ccf(i,j,k),fcf(i,j,k),tcf(i,j,k) |
| 344 |
72 continue |
| 345 |
71 continue |
| 346 |
70 continue |
| 347 |
write(iounit,605) '];' |
| 348 |
c* |
| 349 |
c* *** close the file *** |
| 350 |
close(iounit) |
| 351 |
c* |
| 352 |
c* *** open and rewind the file *** |
| 353 |
open(unit=iounit, file='outny.m', status='unknown') |
| 354 |
rewind(iounit) |
| 355 |
c* |
| 356 |
c* *** write it out *** |
| 357 |
write(iounit,650) title |
| 358 |
write(iounit,661) ny |
| 359 |
write(iounit,670) 'xi','yj','zk','x','a','c','f','t' |
| 360 |
write(iounit,605) 'Z = [' |
| 361 |
do 80 k = nz/2, nz/2 |
| 362 |
do 81 j = 1, ny |
| 363 |
do 82 i = nx/2, nx/2 |
| 364 |
write (iounit,640) xf(i),yf(j),zf(k),u(i,j,k), |
| 365 |
2 (a1cf(i,j,k)+a1cf(i+1,j,k) |
| 366 |
3 +a2cf(i,j,k)+a2cf(i,j+1,k) |
| 367 |
4 +a3cf(i,j,k)+a3cf(i,j,k+1))/6.0d0, |
| 368 |
5 ccf(i,j,k),fcf(i,j,k),tcf(i,j,k) |
| 369 |
82 continue |
| 370 |
81 continue |
| 371 |
80 continue |
| 372 |
write(iounit,605) '];' |
| 373 |
c* |
| 374 |
c* *** close the file *** |
| 375 |
close(iounit) |
| 376 |
c* |
| 377 |
c* *** open and rewind the file *** |
| 378 |
open(unit=iounit, file='outnz.m', status='unknown') |
| 379 |
rewind(iounit) |
| 380 |
c* |
| 381 |
c* *** write it out *** |
| 382 |
write(iounit,650) title |
| 383 |
write(iounit,662) nz |
| 384 |
write(iounit,670) 'xi','yj','zk','x','a','c','f','t' |
| 385 |
write(iounit,605) 'Z = [' |
| 386 |
do 90 k = 1, nz |
| 387 |
do 91 j = ny/2, ny/2 |
| 388 |
do 92 i = nx/2, nx/2 |
| 389 |
write (iounit,640) xf(i),yf(j),zf(k),u(i,j,k), |
| 390 |
2 (a1cf(i,j,k)+a1cf(i+1,j,k) |
| 391 |
3 +a2cf(i,j,k)+a2cf(i,j+1,k) |
| 392 |
4 +a3cf(i,j,k)+a3cf(i,j,k+1))/6.0d0, |
| 393 |
5 ccf(i,j,k),fcf(i,j,k),tcf(i,j,k) |
| 394 |
92 continue |
| 395 |
91 continue |
| 396 |
90 continue |
| 397 |
write(iounit,605) '];' |
| 398 |
c* |
| 399 |
c* *** close the file *** |
| 400 |
close(iounit) |
| 401 |
c* |
| 402 |
c* *** write out in a fast binary format *** |
| 403 |
elseif (key.eq.6) then |
| 404 |
c* |
| 405 |
c* *** open and rewind the file *** |
| 406 |
open(unit=iounit, file='outn', form='unformatted') |
| 407 |
rewind(iounit) |
| 408 |
c* |
| 409 |
c* *** write it out *** |
| 410 |
write(iounit) title |
| 411 |
write(iounit) nx,ny,nz,0.0d0 |
| 412 |
write(iounit) u |
| 413 |
c* |
| 414 |
c* *** close the file *** |
| 415 |
close(iounit) |
| 416 |
c* |
| 417 |
c* *** print out the mesh for display/etc. *** |
| 418 |
elseif (key.eq.7) then |
| 419 |
c* |
| 420 |
c* *** open and rewind the file *** |
| 421 |
open(unit=iounit, file='outn', status='unknown') |
| 422 |
rewind(iounit) |
| 423 |
c* |
| 424 |
c* *** write it out *** |
| 425 |
write(iounit,605) "the mesh" |
| 426 |
write(iounit,680) nx,ny,nz |
| 427 |
do 100 i = 1, nx |
| 428 |
write (iounit,690) xf(i) |
| 429 |
100 continue |
| 430 |
do 110 j = 1, ny |
| 431 |
write (iounit,690) yf(j) |
| 432 |
110 continue |
| 433 |
do 120 k = 1, nz |
| 434 |
write (iounit,690) zf(k) |
| 435 |
120 continue |
| 436 |
c* |
| 437 |
c* *** close the file *** |
| 438 |
close(iounit) |
| 439 |
c* |
| 440 |
c* *** that's all *** |
| 441 |
endif |
| 442 |
c* |
| 443 |
c* *** format statements *** |
| 444 |
600 format (3(i10),2(1pe10.2)) |
| 445 |
605 format (a) |
| 446 |
610 format (2(1pe10.2)) |
| 447 |
620 format (5(1pe10.2)) |
| 448 |
630 format (3(i10),2(1pe15.7)) |
| 449 |
640 format (8(1pe10.2)) |
| 450 |
650 format ('% ',a) |
| 451 |
660 format ('nx = ',i10,';') |
| 452 |
661 format ('ny = ',i10,';') |
| 453 |
662 format ('nz = ',i10,';') |
| 454 |
670 format ('% ',a8,7(a10)) |
| 455 |
680 format (3(i10)) |
| 456 |
690 format (1pe10.2) |
| 457 |
c* |
| 458 |
c* *** return and end *** |
| 459 |
return |
| 460 |
end |