/[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 2748 - (show annotations)
Tue Nov 17 07:32:59 2009 UTC (10 years, 1 month ago) by gross
File MIME type: text/plain
File size: 5960 byte(s)
Macro elements are implemented now. VTK writer for macro elements still needs testing.
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Finley: Mesh */
18
19 /* removes matching face elements from self */
20
21 /**************************************************************/
22
23 #include "Mesh.h"
24
25 /**************************************************************/
26
27
28 void Finley_Mesh_glueFaces(Finley_Mesh* self,double safety_factor,double tolerance, bool_t optimize) {
29 char error_msg[LenErrorMsg_MAX];
30 Finley_NodeFile *newNodeFile=NULL;
31 Finley_ElementFile *newFaceElementsFile=NULL;
32 dim_t numPairs,e,i,n, NNFace, NN, numDim, new_numFaceElements, newNumNodes;
33 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, *faceNodes=NULL;
34 Finley_ReferenceElement* faceRefElement=NULL;
35
36 if (self->MPIInfo->size>1) {
37 Finley_setError(TYPE_ERROR,"Finley_Mesh_glueFaces: MPI is not supported yet.");
38 return;
39 }
40
41 if (self->FaceElements==NULL) return;
42 faceRefElement= Finley_ReferenceElementSet_borrowReferenceElement(self->FaceElements->referenceElementSet, FALSE);
43 NNFace=faceRefElement->Type->numNodesOnFace;
44 NN=self->FaceElements->numNodes;
45 numDim=self->Nodes->numDim;
46 faceNodes=faceRefElement->Type->faceNodes;
47
48 if (NNFace<=0) {
49 sprintf(error_msg,"Finley_Mesh_glueFaces:glueing faces cannot be applied to face elements of type %s",faceRefElement->Type->Name);
50 Finley_setError(TYPE_ERROR,error_msg);
51 return;
52 }
53
54 /* allocate work arrays */
55 elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
56 elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
57 elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
58 matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
59 new_node_label=TMPMEMALLOC(self->Nodes->numNodes,index_t);
60 new_node_list=TMPMEMALLOC(self->Nodes->numNodes,index_t);
61 new_node_mask=TMPMEMALLOC(self->Nodes->numNodes,index_t);
62 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)) ) {
63 /* find the matching face elements */
64 Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
65 if (Finley_noError()) {
66 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=0;
67 for(n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=n;
68 /* remove mark imatching face elements to be removed */
69 for(e=0;e<numPairs;e++) {
70 elem_mask[elem0[e]]=1;
71 elem_mask[elem1[e]]=1;
72 for (i=0;i<NNFace;i++) {
73 face_node=faceNodes[i];
74 new_node_label[matching_nodes_in_elem1[INDEX2(face_node,e,NN)]]=self->FaceElements->Nodes[INDEX2(face_node,elem0[e],NN)];
75 }
76 }
77 /* create an index of face elements */
78 new_numFaceElements=0;
79 for(e=0;e<self->FaceElements->numElements;e++) {
80 if (elem_mask[e]<1) {
81 elem_mask[new_numFaceElements]=e;
82 new_numFaceElements++;
83 }
84 }
85 /* get the new number of nodes */
86 newNumNodes=0;
87 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[n]=-1;
88 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[new_node_label[n]]=1;
89 for (n=0;n<self->Nodes->numNodes;n++) {
90 if (new_node_mask[n]>0) {
91 new_node_mask[n]=newNumNodes;
92 new_node_list[newNumNodes]=n;
93 newNumNodes++;
94 }
95 }
96 for (n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=new_node_mask[new_node_label[n]];
97 /* allocate new node and element files */
98 newNodeFile=Finley_NodeFile_alloc(numDim, self->MPIInfo);
99
100 if (Finley_noError()) {
101 Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
102 if (Finley_noError()) {
103 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->referenceElementSet, self->MPIInfo);
104 if (Finley_noError()) {
105 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
106 }
107 }
108 }
109 if (Finley_noError())
110 {
111 /* get the new nodes :*/
112 Finley_NodeFile_gather(new_node_list,self->Nodes,newNodeFile);
113 /* they are the new nodes*/
114 Finley_NodeFile_free(self->Nodes);
115 self->Nodes=newNodeFile;
116 /* get the face elements which are still in use:*/
117 Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
118 /* they are the new face elements */
119 Finley_ElementFile_free(self->FaceElements);
120 self->FaceElements=newFaceElementsFile;
121
122 /* assign new node ids to elements */
123 Finley_Mesh_relableElementNodes(new_node_label,0,self);
124
125 Finley_Mesh_prepare(self, optimize);
126 }
127 else
128 {
129 Finley_NodeFile_free(newNodeFile);
130 Finley_ElementFile_free(newFaceElementsFile);
131 }
132
133 }
134 }
135 TMPMEMFREE(elem1);
136 TMPMEMFREE(elem0);
137 TMPMEMFREE(elem_mask);
138 TMPMEMFREE(new_node_label);
139 TMPMEMFREE(new_node_list);
140 TMPMEMFREE(new_node_mask);
141 TMPMEMFREE(matching_nodes_in_elem1);
142 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26