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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 934 - (hide annotations)
Tue Jan 23 09:52:45 2007 UTC (12 years, 10 months ago) by gross
File MIME type: text/plain
File size: 8806 byte(s)
gmsh file reader for finley
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: read mesh */
16    
17     /**************************************************************/
18    
19     /* Author: gross@access.edu.au */
20     /* Version: $Id$ */
21    
22     /**************************************************************/
23    
24     #include "Mesh.h"
25    
26     /**************************************************************/
27    
28     /* reads a mesh from a Finley file of name fname */
29    
30 jgs 123 Finley_Mesh* Finley_Mesh_read(char* fname,index_t order) {
31 jgs 82
32 jgs 123 dim_t numNodes, numDim, numEle, i0, i1;
33 bcumming 730 Finley_Mesh *mesh_p=NULL;
34 jgs 150 char name[LenString_MAX],element_type[LenString_MAX],frm[20];
35     char error_msg[LenErrorMsg_MAX];
36 jgs 82 double time0=Finley_timer();
37 bcumming 730
38 jgs 150 Finley_resetError();
39 jgs 82
40     /* get file handle */
41     FILE * fileHandle_p = fopen(fname, "r");
42     if (fileHandle_p==NULL) {
43 jgs 150 sprintf(error_msg,"%s: Opening file %s for reading failed.",__FILE__,fname);
44     Finley_setError(IO_ERROR,error_msg);
45 jgs 82 return NULL;
46     }
47    
48     /* read header */
49 jgs 150 sprintf(frm,"%%%d[^\n]",LenString_MAX-1);
50     fscanf(fileHandle_p, frm, name);
51 gross 934
52     /* allocate mesh */
53     #ifndef PASO_MPI
54     mesh_p = Finley_Mesh_alloc(name,numDim,order);
55     #else
56     /* TODO */
57     #endif
58     if (! Finley_noError()) return NULL;
59 jgs 82 /* get the nodes */
60    
61     fscanf(fileHandle_p, "%1d%*s %d\n", &numDim,&numNodes);
62 bcumming 730 #ifndef PASO_MPI
63 gross 934 Finley_NodeFile_allocTable(mesh_p->Nodes, numNodes);
64 jgs 150 if (! Finley_noError()) return NULL;
65 bcumming 730 #else
66     /* TODO */
67     #endif
68 jgs 82
69     if (1 == numDim) {
70     for (i0 = 0; i0 < numNodes; i0++)
71 gross 934 fscanf(fileHandle_p, "%d %d %d %le\n", &mesh_p->Nodes->Id[i0],
72     &mesh_p->Nodes->degreeOfFreedom[i0], &mesh_p->Nodes->Tag[i0],
73     &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)]);
74 jgs 82 } else if (2 == numDim) {
75     for (i0 = 0; i0 < numNodes; i0++)
76 gross 934 fscanf(fileHandle_p, "%d %d %d %le %le\n", &mesh_p->Nodes->Id[i0],
77     &mesh_p->Nodes->degreeOfFreedom[i0], &mesh_p->Nodes->Tag[i0],
78     &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],
79     &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)]);
80 jgs 82 } else if (3 == numDim) {
81     for (i0 = 0; i0 < numNodes; i0++)
82 gross 934 fscanf(fileHandle_p, "%d %d %d %le %le %le\n", &mesh_p->Nodes->Id[i0],
83     &mesh_p->Nodes->degreeOfFreedom[i0], &mesh_p->Nodes->Tag[i0],
84     &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],
85     &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)],
86     &mesh_p->Nodes->Coordinates[INDEX2(2,i0,numDim)]);
87 jgs 82 } /* if else else */
88    
89     /* get the element type */
90    
91     fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
92     ElementTypeId typeID=Finley_RefElement_getTypeId(element_type);
93     if (typeID==NoType) {
94 jgs 150 sprintf(error_msg,"%s :Unidentified element type %s",__FILE__,element_type);
95     Finley_setError(VALUE_ERROR,error_msg);
96 jgs 82 return NULL;
97     }
98     /* read the elements */
99 bcumming 730 #ifndef PASO_MPI
100 jgs 82 mesh_p->Elements=Finley_ElementFile_alloc(typeID,mesh_p->order);
101 bcumming 730 #else
102     /* TODO */
103     #endif
104 jgs 82 Finley_ElementFile_allocTable(mesh_p->Elements, numEle);
105 jgs 123 mesh_p->Elements->minColor=0;
106     mesh_p->Elements->maxColor=numEle-1;
107 jgs 82 for (i0 = 0; i0 < numEle; i0++) {
108     fscanf(fileHandle_p, "%d %d", &mesh_p->Elements->Id[i0], &mesh_p->Elements->Tag[i0]);
109     mesh_p->Elements->Color[i0]=i0;
110     for (i1 = 0; i1 < mesh_p->Elements->ReferenceElement->Type->numNodes; i1++) {
111 jgs 126 fscanf(fileHandle_p, " %d",
112 jgs 82 &mesh_p->Elements->Nodes[INDEX2(i1, i0, mesh_p->Elements->ReferenceElement->Type->numNodes)]);
113     } /* for i1 */
114     fscanf(fileHandle_p, "\n");
115     } /* for i0 */
116    
117     /* get the face elements */
118     fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
119     ElementTypeId faceTypeID=Finley_RefElement_getTypeId(element_type);
120     if (faceTypeID==NoType) {
121 jgs 150 sprintf(error_msg,"%s :Unidentified element type %s for face elements",__FILE__,element_type);
122     Finley_setError(VALUE_ERROR,error_msg);
123 jgs 82 return NULL;
124     }
125 bcumming 730 #ifndef PASO_MPI
126 jgs 82 mesh_p->FaceElements=Finley_ElementFile_alloc(faceTypeID,mesh_p->order);
127 bcumming 730 #else
128     /* TODO */
129     #endif
130 jgs 82 Finley_ElementFile_allocTable(mesh_p->FaceElements, numEle);
131 jgs 123 mesh_p->FaceElements->minColor=0;
132     mesh_p->FaceElements->maxColor=numEle-1;
133 jgs 82 for (i0 = 0; i0 < numEle; i0++) {
134     fscanf(fileHandle_p, "%d %d", &mesh_p->FaceElements->Id[i0], &mesh_p->FaceElements->Tag[i0]);
135     mesh_p->FaceElements->Color[i0]=i0;
136     for (i1 = 0; i1 < mesh_p->FaceElements->ReferenceElement->Type->numNodes; i1++) {
137 jgs 126 fscanf(fileHandle_p, " %d",
138 jgs 82 &mesh_p->FaceElements->Nodes[INDEX2(i1, i0, mesh_p->FaceElements->ReferenceElement->Type->numNodes)]);
139     } /* for i1 */
140     fscanf(fileHandle_p, "\n");
141     } /* for i0 */
142    
143     /* get the Contact face element */
144     fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
145     ElementTypeId contactTypeID=Finley_RefElement_getTypeId(element_type);
146     if (contactTypeID==NoType) {
147 jgs 150 sprintf(error_msg,"%s: Unidentified element type %s for contact elements",__FILE__,element_type);
148     Finley_setError(VALUE_ERROR,error_msg);
149 jgs 82 return NULL;
150     }
151 bcumming 730 #ifndef PASO_MPI
152 jgs 82 mesh_p->ContactElements=Finley_ElementFile_alloc(contactTypeID,mesh_p->order);
153 bcumming 730 #else
154     /* TODO */
155     #endif
156 jgs 82 Finley_ElementFile_allocTable(mesh_p->ContactElements, numEle);
157 jgs 123 mesh_p->ContactElements->minColor=0;
158     mesh_p->ContactElements->maxColor=numEle-1;
159 jgs 82 for (i0 = 0; i0 < numEle; i0++) {
160     fscanf(fileHandle_p, "%d %d", &mesh_p->ContactElements->Id[i0], &mesh_p->ContactElements->Tag[i0]);
161     mesh_p->ContactElements->Color[i0]=i0;
162     for (i1 = 0; i1 < mesh_p->ContactElements->ReferenceElement->Type->numNodes; i1++) {
163 jgs 126 fscanf(fileHandle_p, " %d",
164 jgs 82 &mesh_p->ContactElements->Nodes[INDEX2(i1, i0, mesh_p->ContactElements->ReferenceElement->Type->numNodes)]);
165     } /* for i1 */
166     fscanf(fileHandle_p, "\n");
167     } /* for i0 */
168    
169     /* get the nodal element */
170     fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
171     ElementTypeId pointTypeID=Finley_RefElement_getTypeId(element_type);
172     if (pointTypeID==NoType) {
173 jgs 150 sprintf(error_msg,"%s: Unidentified element type %s for points",__FILE__,element_type);
174     Finley_setError(VALUE_ERROR,error_msg);
175 jgs 82 return NULL;
176     }
177 bcumming 730 #ifndef PASO_MPI
178 jgs 82 mesh_p->Points=Finley_ElementFile_alloc(pointTypeID,mesh_p->order);
179 bcumming 730 #else
180     /* TODO */
181     #endif
182 jgs 82 Finley_ElementFile_allocTable(mesh_p->Points, numEle);
183 jgs 123 mesh_p->Points->minColor=0;
184     mesh_p->Points->maxColor=numEle-1;
185 jgs 82 for (i0 = 0; i0 < numEle; i0++) {
186     fscanf(fileHandle_p, "%d %d", &mesh_p->Points->Id[i0], &mesh_p->Points->Tag[i0]);
187     mesh_p->Points->Color[i0]=i0;
188     for (i1 = 0; i1 < mesh_p->Points->ReferenceElement->Type->numNodes; i1++) {
189 jgs 126 fscanf(fileHandle_p, " %d",
190 jgs 82 &mesh_p->Points->Nodes[INDEX2(i1, i0, mesh_p->Points->ReferenceElement->Type->numNodes)]);
191     } /* for i1 */
192     fscanf(fileHandle_p, "\n");
193     } /* for i0 */
194    
195    
196     /* close file */
197    
198     fclose(fileHandle_p);
199    
200     /* resolve id's : */
201 jgs 126
202 jgs 82 Finley_Mesh_resolveNodeIds(mesh_p);
203 jgs 126
204 jgs 82 /* rearrange elements: */
205 jgs 126
206 jgs 82 Finley_Mesh_prepare(mesh_p);
207 jgs 126
208 jgs 82 /* that's it */
209 jgs 149 #ifdef Finley_TRACE
210 jgs 82 printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);
211 jgs 149 #endif
212 jgs 150 if (! Finley_noError()) Finley_Mesh_dealloc(mesh_p);
213 jgs 82 return mesh_p;
214     }
215     /*
216     * $Log$
217 jgs 150 * Revision 1.5 2005/09/15 03:44:22 jgs
218     * Merge of development branch dev-02 back to main trunk on 2005-09-15
219     *
220 jgs 149 * Revision 1.4 2005/09/01 03:31:36 jgs
221     * Merge of development branch dev-02 back to main trunk on 2005-09-01
222     *
223 jgs 150 * Revision 1.3.2.3 2005/09/08 08:28:39 gross
224     * some cleanup in savevtk
225     *
226     * Revision 1.3.2.2 2005/09/07 06:26:19 gross
227     * the solver from finley are put into the standalone package paso now
228     *
229 jgs 149 * Revision 1.3.2.1 2005/08/24 02:02:18 gross
230     * timing output switched off. solver output can be swiched through getSolution(verbose=True) now.
231     *
232 jgs 126 * Revision 1.3 2005/07/22 03:53:08 jgs
233     * Merge of development branch back to main trunk on 2005-07-22
234     *
235 jgs 123 * Revision 1.2 2005/07/08 04:07:54 jgs
236     * Merge of development branch back to main trunk on 2005-07-08
237 jgs 82 *
238 jgs 126 * Revision 1.1.1.1.2.2 2005/07/18 10:34:54 gross
239     * some informance improvements when reading meshes
240     *
241 jgs 123 * Revision 1.1.1.1.2.1 2005/06/29 02:34:53 gross
242     * some changes towards 64 integers in finley
243     *
244     * Revision 1.1.1.1 2004/10/26 06:53:57 jgs
245     * initial import of project esys2
246     *
247 jgs 82 * Revision 1.1.1.1 2004/06/24 04:00:40 johng
248     * Initial version of eys using boost-python.
249     *
250     *
251     */
252    

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26