| 1 |
c* /////////////////////////////////////////////////////////////////////////// |
| 2 |
c* @file sord.f |
| 3 |
c* @author Michael Holst |
| 4 |
c* @brief Successive Over-Relaxation iteration. |
| 5 |
c* @version $Id: sord.f,v 1.2 2010/08/12 05:45:41 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 sor(nx,ny,nz,ipc,rpc,ac,cc,fc,x,w1,w2,r, |
| 61 |
2 itmax,iters,errtol,omega,iresid,iadjoint) |
| 62 |
c* ********************************************************************* |
| 63 |
c* purpose: |
| 64 |
c* |
| 65 |
c* call the fast diagonal iterative method. |
| 66 |
c* |
| 67 |
c* author: michael holst |
| 68 |
c* ********************************************************************* |
| 69 |
implicit none |
| 70 |
integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz |
| 71 |
integer numdia |
| 72 |
double precision omega,errtol |
| 73 |
double precision rpc(*),ac(nx*ny*nz,*),cc(nx,ny,nz),fc(nx,ny,nz) |
| 74 |
double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz) |
| 75 |
double precision r(nx,ny,nz) |
| 76 |
c* |
| 77 |
cmdir 0 0 |
| 78 |
c* |
| 79 |
c* *** do in one step *** |
| 80 |
numdia = ipc(11) |
| 81 |
if (numdia .eq. 7) then |
| 82 |
call sor7(nx,ny,nz,ipc,rpc,ac(1,1),cc,fc, |
| 83 |
2 ac(1,2),ac(1,3),ac(1,4), |
| 84 |
3 x,w1,w2,r, |
| 85 |
4 itmax,iters,errtol,omega,iresid,iadjoint) |
| 86 |
elseif (numdia .eq. 27) then |
| 87 |
call sor27(nx,ny,nz,ipc,rpc,ac(1,1),cc,fc, |
| 88 |
2 ac(1,2),ac(1,3),ac(1,4),ac(1,5),ac(1,6),ac(1,7),ac(1,8), |
| 89 |
3 ac(1,9),ac(1,10),ac(1,11),ac(1,12),ac(1,13),ac(1,14), |
| 90 |
4 x,w1,w2,r, |
| 91 |
5 itmax,iters,errtol,omega,iresid,iadjoint) |
| 92 |
else |
| 93 |
print*,'% SOR: invalid stencil type given...' |
| 94 |
endif |
| 95 |
c* |
| 96 |
c* *** return and end *** |
| 97 |
return |
| 98 |
end |
| 99 |
subroutine sor7(nx,ny,nz,ipc,rpc, |
| 100 |
2 oC,cc,fc, |
| 101 |
3 oE,oN,uC, |
| 102 |
4 x,w1,w2,r, |
| 103 |
5 itmax,iters,errtol,omega,iresid,iadjoint) |
| 104 |
c* ********************************************************************* |
| 105 |
c* purpose: |
| 106 |
c* |
| 107 |
c* fast 7 diagonal red/black sor routine. |
| 108 |
c* |
| 109 |
c* note that the interior grid points from 2,...,nx-1, etc. |
| 110 |
c* we then begin coloring with a red point, and do a point red/black |
| 111 |
c* coloring. |
| 112 |
c* |
| 113 |
c* the red points are: |
| 114 |
c* |
| 115 |
c* if ((j even) and (k even)) then |
| 116 |
c* begin row at first point, i=2 (i even), or ioff = 0 |
| 117 |
c* else if ((j odd) and (k even)) then |
| 118 |
c* begin row at second point, i=3 (i odd), or ioff = 1 |
| 119 |
c* else if ((j even) and (k odd)) then |
| 120 |
c* begin row at second point, i=3 (i odd), or ioff = 1 |
| 121 |
c* else if ((j odd) and (k odd)) then |
| 122 |
c* begin row at first point, i=2 (i even), or ioff = 0 |
| 123 |
c* endif |
| 124 |
c* then: begin row at: i=2+ioff |
| 125 |
c* |
| 126 |
c* the appropriate ioff function for the red points is then: |
| 127 |
c* ioff = dabs(mod(j,2)-mod(k,2)) |
| 128 |
c* |
| 129 |
c* the appropriate ioff function for the black points is then: |
| 130 |
c* ioff = 1 - dabs(mod(j,2)-mod(k,2)) |
| 131 |
c* |
| 132 |
c* |
| 133 |
c* alternatively, the red points are: |
| 134 |
c* |
| 135 |
c* those whose indices add up to an even number. |
| 136 |
c* to see this, consider that all surrounding points are |
| 137 |
c* only one index different, hence the sum will differ by one. |
| 138 |
c* thus, if a given point has an even sum, then the surrounding |
| 139 |
c* points will have an odd sum. |
| 140 |
c* |
| 141 |
c* thus, the black points are: |
| 142 |
c* |
| 143 |
c* therefore those whose indices add up to an odd number. |
| 144 |
c* |
| 145 |
c* author: michael holst |
| 146 |
c* ********************************************************************* |
| 147 |
implicit none |
| 148 |
integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz |
| 149 |
integer i,j,k,ioff |
| 150 |
double precision omega,errtol,fac |
| 151 |
double precision rpc(*),oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz) |
| 152 |
double precision fc(nx,ny,nz),oC(nx,ny,nz),cc(nx,ny,nz) |
| 153 |
double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz) |
| 154 |
double precision r(nx,ny,nz) |
| 155 |
c* |
| 156 |
cmdir 0 0 |
| 157 |
c* |
| 158 |
c* *** do the gauss-seidel iteration itmax times *** |
| 159 |
fac = 1.0d0 - omega |
| 160 |
do 30 iters = 1, itmax |
| 161 |
c* |
| 162 |
c* *** do the red points *** |
| 163 |
cmdir 3 1 |
| 164 |
do 10 k=2,nz-1 |
| 165 |
cmdir 3 2 |
| 166 |
do 11 j=2,ny-1 |
| 167 |
ioff = mod((j+k+2),2) |
| 168 |
cmdir 3 3 |
| 169 |
do 12 i=2+ioff,nx-1, 2 |
| 170 |
x(i,j,k) = x(i,j,k)*fac + omega*(fc(i,j,k)+( |
| 171 |
2 + oN(i,j,k) * x(i,j+1,k) |
| 172 |
3 + oN(i,j-1,k) * x(i,j-1,k) |
| 173 |
4 + oE(i,j,k) * x(i+1,j,k) |
| 174 |
5 + oE(i-1,j,k) * x(i-1,j,k) |
| 175 |
6 + uC(i,j,k-1) * x(i,j,k-1) |
| 176 |
7 + uC(i,j,k) * x(i,j,k+1) |
| 177 |
8 )) / (oC(i,j,k) + cc(i,j,k)) |
| 178 |
12 continue |
| 179 |
11 continue |
| 180 |
10 continue |
| 181 |
c* |
| 182 |
c* *** do the black points *** |
| 183 |
cmdir 3 1 |
| 184 |
do 20 k=2,nz-1 |
| 185 |
cmdir 3 2 |
| 186 |
do 21 j=2,ny-1 |
| 187 |
ioff = 1 - mod((j+k+2),2) |
| 188 |
cmdir 3 3 |
| 189 |
do 22 i=2+ioff,nx-1, 2 |
| 190 |
x(i,j,k) = x(i,j,k)*fac + omega*(fc(i,j,k)+( |
| 191 |
2 + oN(i,j,k) * x(i,j+1,k) |
| 192 |
3 + oN(i,j-1,k) * x(i,j-1,k) |
| 193 |
4 + oE(i,j,k) * x(i+1,j,k) |
| 194 |
5 + oE(i-1,j,k) * x(i-1,j,k) |
| 195 |
6 + uC(i,j,k-1) * x(i,j,k-1) |
| 196 |
7 + uC(i,j,k) * x(i,j,k+1) |
| 197 |
8 )) / (oC(i,j,k) + cc(i,j,k)) |
| 198 |
22 continue |
| 199 |
21 continue |
| 200 |
20 continue |
| 201 |
c* |
| 202 |
c* *** main loop *** |
| 203 |
30 continue |
| 204 |
c* |
| 205 |
c* *** if specified, return the new residual as well *** |
| 206 |
if (iresid .eq. 1) then |
| 207 |
call mresid7_1s(nx,ny,nz,ipc,rpc,oC,cc,fc,oE,oN,uC,x,r) |
| 208 |
endif |
| 209 |
c* |
| 210 |
c* *** return and end *** |
| 211 |
return |
| 212 |
end |
| 213 |
subroutine sor27(nx,ny,nz,ipc,rpc, |
| 214 |
2 oC,cc,fc, |
| 215 |
3 oE,oN,uC,oNE,oNW,uE,uW,uN,uS,uNE,uNW,uSE,uSW, |
| 216 |
4 x,w1,w2,r, |
| 217 |
5 itmax,iters,errtol,omega,iresid,iadjoint) |
| 218 |
c* ********************************************************************* |
| 219 |
c* purpose: |
| 220 |
c* |
| 221 |
c* 27 diagonal sor routine. |
| 222 |
c* |
| 223 |
c* author: michael holst |
| 224 |
c* ********************************************************************* |
| 225 |
implicit none |
| 226 |
integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz |
| 227 |
integer i,j,k |
| 228 |
double precision omega,errtol,fac |
| 229 |
double precision rpc(*),oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz) |
| 230 |
double precision oNE(nx,ny,nz),oNW(nx,ny,nz),uE(nx,ny,nz) |
| 231 |
double precision uW(nx,ny,nz),uN(nx,ny,nz),uS(nx,ny,nz) |
| 232 |
double precision uNE(nx,ny,nz),uNW(nx,ny,nz),uSE(nx,ny,nz) |
| 233 |
double precision uSW(nx,ny,nz) |
| 234 |
double precision fc(nx,ny,nz),oC(nx,ny,nz),cc(nx,ny,nz) |
| 235 |
double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz) |
| 236 |
double precision r(nx,ny,nz) |
| 237 |
double precision tmpO,tmpU,tmpD |
| 238 |
c* |
| 239 |
cmdir 0 0 |
| 240 |
c* |
| 241 |
c* *** do the gauss-seidel iteration itmax times *** |
| 242 |
fac = 1.0d0 - omega |
| 243 |
do 30 iters = 1, itmax |
| 244 |
c* |
| 245 |
c* *** do all of the points *** |
| 246 |
cmdir 3 1 |
| 247 |
do 10 k=2,nz-1 |
| 248 |
cmdir 3 2 |
| 249 |
do 11 j=2,ny-1 |
| 250 |
cmdir 3 3 |
| 251 |
do 12 i=2,nx-1 |
| 252 |
tmpO = |
| 253 |
2 + oN(i,j,k) * x(i,j+1,k) |
| 254 |
3 + oN(i,j-1,k) * x(i,j-1,k) |
| 255 |
4 + oE(i,j,k) * x(i+1,j,k) |
| 256 |
5 + oE(i-1,j,k) * x(i-1,j,k) |
| 257 |
6 + oNE(i,j,k) * x(i+1,j+1,k) |
| 258 |
7 + oNW(i,j,k) * x(i-1,j+1,k) |
| 259 |
8 + oNW(i+1,j-1,k) * x(i+1,j-1,k) |
| 260 |
9 + oNE(i-1,j-1,k) * x(i-1,j-1,k) |
| 261 |
tmpU = |
| 262 |
2 + uC(i,j,k) * x(i,j,k+1) |
| 263 |
3 + uN(i,j,k) * x(i,j+1,k+1) |
| 264 |
4 + uS(i,j,k) * x(i,j-1,k+1) |
| 265 |
5 + uE(i,j,k) * x(i+1,j,k+1) |
| 266 |
6 + uW(i,j,k) * x(i-1,j,k+1) |
| 267 |
7 + uNE(i,j,k) * x(i+1,j+1,k+1) |
| 268 |
8 + uNW(i,j,k) * x(i-1,j+1,k+1) |
| 269 |
9 + uSE(i,j,k) * x(i+1,j-1,k+1) |
| 270 |
9 + uSW(i,j,k) * x(i-1,j-1,k+1) |
| 271 |
tmpD = |
| 272 |
2 + uC(i,j,k-1) * x(i,j,k-1) |
| 273 |
3 + uS(i,j+1,k-1) * x(i,j+1,k-1) |
| 274 |
4 + uN(i,j-1,k-1) * x(i,j-1,k-1) |
| 275 |
5 + uW(i+1,j,k-1) * x(i+1,j,k-1) |
| 276 |
6 + uE(i-1,j,k-1) * x(i-1,j,k-1) |
| 277 |
7 + uSW(i+1,j+1,k-1) * x(i+1,j+1,k-1) |
| 278 |
8 + uSE(i-1,j+1,k-1) * x(i-1,j+1,k-1) |
| 279 |
9 + uNW(i+1,j-1,k-1) * x(i+1,j-1,k-1) |
| 280 |
9 + uNE(i-1,j-1,k-1) * x(i-1,j-1,k-1) |
| 281 |
x(i,j,k) = x(i,j,k)*fac + omega*(fc(i,j,k)+( |
| 282 |
9 + tmpO + tmpU + tmpD |
| 283 |
9 )) / (oC(i,j,k) + cc(i,j,k)) |
| 284 |
12 continue |
| 285 |
11 continue |
| 286 |
10 continue |
| 287 |
c* |
| 288 |
c* *** main loop *** |
| 289 |
30 continue |
| 290 |
c* |
| 291 |
c* *** if specified, return the new residual as well *** |
| 292 |
if (iresid .eq. 1) then |
| 293 |
call mresid27_1s(nx,ny,nz,ipc,rpc,oC,cc,fc, |
| 294 |
2 oE,oN,uC,oNE,oNW,uE,uW,uN,uS,uNE,uNW,uSE,uSW, |
| 295 |
3 x,r) |
| 296 |
endif |
| 297 |
c* |
| 298 |
c* *** return and end *** |
| 299 |
return |
| 300 |
end |
| 301 |
|