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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 730 - (hide annotations)
Mon May 15 04:03:49 2006 UTC (13 years, 5 months ago) by bcumming
File MIME type: text/plain
File size: 6047 byte(s)


1 jgs 150 /*
2 elspeth 616 ************************************************************
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 jgs 150 */
12    
13 jgs 82 /**************************************************************/
14    
15     /* Finley: Mesh */
16    
17     /* removes matching face elements from self */
18    
19     /**************************************************************/
20    
21 jgs 150 /* Author: gross@access.edu.au */
22     /* Version: $Id$
23 jgs 82
24     /**************************************************************/
25    
26     #include "Mesh.h"
27    
28     /**************************************************************/
29    
30    
31     void Finley_Mesh_glueFaces(Finley_Mesh* self,double safety_factor,double tolerance) {
32 jgs 150 char error_msg[LenErrorMsg_MAX];
33 jgs 82 Finley_NodeFile *newNodeFile=NULL;
34     Finley_ElementFile *newFaceElementsFile=NULL;
35 jgs 123 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 jgs 82 if (self->FaceElements==NULL) return;
39    
40     if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
41 jgs 153 sprintf(error_msg,"Finley_Mesh_glueFaces:glueing faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
42 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
43 jgs 82 return;
44     }
45    
46 jgs 123 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 jgs 82 /* allocate work arrays */
50 jgs 123 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 jgs 82 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 jgs 150 if (Finley_noError()) {
61 jgs 82 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 jgs 123 dim_t new_numFaceElements=0;
74 jgs 82 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 jgs 123 dim_t newNumNodes=0;
82 jgs 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 bcumming 730 #ifndef PASO_MPI
94 jgs 82 newNodeFile=Finley_NodeFile_alloc(numDim);
95 bcumming 730
96 jgs 150 if (Finley_noError()) {
97 jgs 82 Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
98 jgs 150 if (Finley_noError()) {
99 jgs 82 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order);
100 jgs 150 if (Finley_noError()) {
101 jgs 82 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
102     }
103     }
104     }
105 bcumming 730 if (Finley_noError())
106     {
107 jgs 82 /* get the new nodes :*/
108     Finley_NodeFile_gather(new_node_list,self->Nodes,newNodeFile);
109     /* they are the new nodes*/
110     Finley_NodeFile_dealloc(self->Nodes);
111     self->Nodes=newNodeFile;
112     /* get the face elements which are still in use:*/
113     Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
114     /* they are the new face elements */
115     Finley_ElementFile_dealloc(self->FaceElements);
116     self->FaceElements=newFaceElementsFile;
117    
118     /* assign new node ids to elements */
119     Finley_Mesh_relableElementNodes(new_node_label,0,self);
120 jgs 153
121     Finley_Mesh_prepare(self);
122 bcumming 730 }
123     else
124     {
125 jgs 82 Finley_NodeFile_dealloc(newNodeFile);
126     Finley_ElementFile_dealloc(newFaceElementsFile);
127     }
128 bcumming 730
129     #else
130     /* TODO */
131     PASO_MPI_TODO;
132     #endif
133 jgs 82 }
134 bcumming 730 }
135    
136 jgs 82 TMPMEMFREE(elem1);
137     TMPMEMFREE(elem0);
138     TMPMEMFREE(elem_mask);
139     TMPMEMFREE(new_node_label);
140     TMPMEMFREE(new_node_list);
141     TMPMEMFREE(new_node_mask);
142     TMPMEMFREE(matching_nodes_in_elem1);
143     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26