/[escript]/trunk/dudley/src/ElementFile.c
ViewVC logotype

Contents of /trunk/dudley/src/ElementFile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3196 - (show annotations)
Wed Sep 22 01:18:52 2010 UTC (9 years, 1 month ago) by jfenwick
Original Path: branches/domexper/dudley/src/ElementFile.c
File MIME type: text/plain
File size: 5250 byte(s)
moving slowly
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
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
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Dudley: ElementFile */
18
19 /* allocates an element file to hold elements of type id and with integration order order. */
20 /* use Dudley_Mesh_allocElementTable to allocate the element table (Id,Nodes,Tag,Owner). */
21
22 /**************************************************************/
23
24 #include "ElementFile.h"
25
26 /**************************************************************/
27
28 Dudley_ElementFile* Dudley_ElementFile_alloc(Dudley_ReferenceElementSet* referenceElementSet, Paso_MPIInfo *MPIInfo)
29 {
30 Dudley_ElementFile *out;
31
32
33 if (! Dudley_noError()) return NULL;
34
35 /* allocate the return value */
36
37 out=MEMALLOC(1,Dudley_ElementFile);
38 if (Dudley_checkPtr(out)) return NULL;
39 out->referenceElementSet=Dudley_ReferenceElementSet_reference(referenceElementSet);
40 out->numElements=0;
41 out->Id=NULL;
42 out->Nodes=NULL;
43 out->Tag=NULL;
44 out->Color=NULL;
45 out->minColor=0;
46 out->maxColor=-1;
47 out->jacobeans=NULL;
48 out->jacobeans_reducedQ=NULL;
49 // out->jacobeans_reducedS=NULL;
50 // out->jacobeans_reducedS_reducedQ=NULL;
51
52 out->Owner=NULL;
53 out->numTagsInUse=0;
54 out->tagsInUse=NULL;
55
56 out->MPIInfo = Paso_MPIInfo_getReference( MPIInfo );
57
58 out->jacobeans=Dudley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElement->BasisFunctions);
59 out->jacobeans_reducedQ=Dudley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElementReducedQuadrature->BasisFunctions);
60 /*
61 out->jacobeans_reducedS=Dudley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElement->BasisFunctions);
62 out->jacobeans_reducedS_reducedQ=Dudley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElementReducedQuadrature->BasisFunctions);
63 */
64
65
66 // out->jacobeans_reducedS=out->jacobeans;
67 // out->jacobeans_reducedS_reducedQ=out->jacobeans_reducedQ;
68 if (! Dudley_noError()) {
69 Dudley_ElementFile_free(out);
70 return NULL;
71 }
72 out->numNodes=out->referenceElementSet->numNodes;
73 out->numDim=referenceElementSet->referenceElement->BasisFunctions->Type->numDim;
74 return out;
75 }
76
77 /* deallocates an element file: */
78
79 void Dudley_ElementFile_free(Dudley_ElementFile* in) {
80 if (in!=NULL) {
81 Dudley_ElementFile_freeTable(in);
82 Dudley_ReferenceElementSet_dealloc(in->referenceElementSet);
83 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans);
84 /*
85 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS);
86 */
87 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedQ);
88 /*
89 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS_reducedQ);
90 */
91 Paso_MPIInfo_free( in->MPIInfo );
92 MEMFREE(in);
93 }
94 }
95 void Dudley_ElementFile_setElementDistribution(Dudley_ElementFile* in, dim_t* distribution) {
96 dim_t local_num_elements,e,num_elements=0, size;
97 Paso_MPI_rank myRank;
98 if (in == NULL) {
99 distribution[0]=num_elements;
100 } else {
101 if (in->MPIInfo->size>1) {
102 num_elements=0;
103 myRank=in->MPIInfo->rank;
104 size=in->MPIInfo->size;
105 #pragma omp parallel private(local_num_elements)
106 {
107 local_num_elements=0;
108 #pragma omp for private(e)
109 for (e=0;e<in->numElements;e++) {
110 if (in->Owner[e] == myRank) local_num_elements++;
111 }
112 #pragma omp critical
113 num_elements+=local_num_elements;
114 }
115 #ifdef PASO_MPI
116 MPI_Allgather(&num_elements,1,MPI_INT,distribution,1,MPI_INT,in->MPIInfo->comm);
117 #else
118 distribution[0]=num_elements;
119 #endif
120 } else {
121 distribution[0]=in->numElements;
122 }
123 }
124 }
125
126 dim_t Dudley_ElementFile_getGlobalNumElements(Dudley_ElementFile* in) {
127 dim_t size, *distribution=NULL, out, p;
128 if (in == NULL) {
129 return 0;
130 } else {
131 size=in->MPIInfo->size;
132 distribution=TMPMEMALLOC(size,dim_t);
133 Dudley_ElementFile_setElementDistribution(in,distribution);
134 out=0;
135 for (p=0;p<size;++p) out+=distribution[p];
136 TMPMEMFREE(distribution);
137 return out;
138 }
139 }
140 dim_t Dudley_ElementFile_getMyNumElements(Dudley_ElementFile* in) {
141 dim_t size, *distribution=NULL, out;
142 if (in == NULL) {
143 return 0;
144 } else {
145 size=in->MPIInfo->size;
146 distribution=TMPMEMALLOC(size,dim_t);
147 Dudley_ElementFile_setElementDistribution(in,distribution);
148 out=distribution[in->MPIInfo->rank];
149 TMPMEMFREE(distribution);
150 return out;
151 }
152
153 }
154 index_t Dudley_ElementFile_getFirstElement(Dudley_ElementFile* in){
155 dim_t size, *distribution=NULL, out, p;
156 if (in == NULL) {
157 return 0;
158 } else {
159 size=in->MPIInfo->size;
160 distribution=TMPMEMALLOC(size,dim_t);
161 Dudley_ElementFile_setElementDistribution(in,distribution);
162 out=0;
163 for (p=0;p<in->MPIInfo->rank;++p) out+=distribution[p];
164 TMPMEMFREE(distribution);
165 return out;
166 }
167 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26