| 1 |
c* /////////////////////////////////////////////////////////////////////////// |
| 2 |
c* @file mgsubd.f |
| 3 |
c* @author Michael Holst |
| 4 |
c* @brief Supporting routines for CS and FAS multigrid algorithms. |
| 5 |
c* @version $Id: mgsubd.f,v 1.2 2010/08/12 05:45:34 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 |
integer function maxlev(n1,n2,n3) |
| 61 |
c* ********************************************************************* |
| 62 |
c* purpose: |
| 63 |
c* |
| 64 |
c* find maximum multigrid possible coarsenning common to three grid |
| 65 |
c* sizes: n1,n2,n3. |
| 66 |
c* |
| 67 |
c* author: michael holst |
| 68 |
c* ********************************************************************* |
| 69 |
implicit none |
| 70 |
integer n1,n2,n3,n1c,n2c,n3c,lev,iden,idone |
| 71 |
c* |
| 72 |
c* *** fine the common level *** |
| 73 |
idone = 0 |
| 74 |
lev = 0 |
| 75 |
10 continue |
| 76 |
lev = lev + 1 |
| 77 |
iden = 2**(lev-1) |
| 78 |
n1c = (n1-1)/iden + 1 |
| 79 |
n2c = (n2-1)/iden + 1 |
| 80 |
n3c = (n3-1)/iden + 1 |
| 81 |
if ( ((n1c-1)*iden .ne. (n1-1)) .or. (n1c .le. 2) ) idone = 1 |
| 82 |
if ( ((n2c-1)*iden .ne. (n2-1)) .or. (n2c .le. 2) ) idone = 1 |
| 83 |
if ( ((n3c-1)*iden .ne. (n3-1)) .or. (n3c .le. 2) ) idone = 1 |
| 84 |
if (idone .ne. 1) goto 10 |
| 85 |
maxlev = lev-1 |
| 86 |
c* |
| 87 |
c* *** return and end *** |
| 88 |
return |
| 89 |
end |
| 90 |
subroutine mkcors(numlev,nxold,nyold,nzold,nxnew,nynew,nznew) |
| 91 |
c* ********************************************************************* |
| 92 |
c* purpose: |
| 93 |
c* |
| 94 |
c* compute the number of grid points in the coarser grid, given the |
| 95 |
c* number of grid points in a finger grid in each direction. |
| 96 |
c* |
| 97 |
c* author: michael holst |
| 98 |
c* ********************************************************************* |
| 99 |
implicit none |
| 100 |
integer numlev,nxold,nyold,nzold,nxnew,nynew,nznew |
| 101 |
integer nxtmp,nytmp,nztmp,i |
| 102 |
c* |
| 103 |
c* *** determine the coarser grid *** |
| 104 |
nxnew = nxold |
| 105 |
nynew = nyold |
| 106 |
nznew = nzold |
| 107 |
do 10 i = 1, numlev |
| 108 |
nxtmp = nxnew |
| 109 |
nytmp = nynew |
| 110 |
nztmp = nznew |
| 111 |
call corsr(nxtmp,nxnew) |
| 112 |
call corsr(nytmp,nynew) |
| 113 |
call corsr(nztmp,nznew) |
| 114 |
10 continue |
| 115 |
c* |
| 116 |
c* *** return and end *** |
| 117 |
return |
| 118 |
end |
| 119 |
subroutine corsr(nold,nnew) |
| 120 |
c* ********************************************************************* |
| 121 |
c* purpose: |
| 122 |
c* |
| 123 |
c* compute the number of grid points in the coarser grid, given the |
| 124 |
c* number of grid points in a finer grid. |
| 125 |
c* |
| 126 |
c* author: michael holst |
| 127 |
c* ********************************************************************* |
| 128 |
implicit none |
| 129 |
integer nold,nnew |
| 130 |
c* |
| 131 |
c* *** find the coarser grid size *** |
| 132 |
nnew = (nold - 1) / 2 + 1 |
| 133 |
c* |
| 134 |
c* *** check a few things *** |
| 135 |
if (((nnew-1)*2).ne.(nold-1)) |
| 136 |
2 print*,'% CORSR: may not corsen grid this far... ' |
| 137 |
if (nnew .lt. 1) |
| 138 |
2 print*,'% CORSR: have corsenned grid below zero... ' |
| 139 |
c* |
| 140 |
c* *** return and end *** |
| 141 |
return |
| 142 |
end |
| 143 |
subroutine mkfine(numlev,nxold,nyold,nzold,nxnew,nynew,nznew) |
| 144 |
c* ********************************************************************* |
| 145 |
c* purpose: |
| 146 |
c* |
| 147 |
c* compute the number of grid points in the finer grid, given the |
| 148 |
c* number of grid points in a coarser grid in each direction. |
| 149 |
c* |
| 150 |
c* author: michael holst |
| 151 |
c* ********************************************************************* |
| 152 |
implicit none |
| 153 |
integer numlev,nxold,nyold,nzold,nxnew,nynew,nznew |
| 154 |
integer nxtmp,nytmp,nztmp,i |
| 155 |
c* |
| 156 |
c* *** determine the finer grid *** |
| 157 |
nxnew = nxold |
| 158 |
nynew = nyold |
| 159 |
nznew = nzold |
| 160 |
do 10 i = 1, numlev |
| 161 |
nxtmp = nxnew |
| 162 |
nytmp = nynew |
| 163 |
nztmp = nznew |
| 164 |
call finer(nxtmp,nxnew) |
| 165 |
call finer(nytmp,nynew) |
| 166 |
call finer(nztmp,nznew) |
| 167 |
10 continue |
| 168 |
c* |
| 169 |
c* *** return and end *** |
| 170 |
return |
| 171 |
end |
| 172 |
subroutine finer(nold,nnew) |
| 173 |
c* ********************************************************************* |
| 174 |
c* purpose: |
| 175 |
c* |
| 176 |
c* compute the number of grid points in the finer grid, given the |
| 177 |
c* number of grid points in a coarser grid. |
| 178 |
c* |
| 179 |
c* author: michael holst |
| 180 |
c* ********************************************************************* |
| 181 |
implicit none |
| 182 |
integer nold,nnew |
| 183 |
c* |
| 184 |
c* *** find the finer grid size *** |
| 185 |
nnew = (nold - 1) * 2 + 1 |
| 186 |
c* |
| 187 |
c* *** return and end *** |
| 188 |
return |
| 189 |
end |
| 190 |
function ivariv (nu,level) |
| 191 |
c* ********************************************************************* |
| 192 |
c* purpose: |
| 193 |
c* |
| 194 |
c* this routine defines the number of smoothings for a particular |
| 195 |
c* level in a variable-v-cycle method. |
| 196 |
c* |
| 197 |
c* possible definitions: |
| 198 |
c* ivariv = nu * 2**(level - 1) |
| 199 |
c* ivariv = nu * level |
| 200 |
c* ivariv = nu + (level - 1) |
| 201 |
c* |
| 202 |
c* author: michael holst |
| 203 |
c* ********************************************************************* |
| 204 |
implicit none |
| 205 |
integer ivariv,nu,level |
| 206 |
c* |
| 207 |
c* ** *** variable V-cycle *** |
| 208 |
c* ** ivariv = nu * 2**(level - 1) |
| 209 |
c* |
| 210 |
c* ** *** standard V-cycle *** |
| 211 |
ivariv = nu |
| 212 |
c* |
| 213 |
c* *** return and end *** |
| 214 |
return |
| 215 |
end |
| 216 |
subroutine prtini(istop) |
| 217 |
c* ********************************************************************* |
| 218 |
c* purpose: |
| 219 |
c* |
| 220 |
c* this routine prints out some info and such from inside multigrid. |
| 221 |
c* |
| 222 |
c* author: michael holst |
| 223 |
c* ********************************************************************* |
| 224 |
implicit none |
| 225 |
integer istop |
| 226 |
character*20 str0a,str1a,str2a,str3a |
| 227 |
character*20 str0b,str1b,str2b,str3b |
| 228 |
character*20 str0c,str1c,str2c,str3c |
| 229 |
c* |
| 230 |
c* *** do some i/o *** |
| 231 |
str0a = 'iteration ' |
| 232 |
str0b = 'count ' |
| 233 |
str0c = '--------- ' |
| 234 |
if (istop .eq. 0) then |
| 235 |
str1a = 'absol resid' |
| 236 |
str1b = 'discr(1-nm)' |
| 237 |
str1c = '-----------' |
| 238 |
elseif (istop .eq. 1) then |
| 239 |
str1a = 'relat resid' |
| 240 |
str1b = 'discr(1-nm)' |
| 241 |
str1c = '-----------' |
| 242 |
elseif (istop .eq. 2) then |
| 243 |
str1a = 'rms change ' |
| 244 |
str1b = 'discr(1-nm)' |
| 245 |
str1c = '---------- ' |
| 246 |
elseif (istop .eq. 3) then |
| 247 |
str1a = 'relat error' |
| 248 |
str1b = 'conti(2-nm)' |
| 249 |
str1c = '-----------' |
| 250 |
elseif (istop .eq. 4) then |
| 251 |
str1a = 'relat error' |
| 252 |
str1b = 'discr(2-nm)' |
| 253 |
str1c = '-----------' |
| 254 |
elseif (istop .eq. 5) then |
| 255 |
str1a = 'relat error' |
| 256 |
str1b = 'discr(A-nm)' |
| 257 |
str1c = '-----------' |
| 258 |
else |
| 259 |
print*,'% PRTINI: bad istop value... ' |
| 260 |
endif |
| 261 |
str2a = 'contraction' |
| 262 |
str2b = 'number ' |
| 263 |
str2c = '-----------' |
| 264 |
str3a = 'wall ' |
| 265 |
str3b = 'clock' |
| 266 |
str3c = '-----' |
| 267 |
write(6,100) str0c,str1c,str2c,str3c |
| 268 |
write(6,100) str0a,str1a,str2a,str3a |
| 269 |
write(6,100) str0b,str1b,str2b,str3b |
| 270 |
write(6,100) str0c,str1c,str2c,str3c |
| 271 |
c* |
| 272 |
c* *** format statements *** |
| 273 |
100 format('% ',a12,1x,a12,3x,a12,3x,a12) |
| 274 |
c* |
| 275 |
c* *** return and end *** |
| 276 |
return |
| 277 |
end |
| 278 |
subroutine prtstp(iok,iters,rsnrm,rsden,orsnrm) |
| 279 |
c* ********************************************************************* |
| 280 |
c* purpose: |
| 281 |
c* |
| 282 |
c* this routine prints out some info and such from inside multigrid. |
| 283 |
c* |
| 284 |
c* author: michael holst |
| 285 |
c* ********************************************************************* |
| 286 |
implicit none |
| 287 |
integer iok,iters |
| 288 |
double precision rsnrm,rsden,orsnrm |
| 289 |
double precision relres,contrac |
| 290 |
double precision bf,oh,cputme |
| 291 |
save bf,oh,cputme |
| 292 |
c* |
| 293 |
c* *** initializing timer *** |
| 294 |
if (iters .eq. -99) then |
| 295 |
print*,'% PRTSTP: initializing timer...' |
| 296 |
call tstart(bf,oh) |
| 297 |
cputme = 0.0d0 |
| 298 |
goto 99 |
| 299 |
c* |
| 300 |
c* *** setup for the iteration *** |
| 301 |
elseif (iters .eq. -1) then |
| 302 |
call tstop(bf,oh,cputme) |
| 303 |
if (iok .eq. 1) then |
| 304 |
write(6,100) -1,0.0d0,0.0d0,cputme |
| 305 |
elseif (iok .eq. 2) then |
| 306 |
write(6,110) -1,0.0d0,0.0d0,cputme |
| 307 |
endif |
| 308 |
goto 99 |
| 309 |
c* |
| 310 |
c* *** during the iteration *** |
| 311 |
else |
| 312 |
c* |
| 313 |
c* *** stop the timer *** |
| 314 |
call tstop(bf,oh,cputme) |
| 315 |
c* |
| 316 |
c* *** relative residual *** |
| 317 |
if (rsden .eq. 0.0d0) then |
| 318 |
relres = 1.0e6 |
| 319 |
print*,'% PRTSTP: avoided division by zero' |
| 320 |
else |
| 321 |
relres = rsnrm/rsden |
| 322 |
endif |
| 323 |
c* |
| 324 |
c* *** contraction number *** |
| 325 |
if (orsnrm .eq. 0.0d0) then |
| 326 |
contrac = 1.0e6 |
| 327 |
print*,'% PRTSTP: avoided division by zero' |
| 328 |
else |
| 329 |
contrac = rsnrm/orsnrm |
| 330 |
endif |
| 331 |
c* |
| 332 |
c* *** the i/o *** |
| 333 |
if (iok .eq. 1) then |
| 334 |
write(6,100) iters,relres,contrac,cputme |
| 335 |
elseif (iok .eq. 2) then |
| 336 |
write(6,110) iters,relres,contrac,cputme |
| 337 |
endif |
| 338 |
endif |
| 339 |
c* |
| 340 |
c* *** format statements *** |
| 341 |
100 format(2x, i5,8x,1pe11.5,4x,1pe11.5,4x,1pe8.2,20x,'%%%') |
| 342 |
110 format('% ',i5,8x,1pe11.5,4x,1pe11.5,4x,1pe8.2) |
| 343 |
c* |
| 344 |
c* *** return and end *** |
| 345 |
99 continue |
| 346 |
return |
| 347 |
end |
| 348 |
subroutine buildstr (nx,ny,nz,nlev,iz) |
| 349 |
c* ********************************************************************* |
| 350 |
c* purpose: |
| 351 |
c* |
| 352 |
c* build the nested operator framework in the array iz |
| 353 |
c* |
| 354 |
c* note: iz(50,i) indexes into the gridfcn arrays |
| 355 |
c* for each level i=(1,...,nlev+1) as follows: |
| 356 |
c* |
| 357 |
c* fun(i) = fun (iz(1,i)) |
| 358 |
c* bndx(i) = bndx(iz(2,i)) |
| 359 |
c* bndy(i) = bndy(iz(3,i)) |
| 360 |
c* bndz(i) = bndz(iz(4,i)) |
| 361 |
c* ipc(i) = ipc(iz(5,i)) |
| 362 |
c* rpc(i) = rpc(iz(6,i)) |
| 363 |
c* oper(i) = oper(iz(7,i)) |
| 364 |
c* grdx(i) = brdx(iz(8,i)) |
| 365 |
c* grdy(i) = brdy(iz(9,i)) |
| 366 |
c* grdz(i) = brdz(iz(10,i)) |
| 367 |
c* |
| 368 |
c* author: michael holst |
| 369 |
c* ********************************************************************* |
| 370 |
implicit none |
| 371 |
integer iz(50,*),nx,ny,nz,nlev,lev,n |
| 372 |
integer nxold,nyold,nzold,nxnew,nynew,nznew |
| 373 |
c* |
| 374 |
c* *** setup *** |
| 375 |
nxnew = nx |
| 376 |
nynew = ny |
| 377 |
nznew = nz |
| 378 |
n = nxnew*nynew*nznew |
| 379 |
c* |
| 380 |
c* *** start with level 1 *** |
| 381 |
lev = 1 |
| 382 |
c* |
| 383 |
c* *** mark beginning of everything at level 1 *** |
| 384 |
iz(1,lev) = 1 |
| 385 |
iz(2,lev) = 1 |
| 386 |
iz(3,lev) = 1 |
| 387 |
iz(4,lev) = 1 |
| 388 |
iz(5,lev) = 1 |
| 389 |
iz(6,lev) = 1 |
| 390 |
iz(7,lev) = 1 |
| 391 |
iz(8,lev) = 1 |
| 392 |
iz(9,lev) = 1 |
| 393 |
iz(10,lev) = 1 |
| 394 |
iz(11,lev) = 1 |
| 395 |
c* |
| 396 |
c* *** mark beginning of everything at level 2 *** |
| 397 |
iz(1,lev+1) = iz(1,lev) + n |
| 398 |
iz(2,lev+1) = iz(2,lev) + 4*nynew*nznew |
| 399 |
iz(3,lev+1) = iz(3,lev) + 4*nxnew*nznew |
| 400 |
iz(4,lev+1) = iz(4,lev) + 4*nxnew*nynew |
| 401 |
iz(5,lev+1) = iz(5,lev) + 100 |
| 402 |
iz(6,lev+1) = iz(6,lev) + 100 |
| 403 |
iz(8,lev+1) = iz(8,lev) + nxnew |
| 404 |
iz(9,lev+1) = iz(9,lev) + nynew |
| 405 |
iz(10,lev+1) = iz(10,lev) + nznew |
| 406 |
c* ********************************************************************* |
| 407 |
c* ***NOTE: we mark operator offsets as we build the operators *** |
| 408 |
c* ***iz(7,lev+1) = iz(7,lev) + 4*n |
| 409 |
c* ********************************************************************* |
| 410 |
c* ***NOTE: we mark prolongation operator offsets lagging a level *** |
| 411 |
c* ***iz(11,lev) = iz(11,lev-1) + 27*nsmall |
| 412 |
c* ********************************************************************* |
| 413 |
c* |
| 414 |
c* *** mark the beginning of everything at (nlev-1) more *** |
| 415 |
do 10 lev = 2, nlev |
| 416 |
nxold = nxnew |
| 417 |
nyold = nynew |
| 418 |
nzold = nznew |
| 419 |
call mkcors(1,nxold,nyold,nzold,nxnew,nynew,nznew) |
| 420 |
n = nxnew*nynew*nznew |
| 421 |
c* |
| 422 |
c* *** mark the beginning of everything at level (lev+1) *** |
| 423 |
iz(1,lev+1) = iz(1,lev) + n |
| 424 |
iz(2,lev+1) = iz(2,lev) + 4*nynew*nznew |
| 425 |
iz(3,lev+1) = iz(3,lev) + 4*nxnew*nznew |
| 426 |
iz(4,lev+1) = iz(4,lev) + 4*nxnew*nynew |
| 427 |
iz(5,lev+1) = iz(5,lev) + 100 |
| 428 |
iz(6,lev+1) = iz(6,lev) + 100 |
| 429 |
iz(7,lev+1) = iz(7,lev) + 4*n |
| 430 |
iz(8,lev+1) = iz(8,lev) + nxnew |
| 431 |
iz(9,lev+1) = iz(9,lev) + nynew |
| 432 |
iz(10,lev+1) = iz(10,lev) + nznew |
| 433 |
c* *** mark prolongation operator storage for previous level *** |
| 434 |
iz(11,lev) = iz(11,lev-1) + 27*n |
| 435 |
c* *************************************************************** |
| 436 |
c* ***NOTE: we mark operator offsets as we build the operators *** |
| 437 |
c* *** iz(7,lev+1) = iz(7,lev) + 4*n |
| 438 |
c* *************************************************************** |
| 439 |
10 continue |
| 440 |
c* |
| 441 |
c* *** end it *** |
| 442 |
return |
| 443 |
end |
| 444 |
subroutine buildops (nx,ny,nz,nlev,ipkey,iinfo,ido,iz, |
| 445 |
2 mgprol,mgcoar,mgsolv,mgdisc, |
| 446 |
3 ipc,rpc,pc,ac,cc,fc, |
| 447 |
4 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf) |
| 448 |
c* ********************************************************************* |
| 449 |
c* purpose: |
| 450 |
c* |
| 451 |
c* build operators, boundary arrays, modify affine vectors. |
| 452 |
c* if (ido=0) do only fine level |
| 453 |
c* if (ido=1) do only coarse levels (including a second op at coarsest) |
| 454 |
c* if (ido=2) do all levels |
| 455 |
c* if (ido=3) rebuild the second operator at the coarsest level |
| 456 |
c* |
| 457 |
c* note: the fine level must be build before any coarse levels. |
| 458 |
c* |
| 459 |
c* author: michael holst |
| 460 |
c* ********************************************************************* |
| 461 |
implicit none |
| 462 |
integer ipc(*),iz(50,*),nx,ny,nz,nlev,iinfo,lev,ido |
| 463 |
integer nxx,nyy,nzz,nxold,nyold,nzold,numdia,key,ipkey |
| 464 |
integer mgprol,mgcoar,mgsolv,mgdisc |
| 465 |
double precision rpc(*),pc(*),ac(*),cc(*),fc(*) |
| 466 |
double precision a1cf(*),a2cf(*),a3cf(*),ccf(*),fcf(*),tcf(*) |
| 467 |
double precision gxcf(*),gycf(*),gzcf(*) |
| 468 |
double precision xf(*),yf(*),zf(*) |
| 469 |
c* |
| 470 |
c* *** setup *** |
| 471 |
nxx = nx |
| 472 |
nyy = ny |
| 473 |
nzz = nz |
| 474 |
c* |
| 475 |
c* *** build the operator a on the finest level *** |
| 476 |
if ((ido .eq. 0) .or. (ido .eq. 2)) then |
| 477 |
lev = 1 |
| 478 |
c* |
| 479 |
c* *** some i/o *** |
| 480 |
if (iinfo .ne. 0) then |
| 481 |
write(6,100)'% BUILDOPS: (FINE) :',nxx,nyy,nzz |
| 482 |
100 format(a,(2x,' [',i3,',',i3,',',i3,'] ')) |
| 483 |
endif |
| 484 |
c* |
| 485 |
c* *** finest level discretization *** |
| 486 |
call buildA (nxx,nyy,nzz,ipkey,mgdisc,numdia, |
| 487 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 488 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 489 |
4 xf(iz(8,lev)),yf(iz(9,lev)),zf(iz(10,lev)), |
| 490 |
5 gxcf(iz(2,lev)),gycf(iz(3,lev)),gzcf(iz(4,lev)), |
| 491 |
6 a1cf(iz(1,lev)),a2cf(iz(1,lev)),a3cf(iz(1,lev)), |
| 492 |
7 ccf(iz(1,lev)),fcf(iz(1,lev))) |
| 493 |
c* |
| 494 |
c* *** now initialize the differential operator offset *** |
| 495 |
print*,'% BUILDOPS: operator stencil (lev,numdia) = ', |
| 496 |
2 lev,numdia |
| 497 |
iz(7,lev+1) = iz(7,lev) + numdia * nxx * nyy * nzz |
| 498 |
c* |
| 499 |
c* *** debug *** |
| 500 |
if (iinfo.gt.7) call prtmatd(nxx,nyy,nzz, |
| 501 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)),ac(iz(7,lev))) |
| 502 |
endif |
| 503 |
c* |
| 504 |
c* *** build the (nlev-1) level operators *** |
| 505 |
if ((ido .eq. 1) .or. (ido .eq. 2) .or. (ido .eq. 3)) then |
| 506 |
do 10 lev = 2, nlev |
| 507 |
nxold = nxx |
| 508 |
nyold = nyy |
| 509 |
nzold = nzz |
| 510 |
call mkcors(1,nxold,nyold,nzold,nxx,nyy,nzz) |
| 511 |
if (ido .ne. 3) then |
| 512 |
c* |
| 513 |
c* *** build the interpolation operator on this level *** |
| 514 |
call buildP (nxold,nyold,nzold,nxx,nyy,nzz,mgprol, |
| 515 |
2 ipc(iz(5,lev-1)),rpc(iz(6,lev-1)), |
| 516 |
3 pc(iz(11,lev-1)),ac(iz(7,lev-1)), |
| 517 |
4 xf(iz(8,lev-1)),yf(iz(9,lev-1)),zf(iz(10,lev-1))) |
| 518 |
c* |
| 519 |
c* *** differential operator this level with standard disc. *** |
| 520 |
if (mgcoar .eq. 0) then |
| 521 |
if (iinfo .ne. 0) then |
| 522 |
write(6,100)'% BUILDOPS: (STAND) ',nxx,nyy,nzz |
| 523 |
endif |
| 524 |
call buildcopy0 (nxx,nyy,nzz,nxold,nyold,nzold, |
| 525 |
2 xf(iz(8,lev)),yf(iz(9,lev)),zf(iz(10,lev)), |
| 526 |
3 gxcf(iz(2,lev)),gycf(iz(3,lev)),gzcf(iz(4,lev)), |
| 527 |
4 a1cf(iz(1,lev)),a2cf(iz(1,lev)),a3cf(iz(1,lev)), |
| 528 |
5 ccf(iz(1,lev)),fcf(iz(1,lev)),tcf(iz(1,lev)), |
| 529 |
6 xf(iz(8,lev-1)),yf(iz(9,lev-1)),zf(iz(10,lev-1)), |
| 530 |
7 gxcf(iz(2,lev-1)),gycf(iz(3,lev-1)), |
| 531 |
7 gzcf(iz(4,lev-1)), |
| 532 |
8 a1cf(iz(1,lev-1)),a2cf(iz(1,lev-1)), |
| 533 |
8 a3cf(iz(1,lev-1)), |
| 534 |
9 ccf(iz(1,lev-1)),fcf(iz(1,lev-1)), |
| 535 |
9 tcf(iz(1,lev-1))) |
| 536 |
call buildA (nxx,nyy,nzz,ipkey,mgdisc,numdia, |
| 537 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 538 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 539 |
4 xf(iz(8,lev)),yf(iz(9,lev)),zf(iz(10,lev)), |
| 540 |
5 gxcf(iz(2,lev)),gycf(iz(3,lev)),gzcf(iz(4,lev)), |
| 541 |
6 a1cf(iz(1,lev)),a2cf(iz(1,lev)),a3cf(iz(1,lev)), |
| 542 |
7 ccf(iz(1,lev)),fcf(iz(1,lev))) |
| 543 |
c* |
| 544 |
c* *** differential operator this level with harmonic disc. *** |
| 545 |
elseif (mgcoar .eq. 1) then |
| 546 |
if (iinfo .ne. 0) then |
| 547 |
write(6,100)'% BUILDOPS: (HARMO) ',nxx,nyy,nzz |
| 548 |
endif |
| 549 |
call buildharm0 (nxx,nyy,nzz,nxold,nyold,nzold, |
| 550 |
2 xf(iz(8,lev)),yf(iz(9,lev)),zf(iz(10,lev)), |
| 551 |
3 gxcf(iz(2,lev)),gycf(iz(3,lev)),gzcf(iz(4,lev)), |
| 552 |
4 a1cf(iz(1,lev)),a2cf(iz(1,lev)),a3cf(iz(1,lev)), |
| 553 |
5 ccf(iz(1,lev)),fcf(iz(1,lev)),tcf(iz(1,lev)), |
| 554 |
6 xf(iz(8,lev-1)),yf(iz(9,lev-1)),zf(iz(10,lev-1)), |
| 555 |
7 gxcf(iz(2,lev-1)),gycf(iz(3,lev-1)), |
| 556 |
7 gzcf(iz(4,lev-1)), |
| 557 |
8 a1cf(iz(1,lev-1)),a2cf(iz(1,lev-1)), |
| 558 |
8 a3cf(iz(1,lev-1)), |
| 559 |
9 ccf(iz(1,lev-1)),fcf(iz(1,lev-1)), |
| 560 |
9 tcf(iz(1,lev-1))) |
| 561 |
call buildA (nxx,nyy,nzz,ipkey,mgdisc,numdia, |
| 562 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 563 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 564 |
4 xf(iz(8,lev)),yf(iz(9,lev)),zf(iz(10,lev)), |
| 565 |
5 gxcf(iz(2,lev)),gycf(iz(3,lev)),gzcf(iz(4,lev)), |
| 566 |
6 a1cf(iz(1,lev)),a2cf(iz(1,lev)),a3cf(iz(1,lev)), |
| 567 |
7 ccf(iz(1,lev)),fcf(iz(1,lev))) |
| 568 |
c* |
| 569 |
c* *** differential operator with galerkin formulation *** |
| 570 |
elseif (mgcoar .eq. 2) then |
| 571 |
if (iinfo .ne. 0) then |
| 572 |
write(6,100)'% BUILDOPS: (GALER) ',nxx,nyy,nzz |
| 573 |
endif |
| 574 |
call buildgaler0 (nxold,nyold,nzold,nxx,nyy,nzz, |
| 575 |
2 ipkey,numdia,pc(iz(11,lev-1)), |
| 576 |
3 ipc(iz(5,lev-1)),rpc(iz(6,lev-1)), |
| 577 |
4 ac(iz(7,lev-1)),cc(iz(1,lev-1)),fc(iz(1,lev-1)), |
| 578 |
5 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 579 |
6 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev))) |
| 580 |
call extrac(nxold,nyold,nzold,nxx,nyy,nzz, |
| 581 |
2 tcf(iz(1,lev-1)),tcf(iz(1,lev))) |
| 582 |
else |
| 583 |
print*,'% BUILDOPS: bad mgcoar key given...' |
| 584 |
endif |
| 585 |
c* |
| 586 |
c* *** now initialize the differential operator offset *** |
| 587 |
print*,'% BUILDOPS: operator stencil (lev,numdia) = ', |
| 588 |
2 lev,numdia |
| 589 |
iz(7,lev+1) = iz(7,lev) + numdia * nxx * nyy * nzz |
| 590 |
c* |
| 591 |
c* *** debug *** |
| 592 |
if (iinfo.gt.8) call prtmatd(nxx,nyy,nzz, |
| 593 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)),ac(iz(7,lev))) |
| 594 |
endif |
| 595 |
10 continue |
| 596 |
c* |
| 597 |
c* *** build a sparse format coarse grid operator *** |
| 598 |
if (mgsolv .eq. 1) then |
| 599 |
lev = nlev |
| 600 |
call buildband (key,nxx,nyy,nzz, |
| 601 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)),ac(iz(7,lev)), |
| 602 |
3 ipc(iz(5,lev+1)),rpc(iz(6,lev+1)),ac(iz(7,lev+1))) |
| 603 |
if (key .eq. 1) then |
| 604 |
print*,'% BUILDOPS: changing your MGSOLV to iterative...' |
| 605 |
mgsolv = 0 |
| 606 |
endif |
| 607 |
endif |
| 608 |
endif |
| 609 |
c* |
| 610 |
c* *** end it *** |
| 611 |
return |
| 612 |
end |
| 613 |
subroutine buildcopy0 (nx,ny,nz,nxf,nyf,nzf, |
| 614 |
2 xc,yc,zc,gxc,gyc,gzc,a1c,a2c,a3c,cc,fc,tc, |
| 615 |
3 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf) |
| 616 |
c* ********************************************************************* |
| 617 |
c* purpose: |
| 618 |
c* |
| 619 |
c* produce information for a coarser grid. |
| 620 |
c* |
| 621 |
c* author: michael holst |
| 622 |
c* ********************************************************************* |
| 623 |
implicit none |
| 624 |
integer nxf,nyf,nzf,nx,ny,nz,i,j,k,ii,jj,kk |
| 625 |
integer iadd,jadd,kadd |
| 626 |
double precision xc(nx),yc(ny),zc(nz) |
| 627 |
double precision gxc(ny,nz,*),gyc(nx,nz,*),gzc(nx,ny,*) |
| 628 |
double precision a1c(nx,ny,nz),a2c(nx,ny,nz),a3c(nx,ny,nz) |
| 629 |
double precision cc(nx,ny,nz),fc(nx,ny,nz),tc(nx,ny,nz) |
| 630 |
double precision xf(nxf),yf(nyf),zf(nzf) |
| 631 |
double precision gxcf(nyf,nzf,*),gycf(nxf,nzf,*),gzcf(nxf,nyf,*) |
| 632 |
double precision a1cf(nxf,nyf,nzf),a2cf(nxf,nyf,nzf) |
| 633 |
double precision a3cf(nxf,nyf,nzf),tcf(nxf,nyf,nzf) |
| 634 |
double precision ccf(nxf,nyf,nzf),fcf(nxf,nyf,nzf) |
| 635 |
c* |
| 636 |
cmdir 0 0 |
| 637 |
c* |
| 638 |
c* *** how far to step into the coefficient arrays *** |
| 639 |
iadd = (nxf-1)/(nx-1) |
| 640 |
jadd = (nyf-1)/(ny-1) |
| 641 |
kadd = (nzf-1)/(nz-1) |
| 642 |
if ((iadd.ne.2).or.(jadd.ne.2).or.(kadd.ne.2)) then |
| 643 |
print*,'% BUILDCOPY0: problem with grid dimensions...' |
| 644 |
endif |
| 645 |
c* |
| 646 |
c* *** compute the coarse grid pde coefficients *** |
| 647 |
cmdir 3 1 |
| 648 |
do 30 k = 1, nz |
| 649 |
kk = 2 * k - 1 |
| 650 |
zc(k) = zf(kk) |
| 651 |
cmdir 3 2 |
| 652 |
do 31 j = 1, ny |
| 653 |
jj = 2 * j - 1 |
| 654 |
yc(j) = yf(jj) |
| 655 |
cmdir 3 3 |
| 656 |
do 32 i = 1, nx |
| 657 |
ii = 2 * i - 1 |
| 658 |
xc(i) = xf(ii) |
| 659 |
c* |
| 660 |
c* *** true solution *** |
| 661 |
tc(i,j,k) = tcf(ii,jj,kk) |
| 662 |
c* |
| 663 |
c* *** helmholtz coefficient *** |
| 664 |
cc(i,j,k) = ccf(ii,jj,kk) |
| 665 |
c* |
| 666 |
c* *** source function *** |
| 667 |
fc(i,j,k) = fcf(ii,jj,kk) |
| 668 |
c* |
| 669 |
c* *** east/west neighbor *** |
| 670 |
a1c(i,j,k) = a1cf(ii,jj,kk) |
| 671 |
c* |
| 672 |
c* *** north/south neighbor *** |
| 673 |
a2c(i,j,k) = a2cf(ii,jj,kk) |
| 674 |
c* |
| 675 |
c* *** up/down neighbor *** |
| 676 |
a3c(i,j,k) = a3cf(ii,jj,kk) |
| 677 |
32 continue |
| 678 |
31 continue |
| 679 |
30 continue |
| 680 |
c* |
| 681 |
c* *** the (i=1) and (i=nx) boundaries *** |
| 682 |
cmdir 2 1 |
| 683 |
do 50 k = 1, nz |
| 684 |
kk = 2 * k - 1 |
| 685 |
cmdir 2 2 |
| 686 |
do 51 j = 1, ny |
| 687 |
jj = 2 * j - 1 |
| 688 |
gxc(j,k,1) = gxcf(jj,kk,1) |
| 689 |
gxc(j,k,2) = gxcf(jj,kk,2) |
| 690 |
gxc(j,k,3) = gxcf(jj,kk,3) |
| 691 |
gxc(j,k,4) = gxcf(jj,kk,4) |
| 692 |
51 continue |
| 693 |
50 continue |
| 694 |
c* |
| 695 |
c* *** the (j=1) and (j=ny) boundaries *** |
| 696 |
cmdir 2 1 |
| 697 |
do 60 k = 1, nz |
| 698 |
kk = 2 * k - 1 |
| 699 |
cmdir 2 2 |
| 700 |
do 61 i = 1, nx |
| 701 |
ii = 2 * i - 1 |
| 702 |
gyc(i,k,1) = gycf(ii,kk,1) |
| 703 |
gyc(i,k,2) = gycf(ii,kk,2) |
| 704 |
gyc(i,k,3) = gycf(ii,kk,3) |
| 705 |
gyc(i,k,4) = gycf(ii,kk,4) |
| 706 |
61 continue |
| 707 |
60 continue |
| 708 |
c* |
| 709 |
c* *** the (k=1) and (k=nz) boundaries *** |
| 710 |
cmdir 2 1 |
| 711 |
do 70 j = 1, ny |
| 712 |
jj = 2 * j - 1 |
| 713 |
cmdir 2 2 |
| 714 |
do 71 i = 1, nx |
| 715 |
ii = 2 * i - 1 |
| 716 |
gzc(i,j,1) = gzcf(ii,jj,1) |
| 717 |
gzc(i,j,2) = gzcf(ii,jj,2) |
| 718 |
gzc(i,j,3) = gzcf(ii,jj,3) |
| 719 |
gzc(i,j,4) = gzcf(ii,jj,4) |
| 720 |
71 continue |
| 721 |
70 continue |
| 722 |
c* |
| 723 |
c* *** return and end *** |
| 724 |
return |
| 725 |
end |
| 726 |
subroutine buildharm0 (nx,ny,nz,nxf,nyf,nzf, |
| 727 |
2 xc,yc,zc,gxc,gyc,gzc,a1c,a2c,a3c,cc,fc,tc, |
| 728 |
3 xf,yf,zf,gxcf,gycf,gzcf,a1cf,a2cf,a3cf,ccf,fcf,tcf) |
| 729 |
c* ********************************************************************* |
| 730 |
c* purpose: |
| 731 |
c* |
| 732 |
c* produce information for a coarser grid. |
| 733 |
c* but also harmonically average the problem coefficients. |
| 734 |
c* |
| 735 |
c* author: michael holst |
| 736 |
c* ********************************************************************* |
| 737 |
implicit none |
| 738 |
integer nxf,nyf,nzf,nx,ny,nz,i,j,k,ii,jj,kk |
| 739 |
integer iadd,jadd,kadd |
| 740 |
double precision xc(nx),yc(ny),zc(nz) |
| 741 |
double precision gxc(ny,nz,*),gyc(nx,nz,*),gzc(nx,ny,*) |
| 742 |
double precision a1c(nx,ny,nz),a2c(nx,ny,nz),a3c(nx,ny,nz) |
| 743 |
double precision cc(nx,ny,nz),fc(nx,ny,nz),tc(nx,ny,nz) |
| 744 |
double precision xf(nxf),yf(nyf),zf(nzf) |
| 745 |
double precision gxcf(nyf,nzf,*),gycf(nxf,nzf,*),gzcf(nxf,nyf,*) |
| 746 |
double precision a1cf(nxf,nyf,nzf),a2cf(nxf,nyf,nzf) |
| 747 |
double precision a3cf(nxf,nyf,nzf),tcf(nxf,nyf,nzf) |
| 748 |
double precision ccf(nxf,nyf,nzf),fcf(nxf,nyf,nzf) |
| 749 |
c* |
| 750 |
c* *** statement functions *** |
| 751 |
double precision harmo2,harmo4,arith2,arith4,arith6,arith8 |
| 752 |
double precision a,b,c,d,e,f,g,h |
| 753 |
harmo2(a,b) = 2. * a * b / (a + b) |
| 754 |
harmo4(a,b,c,d) = 1. / ( 0.25 * ( 1./a + 1./b + 1./c + 1./d ) ) |
| 755 |
arith2(a,b) = (a+b) / 2. |
| 756 |
arith4(a,b,c,d) = (a+b+c+d) / 4. |
| 757 |
arith6(a,b,c,d,e,f) = (a+b+c+d+e+f) / 6. |
| 758 |
arith8(a,b,c,d,e,f,g,h) = (a+b+c+d+e+f+g+h) / 8. |
| 759 |
c* |
| 760 |
cmdir 0 0 |
| 761 |
c* |
| 762 |
c* *** how far to step into the coefficient arrays *** |
| 763 |
iadd = (nxf-1)/(nx-1) |
| 764 |
jadd = (nyf-1)/(ny-1) |
| 765 |
kadd = (nzf-1)/(nz-1) |
| 766 |
if ((iadd.ne.2).or.(jadd.ne.2).or.(kadd.ne.2)) then |
| 767 |
print*,'% BUILDHARM0: problem with grid dimensions...' |
| 768 |
endif |
| 769 |
c* |
| 770 |
c* *** compute the coarse grid pde coefficients *** |
| 771 |
cmdir 3 1 |
| 772 |
do 30 k = 1, nz |
| 773 |
kk = 2 * k - 1 |
| 774 |
zc(k) = zf(kk) |
| 775 |
cmdir 3 2 |
| 776 |
do 31 j = 1, ny |
| 777 |
jj = 2 * j - 1 |
| 778 |
yc(j) = yf(jj) |
| 779 |
cmdir 3 3 |
| 780 |
do 32 i = 1, nx |
| 781 |
ii = 2 * i - 1 |
| 782 |
xc(i) = xf(ii) |
| 783 |
c* |
| 784 |
c* *** true solution *** |
| 785 |
tc(i,j,k) = tcf(ii,jj,kk) |
| 786 |
c* |
| 787 |
c* *** helmholtz coefficient *** |
| 788 |
cc(i,j,k) = ccf(ii,jj,kk) |
| 789 |
CZZZ cc(i,j,k) = ( |
| 790 |
CZZZ 2 +0.5e0 * ccf(ii,jj,kk) |
| 791 |
CZZZ 3 +0.5e0 * arith6( ccf(max0(1,ii-1),jj,kk), |
| 792 |
CZZZ 4 ccf(min0(nxf,ii+1),jj,kk), |
| 793 |
CZZZ 5 ccf(ii,max0(1,jj-1),kk), |
| 794 |
CZZZ 6 ccf(ii,min0(nyf,jj+1),kk), |
| 795 |
CZZZ 7 ccf(ii,jj,max0(nzf,kk-1)), |
| 796 |
CZZZ 8 ccf(ii,jj,min0(nzf,kk+1)) ) |
| 797 |
CZZZ 9 ) |
| 798 |
c* |
| 799 |
c* *** source function *** |
| 800 |
fc(i,j,k) = fcf(ii,jj,kk) |
| 801 |
CZZZ fc(i,j,k) = ( |
| 802 |
CZZZ 2 +0.5e0 * fcf(ii,jj,kk) |
| 803 |
CZZZ 3 +0.5e0 * arith6( fcf(max0(1,ii-1),jj,kk), |
| 804 |
CZZZ 4 fcf(min0(nxf,ii+1),jj,kk), |
| 805 |
CZZZ 5 fcf(ii,max0(1,jj-1),kk), |
| 806 |
CZZZ 6 fcf(ii,min0(nyf,jj+1),kk), |
| 807 |
CZZZ 7 fcf(ii,jj,max0(nzf,kk-1)), |
| 808 |
CZZZ 8 fcf(ii,jj,min0(nzf,kk+1)) ) |
| 809 |
CZZZ 9 ) |
| 810 |
c* |
| 811 |
c* *** east/west neighbor *** |
| 812 |
a1c(i,j,k) = ( |
| 813 |
2 +0.5e0 *harmo2( a1cf(ii,jj,kk), |
| 814 |
2 a1cf(min0(nxf,ii+1),jj,kk) ) |
| 815 |
3 +0.125e0*harmo2( a1cf(ii,jj,max0(1,kk-1)), |
| 816 |
3 a1cf(min0(nxf,ii+1),jj,max0(1,kk-1)) ) |
| 817 |
4 +0.125e0*harmo2( a1cf(ii,jj,min0(nzf,kk+1)), |
| 818 |
4 a1cf(min0(nxf,ii+1),jj,min0(nzf,kk+1)) ) |
| 819 |
5 +0.125e0*harmo2( a1cf(ii,max0(1,jj-1),kk), |
| 820 |
5 a1cf(min0(nxf,ii+1),max0(1,jj-1),kk) ) |
| 821 |
6 +0.125e0*harmo2( a1cf(ii,min0(nyf,jj+1),kk), |
| 822 |
6 a1cf(min0(nxf,ii+1),min0(nyf,jj+1),kk) ) |
| 823 |
7 ) |
| 824 |
c* |
| 825 |
c* *** north/south neighbor *** |
| 826 |
a2c(i,j,k) = ( |
| 827 |
2 +0.5e0 *harmo2( a2cf(ii,jj,kk), |
| 828 |
2 a2cf(ii,min0(nyf,jj+1),kk) ) |
| 829 |
3 +0.125e0*harmo2( a2cf(ii,jj,max0(1,kk-1)), |
| 830 |
3 a2cf(ii,min0(nyf,jj+1),max0(1,kk-1)) ) |
| 831 |
4 +0.125e0*harmo2( a2cf(ii,jj,min0(nzf,kk+1)), |
| 832 |
4 a2cf(ii,min0(nyf,jj+1),min0(nzf,kk+1)) ) |
| 833 |
5 +0.125e0*harmo2( a2cf(max0(1,ii-1),jj,kk), |
| 834 |
5 a2cf(max0(1,ii-1),min0(nyf,jj+1),kk) ) |
| 835 |
6 +0.125e0*harmo2( a2cf(min0(nxf,ii+1),jj,kk), |
| 836 |
6 a2cf(min0(nxf,ii+1),min0(nyf,jj+1),kk) ) |
| 837 |
7 ) |
| 838 |
c* |
| 839 |
c* *** up/down neighbor *** |
| 840 |
a3c(i,j,k) = ( |
| 841 |
2 +0.5e0 *harmo2( a3cf(ii,jj,kk), |
| 842 |
2 a3cf(ii,jj,min0(nzf,kk+1)) ) |
| 843 |
3 +0.125e0*harmo2( a3cf(ii,max0(1,jj-1),kk), |
| 844 |
3 a3cf(ii,max0(1,jj-1),min0(nzf,kk+1)) ) |
| 845 |
4 +0.125e0*harmo2( a3cf(ii,min0(nyf,jj+1),kk), |
| 846 |
4 a3cf(ii,min0(nyf,jj+1),min0(nzf,kk+1)) ) |
| 847 |
5 +0.125e0*harmo2( a3cf(max0(1,ii-1),jj,kk), |
| 848 |
5 a3cf(max0(1,ii-1),jj,min0(nzf,kk+1)) ) |
| 849 |
6 +0.125e0*harmo2( a3cf(min0(nxf,ii+1),jj,kk), |
| 850 |
6 a3cf(min0(nxf,ii+1),jj,min0(nzf,kk+1)) ) |
| 851 |
7 ) |
| 852 |
32 continue |
| 853 |
31 continue |
| 854 |
30 continue |
| 855 |
c* |
| 856 |
c* *** the (i=1) and (i=nx) boundaries *** |
| 857 |
cmdir 2 1 |
| 858 |
do 50 k = 1, nz |
| 859 |
kk = 2 * k - 1 |
| 860 |
cmdir 2 2 |
| 861 |
do 51 j = 1, ny |
| 862 |
jj = 2 * j - 1 |
| 863 |
gxc(j,k,1) = gxcf(jj,kk,1) |
| 864 |
gxc(j,k,2) = gxcf(jj,kk,2) |
| 865 |
gxc(j,k,3) = gxcf(jj,kk,3) |
| 866 |
gxc(j,k,4) = gxcf(jj,kk,4) |
| 867 |
51 continue |
| 868 |
50 continue |
| 869 |
c* |
| 870 |
c* *** the (j=1) and (j=ny) boundaries *** |
| 871 |
cmdir 2 1 |
| 872 |
do 60 k = 1, nz |
| 873 |
kk = 2 * k - 1 |
| 874 |
cmdir 2 2 |
| 875 |
do 61 i = 1, nx |
| 876 |
ii = 2 * i - 1 |
| 877 |
gyc(i,k,1) = gycf(ii,kk,1) |
| 878 |
gyc(i,k,2) = gycf(ii,kk,2) |
| 879 |
gyc(i,k,3) = gycf(ii,kk,3) |
| 880 |
gyc(i,k,4) = gycf(ii,kk,4) |
| 881 |
61 continue |
| 882 |
60 continue |
| 883 |
c* |
| 884 |
c* *** the (k=1) and (k=nz) boundaries *** |
| 885 |
cmdir 2 1 |
| 886 |
do 70 j = 1, ny |
| 887 |
jj = 2 * j - 1 |
| 888 |
cmdir 2 2 |
| 889 |
do 71 i = 1, nx |
| 890 |
ii = 2 * i - 1 |
| 891 |
gzc(i,j,1) = gzcf(ii,jj,1) |
| 892 |
gzc(i,j,2) = gzcf(ii,jj,2) |
| 893 |
gzc(i,j,3) = gzcf(ii,jj,3) |
| 894 |
gzc(i,j,4) = gzcf(ii,jj,4) |
| 895 |
71 continue |
| 896 |
70 continue |
| 897 |
c* |
| 898 |
c* *** return and end *** |
| 899 |
return |
| 900 |
end |
| 901 |
subroutine buildgaler0 (nxf,nyf,nzf,nxc,nyc,nzc,ipkey,numdia, |
| 902 |
2 pcFF, |
| 903 |
3 ipcFF,rpcFF,acFF,ccFF,fcFF, |
| 904 |
4 ipc,rpc,ac,cc,fc) |
| 905 |
c* ********************************************************************* |
| 906 |
c* purpose: |
| 907 |
c* |
| 908 |
c* form the galerkin coarse grid system. |
| 909 |
c* |
| 910 |
c* notes: although the fine grid matrix may be 7 or 27 diagonal, |
| 911 |
c* the coarse grid matrix is always 27 diagonal. |
| 912 |
c* (only 14 stored due to symmetry.) |
| 913 |
c* |
| 914 |
c* author: michael holst |
| 915 |
c* ********************************************************************* |
| 916 |
implicit none |
| 917 |
integer ipcFF(*),ipc(*),nxf,nyf,nzf,nxc,nyc,nzc,ipkey |
| 918 |
integer numdia,numdia_loc |
| 919 |
double precision pcFF(*),rpcFF(*),acFF(*),ccFF(*),fcFF(*) |
| 920 |
double precision rpc(*),ac(*),cc(*),fc(*) |
| 921 |
c* |
| 922 |
cmdir 0 0 |
| 923 |
c* |
| 924 |
c* *** call the algebraic galerkin routine *** |
| 925 |
numdia_loc = ipcFF(11) |
| 926 |
call buildG (nxf,nyf,nzf,nxc,nyc,nzc,numdia_loc,pcFF,acFF,ac) |
| 927 |
c* |
| 928 |
c* *** note how many nonzeros in this new discretization stencil *** |
| 929 |
ipc(11) = 27 |
| 930 |
numdia = 14 |
| 931 |
c* |
| 932 |
c* *** save the problem key with this new operator *** |
| 933 |
ipc(10) = ipkey |
| 934 |
c* |
| 935 |
c* *** restrict the helmholtz term and source function *** |
| 936 |
call restrc(nxf,nyf,nzf,nxc,nyc,nzc,ccFF,cc,pcFF) |
| 937 |
call restrc(nxf,nyf,nzf,nxc,nyc,nzc,fcFF,fc,pcFF) |
| 938 |
c* |
| 939 |
c* *** return and end *** |
| 940 |
return |
| 941 |
end |
| 942 |
subroutine buildgaler1 (nxf,nyf,nzf,nxc,nyc,nzc,numdia, |
| 943 |
2 pcFF, |
| 944 |
3 ipcFF,rpcFF,ccFF, |
| 945 |
4 ipc,rpc,cc) |
| 946 |
c* ********************************************************************* |
| 947 |
c* purpose: |
| 948 |
c* |
| 949 |
c* form the helmholtz term of a galerkin coarse grid system. |
| 950 |
c* |
| 951 |
c* notes: although the fine grid matrix may be 1 or 27 diagonal, |
| 952 |
c* the coarse grid matrix is always 27 diagonal. |
| 953 |
c* (only 14 stored due to symmetry.) |
| 954 |
c* |
| 955 |
c* author: michael holst |
| 956 |
c* ********************************************************************* |
| 957 |
implicit none |
| 958 |
integer ipcFF(*),ipc(*),nxf,nyf,nzf,nxc,nyc,nzc,numdia |
| 959 |
integer numdia_loc |
| 960 |
double precision pcFF(*),rpcFF(*),ccFF(*),rpc(*),cc(*) |
| 961 |
c* |
| 962 |
cmdir 0 0 |
| 963 |
c* |
| 964 |
c* *** call the algebraic galerkin routine *** |
| 965 |
numdia_loc = ipcFF(12) |
| 966 |
call buildG (nxf,nyf,nzf,nxc,nyc,nzc,numdia_loc,pcFF,ccFF,cc) |
| 967 |
c* |
| 968 |
c* *** note how many nonzeros in this new discretization stencil *** |
| 969 |
ipc(12) = 27 |
| 970 |
numdia = 14 |
| 971 |
c* |
| 972 |
c* *** return and end *** |
| 973 |
return |
| 974 |
end |
| 975 |
subroutine buildALG (nx,ny,nz,mode,nlev,iz, |
| 976 |
3 ipc,rpc,ac,cc,fc,x,y,tmp) |
| 977 |
c* ********************************************************************* |
| 978 |
c* purpose: |
| 979 |
c* |
| 980 |
c* build rhs algebraically for analysis purposes. |
| 981 |
c* |
| 982 |
c* note: the fine level must be build before any coarse levels. |
| 983 |
c* |
| 984 |
c* author: michael holst |
| 985 |
c* ********************************************************************* |
| 986 |
implicit none |
| 987 |
integer ipc(*),iz(50,*),nx,ny,nz,mode,nlev,lev |
| 988 |
integer nxx,nyy,nzz,nxold,nyold,nzold |
| 989 |
double precision rpc(*),ac(*),cc(*),fc(*),x(*),y(*),tmp(*) |
| 990 |
c* |
| 991 |
c* *** setup *** |
| 992 |
nxx = nx |
| 993 |
nyy = ny |
| 994 |
nzz = nz |
| 995 |
c* |
| 996 |
c* *** build the rhs the finest level *** |
| 997 |
lev = 1 |
| 998 |
if ((mode .eq. 1) .or. (mode .eq. 2)) then |
| 999 |
call nmatvec(nxx,nyy,nzz, |
| 1000 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 1001 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 1002 |
4 x(iz(1,lev)),y(iz(1,lev)),tmp) |
| 1003 |
else |
| 1004 |
call matvec(nxx,nyy,nzz, |
| 1005 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 1006 |
3 ac(iz(7,lev)),cc(iz(1,lev)), |
| 1007 |
4 x(iz(1,lev)),y(iz(1,lev))) |
| 1008 |
endif |
| 1009 |
c* |
| 1010 |
c* *** build the (nlev-1) level rhs function *** |
| 1011 |
do 10 lev = 2, nlev |
| 1012 |
nxold = nxx |
| 1013 |
nyold = nyy |
| 1014 |
nzold = nzz |
| 1015 |
call mkcors(1,nxold,nyold,nzold,nxx,nyy,nzz) |
| 1016 |
c* |
| 1017 |
c* *** build the rhs on this level *** |
| 1018 |
if ((mode .eq. 1) .or. (mode .eq. 2)) then |
| 1019 |
call nmatvec(nxx,nyy,nzz, |
| 1020 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 1021 |
3 ac(iz(7,lev)),cc(iz(1,lev)),fc(iz(1,lev)), |
| 1022 |
4 x(iz(1,lev)),y(iz(1,lev)),tmp) |
| 1023 |
else |
| 1024 |
call matvec(nxx,nyy,nzz, |
| 1025 |
2 ipc(iz(5,lev)),rpc(iz(6,lev)), |
| 1026 |
3 ac(iz(7,lev)),cc(iz(1,lev)), |
| 1027 |
4 x(iz(1,lev)),y(iz(1,lev))) |
| 1028 |
endif |
| 1029 |
10 continue |
| 1030 |
c* |
| 1031 |
c* *** end it *** |
| 1032 |
return |
| 1033 |
end |