/[escript]/branches/doubleplusgood/dudley/src/Mesh_readGmsh.cpp
ViewVC logotype

Diff of /branches/doubleplusgood/dudley/src/Mesh_readGmsh.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1814 by gross, Tue Sep 30 00:21:21 2008 UTC revision 1887 by ksteube, Wed Oct 15 03:26:25 2008 UTC
# Line 21  Line 21 
21  #include "Mesh.h"  #include "Mesh.h"
22  #include <stdio.h>  #include <stdio.h>
23    
24    #define FSCANF_CHECK(scan_ret, reason) { if (scan_ret == EOF) perror(reason); return NULL; }
25    
26    
27  /**************************************************************/  /**************************************************************/
28    
# Line 31  Line 33 
33  Finley_Mesh* Finley_Mesh_readGmsh(char* fname ,index_t numDim, index_t order, index_t reduced_order, bool_t optimize) {  Finley_Mesh* Finley_Mesh_readGmsh(char* fname ,index_t numDim, index_t order, index_t reduced_order, bool_t optimize) {
34    
35    double version = 1.0;    double version = 1.0;
36    int format = 0, size = sizeof(double);    int format = 0, size = sizeof(double), scan_ret;
37    dim_t numNodes, totalNumElements=0, numTags=0, numNodesPerElement, numNodesPerElement2, element_dim;    dim_t numNodes, totalNumElements=0, numTags=0, numNodesPerElement, numNodesPerElement2, element_dim;
38    index_t e, i0, j, gmsh_type, partition_id, itmp, elementary_id;    index_t e, i0, j, gmsh_type, partition_id, itmp, elementary_id;
39    index_t numElements=0, numFaceElements=0, *id=NULL, *tag=NULL, *vertices=NULL;    index_t numElements=0, numFaceElements=0, *id=NULL, *tag=NULL, *vertices=NULL;
# Line 79  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 81  Finley_Mesh* Finley_Mesh_readGmsh(char*
81        
82         /* format */         /* format */
83         if (!strncmp(&line[1], "MeshFormat", 10)) {         if (!strncmp(&line[1], "MeshFormat", 10)) {
84           fscanf(fileHandle_p, "%lf %d %d\n", &version, &format, &size);           scan_ret = fscanf(fileHandle_p, "%lf %d %d\n", &version, &format, &size);
85         FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
86         }         }
87         /* nodes are read */         /* nodes are read */
88         if ( !strncmp(&line[1], "NOD", 3)   ||         if ( !strncmp(&line[1], "NOD", 3)   ||
89              !strncmp(&line[1], "NOE", 3)   ||              !strncmp(&line[1], "NOE", 3)   ||
90              !strncmp(&line[1], "Nodes", 5)    ) {              !strncmp(&line[1], "Nodes", 5)    ) {
91                    
92           fscanf(fileHandle_p, "%d", &numNodes);           scan_ret = fscanf(fileHandle_p, "%d", &numNodes);
93         FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
94           if (! Finley_noError()) break;           if (! Finley_noError()) break;
95           Finley_NodeFile_allocTable(mesh_p->Nodes, numNodes);           Finley_NodeFile_allocTable(mesh_p->Nodes, numNodes);
96           if (! Finley_noError()) break;           if (! Finley_noError()) break;
97           for (i0 = 0; i0 < numNodes; i0++) {           for (i0 = 0; i0 < numNodes; i0++) {
98              if (1 == numDim) {              if (1 == numDim) {
99             fscanf(fileHandle_p, "%d %le %le %le\n", &mesh_p->Nodes->Id[i0],             scan_ret = fscanf(fileHandle_p, "%d %le %le %le\n", &mesh_p->Nodes->Id[i0],
100                    &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],                    &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],
101                           &rtmp0,                           &rtmp0,
102                           &rtmp1);                           &rtmp1);
103               FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
104              } else if (2 == numDim) {              } else if (2 == numDim) {
105             fscanf(fileHandle_p, "%d %le %le %le\n", &mesh_p->Nodes->Id[i0],             scan_ret = fscanf(fileHandle_p, "%d %le %le %le\n", &mesh_p->Nodes->Id[i0],
106                    &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],                    &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],
107                    &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)],                    &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)],
108                           &rtmp0);                           &rtmp0);
109               FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
110              } else if (3 == numDim) {              } else if (3 == numDim) {
111             fscanf(fileHandle_p, "%d %le %le %le\n", &mesh_p->Nodes->Id[i0],             scan_ret = fscanf(fileHandle_p, "%d %le %le %le\n", &mesh_p->Nodes->Id[i0],
112                    &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],                    &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],
113                    &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)],                    &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)],
114                    &mesh_p->Nodes->Coordinates[INDEX2(2,i0,numDim)]);                    &mesh_p->Nodes->Coordinates[INDEX2(2,i0,numDim)]);
115                     FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
             
