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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (9 years, 2 months ago) by jfenwick
File MIME type: text/plain
File size: 8014 byte(s)
Merging dudley and scons updates from branches

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 /* 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 /*static double Finley_Mesh_lockingGridSize=0;*/
30
31 Finley_Mesh* Finley_Mesh_merge(dim_t numMsh, Finley_Mesh** msh) {
32 Esys_MPIInfo *mpi_info=NULL;
33 Finley_ReferenceElementSet *refPoints=NULL, *refContactElements=NULL, *refFaceElements=NULL, *refElements=NULL;
34 Finley_Mesh* out=NULL;
35 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 dim_t i;
41 index_t order, reduced_order;
42 dim_t numDim;
43 Finley_ElementTypeId elementTypeId=Finley_NoRef;
44 Finley_ElementTypeId faceElementTypeId=Finley_NoRef;
45 Finley_ElementTypeId pointTypeId=Finley_NoRef;
46 Finley_ElementTypeId contactTypeId=Finley_NoRef;
47 index_t maxNodeID=0;
48 index_t maxDOF=0;
49 index_t maxElementID=0;
50 index_t maxElementID2=0;
51 char newName[LenString_MAX];
52 if (numMsh==0) {
53 Finley_setError(VALUE_ERROR,"Finley_Mesh_merge: Empty mesh list");
54 } else {
55 for (i=0;i<numMsh;i++) {
56 if (msh[i]->MPIInfo->size > 1) {
57 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: more than processor is not supported yet.");
58 return NULL;
59 }
60 }
61 order=msh[0]->integrationOrder;
62 reduced_order=msh[0]->reducedIntegrationOrder;
63 numDim=msh[0]->Nodes->numDim;
64 mpi_info=msh[0]->MPIInfo;
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]->integrationOrder);
69 reduced_order=MIN(reduced_order,msh[i]->reducedIntegrationOrder);
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==Finley_NoRef) {
81 elementTypeId=msh[i]->Elements->referenceElementSet->referenceElement->Type->TypeId;
82 } else {
83 if (elementTypeId!=msh[i]->Elements->referenceElementSet->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==Finley_NoRef) {
92 faceElementTypeId=msh[i]->FaceElements->referenceElementSet->referenceElement->Type->TypeId;
93 } else {
94 if (faceElementTypeId!=msh[i]->FaceElements->referenceElementSet->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==Finley_NoRef) {
103 contactTypeId=msh[i]->ContactElements->referenceElementSet->referenceElement->Type->TypeId;
104 } else {
105 if (contactTypeId!=msh[i]->ContactElements->referenceElementSet->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==Finley_NoRef) {
114 pointTypeId=msh[i]->Points->referenceElementSet->referenceElement->Type->TypeId;
115 } else {
116 if (pointTypeId!=msh[i]->Points->referenceElementSet->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,mpi_info);
133 }
134 if (Finley_noError()) {
135 refElements= Finley_ReferenceElementSet_alloc(elementTypeId,order,reduced_order);
136 refFaceElements=Finley_ReferenceElementSet_alloc(faceElementTypeId, order,reduced_order);
137 refContactElements=Finley_ReferenceElementSet_alloc(contactTypeId, order,reduced_order);
138 refPoints=Finley_ReferenceElementSet_alloc(pointTypeId, order,reduced_order);
139 }
140 if (Finley_noError()) {
141 out->Elements=Finley_ElementFile_alloc(refElements,mpi_info);
142 out->FaceElements=Finley_ElementFile_alloc(refFaceElements,mpi_info);
143 out->Points=Finley_ElementFile_alloc(refPoints,mpi_info);
144 out->ContactElements=Finley_ElementFile_alloc(refContactElements,mpi_info);
145
146 }
147 /* allocate new tables */
148 if (Finley_noError()) {
149 Finley_NodeFile_allocTable(out->Nodes,numNodes);
150 Finley_ElementFile_allocTable(out->Elements,numElements);
151 Finley_ElementFile_allocTable(out->FaceElements,numFaceElements);
152 Finley_ElementFile_allocTable(out->ContactElements,numContactElements);
153 Finley_ElementFile_allocTable(out->Points,numPoints);
154 }
155
156 /* copy tables :*/
157
158 if (Finley_noError()) {
159 numNodes=0;
160 numElements=0;
161 numFaceElements=0;
162 numContactElements=0;
163 numPoints=0;
164
165 for (i=0;i<numMsh;i++) {
166
167 Finley_NodeFile_copyTable(numNodes,out->Nodes,maxNodeID,maxDOF,msh[i]->Nodes);
168 Finley_ElementFile_copyTable(numElements,out->Elements,numNodes,maxElementID,msh[i]->Elements);
169 Finley_ElementFile_copyTable(numFaceElements,out->FaceElements,numNodes,maxElementID,msh[i]->FaceElements);
170 Finley_ElementFile_copyTable(numContactElements,out->ContactElements,numNodes,maxElementID,msh[i]->ContactElements);
171 Finley_ElementFile_copyTable(numPoints,out->Points,numNodes,maxElementID,msh[i]->Points);
172
173 numNodes=+msh[i]->Nodes->numNodes;
174 numElements=+msh[i]->Elements->numElements;
175 numFaceElements=+msh[i]->FaceElements->numElements;
176 numContactElements=+msh[i]->ContactElements->numElements;
177 numPoints=+msh[i]->Points->numElements;
178
179 if (msh[i]->Nodes->numNodes>0)
180 maxNodeID+=Finley_Util_getMaxInt(1,msh[i]->Nodes->numNodes,msh[i]->Nodes->Id)+1;
181 maxDOF+=Finley_Util_getMaxInt(1,msh[i]->Nodes->numNodes,msh[i]->Nodes->globalDegreesOfFreedom)+1;
182 maxElementID2=0;
183 if (msh[i]->Elements->numElements>0)
184 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->Elements->numElements,msh[i]->Elements->Id));
185 if (msh[i]->FaceElements->numElements>0)
186 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->FaceElements->numElements,msh[i]->FaceElements->Id));
187 if (msh[i]->ContactElements->numElements>0)
188 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->ContactElements->numElements,msh[i]->ContactElements->Id));
189 if (msh[i]->Points->numElements)
190 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->Points->numElements,msh[i]->Points->Id));
191 maxElementID+=maxElementID2+1;
192 }
193 }
194 /* all done */
195 Finley_ReferenceElementSet_dealloc(refPoints);
196 Finley_ReferenceElementSet_dealloc(refContactElements);
197 Finley_ReferenceElementSet_dealloc(refFaceElements);
198 Finley_ReferenceElementSet_dealloc(refElements);
199 if (! Finley_noError()) {
200 Finley_Mesh_free(out);
201 } else {
202 Finley_Mesh_prepare(out, FALSE);
203 }
204 }
205 return out;
206 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26