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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3157 - (show annotations)
Mon Sep 6 05:10:18 2010 UTC (9 years, 2 months ago) by jfenwick
Original Path: branches/domexper/dudley/src/ElementFile.c
File MIME type: text/plain
File size: 5167 byte(s)
hacking
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 return out;
74 }
75
76 /* deallocates an element file: */
77
78 void Dudley_ElementFile_free(Dudley_ElementFile* in) {
79 if (in!=NULL) {
80 Dudley_ElementFile_freeTable(in);
81 Dudley_ReferenceElementSet_dealloc(in->referenceElementSet);
82 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans);
83 /*
84 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS);
85 */
86 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedQ);
87 /*
88 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS_reducedQ);
89 */
90 Paso_MPIInfo_free( in->MPIInfo );
91 MEMFREE(in);
92 }
93 }
94 void Dudley_ElementFile_setElementDistribution(Dudley_ElementFile* in, dim_t* distribution) {
95 dim_t local_num_elements,e,num_elements=0, size;
96 Paso_MPI_rank myRank;
97 if (in == NULL) {
98 distribution[0]=num_elements;
99 } else {
100 if (in->MPIInfo->size>1) {
101 num_elements=0;
102 myRank=in->MPIInfo->rank;
103 size=in->MPIInfo->size;
104 #pragma omp parallel private(local_num_elements)
105 {
106 local_num_elements=0;
107 #pragma omp for private(e)
108 for (e=0;e<in->numElements;e++) {
109 if (in->Owner[e] == myRank) local_num_elements++;
110 }
111 #pragma omp critical
112 num_elements+=local_num_elements;
113 }
114 #ifdef PASO_MPI
115 MPI_Allgather(&num_elements,1,MPI_INT,distribution,1,MPI_INT,in->MPIInfo->comm);
116 #else
117 distribution[0]=num_elements;
118 #endif
119 } else {
120 distribution[0]=in->numElements;
121 }
122 }
123 }
124
125 dim_t Dudley_ElementFile_getGlobalNumElements(Dudley_ElementFile* in) {
126 dim_t size, *distribution=NULL, out, p;
127 if (in == NULL) {
128 return 0;
129 } else {
130 size=in->MPIInfo->size;
131 distribution=TMPMEMALLOC(size,dim_t);
132 Dudley_ElementFile_setElementDistribution(in,distribution);
133 out=0;
134 for (p=0;p<size;++p) out+=distribution[p];
135 TMPMEMFREE(distribution);
136 return out;
137 }
138 }
139 dim_t Dudley_ElementFile_getMyNumElements(Dudley_ElementFile* in) {
140 dim_t size, *distribution=NULL, out;
141 if (in == NULL) {
142 return 0;
143 } else {
144 size=in->MPIInfo->size;
145 distribution=TMPMEMALLOC(size,dim_t);
146 Dudley_ElementFile_setElementDistribution(in,distribution);
147 out=distribution[in->MPIInfo->rank];
148 TMPMEMFREE(distribution);
149 return out;
150 }
151
152 }
153 index_t Dudley_ElementFile_getFirstElement(Dudley_ElementFile* in){
154 dim_t size, *distribution=NULL, out, p;
155 if (in == NULL) {
156 return 0;
157 } else {
158 size=in->MPIInfo->size;
159 distribution=TMPMEMALLOC(size,dim_t);
160 Dudley_ElementFile_setElementDistribution(in,distribution);
161 out=0;
162 for (p=0;p<in->MPIInfo->rank;++p) out+=distribution[p];
163 TMPMEMFREE(distribution);
164 return out;
165 }
166 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26