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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1223 - (show annotations)
Fri Aug 3 02:40:39 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/plain
File size: 8025 byte(s)
first attemt towards an improved MPI version.  

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: Mesh */
16
17 /* takes nodes elements, etc of in2 and copies them into in1 */
18 /* Ids of in2 are shifted by the maximum Id of in1 */
19
20 /**************************************************************/
21
22 /* Author: gross@access.edu.au */
23 /* Version: $Id$ */
24
25 /**************************************************************/
26
27 #include "Mesh.h"
28 #include "Util.h"
29
30 /**************************************************************/
31
32 static double Finley_Mesh_lockingGridSize=0;
33
34 Finley_Mesh* Finley_Mesh_merge(dim_t numMsh, Finley_Mesh** msh) {
35 Paso_MPIInfo *mpi_info=NULL;
36 Finley_Mesh* out=NULL;
37 dim_t numNodes=0;
38 dim_t numElements=0;
39 dim_t numFaceElements=0;
40 dim_t numContactElements=0;
41 dim_t numPoints=0;
42 dim_t i;
43 index_t order, reduced_order;
44 dim_t numDim;
45 ElementTypeId elementTypeId=NoType;
46 ElementTypeId faceElementTypeId=NoType;
47 ElementTypeId pointTypeId=NoType;
48 ElementTypeId contactTypeId=NoType;
49 index_t maxNodeID=0;
50 index_t maxDOF=0;
51 index_t maxElementID=0;
52 index_t maxElementID2=0;
53 char newName[LenString_MAX];
54 if (numMsh==0) {
55 Finley_setError(VALUE_ERROR,"Finley_Mesh_merge: Empty mesh list");
56 } else {
57 order=msh[0]->order;
58 reduced_order=msh[0]->reduced_order;
59 numDim=msh[0]->Nodes->numDim;
60 mpi_info=msh[0]->MPIInfo;
61 if (mpi_info->size > 1) {
62 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: more than processor is not supported yet.");
63 return NULL;
64 }
65 strcpy(newName,"");
66 for (i=0;i<numMsh;i++) {
67 /* check if all mesh have the same type and dimensions */
68 order=MAX(order,msh[i]->order);
69 reduced_order=MIN(reduced_order,msh[i]->reduced_order);
70 numNodes+=msh[i]->Nodes->numNodes;
71 if (mpi_info->comm!=msh[i]->MPIInfo->comm) {
72 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: MPI communicators of meshes don't match.");
73 }
74 if (numDim!=msh[i]->Nodes->numDim) {
75 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: Spatial dimensions of meshes don't match.");
76 }
77
78 if (msh[i]->Elements!=NULL) {
79 numElements+=msh[i]->Elements->numElements;
80 if (elementTypeId==NoType) {
81 elementTypeId=msh[i]->Elements->ReferenceElement->Type->TypeId;
82 } else {
83 if (elementTypeId!=msh[i]->Elements->ReferenceElement->Type->TypeId ) {
84 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: element types of meshes don't match.");
85 }
86 }
87 }
88
89 if (msh[i]->FaceElements!=NULL) {
90 numFaceElements+=msh[i]->FaceElements->numElements;
91 if (faceElementTypeId==NoType) {
92 faceElementTypeId=msh[i]->FaceElements->ReferenceElement->Type->TypeId;
93 } else {
94 if (faceElementTypeId!=msh[i]->FaceElements->ReferenceElement->Type->TypeId ) {
95 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: face element types of meshes don't match.");
96 }
97 }
98 }
99
100 if (msh[i]->ContactElements!=NULL) {
101 numContactElements+=msh[i]->ContactElements->numElements;
102 if (contactTypeId==NoType) {
103 contactTypeId=msh[i]->ContactElements->ReferenceElement->Type->TypeId;
104 } else {
105 if (contactTypeId!=msh[i]->ContactElements->ReferenceElement->Type->TypeId ) {
106 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: contact element types of meshes don't match.");
107 }
108 }
109 }
110
111 if (msh[i]->Points!=NULL) {
112 numPoints+=msh[i]->Points->numElements;
113 if (pointTypeId==NoType) {
114 pointTypeId=msh[i]->Points->ReferenceElement->Type->TypeId;
115 } else {
116 if (pointTypeId!=msh[i]->Points->ReferenceElement->Type->TypeId ) {
117 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: point element types of meshes don't match.");
118 }
119 }
120 }
121
122 strncat(newName,"+",LenString_MAX-strlen(newName));
123 strncat(newName,msh[i]->Name,LenString_MAX-strlen(newName)-1);
124 }
125
126 if (mpi_info->size >1 ) {
127 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: only single processor runs are supported.");
128 }
129 /* allocate */
130
131 if (Finley_noError())
132 out=Finley_Mesh_alloc(newName,numDim,order,reduced_order,mpi_info);
133
134 out->Elements=Finley_ElementFile_alloc(elementTypeId,out->order, out->reduced_order,mpi_info);
135 out->FaceElements=Finley_ElementFile_alloc(faceElementTypeId,out->order, out->reduced_order,mpi_info);
136 out->Points=Finley_ElementFile_alloc(pointTypeId,out->order, out->reduced_order,mpi_info);
137 out->ContactElements=Finley_ElementFile_alloc(contactTypeId,out->order, out->reduced_order,mpi_info);
138
139 /* allocate new tables */
140
141 if (Finley_noError())
142 {
143 Finley_NodeFile_allocTable(out->Nodes,numNodes);
144 Finley_ElementFile_allocTable(out->Elements,numElements);
145 Finley_ElementFile_allocTable(out->FaceElements,numFaceElements);
146 Finley_ElementFile_allocTable(out->ContactElements,numContactElements);
147 Finley_ElementFile_allocTable(out->Points,numPoints);
148 }
149
150 /* copy tables :*/
151
152 if (Finley_noError()) {
153 numNodes=0;
154 numElements=0;
155 numFaceElements=0;
156 numContactElements=0;
157 numPoints=0;
158
159 for (i=0;i<numMsh;i++) {
160
161 Finley_NodeFile_copyTable(numNodes,out->Nodes,maxNodeID,maxDOF,msh[i]->Nodes);
162 Finley_ElementFile_copyTable(numElements,out->Elements,numNodes,maxElementID,msh[i]->Elements);
163 Finley_ElementFile_copyTable(numFaceElements,out->FaceElements,numNodes,maxElementID,msh[i]->FaceElements);
164 Finley_ElementFile_copyTable(numContactElements,out->ContactElements,numNodes,maxElementID,msh[i]->ContactElements);
165 Finley_ElementFile_copyTable(numPoints,out->Points,numNodes,maxElementID,msh[i]->Points);
166
167 numNodes=+msh[i]->Nodes->numNodes;
168 numElements=+msh[i]->Elements->numElements;
169 numFaceElements=+msh[i]->FaceElements->numElements;
170 numContactElements=+msh[i]->ContactElements->numElements;
171 numPoints=+msh[i]->Points->numElements;
172
173 if (msh[i]->Nodes->numNodes>0)
174 maxNodeID+=Finley_Util_getMaxInt(1,msh[i]->Nodes->numNodes,msh[i]->Nodes->Id)+1;
175 maxDOF+=Finley_Util_getMaxInt(1,msh[i]->Nodes->numNodes,msh[i]->Nodes->globalDegreesOfFreedom)+1;
176 maxElementID2=0;
177 if (msh[i]->Elements->numElements>0)
178 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->Elements->numElements,msh[i]->Elements->Id));
179 if (msh[i]->FaceElements->numElements>0)
180 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->FaceElements->numElements,msh[i]->FaceElements->Id));
181 if (msh[i]->ContactElements->numElements>0)
182 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->ContactElements->numElements,msh[i]->ContactElements->Id));
183 if (msh[i]->Points->numElements)
184 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->Points->numElements,msh[i]->Points->Id));
185 maxElementID+=maxElementID2+1;
186 }
187 }
188 /* all done */
189
190 if (! Finley_noError()) {
191 Finley_Mesh_free(out);
192 } else {
193 Finley_Mesh_prepare(out);
194 #ifdef Finley_TRACE
195 printf("%d meshes merged.\n",numMsh);
196 #endif
197 }
198 }
199 return out;
200 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26