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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/finley/src/finleyC/Mesh_joinFaces.c revision 82 by jgs, Tue Oct 26 06:53:54 2004 UTC temp/finley/src/Mesh_joinFaces.c revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC
# Line 1  Line 1 
 /**************************************************************/  
1    
2  /*   Finley: Mesh */  /* $Id$ */
3    
4  /* detects faces in the mesh that match and replaces it by step elements */  /*******************************************************
5     *
6     *           Copyright 2003-2007 by ACceSS MNRF
7     *       Copyright 2007 by University of Queensland
8     *
9     *                http://esscc.uq.edu.au
10     *        Primary Business: Queensland, Australia
11     *  Licensed under the Open Software License version 3.0
12     *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  /**************************************************************/  /**************************************************************/
17    
18  /*   Copyrights by ACcESS Australia 2003 */  /*   Finley: Mesh */
19  /*   Author: gross@access.edu.au */  
20  /*   Version: $Id$ */  /* detects faces in the mesh that match and replaces it by step elements */
21    
22  /**************************************************************/  /**************************************************************/
23    
 #include "Common.h"  
 #include "Finley.h"  
24  #include "Mesh.h"  #include "Mesh.h"
25    
26  /**************************************************************/  /**************************************************************/
27    
28  void Finley_Mesh_joinFaces(Finley_Mesh* self,double safety_factor,double tolerance) {  void Finley_Mesh_joinFaces(Finley_Mesh* self,double safety_factor,double tolerance, bool_t optimize) {
29    
30     int numPairs,*elem1=NULL,*elem0=NULL,*elem_mask=NULL,*matching_nodes_in_elem1=NULL;     char error_msg[LenErrorMsg_MAX];
31       index_t e0,e1,*elem1=NULL,*elem0=NULL,*elem_mask=NULL,*matching_nodes_in_elem1=NULL;
32     Finley_ElementFile *newFaceElementsFile=NULL,*newContactElementsFile=NULL;     Finley_ElementFile *newFaceElementsFile=NULL,*newContactElementsFile=NULL;
33     int e,i,e0,e1;     dim_t e,i,numPairs, NN, NN_Contact,c, new_numFaceElements;
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->FaceElements==NULL) return;     if (self->FaceElements==NULL) return;
40    
41     if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {     if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
42       Finley_ErrorCode=TYPE_ERROR;       sprintf(error_msg,"Finley_Mesh_joinFaces:joining faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
43       sprintf(Finley_ErrorMsg,"joining faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);       Finley_setError(TYPE_ERROR,error_msg);
44       return;       return;
45     }     }
46     if (self->ContactElements==NULL) {     if (self->ContactElements==NULL) {
47       Finley_ErrorCode=TYPE_ERROR;       Finley_setError(TYPE_ERROR,"Finley_Mesh_joinFaces: no contact element file present.");
      sprintf(Finley_ErrorMsg,"no contact element file present.");  
48       return;       return;
49     }     }
50    
51     int NN=self->FaceElements->ReferenceElement->Type->numNodes;     NN=self->FaceElements->ReferenceElement->Type->numNodes;
52     int NN_Contact=self->ContactElements->ReferenceElement->Type->numNodes;     NN_Contact=self->ContactElements->ReferenceElement->Type->numNodes;
53    
54     if (2*NN!=NN_Contact) {     if (2*NN!=NN_Contact) {
55       Finley_ErrorCode=TYPE_ERROR;       sprintf(error_msg,"Finley_Mesh_joinFaces:contact element file for %s cannot hold elements created from face elements %s",
      sprintf(Finley_ErrorMsg,"contact element file for %s cannot hold elements created from face elements %s",  
56             self->ContactElements->ReferenceElement->Type->Name,self->FaceElements->ReferenceElement->Type->Name);             self->ContactElements->ReferenceElement->Type->Name,self->FaceElements->ReferenceElement->Type->Name);
57         Finley_setError(TYPE_ERROR,error_msg);
58       return;       return;
59     }     }
60    
61     /* allocate work arrays */     /* allocate work arrays */
62     elem1=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements);     elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
63     elem0=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements);     elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
64     elem_mask=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements);     elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
65     matching_nodes_in_elem1=(int*) TMPMEMALLOC(sizeof(int)*self->FaceElements->numElements*NN);     matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
66    
67     if (!(Finley_checkPtr(elem1) || Finley_checkPtr(elem0) || Finley_checkPtr(elem_mask) || Finley_checkPtr(matching_nodes_in_elem1)))  {     if (!(Finley_checkPtr(elem1) || Finley_checkPtr(elem0) || Finley_checkPtr(elem_mask) || Finley_checkPtr(matching_nodes_in_elem1)))  {
68    
69        /* find the matching face elements */        /* find the matching face elements */
70        Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);        Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
71        if (Finley_ErrorCode==NO_ERROR) {        if (Finley_noError()) {
72           /* get a list of the face elements to be kept */           /* get a list of the face elements to be kept */
73           #pragma omp parallel for private(e) schedule(static)           #pragma omp parallel for private(e) schedule(static)
74           for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=1;           for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=1;
# Line 63  void Finley_Mesh_joinFaces(Finley_Mesh* Line 76  void Finley_Mesh_joinFaces(Finley_Mesh*
76               elem_mask[elem0[e]]=0;               elem_mask[elem0[e]]=0;
77               elem_mask[elem1[e]]=0;               elem_mask[elem1[e]]=0;
78           }           }
79           int new_numFaceElements=0;           new_numFaceElements=0;
80           /* OMP */           /* OMP */
81           for(e=0;e<self->FaceElements->numElements;e++) {           for(e=0;e<self->FaceElements->numElements;e++) {
82               if (elem_mask[e]>0) {               if (elem_mask[e]>0) {
# Line 72  void Finley_Mesh_joinFaces(Finley_Mesh* Line 85  void Finley_Mesh_joinFaces(Finley_Mesh*
85               }               }
86           }           }
87           /*  allocate new face element and Contact element files */           /*  allocate new face element and Contact element files */
88           newContactElementsFile=Finley_ElementFile_alloc(self->ContactElements->ReferenceElement->Type->TypeId,self->ContactElements->order);           newContactElementsFile=Finley_ElementFile_alloc(self->ContactElements->ReferenceElement->Type->TypeId,self->ContactElements->order,self->ContactElements->reduced_order, self->MPIInfo);
89           newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order);           newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order,self->FaceElements->reduced_order, self->MPIInfo);
90           if (Finley_ErrorCode==NO_ERROR) {           if (Finley_noError()) {
91                 Finley_ElementFile_allocTable(newContactElementsFile,numPairs+self->ContactElements->numElements);                 Finley_ElementFile_allocTable(newContactElementsFile,numPairs+self->ContactElements->numElements);
92                 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);                 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
93           }           }
94           /* copy the old elements over */           /* copy the old elements over */
95           if (Finley_ErrorCode==NO_ERROR) {           if (Finley_noError()) {
96              /* get the face elements which are still in use:*/              /* get the face elements which are still in use:*/
97              Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);              Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
98              /* get the Contact elements which are still in use:*/              /* get the Contact elements which are still in use:*/
99              Finley_ElementFile_copyTable(0,newContactElementsFile,0,0,self->ContactElements);              Finley_ElementFile_copyTable(0,newContactElementsFile,0,0,self->ContactElements);
100              int c=self->ContactElements->numElements;              c=self->ContactElements->numElements;
101              /* OMP */              /* OMP */
102              for (e=0;e<numPairs;e++) {              for (e=0;e<numPairs;e++) {
103                   e0=elem0[e];                   e0=elem0[e];
# Line 96  void Finley_Mesh_joinFaces(Finley_Mesh* Line 109  void Finley_Mesh_joinFaces(Finley_Mesh*
109                   for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i+NN,c,NN_Contact)]=matching_nodes_in_elem1[INDEX2(i,e,NN)];                   for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i+NN,c,NN_Contact)]=matching_nodes_in_elem1[INDEX2(i,e,NN)];
110                   c++;                   c++;
111              }              }
112              newContactElementsFile->numColors=numPairs;              newContactElementsFile->minColor=0;
113                newContactElementsFile->maxColor=numPairs-1;
114           }           }
115           /* set new face and Contact elements */           /* set new face and Contact elements */
116           if (Finley_ErrorCode==NO_ERROR) {           if (Finley_noError()) {
117    
118              Finley_ElementFile_dealloc(self->FaceElements);              Finley_ElementFile_free(self->FaceElements);
119              self->FaceElements=newFaceElementsFile;              self->FaceElements=newFaceElementsFile;
120              Finley_ElementFile_prepare(&(self->FaceElements),self->Nodes->numNodes,self->Nodes->degreeOfFreedom);              Finley_ElementFile_free(self->ContactElements);
   
             Finley_ElementFile_dealloc(self->ContactElements);  
121              self->ContactElements=newContactElementsFile;              self->ContactElements=newContactElementsFile;
122              Finley_ElementFile_prepare(&(self->ContactElements),self->Nodes->numNodes,self->Nodes->degreeOfFreedom);              Finley_Mesh_prepare(self, optimize);
   
             Finley_Mesh_prepareNodes(self);  
123    
124           } else {           } else {
125              Finley_ElementFile_dealloc(newFaceElementsFile);              Finley_ElementFile_free(newFaceElementsFile);
126              Finley_ElementFile_dealloc(newContactElementsFile);              Finley_ElementFile_free(newContactElementsFile);
127           }           }
128        }        }
129     }     }
# Line 122  void Finley_Mesh_joinFaces(Finley_Mesh* Line 132  void Finley_Mesh_joinFaces(Finley_Mesh*
132     TMPMEMFREE(matching_nodes_in_elem1);     TMPMEMFREE(matching_nodes_in_elem1);
133     TMPMEMFREE(elem_mask);     TMPMEMFREE(elem_mask);
134  }  }
   
 /*  
 * $Log$  
 * Revision 1.1  2004/10/26 06:53:57  jgs  
 * Initial revision  
 *  
 * Revision 1.1.1.1  2004/06/24 04:00:40  johng  
 * Initial version of eys using boost-python.  
 *  
 *  
 */  
   

Legend:
Removed from v.82  
changed lines
  Added in v.1387

  ViewVC Help
Powered by ViewVC 1.1.26