2
/*******************************************************
4
* Copyright (c) 2003-2010 by University of Queensland
5
* Earth Systems Science Computational Center (ESSCC)
6
* http://www.uq.edu.au/esscc
8
* Primary Business: Queensland, Australia
9
* Licensed under the Open Software License version 3.0
10
* http://www.opensource.org/licenses/osl-3.0.php
12
*******************************************************/
14
/**************************************************************/
16
/* Dudley: Converting an element list into a matrix shape */
18
/**************************************************************/
20
#include "IndexList.h"
22
/* Translate from distributed/local array indices to global indices */
24
/**************************************************************/
25
/* inserts the contributions from the element matrices of elements
26
into the row index col. If symmetric is set, only the upper
27
triangle of the matrix is stored. */
29
void Dudley_IndexList_insertElements(Dudley_IndexList * index_list, Dudley_ElementFile * elements,
30
bool_t reduce_row_order, index_t * row_map,
31
bool_t reduce_col_order, index_t * col_map)
33
/* index_list is an array of linked lists. Each entry is a row (DOF) and contains the indices to the non-zero columns */
35
dim_t e, kr, kc, NN_row, NN_col, icol, irow, NN;
38
NN = elements->numNodes;
39
NN_col = (elements->numShapes);
40
NN_row = (elements->numShapes);
42
for (color = elements->minColor; color <= elements->maxColor; color++)
44
#pragma omp for private(e,irow,kr,kc,icol) schedule(static)
45
for (e = 0; e < elements->numElements; e++)
47
if (elements->Color[e] == color)
49
for (kr = 0; kr < NN_row; kr++)
51
irow = row_map[elements->Nodes[INDEX2(kr, e, NN)]];
52
for (kc = 0; kc < NN_col; kc++)
54
icol = col_map[elements->Nodes[INDEX2(kc, e, NN)]];
55
Dudley_IndexList_insertIndex(&(index_list[irow]), icol);
65
void Dudley_IndexList_insertElementsWithRowRange(Dudley_IndexList * index_list, index_t firstRow, index_t lastRow,
66
Dudley_ElementFile * elements, index_t * row_map, index_t * col_map)
68
/* this does not resolve macro elements */
70
dim_t e, kr, kc, icol, irow, NN;
73
NN = elements->numNodes;
74
for (color = elements->minColor; color <= elements->maxColor; color++)
76
#pragma omp for private(e,irow,kr,kc,icol) schedule(static)
77
for (e = 0; e < elements->numElements; e++)
79
if (elements->Color[e] == color)
81
for (kr = 0; kr < NN; kr++)
83
irow = row_map[elements->Nodes[INDEX2(kr, e, NN)]];
84
if ((firstRow <= irow) && (irow < lastRow))
87
for (kc = 0; kc < NN; kc++)
89
icol = col_map[elements->Nodes[INDEX2(kc, e, NN)]];
90
Dudley_IndexList_insertIndex(&(index_list[irow]), icol);
100
void Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(Dudley_IndexList * index_list, index_t firstRow,
101
index_t lastRow, Dudley_ElementFile * elements,
102
index_t * row_map, index_t * col_map)
104
/* this does not resolve macro elements */
106
dim_t e, kr, kc, icol, irow, NN, irow_loc;
107
if (elements != NULL)
109
NN = elements->numNodes;
110
for (color = elements->minColor; color <= elements->maxColor; color++)
112
#pragma omp for private(e,irow,kr,kc,icol,irow_loc) schedule(static)
113
for (e = 0; e < elements->numElements; e++)
115
if (elements->Color[e] == color)
117
for (kr = 0; kr < NN; kr++)
119
irow = row_map[elements->Nodes[INDEX2(kr, e, NN)]];
120
if ((firstRow <= irow) && (irow < lastRow))
122
irow_loc = irow - firstRow;
123
for (kc = 0; kc < NN; kc++)
125
icol = col_map[elements->Nodes[INDEX2(kc, e, NN)]];
127
Dudley_IndexList_insertIndex(&(index_list[irow_loc]), icol);
137
/* inserts row index row into the Dudley_IndexList in if it does not exist */
139
void Dudley_IndexList_insertIndex(Dudley_IndexList * in, index_t index)
142
/* is index in in? */
143
for (i = 0; i < in->n; i++)
145
if (in->index[i] == index)
148
/* index could not be found */
149
if (in->n == INDEXLIST_LENGTH)
151
/* if in->index is full check the extension */
152
if (in->extension == NULL)
154
in->extension = TMPMEMALLOC(1, Dudley_IndexList);
155
if (Dudley_checkPtr(in->extension))
157
in->extension->n = 0;
158
in->extension->extension = NULL;
160
Dudley_IndexList_insertIndex(in->extension, index);
164
/* insert index into in->index */
165
in->index[in->n] = index;
170
/* counts the number of row indices in the Dudley_IndexList in */
172
dim_t Dudley_IndexList_count(Dudley_IndexList * in, index_t range_min, index_t range_max)
176
register index_t itmp;
183
for (i = 0; i < in->n; i++)
186
if ((itmp >= range_min) && (range_max > itmp))
189
return out + Dudley_IndexList_count(in->extension, range_min, range_max);
193
/* count the number of row indices in the Dudley_IndexList in */
195
void Dudley_IndexList_toArray(Dudley_IndexList * in, index_t * array, index_t range_min, index_t range_max,
196
index_t index_offset)
199
register index_t itmp;
203
for (i = 0; i < in->n; i++)
206
if ((itmp >= range_min) && (range_max > itmp))
208
array[ptr] = itmp + index_offset;
213
Dudley_IndexList_toArray(in->extension, &(array[ptr]), range_min, range_max, index_offset);
217
/* deallocates the Dudley_IndexList in by recursive calls */
219
void Dudley_IndexList_free(Dudley_IndexList * in)
223
Dudley_IndexList_free(in->extension);
228
/* creates a Paso_pattern from a range of indices */
229
Paso_Pattern *Dudley_IndexList_createPattern(dim_t n0, dim_t n, Dudley_IndexList * index_list, index_t range_min,
230
index_t range_max, index_t index_offset)
233
register dim_t s, i, itmp;
234
index_t *index = NULL;
235
Paso_Pattern *out = NULL;
237
ptr = MEMALLOC(n + 1 - n0, index_t);
238
if (!Dudley_checkPtr(ptr))
240
/* get the number of connections per row */
241
#pragma omp parallel for schedule(static) private(i)
242
for (i = n0; i < n; ++i)
244
ptr[i - n0] = Dudley_IndexList_count(&index_list[i], range_min, range_max);
248
for (i = n0; i < n; ++i)
256
index = MEMALLOC(ptr[n - n0], index_t);
257
if (!Dudley_checkPtr(index))
259
#pragma omp parallel for schedule(static)
260
for (i = n0; i < n; ++i)
262
Dudley_IndexList_toArray(&index_list[i], &index[ptr[i - n0]], range_min, range_max, index_offset);
264
out = Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT, n - n0, range_max + index_offset, ptr, index);
267
if (!Dudley_noError())
271
Paso_Pattern_free(out);