Debian Codegraph @

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

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file wjd.f
3 c* @author Michael Holst
4 c* @brief Weighted Jacobi iteration.
5 c* @version $Id: wjd.f,v 1.2 2010/08/12 05:45:42 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 wjac(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 wjac7(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 wjac27(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*,'% WJAC: invalid stencil type given...'
94 endif
95 c*
96 c* *** return and end ***
97 return
98 end
99 subroutine wjac7(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 weighted jacobi routine.
108 c*
109 c* author: michael holst
110 c* *********************************************************************
111 implicit none
112 integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz
113 integer i,j,k
114 double precision omega,errtol,fac
115 double precision rpc(*),oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz)
116 double precision fc(nx,ny,nz),oC(nx,ny,nz),cc(nx,ny,nz)
117 double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz)
118 double precision r(nx,ny,nz)
119 c*
120 cmdir 0 0
121 c*
122 c* *** do the jacobi iteration itmax times ***
123 do 30 iters = 1, itmax
124 c*
125 c* *** do it ***
126 cmdir 3 1
127 do 10 k=2,nz-1
128 cmdir 3 2
129 do 11 j=2,ny-1
130 cmdir 3 3
131 do 12 i=2,nx-1
132 w1(i,j,k) = (fc(i,j,k)+(
133 2 + oN(i,j,k) * x(i,j+1,k)
134 3 + oN(i,j-1,k) * x(i,j-1,k)
135 4 + oE(i,j,k) * x(i+1,j,k)
136 5 + oE(i-1,j,k) * x(i-1,j,k)
137 6 + uC(i,j,k-1) * x(i,j,k-1)
138 7 + uC(i,j,k) * x(i,j,k+1)
139 8 )) / (oC(i,j,k) + cc(i,j,k))
140 12 continue
141 11 continue
142 10 continue
143 c*
144 c* *** copy temp back to solution, with over-relaxation ***
145 fac = 1.0d0 - omega
146 cmdir 3 1
147 do 20 k=2,nz-1
148 cmdir 3 2
149 do 21 j=2,ny-1
150 cmdir 3 3
151 do 22 i=2,nx-1
152 x(i,j,k) = omega*w1(i,j,k) + fac*x(i,j,k)
153 22 continue
154 21 continue
155 20 continue
156 c*
157 c* *** main loop ***
158 30 continue
159 c*
160 c* *** if specified, return the new residual as well ***
161 if (iresid .eq. 1) then
162 call mresid7_1s(nx,ny,nz,ipc,rpc,oC,cc,fc,oE,oN,uC,x,r)
163 endif
164 c*
165 c* *** return and end ***
166 return
167 end
168 subroutine wjac27(nx,ny,nz,ipc,rpc,
169 2 oC,cc,fc,
170 3 oE,oN,uC,oNE,oNW,uE,uW,uN,uS,uNE,uNW,uSE,uSW,
171 4 x,w1,w2,r,
172 5 itmax,iters,errtol,omega,iresid,iadjoint)
173 c* *********************************************************************
174 c* purpose:
175 c*
176 c* fast 27 diagonal weighted jacobi routine.
177 c*
178 c* author: michael holst
179 c* *********************************************************************
180 implicit none
181 integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz
182 integer i,j,k
183 double precision omega,errtol,fac
184 double precision rpc(*),oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz)
185 double precision oNE(nx,ny,nz),oNW(nx,ny,nz),uE(nx,ny,nz)
186 double precision uW(nx,ny,nz),uN(nx,ny,nz),uS(nx,ny,nz)
187 double precision uNE(nx,ny,nz),uNW(nx,ny,nz),uSE(nx,ny,nz)
188 double precision uSW(nx,ny,nz)
189 double precision fc(nx,ny,nz),oC(nx,ny,nz),cc(nx,ny,nz)
190 double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz)
191 double precision r(nx,ny,nz)
192 double precision tmpO,tmpU,tmpD
193 c*
194 cmdir 0 0
195 c*
196 c* *** do the gauss-seidel iteration itmax times ***
197 do 30 iters = 1, itmax
198 c*
199 c* *** do all of the points ***
200 cmdir 3 1
201 do 10 k=2,nz-1
202 cmdir 3 2
203 do 11 j=2,ny-1
204 cmdir 3 3
205 do 12 i=2,nx-1
206 tmpO =
207 2 + oN(i,j,k) * x(i,j+1,k)
208 3 + oN(i,j-1,k) * x(i,j-1,k)
209 4 + oE(i,j,k) * x(i+1,j,k)
210 5 + oE(i-1,j,k) * x(i-1,j,k)
211 6 + oNE(i,j,k) * x(i+1,j+1,k)
212 7 + oNW(i,j,k) * x(i-1,j+1,k)
213 8 + oNW(i+1,j-1,k) * x(i+1,j-1,k)
214 9 + oNE(i-1,j-1,k) * x(i-1,j-1,k)
215 tmpU =
216 2 + uC(i,j,k) * x(i,j,k+1)
217 3 + uN(i,j,k) * x(i,j+1,k+1)
218 4 + uS(i,j,k) * x(i,j-1,k+1)
219 5 + uE(i,j,k) * x(i+1,j,k+1)
220 6 + uW(i,j,k) * x(i-1,j,k+1)
221 7 + uNE(i,j,k) * x(i+1,j+1,k+1)
222 8 + uNW(i,j,k) * x(i-1,j+1,k+1)
223 9 + uSE(i,j,k) * x(i+1,j-1,k+1)
224 9 + uSW(i,j,k) * x(i-1,j-1,k+1)
225 tmpD =
226 2 + uC(i,j,k-1) * x(i,j,k-1)
227 3 + uS(i,j+1,k-1) * x(i,j+1,k-1)
228 4 + uN(i,j-1,k-1) * x(i,j-1,k-1)
229 5 + uW(i+1,j,k-1) * x(i+1,j,k-1)
230 6 + uE(i-1,j,k-1) * x(i-1,j,k-1)
231 7 + uSW(i+1,j+1,k-1) * x(i+1,j+1,k-1)
232 8 + uSE(i-1,j+1,k-1) * x(i-1,j+1,k-1)
233 9 + uNW(i+1,j-1,k-1) * x(i+1,j-1,k-1)
234 9 + uNE(i-1,j-1,k-1) * x(i-1,j-1,k-1)
235 w1(i,j,k) = (fc(i,j,k)+(tmpO + tmpU + tmpD
236 9 )) / (oC(i,j,k) + cc(i,j,k))
237 12 continue
238 11 continue
239 10 continue
240 c*
241 c* *** copy temp back to solution, with over-relaxation ***
242 fac = 1.0d0 - omega
243 cmdir 3 1
244 do 20 k=2,nz-1
245 cmdir 3 2
246 do 21 j=2,ny-1
247 cmdir 3 3
248 do 22 i=2,nx-1
249 x(i,j,k) = omega*w1(i,j,k) + fac*x(i,j,k)
250 22 continue
251 21 continue
252 20 continue
253 c*
254 c* *** main loop ***
255 30 continue
256 c*
257 c* *** if specified, return the new residual as well ***
258 if (iresid .eq. 1) then
259 call mresid27_1s(nx,ny,nz,ipc,rpc,oC,cc,fc,
260 2 oE,oN,uC,oNE,oNW,uE,uW,uN,uS,uNE,uNW,uSE,uSW,
261 3 x,r)
262 endif
263 c*
264 c* *** return and end ***
265 return
266 end
267