/[escript]/branches/domexper/dudley/src/Mesh_merge.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/Mesh_merge.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3126 - (show annotations)
Wed Sep 1 00:37:53 2010 UTC (9 years, 2 months ago) by jfenwick
File MIME type: text/plain
File size: 6683 byte(s)
Updated referenceElements and enums
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 /* Dudley: 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 Dudley_Mesh_lockingGridSize=0;*/
30
31 Dudley_Mesh* Dudley_Mesh_merge(dim_t numMsh, Dudley_Mesh** msh) {
32 Paso_MPIInfo *mpi_info=NULL;
33 Dudley_ReferenceElementSet *refPoints=NULL, *refFaceElements=NULL, *refElements=NULL;
34 Dudley_Mesh* out=NULL;
35 dim_t numNodes=0;
36 dim_t numElements=0;
37 dim_t numFaceElements=0;
38 dim_t numPoints=0;
39 dim_t i;
40 index_t order, reduced_order;
41 dim_t numDim;
42 ElementTypeId elementTypeId=NoRef ;
43 ElementTypeId faceElementTypeId=NoRef ;
44 ElementTypeId pointTypeId=NoRef ;
45 index_t maxNodeID=0;
46 index_t maxDOF=0;
47 index_t maxElementID=0;
48 index_t maxElementID2=0;
49 char newName[LenString_MAX];
50 if (numMsh==0) {
51 Dudley_setError(VALUE_ERROR,"Dudley_Mesh_merge: Empty mesh list");
52 } else {
53 for (i=0;i<numMsh;i++) {
54 if (msh[i]->MPIInfo->size > 1) {
55 Dudley_setError(TYPE_ERROR,"Dudley_Mesh_merge: more than processor is not supported yet.");
56 return NULL;
57 }
58 }
59 order=msh[0]->integrationOrder;
60 reduced_order=msh[0]->reducedIntegrationOrder;
61 numDim=msh[0]->Nodes->numDim;
62 mpi_info=msh[0]->MPIInfo;
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]->integrationOrder);
67 reduced_order=MIN(reduced_order,msh[i]->reducedIntegrationOrder);
68 numNodes+=msh[i]->Nodes->numNodes;
69 if (mpi_info->comm!=msh[i]->MPIInfo->comm) {
70 Dudley_setError(TYPE_ERROR,"Dudley_Mesh_merge: MPI communicators of meshes don't match.");
71 }
72 if (numDim!=msh[i]->Nodes->numDim) {
73 Dudley_setError(TYPE_ERROR,"Dudley_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==NoRef ) {
79 elementTypeId=msh[i]->Elements->referenceElementSet->referenceElement->Type->TypeId;
80 } else {
81 if (elementTypeId!=msh[i]->Elements->referenceElementSet->referenceElement->Type->TypeId ) {
82 Dudley_setError(TYPE_ERROR,"Dudley_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==NoRef ) {
90 faceElementTypeId=msh[i]->FaceElements->referenceElementSet->referenceElement->Type->TypeId;
91 } else {
92 if (faceElementTypeId!=msh[i]->FaceElements->referenceElementSet->referenceElement->Type->TypeId ) {
93 Dudley_setError(TYPE_ERROR,"Dudley_Mesh_merge: face element types of meshes don't match.");
94 }
95 }
96 }
97
98 if (msh[i]->Points!=NULL) {
99 numPoints+=msh[i]->Points->numElements;
100 if (pointTypeId==NoRef ) {
101 pointTypeId=msh[i]->Points->referenceElementSet->referenceElement->Type->TypeId;
102 } else {
103 if (pointTypeId!=msh[i]->Points->referenceElementSet->referenceElement->Type->TypeId ) {
104 Dudley_setError(TYPE_ERROR,"Dudley_Mesh_merge: point element types of meshes don't match.");
105 }
106 }
107 }
108
109 strncat(newName,"+",LenString_MAX-strlen(newName));
110 strncat(newName,msh[i]->Name,LenString_MAX-strlen(newName)-1);
111 }
112
113 if (mpi_info->size >1 ) {
114 Dudley_setError(TYPE_ERROR,"Dudley_Mesh_merge: only single processor runs are supported.");
115 }
116 /* allocate */
117
118 if (Dudley_noError()) {
119 out=Dudley_Mesh_alloc(newName,numDim,mpi_info);
120 }
121 if (Dudley_noError()) {
122 refElements= Dudley_ReferenceElementSet_alloc(elementTypeId,order,reduced_order);
123 refFaceElements=Dudley_ReferenceElementSet_alloc(faceElementTypeId, order,reduced_order);
124 refPoints=Dudley_ReferenceElementSet_alloc(pointTypeId, order,reduced_order);
125 }
126 if (Dudley_noError()) {
127 out->Elements=Dudley_ElementFile_alloc(refElements,mpi_info);
128 out->FaceElements=Dudley_ElementFile_alloc(refFaceElements,mpi_info);
129 out->Points=Dudley_ElementFile_alloc(refPoints,mpi_info);
130
131 }
132 /* allocate new tables */
133 if (Dudley_noError()) {
134 Dudley_NodeFile_allocTable(out->Nodes,numNodes);
135 Dudley_ElementFile_allocTable(out->Elements,numElements);
136 Dudley_ElementFile_allocTable(out->FaceElements,numFaceElements);
137 Dudley_ElementFile_allocTable(out->Points,numPoints);
138 }
139
140 /* copy tables :*/
141
142 if (Dudley_noError()) {
143 numNodes=0;
144 numElements=0;
145 numFaceElements=0;
146 numPoints=0;
147
148 for (i=0;i<numMsh;i++) {
149
150 Dudley_NodeFile_copyTable(numNodes,out->Nodes,maxNodeID,maxDOF,msh[i]->Nodes);
151 Dudley_ElementFile_copyTable(numElements,out->Elements,numNodes,maxElementID,msh[i]->Elements);
152 Dudley_ElementFile_copyTable(numFaceElements,out->FaceElements,numNodes,maxElementID,msh[i]->FaceElements);
153 Dudley_ElementFile_copyTable(numPoints,out->Points,numNodes,maxElementID,msh[i]->Points);
154
155 numNodes=+msh[i]->Nodes->numNodes;
156 numElements=+msh[i]->Elements->numElements;
157 numFaceElements=+msh[i]->FaceElements->numElements;
158 numPoints=+msh[i]->Points->numElements;
159
160 if (msh[i]->Nodes->numNodes>0)
161 maxNodeID+=Dudley_Util_getMaxInt(1,msh[i]->Nodes->numNodes,msh[i]->Nodes->Id)+1;
162 maxDOF+=Dudley_Util_getMaxInt(1,msh[i]->Nodes->numNodes,msh[i]->Nodes->globalDegreesOfFreedom)+1;
163 maxElementID2=0;
164 if (msh[i]->Elements->numElements>0)
165 maxElementID2=MAX(maxElementID2,Dudley_Util_getMaxInt(1,msh[i]->Elements->numElements,msh[i]->Elements->Id));
166 if (msh[i]->FaceElements->numElements>0)
167 maxElementID2=MAX(maxElementID2,Dudley_Util_getMaxInt(1,msh[i]->FaceElements->numElements,msh[i]->FaceElements->Id));
168 if (msh[i]->Points->numElements)
169 maxElementID2=MAX(maxElementID2,Dudley_Util_getMaxInt(1,msh[i]->Points->numElements,msh[i]->Points->Id));
170 maxElementID+=maxElementID2+1;
171 }
172 }
173 /* all done */
174 Dudley_ReferenceElementSet_dealloc(refPoints);
175 Dudley_ReferenceElementSet_dealloc(refFaceElements);
176 Dudley_ReferenceElementSet_dealloc(refElements);
177 if (! Dudley_noError()) {
178 Dudley_Mesh_free(out);
179 } else {
180 Dudley_Mesh_prepare(out, FALSE);
181 }
182 }
183 return out;
184 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26