/[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 82 - (show annotations)
Tue Oct 26 06:53:54 2004 UTC (14 years, 6 months ago) by jgs
Original Path: trunk/esys2/finley/src/finleyC/Mesh_read.c
File MIME type: text/plain
File size: 7162 byte(s)
Initial revision

1 /**************************************************************/
2
3 /* Finley: read mesh */
4
5 /**************************************************************/
6
7 /* Copyrights by ACcESS Australia 2003/04 */
8 /* Author: gross@access.edu.au */
9 /* Version: $Id$ */
10
11 /**************************************************************/
12
13 #include "Finley.h"
14 #include "Mesh.h"
15
16 /**************************************************************/
17
18 /* reads a mesh from a Finley file of name fname */
19
20 Finley_Mesh* Finley_Mesh_read(char* fname,int order) {
21
22 int numNodes, numDim, numEle;
23 int i0, i1;
24 char name[LenString_MAX],element_type[LenString_MAX];
25 Finley_NodeFile *nodes_p=NULL;
26 double time0=Finley_timer();
27
28 /* get file handle */
29 FILE * fileHandle_p = fopen(fname, "r");
30 if (fileHandle_p==NULL) {
31 Finley_ErrorCode=IO_ERROR;
32 sprintf(Finley_ErrorMsg,"Opening file %s for reading failed.",fname);
33 return NULL;
34 }
35
36 /* read header */
37 fscanf(fileHandle_p, "%63[^\n]", name);
38
39 /* get the nodes */
40
41 fscanf(fileHandle_p, "%1d%*s %d\n", &numDim,&numNodes);
42 nodes_p=Finley_NodeFile_alloc(numDim);
43 if (Finley_ErrorCode!=NO_ERROR) return NULL;
44 Finley_NodeFile_allocTable(nodes_p, numNodes);
45 if (Finley_ErrorCode!=NO_ERROR) return NULL;
46
47 if (1 == numDim) {
48 for (i0 = 0; i0 < numNodes; i0++)
49 fscanf(fileHandle_p, "%d %d %d %le\n", &nodes_p->Id[i0],
50 &nodes_p->degreeOfFreedom[i0], &nodes_p->Tag[i0],
51 &nodes_p->Coordinates[INDEX2(0,i0,numDim)]);
52 } else if (2 == numDim) {
53 for (i0 = 0; i0 < numNodes; i0++)
54 fscanf(fileHandle_p, "%d %d %d %le %le\n", &nodes_p->Id[i0],
55 &nodes_p->degreeOfFreedom[i0], &nodes_p->Tag[i0],
56 &nodes_p->Coordinates[INDEX2(0,i0,numDim)],
57 &nodes_p->Coordinates[INDEX2(1,i0,numDim)]);
58 } else if (3 == numDim) {
59 for (i0 = 0; i0 < numNodes; i0++)
60 fscanf(fileHandle_p, "%d %d %d %le %le %le\n", &nodes_p->Id[i0],
61 &nodes_p->degreeOfFreedom[i0], &nodes_p->Tag[i0],
62 &nodes_p->Coordinates[INDEX2(0,i0,numDim)],
63 &nodes_p->Coordinates[INDEX2(1,i0,numDim)],
64 &nodes_p->Coordinates[INDEX2(2,i0,numDim)]);
65 } /* if else else */
66
67 /* get the element type */
68
69 fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
70 ElementTypeId typeID=Finley_RefElement_getTypeId(element_type);
71 if (typeID==NoType) {
72 Finley_ErrorCode=VALUE_ERROR;
73 sprintf(Finley_ErrorMsg,"Unidentified element type %s",element_type);
74 return NULL;
75 }
76
77 /* allocate mesh */
78
79 Finley_Mesh * mesh_p =Finley_Mesh_alloc(name,numDim,order);
80 if (Finley_ErrorCode!=NO_ERROR) return NULL;
81 mesh_p->Nodes=nodes_p;
82
83 /* read the elements */
84 mesh_p->Elements=Finley_ElementFile_alloc(typeID,mesh_p->order);
85 Finley_ElementFile_allocTable(mesh_p->Elements, numEle);
86 mesh_p->Elements->numColors=numEle+1;
87 for (i0 = 0; i0 < numEle; i0++) {
88 fscanf(fileHandle_p, "%d %d", &mesh_p->Elements->Id[i0], &mesh_p->Elements->Tag[i0]);
89 mesh_p->Elements->Color[i0]=i0;
90 for (i1 = 0; i1 < mesh_p->Elements->ReferenceElement->Type->numNodes; i1++) {
91 fscanf(fileHandle_p, " %d",
92 &mesh_p->Elements->Nodes[INDEX2(i1, i0, mesh_p->Elements->ReferenceElement->Type->numNodes)]);
93 } /* for i1 */
94 fscanf(fileHandle_p, "\n");
95 } /* for i0 */
96
97 /* get the face elements */
98 fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
99 ElementTypeId faceTypeID=Finley_RefElement_getTypeId(element_type);
100 if (faceTypeID==NoType) {
101 Finley_ErrorCode=VALUE_ERROR;
102 sprintf(Finley_ErrorMsg,"Unidentified element type %s for face elements",element_type);
103 return NULL;
104 }
105 mesh_p->FaceElements=Finley_ElementFile_alloc(faceTypeID,mesh_p->order);
106 Finley_ElementFile_allocTable(mesh_p->FaceElements, numEle);
107 mesh_p->FaceElements->numColors=numEle+1;
108 for (i0 = 0; i0 < numEle; i0++) {
109 fscanf(fileHandle_p, "%d %d", &mesh_p->FaceElements->Id[i0], &mesh_p->FaceElements->Tag[i0]);
110 mesh_p->FaceElements->Color[i0]=i0;
111 for (i1 = 0; i1 < mesh_p->FaceElements->ReferenceElement->Type->numNodes; i1++) {
112 fscanf(fileHandle_p, " %d",
113 &mesh_p->FaceElements->Nodes[INDEX2(i1, i0, mesh_p->FaceElements->ReferenceElement->Type->numNodes)]);
114 } /* for i1 */
115 fscanf(fileHandle_p, "\n");
116 } /* for i0 */
117
118 /* get the Contact face element */
119 fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
120 ElementTypeId contactTypeID=Finley_RefElement_getTypeId(element_type);
121 if (contactTypeID==NoType) {
122 Finley_ErrorCode=VALUE_ERROR;
123 sprintf(Finley_ErrorMsg,"Unidentified element type %s for contact elements",element_type);
124 return NULL;
125 }
126 mesh_p->ContactElements=Finley_ElementFile_alloc(contactTypeID,mesh_p->order);
127 Finley_ElementFile_allocTable(mesh_p->ContactElements, numEle);
128 mesh_p->ContactElements->numColors=numEle+1;
129 for (i0 = 0; i0 < numEle; i0++) {
130 fscanf(fileHandle_p, "%d %d", &mesh_p->ContactElements->Id[i0], &mesh_p->ContactElements->Tag[i0]);
131 mesh_p->ContactElements->Color[i0]=i0;
132 for (i1 = 0; i1 < mesh_p->ContactElements->ReferenceElement->Type->numNodes; i1++) {
133 fscanf(fileHandle_p, " %d",
134 &mesh_p->ContactElements->Nodes[INDEX2(i1, i0, mesh_p->ContactElements->ReferenceElement->Type->numNodes)]);
135 } /* for i1 */
136 fscanf(fileHandle_p, "\n");
137 } /* for i0 */
138
139 /* get the nodal element */
140 fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
141 ElementTypeId pointTypeID=Finley_RefElement_getTypeId(element_type);
142 if (pointTypeID==NoType) {
143 Finley_ErrorCode=VALUE_ERROR;
144 sprintf(Finley_ErrorMsg,"Unidentified element type %s for points",element_type);
145 return NULL;
146 }
147 mesh_p->Points=Finley_ElementFile_alloc(pointTypeID,mesh_p->order);
148
149 Finley_ElementFile_allocTable(mesh_p->Points, numEle);
150 mesh_p->Points->numColors=numEle+1;
151 for (i0 = 0; i0 < numEle; i0++) {
152 fscanf(fileHandle_p, "%d %d", &mesh_p->Points->Id[i0], &mesh_p->Points->Tag[i0]);
153 mesh_p->Points->Color[i0]=i0;
154 for (i1 = 0; i1 < mesh_p->Points->ReferenceElement->Type->numNodes; i1++) {
155 fscanf(fileHandle_p, " %d",
156 &mesh_p->Points->Nodes[INDEX2(i1, i0, mesh_p->Points->ReferenceElement->Type->numNodes)]);
157 } /* for i1 */
158 fscanf(fileHandle_p, "\n");
159 } /* for i0 */
160
161
162 /* close file */
163
164 fclose(fileHandle_p);
165
166 /* resolve id's : */
167
168 Finley_Mesh_resolveNodeIds(mesh_p);
169
170 /* rearrange elements: */
171
172 Finley_Mesh_prepare(mesh_p);
173
174 /* that's it */
175 printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);
176 if (Finley_ErrorCode!=NO_ERROR) Finley_Mesh_dealloc(mesh_p);
177 return mesh_p;
178 }
179 /*
180 * $Log$
181 * Revision 1.1 2004/10/26 06:53:57 jgs
182 * Initial revision
183 *
184 * Revision 1.1.1.1 2004/06/24 04:00:40 johng
185 * Initial version of eys using boost-python.
186 *
187 *
188 */
189

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26