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

Contents of /trunk-mpi-branch/finley/src/Mesh_read.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1295 - (show annotations)
Mon Sep 10 06:07:09 2007 UTC (12 years, 8 months ago) by ksteube
File MIME type: text/plain
File size: 11158 byte(s)
Have now merged latest trunk features into MPI branch in preparation for
ending the MPI branch.
Compiles but has run time problems in bandwith reduction.

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, index_t reduced_order, bool_t optimize)
31
32 {
33
34 Paso_MPIInfo *mpi_info = Paso_MPIInfo_alloc( MPI_COMM_WORLD );
35 dim_t numNodes, numDim, numEle, i0, i1;
36 index_t tag_key;
37 Finley_Mesh *mesh_p=NULL;
38 char name[LenString_MAX],element_type[LenString_MAX],frm[20];
39 char error_msg[LenErrorMsg_MAX];
40 double time0=Finley_timer();
41 FILE *fileHandle_p = NULL;
42 ElementTypeId typeID, faceTypeID, contactTypeID, pointTypeID;
43
44 Finley_resetError();
45
46 if (mpi_info->size > 1) {
47 Finley_setError(SYSTEM_ERROR,"Finley_Mesh_read: MPI is not suporrted yet.");
48 } else {
49 /* get file handle */
50 fileHandle_p = fopen(fname, "r");
51 if (fileHandle_p==NULL) {
52 sprintf(error_msg,"Finley_Mesh_read: Opening file %s for reading failed.",fname);
53 Finley_setError(IO_ERROR,error_msg);
54 Paso_MPIInfo_free( mpi_info );
55 return NULL;
56 }
57
58 /* read header */
59 sprintf(frm,"%%%d[^\n]",LenString_MAX-1);
60 fscanf(fileHandle_p, frm, name);
61
62 /* get the nodes */
63
64 fscanf(fileHandle_p, "%1d%*s %d\n", &numDim,&numNodes);
65 /* allocate mesh */
66 mesh_p = Finley_Mesh_alloc(name,numDim,order,reduced_order,mpi_info);
67 if (Finley_noError()) {
68
69 /* read nodes */
70 Finley_NodeFile_allocTable(mesh_p->Nodes, numNodes);
71 if (Finley_noError()) {
72 if (1 == numDim) {
73 for (i0 = 0; i0 < numNodes; i0++)
74 fscanf(fileHandle_p, "%d %d %d %le\n", &mesh_p->Nodes->Id[i0],
75 &mesh_p->Nodes->globalDegreesOfFreedom[i0], &mesh_p->Nodes->Tag[i0],
76 &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)]);
77 } else if (2 == numDim) {
78 for (i0 = 0; i0 < numNodes; i0++)
79 fscanf(fileHandle_p, "%d %d %d %le %le\n", &mesh_p->Nodes->Id[i0],
80 &mesh_p->Nodes->globalDegreesOfFreedom[i0], &mesh_p->Nodes->Tag[i0],
81 &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],
82 &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)]);
83 } else if (3 == numDim) {
84 for (i0 = 0; i0 < numNodes; i0++)
85 fscanf(fileHandle_p, "%d %d %d %le %le %le\n", &mesh_p->Nodes->Id[i0],
86 &mesh_p->Nodes->globalDegreesOfFreedom[i0], &mesh_p->Nodes->Tag[i0],
87 &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],
88 &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)],
89 &mesh_p->Nodes->Coordinates[INDEX2(2,i0,numDim)]);
90 } /* if else else */
91 }
92 /* read elements */
93 if (Finley_noError()) {
94
95 fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
96 typeID=Finley_RefElement_getTypeId(element_type);
97 if (typeID==NoType) {
98 sprintf(error_msg,"Finley_Mesh_read :Unidentified element type %s",element_type);
99 Finley_setError(VALUE_ERROR,error_msg);
100 } else {
101 /* read the elements */
102 mesh_p->Elements=Finley_ElementFile_alloc(typeID,mesh_p->order, mesh_p->reduced_order, mpi_info);
103 if (Finley_noError()) {
104 Finley_ElementFile_allocTable(mesh_p->Elements, numEle);
105 mesh_p->Elements->minColor=0;
106 mesh_p->Elements->maxColor=numEle-1;
107 if (Finley_noError()) {
108 for (i0 = 0; i0 < numEle; i0++) {
109 fscanf(fileHandle_p, "%d %d", &mesh_p->Elements->Id[i0], &mesh_p->Elements->Tag[i0]);
110 mesh_p->Elements->Color[i0]=i0;
111 for (i1 = 0; i1 < mesh_p->Elements->ReferenceElement->Type->numNodes; i1++) {
112 fscanf(fileHandle_p, " %d",
113 &mesh_p->Elements->Nodes[INDEX2(i1, i0, mesh_p->Elements->ReferenceElement->Type->numNodes)]);
114 } /* for i1 */
115 fscanf(fileHandle_p, "\n");
116 } /* for i0 */
117 }
118 }
119 }
120 }
121 /* get the face elements */
122 if (Finley_noError()) {
123 fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
124 faceTypeID=Finley_RefElement_getTypeId(element_type);
125 if (faceTypeID==NoType) {
126 sprintf(error_msg,"Finley_Mesh_read :Unidentified element type %s for face elements",element_type);
127 Finley_setError(VALUE_ERROR,error_msg);
128 } else {
129 mesh_p->FaceElements=Finley_ElementFile_alloc(faceTypeID,mesh_p->order, mesh_p->reduced_order, mpi_info);
130 if (Finley_noError()) {
131 Finley_ElementFile_allocTable(mesh_p->FaceElements, numEle);
132 if (Finley_noError()) {
133 mesh_p->FaceElements->minColor=0;
134 mesh_p->FaceElements->maxColor=numEle-1;
135 for (i0 = 0; i0 < numEle; i0++) {
136 fscanf(fileHandle_p, "%d %d", &mesh_p->FaceElements->Id[i0], &mesh_p->FaceElements->Tag[i0]);
137 mesh_p->FaceElements->Color[i0]=i0;
138 for (i1 = 0; i1 < mesh_p->FaceElements->ReferenceElement->Type->numNodes; i1++) {
139 fscanf(fileHandle_p, " %d",
140 &mesh_p->FaceElements->Nodes[INDEX2(i1, i0, mesh_p->FaceElements->ReferenceElement->Type->numNodes)]);
141 } /* for i1 */
142 fscanf(fileHandle_p, "\n");
143 } /* for i0 */
144 }
145 }
146 }
147 }
148 /* get the Contact face element */
149 if (Finley_noError()) {
150 fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
151 contactTypeID=Finley_RefElement_getTypeId(element_type);
152 if (contactTypeID==NoType) {
153 sprintf(error_msg,"Finley_Mesh_read: Unidentified element type %s for contact elements",element_type);
154 Finley_setError(VALUE_ERROR,error_msg);
155 } else {
156 mesh_p->ContactElements=Finley_ElementFile_alloc(contactTypeID,mesh_p->order, mesh_p->reduced_order, mpi_info);
157 if (Finley_noError()) {
158 Finley_ElementFile_allocTable(mesh_p->ContactElements, numEle);
159 if (Finley_noError()) {
160 mesh_p->ContactElements->minColor=0;
161 mesh_p->ContactElements->maxColor=numEle-1;
162 for (i0 = 0; i0 < numEle; i0++) {
163 fscanf(fileHandle_p, "%d %d", &mesh_p->ContactElements->Id[i0], &mesh_p->ContactElements->Tag[i0]);
164 mesh_p->ContactElements->Color[i0]=i0;
165 for (i1 = 0; i1 < mesh_p->ContactElements->ReferenceElement->Type->numNodes; i1++) {
166 fscanf(fileHandle_p, " %d",
167 &mesh_p->ContactElements->Nodes[INDEX2(i1, i0, mesh_p->ContactElements->ReferenceElement->Type->numNodes)]);
168 } /* for i1 */
169 fscanf(fileHandle_p, "\n");
170 } /* for i0 */
171 }
172 }
173 }
174 }
175 /* get the nodal element */
176 if (Finley_noError()) {
177 fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
178 pointTypeID=Finley_RefElement_getTypeId(element_type);
179 if (pointTypeID==NoType) {
180 sprintf(error_msg,"Finley_Mesh_read: Unidentified element type %s for points",element_type);
181 Finley_setError(VALUE_ERROR,error_msg);
182 }
183 mesh_p->Points=Finley_ElementFile_alloc(pointTypeID,mesh_p->order, mesh_p->reduced_order, mpi_info);
184 if (Finley_noError()) {
185 Finley_ElementFile_allocTable(mesh_p->Points, numEle);
186 if (Finley_noError()) {
187 mesh_p->Points->minColor=0;
188 mesh_p->Points->maxColor=numEle-1;
189 for (i0 = 0; i0 < numEle; i0++) {
190 fscanf(fileHandle_p, "%d %d", &mesh_p->Points->Id[i0], &mesh_p->Points->Tag[i0]);
191 mesh_p->Points->Color[i0]=i0;
192 for (i1 = 0; i1 < mesh_p->Points->ReferenceElement->Type->numNodes; i1++) {
193 fscanf(fileHandle_p, " %d",
194 &mesh_p->Points->Nodes[INDEX2(i1, i0, mesh_p->Points->ReferenceElement->Type->numNodes)]);
195 } /* for i1 */
196 fscanf(fileHandle_p, "\n");
197 } /* for i0 */
198 }
199 }
200 }
201 /* get the name tags */
202 if (Finley_noError()) {
203 if (feof(fileHandle_p) == 0) {
204 fscanf(fileHandle_p, "%s\n", name);
205 while (feof(fileHandle_p) == 0) {
206 fscanf(fileHandle_p, "%s %d\n", name, &tag_key);
207 Finley_Mesh_addTagMap(mesh_p,name,tag_key);
208 }
209 }
210 }
211 }
212 /* close file */
213 fclose(fileHandle_p);
214
215 /* resolve id's : */
216 /* rearrange elements: */
217
218 if (Finley_noError()) Finley_Mesh_resolveNodeIds(mesh_p);
219 if (Finley_noError()) Finley_Mesh_prepare(mesh_p, optimize);
220
221 /* that's it */
222 #ifdef Finley_TRACE
223 printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);
224 #endif
225 }
226
227 /* close file */
228
229 fclose(fileHandle_p);
230
231 /* resolve id's : */
232
233 if (Finley_noError()) {
234 Finley_Mesh_resolveNodeIds(mesh_p);
235 }
236
237 /* rearrange elements: */
238
239 if (Finley_noError()) {
240 Finley_Mesh_prepare(mesh_p, optimize);
241 }
242
243 /* optimize node labeling*/
244
245 if (Finley_noError()) {
246 if (optimize) Finley_Mesh_optimizeNodeLabeling(mesh_p);
247 }
248
249 /* that's it */
250 #ifdef Finley_TRACE
251 printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);
252 #endif
253 if (! Finley_noError()) {
254 Finley_Mesh_free(mesh_p);
255 }
256 Paso_MPIInfo_free( mpi_info );
257 return mesh_p;
258 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26