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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 201 - (hide annotations)
Wed Nov 23 04:10:21 2005 UTC (14 years, 7 months ago) by jgs
File MIME type: text/plain
File size: 6274 byte(s)
copy finleyC and CPPAdapter to finley and finley/CPPAdapter to
facilitate scons builds

1 jgs 150 /*
2     ******************************************************************************
3     * *
4     * COPYRIGHT ACcESS 2003,2004,2005 - All Rights Reserved *
5     * *
6     * This software is the property of ACcESS. No part of this code *
7     * may be copied in any form or by any means without the expressed written *
8     * consent of ACcESS. Copying, use or modification of this software *
9     * by any unauthorised person is illegal unless that person has a software *
10     * license agreement with ACcESS. *
11     * *
12     ******************************************************************************
13     */
14    
15 jgs 82 /**************************************************************/
16    
17     /* Finley: Mesh */
18    
19     /* removes matching face elements from self */
20    
21     /**************************************************************/
22    
23 jgs 150 /* Author: gross@access.edu.au */
24     /* Version: $Id$
25 jgs 82
26     /**************************************************************/
27    
28     #include "Mesh.h"
29    
30     /**************************************************************/
31    
32    
33     void Finley_Mesh_glueFaces(Finley_Mesh* self,double safety_factor,double tolerance) {
34 jgs 150 char error_msg[LenErrorMsg_MAX];
35 jgs 82 Finley_NodeFile *newNodeFile=NULL;
36     Finley_ElementFile *newFaceElementsFile=NULL;
37 jgs 123 dim_t numPairs,e,i,n;
38     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;
39    
40 jgs 82 if (self->FaceElements==NULL) return;
41    
42     if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
43 jgs 153 sprintf(error_msg,"Finley_Mesh_glueFaces:glueing faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
44 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
45 jgs 82 return;
46     }
47    
48 jgs 123 dim_t NNFace=self->FaceElements->ReferenceElement->Type->numNodesOnFace;
49     dim_t NN=self->FaceElements->ReferenceElement->Type->numNodes;
50     dim_t numDim=self->Nodes->numDim;
51 jgs 82 /* allocate work arrays */
52 jgs 123 elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
53     elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
54     elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
55     matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
56     new_node_label=TMPMEMALLOC(self->Nodes->numNodes,index_t);
57     new_node_list=TMPMEMALLOC(self->Nodes->numNodes,index_t);
58     new_node_mask=TMPMEMALLOC(self->Nodes->numNodes,index_t);
59 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)) ) {
60     /* find the matching face elements */
61     Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
62 jgs 150 if (Finley_noError()) {
63 jgs 82 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=0;
64     for(n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=n;
65     /* remove mark imatching face elements to be removed */
66     for(e=0;e<numPairs;e++) {
67     elem_mask[elem0[e]]=1;
68     elem_mask[elem1[e]]=1;
69     for (i=0;i<NNFace;i++) {
70     face_node=self->FaceElements->ReferenceElement->Type->faceNode[i];
71     new_node_label[matching_nodes_in_elem1[INDEX2(face_node,e,NN)]]=self->FaceElements->Nodes[INDEX2(face_node,elem0[e],NN)];
72     }
73     }
74     /* create an index of face elements */
75 jgs 123 dim_t new_numFaceElements=0;
76 jgs 82 for(e=0;e<self->FaceElements->numElements;e++) {
77     if (elem_mask[e]<1) {
78     elem_mask[new_numFaceElements]=e;
79     new_numFaceElements++;
80     }
81     }
82     /* get the new number of nodes */
83 jgs 123 dim_t newNumNodes=0;
84 jgs 82 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[n]=-1;
85     for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[new_node_label[n]]=1;
86     for (n=0;n<self->Nodes->numNodes;n++) {
87     if (new_node_mask[n]>0) {
88     new_node_mask[n]=newNumNodes;
89     new_node_list[newNumNodes]=n;
90     newNumNodes++;
91     }
92     }
93     for (n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=new_node_mask[new_node_label[n]];
94     /* allocate new node and element files */
95     newNodeFile=Finley_NodeFile_alloc(numDim);
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 jgs 150 if (Finley_noError()) {
106 jgs 82 /* get the new nodes :*/
107     Finley_NodeFile_gather(new_node_list,self->Nodes,newNodeFile);
108     /* they are the new nodes*/
109     Finley_NodeFile_dealloc(self->Nodes);
110     self->Nodes=newNodeFile;
111     /* get the face elements which are still in use:*/
112     Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
113     /* they are the new face elements */
114     Finley_ElementFile_dealloc(self->FaceElements);
115     self->FaceElements=newFaceElementsFile;
116    
117     /* assign new node ids to elements */
118     Finley_Mesh_relableElementNodes(new_node_label,0,self);
119 jgs 153
120     Finley_Mesh_prepare(self);
121 jgs 82 } else {
122     Finley_NodeFile_dealloc(newNodeFile);
123     Finley_ElementFile_dealloc(newFaceElementsFile);
124     }
125     }
126     }
127     TMPMEMFREE(elem1);
128     TMPMEMFREE(elem0);
129     TMPMEMFREE(elem_mask);
130     TMPMEMFREE(new_node_label);
131     TMPMEMFREE(new_node_list);
132     TMPMEMFREE(new_node_mask);
133     TMPMEMFREE(matching_nodes_in_elem1);
134     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26