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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 934 - (show annotations)
Tue Jan 23 09:52:45 2007 UTC (12 years, 9 months ago) by gross
File MIME type: text/plain
File size: 8806 byte(s)
gmsh file reader for finley
1 /*
2 ************************************************************
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 */
12
13 /**************************************************************/
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 Finley_Mesh* Finley_Mesh_read(char* fname,index_t order) {
31
32 dim_t numNodes, numDim, numEle, i0, i1;
33 Finley_Mesh *mesh_p=NULL;
34 char name[LenString_MAX],element_type[LenString_MAX],frm[20];
35 char error_msg[LenErrorMsg_MAX];
36 double time0=Finley_timer();
37
38 Finley_resetError();
39
40 /* get file handle */
41 FILE * fileHandle_p = fopen(fname, "r");
42 if (fileHandle_p==NULL) {
43 sprintf(error_msg,"%s: Opening file %s for reading failed.",__FILE__,fname);
44 Finley_setError(IO_ERROR,error_msg);
45 return NULL;
46 }
47
48 /* read header */
49 sprintf(frm,"%%%d[^\n]",LenString_MAX-1);
50 fscanf(fileHandle_p, frm, name);
51
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 /* get the nodes */
60
61 fscanf(fileHandle_p, "%1d%*s %d\n", &numDim,&numNodes);
62 #ifndef PASO_MPI
63 Finley_NodeFile_allocTable(mesh_p->Nodes, numNodes);
64 if (! Finley_noError()) return NULL;
65 #else
66 /* TODO */
67 #endif
68
69 if (1 == numDim) {
70 for (i0 = 0; i0 < numNodes; i0++)
71 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 } else if (2 == numDim) {
75 for (i0 = 0; i0 < numNodes; i0++)
76 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 } else if (3 == numDim) {
81 for (i0 = 0; i0 < numNodes; i0++)
82 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 } /* 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 sprintf(error_msg,"%s :Unidentified element type %s",__FILE__,element_type);
95 Finley_setError(VALUE_ERROR,error_msg);
96 return NULL;
97 }
98 /* read the elements */
99 #ifndef PASO_MPI
100 mesh_p->Elements=Finley_ElementFile_alloc(typeID,mesh_p->order);
101 #else
102 /* TODO */
103 #endif
104 Finley_ElementFile_allocTable(mesh_p->Elements, numEle);
105 mesh_p->Elements->minColor=0;
106 mesh_p->Elements->maxColor=numEle-1;
107 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 fscanf(fileHandle_p, " %d",
112 &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 sprintf(error_msg,"%s :Unidentified element type %s for face elements",__FILE__,element_type);
122 Finley_setError(VALUE_ERROR,error_msg);
123 return NULL;
124 }
125 #ifndef PASO_MPI
126 mesh_p->FaceElements=Finley_ElementFile_alloc(faceTypeID,mesh_p->order);
127 #else
128 /* TODO */
129 #endif
130 Finley_ElementFile_allocTable(mesh_p->FaceElements, numEle);
131 mesh_p->FaceElements->minColor=0;
132 mesh_p->FaceElements->maxColor=numEle-1;
133 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 fscanf(fileHandle_p, " %d",
138 &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 sprintf(error_msg,"%s: Unidentified element type %s for contact elements",__FILE__,element_type);
148 Finley_setError(VALUE_ERROR,error_msg);
149 return NULL;
150 }
151 #ifndef PASO_MPI
152 mesh_p->ContactElements=Finley_ElementFile_alloc(contactTypeID,mesh_p->order);
153 #else
154 /* TODO */
155 #endif
156 Finley_ElementFile_allocTable(mesh_p->ContactElements, numEle);
157 mesh_p->ContactElements->minColor=0;
158 mesh_p->ContactElements->maxColor=numEle-1;
159 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 fscanf(fileHandle_p, " %d",
164 &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 sprintf(error_msg,"%s: Unidentified element type %s for points",__FILE__,element_type);
174 Finley_setError(VALUE_ERROR,error_msg);
175 return NULL;
176 }
177 #ifndef PASO_MPI
178 mesh_p->Points=Finley_ElementFile_alloc(pointTypeID,mesh_p->order);
179 #else
180 /* TODO */
181 #endif
182 Finley_ElementFile_allocTable(mesh_p->Points, numEle);
183 mesh_p->Points->minColor=0;
184 mesh_p->Points->maxColor=numEle-1;
185 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 fscanf(fileHandle_p, " %d",
190 &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
202 Finley_Mesh_resolveNodeIds(mesh_p);
203
204 /* rearrange elements: */
205
206 Finley_Mesh_prepare(mesh_p);
207
208 /* that's it */
209 #ifdef Finley_TRACE
210 printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);
211 #endif
212 if (! Finley_noError()) Finley_Mesh_dealloc(mesh_p);
213 return mesh_p;
214 }
215 /*
216 * $Log$
217 * 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 * 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 * 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 * 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 * 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 * Revision 1.2 2005/07/08 04:07:54 jgs
236 * Merge of development branch back to main trunk on 2005-07-08
237 *
238 * Revision 1.1.1.1.2.2 2005/07/18 10:34:54 gross
239 * some informance improvements when reading meshes
240 *
241 * 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 * 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