Debian Codegraph @

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

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file buildBd.f
3 c* @author Michael Holst
4 c* @brief Routines to build/factor/store a banded coarse grid matrix.
5 c* @version $Id: buildBd.f,v 1.2 2010/08/12 05:45:30 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 buildband(key,nx,ny,nz,ipc,rpc,ac,ipcB,rpcB,acB)
61 c* *********************************************************************
62 c* purpose:
63 c*
64 c* build and factor a banded matrix given a matrix in diagonal form.
65 c*
66 c* author: michael holst
67 c* *********************************************************************
68 implicit none
69 integer ipc(*),ipcB(*),nx,ny,nz,numdia,n,m,lda,info,key
70 double precision rpc(*),ac(nx*ny*nz,*),rpcB(*),acB(*)
71 CZZZZ double precision rcond
72 c*
73 cmdir 0 0
74 c*
75 c* *** do in one step ***
76 numdia = ipc(11)
77 if (numdia .eq. 7) then
78 print*,'% BUILDBAND: building 7-pt banded coarse operator...'
79 n = (nx-2)*(ny-2)*(nz-2)
80 m = (nx-2)*(ny-2)
81 lda = m+1
82 call buildband1_7(nx,ny,nz,ipc,rpc,ac(1,1),
83 2 ac(1,2),ac(1,3),ac(1,4),
84 3 ipcB,rpcB,acB,n,m,lda)
85 elseif (numdia .eq. 27) then
86 print*,'% BUILDBAND: building 27-pt banded coarse operator...'
87 n = (nx-2)*(ny-2)*(nz-2)
88 m = (nx-2)*(ny-2) + (nx-2) + 1
89 lda = m+1
90 call buildband1_27(nx,ny,nz,ipc,rpc,ac(1,1),
91 2 ac(1,2),ac(1,3),ac(1,4),
92 3 ac(1,5),ac(1,6),ac(1,7),ac(1,8),ac(1,9),
93 4 ac(1,10),ac(1,11),ac(1,12),ac(1,13),ac(1,14),
94 5 ipcB,rpcB,acB,n,m,lda)
95 else
96 print*,'% BUILDBAND: invalid stencil type given...'
97 endif
98 c*
99 c* *** print matrices ***
100 CZZZZ call prtmatd(nx,ny,nz,ipc,rpc,ac)
101 CZZZZ call prtmatb(acB,n,m,lda)
102 c*
103 c* *** factor the system ***
104 key = 0
105 info = 0
106 print*,'% BUILDBAND: dpbfa factoring banded coarse system...'
107 call dpbfa(acB,lda,n,m,info)
108 CZZZZ call dpbco(acB,lda,n,m,rcond,w1,info)
109 ipcB(4) = 1
110 if (info .ne. 0) then
111 CZZZZ print*,'% BUILDBAND: dpbco rcond: ',rcond
112 print*,'% BUILDBAND: dpbfa problem: ',info
113 print*,'% BUILDBAND: leading principle minor not PD...'
114 key = 1
115 endif
116 print*,'% BUILDBAND: dpbfa banded factorization complete.'
117 c*
118 c* *** return and end ***
119 return
120 end
121 subroutine buildband1_7 (nx,ny,nz,ipc,rpc,
122 2 oC,oE,oN,uC,
123 3 ipcB,rpcB,acB,n,m,lda)
124 c* *********************************************************************
125 c* purpose:
126 c*
127 c* build the operator in banded form given the 7-diagonal form.
128 c*
129 c* notes:
130 c*
131 c* pseudo-code from the banded linpack routines:
132 c*
133 c* jj = 0
134 c* do 10 k = 2, nz-1
135 c* do 10 j = 2, ny-1
136 c* do 10 i = 2, nx-1
137 c* jj = jj + 1
138 c* i1 = max0(1, jj-m)
139 c* do 20 ii = i1, jj
140 c* kk = ii - jj + m + 1
141 c* acB(kk,jj) = 0.0e0
142 c* if ((jj-ii).eq.0) acB(kk,jj)=oC(i,j,k)
143 c* if ((jj-ii).eq.1) acB(kk,jj)=-oE(i-1,j,k)
144 c* if ((jj-ii).eq.(nx-2)) acB(kk,jj)=-oN(i,j-1,k)
145 c* if ((jj-ii).eq.(nx-2)*(ny-2)) acB(kk,jj)=-uC(i,j,k-1)
146 c* 20 continue
147 c* 10 continue
148 c*
149 c* author: michael holst
150 c* *********************************************************************
151 implicit none
152 integer ipc(*),ipcB(*),nx,ny,nz,lda,m,n
153 integer i,j,k,ii,jj,kk
154 double precision rpc(*),rpcB(*),acB(lda,*),oC(nx,ny,nz)
155 double precision oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz)
156 c*
157 cmdir 0 0
158 c*
159 c* *** doit ***
160 ipcB(1) = n
161 ipcB(2) = m
162 ipcB(3) = lda
163 ipcB(4) = 0
164 jj = 0
165 cmdir 3 1
166 do 10 k = 2, nz-1
167 cmdir 3 2
168 do 11 j = 2, ny-1
169 cmdir 3 3
170 do 12 i = 2, nx-1
171 jj = jj + 1
172 c*
173 c* *** diagonal term ***
174 ii = jj
175 kk = ii - jj + m + 1
176 acB(kk,jj) = oC(i,j,k)
177 c*
178 c* *** east neighbor ***
179 ii = jj-1
180 kk = ii - jj + m + 1
181 acB(kk,jj) = - oE(i-1,j,k)
182 c*
183 c* *** north neighbor ***
184 ii = jj-(nx-2)
185 kk = ii - jj + m + 1
186 acB(kk,jj) = - oN(i,j-1,k)
187 c*
188 c* *** up neighbor ***
189 ii = jj-(nx-2)*(ny-2)
190 kk = ii - jj + m + 1
191 acB(kk,jj) = - uC(i,j,k-1)
192 12 continue
193 11 continue
194 10 continue
195 c*
196 c* *** return and end ***
197 return
198 end
199 subroutine buildband1_27 (nx,ny,nz,ipc,rpc,
200 2 oC,oE,oN,uC,
201 3 oNE,oNW,uE,uW,uN,uS,uNE,uNW,uSE,uSW,
202 4 ipcB,rpcB,acB,n,m,lda)
203 c* *********************************************************************
204 c* purpose:
205 c*
206 c* build the operator in banded form given the 27-diagonal form.
207 c*
208 c* author: michael holst
209 c* *********************************************************************
210 implicit none
211 integer ipc(*),ipcB(*),nx,ny,nz,lda,m,n
212 integer i,j,k,ii,jj,kk
213 double precision rpc(*),rpcB(*),acB(lda,*),oC(nx,ny,nz)
214 double precision oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz)
215 double precision oNE(nx,ny,nz),oNW(nx,ny,nz),uE(nx,ny,nz)
216 double precision uW(nx,ny,nz),uN(nx,ny,nz),uS(nx,ny,nz)
217 double precision uNE(nx,ny,nz),uNW(nx,ny,nz),uSE(nx,ny,nz)
218 double precision uSW(nx,ny,nz)
219 c*
220 cmdir 0 0
221 c*
222 c* *** doit ***
223 ipcB(1) = n
224 ipcB(2) = m
225 ipcB(3) = lda
226 ipcB(4) = 0
227 jj = 0
228 cmdir 3 1
229 do 10 k = 2, nz-1
230 cmdir 3 2
231 do 11 j = 2, ny-1
232 cmdir 3 3
233 do 12 i = 2, nx-1
234 jj = jj + 1
235 c*
236 c* *** diagonal term ***
237 ii = jj
238 kk = ii - jj + m + 1
239 acB(kk,jj) = oC(i,j,k)
240 c*
241 c* *** east neighbor ***
242 ii = jj-1
243 kk = ii - jj + m + 1
244 acB(kk,jj) = - oE(i-1,j,k)
245 c*
246 c* *** north neighbor ***
247 ii = jj-(nx-2)
248 kk = ii - jj + m + 1
249 acB(kk,jj) = - oN(i,j-1,k)
250 c*
251 c* *** north-east neighbor ***
252 ii = jj-(nx-2)+1
253 kk = ii - jj + m + 1
254 acB(kk,jj) = - oNE(i,j-1,k)
255 c*
256 c* *** north-west neighbor ***
257 ii = jj-(nx-2)-1
258 kk = ii - jj + m + 1
259 acB(kk,jj) = - oNW(i,j-1,k)
260 c*
261 c* *** up neighbor ***
262 ii = jj-(nx-2)*(ny-2)
263 kk = ii - jj + m + 1
264 acB(kk,jj) = - uC(i,j,k-1)
265 c*
266 c* *** up-east neighbor ***
267 ii = jj-(nx-2)*(ny-2)+1
268 kk = ii - jj + m + 1
269 acB(kk,jj) = - uE(i,j,k-1)
270 c*
271 c* *** up-west neighbor ***
272 ii = jj-(nx-2)*(ny-2)-1
273 kk = ii - jj + m + 1
274 acB(kk,jj) = - uW(i,j,k-1)
275 c*
276 c* *** up-north neighbor ***
277 ii = jj-(nx-2)*(ny-2)+(nx-2)
278 kk = ii - jj + m + 1
279 acB(kk,jj) = - uN(i,j,k-1)
280 c*
281 c* *** up-south neighbor ***
282 ii = jj-(nx-2)*(ny-2)-(nx-2)
283 kk = ii - jj + m + 1
284 acB(kk,jj) = - uS(i,j,k-1)
285 c*
286 c* *** up-north-east neighbor ***
287 ii = jj-(nx-2)*(ny-2)+(nx-2)+1
288 kk = ii - jj + m + 1
289 acB(kk,jj) = - uNE(i,j,k-1)
290 c*
291 c* *** up-north-west neighbor ***
292 ii = jj-(nx-2)*(ny-2)+(nx-2)-1
293 kk = ii - jj + m + 1
294 acB(kk,jj) = - uNW(i,j,k-1)
295 c*
296 c* *** up-south-east neighbor ***
297 ii = jj-(nx-2)*(ny-2)-(nx-2)+1
298 kk = ii - jj + m + 1
299 acB(kk,jj) = - uSE(i,j,k-1)
300 c*
301 c* *** up-south-west neighbor ***
302 ii = jj-(nx-2)*(ny-2)-(nx-2)-1
303 kk = ii - jj + m + 1
304 acB(kk,jj) = - uSW(i,j,k-1)
305 12 continue
306 11 continue
307 10 continue
308 c*
309 c* *** return and end ***
310 return
311 end
312