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

Diff of /trunk/finley/src/Mesh_read.c

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

revision 730 by bcumming, Mon May 15 04:03:49 2006 UTC revision 1028 by gross, Wed Mar 14 00:15:24 2007 UTC
# Line 33  Finley_Mesh* Finley_Mesh_read(char* fnam Line 33  Finley_Mesh* Finley_Mesh_read(char* fnam
33    Finley_Mesh *mesh_p=NULL;    Finley_Mesh *mesh_p=NULL;
34    char name[LenString_MAX],element_type[LenString_MAX],frm[20];    char name[LenString_MAX],element_type[LenString_MAX],frm[20];
35    char error_msg[LenErrorMsg_MAX];    char error_msg[LenErrorMsg_MAX];
   Finley_NodeFile *nodes_p=NULL;  
36    double time0=Finley_timer();    double time0=Finley_timer();
37      FILE *fileHandle_p = NULL;
38      ElementTypeId typeID, faceTypeID, contactTypeID, pointTypeID;
39    
40    Finley_resetError();    Finley_resetError();
41    
42    /* get file handle */    /* get file handle */
43    FILE * fileHandle_p = fopen(fname, "r");    fileHandle_p = fopen(fname, "r");
44    if (fileHandle_p==NULL) {    if (fileHandle_p==NULL) {
45      sprintf(error_msg,"%s: Opening file %s for reading failed.",__FILE__,fname);      sprintf(error_msg,"Finley_Mesh_read: Opening file %s for reading failed.",fname);
46      Finley_setError(IO_ERROR,error_msg);      Finley_setError(IO_ERROR,error_msg);
47      return NULL;      return NULL;
48    }    }
# Line 49  Finley_Mesh* Finley_Mesh_read(char* fnam Line 50  Finley_Mesh* Finley_Mesh_read(char* fnam
50    /* read header */    /* read header */
51    sprintf(frm,"%%%d[^\n]",LenString_MAX-1);    sprintf(frm,"%%%d[^\n]",LenString_MAX-1);
52    fscanf(fileHandle_p, frm, name);    fscanf(fileHandle_p, frm, name);
53    
54    /* get the nodes */    /* get the nodes */
55    
56    fscanf(fileHandle_p, "%1d%*s %d\n", &numDim,&numNodes);    fscanf(fileHandle_p, "%1d%*s %d\n", &numDim,&numNodes);
57      /* allocate mesh */
58  #ifndef PASO_MPI  #ifndef PASO_MPI
59    nodes_p=Finley_NodeFile_alloc(numDim);    mesh_p = Finley_Mesh_alloc(name,numDim,order);
60    if (! Finley_noError()) return NULL;    if (! Finley_noError()) return NULL;
61    Finley_NodeFile_allocTable(nodes_p, numNodes);  #else
62      /* TODO */
63    #endif
64    
65    #ifndef PASO_MPI
66      Finley_NodeFile_allocTable(mesh_p->Nodes, numNodes);
67    if (! Finley_noError()) return NULL;    if (! Finley_noError()) return NULL;
68  #else  #else
69    /* TODO */    /* TODO */
# Line 63  Finley_Mesh* Finley_Mesh_read(char* fnam Line 71  Finley_Mesh* Finley_Mesh_read(char* fnam
71    
72    if (1 == numDim) {    if (1 == numDim) {
73        for (i0 = 0; i0 < numNodes; i0++)        for (i0 = 0; i0 < numNodes; i0++)
74      fscanf(fileHandle_p, "%d %d %d %le\n", &nodes_p->Id[i0],      fscanf(fileHandle_p, "%d %d %d %le\n", &mesh_p->Nodes->Id[i0],
75             &nodes_p->degreeOfFreedom[i0], &nodes_p->Tag[i0],             &mesh_p->Nodes->degreeOfFreedom[i0], &mesh_p->Nodes->Tag[i0],
76             &nodes_p->Coordinates[INDEX2(0,i0,numDim)]);             &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)]);
77    } else if (2 == numDim) {    } else if (2 == numDim) {
78        for (i0 = 0; i0 < numNodes; i0++)        for (i0 = 0; i0 < numNodes; i0++)
79      fscanf(fileHandle_p, "%d %d %d %le %le\n", &nodes_p->Id[i0],      fscanf(fileHandle_p, "%d %d %d %le %le\n", &mesh_p->Nodes->Id[i0],
80             &nodes_p->degreeOfFreedom[i0], &nodes_p->Tag[i0],             &mesh_p->Nodes->degreeOfFreedom[i0], &mesh_p->Nodes->Tag[i0],
81             &nodes_p->Coordinates[INDEX2(0,i0,numDim)],             &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],
82             &nodes_p->Coordinates[INDEX2(1,i0,numDim)]);             &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)]);
83    } else if (3 == numDim) {    } else if (3 == numDim) {
84        for (i0 = 0; i0 < numNodes; i0++)        for (i0 = 0; i0 < numNodes; i0++)
85      fscanf(fileHandle_p, "%d %d %d %le %le %le\n", &nodes_p->Id[i0],      fscanf(fileHandle_p, "%d %d %d %le %le %le\n", &mesh_p->Nodes->Id[i0],
86             &nodes_p->degreeOfFreedom[i0], &nodes_p->Tag[i0],             &mesh_p->Nodes->degreeOfFreedom[i0], &mesh_p->Nodes->Tag[i0],
87             &nodes_p->Coordinates[INDEX2(0,i0,numDim)],             &mesh_p->Nodes->Coordinates[INDEX2(0,i0,numDim)],
88             &nodes_p->Coordinates[INDEX2(1,i0,numDim)],             &mesh_p->Nodes->Coordinates[INDEX2(1,i0,numDim)],
89             &nodes_p->Coordinates[INDEX2(2,i0,numDim)]);             &mesh_p->Nodes->Coordinates[INDEX2(2,i0,numDim)]);
90    } /* if else else */    } /* if else else */
91    
92    /* get the element type */    /* get the element type */
93    
94    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
95    ElementTypeId typeID=Finley_RefElement_getTypeId(element_type);    typeID=Finley_RefElement_getTypeId(element_type);
96    if (typeID==NoType) {    if (typeID==NoType) {
97      sprintf(error_msg,"%s :Unidentified element type %s",__FILE__,element_type);      sprintf(error_msg,"Finley_Mesh_read :Unidentified element type %s",element_type);
98      Finley_setError(VALUE_ERROR,error_msg);      Finley_setError(VALUE_ERROR,error_msg);
99      return NULL;      return NULL;
100    }    }
   
   /* allocate mesh */  
   
   /* Finley_Mesh * mesh_p =Finley_Mesh_alloc(name,numDim,order); */  
 #ifndef PASO_MPI  
   mesh_p = Finley_Mesh_alloc(name,numDim,order);  
 #else  
   /* TODO */  
 #endif  
   
   if (! Finley_noError()) return NULL;  
   mesh_p->Nodes=nodes_p;  
   
