/[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 616 - (show annotations)
Wed Mar 22 02:46:56 2006 UTC (13 years, 6 months ago) by elspeth
File MIME type: text/plain
File size: 5952 byte(s)
Copyright added to more source files.

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) {
32 char error_msg[LenErrorMsg_MAX];
33 Finley_NodeFile *newNodeFile=NULL;
34 Finley_ElementFile *newFaceElementsFile=NULL;
35 dim_t numPairs,e,i,n;
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->FaceElements==NULL) return;
39
40 if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
41 sprintf(error_msg,"Finley_Mesh_glueFaces:glueing faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
42 Finley_setError(TYPE_ERROR,error_msg);
43 return;
44 }
45
46 dim_t NNFace=self->FaceElements->ReferenceElement->Type->numNodesOnFace;
47 dim_t NN=self->FaceElements->ReferenceElement->Type->numNodes;
48 dim_t numDim=self->Nodes->numDim;
49 /* allocate work arrays */
50 elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
51 elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
52 elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
53 matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
54 new_node_label=TMPMEMALLOC(self->Nodes->numNodes,index_t);
55 new_node_list=TMPMEMALLOC(self->Nodes->numNodes,index_t);
56 new_node_mask=TMPMEMALLOC(self->Nodes->numNodes,index_t);
57 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)) ) {
58 /* find the matching face elements */
59 Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
60 if (Finley_noError()) {
61 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=0;
62 for(n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=n;
63 /* remove mark imatching face elements to be removed */
64 for(e=0;e<numPairs;e++) {
65 elem_mask[elem0[e]]=1;
66 elem_mask[elem1[e]]=1;
67 for (i=0;i<NNFace;i++) {
68 face_node=self->FaceElements->ReferenceElement->Type->faceNode[i];
69 new_node_label[matching_nodes_in_elem1[INDEX2(face_node,e,NN)]]=self->FaceElements->Nodes[INDEX2(face_node,elem0[e],NN)];
70 }
71 }
72 /* create an index of face elements */
73 dim_t new_numFaceElements=0;
74 for(e=0;e<self->FaceElements->numElements;e++) {
75 if (elem_mask[e]<1) {
76 elem_mask[new_numFaceElements]=e;
77 new_numFaceElements++;
78 }
79 }
80 /* get the new number of nodes */
81 dim_t newNumNodes=0;
82 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[n]=-1;
83 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[new_node_label[n]]=1;
84 for (n=0;n<self->Nodes->numNodes;n++) {
85 if (new_node_mask[n]>0) {
86 new_node_mask[n]=newNumNodes;
87 new_node_list[newNumNodes]=n;
88 newNumNodes++;
89 }
90 }
91 for (n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=new_node_mask[new_node_label[n]];
92 /* allocate new node and element files */
93 newNodeFile=Finley_NodeFile_alloc(numDim);
94 if (Finley_noError()) {
95 Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
96 if (Finley_noError()) {
97 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order);
98 if (Finley_noError()) {
99 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
100 }
101 }
102 }
103 if (Finley_noError()) {
104 /* get the new nodes :*/
105 Finley_NodeFile_gather(new_node_list,self->Nodes,newNodeFile);
106 /* they are the new nodes*/
107 Finley_NodeFile_dealloc(self->Nodes);
108 self->Nodes=newNodeFile;
109 /* get the face elements which are still in use:*/
110 Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
111 /* they are the new face elements */
112 Finley_ElementFile_dealloc(self->FaceElements);
113 self->FaceElements=newFaceElementsFile;
114
115 /* assign new node ids to elements */
116 Finley_Mesh_relableElementNodes(new_node_label,0,self);
117
118 Finley_Mesh_prepare(self);
119 } else {
120 Finley_NodeFile_dealloc(newNodeFile);
121 Finley_ElementFile_dealloc(newFaceElementsFile);
122 }
123 }
124 }
125 TMPMEMFREE(elem1);
126 TMPMEMFREE(elem0);
127 TMPMEMFREE(elem_mask);
128 TMPMEMFREE(new_node_label);
129 TMPMEMFREE(new_node_list);
130 TMPMEMFREE(new_node_mask);
131 TMPMEMFREE(matching_nodes_in_elem1);
132 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26