/[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 730 - (show annotations)
Mon May 15 04:03:49 2006 UTC (13 years, 4 months ago) by bcumming
File MIME type: text/plain
File size: 8919 byte(s)


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26