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

Annotation of /temp/finley/src/Mesh_findMatchingFaces.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1387 - (hide annotations)
Fri Jan 11 07:45:26 2008 UTC (11 years, 9 months ago) by trankine
File MIME type: text/plain
File size: 8529 byte(s)
Restore the trunk that existed before the windows changes were committed to the (now moved to branches) old trunk.
1 jgs 150
2 ksteube 1312 /* $Id$ */
3    
4     /*******************************************************
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 jgs 82 /**************************************************************/
17    
18     /* Finley: Mesh */
19    
20     /* searches for faces in the mesh which are matching */
21    
22     /**************************************************************/
23    
24     #include "Util.h"
25     #include "Mesh.h"
26     /**************************************************************/
27    
28     static double Finley_Mesh_lockingGridSize=0;
29    
30     int Finley_Mesh_findMatchingFaces_compar(const void *arg1 , const void *arg2 ) {
31     Finley_Mesh_findMatchingFaces_center *e1,*e2;
32 jgs 123 bool_t l,g;
33     dim_t i;
34 jgs 82 e1=(Finley_Mesh_findMatchingFaces_center*) arg1;
35     e2=(Finley_Mesh_findMatchingFaces_center*) arg2;
36     for (i=0;i<MAX_numDim;i++) {
37     l= (e1->x[i]<e2->x[i]+Finley_Mesh_lockingGridSize) ? TRUE : FALSE;
38     g= (e2->x[i]<e1->x[i]+Finley_Mesh_lockingGridSize) ? TRUE : FALSE;
39     if (! (l && g)) {
40     if (l) return -1;
41     if (g) return 1;
42     }
43     }
44 gross 888 if ( e1->refId < e2->refId ) {
45     return -1;
46     } else if ( e1->refId > e2->refId ) {
47 gross 1134 return 1;
48 gross 888 } else {
49     return 0;
50     }
51 jgs 82 }
52    
53     void Finley_Mesh_findMatchingFaces(Finley_NodeFile *nodes, Finley_ElementFile *faces, double safety_factor,double tolerance,
54 jgs 123 dim_t* numPairs, index_t* elem0,index_t* elem1,index_t* matching_nodes_in_elem1) {
55 jgs 82 #define getDist(_dist_,_e0_,_i0_,_e1_,_i1_) \
56 jgs 123 {dim_t i; \
57 jgs 82 _dist_=0; \
58     for (i=0;i<numDim;i++) _dist_=MAX(_dist_,ABS(X[INDEX3(i,_i0_,_e0_,numDim,NN)]-X[INDEX3(i,_i1_,_e1_,numDim,NN)])); \
59     }
60    
61 jgs 150 char error_msg[LenErrorMsg_MAX];
62 jgs 82 double h=DBLE(HUGE_VAL),h_local,dist,*X=NULL;
63 jgs 123 dim_t NN=faces->ReferenceElement->Type->numNodes;
64     dim_t numDim=nodes->numDim;
65 jgs 82 Finley_Mesh_findMatchingFaces_center *center;
66 gross 1376 index_t e_0,e_1,*a1=NULL,*a2=NULL,*perm=NULL,*perm_tmp=NULL,*itmp_ptr=NULL;
67 jgs 123 dim_t e,i,i0,i1,n;
68 jgs 82
69 jgs 102 X=TMPMEMALLOC(NN*numDim*faces->numElements,double);
70     center=TMPMEMALLOC(faces->numElements,Finley_Mesh_findMatchingFaces_center);
71 gross 1028 a1=TMPMEMALLOC(NN,int);
72     a2=TMPMEMALLOC(NN,int);
73     if (!(Finley_checkPtr(X) || Finley_checkPtr(center) || Finley_checkPtr(a1) || Finley_checkPtr(a2)) ) {
74 jgs 82 /* OMP */
75     for (e=0;e<faces->numElements;e++) {
76     /* get the coordinates of the nodes */
77     Finley_Util_Gather_double(NN,&(faces->Nodes[INDEX2(0,e,NN)]),numDim,nodes->Coordinates,&(X[INDEX3(0,0,e,numDim,NN)]));
78     /* get the element center */
79     center[e].refId=e;
80     for (i=0;i<MAX_numDim;i++) center[e].x[i]=0;
81     for (i0=0;i0<faces->ReferenceElement->Type->numNodesOnFace;i0++) {
82     for (i=0;i<numDim;i++) center[e].x[i]+=X[INDEX3(i,faces->ReferenceElement->Type->faceNode[i0],e,numDim,NN)];
83     }
84     for (i=0;i<numDim;i++) center[e].x[i]/=faces->ReferenceElement->Type->numNodesOnFace;
85     /* get the minimum distance between nodes in the element */
86     for (i0=0;i0<faces->ReferenceElement->Type->numNodesOnFace;i0++) {
87     for (i1=i0+1;i1<faces->ReferenceElement->Type->numNodesOnFace;i1++) {
88     getDist(h_local,e,faces->ReferenceElement->Type->faceNode[i0],e,faces->ReferenceElement->Type->faceNode[i1]);
89     h=MIN(h,h_local);
90     }
91     }
92     }
93     /* set the */
94     Finley_Mesh_lockingGridSize=h*MAX(safety_factor,0);
95     #ifdef Finley_TRACE
96     printf("locking grid size is %e\n",Finley_Mesh_lockingGridSize);
97 gross 888 printf("absolute tolerance is %e.\n",h * tolerance);
98 jgs 82 #endif
99     /* sort the elements by center center coordinates (lexigraphical)*/
100     qsort(center,faces->numElements,sizeof(Finley_Mesh_findMatchingFaces_center),Finley_Mesh_findMatchingFaces_compar);
101     /* find elements with matching center */
102     *numPairs=0;
103     /* OMP */
104 jgs 150 for (e=0;e<faces->numElements-1 && Finley_noError();e++) {
105 gross 888 dist=0;
106     for (i=0;i<numDim;i++) dist=MAX(dist,ABS(center[e].x[i]-center[e+1].x[i]));
107     if (dist < h * tolerance) {
108 jgs 82 e_0=center[e].refId;
109     e_1=center[e+1].refId;
110     elem0[*numPairs]=e_0;
111     elem1[*numPairs]=e_1;
112     /* now the element e_1 is rotated such that the first node in element e_0 and e_1 have the same coordinates */
113     perm=a1;
114     perm_tmp=a2;
115     for (i=0;i<NN;i++) perm[i]=i;
116 jgs 150 while (Finley_noError()) {
117 jgs 82 /* if node 0 and perm[0] are the same we are ready */
118     getDist(dist,e_0,0,e_1,perm[0]);
119     if (dist<=h*tolerance) break;
120     if (faces->ReferenceElement->Type->shiftNodes[0]>=0) {
121     /* rotate the nodes */
122 gross 1377 itmp_ptr=perm;
123     perm=perm_tmp;
124     perm_tmp=itmp_ptr;
125     #pragma ivdep
126     for (i=0;i<NN;i++) perm[i]=perm_tmp[faces->ReferenceElement->Type->shiftNodes[i]];
127 jgs 82 }
128     /* if the permutation is back at the identity, ie. perm[0]=0, the faces don't match: */
129     if (perm[0]==0) {
130 gross 888 sprintf(error_msg,"Mesh_findMatchingFaces:couldn't match first node of element %d to touching element %d",e_0,e_1);
131 jgs 150 Finley_setError(VALUE_ERROR,error_msg);
132 jgs 82 }
133     }
134     /* now we check if the second nodes match */
135 jgs 150 if (Finley_noError()) {
136 jgs 82 if (faces->ReferenceElement->Type->numNodesOnFace>1) {
137     getDist(dist,e_0,1,e_1,perm[faces->ReferenceElement->Type->faceNode[1]]);
138     /* if the second node does not match we reverse the direction of the nodes */
139     if (dist>h*tolerance) {
140     /* rotate the nodes */
141     if (faces->ReferenceElement->Type->reverseNodes[0]<0) {
142 gross 888 sprintf(error_msg,"Mesh_findMatchingFaces:couldn't match the second node of element %d to touching element %d",e_0,e_1);
143 jgs 150 Finley_setError(VALUE_ERROR,error_msg);
144 jgs 82 } else {
145 gross 1377 itmp_ptr=perm;
146     perm=perm_tmp;
147     perm_tmp=itmp_ptr;
148     #pragma ivdep
149     for (i=0;i<NN;i++) perm[i]=perm_tmp[faces->ReferenceElement->Type->reverseNodes[i]];
150 jgs 82 getDist(dist,e_0,1,e_1,perm[faces->ReferenceElement->Type->faceNode[1]]);
151     if (dist>h*tolerance) {
152 gross 888 sprintf(error_msg,"Mesh_findMatchingFaces:couldn't match the second node of element %d to touching element %d",e_0,e_1);
153 jgs 150 Finley_setError(VALUE_ERROR,error_msg);
154 jgs 82 }
155     }
156     }
157     }
158     }
159     /* we check if the rest of the face nodes match: */
160 jgs 150 if (Finley_noError()) {
161 jgs 82 for (i=2;i<faces->ReferenceElement->Type->numNodesOnFace;i++) {
162     n=faces->ReferenceElement->Type->faceNode[i];
163     getDist(dist,e_0,n,e_1,perm[n]);
164     if (dist>h*tolerance) {
165 gross 888 sprintf(error_msg,"Mesh_findMatchingFaces:couldn't match the %d-th node of element %d to touching element %d",i,e_0,e_1);
166 jgs 150 Finley_setError(VALUE_ERROR,error_msg);
167 jgs 82 break;
168     }
169     }
170     }
171     /* copy over the permuted nodes of e_1 into matching_nodes_in_elem1 */
172 jgs 150 if (Finley_noError()) {
173 jgs 82 for (i=0;i<NN;i++) matching_nodes_in_elem1[INDEX2(i,*numPairs,NN)]=faces->Nodes[INDEX2(perm[i],e_1,NN)];
174     }
175     (*numPairs)++;
176     }
177     }
178     #ifdef Finley_TRACE
179     printf("number of pairs of matching faces %d\n",*numPairs);
180     #endif
181     }
182     /* clean up */
183     TMPMEMFREE(X);
184     TMPMEMFREE(center);
185 gross 1028 TMPMEMFREE(a1);
186     TMPMEMFREE(a1);
187 jgs 82
188     #undef getDist
189     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26