/[escript]/branches/domexper/dudley/src/Mesh_readGmsh.c
ViewVC logotype

Diff of /branches/domexper/dudley/src/Mesh_readGmsh.c

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

revision 997 by gross, Mon Feb 26 06:31:45 2007 UTC revision 1177 by gross, Wed May 30 05:01:29 2007 UTC
# Line 37  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 37  Finley_Mesh* Finley_Mesh_readGmsh(char*
37    int format = 0, size = sizeof(double);    int format = 0, size = sizeof(double);
38    dim_t numNodes, totalNumElements=0, numTags=0, numNodesPerElement, numNodesPerElement2, element_dim;    dim_t numNodes, totalNumElements=0, numTags=0, numNodesPerElement, numNodesPerElement2, element_dim;
39    index_t e, i0, j, gmsh_type, partition_id, itmp, final_element_type,  elementary_id;    index_t e, i0, j, gmsh_type, partition_id, itmp, final_element_type,  elementary_id;
40      index_t numElements=0, numFaceElements=0, *id=NULL, *tag=NULL, *vertices=NULL;
41    Finley_Mesh *mesh_p=NULL;    Finley_Mesh *mesh_p=NULL;
42    char name[LenString_MAX],element_type[LenString_MAX],frm[20], line[LenString_MAX+1];    char line[LenString_MAX+1];
43    char error_msg[LenErrorMsg_MAX];    char error_msg[LenErrorMsg_MAX];
44    double rtmp0, rtmp1;    double rtmp0, rtmp1;
45    double time0=Finley_timer();    double time0=Finley_timer();
46      FILE * fileHandle_p = NULL;
47      ElementTypeId* element_type=NULL;
48    
49    Finley_resetError();    Finley_resetError();
50   #if PASO_MPI   #if PASO_MPI
51      sprintf(error_msg,"reading GMSH with MPI is not supported yet.");      sprintf(error_msg,"reading GMSH with MPI is not supported yet.");
52      Finley_setError(IO_ERROR,error_msg);      Finley_setError(IO_ERROR,error_msg);
53      return NULL;      return NULL;
   
