/[escript]/branches/domexper/dudley/src/Mesh_glueFaces.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/Mesh_glueFaces.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3149 - (show annotations)
Fri Sep 3 03:49:32 2010 UTC (8 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 5831 byte(s)


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 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 /* Dudley: Mesh */
18
19 /* removes matching face elements from self */
20
21 /**************************************************************/
22
23 #include "Mesh.h"
24
25 /**************************************************************/
26
27
28 void Dudley_Mesh_glueFaces(Dudley_Mesh* self,double safety_factor,double tolerance, bool_t optimize) {
29 char error_msg[LenErrorMsg_MAX];
30 Dudley_NodeFile *newNodeFile=NULL;
31 Dudley_ElementFile *newFaceElementsFile=NULL;
32 dim_t numPairs,e,i,n, NNFace, NN, numDim, new_numFaceElements, newNumNodes;
33 index_t *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 Dudley_ReferenceElement* faceRefElement=NULL;
35
36 if (self->MPIInfo->size>1) {
37 Dudley_setError(TYPE_ERROR,"Dudley_Mesh_glueFaces: MPI is not supported yet.");
38 return;
39 }
40
41 if (self->FaceElements==NULL) return;
42 faceRefElement= Dudley_ReferenceElementSet_borrowReferenceElement(self->FaceElements->referenceElementSet, FALSE);
43 NNFace=faceRefElement->Type->numNodesOnFace;
44 NN=self->FaceElements->numNodes;
45 numDim=self->Nodes->numDim;
46
47 if (NNFace<=0) {
48 sprintf(error_msg,"Dudley_Mesh_glueFaces:glueing faces cannot be applied to face elements of type %s",faceRefElement->Type->Name);
49 Dudley_setError(TYPE_ERROR,error_msg);
50 return;
51 }
52
53 /* allocate work arrays */
54 elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
55 elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
56 elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
57 matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
58 new_node_label=TMPMEMALLOC(self->Nodes->numNodes,index_t);
59 new_node_list=TMPMEMALLOC(self->Nodes->numNodes,index_t);
60 new_node_mask=TMPMEMALLOC(self->Nodes->numNodes,index_t);
61 if (!(Dudley_checkPtr(elem1) || Dudley_checkPtr(elem0) || Dudley_checkPtr(elem_mask) || Dudley_checkPtr(new_node_label) || Dudley_checkPtr(new_node_list) || Dudley_checkPtr(new_node_mask) || Dudley_checkPtr(matching_nodes_in_elem1)) ) {
62 /* find the matching face elements */
63 Dudley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
64 if (Dudley_noError()) {
65 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=0;
66 for(n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=n;
67 /* remove mark imatching face elements to be removed */
68 for(e=0;e<numPairs;e++) {
69 elem_mask[elem0[e]]=1;
70 elem_mask[elem1[e]]=1;
71 for (i=0;i<NNFace;i++) {
72 new_node_label[matching_nodes_in_elem1[INDEX2(i,e,NN)]]=self->FaceElements->Nodes[INDEX2(i,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=Dudley_NodeFile_alloc(numDim, self->MPIInfo);
97
98 if (Dudley_noError()) {
99 Dudley_NodeFile_allocTable(newNodeFile,newNumNodes);
100 if (Dudley_noError()) {
101 newFaceElementsFile=Dudley_ElementFile_alloc(self->FaceElements->referenceElementSet, self->MPIInfo);
102 if (Dudley_noError()) {
103 Dudley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
104 }
105 }
106 }
107 if (Dudley_noError())
108 {
109 /* get the new nodes :*/
110 Dudley_NodeFile_gather(new_node_list,self->Nodes,newNodeFile);
111 /* they are the new nodes*/
112 Dudley_NodeFile_free(self->Nodes);
113 self->Nodes=newNodeFile;
114 /* get the face elements which are still in use:*/
115 Dudley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
116 /* they are the new face elements */
117 Dudley_ElementFile_free(self->FaceElements);
118 self->FaceElements=newFaceElementsFile;
119
120 /* assign new node ids to elements */
121 Dudley_Mesh_relableElementNodes(new_node_label,0,self);
122
123 Dudley_Mesh_prepare(self, optimize);
124 }
125 else
126 {
127 Dudley_NodeFile_free(newNodeFile);
128 Dudley_ElementFile_free(newFaceElementsFile);
129 }
130
131 }
132 }
133 TMPMEMFREE(elem1);
134 TMPMEMFREE(elem0);
135 TMPMEMFREE(elem_mask);
136 TMPMEMFREE(new_node_label);
137 TMPMEMFREE(new_node_list);
138 TMPMEMFREE(new_node_mask);
139 TMPMEMFREE(matching_nodes_in_elem1);
140 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26