/[escript]/trunk-mpi-branch/finley/src/Mesh_glueFaces.c
ViewVC logotype

Contents of /trunk-mpi-branch/finley/src/Mesh_glueFaces.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1223 - (show annotations)
Fri Aug 3 02:40:39 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/plain
File size: 6614 byte(s)
first attemt towards an improved MPI version.  

1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* Finley: Mesh */
16
17 /* removes matching face elements from self */
18
19 /**************************************************************/
20
21 /* Author: gross@access.edu.au */
22 /* Version: $Id$
23
24 /**************************************************************/
25
26 #include "Mesh.h"
27
28 /**************************************************************/
29
30
31 void Finley_Mesh_glueFaces(Finley_Mesh* self,double safety_factor,double tolerance, bool_t optimize_labeling) {
32 char error_msg[LenErrorMsg_MAX];
33 Finley_NodeFile *newNodeFile=NULL;
34 Finley_ElementFile *newFaceElementsFile=NULL;
35 dim_t numPairs,e,i,n, NNFace, NN, numDim, new_numFaceElements, newNumNodes;
36 index_t face_node, *elem1=NULL,*elem0=NULL,*elem_mask=NULL,*new_node_label=NULL,*new_node_list=NULL,*new_node_mask=NULL,*matching_nodes_in_elem1=NULL;
37
38 if (self->MPIInfo->size>1) {
39 Finley_setError(TYPE_ERROR,"Finley_Mesh_glueFaces: MPI is not supported yet.");
40 return;
41 }
42
43
44 if (self->FaceElements==NULL) return;
45
46 if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
47 sprintf(error_msg,"Finley_Mesh_glueFaces:glueing faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
48 Finley_setError(TYPE_ERROR,error_msg);
49 return;
50 }
51
52 NNFace=self->FaceElements->ReferenceElement->Type->numNodesOnFace;
53 NN=self->FaceElements->ReferenceElement->Type->numNodes;
54 numDim=self->Nodes->numDim;
55 /* allocate work arrays */
56 elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
57 elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
58 elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
59 matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
60 new_node_label=TMPMEMALLOC(self->Nodes->numNodes,index_t);
61 new_node_list=TMPMEMALLOC(self->Nodes->numNodes,index_t);
62 new_node_mask=TMPMEMALLOC(self->Nodes->numNodes,index_t);
63 if (!(Finley_checkPtr(elem1) || Finley_checkPtr(elem0) || Finley_checkPtr(elem_mask) || Finley_checkPtr(new_node_label) || Finley_checkPtr(new_node_list) || Finley_checkPtr(new_node_mask) || Finley_checkPtr(matching_nodes_in_elem1)) ) {
64 /* find the matching face elements */
65 Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
66 if (Finley_noError()) {
67 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=0;
68 for(n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=n;
69 /* remove mark imatching face elements to be removed */
70 for(e=0;e<numPairs;e++) {
71 elem_mask[elem0[e]]=1;
72 elem_mask[elem1[e]]=1;
73 for (i=0;i<NNFace;i++) {
74 face_node=self->FaceElements->ReferenceElement->Type->faceNode[i];
75 new_node_label[matching_nodes_in_elem1[INDEX2(face_node,e,NN)]]=self->FaceElements->Nodes[INDEX2(face_node,elem0[e],NN)];
76 }
77 }
78 /* create an index of face elements */
79 new_numFaceElements=0;
80 for(e=0;e<self->FaceElements->numElements;e++) {
81 if (elem_mask[e]<1) {
82 elem_mask[new_numFaceElements]=e;
83 new_numFaceElements++;
84 }
85 }
86 /* get the new number of nodes */
87 newNumNodes=0;
88 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[n]=-1;
89 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[new_node_label[n]]=1;
90 for (n=0;n<self->Nodes->numNodes;n++) {
91 if (new_node_mask[n]>0) {
92 new_node_mask[n]=newNumNodes;
93 new_node_list[newNumNodes]=n;
94 newNumNodes++;
95 }
96 }
97 for (n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=new_node_mask[new_node_label[n]];
98 /* allocate new node and element files */
99 newNodeFile=Finley_NodeFile_alloc(numDim, self->MPIInfo);
100
101 if (Finley_noError()) {
102 Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
103 if (Finley_noError()) {
104 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,
105 self->FaceElements->order,
106 self->FaceElements->reduced_order,
107 self->MPIInfo);
108 if (Finley_noError()) {
109 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
110 }
111 }
112 }
113 if (Finley_noError())
114 {
115 /* get the new nodes :*/
116 Finley_NodeFile_gather(new_node_list,self->Nodes,newNodeFile);
117 /* they are the new nodes*/
118 Finley_NodeFile_free(self->Nodes);
119 self->Nodes=newNodeFile;
120 /* get the face elements which are still in use:*/
121 Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
122 /* they are the new face elements */
123 Finley_ElementFile_free(self->FaceElements);
124 self->FaceElements=newFaceElementsFile;
125
126 /* assign new node ids to elements */
127 Finley_Mesh_relableElementNodes(new_node_label,0,self);
128
129 Finley_Mesh_prepare(self);
130 }
131 else
132 {
133 Finley_NodeFile_free(newNodeFile);
134 Finley_ElementFile_free(newFaceElementsFile);
135 }
136
137 }
138 }
139 TMPMEMFREE(elem1);
140 TMPMEMFREE(elem0);
141 TMPMEMFREE(elem_mask);
142 TMPMEMFREE(new_node_label);
143 TMPMEMFREE(new_node_list);
144 TMPMEMFREE(new_node_mask);
145 TMPMEMFREE(matching_nodes_in_elem1);
146 if (Finley_noError()) {
147 if (!Finley_Mesh_isPrepared(self)) {
148 Finley_setError(SYSTEM_ERROR,"Mesh is not prepared for calculation. Contact the programmers.");
149 }
150 }
151 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26