/[escript]/trunk/dudley/src/Mesh_saveDX.c
ViewVC logotype

Diff of /trunk/dudley/src/Mesh_saveDX.c

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

revision 903 by gross, Fri Nov 17 01:59:49 2006 UTC revision 1028 by gross, Wed Mar 14 00:15:24 2007 UTC
# Line 27  Line 27 
27  /**************************************************************/  /**************************************************************/
28    
29  void Finley_Mesh_saveDX(const char * filename_p, Finley_Mesh *mesh_p, const dim_t num_data,char* *names_p,escriptDataC* *data_pp) {  void Finley_Mesh_saveDX(const char * filename_p, Finley_Mesh *mesh_p, const dim_t num_data,char* *names_p,escriptDataC* *data_pp) {
30    char error_msg[LenErrorMsg_MAX];    char error_msg[LenErrorMsg_MAX], elemTypeStr[32];
   /* if there is no mesh we just return */  
   if (mesh_p==NULL) return;  
   
31    /* some tables needed for reordering */    /* some tables needed for reordering */
32    int resort[6][9]={    int resort[6][9]={
33                      {0,1},   /* line */                      {0,1},   /* line */
# Line 39  void Finley_Mesh_saveDX(const char * fil Line 36  void Finley_Mesh_saveDX(const char * fil
36                      {0,3,1,2}, /* quadrilateral */                      {0,3,1,2}, /* quadrilateral */
37                      {3,0,7,4,2,1,6,5}, /* hexahedron */                      {3,0,7,4,2,1,6,5}, /* hexahedron */
38                     };                     };
39    int i,j,k,i_data;    FILE * fileHandle_p = NULL;
40      int i,j,k,i_data, nodetype, elementtype, numPoints = 0, nDim, *resortIndex=NULL,
41          numDXNodesPerElement=0, numCells, NN, object_count, rank, nComp;
42      double* values,rtmp;
43      bool_t *isCellCentered=NULL;
44      Finley_ElementFile* elements=NULL;
45      ElementTypeId TypeId;
46    /* open the file  and check handel */    /* open the file  and check handel */
47    
48    FILE * fileHandle_p = fopen(filename_p, "w");    /* if there is no mesh we just return */
49      if (mesh_p==NULL) return;
50      isCellCentered=MEMALLOC(num_data, bool_t);
51      if (Finley_checkPtr(isCellCentered)) return;
52    
53      fileHandle_p = fopen(filename_p, "w");
54    if (fileHandle_p==NULL) {    if (fileHandle_p==NULL) {
55      sprintf(error_msg,"File %s could not be opened for writing.",filename_p);      sprintf(error_msg,"File %s could not be opened for writing.",filename_p);
56        MEMFREE(isCellCentered);
57        fclose(fileHandle_p);
58      Finley_setError(IO_ERROR,error_msg);      Finley_setError(IO_ERROR,error_msg);
59      return;      return;
60    }    }
61    /* find the mesh type to be written */    /* find the mesh type to be written */
62    int nodetype=FINLEY_DEGREES_OF_FREEDOM;    nodetype=FINLEY_DEGREES_OF_FREEDOM;
63    int elementtype=FINLEY_UNKNOWN;    elementtype=FINLEY_UNKNOWN;
   bool_t isCellCentered[num_data];  
64    for (i_data=0;i_data<num_data;++i_data) {    for (i_data=0;i_data<num_data;++i_data) {
65       if (! isEmpty(data_pp[i_data])) {       if (! isEmpty(data_pp[i_data])) {
66          switch(getFunctionSpaceType(data_pp[i_data])) {          switch(getFunctionSpaceType(data_pp[i_data])) {
# Line 61  void Finley_Mesh_saveDX(const char * fil Line 70  void Finley_Mesh_saveDX(const char * fil
70                   elementtype=FINLEY_ELEMENTS;                   elementtype=FINLEY_ELEMENTS;
71               } else {               } else {
72                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");
73                     MEMFREE(isCellCentered);
74                     fclose(fileHandle_p);
75                   return;                   return;
76               }               }
77               isCellCentered[i_data]=FALSE;               isCellCentered[i_data]=FALSE;
# Line 71  void Finley_Mesh_saveDX(const char * fil Line 82  void Finley_Mesh_saveDX(const char * fil
82                   elementtype=FINLEY_ELEMENTS;                   elementtype=FINLEY_ELEMENTS;
83               } else {               } else {
84                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");
85                     MEMFREE(isCellCentered);
86                     fclose(fileHandle_p);
87                   return;                   return;
88               }               }
89               isCellCentered[i_data]=FALSE;               isCellCentered[i_data]=FALSE;
# Line 81  void Finley_Mesh_saveDX(const char * fil Line 94  void Finley_Mesh_saveDX(const char * fil
94                   elementtype=FINLEY_ELEMENTS;                   elementtype=FINLEY_ELEMENTS;
95               } else {               } else {
96                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");
97                     MEMFREE(isCellCentered);
98                     fclose(fileHandle_p);
99                   return;                   return;
100               }               }
101               isCellCentered[i_data]=FALSE;               isCellCentered[i_data]=FALSE;
# Line 91  void Finley_Mesh_saveDX(const char * fil Line 106  void Finley_Mesh_saveDX(const char * fil
106                   elementtype=FINLEY_ELEMENTS;                   elementtype=FINLEY_ELEMENTS;
107               } else {               } else {
108                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");
109                     MEMFREE(isCellCentered);
110                     fclose(fileHandle_p);
111                   return;                   return;
112               }               }
113               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
# Line 101  void Finley_Mesh_saveDX(const char * fil Line 118  void Finley_Mesh_saveDX(const char * fil
118                   elementtype=FINLEY_FACE_ELEMENTS;                   elementtype=FINLEY_FACE_ELEMENTS;
119               } else {               } else {
120                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");
121                     MEMFREE(isCellCentered);
122                     fclose(fileHandle_p);
123                   return;                   return;
124               }               }
125               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
# Line 111  void Finley_Mesh_saveDX(const char * fil Line 130  void Finley_Mesh_saveDX(const char * fil
130                   elementtype=FINLEY_POINTS;                   elementtype=FINLEY_POINTS;
131               } else {               } else {
132                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");
133                     MEMFREE(isCellCentered);
134                     fclose(fileHandle_p);
135                   return;                   return;
136               }               }
137               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
# Line 121  void Finley_Mesh_saveDX(const char * fil Line 142  void Finley_Mesh_saveDX(const char * fil
142                   elementtype=FINLEY_CONTACT_ELEMENTS_1;                   elementtype=FINLEY_CONTACT_ELEMENTS_1;
143               } else {               } else {
144                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");
145                     MEMFREE(isCellCentered);
146                     fclose(fileHandle_p);
147                   return;                   return;
148               }               }
149               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
# Line 131  void Finley_Mesh_saveDX(const char * fil Line 154  void Finley_Mesh_saveDX(const char * fil
154                   elementtype=FINLEY_CONTACT_ELEMENTS_1;                   elementtype=FINLEY_CONTACT_ELEMENTS_1;
155               } else {               } else {
156                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");
157                     MEMFREE(isCellCentered);
158                     fclose(fileHandle_p);
159                   return;                   return;
160               }               }
161               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
# Line 138  void Finley_Mesh_saveDX(const char * fil Line 163  void Finley_Mesh_saveDX(const char * fil
163             default:             default:
164               sprintf(error_msg,"saveDX: Finley does not know anything about function space type %d",getFunctionSpaceType(data_pp[i_data]));               sprintf(error_msg,"saveDX: Finley does not know anything about function space type %d",getFunctionSpaceType(data_pp[i_data]));
165               Finley_setError(TYPE_ERROR,error_msg);               Finley_setError(TYPE_ERROR,error_msg);
166                 MEMFREE(isCellCentered);
167                 fclose(fileHandle_p);
168               return;               return;
169          }          }
170       }       }
171    }    }
172    /* select number of points and the mesh component */    /* select number of points and the mesh component */
173    int numPoints = mesh_p->Nodes->numNodes;    numPoints = mesh_p->Nodes->numNodes;
174    int nDim = mesh_p->Nodes->numDim;    nDim = mesh_p->Nodes->numDim;
175    if (nodetype==FINLEY_REDUCED_DEGREES_OF_FREEDOM) {    if (nodetype==FINLEY_REDUCED_DEGREES_OF_FREEDOM) {
176         numPoints = mesh_p->Nodes->reducedNumNodes;         numPoints = mesh_p->Nodes->reducedNumNodes;
177    } else {    } else {
178         numPoints = mesh_p->Nodes->numNodes;         numPoints = mesh_p->Nodes->numNodes;
179    }    }
180    if (elementtype==FINLEY_UNKNOWN) elementtype=FINLEY_ELEMENTS;    if (elementtype==FINLEY_UNKNOWN) elementtype=FINLEY_ELEMENTS;
   Finley_ElementFile* elements=NULL;  
