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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 123 - (hide annotations)
Fri Jul 8 04:08:13 2005 UTC (14 years, 5 months ago) by jgs
File MIME type: text/plain
File size: 6145 byte(s)
Merge of development branch back to main trunk on 2005-07-08

1 jgs 82 /**************************************************************/
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 jgs 123 index_t e0,e1,*elem1=NULL,*elem0=NULL,*elem_mask=NULL,*matching_nodes_in_elem1=NULL;
24 jgs 82 Finley_ElementFile *newFaceElementsFile=NULL,*newContactElementsFile=NULL;
25 jgs 123 dim_t e,i,numPairs;
26 jgs 82 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 jgs 123 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 jgs 82
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 jgs 123 dim_t new_numFaceElements=0;
67 jgs 82 /* 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 jgs 123 dim_t c=self->ContactElements->numElements;
88 jgs 82 /* 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 jgs 123 newContactElementsFile->minColor=0;
100     newContactElementsFile->maxColor=numPairs-1;
101 jgs 82 }
102     /* set new face and Contact elements */
103     if (Finley_ErrorCode==NO_ERROR) {
104    
105     Finley_ElementFile_dealloc(self->FaceElements);
106     self->FaceElements=newFaceElementsFile;
107     Finley_ElementFile_prepare(&(self->FaceElements),self->Nodes->numNodes,self->Nodes->degreeOfFreedom);
108    
109     Finley_ElementFile_dealloc(self->ContactElements);
110     self->ContactElements=newContactElementsFile;
111     Finley_ElementFile_prepare(&(self->ContactElements),self->Nodes->numNodes,self->Nodes->degreeOfFreedom);
112    
113     Finley_Mesh_prepareNodes(self);
114    
115     } else {
116     Finley_ElementFile_dealloc(newFaceElementsFile);
117     Finley_ElementFile_dealloc(newContactElementsFile);
118     }
119     }
120     }
121     TMPMEMFREE(elem1);
122     TMPMEMFREE(elem0);
123     TMPMEMFREE(matching_nodes_in_elem1);
124     TMPMEMFREE(elem_mask);
125     }
126    
127     /*
128     * $Log$
129 jgs 123 * Revision 1.5 2005/07/08 04:07:52 jgs
130     * Merge of development branch back to main trunk on 2005-07-08
131     *
132 jgs 102 * Revision 1.4 2004/12/15 07:08:33 jgs
133 jgs 97 * *** empty log message ***
134 jgs 123 * Revision 1.1.1.1.2.2 2005/06/29 02:34:52 gross
135     * some changes towards 64 integers in finley
136 jgs 82 *
137 jgs 123 * Revision 1.1.1.1.2.1 2004/11/24 01:37:14 gross
138     * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now
139 jgs 97 *
140 jgs 82 *
141 jgs 123 *
142 jgs 82 */
143    

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26