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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (hide annotations)
Tue Nov 17 07:32:59 2009 UTC (10 years, 2 months ago) by gross
File MIME type: text/plain
File size: 6049 byte(s)
Macro elements are implemented now. VTK writer for macro elements still needs testing.
1 jgs 150
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2548 * Copyright (c) 2003-2009 by University of Queensland
5 ksteube 1811 * 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 ksteube 1312
14 ksteube 1811
15 jgs 82 /**************************************************************/
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 ksteube 1312 void Finley_Mesh_joinFaces(Finley_Mesh* self,double safety_factor,double tolerance, bool_t optimize) {
28 jgs 82
29 jgs 150 char error_msg[LenErrorMsg_MAX];
30 jgs 123 index_t e0,e1,*elem1=NULL,*elem0=NULL,*elem_mask=NULL,*matching_nodes_in_elem1=NULL;
31 jgs 82 Finley_ElementFile *newFaceElementsFile=NULL,*newContactElementsFile=NULL;
32 gross 1028 dim_t e,i,numPairs, NN, NN_Contact,c, new_numFaceElements;
33 gross 2748 Finley_ReferenceElement* faceRefElement=NULL, *contactRefElement=NULL;
34 ksteube 1312
35     if (self->MPIInfo->size>1) {
36     Finley_setError(TYPE_ERROR,"Finley_Mesh_joinFaces: MPI is not supported yet.");
37     return;
38     }
39 gross 2748 if (self->ContactElements==NULL) {
40     Finley_setError(TYPE_ERROR,"Finley_Mesh_joinFaces: no contact element file present.");
41     return;
42     }
43 jgs 82 if (self->FaceElements==NULL) return;
44 gross 2748 faceRefElement= Finley_ReferenceElementSet_borrowReferenceElement(self->FaceElements->referenceElementSet, FALSE);
45     contactRefElement= Finley_ReferenceElementSet_borrowReferenceElement(self->ContactElements->referenceElementSet, FALSE);
46    
47 jgs 82
48 gross 2748 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 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
54 jgs 82 return;
55     }
56    
57    
58 gross 2748 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 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
61 jgs 82 return;
62     }
63    
64     /* allocate work arrays */
65 jgs 123 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 jgs 82
70     if (!(Finley_checkPtr(elem1) || Finley_checkPtr(elem0) || Finley_checkPtr(elem_mask) || Finley_checkPtr(matching_nodes_in_elem1))) {
71 gross 1376
72 jgs 82 /* find the matching face elements */
73     Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
74 jgs 150 if (Finley_noError()) {
75 jgs 82 /* 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 gross 1028 new_numFaceElements=0;
83 jgs 82 /* 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 gross 2748 newContactElementsFile=Finley_ElementFile_alloc(self->ContactElements->referenceElementSet, self->MPIInfo);
92     newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->referenceElementSet, self->MPIInfo);
93 jgs 150 if (Finley_noError()) {
94 jgs 82 Finley_ElementFile_allocTable(newContactElementsFile,numPairs+self->ContactElements->numElements);
95     Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
96     }
97     /* copy the old elements over */
98 jgs 150 if (Finley_noError()) {
99 jgs 82 /* 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 gross 1028 c=self->ContactElements->numElements;
104 jgs 82 /* 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 jgs 123 newContactElementsFile->minColor=0;
116     newContactElementsFile->maxColor=numPairs-1;
117 jgs 82 }
118     /* set new face and Contact elements */
119 jgs 150 if (Finley_noError()) {
120 jgs 82
121 ksteube 1312 Finley_ElementFile_free(self->FaceElements);
122 jgs 82 self->FaceElements=newFaceElementsFile;
123 ksteube 1312 Finley_ElementFile_free(self->ContactElements);
124 jgs 82 self->ContactElements=newContactElementsFile;
125 ksteube 1312 Finley_Mesh_prepare(self, optimize);
126 jgs 82
127     } else {
128 ksteube 1312 Finley_ElementFile_free(newFaceElementsFile);
129     Finley_ElementFile_free(newContactElementsFile);
130 jgs 82 }
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