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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26