Debian Codegraph @

debian/external_deps/fetk/punc/src/pmg/buildAd.c

raw
1 /* ./src_f77/buildAd.f -- translated by f2c (version 20030320).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include <punc/vf2c.h>
7
8 /* Table of constant values */
9
10 static integer c__9 = 9;
11 static integer c__1 = 1;
12
13 /* * /////////////////////////////////////////////////////////////////////////// */
14 /* * @file buildAd.f */
15 /* * @author Michael Holst */
16 /* * @brief PDE Discretization routines. */
17 /* * @version $Id: buildAd.c,v 1.3 2010/08/12 05:45:18 fetk Exp $ */
18 /* * @attention */
19 /* * @verbatim */
20 /* * */
21 /* * PMG -- Parallel algebraic MultiGrid */
22 /* * Copyright (C) 1994-- Michael Holst. */
23 /* * */
24 /* * Michael Holst <[email protected]> */
25 /* * University of California, San Diego */
26 /* * Department of Mathematics, 5739 AP&M */
27 /* * 9500 Gilman Drive, Dept. 0112 */
28 /* * La Jolla, CA 92093-0112 USA */
29 /* * http://math.ucsd.edu/~mholst */
30 /* * */
31 /* * This file is part of PMG. */
32 /* * */
33 /* * PMG is free software; you can redistribute it and/or modify */
34 /* * it under the terms of the GNU General Public License as published by */
35 /* * the Free Software Foundation; either version 2 of the License, or */
36 /* * (at your option) any later version. */
37 /* * */
38 /* * PMG is distributed in the hope that it will be useful, */
39 /* * but WITHOUT ANY WARRANTY; without even the implied warranty of */
40 /* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
41 /* * GNU General Public License for more details. */
42 /* * */
43 /* * You should have received a copy of the GNU General Public License */
44 /* * along with PMG; if not, write to the Free Software */
45 /* * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
46 /* * */
47 /* * Linking PMG statically or dynamically with other modules is making a */
48 /* * combined work based on PMG. Thus, the terms and conditions of the GNU */
49 /* * General Public License cover the whole combination. */
50 /* * */
51 /* * SPECIAL GPL EXCEPTION */
52 /* * In addition, as a special exception, the copyright holders of PMG */
53 /* * give you permission to combine the PMG program with free software */
54 /* * programs and libraries that are released under the GNU LGPL or with */
55 /* * code included in releases of ISIM, PMV, PyMOL, SMOL, VMD, and Vision. */
56 /* * Such combined software may be linked with PMG and redistributed together */
57 /* * in original or modified form as mere aggregation without requirement that */
58 /* * the entire work be under the scope of the GNU General Public License. */
59 /* * This special exception permission is also extended to any software listed */
60 /* * in the SPECIAL GPL EXCEPTION clauses by the FEtk and APBS libraries. */
61 /* * */
62 /* * Note that people who make modified versions of PMG are not obligated */
63 /* * to grant this special exception for their modified versions; it is */
64 /* * their choice whether to do so. The GNU General Public License gives */
65 /* * permission to release a modified version without this exception; this */
66 /* * exception also makes it possible to release a modified version which */
67 /* * carries forward this exception. */
68 /* * */
69 /* * @endverbatim */
70 /* * /////////////////////////////////////////////////////////////////////////// */
71 /* Subroutine */ int builda_(integer *nx, integer *ny, integer *nz, integer *
72 ipkey, integer *mgdisc, integer *numdia, integer *ipc, doublereal *
73 rpc, doublereal *ac, doublereal *cc, doublereal *fc, doublereal *xf,
74 doublereal *yf, doublereal *zf, doublereal *gxcf, doublereal *gycf,
75 doublereal *gzcf, doublereal *a1cf, doublereal *a2cf, doublereal *
76 a3cf, doublereal *ccf, doublereal *fcf)
77 {
78 /* System generated locals */
79 integer ac_dim1, ac_offset;
80
81 /* Builtin functions */
82 integer s_wsle(cilist *), do_lio(integer *, integer *, char *, ftnlen),
83 e_wsle(void);
84
85 /* Local variables */
86 extern /* Subroutine */ int builda_fe__(integer *, integer *, integer *,
87 integer *, integer *, integer *, doublereal *, doublereal *,
88 doublereal *, doublereal *, doublereal *, doublereal *,
89 doublereal *, doublereal *, doublereal *, doublereal *,
90 doublereal *, doublereal *, doublereal *, doublereal *,
91 doublereal *, doublereal *, doublereal *, doublereal *,
92 doublereal *, doublereal *, doublereal *, doublereal *,
93 doublereal *, doublereal *, doublereal *, doublereal *,
94 doublereal *, doublereal *), builda_fv__(integer *, integer *,
95 integer *, integer *, integer *, integer *, doublereal *,
96 doublereal *, doublereal *, doublereal *, doublereal *,
97 doublereal *, doublereal *, doublereal *, doublereal *,
98 doublereal *, doublereal *, doublereal *, doublereal *,
99 doublereal *, doublereal *, doublereal *, doublereal *,
100 doublereal *);
101
102 /* Fortran I/O blocks */
103 static cilist io___1 = { 0, 6, 0, 0, 0 };
104 static cilist io___2 = { 0, 6, 0, 0, 0 };
105 static cilist io___3 = { 0, 6, 0, 0, 0 };
106
107
108 /* * ********************************************************************* */
109 /* * purpose: */
110 /* * */
111 /* * break the matrix data-structure into diagonals */
112 /* * and then call the matrix build routine. */
113 /* * */
114 /* * author: michael holst */
115 /* * ********************************************************************* */
116 /* * */
117 /* mdir 0 0 */
118 /* * */
119 /* * *** call the build routine *** */
120 /* Parameter adjustments */
121 ac_dim1 = *nx * *ny * *nz;
122 ac_offset = 1 + ac_dim1;
123 ac -= ac_offset;
124 --ipc;
125 --rpc;
126 --cc;
127 --fc;
128 --xf;
129 --yf;
130 --zf;
131 --gxcf;
132 --gycf;
133 --gzcf;
134 --a1cf;
135 --a2cf;
136 --a3cf;
137 --ccf;
138 --fcf;
139
140 /* Function Body */
141 if (*mgdisc == 0) {
142 s_wsle(&io___1);
143 do_lio(&c__9, &c__1, "% BUILDA: (BOX) performing discretization...",
144 (ftnlen)46);
145 e_wsle();
146 builda_fv__(nx, ny, nz, ipkey, numdia, &ipc[1], &rpc[1], &ac[ac_dim1
147 + 1], &cc[1], &fc[1], &ac[(ac_dim1 << 1) + 1], &ac[ac_dim1 *
148 3 + 1], &ac[(ac_dim1 << 2) + 1], &xf[1], &yf[1], &zf[1], &
149 gxcf[1], &gycf[1], &gzcf[1], &a1cf[1], &a2cf[1], &a3cf[1], &
150 ccf[1], &fcf[1]);
151 } else if (*mgdisc == 1) {
152 s_wsle(&io___2);
153 do_lio(&c__9, &c__1, "% BUILDA: (FEM) performing discretization...",
154 (ftnlen)46);
155 e_wsle();
156 builda_fe__(nx, ny, nz, ipkey, numdia, &ipc[1], &rpc[1], &ac[ac_dim1
157 + 1], &cc[1], &fc[1], &ac[(ac_dim1 << 1) + 1], &ac[ac_dim1 *
158 3 + 1], &ac[(ac_dim1 << 2) + 1], &ac[ac_dim1 * 5 + 1], &ac[
159 ac_dim1 * 6 + 1], &ac[ac_dim1 * 7 + 1], &ac[(ac_dim1 << 3) +
160 1], &ac[ac_dim1 * 9 + 1], &ac[ac_dim1 * 10 + 1], &ac[ac_dim1 *
161 11 + 1], &ac[ac_dim1 * 12 + 1], &ac[ac_dim1 * 13 + 1], &ac[
162 ac_dim1 * 14 + 1], &xf[1], &yf[1], &zf[1], &gxcf[1], &gycf[1],
163 &gzcf[1], &a1cf[1], &a2cf[1], &a3cf[1], &ccf[1], &fcf[1]);
164 } else {
165 s_wsle(&io___3);
166 do_lio(&c__9, &c__1, "% BUILDA: invalid discretization requested...",
167 (ftnlen)45);
168 e_wsle();
169 }
170 /* * */
171 /* * *** return and end *** */
172 return 0;
173 } /* builda_ */
174
175 /* Subroutine */ int builda_fv__(integer *nx, integer *ny, integer *nz,
176 integer *ipkey, integer *numdia, integer *ipc, doublereal *rpc,
177 doublereal *oc, doublereal *cc, doublereal *fc, doublereal *oe,
178 doublereal *on, doublereal *uc, doublereal *xf, doublereal *yf,
179 doublereal *zf, doublereal *gxcf, doublereal *gycf, doublereal *gzcf,
180 doublereal *a1cf, doublereal *a2cf, doublereal *a3cf, doublereal *ccf,
181 doublereal *fcf)
182 {
183 /* System generated locals */
184 integer a1cf_dim1, a1cf_dim2, a1cf_offset, a2cf_dim1, a2cf_dim2,
185 a2cf_offset, a3cf_dim1, a3cf_dim2, a3cf_offset, ccf_dim1,
186 ccf_dim2, ccf_offset, fcf_dim1, fcf_dim2, fcf_offset, oe_dim1,
187 oe_dim2, oe_offset, on_dim1, on_dim2, on_offset, uc_dim1, uc_dim2,
188 uc_offset, cc_dim1, cc_dim2, cc_offset, fc_dim1, fc_dim2,
189 fc_offset, oc_dim1, oc_dim2, oc_offset, gxcf_dim1, gxcf_dim2,
190 gxcf_offset, gycf_dim1, gycf_dim2, gycf_offset, gzcf_dim1,
191 gzcf_dim2, gzcf_offset, i__1, i__2, i__3, i__4, i__5, i__6;
192
193 /* Local variables */
194 static doublereal coef_oem1__, coef_ucm1__, coef_onm1__;
195 static integer i__, j, k;
196 static doublereal bc_cond_e__, bc_cond_d__, bc_cond_n__, bc_cond_s__,
197 bc_cond_u__, bc_cond_w__, hx, hy, hz;
198 static integer ike, jke, kke;
199 static doublereal hxm1, hym1, hzm1;
200 static integer nxm1, nym1, nzm1;
201 static doublereal diag, coef_fc__, coef_oe__, coef_uc__, coef_on__;
202
203 /* * ********************************************************************* */
204 /* * purpose: */
205 /* * */
206 /* * box method (finite volume) discretization of a 3d pde on a */
207 /* * tensor product (axi-parallel) three-dimensional mesh. */
208 /* * */
209 /* * this subroutine discretizes the elliptic boundary value problem: */
210 /* * */
211 /* * lu = f, u in omega */
212 /* * u = g, u on boundary of omega */
213 /* * */
214 /* * the multigrid code requires the operator in the form: */
215 /* * */
216 /* * - \nabla \cdot (a \nabla u) + b \cdot u + c u = f */
217 /* * */
218 /* * or: */
219 /* * */
220 /* * lu = (a11 u_x)_x + (a22 u_y)_y + (a33 u_z)_z */
221 /* * + b1 u_x + b2 u_y + b3 u_z + c u */
222 /* * */
223 /* * here, we consider only the case: b=b1=b2=b3=0. */
224 /* * then we assume: */
225 /* * */
226 /* * the tensor a=diag(a11,a22,a33) has components which are */
227 /* * then scalar functions, a11(x,y,z),a22(x,y,z),a33(x,y,z) */
228 /* * and the functions c(x,y,z) and f(x,y,z) are also scalar. */
229 /* * functions. All are allowed to be possibly discontinuous on */
230 /* * omega (the discontinuities must be along grid lines on fine grid). */
231 /* * the boundary function g(x,y,z) is smooth on boundary of omega. */
232 /* * */
233 /* * we will take the following conventions: */
234 /* * (north,south,east,west refers to x-y plane. */
235 /* * up/down refers to the z-axis) */
236 /* * (u(x+h_x,y,z) = u^+ (east neighbor of u(x,y,z)) */
237 /* * (u(x-h_x,y,z) = u^- (west neighbor of u(x,y,z)) */
238 /* * (u(x,y+h_y,z) = u_+ (north neighbor of u(x,y,z)) */
239 /* * (u(x,y-h_y,z) = u_- (south neighbor of u(x,y,z)) */
240 /* * (u(x,y,z+h_z) = u.+ (up neighbor of u(x,y,z)) */
241 /* * (u(x,y,z-h_z) = u.- (down neighbor u(x,y,z)) */
242 /* * */
243 /* * below, we will denote: */
244 /* * u(x+h_x,y,z) as u^+ */
245 /* * u(x+(1/2)h_x,y,z) as u^++ */
246 /* * u(x-h_x,y,z) as u^+ */
247 /* * u(x-(1/2)h_x,y,z) as u^-- */
248 /* * and similarly for u_-,u_--,u_+,u_++,u.-,u.--,u.+,u.++. */
249 /* * */
250 /* * we use the 3d analogue of the box method (see varga, pg. 191) */
251 /* * which results in the following difference scheme: */
252 /* * */
253 /* * u : [ + (a11^++ + a11^--) * (h_y*h_z/h_x) */
254 /* * + (a22_++ + a22_--) * (h_x*h_z/h_y) */
255 /* * + (a33.++ + a33.--) * (h_x*h_y/h_z) */
256 /* * + c * (h_x*h_y*h_z) ] u */
257 /* * u^+ (e nbr) : [ - (a11^++) * (h_y*h_z/h_x) ] */
258 /* * u^_ (w nbr) : [ - (a11^--) * (h_y*h_z/h_x) ] */
259 /* * u_+ (n nbr) : [ - (a22_++) * (h_x*h_z/h_y) ] */
260 /* * u_- (s nbr) : [ - (a22_--) * (h_x*h_z/h_y) ] */
261 /* * u.+ (u nbr) : [ - (a33.++) * (h_x*h_y/h_z) ] */
262 /* * u.- (d nbr) : [ - (a33.--) * (h_x*h_y/h_z) ] */
263 /* * f : [ h_x*h_y*h_z ] f */
264 /* * */
265 /* * note: fast way to do a conditional: we wish to set (a=coef), */
266 /* * unless we are on the (z=0)-boundary, which occurs with k=1: */
267 /* * */
268 /* * coef = ...etc... */
269 /* * ike = min0(1,iabs(k-1)) */
270 /* * a (index1) = (ike)*coef */
271 /* * b(index2) = b(index2) - (1-ike)*coef*bnd_data */
272 /* * */
273 /* * author: michael holst */
274 /* * ********************************************************************* */
275 /* * */
276 /* mdir 0 0 */
277 /* * */
278 /* * *** save the problem key with this operator *** */
279 /* Parameter adjustments */
280 gzcf_dim1 = *nx;
281 gzcf_dim2 = *ny;
282 gzcf_offset = 1 + gzcf_dim1 * (1 + gzcf_dim2);
283 gzcf -= gzcf_offset;
284 fcf_dim1 = *nx;
285 fcf_dim2 = *ny;
286 fcf_offset = 1 + fcf_dim1 * (1 + fcf_dim2);
287 fcf -= fcf_offset;
288 ccf_dim1 = *nx;
289 ccf_dim2 = *ny;
290 ccf_offset = 1 + ccf_dim1 * (1 + ccf_dim2);
291 ccf -= ccf_offset;
292 a3cf_dim1 = *nx;
293 a3cf_dim2 = *ny;
294 a3cf_offset = 1 + a3cf_dim1 * (1 + a3cf_dim2);
295 a3cf -= a3cf_offset;
296 a2cf_dim1 = *nx;
297 a2cf_dim2 = *ny;
298 a2cf_offset = 1 + a2cf_dim1 * (1 + a2cf_dim2);
299 a2cf -= a2cf_offset;
300 a1cf_dim1 = *nx;
301 a1cf_dim2 = *ny;
302 a1cf_offset = 1 + a1cf_dim1 * (1 + a1cf_dim2);
303 a1cf -= a1cf_offset;
304 gycf_dim1 = *nx;
305 gycf_dim2 = *nz;
306 gycf_offset = 1 + gycf_dim1 * (1 + gycf_dim2);
307 gycf -= gycf_offset;
308 gxcf_dim1 = *ny;
309 gxcf_dim2 = *nz;
310 gxcf_offset = 1 + gxcf_dim1 * (1 + gxcf_dim2);
311 gxcf -= gxcf_offset;
312 uc_dim1 = *nx;
313 uc_dim2 = *ny;
314 uc_offset = 1 + uc_dim1 * (1 + uc_dim2);
315 uc -= uc_offset;
316 on_dim1 = *nx;
317 on_dim2 = *ny;
318 on_offset = 1 + on_dim1 * (1 + on_dim2);
319 on -= on_offset;
320 oe_dim1 = *nx;
321 oe_dim2 = *ny;
322 oe_offset = 1 + oe_dim1 * (1 + oe_dim2);
323 oe -= oe_offset;
324 fc_dim1 = *nx;
325 fc_dim2 = *ny;
326 fc_offset = 1 + fc_dim1 * (1 + fc_dim2);
327 fc -= fc_offset;
328 cc_dim1 = *nx;
329 cc_dim2 = *ny;
330 cc_offset = 1 + cc_dim1 * (1 + cc_dim2);
331 cc -= cc_offset;
332 oc_dim1 = *nx;
333 oc_dim2 = *ny;
334 oc_offset = 1 + oc_dim1 * (1 + oc_dim2);
335 oc -= oc_offset;
336 --ipc;
337 --rpc;
338 --xf;
339 --yf;
340 --zf;
341
342 /* Function Body */
343 ipc[10] = *ipkey;
344 /* * */
345 /* * *** note how many nonzeros in this discretization stencil */
346 ipc[11] = 7;
347 ipc[12] = 1;
348 *numdia = 4;
349 /* * */
350 /* * *** define n and determine number of mesh points *** */
351 nxm1 = *nx - 1;
352 nym1 = *ny - 1;
353 nzm1 = *nz - 1;
354 /* * */
355 /* * *** determine diag scale factor *** */
356 /* * *** (would like something close to ones on the main diagonal) *** */
357 diag = 1.;
358 /* * */
359 /* * ********************************************************************* */
360 /* * *** interior points *** */
361 /* * ********************************************************************* */
362 /* * */
363 /* * *** build the operator *** */
364 /* mdir 3 1 */
365 i__1 = *nz - 1;
366 for (k = 2; k <= i__1; ++k) {
367 hzm1 = zf[k] - zf[k - 1];
368 hz = zf[k + 1] - zf[k];
369 /* mdir 3 2 */
370 i__2 = *ny - 1;
371 for (j = 2; j <= i__2; ++j) {
372 hym1 = yf[j] - yf[j - 1];
373 hy = yf[j + 1] - yf[j];
374 /* mdir 3 3 */
375 i__3 = *nx - 1;
376 for (i__ = 2; i__ <= i__3; ++i__) {
377 hxm1 = xf[i__] - xf[i__ - 1];
378 hx = xf[i__ + 1] - xf[i__];
379 /* * */
380 /* * *** some coefficients *** */
381 coef_oe__ = diag * (hym1 + hy) * (hzm1 + hz) / (hx * 4.f);
382 coef_oem1__ = diag * (hym1 + hy) * (hzm1 + hz) / (hxm1 * 4.f);
383 coef_on__ = diag * (hxm1 + hx) * (hzm1 + hz) / (hy * 4.f);
384 coef_onm1__ = diag * (hxm1 + hx) * (hzm1 + hz) / (hym1 * 4.f);
385 coef_uc__ = diag * (hxm1 + hx) * (hym1 + hy) / (hz * 4.f);
386 coef_ucm1__ = diag * (hxm1 + hx) * (hym1 + hy) / (hzm1 * 4.f);
387 coef_fc__ = diag * (hxm1 + hx) * (hym1 + hy) * (hzm1 + hz) /
388 8.f;
389 /* * */
390 /* * *** the coefficient and source function *** */
391 fc[i__ + (j + k * fc_dim2) * fc_dim1] = coef_fc__ * fcf[i__ +
392 (j + k * fcf_dim2) * fcf_dim1];
393 cc[i__ + (j + k * cc_dim2) * cc_dim1] = coef_fc__ * ccf[i__ +
394 (j + k * ccf_dim2) * ccf_dim1];
395 /* * */
396 /* * *** the diagonal for matvecs and smoothings *** */
397 oc[i__ + (j + k * oc_dim2) * oc_dim1] = coef_oe__ * a1cf[i__
398 + (j + k * a1cf_dim2) * a1cf_dim1] + coef_oem1__ *
399 a1cf[i__ - 1 + (j + k * a1cf_dim2) * a1cf_dim1] +
400 coef_on__ * a2cf[i__ + (j + k * a2cf_dim2) *
401 a2cf_dim1] + coef_onm1__ * a2cf[i__ + (j - 1 + k *
402 a2cf_dim2) * a2cf_dim1] + coef_uc__ * a3cf[i__ + (j +
403 k * a3cf_dim2) * a3cf_dim1] + coef_ucm1__ * a3cf[i__
404 + (j + (k - 1) * a3cf_dim2) * a3cf_dim1];
405 /* * */
406 /* * *** east neighbor *** */
407 /* Computing MIN */
408 i__5 = 1, i__6 = (i__4 = i__ - nxm1, abs(i__4));
409 ike = min(i__5,i__6);
410 oe[i__ + (j + k * oe_dim2) * oe_dim1] = ike * coef_oe__ *
411 a1cf[i__ + (j + k * a1cf_dim2) * a1cf_dim1];
412 bc_cond_e__ = (1 - ike) * coef_oe__ * a1cf[i__ + (j + k *
413 a1cf_dim2) * a1cf_dim1] * gxcf[j + (k + (gxcf_dim2 <<
414 1)) * gxcf_dim1];
415 fc[i__ + (j + k * fc_dim2) * fc_dim1] += bc_cond_e__;
416 /* * */
417 /* * *** north neighbor *** */
418 /* Computing MIN */
419 i__5 = 1, i__6 = (i__4 = j - nym1, abs(i__4));
420 jke = min(i__5,i__6);
421 on[i__ + (j + k * on_dim2) * on_dim1] = jke * coef_on__ *
422 a2cf[i__ + (j + k * a2cf_dim2) * a2cf_dim1];
423 bc_cond_n__ = (1 - jke) * coef_on__ * a2cf[i__ + (j + k *
424 a2cf_dim2) * a2cf_dim1] * gycf[i__ + (k + (gycf_dim2
425 << 1)) * gycf_dim1];
426 fc[i__ + (j + k * fc_dim2) * fc_dim1] += bc_cond_n__;
427 /* * */
428 /* * *** up neighbor *** */
429 /* Computing MIN */
430 i__5 = 1, i__6 = (i__4 = k - nzm1, abs(i__4));
431 kke = min(i__5,i__6);
432 uc[i__ + (j + k * uc_dim2) * uc_dim1] = kke * coef_uc__ *
433 a3cf[i__ + (j + k * a3cf_dim2) * a3cf_dim1];
434 bc_cond_u__ = (1 - kke) * coef_uc__ * a3cf[i__ + (j + k *
435 a3cf_dim2) * a3cf_dim1] * gzcf[i__ + (j + (gzcf_dim2
436 << 1)) * gzcf_dim1];
437 fc[i__ + (j + k * fc_dim2) * fc_dim1] += bc_cond_u__;
438 /* * */
439 /* * *** west neighbor (just handle b.c.) *** */
440 /* Computing MIN */
441 i__5 = 1, i__6 = (i__4 = i__ - 2, abs(i__4));
442 ike = min(i__5,i__6);
443 bc_cond_w__ = (1 - ike) * coef_oem1__ * a1cf[i__ - 1 + (j + k
444 * a1cf_dim2) * a1cf_dim1] * gxcf[j + (k + gxcf_dim2) *
445 gxcf_dim1];
446 fc[i__ + (j + k * fc_dim2) * fc_dim1] += bc_cond_w__;
447 /* * */
448 /* * *** south neighbor (just handle b.c.) *** */
449 /* Computing MIN */
450 i__5 = 1, i__6 = (i__4 = j - 2, abs(i__4));
451 jke = min(i__5,i__6);
452 bc_cond_s__ = (1 - jke) * coef_onm1__ * a2cf[i__ + (j - 1 + k
453 * a2cf_dim2) * a2cf_dim1] * gycf[i__ + (k + gycf_dim2)
454 * gycf_dim1];
455 fc[i__ + (j + k * fc_dim2) * fc_dim1] += bc_cond_s__;
456 /* * */
457 /* * *** down neighbor (just handle b.c.) *** */
458 /* Computing MIN */
459 i__5 = 1, i__6 = (i__4 = k - 2, abs(i__4));
460 kke = min(i__5,i__6);
461 bc_cond_d__ = (1 - kke) * coef_ucm1__ * a3cf[i__ + (j + (k -
462 1) * a3cf_dim2) * a3cf_dim1] * gzcf[i__ + (j +
463 gzcf_dim2) * gzcf_dim1];
464 fc[i__ + (j + k * fc_dim2) * fc_dim1] += bc_cond_d__;
465 /* L12: */
466 }
467 /* L11: */
468 }
469 /* L10: */
470 }
471 /* * */
472 /* * *** return and end *** */
473 return 0;
474 } /* builda_fv__ */
475
476 /* Subroutine */ int builda_fe__(integer *nx, integer *ny, integer *nz,
477 integer *ipkey, integer *numdia, integer *ipc, doublereal *rpc,
478 doublereal *oc, doublereal *cc, doublereal *fc, doublereal *oe,
479 doublereal *on, doublereal *uc, doublereal *one, doublereal *onw,
480 doublereal *ue, doublereal *uw, doublereal *un, doublereal *us,
481 doublereal *une, doublereal *unw, doublereal *use, doublereal *usw,
482 doublereal *xf, doublereal *yf, doublereal *zf, doublereal *gxcf,
483 doublereal *gycf, doublereal *gzcf, doublereal *a1cf, doublereal *
484 a2cf, doublereal *a3cf, doublereal *ccf, doublereal *fcf)
485 {
486 /* System generated locals */
487 integer a1cf_dim1, a1cf_dim2, a1cf_offset, a2cf_dim1, a2cf_dim2,
488 a2cf_offset, a3cf_dim1, a3cf_dim2, a3cf_offset, ccf_dim1,
489 ccf_dim2, ccf_offset, fcf_dim1, fcf_dim2, fcf_offset, oe_dim1,
490 oe_dim2, oe_offset, on_dim1, on_dim2, on_offset, uc_dim1, uc_dim2,
491 uc_offset, one_dim1, one_dim2, one_offset, onw_dim1, onw_dim2,
492 onw_offset, ue_dim1, ue_dim2, ue_offset, uw_dim1, uw_dim2,
493 uw_offset, un_dim1, un_dim2, un_offset, us_dim1, us_dim2,
494 us_offset, une_dim1, une_dim2, une_offset, unw_dim1, unw_dim2,
495 unw_offset, use_dim1, use_dim2, use_offset, usw_dim1, usw_dim2,
496 usw_offset, cc_dim1, cc_dim2, cc_offset, fc_dim1, fc_dim2,
497 fc_offset, oc_dim1, oc_dim2, oc_offset, gxcf_dim1, gxcf_dim2,
498 gxcf_offset, gycf_dim1, gycf_dim2, gycf_offset, gzcf_dim1,
499 gzcf_dim2, gzcf_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7,
500 i__8, i__9, i__10, i__11, i__12;
501
502 /* Local variables */
503 static integer i__, j, k;
504 static doublereal hx, hy, hz;
505 static integer ike, jke, kke;
506 static doublereal hxm1, hym1, hzm1;
507 static integer nxm1, nym1, nzm1;
508 static doublereal diag, coef_fc__, coef_uc__;
509
510 /* * ********************************************************************* */
511 /* * purpose: */
512 /* * */
513 /* * finite element method discretization of a 3d pde on a */
514 /* * tensor product (axi-parallel) three-dimensional mesh. */
515 /* * */
516 /* * KEY RESTRICTION: the coefficients in the pde below must */
517 /* * be piecewise constant in the elements */
518 /* * for this discretization to be formally */
519 /* * correct. */
520 /* * */
521 /* * this subroutine discretizes the elliptic boundary value problem: */
522 /* * */
523 /* * lu = f, u in omega */
524 /* * u = g, u on boundary of omega */
525 /* * */
526 /* * the multigrid code requires the operator in the form: */
527 /* * */
528 /* * - \nabla \cdot (a \nabla u) + b \cdot u + c u = f */
529 /* * */
530 /* * or: */
531 /* * */
532 /* * lu = (a11 u_x)_x + (a22 u_y)_y + (a33 u_z)_z */
533 /* * + b1 u_x + b2 u_y + b3 u_z + c u */
534 /* * */
535 /* * here, we consider only the case: b=b1=b2=b3=0. */
536 /* * then we assume: */
537 /* * */
538 /* * the tensor a=diag(a11,a22,a33) has components which are */
539 /* * then scalar functions, a11(x,y,z),a22(x,y,z),a33(x,y,z) */
540 /* * and the functions c(x,y,z) and f(x,y,z) are also scalar. */
541 /* * functions. All are allowed to be possibly discontinuous on */
542 /* * omega (the discontinuities must be along grid lines on fine grid). */
543 /* * the boundary function g(x,y,z) is smooth on boundary of omega. */
544 /* * */
545 /* * we will take the following conventions: */
546 /* * (north,south,east,west refers to x-y plane. */
547 /* * up/down refers to the z-axis) */
548 /* * (u(x+h_x,y,z) = u^+ (east neighbor of u(x,y,z)) */
549 /* * (u(x-h_x,y,z) = u^- (west neighbor of u(x,y,z)) */
550 /* * (u(x,y+h_y,z) = u_+ (north neighbor of u(x,y,z)) */
551 /* * (u(x,y-h_y,z) = u_- (south neighbor of u(x,y,z)) */
552 /* * (u(x,y,z+h_z) = u.+ (up neighbor of u(x,y,z)) */
553 /* * (u(x,y,z-h_z) = u.- (down neighbor u(x,y,z)) */
554 /* * */
555 /* * below, we will denote: */
556 /* * u(x+h_x,y,z) as u^+ */
557 /* * u(x+(1/2)h_x,y,z) as u^++ */
558 /* * u(x-h_x,y,z) as u^+ */
559 /* * u(x-(1/2)h_x,y,z) as u^-- */
560 /* * and similarly for u_-,u_--,u_+,u_++,u.-,u.--,u.+,u.++. */
561 /* * */
562 /* * we use trilinear basis functions and hexahedral elements */
563 /* * to perform this standard finite element discretization, */
564 /* * which results in the following difference scheme: */
565 /* * */
566 /* * u : [ + (a11^++ + a11^--) * (h_y*h_z/h_x) */
567 /* * + (a22_++ + a22_--) * (h_x*h_z/h_y) */
568 /* * + (a33.++ + a33.--) * (h_x*h_y/h_z) */
569 /* * + c * (h_x*h_y*h_z) ] u */
570 /* * u^+ (e nbr) : [ - (a11^++) * (h_y*h_z/h_x) ] */
571 /* * u^_ (w nbr) : [ - (a11^--) * (h_y*h_z/h_x) ] */
572 /* * u_+ (n nbr) : [ - (a22_++) * (h_x*h_z/h_y) ] */
573 /* * u_- (s nbr) : [ - (a22_--) * (h_x*h_z/h_y) ] */
574 /* * u.+ (u nbr) : [ - (a33.++) * (h_x*h_y/h_z) ] */
575 /* * u.- (d nbr) : [ - (a33.--) * (h_x*h_y/h_z) ] */
576 /* * f : [ h_x*h_y*h_z ] f */
577 /* * */
578 /* * note: fast way to do a conditional: we wish to set (a=coef), */
579 /* * unless we are on the (z=0)-boundary, which occurs with k=1: */
580 /* * */
581 /* * coef = ...etc... */
582 /* * ike = min0(1,iabs(k-1)) */
583 /* * a (index1) = (ike)*coef */
584 /* * b(index2) = b(index2) - (1-ike)*coef*bnd_data */
585 /* * */
586 /* * author: michael holst */
587 /* * ********************************************************************* */
588 /* * */
589 /* mdir 0 0 */
590 /* * */
591 /* * *** save the problem key with this operator *** */
592 /* Parameter adjustments */
593 gzcf_dim1 = *nx;
594 gzcf_dim2 = *ny;
595 gzcf_offset = 1 + gzcf_dim1 * (1 + gzcf_dim2);
596 gzcf -= gzcf_offset;
597 fcf_dim1 = *nx;
598 fcf_dim2 = *ny;
599 fcf_offset = 1 + fcf_dim1 * (1 + fcf_dim2);
600 fcf -= fcf_offset;
601 ccf_dim1 = *nx;
602 ccf_dim2 = *ny;
603 ccf_offset = 1 + ccf_dim1 * (1 + ccf_dim2);
604 ccf -= ccf_offset;
605 a3cf_dim1 = *nx;
606 a3cf_dim2 = *ny;
607 a3cf_offset = 1 + a3cf_dim1 * (1 + a3cf_dim2);
608 a3cf -= a3cf_offset;
609 a2cf_dim1 = *nx;
610 a2cf_dim2 = *ny;
611 a2cf_offset = 1 + a2cf_dim1 * (1 + a2cf_dim2);
612 a2cf -= a2cf_offset;
613 a1cf_dim1 = *nx;
614 a1cf_dim2 = *ny;
615 a1cf_offset = 1 + a1cf_dim1 * (1 + a1cf_dim2);
616 a1cf -= a1cf_offset;
617 gycf_dim1 = *nx;
618 gycf_dim2 = *nz;
619 gycf_offset = 1 + gycf_dim1 * (1 + gycf_dim2);
620 gycf -= gycf_offset;
621 gxcf_dim1 = *ny;
622 gxcf_dim2 = *nz;
623 gxcf_offset = 1 + gxcf_dim1 * (1 + gxcf_dim2);
624 gxcf -= gxcf_offset;
625 usw_dim1 = *nx;
626 usw_dim2 = *ny;
627 usw_offset = 1 + usw_dim1 * (1 + usw_dim2);
628 usw -= usw_offset;
629 use_dim1 = *nx;
630 use_dim2 = *ny;
631 use_offset = 1 + use_dim1 * (1 + use_dim2);
632 use -= use_offset;
633 unw_dim1 = *nx;
634 unw_dim2 = *ny;
635 unw_offset = 1 + unw_dim1 * (1 + unw_dim2);
636 unw -= unw_offset;
637 une_dim1 = *nx;
638 une_dim2 = *ny;
639 une_offset = 1 + une_dim1 * (1 + une_dim2);
640 une -= une_offset;
641 us_dim1 = *nx;
642 us_dim2 = *ny;
643 us_offset = 1 + us_dim1 * (1 + us_dim2);
644 us -= us_offset;
645 un_dim1 = *nx;
646 un_dim2 = *ny;
647 un_offset = 1 + un_dim1 * (1 + un_dim2);
648 un -= un_offset;
649 uw_dim1 = *nx;
650 uw_dim2 = *ny;
651 uw_offset = 1 + uw_dim1 * (1 + uw_dim2);
652 uw -= uw_offset;
653 ue_dim1 = *nx;
654 ue_dim2 = *ny;
655 ue_offset = 1 + ue_dim1 * (1 + ue_dim2);
656 ue -= ue_offset;
657 onw_dim1 = *nx;
658 onw_dim2 = *ny;
659 onw_offset = 1 + onw_dim1 * (1 + onw_dim2);
660 onw -= onw_offset;
661 one_dim1 = *nx;
662 one_dim2 = *ny;
663 one_offset = 1 + one_dim1 * (1 + one_dim2);
664 one -= one_offset;
665 uc_dim1 = *nx;
666 uc_dim2 = *ny;
667 uc_offset = 1 + uc_dim1 * (1 + uc_dim2);
668 uc -= uc_offset;
669 on_dim1 = *nx;
670 on_dim2 = *ny;
671 on_offset = 1 + on_dim1 * (1 + on_dim2);
672 on -= on_offset;
673 oe_dim1 = *nx;
674 oe_dim2 = *ny;
675 oe_offset = 1 + oe_dim1 * (1 + oe_dim2);
676 oe -= oe_offset;
677 fc_dim1 = *nx;
678 fc_dim2 = *ny;
679 fc_offset = 1 + fc_dim1 * (1 + fc_dim2);
680 fc -= fc_offset;
681 cc_dim1 = *nx;
682 cc_dim2 = *ny;
683 cc_offset = 1 + cc_dim1 * (1 + cc_dim2);
684 cc -= cc_offset;
685 oc_dim1 = *nx;
686 oc_dim2 = *ny;
687 oc_offset = 1 + oc_dim1 * (1 + oc_dim2);
688 oc -= oc_offset;
689 --ipc;
690 --rpc;
691 --xf;
692 --yf;
693 --zf;
694
695 /* Function Body */
696 ipc[10] = *ipkey;
697 /* * */
698 /* * *** note how many nonzeros in this discretization stencil */
699 ipc[11] = 27;
700 ipc[12] = 1;
701 *numdia = 14;
702 /* * */
703 /* * *** define n and determine number of mesh points *** */
704 nxm1 = *nx - 1;
705 nym1 = *ny - 1;
706 nzm1 = *nz - 1;
707 /* * */
708 /* * *** determine diag scale factor *** */
709 /* * *** (would like something close to ones on the main diagonal) *** */
710 diag = 1.;
711 /* * */
712 /* * ********************************************************************* */
713 /* * *** interior points *** */
714 /* * ********************************************************************* */
715 /* * */
716 /* * *** build the operator *** */
717 /* mdir 3 1 */
718 i__1 = *nz - 1;
719 for (k = 2; k <= i__1; ++k) {
720 hzm1 = zf[k] - zf[k - 1];
721 hz = zf[k + 1] - zf[k];
722 /* mdir 3 2 */
723 i__2 = *ny - 1;
724 for (j = 2; j <= i__2; ++j) {
725 hym1 = yf[j] - yf[j - 1];
726 hy = yf[j + 1] - yf[j];
727 /* mdir 3 3 */
728 i__3 = *nx - 1;
729 for (i__ = 2; i__ <= i__3; ++i__) {
730 hxm1 = xf[i__] - xf[i__ - 1];
731 hx = xf[i__ + 1] - xf[i__];
732 /* * */
733 /* * *** some coefficients *** */
734 coef_uc__ = hx * hy / (hz * 2.);
735 coef_fc__ = hx * hy * hz;
736 /* * */
737 /* * *** the coefficient and source function *** */
738 fc[i__ + (j + k * fc_dim2) * fc_dim1] = coef_fc__ * fcf[i__ +
739 (j + k * fcf_dim2) * fcf_dim1];
740 cc[i__ + (j + k * cc_dim2) * cc_dim1] = coef_fc__ * ccf[i__ +
741 (j + k * ccf_dim2) * ccf_dim1];
742 /* * */
743 /* * *** the diagonal for matvecs and smoothings *** */
744 oc[i__ + (j + k * oc_dim2) * oc_dim1] = coef_uc__ * 32. / 6.;
745 /* * */
746 /* * *** east neighbor *** */
747 /* Computing MIN */
748 i__5 = 1, i__6 = (i__4 = i__ - nxm1, abs(i__4));
749 ike = min(i__5,i__6);
750 oe[i__ + (j + k * oe_dim2) * oe_dim1] = 0.;
751 /* * */
752 /* * *** north neighbor *** */
753 /* Computing MIN */
754 i__5 = 1, i__6 = (i__4 = j - nym1, abs(i__4));
755 jke = min(i__5,i__6);
756 on[i__ + (j + k * on_dim2) * on_dim1] = 0.;
757 /* * */
758 /* * *** up neighbor *** */
759 /* Computing MIN */
760 i__5 = 1, i__6 = (i__4 = k - nzm1, abs(i__4));
761 kke = min(i__5,i__6);
762 uc[i__ + (j + k * uc_dim2) * uc_dim1] = 0.;
763 /* * */
764 /* * *** north-east neighbor *** */
765 /* Computing MIN */
766 i__6 = 1, i__7 = (i__4 = i__ - nxm1, abs(i__4));
767 /* Computing MIN */
768 i__8 = 1, i__9 = (i__5 = j - nym1, abs(i__5));
769 ike = min(i__6,i__7) * min(i__8,i__9);
770 one[i__ + (j + k * one_dim2) * one_dim1] = ike * coef_uc__ *
771 2. / 6.;
772 /* * */
773 /* * *** north-west neighbor *** */
774 /* Computing MIN */
775 i__6 = 1, i__7 = (i__4 = i__ - 2, abs(i__4));
776 /* Computing MIN */
777 i__8 = 1, i__9 = (i__5 = j - nym1, abs(i__5));
778 ike = min(i__6,i__7) * min(i__8,i__9);
779 onw[i__ + (j + k * onw_dim2) * onw_dim1] = ike * coef_uc__ *
780 2. / 6.;
781 /* * */
782 /* * *** up-east neighbor *** */
783 /* Computing MIN */
784 i__6 = 1, i__7 = (i__4 = i__ - nxm1, abs(i__4));
785 /* Computing MIN */
786 i__8 = 1, i__9 = (i__5 = k - nzm1, abs(i__5));
787 ike = min(i__6,i__7) * min(i__8,i__9);
788 ue[i__ + (j + k * ue_dim2) * ue_dim1] = ike * coef_uc__ * 2. /
789 6.;
790 /* * */
791 /* * *** up-west neighbor *** */
792 /* Computing MIN */
793 i__6 = 1, i__7 = (i__4 = i__ - 2, abs(i__4));
794 /* Computing MIN */
795 i__8 = 1, i__9 = (i__5 = k - nzm1, abs(i__5));
796 ike = min(i__6,i__7) * min(i__8,i__9);
797 uw[i__ + (j + k * uw_dim2) * uw_dim1] = ike * coef_uc__ * 2. /
798 6.;
799 /* * */
800 /* * *** up-north neighbor *** */
801 /* Computing MIN */
802 i__6 = 1, i__7 = (i__4 = j - nym1, abs(i__4));
803 /* Computing MIN */
804 i__8 = 1, i__9 = (i__5 = k - nzm1, abs(i__5));
805 ike = min(i__6,i__7) * min(i__8,i__9);
806 un[i__ + (j + k * un_dim2) * un_dim1] = ike * coef_uc__ * 2. /
807 6.;
808 /* * */
809 /* * *** up-south neighbor *** */
810 /* Computing MIN */
811 i__6 = 1, i__7 = (i__4 = j - 2, abs(i__4));
812 /* Computing MIN */
813 i__8 = 1, i__9 = (i__5 = k - nzm1, abs(i__5));
814 ike = min(i__6,i__7) * min(i__8,i__9);
815 us[i__ + (j + k * us_dim2) * us_dim1] = ike * coef_uc__ * 2. /
816 6.;
817 /* * */
818 /* * *** up-north-east neighbor *** */
819 /* Computing MIN */
820 i__7 = 1, i__8 = (i__4 = i__ - nxm1, abs(i__4));
821 /* Computing MIN */
822 i__9 = 1, i__10 = (i__5 = j - nym1, abs(i__5));
823 /* Computing MIN */
824 i__11 = 1, i__12 = (i__6 = k - nzm1, abs(i__6));
825 ike = min(i__7,i__8) * min(i__9,i__10) * min(i__11,i__12);
826 une[i__ + (j + k * une_dim2) * une_dim1] = ike * coef_uc__ *
827 1. / 6.;
828 /* * */
829 /* * *** up-north-west neighbor *** */
830 /* Computing MIN */
831 i__7 = 1, i__8 = (i__4 = i__ - 2, abs(i__4));
832 /* Computing MIN */
833 i__9 = 1, i__10 = (i__5 = j - nym1, abs(i__5));
834 /* Computing MIN */
835 i__11 = 1, i__12 = (i__6 = k - nzm1, abs(i__6));
836 ike = min(i__7,i__8) * min(i__9,i__10) * min(i__11,i__12);
837 unw[i__ + (j + k * unw_dim2) * unw_dim1] = ike * coef_uc__ *
838 1. / 6.;
839 /* * */
840 /* * *** up-south-east neighbor *** */
841 /* Computing MIN */
842 i__7 = 1, i__8 = (i__4 = i__ - nxm1, abs(i__4));
843 /* Computing MIN */
844 i__9 = 1, i__10 = (i__5 = j - 2, abs(i__5));
845 /* Computing MIN */
846 i__11 = 1, i__12 = (i__6 = k - nzm1, abs(i__6));
847 ike = min(i__7,i__8) * min(i__9,i__10) * min(i__11,i__12);
848 use[i__ + (j + k * use_dim2) * use_dim1] = ike * coef_uc__ *
849 1. / 6.;
850 /* * */
851 /* * *** up-south-west neighbor *** */
852 /* Computing MIN */
853 i__7 = 1, i__8 = (i__4 = i__ - 2, abs(i__4));
854 /* Computing MIN */
855 i__9 = 1, i__10 = (i__5 = j - 2, abs(i__5));
856 /* Computing MIN */
857 i__11 = 1, i__12 = (i__6 = k - nzm1, abs(i__6));
858 ike = min(i__7,i__8) * min(i__9,i__10) * min(i__11,i__12);
859 usw[i__ + (j + k * usw_dim2) * usw_dim1] = ike * coef_uc__ *
860 1. / 6.;
861 /* * */
862 /* L12: */
863 }
864 /* L11: */
865 }
866 /* L10: */
867 }
868 /* * */
869 /* * *** return and end *** */
870 return 0;
871 } /* builda_fe__ */
872