/[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 149 by jgs, Thu Sep 1 03:31:39 2005 UTC revision 150 by jgs, Thu Sep 15 03:44:45 2005 UTC
# Line 1  Line 1 
1    /*
2     ******************************************************************************
3     *                                                                            *
4     *       COPYRIGHT  ACcESS 2003,2004,2005 -  All Rights Reserved              *
5     *                                                                            *
6     * This software is the property of ACcESS. No part of this code              *
7     * may be copied in any form or by any means without the expressed written    *
8     * consent of ACcESS.  Copying, use or modification of this software          *
9     * by any unauthorised person is illegal unless that person has a software    *
10     * license agreement with ACcESS.                                             *
11     *                                                                            *
12     ******************************************************************************
13    */
14    
15  /**************************************************************/  /**************************************************************/
16    
17  /*   Finley: read mesh */  /*   Finley: read mesh */
18    
19  /**************************************************************/  /**************************************************************/
20    
 /*   Copyrights by ACcESS Australia 2003/04 */  
21  /*   Author: gross@access.edu.au */  /*   Author: gross@access.edu.au */
22  /*   Version: $Id$ */  /*   Version: $Id$ */
23    
24  /**************************************************************/  /**************************************************************/
25    
 #include "Finley.h"  
26  #include "Mesh.h"  #include "Mesh.h"
27    
28  /**************************************************************/  /**************************************************************/
# Line 20  Line 32 
32  Finley_Mesh* Finley_Mesh_read(char* fname,index_t order) {  Finley_Mesh* Finley_Mesh_read(char* fname,index_t order) {
33    
34    dim_t numNodes, numDim, numEle, i0, i1;    dim_t numNodes, numDim, numEle, i0, i1;
35    char name[LenString_MAX],element_type[LenString_MAX];    char name[LenString_MAX],element_type[LenString_MAX],frm[20];
36      char error_msg[LenErrorMsg_MAX];
37    Finley_NodeFile *nodes_p=NULL;    Finley_NodeFile *nodes_p=NULL;
38    double time0=Finley_timer();    double time0=Finley_timer();
39      Finley_resetError();
40    
41    /* get file handle */    /* get file handle */
42    FILE * fileHandle_p = fopen(fname, "r");    FILE * fileHandle_p = fopen(fname, "r");
43    if (fileHandle_p==NULL) {    if (fileHandle_p==NULL) {
44      Finley_ErrorCode=IO_ERROR;      sprintf(error_msg,"%s: Opening file %s for reading failed.",__FILE__,fname);
45      sprintf(Finley_ErrorMsg,"Opening file %s for reading failed.",fname);      Finley_setError(IO_ERROR,error_msg);
46      return NULL;      return NULL;
47    }    }
48    
49    /* read header */    /* read header */
50    fscanf(fileHandle_p, "%63[^\n]", name);    sprintf(frm,"%%%d[^\n]",LenString_MAX-1);
51      fscanf(fileHandle_p, frm, name);
52    /* get the nodes */    /* get the nodes */
53    
54    fscanf(fileHandle_p, "%1d%*s %d\n", &numDim,&numNodes);    fscanf(fileHandle_p, "%1d%*s %d\n", &numDim,&numNodes);
55    nodes_p=Finley_NodeFile_alloc(numDim);    nodes_p=Finley_NodeFile_alloc(numDim);
56    if (Finley_ErrorCode!=NO_ERROR) return NULL;    if (! Finley_noError()) return NULL;
57    Finley_NodeFile_allocTable(nodes_p, numNodes);    Finley_NodeFile_allocTable(nodes_p, numNodes);
58    if (Finley_ErrorCode!=NO_ERROR) return NULL;    if (! Finley_noError()) return NULL;
59    
60    if (1 == numDim) {    if (1 == numDim) {
61        for (i0 = 0; i0 < numNodes; i0++)        for (i0 = 0; i0 < numNodes; i0++)
# Line 68  Finley_Mesh* Finley_Mesh_read(char* fnam Line 82  Finley_Mesh* Finley_Mesh_read(char* fnam
82    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
83    ElementTypeId typeID=Finley_RefElement_getTypeId(element_type);    ElementTypeId typeID=Finley_RefElement_getTypeId(element_type);
84    if (typeID==NoType) {    if (typeID==NoType) {
85      Finley_ErrorCode=VALUE_ERROR;      sprintf(error_msg,"%s :Unidentified element type %s",__FILE__,element_type);
86      sprintf(Finley_ErrorMsg,"Unidentified element type %s",element_type);      Finley_setError(VALUE_ERROR,error_msg);
87      return NULL;      return NULL;
88    }    }
89    
90    /* allocate mesh */    /* allocate mesh */
91    
92    Finley_Mesh * mesh_p =Finley_Mesh_alloc(name,numDim,order);    Finley_Mesh * mesh_p =Finley_Mesh_alloc(name,numDim,order);
93    if (Finley_ErrorCode!=NO_ERROR) return NULL;    if (! Finley_noError()) return NULL;
94    mesh_p->Nodes=nodes_p;    mesh_p->Nodes=nodes_p;
95    
96    /* read the elements */    /* read the elements */
# Line 98  Finley_Mesh* Finley_Mesh_read(char* fnam Line 112  Finley_Mesh* Finley_Mesh_read(char* fnam
112    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
113    ElementTypeId faceTypeID=Finley_RefElement_getTypeId(element_type);    ElementTypeId faceTypeID=Finley_RefElement_getTypeId(element_type);
114    if (faceTypeID==NoType) {    if (faceTypeID==NoType) {
115      Finley_ErrorCode=VALUE_ERROR;      sprintf(error_msg,"%s :Unidentified element type %s for face elements",__FILE__,element_type);
116      sprintf(Finley_ErrorMsg,"Unidentified element type %s for face elements",element_type);      Finley_setError(VALUE_ERROR,error_msg);
117      return NULL;      return NULL;
118    }    }
119    mesh_p->FaceElements=Finley_ElementFile_alloc(faceTypeID,mesh_p->order);    mesh_p->FaceElements=Finley_ElementFile_alloc(faceTypeID,mesh_p->order);
# Line 120  Finley_Mesh* Finley_Mesh_read(char* fnam Line 134  Finley_Mesh* Finley_Mesh_read(char* fnam
134    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
135    ElementTypeId contactTypeID=Finley_RefElement_getTypeId(element_type);    ElementTypeId contactTypeID=Finley_RefElement_getTypeId(element_type);
136    if (contactTypeID==NoType) {    if (contactTypeID==NoType) {
137      Finley_ErrorCode=VALUE_ERROR;      sprintf(error_msg,"%s: Unidentified element type %s for contact elements",__FILE__,element_type);
138      sprintf(Finley_ErrorMsg,"Unidentified element type %s for contact elements",element_type);      Finley_setError(VALUE_ERROR,error_msg);
139      return NULL;      return NULL;
140    }    }
141    mesh_p->ContactElements=Finley_ElementFile_alloc(contactTypeID,mesh_p->order);    mesh_p->ContactElements=Finley_ElementFile_alloc(contactTypeID,mesh_p->order);
# Line 142  Finley_Mesh* Finley_Mesh_read(char* fnam Line 156  Finley_Mesh* Finley_Mesh_read(char* fnam
156    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);    fscanf(fileHandle_p, "%s %d\n", element_type, &numEle);
157    ElementTypeId pointTypeID=Finley_RefElement_getTypeId(element_type);    ElementTypeId pointTypeID=Finley_RefElement_getTypeId(element_type);
158    if (pointTypeID==NoType) {    if (pointTypeID==NoType) {
159      Finley_ErrorCode=VALUE_ERROR;      sprintf(error_msg,"%s: Unidentified element type %s for points",__FILE__,element_type);
160      sprintf(Finley_ErrorMsg,"Unidentified element type %s for points",element_type);      Finley_setError(VALUE_ERROR,error_msg);
161      return NULL;      return NULL;
162    }    }
163    mesh_p->Points=Finley_ElementFile_alloc(pointTypeID,mesh_p->order);    mesh_p->Points=Finley_ElementFile_alloc(pointTypeID,mesh_p->order);
# Line 173  Finley_Mesh* Finley_Mesh_read(char* fnam Line 187  Finley_Mesh* Finley_Mesh_read(char* fnam
187    /* rearrange elements: */    /* rearrange elements: */
188    
189    Finley_Mesh_prepare(mesh_p);    Finley_Mesh_prepare(mesh_p);
   printf ("nodes read!\n");  
190    
191    /* that's it */    /* that's it */
192    #ifdef Finley_TRACE    #ifdef Finley_TRACE
193    printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);    printf("timing: reading mesh: %.4e sec\n",Finley_timer()-time0);
194    #endif    #endif
195    if (Finley_ErrorCode!=NO_ERROR) Finley_Mesh_dealloc(mesh_p);    if (! Finley_noError()) Finley_Mesh_dealloc(mesh_p);
196    return mesh_p;    return mesh_p;
197  }  }
198  /*  /*
199  * $Log$  * $Log$
200    * Revision 1.5  2005/09/15 03:44:22  jgs
201    * Merge of development branch dev-02 back to main trunk on 2005-09-15
202    *
203  * Revision 1.4  2005/09/01 03:31:36  jgs  * Revision 1.4  2005/09/01 03:31:36  jgs
204  * Merge of development branch dev-02 back to main trunk on 2005-09-01  * Merge of development branch dev-02 back to main trunk on 2005-09-01
205  *  *
206    * Revision 1.3.2.3  2005/09/08 08:28:39  gross
207    * some cleanup in savevtk
208    *
209    * Revision 1.3.2.2  2005/09/07 06:26:19  gross
210    * the solver from finley are put into the standalone package paso now
211    *
212  * Revision 1.3.2.1  2005/08/24 02:02:18  gross  * Revision 1.3.2.1  2005/08/24 02:02:18  gross
213  * timing output switched off. solver output can be swiched through getSolution(verbose=True) now.  * timing output switched off. solver output can be swiched through getSolution(verbose=True) now.
214  *  *

Legend:
Removed from v.149  
changed lines
  Added in v.150

  ViewVC Help
Powered by ViewVC 1.1.26