/[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 1811 - (hide annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years, 5 months ago) by ksteube
File MIME type: text/plain
File size: 5968 byte(s)
Copyright updated in all files

1 jgs 150
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4     * Copyright (c) 2003-2008 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 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 ksteube 1312
34     if (self->MPIInfo->size>1) {
35     Finley_setError(TYPE_ERROR,"Finley_Mesh_joinFaces: MPI is not supported yet.");
36     return;
37     }
38 jgs 82 if (self->FaceElements==NULL) return;
39    
40     if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
41 jgs 153 sprintf(error_msg,"Finley_Mesh_joinFaces:joining faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
42 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
43 jgs 82 return;
44     }
45     if (self->ContactElements==NULL) {
46 jgs 153 Finley_setError(TYPE_ERROR,"Finley_Mesh_joinFaces: no contact element file present.");
47 jgs 82 return;
48     }
49    
50 gross 1028 NN=self->FaceElements->ReferenceElement->Type->numNodes;
51     NN_Contact=self->ContactElements->ReferenceElement->Type->numNodes;
52 jgs 82
53     if (2*NN!=NN_Contact) {
54 jgs 153 sprintf(error_msg,"Finley_Mesh_joinFaces:contact element file for %s cannot hold elements created from face elements %s",
55 jgs 82 self->ContactElements->ReferenceElement->Type->Name,self->FaceElements->ReferenceElement->Type->Name);
56 jgs 150 Finley_setError(TYPE_ERROR,error_msg);
57 jgs 82 return;
58     }
59    
60     /* allocate work arrays */
61 jgs 123 elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
62     elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
63     elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
64     matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
65 jgs 82
66     if (!(Finley_checkPtr(elem1) || Finley_checkPtr(elem0) || Finley_checkPtr(elem_mask) || Finley_checkPtr(matching_nodes_in_elem1))) {
67 gross 1376
68 jgs 82 /* find the matching face elements */
69     Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
70 jgs 150 if (Finley_noError()) {
71 jgs 82 /* get a list of the face elements to be kept */
72     #pragma omp parallel for private(e) schedule(static)
73     for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=1;
74     for(e=0;e<numPairs;e++) {
75     elem_mask[elem0[e]]=0;
76     elem_mask[elem1[e]]=0;
77     }
78 gross 1028 new_numFaceElements=0;
79 jgs 82 /* OMP */
80     for(e=0;e<self->FaceElements->numElements;e++) {
81     if (elem_mask[e]>0) {
82     elem_mask[new_numFaceElements]=e;
83     new_numFaceElements++;
84     }
85     }
86     /* allocate new face element and Contact element files */
87 ksteube 1312 newContactElementsFile=Finley_ElementFile_alloc(self->ContactElements->ReferenceElement->Type->TypeId,self->ContactElements->order,self->ContactElements->reduced_order, self->MPIInfo);
88     newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order,self->FaceElements->reduced_order, self->MPIInfo);
89 jgs 150 if (Finley_noError()) {
90 jgs 82 Finley_ElementFile_allocTable(newContactElementsFile,numPairs+self->ContactElements->numElements);
91     Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
92     }
93     /* copy the old elements over */
94 jgs 150 if (Finley_noError()) {
95 jgs 82 /* get the face elements which are still in use:*/
96     Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
97     /* get the Contact elements which are still in use:*/
98     Finley_ElementFile_copyTable(0,newContactElementsFile,0,0,self->ContactElements);
99 gross 1028 c=self->ContactElements->numElements;
100 jgs 82 /* OMP */
101     for (e=0;e<numPairs;e++) {
102     e0=elem0[e];
103     e1=elem1[e];
104     newContactElementsFile->Id[c]=MIN(self->FaceElements->Id[e0],self->FaceElements->Id[e1]);
105     newContactElementsFile->Tag[c]=MIN(self->FaceElements->Tag[e0],self->FaceElements->Tag[e1]);
106     newContactElementsFile->Color[c]=e;
107     for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i,c,NN_Contact)]=self->FaceElements->Nodes[INDEX2(i,e0,NN)];
108     for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i+NN,c,NN_Contact)]=matching_nodes_in_elem1[INDEX2(i,e,NN)];
109     c++;
110     }
111 jgs 123 newContactElementsFile->minColor=0;
112     newContactElementsFile->maxColor=numPairs-1;
113 jgs 82 }
114     /* set new face and Contact elements */
115 jgs 150 if (Finley_noError()) {
116 jgs 82
117 ksteube 1312 Finley_ElementFile_free(self->FaceElements);
118 jgs 82 self->FaceElements=newFaceElementsFile;
119 ksteube 1312 Finley_ElementFile_free(self->ContactElements);
120 jgs 82 self->ContactElements=newContactElementsFile;
121 ksteube 1312 Finley_Mesh_prepare(self, optimize);
122 jgs 82
123     } else {
124 ksteube 1312 Finley_ElementFile_free(newFaceElementsFile);
125     Finley_ElementFile_free(newContactElementsFile);
126 jgs 82 }
127     }
128     }
129     TMPMEMFREE(elem1);
130     TMPMEMFREE(elem0);
131     TMPMEMFREE(matching_nodes_in_elem1);
132     TMPMEMFREE(elem_mask);
133     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26