/[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 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 2 months ago) by ksteube
File MIME type: text/plain
File size: 7784 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

1
2 /* $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 /**************************************************************/
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 Finley_Mesh* Finley_Mesh_merge(dim_t numMsh, Finley_Mesh** msh) {
33 Paso_MPIInfo *mpi_info=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 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 char newName[LenString_MAX];
52 if (numMsh==0) {
53 Finley_setError(VALUE_ERROR,"Finley_Mesh_merge: Empty mesh list");
54 } else {
55 order=msh[0]->order;
56 reduced_order=msh[0]->reduced_order;
57 numDim=msh[0]->Nodes->numDim;
58 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 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 reduced_order=MIN(reduced_order,msh[i]->reduced_order);
68 numNodes+=msh[i]->Nodes->numNodes;
69 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 if (numDim!=msh[i]->Nodes->numDim) {
73 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: Spatial dimensions of meshes don't match.");
74 }
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 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: element types of meshes don't match.");
83 }
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 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: face element types of meshes don't match.");
94 }
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 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: contact element types of meshes don't match.");
105 }
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 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: point element types of meshes don't match.");
116 }
117 }
118 }
119
120 strncat(newName,"+",LenString_MAX-strlen(newName));
121 strncat(newName,msh[i]->Name,LenString_MAX-strlen(newName)-1);
122 }
123
124 if (mpi_info->size >1 ) {
125 Finley_setError(TYPE_ERROR,"Finley_Mesh_merge: only single processor runs are supported.");
126 }
127 /* allocate */
128
129 if (Finley_noError())
130 out=Finley_Mesh_alloc(newName,numDim,order,reduced_order,mpi_info);
131
132 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
137 /* allocate new tables */
138
139 if (Finley_noError())
140 {
141 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 if (Finley_noError()) {
151 numNodes=0;
152 numElements=0;
153 numFaceElements=0;
154 numContactElements=0;
155 numPoints=0;
156
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 maxDOF+=Finley_Util_getMaxInt(1,msh[i]->Nodes->numNodes,msh[i]->Nodes->globalDegreesOfFreedom)+1;
174 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 if (! Finley_noError()) {
189 Finley_Mesh_free(out);
190 } else {
191 Finley_Mesh_prepare(out, FALSE);
192 #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