/[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 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years, 2 months ago) by ksteube
File MIME type: text/plain
File size: 6144 byte(s)
Copyright updated in all files

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