/[escript]/branches/arrayview_from_1695_trunk/finley/src/Mesh_read.c
ViewVC logotype

Contents of /branches/arrayview_from_1695_trunk/finley/src/Mesh_read.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 201 - (show annotations)
Wed Nov 23 04:10:21 2005 UTC (13 years, 6 months ago) by jgs
Original Path: trunk/finley/src/finley/Mesh_read.c
File MIME type: text/plain
File size: 8899 byte(s)
copy finleyC and CPPAdapter to finley and finley/CPPAdapter to
facilitate scons builds

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26