/[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 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years ago) by ksteube
File MIME type: text/plain
File size: 6179 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 /**************************************************************/
17
18 /* Finley: Mesh */
19
20 /* removes matching face elements from self */
21
22 /**************************************************************/
23
24 #include "Mesh.h"
25
26 /**************************************************************/
27
28
29 void Finley_Mesh_glueFaces(Finley_Mesh* self,double safety_factor,double tolerance, bool_t optimize) {
30 char error_msg[LenErrorMsg_MAX];
31 Finley_NodeFile *newNodeFile=NULL;
32 Finley_ElementFile *newFaceElementsFile=NULL;
33 dim_t numPairs,e,i,n, NNFace, NN, numDim, new_numFaceElements, newNumNodes;
34 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;
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
42 if (self->FaceElements==NULL) return;
43
44 if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
45 sprintf(error_msg,"Finley_Mesh_glueFaces:glueing faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
46 Finley_setError(TYPE_ERROR,error_msg);
47 return;
48 }
49
50 NNFace=self->FaceElements->ReferenceElement->Type->numNodesOnFace;
51 NN=self->FaceElements->ReferenceElement->Type->numNodes;
52 numDim=self->Nodes->numDim;
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 (!(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)) ) {
62 /* find the matching face elements */
63 Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
64 if (Finley_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 face_node=self->FaceElements->ReferenceElement->Type->faceNode[i];
73 new_node_label[matching_nodes_in_elem1[INDEX2(face_node,e,NN)]]=self->FaceElements->Nodes[INDEX2(face_node,elem0[e],NN)];
74 }
75 }
76 /* create an index of face elements */
77 new_numFaceElements=0;
78 for(e=0;e<self->FaceElements->numElements;e++) {
79 if (elem_mask[e]<1) {
80 elem_mask[new_numFaceElements]=e;
81 new_numFaceElements++;
82 }
83 }
84 /* get the new number of nodes */
85 newNumNodes=0;
86 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[n]=-1;
87 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[new_node_label[n]]=1;
88 for (n=0;n<self->Nodes->numNodes;n++) {
89 if (new_node_mask[n]>0) {
90 new_node_mask[n]=newNumNodes;
91 new_node_list[newNumNodes]=n;
92 newNumNodes++;
93 }
94 }
95 for (n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=new_node_mask[new_node_label[n]];
96 /* allocate new node and element files */
97 newNodeFile=Finley_NodeFile_alloc(numDim, self->MPIInfo);
98
99 if (Finley_noError()) {
100 Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
101 if (Finley_noError()) {
102 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,
103 self->FaceElements->order,
104 self->FaceElements->reduced_order,
105 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 TMPMEMFREE(elem1);
138 TMPMEMFREE(elem0);
139 TMPMEMFREE(elem_mask);
140 TMPMEMFREE(new_node_label);
141 TMPMEMFREE(new_node_list);
142 TMPMEMFREE(new_node_mask);
143 TMPMEMFREE(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