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

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

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

trunk/esys2/finley/src/finleyC/Mesh_findMatchingFaces.c revision 82 by jgs, Tue Oct 26 06:53:54 2004 UTC trunk/finley/src/Mesh_findMatchingFaces.c revision 757 by woo409, Mon Jun 26 13:12:56 2006 UTC
# Line 1  Line 1 
1    /*
2     ************************************************************
3     *          Copyright 2006 by ACcESS MNRF                   *
4     *                                                          *
5     *              http://www.access.edu.au                    *
6     *       Primary Business: Queensland, Australia            *
7     *  Licensed under the Open Software License version 3.0    *
8     *     http://www.opensource.org/licenses/osl-3.0.php       *
9     *                                                          *
10     ************************************************************
11    */
12    
13  /**************************************************************/  /**************************************************************/
14    
15  /*   Finley: Mesh */  /*   Finley: Mesh */
# Line 6  Line 18 
18    
19  /**************************************************************/  /**************************************************************/
20    
21  /*   Copyrights by ACcESS Australia 2003/04 */  /*  Author: gross@access.edu.au */
22  /*   Author: gross@access.edu.au */  /*  Version: $Id$
 /*   Version: $Id$ */  
23    
24  /**************************************************************/  /**************************************************************/
25    
 #include "Common.h"  
 #include "Finley.h"  
26  #include "Util.h"  #include "Util.h"
27  #include "Mesh.h"  #include "Mesh.h"
   
