/[escript]/branches/domexper/dudley/src/ElementFile.c
ViewVC logotype

Annotation of /branches/domexper/dudley/src/ElementFile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3080 - (hide annotations)
Tue Aug 3 04:28:03 2010 UTC (9 years, 4 months ago) by jfenwick
File MIME type: text/plain
File size: 5052 byte(s)
inital rename
1 jgs 150
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1811 * 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 ksteube 1312
14 ksteube 1811
15 jgs 82 /**************************************************************/
16    
17     /* Finley: ElementFile */
18    
19     /* allocates an element file to hold elements of type id and with integration order order. */
20 ksteube 1312 /* use Finley_Mesh_allocElementTable to allocate the element table (Id,Nodes,Tag,Owner). */
21 jgs 82
22     /**************************************************************/
23    
24     #include "ElementFile.h"
25    
26     /**************************************************************/
27    
28 gross 2748 Finley_ElementFile* Finley_ElementFile_alloc(Finley_ReferenceElementSet* referenceElementSet, Paso_MPIInfo *MPIInfo)
29 bcumming 730 {
30 jgs 82 Finley_ElementFile *out;
31    
32    
33 jgs 150 if (! Finley_noError()) return NULL;
34 jgs 82
35     /* allocate the return value */
36    
37 jgs 102 out=MEMALLOC(1,Finley_ElementFile);
38 jgs 82 if (Finley_checkPtr(out)) return NULL;
39 gross 2748 out->referenceElementSet=Finley_ReferenceElementSet_reference(referenceElementSet);
40 jgs 82 out->numElements=0;
41     out->Id=NULL;
42     out->Nodes=NULL;
43     out->Tag=NULL;
44     out->Color=NULL;
45 jgs 123 out->minColor=0;
46     out->maxColor=-1;
47 gross 777 out->jacobeans=NULL;
48     out->jacobeans_reducedQ=NULL;
49     out->jacobeans_reducedS=NULL;
50     out->jacobeans_reducedS_reducedQ=NULL;
51 jgs 82
52 ksteube 1312 out->Owner=NULL;
53 gross 1716 out->numTagsInUse=0;
54     out->tagsInUse=NULL;
55    
56 bcumming 730 out->MPIInfo = Paso_MPIInfo_getReference( MPIInfo );
57 gross 2748
58     out->jacobeans=Finley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElement->BasisFunctions);
59     out->jacobeans_reducedQ=Finley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElementReducedQuadrature->BasisFunctions);
60     out->jacobeans_reducedS=Finley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElement->LinearBasisFunctions);
61     out->jacobeans_reducedS_reducedQ=Finley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElementReducedQuadrature->LinearBasisFunctions);
62 gross 532
63 gross 777
64 ksteube 1312
65 jgs 150 if (! Finley_noError()) {
66 ksteube 1312 Finley_ElementFile_free(out);
67 jgs 82 return NULL;
68     }
69 gross 2748 out->numNodes=out->referenceElementSet->numNodes;
70 jgs 82 return out;
71     }
72    
73     /* deallocates an element file: */
74    
75 ksteube 1312 void Finley_ElementFile_free(Finley_ElementFile* in) {
76 jgs 82 if (in!=NULL) {
77 ksteube 1312 Finley_ElementFile_freeTable(in);
78 gross 2748 Finley_ReferenceElementSet_dealloc(in->referenceElementSet);
79 gross 776 Finley_ElementFile_Jacobeans_dealloc(in->jacobeans);
80     Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS);
81     Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedQ);
82     Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS_reducedQ);
83 ksteube 1312 Paso_MPIInfo_free( in->MPIInfo );
84 jgs 82 MEMFREE(in);
85     }
86     }
87 ksteube 1312 void Finley_ElementFile_setElementDistribution(Finley_ElementFile* in, dim_t* distribution) {
88 phornby 1628 dim_t local_num_elements,e,num_elements=0, size;
89 ksteube 1312 Paso_MPI_rank myRank;
90     if (in == NULL) {
91     distribution[0]=num_elements;
92     } else {
93     if (in->MPIInfo->size>1) {
94     num_elements=0;
95     myRank=in->MPIInfo->rank;
96     size=in->MPIInfo->size;
97     #pragma omp parallel private(local_num_elements)
98     {
99     local_num_elements=0;
100     #pragma omp for private(e)
101     for (e=0;e<in->numElements;e++) {
102     if (in->Owner[e] == myRank) local_num_elements++;
103     }
104     #pragma omp critical
105     num_elements+=local_num_elements;
106     }
107     #ifdef PASO_MPI
108     MPI_Allgather(&num_elements,1,MPI_INT,distribution,1,MPI_INT,in->MPIInfo->comm);
109     #else
110     distribution[0]=num_elements;
111     #endif
112     } else {
113     distribution[0]=in->numElements;
114     }
115     }
116     }
117    
118     dim_t Finley_ElementFile_getGlobalNumElements(Finley_ElementFile* in) {
119     dim_t size, *distribution=NULL, out, p;
120     if (in == NULL) {
121     return 0;
122     } else {
123     size=in->MPIInfo->size;
124     distribution=TMPMEMALLOC(size,dim_t);
125     Finley_ElementFile_setElementDistribution(in,distribution);
126     out=0;
127     for (p=0;p<size;++p) out+=distribution[p];
128     TMPMEMFREE(distribution);
129     return out;
130     }
131     }
132     dim_t Finley_ElementFile_getMyNumElements(Finley_ElementFile* in) {
133 phornby 1628 dim_t size, *distribution=NULL, out;
134 ksteube 1312 if (in == NULL) {
135     return 0;
136     } else {
137     size=in->MPIInfo->size;
138     distribution=TMPMEMALLOC(size,dim_t);
139     Finley_ElementFile_setElementDistribution(in,distribution);
140     out=distribution[in->MPIInfo->rank];
141     TMPMEMFREE(distribution);
142     return out;
143     }
144    
145     }
146     index_t Finley_ElementFile_getFirstElement(Finley_ElementFile* in){
147     dim_t size, *distribution=NULL, out, p;
148     if (in == NULL) {
149     return 0;
150     } else {
151     size=in->MPIInfo->size;
152     distribution=TMPMEMALLOC(size,dim_t);
153     Finley_ElementFile_setElementDistribution(in,distribution);
154     out=0;
155     for (p=0;p<in->MPIInfo->rank;++p) out+=distribution[p];
156     TMPMEMFREE(distribution);
157     return out;
158     }
159     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26