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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 616 - (hide annotations)
Wed Mar 22 02:46:56 2006 UTC (13 years, 3 months ago) by elspeth
File MIME type: text/plain
File size: 9962 byte(s)
Copyright added to more source files.

1 jgs 150 /*
2 elspeth 616 ************************************************************
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 jgs 150 */
12    
13 jgs 82 /**************************************************************/
14    
15     /* Finley: generates rectangular meshes */
16    
17     /* Generates a numElements[0] x numElements[1] mesh with second order elements (Rec8) in the rectangle */
18     /* [0,Length[0]] x [0,Length[1]]. order is the desired accuracy of the integration scheme. */
19    
20     /**************************************************************/
21    
22     /* Author: gross@access.edu.au */
23     /* Version: $Id$ */
24    
25     /**************************************************************/
26    
27     #include "RectangularMesh.h"
28    
29     /**************************************************************/
30    
31     Finley_Mesh* Finley_RectangularMesh_Rec8(int* numElements,double* Length,int* periodic,int order,int useElementsOnFace) {
32 jgs 153 dim_t N0,N1,NE0,NE1,i0,i1,totalNECount,faceNECount,NDOF0,NDOF1,NFaceElements,NUMNODES,M0,M1;
33 jgs 123 index_t k,node0;
34 jgs 82 Finley_Mesh* out;
35     char name[50];
36     double time0=Finley_timer();
37     NE0=MAX(1,numElements[0]);
38     NE1=MAX(1,numElements[1]);
39     N0=2*NE0+1;
40     N1=2*NE1+1;
41    
42 jgs 153 if (N0<=N1) {
43     M0=1;
44     M1=N0;
45     } else {
46     M0=N1;
47     M1=1;
48     }
49    
50 jgs 82 NFaceElements=0;
51     if (!periodic[0]) {
52     NDOF0=N0;
53     NFaceElements+=2*NE1;
54     } else {
55     NDOF0=N0-1;
56     }
57     if (!periodic[1]) {
58     NDOF1=N1;
59     NFaceElements+=2*NE0;
60     } else {
61     NDOF1=N1-1;
62     }
63    
64     /* allocate mesh: */
65    
66     sprintf(name,"Rectangular %d x %d mesh",N0,N1);
67     out=Finley_Mesh_alloc(name,2,order);
68 jgs 150 if (! Finley_noError()) return NULL;
69 jgs 82
70     out->Elements=Finley_ElementFile_alloc(Rec8,out->order);
71     if (useElementsOnFace) {
72     out->FaceElements=Finley_ElementFile_alloc(Rec8Face,out->order);
73     out->ContactElements=Finley_ElementFile_alloc(Rec8Face_Contact,out->order);
74     } else {
75     out->FaceElements=Finley_ElementFile_alloc(Line3,out->order);
76     out->ContactElements=Finley_ElementFile_alloc(Line3_Contact,out->order);
77     }
78     out->Points=Finley_ElementFile_alloc(Point1,out->order);
79 jgs 150 if (! Finley_noError()) {
80 jgs 82 Finley_Mesh_dealloc(out);
81     return NULL;
82     }
83    
84     /* allocate tables: */
85    
86     Finley_NodeFile_allocTable(out->Nodes,N0*N1);
87     Finley_ElementFile_allocTable(out->Elements,NE0*NE1);
88     Finley_ElementFile_allocTable(out->FaceElements,NFaceElements);
89 jgs 150 if (! Finley_noError()) {
90 jgs 82 Finley_Mesh_dealloc(out);
91     return NULL;
92     }
93     /* set nodes: */
94 jgs 153
95     #pragma omp parallel for private(i0,i1,k)
96 jgs 82 for (i1=0;i1<N1;i1++) {
97     for (i0=0;i0<N0;i0++) {
98 jgs 153 k=M0*i0+M1*i1;
99 jgs 82 out->Nodes->Coordinates[INDEX2(0,k,2)]=DBLE(i0)/DBLE(N0-1)*Length[0];
100     out->Nodes->Coordinates[INDEX2(1,k,2)]=DBLE(i1)/DBLE(N1-1)*Length[1];
101 jgs 153 out->Nodes->Id[k]=i0+N0*i1;
102 jgs 82 out->Nodes->Tag[k]=0;
103 jgs 153 out->Nodes->degreeOfFreedom[k]=M0*(i0%NDOF0) +M1*(i1%NDOF1);
104 jgs 82 }
105     }
106     /* tags for the faces: */
107     if (!periodic[1]) {
108     for (i0=0;i0<N0;i0++) {
109 jgs 153 out->Nodes->Tag[M0*i0+M1*0]+=10;
110     out->Nodes->Tag[M0*i0+M1*(N1-1)]+=20;
111 jgs 82 }
112     }
113     if (!periodic[0]) {
114     for (i1=0;i1<N1;i1++) {
115 jgs 153 out->Nodes->Tag[M0*0+M1*i1]+=1;
116     out->Nodes->Tag[M0*(N0-1)+M1*i1]+=2;
117 jgs 82 }
118     }
119 jgs 153
120 jgs 82 /* set the elements: */
121    
122     #pragma omp parallel for private(i0,i1,k,node0)
123     for (i1=0;i1<NE1;i1++) {
124     for (i0=0;i0<NE0;i0++) {
125     k=i0+NE0*i1;
126     node0=2*i0+2*i1*N0;
127    
128     out->Elements->Id[k]=k;
129     out->Elements->Tag[k]=0;
130     out->Elements->Color[k]=COLOR_MOD(i0)+3*COLOR_MOD(i1);
131    
132     out->Elements->Nodes[INDEX2(0,k,8)]=node0;
133     out->Elements->Nodes[INDEX2(1,k,8)]=node0+2;
134     out->Elements->Nodes[INDEX2(2,k,8)]=node0+2*N0+2;
135     out->Elements->Nodes[INDEX2(3,k,8)]=node0+2*N0;
136     out->Elements->Nodes[INDEX2(4,k,8)]=node0+1;
137     out->Elements->Nodes[INDEX2(5,k,8)]=node0+N0+2;
138     out->Elements->Nodes[INDEX2(6,k,8)]=node0+2*N0+1;
139     out->Elements->Nodes[INDEX2(7,k,8)]=node0+N0;
140    
141     }
142     }
143 jgs 123 out->Elements->minColor=0;
144     out->Elements->maxColor=COLOR_MOD(0)+3*COLOR_MOD(0);
145 jgs 82
146     /* face elements: */
147     if (useElementsOnFace) {
148     NUMNODES=8;
149     } else {
150     NUMNODES=3;
151     }
152    
153    
154     totalNECount=NE0*NE1;
155     faceNECount=0;
156    
157     if (!periodic[1]) {
158     /* ** elements on boundary 010 (x2=0): */
159    
160     #pragma omp parallel for private(i0,k,node0)
161     for (i0=0;i0<NE0;i0++) {
162     k=i0+faceNECount;
163     node0=2*i0;
164    
165     out->FaceElements->Id[k]=i0+totalNECount;
166     out->FaceElements->Tag[k]=10;
167     out->FaceElements->Color[k]=i0%2;
168    
169     if (useElementsOnFace) {
170     out->FaceElements->Nodes[INDEX2(0,k,NUMNODES)]=node0;
171     out->FaceElements->Nodes[INDEX2(1,k,NUMNODES)]=node0+2;
172     out->FaceElements->Nodes[INDEX2(2,k,NUMNODES)]=node0+2*N0+2;
173     out->FaceElements->Nodes[INDEX2(3,k,NUMNODES)]=node0+2*N0;
174     out->FaceElements->Nodes[INDEX2(4,k,NUMNODES)]=node0+1;
175     out->FaceElements->Nodes[INDEX2(5,k,NUMNODES)]=node0+N0+2;
176     out->FaceElements->Nodes[INDEX2(6,k,NUMNODES)]=node0+2*N0+1;
177     out->FaceElements->Nodes[INDEX2(7,k,NUMNODES)]=node0+N0;
178     } else {
179     out->FaceElements->Nodes[INDEX2(0,k,NUMNODES)]=node0;
180     out->FaceElements->Nodes[INDEX2(1,k,NUMNODES)]=node0+2;
181     out->FaceElements->Nodes[INDEX2(2,k,NUMNODES)]=node0+1;
182     }
183     }
184     totalNECount+=NE0;
185     faceNECount+=NE0;
186    
187     /* ** elements on boundary 020 (x2=1): */
188    
189     #pragma omp parallel for private(i0,k,node0)
190     for (i0=0;i0<NE0;i0++) {
191     k=i0+faceNECount;
192     node0=2*i0+2*(NE1-1)*N0;
193    
194     out->FaceElements->Id[k]=i0+totalNECount;
195     out->FaceElements->Tag[k]=20;
196     out->FaceElements->Color[k]=i0%2+2;
197     if (useElementsOnFace) {
198     out->FaceElements->Nodes[INDEX2(0,k,NUMNODES)]=node0+2*N0+2;
199     out->FaceElements->Nodes[INDEX2(1,k,NUMNODES)]=node0+2*N0;
200     out->FaceElements->Nodes[INDEX2(2,k,NUMNODES)]=node0;
201     out->FaceElements->Nodes[INDEX2(3,k,NUMNODES)]=node0+2;
202     out->FaceElements->Nodes[INDEX2(4,k,NUMNODES)]=node0+2*N0+1;
203     out->FaceElements->Nodes[INDEX2(5,k,NUMNODES)]=node0+N0;
204     out->FaceElements->Nodes[INDEX2(6,k,NUMNODES)]=node0+1;
205     out->FaceElements->Nodes[INDEX2(7,k,NUMNODES)]=node0+N0+2;
206     } else {
207     out->FaceElements->Nodes[INDEX2(0,k,NUMNODES)]=node0+2*N0+2;
208     out->FaceElements->Nodes[INDEX2(1,k,NUMNODES)]=node0+2*N0;
209     out->FaceElements->Nodes[INDEX2(2,k,NUMNODES)]=node0+2*N0+1;
210     }
211     }
212     totalNECount+=NE0;
213     faceNECount+=NE0;
214     }
215     if (!periodic[0]) {
216     /* ** elements on boundary 001 (x1=0): */
217    
218     #pragma omp parallel for private(i1,k,node0)
219     for (i1=0;i1<NE1;i1++) {
220     k=i1+faceNECount;
221     node0=2*i1*N0;
222    
223     out->FaceElements->Id[k]=i1+totalNECount;
224     out->FaceElements->Tag[k]=1;
225     out->FaceElements->Color[k]=(i1%2)+4;
226    
227     if (useElementsOnFace) {
228     out->FaceElements->Nodes[INDEX2(0,k,NUMNODES)]=node0+2*N0;
229     out->FaceElements->Nodes[INDEX2(1,k,NUMNODES)]=node0;
230     out->FaceElements->Nodes[INDEX2(2,k,NUMNODES)]=node0+2;
231     out->FaceElements->Nodes[INDEX2(3,k,NUMNODES)]=node0+2*N0+2;
232     out->FaceElements->Nodes[INDEX2(4,k,NUMNODES)]=node0+N0;
233     out->FaceElements->Nodes[INDEX2(5,k,NUMNODES)]=node0+1;
234     out->FaceElements->Nodes[INDEX2(6,k,NUMNODES)]=node0+N0+2;
235     out->FaceElements->Nodes[INDEX2(7,k,NUMNODES)]=node0+2*N0+1;
236     } else {
237     out->FaceElements->Nodes[INDEX2(0,k,NUMNODES)]=node0+2*N0;
238     out->FaceElements->Nodes[INDEX2(1,k,NUMNODES)]=node0;
239     out->FaceElements->Nodes[INDEX2(2,k,NUMNODES)]=node0+N0;
240     }
241    
242     }
243     totalNECount+=NE1;
244     faceNECount+=NE1;
245    
246     /* ** elements on boundary 002 (x1=1): */
247    
248     #pragma omp parallel for private(i1,k,node0)
249     for (i1=0;i1<NE1;i1++) {
250     k=i1+faceNECount;
251     node0=2*(NE0-1)+2*i1*N0;
252    
253     out->FaceElements->Id[k]=i1+totalNECount;
254     out->FaceElements->Tag[k]=2;
255     out->FaceElements->Color[k]=(i1%2)+6;
256    
257     if (useElementsOnFace) {
258     out->FaceElements->Nodes[INDEX2(0,k,NUMNODES)]=node0+2;
259     out->FaceElements->Nodes[INDEX2(1,k,NUMNODES)]=node0+2*N0+2;
260     out->FaceElements->Nodes[INDEX2(2,k,NUMNODES)]=node0+2*N0;
261     out->FaceElements->Nodes[INDEX2(3,k,NUMNODES)]=node0;
262     out->FaceElements->Nodes[INDEX2(4,k,NUMNODES)]=node0+N0+2;
263     out->FaceElements->Nodes[INDEX2(5,k,NUMNODES)]=node0+2*N0+1;
264     out->FaceElements->Nodes[INDEX2(6,k,NUMNODES)]=node0+N0;
265     out->FaceElements->Nodes[INDEX2(7,k,NUMNODES)]=node0+1;
266     } else {
267     out->FaceElements->Nodes[INDEX2(0,k,NUMNODES)]=node0+2;
268     out->FaceElements->Nodes[INDEX2(1,k,NUMNODES)]=node0+2*N0+2;
269     out->FaceElements->Nodes[INDEX2(2,k,NUMNODES)]=node0+N0+2;
270     }
271     }
272     totalNECount+=NE1;
273     faceNECount+=NE1;
274    
275     }
276 jgs 123 out->FaceElements->minColor=0;
277     out->FaceElements->maxColor=7;
278 jgs 82
279     /* face elements done: */
280    
281     /* condense the nodes: */
282    
283     Finley_Mesh_resolveNodeIds(out);
284    
285     /* prepare mesh for further calculatuions:*/
286    
287     Finley_Mesh_prepare(out) ;
288    
289 jgs 149 #ifdef Finley_TRACE
290 jgs 82 printf("timing: mesh generation: %.4e sec\n",Finley_timer()-time0);
291 jgs 149 #endif
292 jgs 82
293 jgs 150 if (! Finley_noError()) {
294 jgs 82 Finley_Mesh_dealloc(out);
295     return NULL;
296     }
297     return out;
298     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26