28  /**************************************************************/  /**************************************************************/
29    
30  static double  Finley_Mesh_lockingGridSize=0;  static double  Finley_Mesh_lockingGridSize=0;
31    
32  int Finley_Mesh_findMatchingFaces_compar(const void *arg1 , const void *arg2 ) {  int Finley_Mesh_findMatchingFaces_compar(const void *arg1 , const void *arg2 ) {
33     Finley_Mesh_findMatchingFaces_center *e1,*e2;     Finley_Mesh_findMatchingFaces_center *e1,*e2;
34     int i,l,g;     bool_t l,g;
35       dim_t i;
36     e1=(Finley_Mesh_findMatchingFaces_center*) arg1;     e1=(Finley_Mesh_findMatchingFaces_center*) arg1;
37     e2=(Finley_Mesh_findMatchingFaces_center*) arg2;     e2=(Finley_Mesh_findMatchingFaces_center*) arg2;
38     for (i=0;i<MAX_numDim;i++) {     for (i=0;i<MAX_numDim;i++) {
# Line 38  int Finley_Mesh_findMatchingFaces_compar Line 47  int Finley_Mesh_findMatchingFaces_compar
47  }  }
48    
49  void Finley_Mesh_findMatchingFaces(Finley_NodeFile *nodes, Finley_ElementFile *faces, double safety_factor,double tolerance,  void Finley_Mesh_findMatchingFaces(Finley_NodeFile *nodes, Finley_ElementFile *faces, double safety_factor,double tolerance,
50                                     int* numPairs, int* elem0,int* elem1,int* matching_nodes_in_elem1) {                                     dim_t* numPairs, index_t* elem0,index_t* elem1,index_t* matching_nodes_in_elem1) {
51  #define getDist(_dist_,_e0_,_i0_,_e1_,_i1_) \  #define getDist(_dist_,_e0_,_i0_,_e1_,_i1_) \
52        {int i;   \        {dim_t i;   \
53        _dist_=0; \        _dist_=0; \
54        for (i=0;i<numDim;i++) _dist_=MAX(_dist_,ABS(X[INDEX3(i,_i0_,_e0_,numDim,NN)]-X[INDEX3(i,_i1_,_e1_,numDim,NN)])); \        for (i=0;i<numDim;i++) _dist_=MAX(_dist_,ABS(X[INDEX3(i,_i0_,_e0_,numDim,NN)]-X[INDEX3(i,_i1_,_e1_,numDim,NN)])); \
55        }        }
56    
57  #define SWAP(_i1_,_i2_) \  #define SWAP(_i1_,_i2_) \
58              {int* i;  \              {index_t* i;  \
59                i=(_i2_); \                i=(_i2_); \
60                (_i2_)=(_i1_); \                (_i2_)=(_i1_); \
61                (_i1_)=i; \                (_i1_)=i; \
62               }               }
63    
64      int e,i,i0,i1,e_0,e_1;      char error_msg[LenErrorMsg_MAX];
65      double h=DBLE(HUGE_VAL),h_local,dist,*X=NULL;      double h=DBLE(HUGE_VAL),h_local,dist,*X=NULL;
66      int NN=faces->ReferenceElement->Type->numNodes;      dim_t NN=faces->ReferenceElement->Type->numNodes;
67      int numDim=nodes->numDim;      dim_t numDim=nodes->numDim;
     int a1[NN],a2[NN],*perm,*perm_tmp,n;  
68      Finley_Mesh_findMatchingFaces_center *center;      Finley_Mesh_findMatchingFaces_center *center;
69        index_t e_0,e_1,a1[NN],a2[NN],*perm,*perm_tmp;
70        dim_t e,i,i0,i1,n;
71    
72      X=(double*) TMPMEMALLOC(sizeof(double)*NN*numDim*faces->numElements);      X=TMPMEMALLOC(NN*numDim*faces->numElements,double);
73      center=(Finley_Mesh_findMatchingFaces_center*) TMPMEMALLOC(sizeof(Finley_Mesh_findMatchingFaces_center)*faces->numElements);      center=TMPMEMALLOC(faces->numElements,Finley_Mesh_findMatchingFaces_center);
74      if (!(Finley_checkPtr(X) || Finley_checkPtr(center)) ) {      if (!(Finley_checkPtr(X) || Finley_checkPtr(center)) ) {
75         /* OMP */         /* OMP */
76         for (e=0;e<faces->numElements;e++) {         for (e=0;e<faces->numElements;e++) {
# Line 91  void Finley_Mesh_findMatchingFaces(Finle Line 101  void Finley_Mesh_findMatchingFaces(Finle
101         /* find elements with matching center */         /* find elements with matching center */
102         *numPairs=0;         *numPairs=0;
103         /* OMP */         /* OMP */
104         for (e=0;e<faces->numElements-1 && Finley_ErrorCode==NO_ERROR;e++) {         for (e=0;e<faces->numElements-1 && Finley_noError();e++) {
105            if (Finley_Mesh_findMatchingFaces_compar((void*) &(center[e]),(void*) &(center[e+1]))==0) {            if (Finley_Mesh_findMatchingFaces_compar((void*) &(center[e]),(void*) &(center[e+1]))==0) {
106                e_0=center[e].refId;                e_0=center[e].refId;
107                e_1=center[e+1].refId;                e_1=center[e+1].refId;
# Line 101  void Finley_Mesh_findMatchingFaces(Finle Line 111  void Finley_Mesh_findMatchingFaces(Finle
111                perm=a1;                perm=a1;
112                perm_tmp=a2;                perm_tmp=a2;
113                for (i=0;i<NN;i++) perm[i]=i;                for (i=0;i<NN;i++) perm[i]=i;
114                while (Finley_ErrorCode==NO_ERROR) {                while (Finley_noError()) {
115                   /* if node 0 and perm[0] are the same we are ready */                   /* if node 0 and perm[0] are the same we are ready */
116                   getDist(dist,e_0,0,e_1,perm[0]);                   getDist(dist,e_0,0,e_1,perm[0]);
117                   if (dist<=h*tolerance) break;                   if (dist<=h*tolerance) break;
# Line 112  void Finley_Mesh_findMatchingFaces(Finle Line 122  void Finley_Mesh_findMatchingFaces(Finle
122                   }                   }
123                   /* if the permutation is back at the identity, ie. perm[0]=0, the faces don't match: */                   /* if the permutation is back at the identity, ie. perm[0]=0, the faces don't match: */
124                   if (perm[0]==0) {                   if (perm[0]==0) {
125                         Finley_ErrorCode=VALUE_ERROR;                         sprintf(error_msg,"__FILE__:couldn't match first node of element %d to touching element %d",e_0,e_1);
126                         sprintf(Finley_ErrorMsg,"couldn't match first node of element %d to touching element %d",e_0,e_1);                         Finley_setError(VALUE_ERROR,error_msg);
127                   }                   }
128                }                }
129                /* now we check if the second nodes match */                /* now we check if the second nodes match */
130                if (Finley_ErrorCode==NO_ERROR) {                if (Finley_noError()) {
131                   if (faces->ReferenceElement->Type->numNodesOnFace>1) {                   if (faces->ReferenceElement->Type->numNodesOnFace>1) {
132                      getDist(dist,e_0,1,e_1,perm[faces->ReferenceElement->Type->faceNode[1]]);                      getDist(dist,e_0,1,e_1,perm[faces->ReferenceElement->Type->faceNode[1]]);
133                      /* if the second node does not match we reverse the direction of the nodes */                      /* if the second node does not match we reverse the direction of the nodes */
134                      if (dist>h*tolerance) {                      if (dist>h*tolerance) {
135                            /* rotate the nodes */                            /* rotate the nodes */
136                            if (faces->ReferenceElement->Type->reverseNodes[0]<0) {                            if (faces->ReferenceElement->Type->reverseNodes[0]<0) {
137                               Finley_ErrorCode=VALUE_ERROR;                               sprintf(error_msg,"__FILE__:couldn't match the second node of element %d to touching element %d",e_0,e_1);
138                               sprintf(Finley_ErrorMsg,"couldn't match the second node of element %d to touching element %d",e_0,e_1);                               Finley_setError(VALUE_ERROR,error_msg);
139                            } else {                            } else {
140                               for (i=0;i<NN;i++) perm_tmp[i]=perm[faces->ReferenceElement->Type->reverseNodes[i]];                               for (i=0;i<NN;i++) perm_tmp[i]=perm[faces->ReferenceElement->Type->reverseNodes[i]];
141                               SWAP(perm,perm_tmp);                               SWAP(perm,perm_tmp);
142                               getDist(dist,e_0,1,e_1,perm[faces->ReferenceElement->Type->faceNode[1]]);                               getDist(dist,e_0,1,e_1,perm[faces->ReferenceElement->Type->faceNode[1]]);
143                               if (dist>h*tolerance) {                               if (dist>h*tolerance) {
144                                   Finley_ErrorCode=VALUE_ERROR;                                   sprintf(error_msg,"__FILE__:couldn't match the second node of element %d to touching element %d",e_0,e_1);
145                                   sprintf(Finley_ErrorMsg,"couldn't match the second node of element %d to touching element %d",e_0,e_1);                                   Finley_setError(VALUE_ERROR,error_msg);
146                               }                               }
147                            }                            }
148                      }                      }
149                   }                   }
150                }                }
151                /* we check if the rest of the face nodes match: */                /* we check if the rest of the face nodes match: */
152                if (Finley_ErrorCode==NO_ERROR) {                if (Finley_noError()) {
153                   for (i=2;i<faces->ReferenceElement->Type->numNodesOnFace;i++) {                   for (i=2;i<faces->ReferenceElement->Type->numNodesOnFace;i++) {
154                      n=faces->ReferenceElement->Type->faceNode[i];                      n=faces->ReferenceElement->Type->faceNode[i];
155                      getDist(dist,e_0,n,e_1,perm[n]);                      getDist(dist,e_0,n,e_1,perm[n]);
156                      if (dist>h*tolerance) {                      if (dist>h*tolerance) {
157                         Finley_ErrorCode=VALUE_ERROR;                         sprintf(error_msg,"__FILE__:couldn't match the %d-th node of element %d to touching element %d",i,e_0,e_1);
158                         sprintf(Finley_ErrorMsg,"couldn't match the %d-th node of element %d to touching element %d",i,e_0,e_1);                         Finley_setError(VALUE_ERROR,error_msg);
159                         break;                         break;
160                      }                      }
161                   }                   }
162                }                }
163                /* copy over the permuted nodes of e_1 into matching_nodes_in_elem1 */                /* copy over the permuted nodes of e_1 into matching_nodes_in_elem1 */
164                if (Finley_ErrorCode==NO_ERROR) {                if (Finley_noError()) {
165                   for (i=0;i<NN;i++)  matching_nodes_in_elem1[INDEX2(i,*numPairs,NN)]=faces->Nodes[INDEX2(perm[i],e_1,NN)];                   for (i=0;i<NN;i++)  matching_nodes_in_elem1[INDEX2(i,*numPairs,NN)]=faces->Nodes[INDEX2(perm[i],e_1,NN)];
166                }                }
167                (*numPairs)++;                (*numPairs)++;
# Line 171  void Finley_Mesh_findMatchingFaces(Finle Line 181  void Finley_Mesh_findMatchingFaces(Finle
181    
182  /*  /*
183  * $Log$  * $Log$
184  * Revision 1.1  2004/10/26 06:53:57  jgs  * Revision 1.6  2005/09/15 03:44:22  jgs
185  * Initial revision  * Merge of development branch dev-02 back to main trunk on 2005-09-15
186    *
187    * Revision 1.5.2.1  2005/09/07 06:26:19  gross
188    * the solver from finley are put into the standalone package paso now
189    *
190    * Revision 1.5  2005/07/08 04:07:51  jgs
191    * Merge of development branch back to main trunk on 2005-07-08
192    *
193    * Revision 1.4  2004/12/15 07:08:32  jgs
194    * *** empty log message ***
195    * Revision 1.1.1.1.2.2  2005/06/29 02:34:51  gross
196    * some changes towards 64 integers in finley
197  *  *
198  * Revision 1.2  2004/07/02 04:21:13  gross  * Revision 1.1.1.1.2.1  2004/11/24 01:37:14  gross
199  * Finley C code has been included  * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now
200  *  *
 * Revision 1.1.1.1  2004/06/24 04:00:40  johng  
 * Initial version of eys using boost-python.  
201  *  *
202  *  *
203  */  */

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

  ViewVC Help
Powered by ViewVC 1.1.26