/[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 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 6049 byte(s)
Don't panic.
Updating copyright stamps

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 /* Finley: Mesh */
18
19 /* detects faces in the mesh that match and replaces it by step elements */
20
21 /**************************************************************/
22
23 #include "Mesh.h"
24
25 /**************************************************************/
26
27 void Finley_Mesh_joinFaces(Finley_Mesh* self,double safety_factor,double tolerance, bool_t optimize) {
28
29 char error_msg[LenErrorMsg_MAX];
30 index_t e0,e1,*elem1=NULL,*elem0=NULL,*elem_mask=NULL,*matching_nodes_in_elem1=NULL;
31 Finley_ElementFile *newFaceElementsFile=NULL,*newContactElementsFile=NULL;
32 dim_t e,i,numPairs, NN, NN_Contact,c, new_numFaceElements;
33 Finley_ReferenceElement* faceRefElement=NULL, *contactRefElement=NULL;
34
35 if (self->MPIInfo->size>1) {
36 Finley_setError(TYPE_ERROR,"Finley_Mesh_joinFaces: MPI is not supported yet.");
37 return;
38 }
39 if (self->ContactElements==NULL) {
40 Finley_setError(TYPE_ERROR,"Finley_Mesh_joinFaces: no contact element file present.");
41 return;
42 }
43 if (self->FaceElements==NULL) return;
44 faceRefElement= Finley_ReferenceElementSet_borrowReferenceElement(self->FaceElements->referenceElementSet, FALSE);
45 contactRefElement= Finley_ReferenceElementSet_borrowReferenceElement(self->ContactElements->referenceElementSet, FALSE);
46
47
48 NN=self->FaceElements->numNodes;
49 NN_Contact=self->ContactElements->numNodes;
50
51 if (faceRefElement->Type->numNodesOnFace<=0) {
52 sprintf(error_msg,"Finley_Mesh_joinFaces:joining faces cannot be applied to face elements of type %s",faceRefElement->Type->Name);
53 Finley_setError(TYPE_ERROR,error_msg);
54 return;
55 }
56
57
58 if (contactRefElement->Type->numNodes != 2*faceRefElement->Type->numNodes) {
59 sprintf(error_msg,"Finley_Mesh_joinFaces:contact element file for %s need to hold elements created from face elements %s", contactRefElement->Type->Name,faceRefElement->Type->Name);
60 Finley_setError(TYPE_ERROR,error_msg);
61 return;
62 }
63
64 /* allocate work arrays */
65 elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
66 elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
67 elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
68 matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
69
70 if (!(Finley_checkPtr(elem1) || Finley_checkPtr(elem0) || Finley_checkPtr(elem_mask) || Finley_checkPtr(matching_nodes_in_elem1))) {
71
72 /* find the matching face elements */
73 Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
74 if (Finley_noError()) {
75 /* get a list of the face elements to be kept */
76 #pragma omp parallel for private(e) schedule(static)
77 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=1;
78 for(e=0;e<numPairs;e++) {
79 elem_mask[elem0[e]]=0;
80 elem_mask[elem1[e]]=0;
81 }
82 new_numFaceElements=0;
83 /* OMP */
84 for(e=0;e<self->FaceElements->numElements;e++) {
85 if (elem_mask[e]>0) {
86 elem_mask[new_numFaceElements]=e;
87 new_numFaceElements++;
88 }
89 }
90 /* allocate new face element and Contact element files */
91 newContactElementsFile=Finley_ElementFile_alloc(self->ContactElements->referenceElementSet, self->MPIInfo);
92 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->referenceElementSet, self->MPIInfo);
93 if (Finley_noError()) {
94 Finley_ElementFile_allocTable(newContactElementsFile,numPairs+self->ContactElements->numElements);
95 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
96 }
97 /* copy the old elements over */
98 if (Finley_noError()) {
99 /* get the face elements which are still in use:*/
100 Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
101 /* get the Contact elements which are still in use:*/
102 Finley_ElementFile_copyTable(0,newContactElementsFile,0,0,self->ContactElements);
103 c=self->ContactElements->numElements;
104 /* OMP */
105 for (e=0;e<numPairs;e++) {
106 e0=elem0[e];
107 e1=elem1[e];
108 newContactElementsFile->Id[c]=MIN(self->FaceElements->Id[e0],self->FaceElements->Id[e1]);
109 newContactElementsFile->Tag[c]=MIN(self->FaceElements->Tag[e0],self->FaceElements->Tag[e1]);
110 newContactElementsFile->Color[c]=e;
111 for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i,c,NN_Contact)]=self->FaceElements->Nodes[INDEX2(i,e0,NN)];
112 for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i+NN,c,NN_Contact)]=matching_nodes_in_elem1[INDEX2(i,e,NN)];
113 c++;
114 }
115 newContactElementsFile->minColor=0;
116 newContactElementsFile->maxColor=numPairs-1;
117 }
118 /* set new face and Contact elements */
119 if (Finley_noError()) {
120
121 Finley_ElementFile_free(self->FaceElements);
122 self->FaceElements=newFaceElementsFile;
123 Finley_ElementFile_free(self->ContactElements);
124 self->ContactElements=newContactElementsFile;
125 Finley_Mesh_prepare(self, optimize);
126
127 } else {
128 Finley_ElementFile_free(newFaceElementsFile);
129 Finley_ElementFile_free(newContactElementsFile);
130 }
131 }
132 }
133 TMPMEMFREE(elem1);
134 TMPMEMFREE(elem0);
135 TMPMEMFREE(matching_nodes_in_elem1);
136 TMPMEMFREE(elem_mask);
137 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26