Debian Codegraph @

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

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file gsd.f
3 c* @author Michael Holst
4 c* @brief Gauss-Seidel iteration.
5 c* @version $Id: gsd.f,v 1.2 2010/08/12 05:45:32 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 gsrb(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),r(nx,ny,nz)
75 c*
76 cmdir 0 0
77 c*
78 c* *** do in one step ***
79 numdia = ipc(11)
80 if (numdia .eq. 7) then
81 call gsrb7(nx,ny,nz,ipc,rpc,ac(1,1),cc,fc,
82 2 ac(1,2),ac(1,3),ac(1,4),
83 3 x,w1,w2,r,
84 4 itmax,iters,errtol,omega,iresid,iadjoint)
85 elseif (numdia .eq. 27) then
86 call gsrb27(nx,ny,nz,ipc,rpc,ac(1,1),cc,fc,
87 2 ac(1,2),ac(1,3),ac(1,4),ac(1,5),ac(1,6),ac(1,7),ac(1,8),
88 3 ac(1,9),ac(1,10),ac(1,11),ac(1,12),ac(1,13),ac(1,14),
89 4 x,w1,w2,r,
90 4 itmax,iters,errtol,omega,iresid,iadjoint)
91 else
92 print*,'% GSRB: invalid stencil type given...'
93 endif
94 c*
95 c* *** return and end ***
96 return
97 end
98 subroutine gsrb7(nx,ny,nz,ipc,rpc,
99 2 oC,cc,fc,
100 3 oE,oN,uC,
101 4 x,w1,w2,r,
102 5 itmax,iters,errtol,omega,iresid,iadjoint)
103 c* *********************************************************************
104 c* purpose:
105 c*
106 c* 7 diagonal gauss-seidel routine.
107 c*
108 c* this routine applies the gauss-seidel operator or its
109 c* adjoint depending on the flag iadjoint.
110 c*
111 c* author: michael holst
112 c* *********************************************************************
113 implicit none
114 integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz
115 integer i,j,k,i1,i2,j1,j2,k1,k2,istep
116 double precision omega,errtol
117 double precision rpc(*),oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz)
118 double precision fc(nx,ny,nz),oC(nx,ny,nz),cc(nx,ny,nz)
119 double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz)
120 double precision r(nx,ny,nz)
121 c*
122 cmdir 0 0
123 c*
124 c* *** do the gauss-seidel iteration itmax times ***
125 i1 = (1-iadjoint) * 2 + iadjoint * (nx-1)
126 i2 = iadjoint * 2 + (1-iadjoint) * (nx-1)
127 j1 = (1-iadjoint) * 2 + iadjoint * (ny-1)
128 j2 = iadjoint * 2 + (1-iadjoint) * (ny-1)
129 k1 = (1-iadjoint) * 2 + iadjoint * (nz-1)
130 k2 = iadjoint * 2 + (1-iadjoint) * (nz-1)
131 istep = iadjoint*(-1) + (1-iadjoint)*(1)
132 do 30 iters = 1, itmax
133 c*
134 c* *** do the red points ***
135 cmdir 3 1
136 do 10 k=k1,k2,istep
137 cmdir 3 2
138 do 11 j=j1,j2,istep
139 cmdir 3 3
140 do 12 i=i1,i2,istep
141 x(i,j,k) = (fc(i,j,k)+(
142 2 + oN(i,j,k) * x(i,j+1,k)
143 3 + oN(i,j-1,k) * x(i,j-1,k)
144 4 + oE(i,j,k) * x(i+1,j,k)
145 5 + oE(i-1,j,k) * x(i-1,j,k)
146 6 + uC(i,j,k-1) * x(i,j,k-1)
147 7 + uC(i,j,k) * x(i,j,k+1)
148 8 )) / (oC(i,j,k) + cc(i,j,k))
149 12 continue
150 11 continue
151 10 continue
152 c*
153 c* *** main loop ***
154 30 continue
155 c*
156 c* *** if specified, return the new residual as well ***
157 if (iresid .eq. 1) then
158 call mresid7_1s(nx,ny,nz,ipc,rpc,oC,cc,fc,oE,oN,uC,x,r)
159 endif
160 c*
161 c* *** return and end ***
162 return
163 end
164 subroutine gsrb27(nx,ny,nz,ipc,rpc,
165 2 oC,cc,fc,
166 3 oE,oN,uC,oNE,oNW,uE,uW,uN,uS,uNE,uNW,uSE,uSW,
167 4 x,w1,w2,r,
168 5 itmax,iters,errtol,omega,iresid,iadjoint)
169 c* *********************************************************************
170 c* purpose:
171 c*
172 c* 27 diagonal gauss-seidel routine.
173 c*
174 c* this routine applies the gauss-seidel operator or its
175 c* adjoint depending on the flag iadjoint.
176 c*
177 c* author: michael holst
178 c* *********************************************************************
179 implicit none
180 integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz
181 integer i,j,k,i1,i2,j1,j2,k1,k2,istep
182 double precision omega,errtol
183 double precision rpc(*),oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz)
184 double precision oNE(nx,ny,nz),oNW(nx,ny,nz),uE(nx,ny,nz)
185 double precision uW(nx,ny,nz),uN(nx,ny,nz),uS(nx,ny,nz)
186 double precision uNE(nx,ny,nz),uNW(nx,ny,nz),uSE(nx,ny,nz)
187 double precision uSW(nx,ny,nz)
188 double precision fc(nx,ny,nz),oC(nx,ny,nz),cc(nx,ny,nz)
189 double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz)
190 double precision r(nx,ny,nz)
191 double precision tmpO,tmpU,tmpD
192 c*
193 cmdir 0 0
194 c*
195 c* *** do the gauss-seidel iteration itmax times ***
196 i1 = (1-iadjoint) * 2 + iadjoint * (nx-1)
197 i2 = iadjoint * 2 + (1-iadjoint) * (nx-1)
198 j1 = (1-iadjoint) * 2 + iadjoint * (ny-1)
199 j2 = iadjoint * 2 + (1-iadjoint) * (ny-1)
200 k1 = (1-iadjoint) * 2 + iadjoint * (nz-1)
201 k2 = iadjoint * 2 + (1-iadjoint) * (nz-1)
202 istep = iadjoint*(-1) + (1-iadjoint)*(1)
203 do 30 iters = 1, itmax
204 c*
205 c* *** do all of the points ***
206 cmdir 3 1
207 do 10 k=k1,k2,istep
208 cmdir 3 2
209 do 11 j=j1,j2,istep
210 cmdir 3 3
211 do 12 i=i1,i2,istep
212 tmpO =
213 2 + oN(i,j,k) * x(i,j+1,k)
214 3 + oN(i,j-1,k) * x(i,j-1,k)
215 4 + oE(i,j,k) * x(i+1,j,k)
216 5 + oE(i-1,j,k) * x(i-1,j,k)
217 6 + oNE(i,j,k) * x(i+1,j+1,k)
218 7 + oNW(i,j,k) * x(i-1,j+1,k)
219 8 + oNW(i+1,j-1,k) * x(i+1,j-1,k)
220 9 + oNE(i-1,j-1,k) * x(i-1,j-1,k)
221 tmpU =
222 2 + uC(i,j,k) * x(i,j,k+1)
223 3 + uN(i,j,k) * x(i,j+1,k+1)
224 4 + uS(i,j,k) * x(i,j-1,k+1)
225 5 + uE(i,j,k) * x(i+1,j,k+1)
226 6 + uW(i,j,k) * x(i-1,j,k+1)
227 7 + uNE(i,j,k) * x(i+1,j+1,k+1)
228 8 + uNW(i,j,k) * x(i-1,j+1,k+1)
229 9 + uSE(i,j,k) * x(i+1,j-1,k+1)
230 9 + uSW(i,j,k) * x(i-1,j-1,k+1)
231 tmpD =
232 2 + uC(i,j,k-1) * x(i,j,k-1)
233 3 + uS(i,j+1,k-1) * x(i,j+1,k-1)
234 4 + uN(i,j-1,k-1) * x(i,j-1,k-1)
235 5 + uW(i+1,j,k-1) * x(i+1,j,k-1)
236 6 + uE(i-1,j,k-1) * x(i-1,j,k-1)
237 7 + uSW(i+1,j+1,k-1) * x(i+1,j+1,k-1)
238 8 + uSE(i-1,j+1,k-1) * x(i-1,j+1,k-1)
239 9 + uNW(i+1,j-1,k-1) * x(i+1,j-1,k-1)
240 9 + uNE(i-1,j-1,k-1) * x(i-1,j-1,k-1)
241 x(i,j,k) = (fc(i,j,k)+(tmpO + tmpU + tmpD
242 9 )) / (oC(i,j,k) + cc(i,j,k))
243 12 continue
244 11 continue
245 10 continue
246 c*
247 c* *** main loop ***
248 30 continue
249 c*
250 c* *** if specified, return the new residual as well ***
251 if (iresid .eq. 1) then
252 call mresid27_1s(nx,ny,nz,ipc,rpc,oC,cc,fc,
253 2 oE,oN,uC,oNE,oNW,uE,uW,uN,uS,uNE,uNW,uSE,uSW,
254 3 x,r)
255 endif
256 c*
257 c* *** return and end ***
258 return
259 end
260 subroutine gsrb7X(nx,ny,nz,ipc,rpc,
261 2 oC,cc,fc,
262 3 oE,oN,uC,
263 4 x,w1,w2,r,
264 5 itmax,iters,errtol,omega,iresid,iadjoint)
265 c* *********************************************************************
266 c* purpose:
267 c*
268 c* fast 7 diagonal red/black gauss-seidel routine.
269 c*
270 c* this routine applies the red/black gauss-seidel operator or its
271 c* adjoint depending on the flag iadjoint. note that the adjoint
272 c* in this case is simply doing the red or black points first.
273 c*
274 c* note that the interior grid points from 2,...,nx-1, etc.
275 c* we then begin coloring with a red point, and do a point red/black
276 c* coloring.
277 c*
278 c* the red points are:
279 c*
280 c* if ((j even) and (k even)) then
281 c* begin row at first point, i=2 (i even), or ioff = 0
282 c* else if ((j odd) and (k even)) then
283 c* begin row at second point, i=3 (i odd), or ioff = 1
284 c* else if ((j even) and (k odd)) then
285 c* begin row at second point, i=3 (i odd), or ioff = 1
286 c* else if ((j odd) and (k odd)) then
287 c* begin row at first point, i=2 (i even), or ioff = 0
288 c* endif
289 c* then: begin row at: i=2+ioff
290 c*
291 c* the appropriate ioff function for the red points is then:
292 c* ioff = dabs(mod(j,2)-mod(k,2))
293 c*
294 c* the appropriate ioff function for the black points is then:
295 c* ioff = 1 - dabs(mod(j,2)-mod(k,2))
296 c*
297 c*
298 c* alternatively, the red points are:
299 c*
300 c* those whose indices add up to an even number.
301 c* to see this, consider that all surrounding points are
302 c* only one index different, hence the sum will differ by one.
303 c* thus, if a given point has an even sum, then the surrounding
304 c* points will have an odd sum.
305 c*
306 c* thus, the black points are:
307 c*
308 c* therefore those whose indices add up to an odd number.
309 c*
310 c* author: michael holst
311 c* *********************************************************************
312 implicit none
313 integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz
314 integer i,j,k,ioff
315 double precision omega,errtol
316 double precision rpc(*),oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz)
317 double precision fc(nx,ny,nz),oC(nx,ny,nz),cc(nx,ny,nz)
318 double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz)
319 double precision r(nx,ny,nz)
320 c*
321 cmdir 0 0
322 c*
323 c* *** do the gauss-seidel iteration itmax times ***
324 do 30 iters = 1, itmax
325 c*
326 c* *** do the red points ***
327 cmdir 3 1
328 do 10 k=2,nz-1
329 cmdir 3 2
330 do 11 j=2,ny-1
331 CZZZ ioff = mod((j+k+2),2)
332 ioff = (1-iadjoint)*mod((j+k+2),2)
333 2 + iadjoint *(1-mod((j+k+2),2))
334 cmdir 3 3
335 do 12 i=2+ioff,nx-1, 2
336 x(i,j,k) = (fc(i,j,k)+(
337 2 + oN(i,j,k) * x(i,j+1,k)
338 3 + oN(i,j-1,k) * x(i,j-1,k)
339 4 + oE(i,j,k) * x(i+1,j,k)
340 5 + oE(i-1,j,k) * x(i-1,j,k)
341 6 + uC(i,j,k-1) * x(i,j,k-1)
342 7 + uC(i,j,k) * x(i,j,k+1)
343 8 )) / (oC(i,j,k) + cc(i,j,k))
344 12 continue
345 11 continue
346 10 continue
347 c*
348 c* *** do the black points ***
349 cmdir 3 1
350 do 20 k=2,nz-1
351 cmdir 3 2
352 do 21 j=2,ny-1
353 CZZZ ioff = 1-mod((j+k+2),2)
354 ioff = iadjoint *mod((j+k+2),2)
355 2 + (1-iadjoint)*(1-mod((j+k+2),2))
356 cmdir 3 3
357 do 22 i=2+ioff,nx-1, 2
358 x(i,j,k) = (fc(i,j,k)+(
359 2 + oN(i,j,k) * x(i,j+1,k)
360 3 + oN(i,j-1,k) * x(i,j-1,k)
361 4 + oE(i,j,k) * x(i+1,j,k)
362 5 + oE(i-1,j,k) * x(i-1,j,k)
363 6 + uC(i,j,k-1) * x(i,j,k-1)
364 7 + uC(i,j,k) * x(i,j,k+1)
365 8 )) / (oC(i,j,k) + cc(i,j,k))
366 22 continue
367 21 continue
368 20 continue
369 c*
370 c* *** main loop ***
371 30 continue
372 c*
373 c* *** if specified, return the new residual as well ***
374 if (iresid .eq. 1) then
375 call mresid7_1s(nx,ny,nz,ipc,rpc,oC,cc,fc,oE,oN,uC,x,r)
376 endif
377 c*
378 c* *** return and end ***
379 return
380 end