1 /*  misc.C  */
2 
3 #include "../EGraph.h"
4 
5 #define MYDEBUG 0
6 
7 /*--------------------------------------------------------------------*/
8 /*
9    --------------------------------------------------------------
10    make an element graph for a n1 x n2 grid with ncomp components
11 
12    created -- 95nov03, cca
13    --------------------------------------------------------------
14 */
15 EGraph *
EGraph_make9P(int n1,int n2,int ncomp)16 EGraph_make9P (
17    int   n1,
18    int   n2,
19    int   ncomp
20 ) {
21 EGraph    *egraph ;
22 int       eid, icomp, ij, ielem, jelem, m, nelem, nvtx ;
23 int       *list ;
24 #if MYDEBUG > 0
25 fprintf(stdout, "\n inside EGraph_make9P(%d,%d,%d)", n1, n2, ncomp) ;
26 fflush(stdout) ;
27 #endif
28 /*
29    ---------------
30    check the input
31    ---------------
32 */
33 if ( n1 <= 0 || n2 <= 0 || ncomp <= 0 ) {
34    fprintf(stderr, "\n fatal error in EGraph_make9P(%d,%d,%d)"
35            "\n bad input\n", n1, n2, ncomp) ;
36    exit(-1) ;
37 }
38 /*
39    -----------------
40    create the object
41    -----------------
42 */
43 nelem = (n1 - 1)*(n2 - 1) ;
44 nvtx  = n1*n2*ncomp ;
45 egraph = EGraph_new() ;
46 if ( ncomp == 1 ) {
47    EGraph_init(egraph, 0, nelem, nvtx, IVL_CHUNKED) ;
48 } else {
49    EGraph_init(egraph, 1, nelem, nvtx, IVL_CHUNKED) ;
50    IVfill(nvtx, egraph->vwghts, ncomp) ;
51 }
52 /*
53    ----------------------------
54    fill the adjacency structure
55    ----------------------------
56 */
57 list = IVinit(4*ncomp, -1) ;
58 for ( jelem = 0 ; jelem < n2 - 1 ; jelem++ ) {
59    for ( ielem = 0 ; ielem < n1 - 1 ; ielem++ ) {
60       eid   = ielem + jelem * (n1 - 1) ;
61       m  = 0 ;
62       ij = ncomp*(ielem + jelem*n1) ;
63       for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
64          list[m++] = ij++ ;
65       }
66       ij = ncomp*(ielem + 1 + jelem*n1) ;
67       for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
68          list[m++] = ij++ ;
69       }
70       ij = ncomp*(ielem + (jelem+1)*n1) ;
71       for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
72          list[m++] = ij++ ;
73       }
74       ij = ncomp*(ielem + 1 + (jelem+1)*n1) ;
75       for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
76          list[m++] = ij++ ;
77       }
78       IVqsortUp(m, list) ;
79       IVL_setList(egraph->adjIVL, eid, m, list) ;
80    }
81 }
82 IVfree(list) ;
83 
84 return(egraph) ; }
85 
86 /*--------------------------------------------------------------------*/
87 /*
88    -------------------------------------------------------------------
89    make an element graph for a n1 x n2 x n3 grid with ncomp components
90 
91    created -- 95nov03, cca
92    -------------------------------------------------------------------
93 */
94 EGraph *
EGraph_make27P(int n1,int n2,int n3,int ncomp)95 EGraph_make27P (
96    int   n1,
97    int   n2,
98    int   n3,
99    int   ncomp
100 ) {
101 EGraph    *egraph ;
102 int       eid, icomp, ijk, ielem, jelem, kelem, m, nelem, nvtx ;
103 int       *list ;
104 /*
105    ---------------
106    check the input
107    ---------------
108 */
109 if ( n1 <= 0 || n2 <= 0 || n3 <= 0 || ncomp <= 0 ) {
110    fprintf(stderr, "\n fatal error in EGraph_make27P(%d,%d,%d,%d)"
111            "\n bad input\n", n1, n2, n3, ncomp) ;
112    exit(-1) ;
113 }
114 #if MYDEBUG > 0
115 fprintf(stdout, "\n inside EGraph_make27P(%d,%d,%d,%d)",
116         n1, n2, n3, ncomp) ;
117 fflush(stdout) ;
118 #endif
119 /*
120    -----------------
121    create the object
122    -----------------
123 */
124 nelem = (n1 - 1)*(n2 - 1)*(n3 - 1) ;
125 nvtx  = n1*n2*n3*ncomp ;
126 egraph = EGraph_new() ;
127 if ( ncomp == 1 ) {
128    EGraph_init(egraph, 0, nelem, nvtx, IVL_CHUNKED) ;
129 } else {
130    EGraph_init(egraph, 1, nelem, nvtx, IVL_CHUNKED) ;
131    IVfill(nvtx, egraph->vwghts, ncomp) ;
132 }
133 /*
134    ----------------------------
135    fill the adjacency structure
136    ----------------------------
137 */
138 list = IVinit(8*ncomp, -1) ;
139 for ( kelem = 0 ; kelem < n3 - 1 ; kelem++ ) {
140    for ( jelem = 0 ; jelem < n2 - 1 ; jelem++ ) {
141       for ( ielem = 0 ; ielem < n1 - 1 ; ielem++ ) {
142          eid   = ielem + jelem*(n1-1) + kelem*(n1-1)*(n2-1);
143          m   = 0 ;
144          ijk = ncomp*(ielem + jelem*n1 + kelem*n1*n2) ;
145          for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
146             list[m++] = ijk++ ;
147          }
148          ijk = ncomp*(ielem + 1 + jelem*n1 + kelem*n1*n2) ;
149          for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
150             list[m++] = ijk++ ;
151          }
152          ijk = ncomp*(ielem + (jelem+1)*n1 + kelem*n1*n2) ;
153          for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
154             list[m++] = ijk++ ;
155          }
156          ijk = ncomp*(ielem + 1 + (jelem+1)*n1 + kelem*n1*n2) ;
157          for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
158             list[m++] = ijk++ ;
159          }
160          ijk = ncomp*(ielem + jelem*n1 + (kelem+1)*n1*n2) ;
161          for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
162             list[m++] = ijk++ ;
163          }
164          ijk = ncomp*(ielem + 1 + jelem*n1 + (kelem+1)*n1*n2) ;
165          for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
166             list[m++] = ijk++ ;
167          }
168          ijk = ncomp*(ielem + (jelem+1)*n1 + (kelem+1)*n1*n2) ;
169          for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
170             list[m++] = ijk++ ;
171          }
172          ijk = ncomp*(ielem + 1 + (jelem+1)*n1 + (kelem+1)*n1*n2) ;
173          for ( icomp = 0 ; icomp < ncomp ; icomp++ ) {
174             list[m++] = ijk++ ;
175          }
176          IVqsortUp(m, list) ;
177          IVL_setList(egraph->adjIVL, eid, m, list) ;
178       }
179    }
180 }
181 IVfree(list) ;
182 
183 return(egraph) ; }
184 
185 /*--------------------------------------------------------------------*/
186