/[escript]/branches/doubleplusgood/finley/src/Mesh_glueFaces.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/finley/src/Mesh_glueFaces.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26