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

Annotation of /trunk/finley/src/Mesh_merge.c

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26