116              }              }
117              mesh_p->Nodes->globalDegreesOfFreedom[i0]=mesh_p->Nodes->Id[i0];              mesh_p->Nodes->globalDegreesOfFreedom[i0]=mesh_p->Nodes->Id[i0];
118              mesh_p->Nodes->Tag[i0]=0;              mesh_p->Nodes->Tag[i0]=0;
# Line 122  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 127  Finley_Mesh* Finley_Mesh_readGmsh(char*
127           ElementTypeId contact_element_type = NoType;           ElementTypeId contact_element_type = NoType;
128           numElements=0;           numElements=0;
129           numFaceElements=0;           numFaceElements=0;
130           fscanf(fileHandle_p, "%d", &totalNumElements);           scan_ret = fscanf(fileHandle_p, "%d", &totalNumElements);
131         FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
132        
133           id=TMPMEMALLOC(totalNumElements,index_t);           id=TMPMEMALLOC(totalNumElements,index_t);
134           tag=TMPMEMALLOC(totalNumElements,index_t);           tag=TMPMEMALLOC(totalNumElements,index_t);
# Line 133  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 139  Finley_Mesh* Finley_Mesh_readGmsh(char*
139           if (! (Finley_checkPtr(id) || Finley_checkPtr(tag) || Finley_checkPtr(element_type) || Finley_checkPtr(vertices) ) ) {           if (! (Finley_checkPtr(id) || Finley_checkPtr(tag) || Finley_checkPtr(element_type) || Finley_checkPtr(vertices) ) ) {
140              /* read all in */              /* read all in */
141              for(e = 0; e < totalNumElements; e++) {              for(e = 0; e < totalNumElements; e++) {
142                fscanf(fileHandle_p, "%d %d", &id[e], &gmsh_type);                scan_ret = fscanf(fileHandle_p, "%d %d", &id[e], &gmsh_type);
143              FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
144                switch (gmsh_type) {                switch (gmsh_type) {
145                    case 1:  /* line order 1 */                    case 1:  /* line order 1 */
146                        element_type[e]=Line2;                        element_type[e]=Line2;
# Line 211  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 218  Finley_Mesh* Finley_Mesh_readGmsh(char*
218                }                }
219                                
220         if(version <= 1.0){         if(version <= 1.0){
221           fscanf(fileHandle_p, "%d %d %d", &tag[e], &elementary_id, &numNodesPerElement2);           scan_ret = fscanf(fileHandle_p, "%d %d %d", &tag[e], &elementary_id, &numNodesPerElement2);
222             FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
223           partition_id = 1;           partition_id = 1;
224                  if (numNodesPerElement2 != numNodesPerElement) {                  if (numNodesPerElement2 != numNodesPerElement) {
225                       sprintf(error_msg,"Illegal number of nodes for element %d in mesh file %s.",id[e],fname);                       sprintf(error_msg,"Illegal number of nodes for element %d in mesh file %s.",id[e],fname);
226                       Finley_setError(IO_ERROR,error_msg);                       Finley_setError(IO_ERROR,error_msg);
227                  }                  }
228         } else {         } else {
229           fscanf(fileHandle_p, "%d", &numTags);           scan_ret = fscanf(fileHandle_p, "%d", &numTags);
230             FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
231           elementary_id = tag[e] = partition_id = 1;           elementary_id = tag[e] = partition_id = 1;
232                  numNodesPerElement2=-1;                  numNodesPerElement2=-1;
233           for(j = 0; j < numTags; j++){           for(j = 0; j < numTags; j++){
234             fscanf(fileHandle_p, "%d", &itmp);                   scan_ret = fscanf(fileHandle_p, "%d", &itmp);        
235               FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
236             if (j == 0) {             if (j == 0) {
237               tag[e] = itmp;               tag[e] = itmp;
238             } else if (j == 1) {             } else if (j == 1) {
# Line 234  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 244  Finley_Mesh* Finley_Mesh_readGmsh(char*
244           }           }
245         }         }
246                if (! Finley_noError()) break;                if (! Finley_noError()) break;
247                for(j = 0; j < numNodesPerElement; j++) fscanf(fileHandle_p, "%d", &vertices[INDEX2(j,e,MAX_numNodes_gmsh)]);                for(j = 0; j < numNodesPerElement; j++) {
248            scan_ret = fscanf(fileHandle_p, "%d", &vertices[INDEX2(j,e,MAX_numNodes_gmsh)]);
249                FSCANF_CHECK(scan_ret, "fscanf: Finley_Mesh_readGmsh");
250              }
251                /* for tet10 the last two nodes need to be swapped */                /* for tet10 the last two nodes need to be swapped */
252                if (element_type[e]==Tet10) {                if (element_type[e]==Tet10) {
253                     itmp=vertices[INDEX2(9,e,MAX_numNodes_gmsh)];                     itmp=vertices[INDEX2(9,e,MAX_numNodes_gmsh)];

Legend:
Removed from v.1814  
changed lines
  Added in v.1887

  ViewVC Help
Powered by ViewVC 1.1.26