/[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 1223 - (show annotations)
Fri Aug 3 02:40:39 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/plain
File size: 10838 byte(s)
first attemt towards an improved MPI version.  

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26