1 |
jgs |
150 |
|
2 |
ksteube |
1312 |
/* $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 |
jgs |
82 |
/**************************************************************/ |
17 |
|
|
|
18 |
|
|
/* Finley: ElementFile */ |
19 |
|
|
|
20 |
|
|
/* allocates an element file to hold elements of type id and with integration order order. */ |
21 |
ksteube |
1312 |
/* use Finley_Mesh_allocElementTable to allocate the element table (Id,Nodes,Tag,Owner). */ |
22 |
jgs |
82 |
|
23 |
|
|
/**************************************************************/ |
24 |
|
|
|
25 |
|
|
#include "ElementFile.h" |
26 |
|
|
|
27 |
|
|
/**************************************************************/ |
28 |
|
|
|
29 |
gross |
1062 |
Finley_ElementFile* Finley_ElementFile_alloc(ElementTypeId id, index_t order, index_t reduced_order, Paso_MPIInfo *MPIInfo) |
30 |
bcumming |
730 |
{ |
31 |
jgs |
82 |
extern Finley_RefElementInfo Finley_RefElement_InfoList[]; |
32 |
gross |
1062 |
dim_t NQ, reduced_NQ; |
33 |
jgs |
82 |
Finley_ElementFile *out; |
34 |
|
|
|
35 |
|
|
/* get the number of quadrature nodes needed to achieve integration order order: */ |
36 |
|
|
|
37 |
gross |
1062 |
if (order<0) order=MAX(2*Finley_RefElement_InfoList[id].numOrder,0); |
38 |
|
|
if (reduced_order<0) reduced_order=MAX(2*(Finley_RefElement_InfoList[id].numOrder-1),0); |
39 |
jgs |
82 |
NQ= Finley_RefElement_InfoList[id].getNumQuadNodes(order); |
40 |
gross |
1062 |
reduced_NQ= Finley_RefElement_InfoList[id].getNumQuadNodes(reduced_order); |
41 |
jgs |
150 |
if (! Finley_noError()) return NULL; |
42 |
jgs |
82 |
|
43 |
|
|
/* allocate the return value */ |
44 |
|
|
|
45 |
jgs |
102 |
out=MEMALLOC(1,Finley_ElementFile); |
46 |
jgs |
82 |
if (Finley_checkPtr(out)) return NULL; |
47 |
gross |
1062 |
out->order = order; |
48 |
|
|
out->reduced_order = reduced_order; |
49 |
jgs |
82 |
out->ReferenceElement=NULL; |
50 |
|
|
out->LinearReferenceElement=NULL; |
51 |
gross |
1062 |
out->ReferenceElementReducedOrder=NULL; |
52 |
|
|
out->LinearReferenceElementReducedOrder=NULL; |
53 |
jgs |
82 |
out->numElements=0; |
54 |
|
|
out->Id=NULL; |
55 |
|
|
out->Nodes=NULL; |
56 |
|
|
out->Tag=NULL; |
57 |
|
|
out->Color=NULL; |
58 |
jgs |
123 |
out->minColor=0; |
59 |
|
|
out->maxColor=-1; |
60 |
gross |
777 |
out->jacobeans=NULL; |
61 |
|
|
out->jacobeans_reducedQ=NULL; |
62 |
|
|
out->jacobeans_reducedS=NULL; |
63 |
|
|
out->jacobeans_reducedS_reducedQ=NULL; |
64 |
jgs |
82 |
|
65 |
ksteube |
1312 |
out->Owner=NULL; |
66 |
bcumming |
730 |
out->MPIInfo = Paso_MPIInfo_getReference( MPIInfo ); |
67 |
gross |
532 |
|
68 |
jgs |
82 |
/* allocate the reference element: */ |
69 |
|
|
|
70 |
|
|
out->ReferenceElement=Finley_RefElement_alloc(id,NQ); |
71 |
gross |
777 |
out->jacobeans=Finley_ElementFile_Jacobeans_alloc(out->ReferenceElement); |
72 |
gross |
1062 |
out->ReferenceElementReducedOrder=Finley_RefElement_alloc(id,reduced_NQ); |
73 |
|
|
out->jacobeans_reducedQ=Finley_ElementFile_Jacobeans_alloc(out->ReferenceElementReducedOrder); |
74 |
gross |
777 |
|
75 |
jgs |
82 |
out->LinearReferenceElement=Finley_RefElement_alloc(Finley_RefElement_InfoList[id].LinearTypeId,NQ); |
76 |
gross |
777 |
out->jacobeans_reducedS=Finley_ElementFile_Jacobeans_alloc(out->LinearReferenceElement); |
77 |
gross |
1062 |
out->LinearReferenceElementReducedOrder=Finley_RefElement_alloc(Finley_RefElement_InfoList[id].LinearTypeId,reduced_NQ); |
78 |
|
|
out->jacobeans_reducedS_reducedQ=Finley_ElementFile_Jacobeans_alloc(out->LinearReferenceElementReducedOrder); |
79 |
ksteube |
1312 |
|
80 |
|
|
out->numNodes=out->ReferenceElement->Type->numNodes; |
81 |
|
|
|
82 |
jgs |
150 |
if (! Finley_noError()) { |
83 |
ksteube |
1312 |
Finley_ElementFile_free(out); |
84 |
jgs |
82 |
return NULL; |
85 |
|
|
} |
86 |
|
|
return out; |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
/* deallocates an element file: */ |
90 |
|
|
|
91 |
ksteube |
1312 |
void Finley_ElementFile_free(Finley_ElementFile* in) { |
92 |
jgs |
82 |
if (in!=NULL) { |
93 |
|
|
#ifdef Finley_TRACE |
94 |
|
|
if (in->ReferenceElement!=NULL) printf("element file for %s is deallocated.\n",in->ReferenceElement->Type->Name); |
95 |
|
|
#endif |
96 |
ksteube |
1312 |
Finley_ElementFile_freeTable(in); |
97 |
jgs |
82 |
Finley_RefElement_dealloc(in->ReferenceElement); |
98 |
gross |
1062 |
Finley_RefElement_dealloc(in->ReferenceElementReducedOrder); |
99 |
jgs |
82 |
Finley_RefElement_dealloc(in->LinearReferenceElement); |
100 |
gross |
1062 |
Finley_RefElement_dealloc(in->LinearReferenceElementReducedOrder); |
101 |
gross |
776 |
Finley_ElementFile_Jacobeans_dealloc(in->jacobeans); |
102 |
|
|
Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS); |
103 |
|
|
Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedQ); |
104 |
|
|
Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS_reducedQ); |
105 |
ksteube |
1312 |
Paso_MPIInfo_free( in->MPIInfo ); |
106 |
jgs |
82 |
MEMFREE(in); |
107 |
|
|
} |
108 |
|
|
} |
109 |
ksteube |
1312 |
void Finley_ElementFile_setElementDistribution(Finley_ElementFile* in, dim_t* distribution) { |
110 |
phornby |
1628 |
dim_t local_num_elements,e,num_elements=0, size; |
111 |
ksteube |
1312 |
Paso_MPI_rank myRank; |
112 |
|
|
if (in == NULL) { |
113 |
|
|
distribution[0]=num_elements; |
114 |
|
|
} else { |
115 |
|
|
if (in->MPIInfo->size>1) { |
116 |
|
|
num_elements=0; |
117 |
|
|
myRank=in->MPIInfo->rank; |
118 |
|
|
size=in->MPIInfo->size; |
119 |
|
|
#pragma omp parallel private(local_num_elements) |
120 |
|
|
{ |
121 |
|
|
local_num_elements=0; |
122 |
|
|
#pragma omp for private(e) |
123 |
|
|
for (e=0;e<in->numElements;e++) { |
124 |
|
|
if (in->Owner[e] == myRank) local_num_elements++; |
125 |
|
|
} |
126 |
|
|
#pragma omp critical |
127 |
|
|
num_elements+=local_num_elements; |
128 |
|
|
} |
129 |
|
|
#ifdef PASO_MPI |
130 |
|
|
MPI_Allgather(&num_elements,1,MPI_INT,distribution,1,MPI_INT,in->MPIInfo->comm); |
131 |
|
|
#else |
132 |
|
|
distribution[0]=num_elements; |
133 |
|
|
#endif |
134 |
|
|
} else { |
135 |
|
|
distribution[0]=in->numElements; |
136 |
|
|
} |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
dim_t Finley_ElementFile_getGlobalNumElements(Finley_ElementFile* in) { |
141 |
|
|
dim_t size, *distribution=NULL, out, p; |
142 |
|
|
if (in == NULL) { |
143 |
|
|
return 0; |
144 |
|
|
} else { |
145 |
|
|
size=in->MPIInfo->size; |
146 |
|
|
distribution=TMPMEMALLOC(size,dim_t); |
147 |
|
|
Finley_ElementFile_setElementDistribution(in,distribution); |
148 |
|
|
out=0; |
149 |
|
|
for (p=0;p<size;++p) out+=distribution[p]; |
150 |
|
|
TMPMEMFREE(distribution); |
151 |
|
|
return out; |
152 |
|
|
} |
153 |
|
|
} |
154 |
|
|
dim_t Finley_ElementFile_getMyNumElements(Finley_ElementFile* in) { |
155 |
phornby |
1628 |
dim_t size, *distribution=NULL, out; |
156 |
ksteube |
1312 |
if (in == NULL) { |
157 |
|
|
return 0; |
158 |
|
|
} else { |
159 |
|
|
size=in->MPIInfo->size; |
160 |
|
|
distribution=TMPMEMALLOC(size,dim_t); |
161 |
|
|
Finley_ElementFile_setElementDistribution(in,distribution); |
162 |
|
|
out=distribution[in->MPIInfo->rank]; |
163 |
|
|
TMPMEMFREE(distribution); |
164 |
|
|
return out; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
} |
168 |
|
|
index_t Finley_ElementFile_getFirstElement(Finley_ElementFile* in){ |
169 |
|
|
dim_t size, *distribution=NULL, out, p; |
170 |
|
|
if (in == NULL) { |
171 |
|
|
return 0; |
172 |
|
|
} else { |
173 |
|
|
size=in->MPIInfo->size; |
174 |
|
|
distribution=TMPMEMALLOC(size,dim_t); |
175 |
|
|
Finley_ElementFile_setElementDistribution(in,distribution); |
176 |
|
|
out=0; |
177 |
|
|
for (p=0;p<in->MPIInfo->rank;++p) out+=distribution[p]; |
178 |
|
|
TMPMEMFREE(distribution); |
179 |
|
|
return out; |
180 |
|
|
} |
181 |
|
|
} |