/[escript]/trunk-mpi-branch/finley/src/ElementFile.c
ViewVC logotype

Contents of /trunk-mpi-branch/finley/src/ElementFile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1272 - (show annotations)
Fri Aug 24 00:40:43 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/plain
File size: 6515 byte(s)
some bugs in the node-node interpolation fixed
1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* Finley: ElementFile */
16
17 /* allocates an element file to hold elements of type id and with integration order order. */
18 /* use Finley_Mesh_allocElementTable to allocate the element table (Id,Nodes,Tag,Owner). */
19
20 /**************************************************************/
21
22 /* Author: gross@access.edu.au */
23 /* Version: $Id$ */
24
25 /**************************************************************/
26
27 #include "ElementFile.h"
28
29 /**************************************************************/
30
31 Finley_ElementFile* Finley_ElementFile_alloc(ElementTypeId id, index_t order, index_t reduced_order, Paso_MPIInfo *MPIInfo)
32 {
33 extern Finley_RefElementInfo Finley_RefElement_InfoList[];
34 dim_t NQ, reduced_NQ;
35 Finley_ElementFile *out;
36
37 /* get the number of quadrature nodes needed to achieve integration order order: */
38
39 if (order<0) order=MAX(2*Finley_RefElement_InfoList[id].numOrder,0);
40 if (reduced_order<0) reduced_order=MAX(2*(Finley_RefElement_InfoList[id].numOrder-1),0);
41 NQ= Finley_RefElement_InfoList[id].getNumQuadNodes(order);
42 reduced_NQ= Finley_RefElement_InfoList[id].getNumQuadNodes(reduced_order);
43 if (! Finley_noError()) return NULL;
44
45 /* allocate the return value */
46
47 out=MEMALLOC(1,Finley_ElementFile);
48 if (Finley_checkPtr(out)) return NULL;
49 out->order = order;
50 out->reduced_order = reduced_order;
51 out->ReferenceElement=NULL;
52 out->LinearReferenceElement=NULL;
53 out->ReferenceElementReducedOrder=NULL;
54 out->LinearReferenceElementReducedOrder=NULL;
55 out->numElements=0;
56 out->Id=NULL;
57 out->Nodes=NULL;
58 out->Tag=NULL;
59 out->Color=NULL;
60 out->minColor=0;
61 out->maxColor=-1;
62 out->jacobeans=NULL;
63 out->jacobeans_reducedQ=NULL;
64 out->jacobeans_reducedS=NULL;
65 out->jacobeans_reducedS_reducedQ=NULL;
66
67 out->Owner=NULL;
68 out->MPIInfo = Paso_MPIInfo_getReference( MPIInfo );
69
70 /* allocate the reference element: */
71
72 out->ReferenceElement=Finley_RefElement_alloc(id,NQ);
73 out->jacobeans=Finley_ElementFile_Jacobeans_alloc(out->ReferenceElement);
74 out->ReferenceElementReducedOrder=Finley_RefElement_alloc(id,reduced_NQ);
75 out->jacobeans_reducedQ=Finley_ElementFile_Jacobeans_alloc(out->ReferenceElementReducedOrder);
76
77 out->LinearReferenceElement=Finley_RefElement_alloc(Finley_RefElement_InfoList[id].LinearTypeId,NQ);
78 out->jacobeans_reducedS=Finley_ElementFile_Jacobeans_alloc(out->LinearReferenceElement);
79 out->LinearReferenceElementReducedOrder=Finley_RefElement_alloc(Finley_RefElement_InfoList[id].LinearTypeId,reduced_NQ);
80 out->jacobeans_reducedS_reducedQ=Finley_ElementFile_Jacobeans_alloc(out->LinearReferenceElementReducedOrder);
81
82 out->numNodes=out->ReferenceElement->Type->numNodes;
83
84 if (! Finley_noError()) {
85 Finley_ElementFile_free(out);
86 return NULL;
87 }
88 return out;
89 }
90
91 /* deallocates an element file: */
92
93 void Finley_ElementFile_free(Finley_ElementFile* in) {
94 if (in!=NULL) {
95 #ifdef Finley_TRACE
96 if (in->ReferenceElement!=NULL) printf("element file for %s is deallocated.\n",in->ReferenceElement->Type->Name);
97 #endif
98 Finley_ElementFile_freeTable(in);
99 Finley_RefElement_dealloc(in->ReferenceElement);
100 Finley_RefElement_dealloc(in->ReferenceElementReducedOrder);
101 Finley_RefElement_dealloc(in->LinearReferenceElement);
102 Finley_RefElement_dealloc(in->LinearReferenceElementReducedOrder);
103 Finley_ElementFile_Jacobeans_dealloc(in->jacobeans);
104 Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS);
105 Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedQ);
106 Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS_reducedQ);
107 Paso_MPIInfo_free( in->MPIInfo );
108 MEMFREE(in);
109 }
110 }
111 void Finley_ElementFile_setElementDistribution(Finley_ElementFile* in, dim_t* distribution) {
112 dim_t local_num_elements,e,out,num_elements=0, size;
113 Paso_MPI_rank myRank;
114 if (in == NULL) {
115 distribution[0]=num_elements;
116 } else {
117 if (in->MPIInfo->size>1) {
118 num_elements=0;
119 myRank=in->MPIInfo->rank;
120 size=in->MPIInfo->size;
121 #pragma omp parallel private(local_num_elements)
122 {
123 local_num_elements=0;
124 #pragma omp for private(e)
125 for (e=0;e<in->numElements;e++) {
126 if (in->Owner[e] == myRank) local_num_elements++;
127 }
128 #pragma omp critical
129 num_elements+=local_num_elements;
130 }
131 #ifdef PASO_MPI
132 MPI_Allgather(&num_elements,1,MPI_INT,distribution,1,MPI_INT,in->MPIInfo->comm);
133 #else
134 distribution[0]=num_elements;
135 #endif
136 } else {
137 distribution[0]=in->numElements;
138 }
139 }
140 }
141
142 dim_t Finley_ElementFile_getGlobalNumElements(Finley_ElementFile* in) {
143 dim_t size, *distribution=NULL, out, p;
144 if (in == NULL) {
145 return 0;
146 } else {
147 size=in->MPIInfo->size;
148 distribution=TMPMEMALLOC(size,dim_t);
149 Finley_ElementFile_setElementDistribution(in,distribution);
150 out=0;
151 for (p=0;p<size;++p) out+=distribution[p];
152 TMPMEMFREE(distribution);
153 return out;
154 }
155 }
156 dim_t Finley_ElementFile_getMyNumElements(Finley_ElementFile* in) {
157 dim_t size, *distribution=NULL, out, p;
158 if (in == NULL) {
159 return 0;
160 } else {
161 size=in->MPIInfo->size;
162 distribution=TMPMEMALLOC(size,dim_t);
163 Finley_ElementFile_setElementDistribution(in,distribution);
164 out=distribution[in->MPIInfo->rank];
165 TMPMEMFREE(distribution);
166 return out;
167 }
168
169 }
170 index_t Finley_ElementFile_getFirstElement(Finley_ElementFile* in){
171 dim_t size, *distribution=NULL, out, p;
172 if (in == NULL) {
173 return 0;
174 } else {
175 size=in->MPIInfo->size;
176 distribution=TMPMEMALLOC(size,dim_t);
177 Finley_ElementFile_setElementDistribution(in,distribution);
178 out=0;
179 for (p=0;p<in->MPIInfo->rank;++p) out+=distribution[p];
180 TMPMEMFREE(distribution);
181 return out;
182 }
183 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26