/[escript]/trunk/finley/src/Mesh_joinFaces.c
ViewVC logotype

Contents of /trunk/finley/src/Mesh_joinFaces.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (show annotations)
Tue Oct 26 06:53:54 2004 UTC (15 years, 2 months ago) by jgs
Original Path: trunk/esys2/finley/src/finleyC/Mesh_joinFaces.c
File MIME type: text/plain
File size: 5857 byte(s)
Initial revision

1 /**************************************************************/
2
3 /* Finley: Mesh */
4
5 /* detects faces in the mesh that match and replaces it by step elements */
6
7 /**************************************************************/
8
9 /* Copyrights by ACcESS Australia 2003 */
10 /* Author: gross@access.edu.au */
11 /* Version: $Id$ */
12
13 /**************************************************************/
14
15 #include "Common.h"
16 #include "Finley.h"
17 #include "Mesh.h"
18
19 /**************************************************************/
20
21 void Finley_Mesh_joinFaces(Finley_Mesh* self,double safety_factor,double tolerance) {
22
23 int numPairs,*elem1=NULL,*elem0=NULL,*elem_mask=NULL,*matching_nodes_in_elem1=NULL;
24 Finley_ElementFile *newFaceElementsFile=NULL,*newContactElementsFile=NULL;
25 int e,i,e0,e1;
26 if (self->FaceElements==NULL) return;
27
28 if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
29 Finley_ErrorCode=TYPE_ERROR;
30 sprintf(Finley_ErrorMsg,"joining faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
31 return;
32 }
33 if (self->ContactElements==NULL) {
34 Finley_ErrorCode=TYPE_ERROR;
35 sprintf(Finley_ErrorMsg,"no contact element file present.");
36 return;
37 }
38
39 int NN=self->FaceElements->ReferenceElement->Type->numNodes;
40 int NN_Contact=self->ContactElements->ReferenceElement->Type->numNodes;
41
42 if (2*NN!=NN_Contact) {
43 Finley_ErrorCode=TYPE_ERROR;
44 sprintf(Finley_ErrorMsg,"contact element file for %s cannot hold elements created from face elements %s",
45 self->ContactElements->ReferenceElement->Type->Name,self->FaceElements->ReferenceElement->Type->Name);
46 return;
47 }
48
49 /* allocate work arrays */
50 elem1=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements);
51 elem0=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements);
52 elem_mask=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements);
53 matching_nodes_in_elem1=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements*NN);
54
55 if (!(Finley_checkPtr(elem1) || Finley_checkPtr(elem0) || Finley_checkPtr(elem_mask) || Finley_checkPtr(matching_nodes_in_elem1))) {
56 /* find the matching face elements */
57 Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
58 if (Finley_ErrorCode==NO_ERROR) {
59 /* get a list of the face elements to be kept */
60 #pragma omp parallel for private(e) schedule(static)
61 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=1;
62 for(e=0;e<numPairs;e++) {
63 elem_mask[elem0[e]]=0;
64 elem_mask[elem1[e]]=0;
65 }
66 int new_numFaceElements=0;
67 /* OMP */
68 for(e=0;e<self->FaceElements->numElements;e++) {
69 if (elem_mask[e]>0) {
70 elem_mask[new_numFaceElements]=e;
71 new_numFaceElements++;
72 }
73 }
74 /* allocate new face element and Contact element files */
75 newContactElementsFile=Finley_ElementFile_alloc(self->ContactElements->ReferenceElement->Type->TypeId,self->ContactElements->order);
76 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order);
77 if (Finley_ErrorCode==NO_ERROR) {
78 Finley_ElementFile_allocTable(newContactElementsFile,numPairs+self->ContactElements->numElements);
79 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
80 }
81 /* copy the old elements over */
82 if (Finley_ErrorCode==NO_ERROR) {
83 /* get the face elements which are still in use:*/
84 Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
85 /* get the Contact elements which are still in use:*/
86 Finley_ElementFile_copyTable(0,newContactElementsFile,0,0,self->ContactElements);
87 int c=self->ContactElements->numElements;
88 /* OMP */
89 for (e=0;e<numPairs;e++) {
90 e0=elem0[e];
91 e1=elem1[e];
92 newContactElementsFile->Id[c]=MIN(self->FaceElements->Id[e0],self->FaceElements->Id[e1]);
93 newContactElementsFile->Tag[c]=MIN(self->FaceElements->Tag[e0],self->FaceElements->Tag[e1]);
94 newContactElementsFile->Color[c]=e;
95 for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i,c,NN_Contact)]=self->FaceElements->Nodes[INDEX2(i,e0,NN)];
96 for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i+NN,c,NN_Contact)]=matching_nodes_in_elem1[INDEX2(i,e,NN)];
97 c++;
98 }
99 newContactElementsFile->numColors=numPairs;
100 }
101 /* set new face and Contact elements */
102 if (Finley_ErrorCode==NO_ERROR) {
103
104 Finley_ElementFile_dealloc(self->FaceElements);
105 self->FaceElements=newFaceElementsFile;
106 Finley_ElementFile_prepare(&(self->FaceElements),self->Nodes->numNodes,self->Nodes->degreeOfFreedom);
107
108 Finley_ElementFile_dealloc(self->ContactElements);
109 self->ContactElements=newContactElementsFile;
110 Finley_ElementFile_prepare(&(self->ContactElements),self->Nodes->numNodes,self->Nodes->degreeOfFreedom);
111
112 Finley_Mesh_prepareNodes(self);
113
114 } else {
115 Finley_ElementFile_dealloc(newFaceElementsFile);
116 Finley_ElementFile_dealloc(newContactElementsFile);
117 }
118 }
119 }
120 TMPMEMFREE(elem1);
121 TMPMEMFREE(elem0);
122 TMPMEMFREE(matching_nodes_in_elem1);
123 TMPMEMFREE(elem_mask);
124 }
125
126 /*
127 * $Log$
128 * Revision 1.1 2004/10/26 06:53:57 jgs
129 * Initial revision
130 *
131 * Revision 1.1.1.1 2004/06/24 04:00:40 johng
132 * Initial version of eys using boost-python.
133 *
134 *
135 */
136

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26