/[escript]/branches/doubleplusgood/finley/src/Mesh_read.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/finley/src/Mesh_read.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 616 - (show annotations)
Wed Mar 22 02:46:56 2006 UTC (13 years, 8 months ago) by elspeth
Original Path: trunk/finley/src/Mesh_read.c
File MIME type: text/plain
File size: 8577 byte(s)
Copyright added to more source files.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26