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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 123 - (show annotations)
Fri Jul 8 04:08:13 2005 UTC (14 years, 3 months ago) by jgs
Original Path: trunk/esys2/finley/src/finleyC/Mesh_findMatchingFaces.c
File MIME type: text/plain
File size: 8184 byte(s)
Merge of development branch back to main trunk on 2005-07-08

1 /**************************************************************/
2
3 /* Finley: Mesh */
4
5 /* searches for faces in the mesh which are matching */
6
7 /**************************************************************/
8
9 /* Copyrights by ACcESS Australia 2003/04 */
10 /* Author: gross@access.edu.au */
11 /* Version: $Id$ */
12
13 /**************************************************************/
14
15 #include "Common.h"
16 #include "Finley.h"
17 #include "Util.h"
18 #include "Mesh.h"
19
20 /**************************************************************/
21
22 static double Finley_Mesh_lockingGridSize=0;
23
24 int Finley_Mesh_findMatchingFaces_compar(const void *arg1 , const void *arg2 ) {
25 Finley_Mesh_findMatchingFaces_center *e1,*e2;
26 bool_t l,g;
27 dim_t i;
28 e1=(Finley_Mesh_findMatchingFaces_center*) arg1;
29 e2=(Finley_Mesh_findMatchingFaces_center*) arg2;
30 for (i=0;i<MAX_numDim;i++) {
31 l= (e1->x[i]<e2->x[i]+Finley_Mesh_lockingGridSize) ? TRUE : FALSE;
32 g= (e2->x[i]<e1->x[i]+Finley_Mesh_lockingGridSize) ? TRUE : FALSE;
33 if (! (l && g)) {
34 if (l) return -1;
35 if (g) return 1;
36 }
37 }
38 return 0;
39 }
40
41 void Finley_Mesh_findMatchingFaces(Finley_NodeFile *nodes, Finley_ElementFile *faces, double safety_factor,double tolerance,
42 dim_t* numPairs, index_t* elem0,index_t* elem1,index_t* matching_nodes_in_elem1) {
43 #define getDist(_dist_,_e0_,_i0_,_e1_,_i1_) \
44 {dim_t i; \
45 _dist_=0; \
46 for (i=0;i<numDim;i++) _dist_=MAX(_dist_,ABS(X[INDEX3(i,_i0_,_e0_,numDim,NN)]-X[INDEX3(i,_i1_,_e1_,numDim,NN)])); \
47 }
48
49 #define SWAP(_i1_,_i2_) \
50 {index_t* i; \
51 i=(_i2_); \
52 (_i2_)=(_i1_); \
53 (_i1_)=i; \
54 }
55
56 double h=DBLE(HUGE_VAL),h_local,dist,*X=NULL;
57 dim_t NN=faces->ReferenceElement->Type->numNodes;
58 dim_t numDim=nodes->numDim;
59 Finley_Mesh_findMatchingFaces_center *center;
60 index_t e_0,e_1,a1[NN],a2[NN],*perm,*perm_tmp;
61 dim_t e,i,i0,i1,n;
62
63 X=TMPMEMALLOC(NN*numDim*faces->numElements,double);
64 center=TMPMEMALLOC(faces->numElements,Finley_Mesh_findMatchingFaces_center);
65 if (!(Finley_checkPtr(X) || Finley_checkPtr(center)) ) {
66 /* OMP */
67 for (e=0;e<faces->numElements;e++) {
68 /* get the coordinates of the nodes */
69 Finley_Util_Gather_double(NN,&(faces->Nodes[INDEX2(0,e,NN)]),numDim,nodes->Coordinates,&(X[INDEX3(0,0,e,numDim,NN)]));
70 /* get the element center */
71 center[e].refId=e;
72 for (i=0;i<MAX_numDim;i++) center[e].x[i]=0;
73 for (i0=0;i0<faces->ReferenceElement->Type->numNodesOnFace;i0++) {
74 for (i=0;i<numDim;i++) center[e].x[i]+=X[INDEX3(i,faces->ReferenceElement->Type->faceNode[i0],e,numDim,NN)];
75 }
76 for (i=0;i<numDim;i++) center[e].x[i]/=faces->ReferenceElement->Type->numNodesOnFace;
77 /* get the minimum distance between nodes in the element */
78 for (i0=0;i0<faces->ReferenceElement->Type->numNodesOnFace;i0++) {
79 for (i1=i0+1;i1<faces->ReferenceElement->Type->numNodesOnFace;i1++) {
80 getDist(h_local,e,faces->ReferenceElement->Type->faceNode[i0],e,faces->ReferenceElement->Type->faceNode[i1]);
81 h=MIN(h,h_local);
82 }
83 }
84 }
85 /* set the */
86 Finley_Mesh_lockingGridSize=h*MAX(safety_factor,0);
87 #ifdef Finley_TRACE
88 printf("locking grid size is %e\n",Finley_Mesh_lockingGridSize);
89 #endif
90 /* sort the elements by center center coordinates (lexigraphical)*/
91 qsort(center,faces->numElements,sizeof(Finley_Mesh_findMatchingFaces_center),Finley_Mesh_findMatchingFaces_compar);
92 /* find elements with matching center */
93 *numPairs=0;
94 /* OMP */
95 for (e=0;e<faces->numElements-1 && Finley_ErrorCode==NO_ERROR;e++) {
96 if (Finley_Mesh_findMatchingFaces_compar((void*) &(center[e]),(void*) &(center[e+1]))==0) {
97 e_0=center[e].refId;
98 e_1=center[e+1].refId;
99 elem0[*numPairs]=e_0;
100 elem1[*numPairs]=e_1;
101 /* now the element e_1 is rotated such that the first node in element e_0 and e_1 have the same coordinates */
102 perm=a1;
103 perm_tmp=a2;
104 for (i=0;i<NN;i++) perm[i]=i;
105 while (Finley_ErrorCode==NO_ERROR) {
106 /* if node 0 and perm[0] are the same we are ready */
107 getDist(dist,e_0,0,e_1,perm[0]);
108 if (dist<=h*tolerance) break;
109 if (faces->ReferenceElement->Type->shiftNodes[0]>=0) {
110 /* rotate the nodes */
111 for (i=0;i<NN;i++) perm_tmp[i]=perm[faces->ReferenceElement->Type->shiftNodes[i]];
112 SWAP(perm,perm_tmp);
113 }
114 /* if the permutation is back at the identity, ie. perm[0]=0, the faces don't match: */
115 if (perm[0]==0) {
116 Finley_ErrorCode=VALUE_ERROR;
117 sprintf(Finley_ErrorMsg,"couldn't match first node of element %d to touching element %d",e_0,e_1);
118 }
119 }
120 /* now we check if the second nodes match */
121 if (Finley_ErrorCode==NO_ERROR) {
122 if (faces->ReferenceElement->Type->numNodesOnFace>1) {
123 getDist(dist,e_0,1,e_1,perm[faces->ReferenceElement->Type->faceNode[1]]);
124 /* if the second node does not match we reverse the direction of the nodes */
125 if (dist>h*tolerance) {
126 /* rotate the nodes */
127 if (faces->ReferenceElement->Type->reverseNodes[0]<0) {
128 Finley_ErrorCode=VALUE_ERROR;
129 sprintf(Finley_ErrorMsg,"couldn't match the second node of element %d to touching element %d",e_0,e_1);
130 } else {
131 for (i=0;i<NN;i++) perm_tmp[i]=perm[faces->ReferenceElement->Type->reverseNodes[i]];
132 SWAP(perm,perm_tmp);
133 getDist(dist,e_0,1,e_1,perm[faces->ReferenceElement->Type->faceNode[1]]);
134 if (dist>h*tolerance) {
135 Finley_ErrorCode=VALUE_ERROR;
136 sprintf(Finley_ErrorMsg,"couldn't match the second node of element %d to touching element %d",e_0,e_1);
137 }
138 }
139 }
140 }
141 }
142 /* we check if the rest of the face nodes match: */
143 if (Finley_ErrorCode==NO_ERROR) {
144 for (i=2;i<faces->ReferenceElement->Type->numNodesOnFace;i++) {
145 n=faces->ReferenceElement->Type->faceNode[i];
146 getDist(dist,e_0,n,e_1,perm[n]);
147 if (dist>h*tolerance) {
148 Finley_ErrorCode=VALUE_ERROR;
149 sprintf(Finley_ErrorMsg,"couldn't match the %d-th node of element %d to touching element %d",i,e_0,e_1);
150 break;
151 }
152 }
153 }
154 /* copy over the permuted nodes of e_1 into matching_nodes_in_elem1 */
155 if (Finley_ErrorCode==NO_ERROR) {
156 for (i=0;i<NN;i++) matching_nodes_in_elem1[INDEX2(i,*numPairs,NN)]=faces->Nodes[INDEX2(perm[i],e_1,NN)];
157 }
158 (*numPairs)++;
159 }
160 }
161 #ifdef Finley_TRACE
162 printf("number of pairs of matching faces %d\n",*numPairs);
163 #endif
164 }
165 /* clean up */
166 TMPMEMFREE(X);
167 TMPMEMFREE(center);
168
169 #undef getDist
170 #undef SWAP
171 }
172
173 /*
174 * $Log$
175 * Revision 1.5 2005/07/08 04:07:51 jgs
176 * Merge of development branch back to main trunk on 2005-07-08
177 *
178 * Revision 1.4 2004/12/15 07:08:32 jgs
179 * *** empty log message ***
180 * Revision 1.1.1.1.2.2 2005/06/29 02:34:51 gross
181 * some changes towards 64 integers in finley
182 *
183 * Revision 1.1.1.1.2.1 2004/11/24 01:37:14 gross
184 * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now
185 *
186 *
187 *
188 */
189

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26