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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (show annotations)
Tue Oct 26 06:53:54 2004 UTC (15 years ago) by jgs
Original Path: trunk/esys2/finley/src/finleyC/Mesh_glueFaces.c
File MIME type: text/plain
File size: 5672 byte(s)
Initial revision

1 /**************************************************************/
2
3 /* Finley: Mesh */
4
5 /* removes matching face elements from self */
6
7 /**************************************************************/
8
9 /* Copyrights by ACcESS Australia 2003/04 */
10 /* Author: gross@access.edu.au */
11 /* Version: $Id$ */
12
13 /**************************************************************/
14
15 #include "Common.h"
16 #include "Finley.h"
17 #include "Mesh.h"
18
19 /**************************************************************/
20
21
22 void Finley_Mesh_glueFaces(Finley_Mesh* self,double safety_factor,double tolerance) {
23 Finley_NodeFile *newNodeFile=NULL;
24 Finley_ElementFile *newFaceElementsFile=NULL;
25 int numPairs,*elem1=NULL,*elem0=NULL,*elem_mask=NULL,*new_node_label=NULL,*new_node_list=NULL,*new_node_mask=NULL,*matching_nodes_in_elem1=NULL;
26 int e,i,n,face_node;
27 if (self->FaceElements==NULL) return;
28
29 if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
30 Finley_ErrorCode=TYPE_ERROR;
31 sprintf(Finley_ErrorMsg,"glueing faces cannot be applied to face elements pf type %s",self->FaceElements->ReferenceElement->Type->Name);
32 return;
33 }
34
35 int NNFace=self->FaceElements->ReferenceElement->Type->numNodesOnFace;
36 int NN=self->FaceElements->ReferenceElement->Type->numNodes;
37 int numDim=self->Nodes->numDim;
38 /* allocate work arrays */
39 elem1=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements);
40 elem0=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements);
41 elem_mask=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements);
42 matching_nodes_in_elem1=(int*) TMPMEMALLOC(sizeof(int)*sizeof(int)*self->FaceElements->numElements*NN);
43 new_node_label=(int*) TMPMEMALLOC(sizeof(int)*self->Nodes->numNodes);
44 new_node_list=(int*) TMPMEMALLOC(sizeof(int)*self->Nodes->numNodes);
45 new_node_mask=(int*) TMPMEMALLOC(sizeof(int)*self->Nodes->numNodes);
46 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)) ) {
47 /* find the matching face elements */
48 Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
49 if (Finley_ErrorCode==NO_ERROR) {
50 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=0;
51 for(n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=n;
52 /* remove mark imatching face elements to be removed */
53 for(e=0;e<numPairs;e++) {
54 elem_mask[elem0[e]]=1;
55 elem_mask[elem1[e]]=1;
56 for (i=0;i<NNFace;i++) {
57 face_node=self->FaceElements->ReferenceElement->Type->faceNode[i];
58 new_node_label[matching_nodes_in_elem1[INDEX2(face_node,e,NN)]]=self->FaceElements->Nodes[INDEX2(face_node,elem0[e],NN)];
59 }
60 }
61 /* create an index of face elements */
62 int new_numFaceElements=0;
63 for(e=0;e<self->FaceElements->numElements;e++) {
64 if (elem_mask[e]<1) {
65 elem_mask[new_numFaceElements]=e;
66 new_numFaceElements++;
67 }
68 }
69 /* get the new number of nodes */
70 int newNumNodes=0;
71 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[n]=-1;
72 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[new_node_label[n]]=1;
73 for (n=0;n<self->Nodes->numNodes;n++) {
74 if (new_node_mask[n]>0) {
75 new_node_mask[n]=newNumNodes;
76 new_node_list[newNumNodes]=n;
77 newNumNodes++;
78 }
79 }
80 for (n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=new_node_mask[new_node_label[n]];
81 /* allocate new node and element files */
82 newNodeFile=Finley_NodeFile_alloc(numDim);
83 if (Finley_ErrorCode==NO_ERROR) {
84 Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
85 if (Finley_ErrorCode==NO_ERROR) {
86 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order);
87 if (Finley_ErrorCode==NO_ERROR) {
88 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
89 }
90 }
91 }
92 if (Finley_ErrorCode==NO_ERROR) {
93 /* get the new nodes :*/
94 Finley_NodeFile_gather(new_node_list,self->Nodes,newNodeFile);
95 /* they are the new nodes*/
96 Finley_NodeFile_dealloc(self->Nodes);
97 self->Nodes=newNodeFile;
98 /* get the face elements which are still in use:*/
99 Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
100 /* they are the new face elements */
101 Finley_ElementFile_dealloc(self->FaceElements);
102 self->FaceElements=newFaceElementsFile;
103
104 /* assign new node ids to elements */
105 Finley_Mesh_relableElementNodes(new_node_label,0,self);
106 } else {
107 Finley_NodeFile_dealloc(newNodeFile);
108 Finley_ElementFile_dealloc(newFaceElementsFile);
109 }
110 }
111 }
112 TMPMEMFREE(elem1);
113 TMPMEMFREE(elem0);
114 TMPMEMFREE(elem_mask);
115 TMPMEMFREE(new_node_label);
116 TMPMEMFREE(new_node_list);
117 TMPMEMFREE(new_node_mask);
118 TMPMEMFREE(matching_nodes_in_elem1);
119 }
120
121 /*
122 * $Log$
123 * Revision 1.1 2004/10/26 06:53:57 jgs
124 * Initial revision
125 *
126 * Revision 1.1.1.1 2004/06/24 04:00:40 johng
127 * Initial version of eys using boost-python.
128 *
129 *
130 */
131

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26