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: ElementFile */
18
/* This routine tries to reduce the number of colors used to color elements in the Dudley_ElementFile in */
20
/**************************************************************/
22
#include "ElementFile.h"
25
/**************************************************************/
27
void Dudley_ElementFile_createColoring(Dudley_ElementFile * in, dim_t numNodes, index_t * degreeOfFreedom)
29
dim_t e, i, numUncoloredElements, n, len, NN;
30
index_t *maskDOF, min_id, max_id;
35
if (in->numElements < 1)
39
min_id = Dudley_Util_getMinInt(1, numNodes, degreeOfFreedom);
40
max_id = Dudley_Util_getMaxInt(1, numNodes, degreeOfFreedom);
41
len = max_id - min_id + 1;
42
maskDOF = TMPMEMALLOC(len, index_t);
43
if (!Dudley_checkPtr(maskDOF))
45
#pragma omp parallel for private(e) schedule(static)
46
for (e = 0; e < in->numElements; e++)
48
numUncoloredElements = in->numElements;
50
in->maxColor = in->minColor - 1;
51
while (numUncoloredElements > 0)
53
/* initialize the mask marking nodes used by a color */
54
#pragma omp parallel for private(n) schedule(static)
55
for (n = 0; n < len; n++)
57
numUncoloredElements = 0;
59
for (e = 0; e < in->numElements; e++)
63
/* find out if element e is independend from the elements already colored: */
65
for (i = 0; i < NN; i++)
68
if (in->Nodes[INDEX2(i, e, NN)] < 0 || in->Nodes[INDEX2(i, e, NN)] >= numNodes)
70
printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d in->Nodes[INDEX2...]=%d\n", __FILE__,
71
__LINE__, i, e, NN, min_id, in->Nodes[INDEX2(i, e, NN)]);
74
if ((degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id) >= len
75
|| (degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id) < 0)
77
printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d dof=%d\n", __FILE__, __LINE__, i, e,
78
NN, min_id, degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id);
82
if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id] > 0)
88
/* if e is independend a new color is assigned and the nodes are marked as being used */
91
for (i = 0; i < NN; i++)
92
maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i, e, NN)]] - min_id] = 1;
93
in->Color[e] = in->maxColor + 1;
97
numUncoloredElements++;
103
} /* end of while loop */