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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (hide annotations)
Tue Oct 25 01:51:20 2005 UTC (14 years ago) by jgs
Original Path: trunk/esys2/finley/src/finleyC/Mesh_joinFaces.c
File MIME type: text/plain
File size: 6534 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-10-25

1 jgs 150 /*
2     ******************************************************************************
3     * *
4     * COPYRIGHT ACcESS 2003,2004,2005 - All Rights Reserved *
5     * *
6     * This software is the property of ACcESS. No part of this code *
7     * may be copied in any form or by any means without the expressed written *
8     * consent of ACcESS. Copying, use or modification of this software *
9     * by any unauthorised person is illegal unless that person has a software *
10     * license agreement with ACcESS. *
11     * *
12     ******************************************************************************
13     */
14    
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 jgs 150 /* Author: gross@access.edu.au */
24     /* Version: $Id$ */
25 jgs 82
26     /**************************************************************/
27    
28     #include "Mesh.h"
29    
30     /**************************************************************/
31    
32     void Finley_Mesh_joinFaces(Finley_Mesh* self,double safety_factor,double tolerance) {
33    
34 jgs 150 char error_msg[LenErrorMsg_MAX];
35 jgs 123 index_t e0,e1,*elem1=NULL,*elem0=NULL,*elem_mask=NULL,*matching_nodes_in_elem1=NULL;
36 jgs 82 Finley_ElementFile *newFaceElementsFile=NULL,*newContactElementsFile=NULL;
37 jgs 123 dim_t e,i,numPairs;
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     int NN=self->FaceElements->ReferenceElement->Type->numNodes;
51     int NN_Contact=self->ContactElements->ReferenceElement->Type->numNodes;
52    
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     /* find the matching face elements */
68     Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
69 jgs 150 if (Finley_noError()) {
70 jgs 82 /* get a list of the face elements to be kept */
71     #pragma omp parallel for private(e) schedule(static)
72     for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=1;
73     for(e=0;e<numPairs;e++) {
74     elem_mask[elem0[e]]=0;
75     elem_mask[elem1[e]]=0;
76     }
77 jgs 123 dim_t new_numFaceElements=0;
78 jgs 82 /* OMP */
79     for(e=0;e<self->FaceElements->numElements;e++) {
80     if (elem_mask[e]>0) {
81     elem_mask[new_numFaceElements]=e;
82     new_numFaceElements++;
83     }
84     }
85     /* allocate new face element and Contact element files */
86     newContactElementsFile=Finley_ElementFile_alloc(self->ContactElements->ReferenceElement->Type->TypeId,self->ContactElements->order);
87     newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order);
88 jgs 150 if (Finley_noError()) {
89 jgs 82 Finley_ElementFile_allocTable(newContactElementsFile,numPairs+self->ContactElements->numElements);
90     Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
91     }
92     /* copy the old elements over */
93 jgs 150 if (Finley_noError()) {
94 jgs 82 /* get the face elements which are still in use:*/
95     Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
96     /* get the Contact elements which are still in use:*/
97     Finley_ElementFile_copyTable(0,newContactElementsFile,0,0,self->ContactElements);
98 jgs 123 dim_t c=self->ContactElements->numElements;
99 jgs 82 /* OMP */
100     for (e=0;e<numPairs;e++) {
101     e0=elem0[e];
102     e1=elem1[e];
103     newContactElementsFile->Id[c]=MIN(self->FaceElements->Id[e0],self->FaceElements->Id[e1]);
104     newContactElementsFile->Tag[c]=MIN(self->FaceElements->Tag[e0],self->FaceElements->Tag[e1]);
105     newContactElementsFile->Color[c]=e;
106     for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i,c,NN_Contact)]=self->FaceElements->Nodes[INDEX2(i,e0,NN)];
107     for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i+NN,c,NN_Contact)]=matching_nodes_in_elem1[INDEX2(i,e,NN)];
108     c++;
109     }
110 jgs 123 newContactElementsFile->minColor=0;
111     newContactElementsFile->maxColor=numPairs-1;
112 jgs 82 }
113     /* set new face and Contact elements */
114 jgs 150 if (Finley_noError()) {
115 jgs 82
116     Finley_ElementFile_dealloc(self->FaceElements);
117     self->FaceElements=newFaceElementsFile;
118     Finley_ElementFile_prepare(&(self->FaceElements),self->Nodes->numNodes,self->Nodes->degreeOfFreedom);
119    
120     Finley_ElementFile_dealloc(self->ContactElements);
121     self->ContactElements=newContactElementsFile;
122     Finley_ElementFile_prepare(&(self->ContactElements),self->Nodes->numNodes,self->Nodes->degreeOfFreedom);
123    
124 jgs 153 Finley_Mesh_prepare(self);
125 jgs 82
126     } else {
127     Finley_ElementFile_dealloc(newFaceElementsFile);
128     Finley_ElementFile_dealloc(newContactElementsFile);
129     }
130     }
131     }
132     TMPMEMFREE(elem1);
133     TMPMEMFREE(elem0);
134     TMPMEMFREE(matching_nodes_in_elem1);
135     TMPMEMFREE(elem_mask);
136     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26