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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 82 - (hide annotations)
Tue Oct 26 06:53:54 2004 UTC (14 years, 11 months ago) by jgs
Original Path: trunk/esys2/finley/src/finleyC/Mesh_rec4.c
File MIME type: text/plain
File size: 7844 byte(s)
Initial revision

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26