/[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 1986 - (show annotations)
Thu Nov 6 23:33:14 2008 UTC (11 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 7753 byte(s)
Warning removal
1
2 /*******************************************************
3 *
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
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 Paso_MPIInfo *mpi_info=NULL;
33 Finley_Mesh* out=NULL;
34 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 dim_t i;
40 index_t order, reduced_order;
41 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 char newName[LenString_MAX];
51 if (numMsh==0) {
52 Finley_setError(VALUE_ERROR,"Finley_Mesh_merge: Empty mesh list");
53 } else {
54 order=msh[0]->order;
55 reduced_order=msh[0]->reduced_order;
56 numDim=msh[0]->Nodes->numDim;
57 mpi_info=msh[0]->MPIInfo;
58 if (mpi_info->size > 1) {
59 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: more than processor is not supported yet.");
60 return NULL;
61 }
62 strcpy(newName,"");
63 for (i=0;i<numMsh;i++) {
64 /* check if all mesh have the same type and dimensions */
65 order=MAX(order,msh[i]->order);
66 reduced_order=MIN(reduced_order,msh[i]->reduced_order);
67 numNodes+=msh[i]->Nodes->numNodes;
68 if (mpi_info->comm!=msh[i]->MPIInfo->comm) {
69 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: MPI communicators of meshes don't match.");
70 }
71 if (numDim!=msh[i]->Nodes->numDim) {
72 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: Spatial dimensions of meshes don't match.");
73 }
74
75 if (msh[i]->Elements!=NULL) {
76 numElements+=msh[i]->Elements->numElements;
77 if (elementTypeId==NoType) {
78 elementTypeId=msh[i]->Elements->ReferenceElement->Type->TypeId;
79 } else {
80 if (elementTypeId!=msh[i]->Elements->ReferenceElement->Type->TypeId ) {
81 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: element types of meshes don't match.");
82 }
83 }
84 }
85
86 if (msh[i]->FaceElements!=NULL) {
87 numFaceElements+=msh[i]->FaceElements->numElements;
88 if (faceElementTypeId==NoType) {
89 faceElementTypeId=msh[i]->FaceElements->ReferenceElement->Type->TypeId;
90 } else {
91 if (faceElementTypeId!=msh[i]->FaceElements->ReferenceElement->Type->TypeId ) {
92 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: face element types of meshes don't match.");
93 }
94 }
95 }
96
97 if (msh[i]->ContactElements!=NULL) {
98 numContactElements+=msh[i]->ContactElements->numElements;
99 if (contactTypeId==NoType) {
100 contactTypeId=msh[i]->ContactElements->ReferenceElement->Type->TypeId;
101 } else {
102 if (contactTypeId!=msh[i]->ContactElements->ReferenceElement->Type->TypeId ) {
103 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: contact element types of meshes don't match.");
104 }
105 }
106 }
107
108 if (msh[i]->Points!=NULL) {
109 numPoints+=msh[i]->Points->numElements;
110 if (pointTypeId==NoType) {
111 pointTypeId=msh[i]->Points->ReferenceElement->Type->TypeId;
112 } else {
113 if (pointTypeId!=msh[i]->Points->ReferenceElement->Type->TypeId ) {
114 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: point element types of meshes don't match.");
115 }
116 }
117 }
118
119 strncat(newName,"+",LenString_MAX-strlen(newName));
120 strncat(newName,msh[i]->Name,LenString_MAX-strlen(newName)-1);
121 }
122
123 if (mpi_info->size >1 ) {
124 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: only single processor runs are supported.");
125 }
126 /* allocate */
127
128 if (Finley_noError())
129 out=Finley_Mesh_alloc(newName,numDim,order,reduced_order,mpi_info);
130
131 out->Elements=Finley_ElementFile_alloc(elementTypeId,out->order, out->reduced_order,mpi_info);
132 out->FaceElements=Finley_ElementFile_alloc(faceElementTypeId,out->order, out->reduced_order,mpi_info);
133 out->Points=Finley_ElementFile_alloc(pointTypeId,out->order, out->reduced_order,mpi_info);
134 out->ContactElements=Finley_ElementFile_alloc(contactTypeId,out->order, out->reduced_order,mpi_info);
135
136 /* allocate new tables */
137
138 if (Finley_noError())
139 {
140 Finley_NodeFile_allocTable(out->Nodes,numNodes);
141 Finley_ElementFile_allocTable(out->Elements,numElements);
142 Finley_ElementFile_allocTable(out->FaceElements,numFaceElements);
143 Finley_ElementFile_allocTable(out->ContactElements,numContactElements);
144 Finley_ElementFile_allocTable(out->Points,numPoints);
145 }
146
147 /* copy tables :*/
148
149 if (Finley_noError()) {
150 numNodes=0;
151 numElements=0;
152 numFaceElements=0;
153 numContactElements=0;
154 numPoints=0;
155
156 for (i=0;i<numMsh;i++) {
157
158 Finley_NodeFile_copyTable(numNodes,out->Nodes,maxNodeID,maxDOF,msh[i]->Nodes);
159 Finley_ElementFile_copyTable(numElements,out->Elements,numNodes,maxElementID,msh[i]->Elements);
160 Finley_ElementFile_copyTable(numFaceElements,out->FaceElements,numNodes,maxElementID,msh[i]->FaceElements);
161 Finley_ElementFile_copyTable(numContactElements,out->ContactElements,numNodes,maxElementID,msh[i]->ContactElements);
162 Finley_ElementFile_copyTable(numPoints,out->Points,numNodes,maxElementID,msh[i]->Points);
163
164 numNodes=+msh[i]->Nodes->numNodes;
165 numElements=+msh[i]->Elements->numElements;
166 numFaceElements=+msh[i]->FaceElements->numElements;
167 numContactElements=+msh[i]->ContactElements->numElements;
168 numPoints=+msh[i]->Points->numElements;
169
170 if (msh[i]->Nodes->numNodes>0)
171 maxNodeID+=Finley_Util_getMaxInt(1,msh[i]->Nodes->numNodes,msh[i]->Nodes->Id)+1;
172 maxDOF+=Finley_Util_getMaxInt(1,msh[i]->Nodes->numNodes,msh[i]->Nodes->globalDegreesOfFreedom)+1;
173 maxElementID2=0;
174 if (msh[i]->Elements->numElements>0)
175 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->Elements->numElements,msh[i]->Elements->Id));
176 if (msh[i]->FaceElements->numElements>0)
177 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->FaceElements->numElements,msh[i]->FaceElements->Id));
178 if (msh[i]->ContactElements->numElements>0)
179 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->ContactElements->numElements,msh[i]->ContactElements->Id));
180 if (msh[i]->Points->numElements)
181 maxElementID2=MAX(maxElementID2,Finley_Util_getMaxInt(1,msh[i]->Points->numElements,msh[i]->Points->Id));
182 maxElementID+=maxElementID2+1;
183 }
184 }
185 /* all done */
186
187 if (! Finley_noError()) {
188 Finley_Mesh_free(out);
189 } else {
190 Finley_Mesh_prepare(out, FALSE);
191 #ifdef Finley_TRACE
192 printf("%d meshes merged.\n",numMsh);
193 #endif
194 }
195 }
196 return out;
197 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26