/[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 1028 - (show annotations)
Wed Mar 14 00:15:24 2007 UTC (12 years, 6 months ago) by gross
File MIME type: text/plain
File size: 6261 byte(s)
modifications to be compliant with _WIN32. The substitutes for asinh, acosh, atanh are still missing (erf will through an exception)
1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* Finley: Mesh */
16
17 /* removes matching face elements from self */
18
19 /**************************************************************/
20
21 /* Author: gross@access.edu.au */
22 /* Version: $Id$
23
24 /**************************************************************/
25
26 #include "Mesh.h"
27
28 /**************************************************************/
29
30
31 void Finley_Mesh_glueFaces(Finley_Mesh* self,double safety_factor,double tolerance) {
32 char error_msg[LenErrorMsg_MAX];
33 Finley_NodeFile *newNodeFile=NULL;
34 Finley_ElementFile *newFaceElementsFile=NULL;
35 dim_t numPairs,e,i,n, NNFace, NN, numDim, new_numFaceElements, newNumNodes;
36 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;
37
38 if (self->FaceElements==NULL) return;
39
40 if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
41 sprintf(error_msg,"Finley_Mesh_glueFaces:glueing faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
42 Finley_setError(TYPE_ERROR,error_msg);
43 return;
44 }
45
46 NNFace=self->FaceElements->ReferenceElement->Type->numNodesOnFace;
47 NN=self->FaceElements->ReferenceElement->Type->numNodes;
48 numDim=self->Nodes->numDim;
49 /* allocate work arrays */
50 elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
51 elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
52 elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
53 matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
54 new_node_label=TMPMEMALLOC(self->Nodes->numNodes,index_t);
55 new_node_list=TMPMEMALLOC(self->Nodes->numNodes,index_t);
56 new_node_mask=TMPMEMALLOC(self->Nodes->numNodes,index_t);
57 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)) ) {
58 /* find the matching face elements */
59 Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
60 if (Finley_noError()) {
61 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=0;
62 for(n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=n;
63 /* remove mark imatching face elements to be removed */
64 for(e=0;e<numPairs;e++) {
65 elem_mask[elem0[e]]=1;
66 elem_mask[elem1[e]]=1;
67 for (i=0;i<NNFace;i++) {
68 face_node=self->FaceElements->ReferenceElement->Type->faceNode[i];
69 new_node_label[matching_nodes_in_elem1[INDEX2(face_node,e,NN)]]=self->FaceElements->Nodes[INDEX2(face_node,elem0[e],NN)];
70 }
71 }
72 /* create an index of face elements */
73 new_numFaceElements=0;
74 for(e=0;e<self->FaceElements->numElements;e++) {
75 if (elem_mask[e]<1) {
76 elem_mask[new_numFaceElements]=e;
77 new_numFaceElements++;
78 }
79 }
80 /* get the new number of nodes */
81 newNumNodes=0;
82 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[n]=-1;
83 for (n=0;n<self->Nodes->numNodes;n++) new_node_mask[new_node_label[n]]=1;
84 for (n=0;n<self->Nodes->numNodes;n++) {
85 if (new_node_mask[n]>0) {
86 new_node_mask[n]=newNumNodes;
87 new_node_list[newNumNodes]=n;
88 newNumNodes++;
89 }
90 }
91 for (n=0;n<self->Nodes->numNodes;n++) new_node_label[n]=new_node_mask[new_node_label[n]];
92 /* allocate new node and element files */
93 #ifndef PASO_MPI
94 newNodeFile=Finley_NodeFile_alloc(numDim);
95
96 if (Finley_noError()) {
97 Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
98 if (Finley_noError()) {
99 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order);
100 if (Finley_noError()) {
101 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
102 }
103 }
104 }
105 if (Finley_noError())
106 {
107 /* get the new nodes :*/
108 Finley_NodeFile_gather(new_node_list,self->Nodes,newNodeFile);
109 /* they are the new nodes*/
110 Finley_NodeFile_dealloc(self->Nodes);
111 self->Nodes=newNodeFile;
112 /* get the face elements which are still in use:*/
113 Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
114 /* they are the new face elements */
115 Finley_ElementFile_dealloc(self->FaceElements);
116 self->FaceElements=newFaceElementsFile;
117
118 /* assign new node ids to elements */
119 Finley_Mesh_relableElementNodes(new_node_label,0,self);
120
121 Finley_Mesh_prepare(self);
122 }
123 else
124 {
125 Finley_NodeFile_dealloc(newNodeFile);
126 Finley_ElementFile_dealloc(newFaceElementsFile);
127 }
128
129 #else
130 /* TODO */
131 PASO_MPI_TODO;
132 #endif
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 if (Finley_noError()) {
143 if (!Finley_Mesh_isPrepared(self)) {
144 Finley_setError(SYSTEM_ERROR,"Mesh is not prepared for calculation. Contact the programmers.");
145 }
146 }
147 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26