101    /* read the elements */    /* read the elements */
102  #ifndef PASO_MPI  #ifndef PASO_MPI
103    mesh_p->Elements=Finley_ElementFile_alloc(typeID,mesh_p->order);    mesh_p->Elements=Finley_ElementFile_alloc(typeID,mesh_p->order);
# Line 124  Finley_Mesh* Finley_Mesh_read(char* fnam Line 119  Finley_Mesh* Finley_Mesh_read(char* fnam
119    
120    /* get the face elements */    /* get the face elements */
121    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
122    ElementTypeId faceTypeID=Finley_RefElement_getTypeId(element_type);    faceTypeID=Finley_RefElement_getTypeId(element_type);
123      faceTypeID=Finley_RefElement_getTypeId(element_type);
124    if (faceTypeID==NoType) {    if (faceTypeID==NoType) {
125      sprintf(error_msg,"%s :Unidentified element type %s for face elements",__FILE__,element_type);      sprintf(error_msg,"Finley_Mesh_read :Unidentified element type %s for face elements",element_type);
126      Finley_setError(VALUE_ERROR,error_msg);      Finley_setError(VALUE_ERROR,error_msg);
127      return NULL;      return NULL;
128    }    }
# Line 150  Finley_Mesh* Finley_Mesh_read(char* fnam Line 146  Finley_Mesh* Finley_Mesh_read(char* fnam
146    
147    /* get the Contact face element */    /* get the Contact face element */
148    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
149    ElementTypeId contactTypeID=Finley_RefElement_getTypeId(element_type);    contactTypeID=Finley_RefElement_getTypeId(element_type);
150    if (contactTypeID==NoType) {    if (contactTypeID==NoType) {
151      sprintf(error_msg,"%s: Unidentified element type %s for contact elements",__FILE__,element_type);      sprintf(error_msg,"Finley_Mesh_read: Unidentified element type %s for contact elements",element_type);
152      Finley_setError(VALUE_ERROR,error_msg);      Finley_setError(VALUE_ERROR,error_msg);
153      return NULL;      return NULL;
154    }    }
# Line 176  Finley_Mesh* Finley_Mesh_read(char* fnam Line 172  Finley_Mesh* Finley_Mesh_read(char* fnam
172    
173    /* get the nodal element */    /* get the nodal element */
174    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
175    ElementTypeId pointTypeID=Finley_RefElement_getTypeId(element_type);    pointTypeID=Finley_RefElement_getTypeId(element_type);
176    if (pointTypeID==NoType) {    if (pointTypeID==NoType) {
177      sprintf(error_msg,"%s: Unidentified element type %s for points",__FILE__,element_type);      sprintf(error_msg,"Finley_Mesh_read: Unidentified element type %s for points",element_type);
178      Finley_setError(VALUE_ERROR,error_msg);      Finley_setError(VALUE_ERROR,error_msg);
179      return NULL;      return NULL;
180    }    }
# Line 217  Finley_Mesh* Finley_Mesh_read(char* fnam Line 213  Finley_Mesh* Finley_Mesh_read(char* fnam
213    #ifdef Finley_TRACE    #ifdef Finley_TRACE
214    printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);    printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);
215    #endif    #endif
216    if (! Finley_noError()) Finley_Mesh_dealloc(mesh_p);    if (Finley_noError()) {
217           if ( ! Finley_Mesh_isPrepared(mesh_p)) {
218              Finley_setError(SYSTEM_ERROR,"Mesh is not prepared for calculation. Contact the programmers.");
219           }
220      } else {
221           Finley_Mesh_dealloc(mesh_p);
222      }
223    return mesh_p;    return mesh_p;
224  }  }
 /*  
 * $Log$  
 * Revision 1.5  2005/09/15 03:44:22  jgs  
 * Merge of development branch dev-02 back to main trunk on 2005-09-15  
 *  
 * Revision 1.4  2005/09/01 03:31:36  jgs  
 * Merge of development branch dev-02 back to main trunk on 2005-09-01  
 *  
 * Revision 1.3.2.3  2005/09/08 08:28:39  gross  
 * some cleanup in savevtk  
 *  
 * Revision 1.3.2.2  2005/09/07 06:26:19  gross  
 * the solver from finley are put into the standalone package paso now  
 *  
 * Revision 1.3.2.1  2005/08/24 02:02:18  gross  
 * timing output switched off. solver output can be swiched through getSolution(verbose=True) now.  
 *  
 * Revision 1.3  2005/07/22 03:53:08  jgs  
 * Merge of development branch back to main trunk on 2005-07-22  
 *  
 * Revision 1.2  2005/07/08 04:07:54  jgs  
 * Merge of development branch back to main trunk on 2005-07-08  
 *  
 * Revision 1.1.1.1.2.2  2005/07/18 10:34:54  gross  
 * some informance improvements when reading meshes  
 *  
 * Revision 1.1.1.1.2.1  2005/06/29 02:34:53  gross  
 * some changes towards 64 integers in finley  
 *  
 * Revision 1.1.1.1  2004/10/26 06:53:57  jgs  
 * initial import of project esys2  
 *  
 * Revision 1.1.1.1  2004/06/24 04:00:40  johng  
 * Initial version of eys using boost-python.  
 *  
 *  
 */  
   

Legend:
Removed from v.730  
changed lines
  Added in v.1028

  ViewVC Help
Powered by ViewVC 1.1.26