54  #else  #else
55    /* allocate mesh */    /* allocate mesh */
56    
57    mesh_p = Finley_Mesh_alloc(fname,numDim,order);    mesh_p = Finley_Mesh_alloc(fname,numDim,order, reduced_order);
58    if (! Finley_noError()) return NULL;    if (! Finley_noError()) return NULL;
59    
60    /* get file handle */    /* get file handle */
61    FILE * fileHandle_p = fopen(fname, "r");    fileHandle_p = fopen(fname, "r");
62    if (fileHandle_p==NULL) {    if (fileHandle_p==NULL) {
63      sprintf(error_msg,"Opening Gmsh file %s for reading failed.",fname);      sprintf(error_msg,"Opening Gmsh file %s for reading failed.",fname);
64      Finley_setError(IO_ERROR,error_msg);      Finley_setError(IO_ERROR,error_msg);
# Line 117  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 119  Finley_Mesh* Finley_Mesh_readGmsh(char*
119    
120        ElementTypeId final_element_type = NoType;        ElementTypeId final_element_type = NoType;
121        ElementTypeId final_face_element_type = NoType;        ElementTypeId final_face_element_type = NoType;
122        index_t numElements=0;        numElements=0;
123        index_t numFaceElements=0;        numFaceElements=0;
124        fscanf(fileHandle_p, "%d", &totalNumElements);        fscanf(fileHandle_p, "%d", &totalNumElements);
125    
126        index_t* id=TMPMEMALLOC(totalNumElements,index_t);        id=TMPMEMALLOC(totalNumElements,index_t);
127        index_t* tag=TMPMEMALLOC(totalNumElements,index_t);        tag=TMPMEMALLOC(totalNumElements,index_t);
128        ElementTypeId* element_type=TMPMEMALLOC(totalNumElements,ElementTypeId);  
129        index_t* vertices=TMPMEMALLOC(totalNumElements*MAX_numNodes_gmsh,index_t);  
130          element_type=TMPMEMALLOC(totalNumElements,ElementTypeId);
131          vertices=TMPMEMALLOC(totalNumElements*MAX_numNodes_gmsh,index_t);
132        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) ) ) {
133           /* read all in */           /* read all in */
134           for(e = 0; e < totalNumElements; e++) {           for(e = 0; e < totalNumElements; e++) {
# Line 225  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 229  Finley_Mesh* Finley_Mesh_readGmsh(char*
229             } else if (j == 2) {             } else if (j == 2) {
230               partition_id = itmp;               partition_id = itmp;
231                 }                 }
232             // ignore any other tags             /* ignore any other tags */
233           }           }
234         }         }
235             if (! Finley_noError()) break;             if (! Finley_noError()) break;
# Line 234  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 238  Finley_Mesh* Finley_Mesh_readGmsh(char*
238           /* all elements have been read, now we have to identify the elements for finley */           /* all elements have been read, now we have to identify the elements for finley */
239            
240           if (Finley_noError()) {           if (Finley_noError()) {
241              /* first we have to identify the elements to define Elementis and FaceElements */             /* first we have to identify the elements to define Elementis and FaceElements */
242             mesh_p->Elements=Finley_ElementFile_alloc(final_element_type,mesh_p->order);             if (final_element_type == NoType) {
243             mesh_p->FaceElements=Finley_ElementFile_alloc(final_face_element_type,mesh_p->order);                if (numDim==1) {
244             mesh_p->ContactElements=Finley_ElementFile_alloc(Point1_Contact,mesh_p->order);                   final_element_type=Line2;
245             mesh_p->Points=Finley_ElementFile_alloc(Point1,mesh_p->order);                } else if (numDim==2) {
246                     final_element_type=Tri3;
247                  } else if (numDim==3) {
248                     final_element_type=Tet4;
249                  }
250               }
251               if (final_face_element_type == NoType) {
252                  if (numDim==1) {
253                     final_face_element_type=Point1;
254                  } else if (numDim==2) {
255                     final_face_element_type=Line2;
256                  } else if (numDim==3) {
257                     final_face_element_type=Tri3;
258                  }
259               }
260               mesh_p->Elements=Finley_ElementFile_alloc(final_element_type,mesh_p->order, mesh_p->reduced_order);
261               mesh_p->FaceElements=Finley_ElementFile_alloc(final_face_element_type,mesh_p->order, mesh_p->reduced_order);
262               mesh_p->ContactElements=Finley_ElementFile_alloc(Point1_Contact,mesh_p->order, mesh_p->reduced_order);
263               mesh_p->Points=Finley_ElementFile_alloc(Point1,mesh_p->order, mesh_p->reduced_order);
264             if (Finley_noError()) {             if (Finley_noError()) {
265                 Finley_ElementFile_allocTable(mesh_p->Elements, numElements);                 Finley_ElementFile_allocTable(mesh_p->Elements, numElements);
266                 Finley_ElementFile_allocTable(mesh_p->FaceElements, numFaceElements);                 Finley_ElementFile_allocTable(mesh_p->FaceElements, numFaceElements);
# Line 300  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 322  Finley_Mesh* Finley_Mesh_readGmsh(char*
322    
323    /* close file */    /* close file */
324    fclose(fileHandle_p);    fclose(fileHandle_p);
   /* clean up */  
   if (! Finley_noError()) {  
      Finley_Mesh_dealloc(mesh_p);  
      return NULL;  
   }  
325    /*   resolve id's : */    /*   resolve id's : */
326    Finley_Mesh_resolveNodeIds(mesh_p);    if (Finley_noError()) {
327          Finley_Mesh_resolveNodeIds(mesh_p);
328      }
329    /* rearrange elements: */    /* rearrange elements: */
330    Finley_Mesh_prepare(mesh_p);    if (Finley_noError()) {
331         Finley_Mesh_prepare(mesh_p);
332      }
333    
334      /* optimize node labeling*/
335      if (Finley_noError()) {
336          if (optimize_labeling) Finley_Mesh_optimizeNodeLabeling(mesh_p);
337      }
338    /* that's it */    /* that's it */
339    #ifdef Finley_TRACE    #ifdef Finley_TRACE
340    printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);    printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);
# Line 318  Finley_Mesh* Finley_Mesh_readGmsh(char* Line 344  Finley_Mesh* Finley_Mesh_readGmsh(char*
344         if (  ! Finley_Mesh_isPrepared(mesh_p)) {         if (  ! Finley_Mesh_isPrepared(mesh_p)) {
345            Finley_setError(SYSTEM_ERROR,"Mesh is not prepared for calculation. Contact the programmers.");            Finley_setError(SYSTEM_ERROR,"Mesh is not prepared for calculation. Contact the programmers.");
346         }         }
347      } else {
348         Finley_Mesh_dealloc(mesh_p);
349    }    }
350    return mesh_p;    return mesh_p;
351  }  }

Legend:
Removed from v.997  
changed lines
  Added in v.1177

  ViewVC Help
Powered by ViewVC 1.1.26