181    switch(elementtype) {    switch(elementtype) {
182      case FINLEY_ELEMENTS:      case FINLEY_ELEMENTS:
183        elements=mesh_p->Elements;        elements=mesh_p->Elements;
# Line 168  void Finley_Mesh_saveDX(const char * fil Line 194  void Finley_Mesh_saveDX(const char * fil
194    }    }
195    if (elements==NULL) {    if (elements==NULL) {
196       Finley_setError(SYSTEM_ERROR,"saveDX: undefined element file");       Finley_setError(SYSTEM_ERROR,"saveDX: undefined element file");
197         MEMFREE(isCellCentered);
198         fclose(fileHandle_p);
199       return;       return;
200    }    }
201    
202    /* map finley element type to DX element type */    /* map finley element type to DX element type */
203    ElementTypeId TypeId = elements->ReferenceElement->Type->TypeId;    TypeId = elements->ReferenceElement->Type->TypeId;
204    int *resortIndex=NULL;    numDXNodesPerElement=0;
205    int numDXNodesPerElement=0;    numCells = elements->numElements;
   int numCells = elements->numElements;  
   char elemTypeStr[32];  
206    if (TypeId==Line2 || TypeId==Line3 || TypeId==Line4 ) {    if (TypeId==Line2 || TypeId==Line3 || TypeId==Line4 ) {
207       numDXNodesPerElement=2;       numDXNodesPerElement=2;
208       resortIndex=resort[0];       resortIndex=resort[0];
# Line 200  void Finley_Mesh_saveDX(const char * fil Line 226  void Finley_Mesh_saveDX(const char * fil
226     } else {     } else {
227       sprintf(error_msg,"saveDX: Element type %s is not supported by DX",elements->ReferenceElement->Type->Name);       sprintf(error_msg,"saveDX: Element type %s is not supported by DX",elements->ReferenceElement->Type->Name);
228       Finley_setError(VALUE_ERROR,error_msg);       Finley_setError(VALUE_ERROR,error_msg);
229         MEMFREE(isCellCentered);
230         fclose(fileHandle_p);
231       return;       return;
232     }     }
233    
# Line 212  void Finley_Mesh_saveDX(const char * fil Line 240  void Finley_Mesh_saveDX(const char * fil
240      }      }
241    }    }
242    /* connection table */    /* connection table */
243    int NN=elements->ReferenceElement->Type->numNodes;    NN=elements->ReferenceElement->Type->numNodes;
244    fprintf(fileHandle_p, "object 2 class array type int rank 1 shape %d items %d data follows\n",numDXNodesPerElement, numCells);    fprintf(fileHandle_p, "object 2 class array type int rank 1 shape %d items %d data follows\n",numDXNodesPerElement, numCells);
245    for (i = 0; i < numCells; i++) {    for (i = 0; i < numCells; i++) {
246        for (j = 0; j < numDXNodesPerElement; j++) fprintf(fileHandle_p," %d",mesh_p->Nodes->toReduced[elements->Nodes[INDEX2(resortIndex[j], i, NN)]]);        for (j = 0; j < numDXNodesPerElement; j++) fprintf(fileHandle_p," %d",mesh_p->Nodes->toReduced[elements->Nodes[INDEX2(resortIndex[j], i, NN)]]);
# Line 222  void Finley_Mesh_saveDX(const char * fil Line 250  void Finley_Mesh_saveDX(const char * fil
250    fprintf(fileHandle_p, "attribute \"ref\" string \"positions\"\n");    fprintf(fileHandle_p, "attribute \"ref\" string \"positions\"\n");
251    
252    /* data */    /* data */
253    int object_count=2;    object_count=2;
254    for (i_data =0 ;i_data<num_data;++i_data) {    for (i_data =0 ;i_data<num_data;++i_data) {
255        if (! isEmpty(data_pp[i_data])) {        if (! isEmpty(data_pp[i_data])) {
256           object_count++;           object_count++;
257           int rank=getDataPointRank(data_pp[i_data]);           rank=getDataPointRank(data_pp[i_data]);
258           int nComp=getDataPointSize(data_pp[i_data]);           nComp=getDataPointSize(data_pp[i_data]);
          double* values,rtmp;  
259           fprintf(fileHandle_p, "object %d class array type float rank %d ",object_count,rank);           fprintf(fileHandle_p, "object %d class array type float rank %d ",object_count,rank);
260           if (0 < rank) {           if (0 < rank) {
261              fprintf(fileHandle_p, "shape ");              fprintf(fileHandle_p, "shape ");
# Line 297  void Finley_Mesh_saveDX(const char * fil Line 324  void Finley_Mesh_saveDX(const char * fil
324    fprintf(fileHandle_p, "end\n");    fprintf(fileHandle_p, "end\n");
325    /* close the file */    /* close the file */
326    fclose(fileHandle_p);    fclose(fileHandle_p);
327      MEMFREE(isCellCentered);
328    return;    return;
329  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26