1 |
ksteube |
1315 |
|
2 |
|
|
/* $Id$ */ |
3 |
|
|
|
4 |
|
|
/******************************************************* |
5 |
|
|
* |
6 |
|
|
* Copyright 2003-2007 by ACceSS MNRF |
7 |
|
|
* Copyright 2007 by University of Queensland |
8 |
|
|
* |
9 |
|
|
* http://esscc.uq.edu.au |
10 |
|
|
* Primary Business: Queensland, Australia |
11 |
|
|
* Licensed under the Open Software License version 3.0 |
12 |
|
|
* http://www.opensource.org/licenses/osl-3.0.php |
13 |
|
|
* |
14 |
|
|
*******************************************************/ |
15 |
|
|
|
16 |
|
|
/**************************************************************/ |
17 |
|
|
/* */ |
18 |
|
|
/* Finley: ElementFile */ |
19 |
|
|
/* */ |
20 |
|
|
/* This routine tries to reduce the number of colors used to color elements in the Finley_ElementFile in */ |
21 |
|
|
/* */ |
22 |
|
|
/**************************************************************/ |
23 |
|
|
|
24 |
|
|
#include "ElementFile.h" |
25 |
|
|
#include "Util.h" |
26 |
|
|
|
27 |
|
|
/**************************************************************/ |
28 |
|
|
|
29 |
|
|
void Finley_ElementFile_createColoring(Finley_ElementFile* in,dim_t numNodes, index_t* degreeOfFreedom) { |
30 |
|
|
dim_t e,i,numUncoloredElements,n,len,NN; |
31 |
|
|
index_t *maskDOF,color,min_id,max_id; |
32 |
|
|
bool_t independent; |
33 |
|
|
|
34 |
|
|
if (in==NULL) return; |
35 |
|
|
if (in->numElements<1) return; |
36 |
|
|
NN=in->numNodes; |
37 |
|
|
|
38 |
|
|
min_id=Finley_Util_getMinInt(1,numNodes,degreeOfFreedom); |
39 |
|
|
max_id=Finley_Util_getMaxInt(1,numNodes,degreeOfFreedom); |
40 |
|
|
len=max_id-min_id+1; |
41 |
|
|
maskDOF=TMPMEMALLOC(len,index_t); |
42 |
|
|
if (! Finley_checkPtr(maskDOF) ) { |
43 |
|
|
#pragma omp parallel for private(e) schedule(static) |
44 |
|
|
for (e=0;e<in->numElements;e++) in->Color[e]=-1; |
45 |
|
|
numUncoloredElements=in->numElements; |
46 |
gross |
1335 |
in->minColor=0; |
47 |
|
|
in->maxColor=in->minColor-1; |
48 |
ksteube |
1315 |
while (numUncoloredElements>0) { |
49 |
|
|
/* initialize the mask marking nodes used by a color */ |
50 |
|
|
#pragma omp parallel for private(n) schedule(static) |
51 |
|
|
for (n=0;n<len;n++) maskDOF[n]=-1; |
52 |
|
|
numUncoloredElements=0; |
53 |
|
|
/* OMP ?*/ |
54 |
|
|
for (e=0;e<in->numElements;e++) { |
55 |
|
|
if (in->Color[e]<0) { |
56 |
|
|
/* find out if element e is independend from the elements already colored: */ |
57 |
|
|
independent=TRUE; |
58 |
ksteube |
1326 |
for (i=0;i<NN;i++) { |
59 |
|
|
#ifdef BOUNDS_CHECK |
60 |
ksteube |
1340 |
if (in->Nodes[INDEX2(i,e,NN)] < 0 || in->Nodes[INDEX2(i,e,NN)] >= numNodes) { printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d in->Nodes[INDEX2...]=%d\n", __FILE__, __LINE__, i, e, NN, min_id, in->Nodes[INDEX2(i,e,NN)]); exit(1); } |
61 |
ksteube |
1326 |
if ((degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id) >= len || (degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id) < 0) { printf("BOUNDS_CHECK %s %d i=%d e=%d NN=%d min_id=%d dof=%d\n", __FILE__, __LINE__, i, e, NN, min_id, degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id); exit(1); } |
62 |
|
|
#endif |
63 |
gross |
1335 |
if (maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]>0) { |
64 |
|
|
independent=FALSE; |
65 |
|
|
break; |
66 |
|
|
} |
67 |
ksteube |
1326 |
} |
68 |
ksteube |
1315 |
/* if e is independend a new color is assigned and the nodes are marked as being used */ |
69 |
|
|
if (independent) { |
70 |
gross |
1335 |
for (i=0;i<NN;i++) maskDOF[degreeOfFreedom[in->Nodes[INDEX2(i,e,NN)]]-min_id]=1; |
71 |
|
|
in->Color[e]=in->maxColor+1; |
72 |
|
|
} else { |
73 |
|
|
numUncoloredElements++; |
74 |
|
|
} |
75 |
ksteube |
1315 |
} |
76 |
gross |
1358 |
|
77 |
ksteube |
1315 |
} |
78 |
|
|
in->maxColor++; |
79 |
|
|
} /* end of while loop */ |
80 |
|
|
} |
81 |
|
|
/* all done : */ |
82 |
|
|
TMPMEMFREE(maskDOF); |
83 |
|
|
} |