/[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

temp/finley/src/Mesh_saveDX.c revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC branches/domexper/dudley/src/Mesh_saveDX.c revision 3090 by jfenwick, Wed Aug 11 00:51:28 2010 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2010 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15  /**************************************************************/  /**************************************************************/
16    
# Line 25  Line 24 
24    
25  /**************************************************************/  /**************************************************************/
26    
27  void Finley_Mesh_saveDX(const char * filename_p, Finley_Mesh *mesh_p, const dim_t num_data,char* *names_p,escriptDataC* *data_pp) {  void Dudley_Mesh_saveDX(const char * filename_p, Dudley_Mesh *mesh_p, const dim_t num_data,char* *names_p,escriptDataC* *data_pp) {
28    char error_msg[LenErrorMsg_MAX], elemTypeStr[32];    char error_msg[LenErrorMsg_MAX], elemTypeStr[32];
29    /* some tables needed for reordering */    /* some tables needed for reordering */
30    int resort[6][9]={    int resort[6][9]={
# Line 38  void Finley_Mesh_saveDX(const char * fil Line 37  void Finley_Mesh_saveDX(const char * fil
37    FILE * fileHandle_p = NULL;    FILE * fileHandle_p = NULL;
38    int i,j,k,i_data, elementtype, numPoints = 0, nDim, *resortIndex=NULL, p,    int i,j,k,i_data, elementtype, numPoints = 0, nDim, *resortIndex=NULL, p,
39        numDXNodesPerElement=0, numCells, NN, object_count, rank, nComp, numPointsPerSample;        numDXNodesPerElement=0, numCells, NN, object_count, rank, nComp, numPointsPerSample;
40    double* values,rtmp;    __const double* values;
41      double rtmp;
42    bool_t *isCellCentered=NULL;    bool_t *isCellCentered=NULL;
43    Finley_ElementFile* elements=NULL;    Dudley_ElementFile* elements=NULL;
44    ElementTypeId TypeId;    ElementTypeId TypeId;
45    /* open the file  and check handel */    /* open the file  and check handel */
46    
47    /* if there is no mesh we just return */    /* if there is no mesh we just return */
48    if (mesh_p==NULL) return;    if (mesh_p==NULL) return;
49    isCellCentered=MEMALLOC(num_data, bool_t);    isCellCentered=MEMALLOC(num_data, bool_t);
50    if (Finley_checkPtr(isCellCentered)) return;    if (Dudley_checkPtr(isCellCentered)) return;
51    
52    fileHandle_p = fopen(filename_p, "w");    fileHandle_p = fopen(filename_p, "w");
53    if (fileHandle_p==NULL) {    if (fileHandle_p==NULL) {
54      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);
55      MEMFREE(isCellCentered);      MEMFREE(isCellCentered);
56      fclose(fileHandle_p);      fclose(fileHandle_p);
57      Finley_setError(IO_ERROR,error_msg);      Dudley_setError(IO_ERROR,error_msg);
58      return;      return;
59    }    }
60    /* find the mesh type to be written */    /* find the mesh type to be written */
61    elementtype=FINLEY_UNKNOWN;    elementtype=DUDLEY_UNKNOWN;
62    for (i_data=0;i_data<num_data;++i_data) {    for (i_data=0;i_data<num_data;++i_data) {
63       if (! isEmpty(data_pp[i_data])) {       if (! isEmpty(data_pp[i_data])) {
64          switch(getFunctionSpaceType(data_pp[i_data])) {          switch(getFunctionSpaceType(data_pp[i_data])) {
65             case FINLEY_REDUCED_NODES:             case DUDLEY_REDUCED_NODES:
66               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {               if (elementtype==DUDLEY_UNKNOWN || elementtype==DUDLEY_ELEMENTS) {
67                   elementtype=FINLEY_ELEMENTS;                   elementtype=DUDLEY_ELEMENTS;
68               } else {               } else {
69                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");                   Dudley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");
70                   MEMFREE(isCellCentered);                   MEMFREE(isCellCentered);
71                   fclose(fileHandle_p);                   fclose(fileHandle_p);
72                   return;                   return;
73               }               }
74               isCellCentered[i_data]=FALSE;               isCellCentered[i_data]=FALSE;
75               break;               break;
76             case FINLEY_ELEMENTS:             case DUDLEY_ELEMENTS:
77             case FINLEY_REDUCED_ELEMENTS:             case DUDLEY_REDUCED_ELEMENTS:
78               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {               if (elementtype==DUDLEY_UNKNOWN || elementtype==DUDLEY_ELEMENTS) {
79                   elementtype=FINLEY_ELEMENTS;                   elementtype=DUDLEY_ELEMENTS;
              } else {  
                  Finley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");  
                  MEMFREE(isCellCentered);  
                  fclose(fileHandle_p);  
                  return;  
              }  
              isCellCentered[i_data]=TRUE;  
              break;  
            case FINLEY_FACE_ELEMENTS:  
            case FINLEY_REDUCED_FACE_ELEMENTS:  
              if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_FACE_ELEMENTS) {  
                  elementtype=FINLEY_FACE_ELEMENTS;  
              } else {  
                  Finley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");  
                  MEMFREE(isCellCentered);  
                  fclose(fileHandle_p);  
                  return;  
              }  
              isCellCentered[i_data]=TRUE;  
              break;  
            case FINLEY_POINTS:  
              if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_POINTS) {  
                  elementtype=FINLEY_POINTS;  
80               } else {               } else {
81                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");                   Dudley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");
82                   MEMFREE(isCellCentered);                   MEMFREE(isCellCentered);
83                   fclose(fileHandle_p);                   fclose(fileHandle_p);
84                   return;                   return;
85               }               }
86               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
87               break;               break;
88             case FINLEY_CONTACT_ELEMENTS_1:             case DUDLEY_FACE_ELEMENTS:
89             case FINLEY_REDUCED_CONTACT_ELEMENTS_1:             case DUDLEY_REDUCED_FACE_ELEMENTS:
90               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_CONTACT_ELEMENTS_1) {               if (elementtype==DUDLEY_UNKNOWN || elementtype==DUDLEY_FACE_ELEMENTS) {
91                   elementtype=FINLEY_CONTACT_ELEMENTS_1;                   elementtype=DUDLEY_FACE_ELEMENTS;
92               } else {               } else {
93                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");                   Dudley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");
94                   MEMFREE(isCellCentered);                   MEMFREE(isCellCentered);
95                   fclose(fileHandle_p);                   fclose(fileHandle_p);
96                   return;                   return;
97               }               }
98               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
99               break;               break;
100             case FINLEY_CONTACT_ELEMENTS_2:             case DUDLEY_POINTS:
101             case FINLEY_REDUCED_CONTACT_ELEMENTS_2:               if (elementtype==DUDLEY_UNKNOWN || elementtype==DUDLEY_POINTS) {
102               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_CONTACT_ELEMENTS_1) {                   elementtype=DUDLEY_POINTS;
                  elementtype=FINLEY_CONTACT_ELEMENTS_1;  
103               } else {               } else {
104                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");                   Dudley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");
105                   MEMFREE(isCellCentered);                   MEMFREE(isCellCentered);
106                   fclose(fileHandle_p);                   fclose(fileHandle_p);
107                   return;                   return;
# Line 134  void Finley_Mesh_saveDX(const char * fil Line 110  void Finley_Mesh_saveDX(const char * fil
110               break;               break;
111             default:             default:
112               sprintf(error_msg,"saveDX: I don't know how to handle function space type %d",getFunctionSpaceType(data_pp[i_data]));               sprintf(error_msg,"saveDX: I don't know how to handle function space type %d",getFunctionSpaceType(data_pp[i_data]));
113               Finley_setError(TYPE_ERROR,error_msg);               Dudley_setError(TYPE_ERROR,error_msg);
114               MEMFREE(isCellCentered);               MEMFREE(isCellCentered);
115               fclose(fileHandle_p);               fclose(fileHandle_p);
116               return;               return;
# Line 144  void Finley_Mesh_saveDX(const char * fil Line 120  void Finley_Mesh_saveDX(const char * fil
120    /* select number of points and the mesh component */    /* select number of points and the mesh component */
121    numPoints = mesh_p->Nodes->reducedNodesMapping->numTargets;    numPoints = mesh_p->Nodes->reducedNodesMapping->numTargets;
122    nDim = mesh_p->Nodes->numDim;    nDim = mesh_p->Nodes->numDim;
123    if (elementtype==FINLEY_UNKNOWN) elementtype=FINLEY_ELEMENTS;    if (elementtype==DUDLEY_UNKNOWN) elementtype=DUDLEY_ELEMENTS;
124    switch(elementtype) {    switch(elementtype) {
125      case FINLEY_ELEMENTS:      case DUDLEY_ELEMENTS:
126        elements=mesh_p->Elements;        elements=mesh_p->Elements;
127        break;        break;
128      case FINLEY_FACE_ELEMENTS:      case DUDLEY_FACE_ELEMENTS:
129        elements=mesh_p->FaceElements;        elements=mesh_p->FaceElements;
130        break;        break;
131      case FINLEY_POINTS:      case DUDLEY_POINTS:
132        elements=mesh_p->Points;        elements=mesh_p->Points;
133        break;        break;  }
     case FINLEY_CONTACT_ELEMENTS_2:  
       elements=mesh_p->ContactElements;  
       break;  
     case FINLEY_CONTACT_ELEMENTS_1:  
       elements=mesh_p->ContactElements;  
       break;  
   }  
134    if (elements==NULL) {    if (elements==NULL) {
135       Finley_setError(SYSTEM_ERROR,"saveDX: undefined element file");       Dudley_setError(SYSTEM_ERROR,"saveDX: undefined element file");
136       MEMFREE(isCellCentered);       MEMFREE(isCellCentered);
137       fclose(fileHandle_p);       fclose(fileHandle_p);
138       return;       return;
139    }    }
140    
141    /* map finley element type to DX element type */    /* map dudley element type to DX element type */
142    TypeId = elements->ReferenceElement->Type->TypeId;    TypeId = elements->referenceElementSet->referenceElement->Type->TypeId;
143    numDXNodesPerElement=0;    numDXNodesPerElement=0;
144    numCells = elements->numElements;    numCells = elements->numElements;
145    if (TypeId==Line2 || TypeId==Line3 || TypeId==Line4 ) {    if (TypeId==Line2 || TypeId==Line3 || TypeId==Line4 || TypeId==Line3Macro ) {
146       numDXNodesPerElement=2;       numDXNodesPerElement=2;
147       resortIndex=resort[0];       resortIndex=resort[0];
148       strcpy(elemTypeStr, "lines");       strcpy(elemTypeStr, "lines");
# Line 181  void Finley_Mesh_saveDX(const char * fil Line 150  void Finley_Mesh_saveDX(const char * fil
150       numDXNodesPerElement = 3;       numDXNodesPerElement = 3;
151       resortIndex=resort[1];       resortIndex=resort[1];
152       strcpy(elemTypeStr, "triangles");       strcpy(elemTypeStr, "triangles");
153     } else if (TypeId==Rec4 || TypeId==Rec8 || TypeId==Rec9 || TypeId==Rec12 || TypeId==Rec16 ) {     } else if (TypeId==Rec4 || TypeId==Rec8 || TypeId==Rec9 || TypeId==Rec12 || TypeId==Rec16 || TypeId==Rec9Macro ) {
154       numDXNodesPerElement = 4;       numDXNodesPerElement = 4;
155       resortIndex=resort[3];       resortIndex=resort[3];
156       strcpy(elemTypeStr, "quads");       strcpy(elemTypeStr, "quads");
157     } else if (TypeId==Tet4 || TypeId==Tet10 || TypeId==Tet16 ) {     } else if (TypeId==Tet4 || TypeId==Tet10 || TypeId==Tet16 || TypeId==Tet10Macro ) {
158       numDXNodesPerElement = 4;       numDXNodesPerElement = 4;
159       resortIndex=resort[2];       resortIndex=resort[2];
160       strcpy(elemTypeStr, "tetrahedra");       strcpy(elemTypeStr, "tetrahedra");
# Line 194  void Finley_Mesh_saveDX(const char * fil Line 163  void Finley_Mesh_saveDX(const char * fil
163       resortIndex=resort[4];       resortIndex=resort[4];
164       strcpy(elemTypeStr, "cubes");       strcpy(elemTypeStr, "cubes");
165     } else {     } else {
166       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->referenceElementSet->referenceElement->Type->Name);
167       Finley_setError(VALUE_ERROR,error_msg);       Dudley_setError(VALUE_ERROR,error_msg);
168       MEMFREE(isCellCentered);       MEMFREE(isCellCentered);
169       fclose(fileHandle_p);       fclose(fileHandle_p);
170       return;       return;
# Line 232  void Finley_Mesh_saveDX(const char * fil Line 201  void Finley_Mesh_saveDX(const char * fil
201              for (i = 0; i < rank; i++) fprintf(fileHandle_p, "%d ", getDataPointShape(data_pp[i_data],i));              for (i = 0; i < rank; i++) fprintf(fileHandle_p, "%d ", getDataPointShape(data_pp[i_data],i));
202           }           }
203           if (isCellCentered[i_data]) {           if (isCellCentered[i_data]) {
204               if (Finley_Assemble_reducedIntegrationOrder(data_pp[i_data])) {               if (Dudley_Assemble_reducedIntegrationOrder(data_pp[i_data])) {
205                  numPointsPerSample=elements->ReferenceElementReducedOrder->numQuadNodes;                  numPointsPerSample=elements->referenceElementSet->referenceElementReducedQuadrature->Parametrization->numQuadNodes;
206               } else {               } else {
207                  numPointsPerSample=elements->ReferenceElement->numQuadNodes;                  numPointsPerSample=elements->referenceElementSet->referenceElement->Parametrization->numQuadNodes;
208               }               }
209               if (numPointsPerSample>0) {               if (numPointsPerSample>0) {
210                  fprintf(fileHandle_p, "items %d data follows\n", numCells);                  fprintf(fileHandle_p, "items %d data follows\n", numCells);
211                  for (i=0;i<elements->numElements;i++) {                  for (i=0;i<elements->numElements;i++) {
212                      values=getSampleData(data_pp[i_data],i);                      values=getSampleDataRO(data_pp[i_data],i);
213                      for (k=0;k<nComp;k++) {                      for (k=0;k<nComp;k++) {
214                          if ( isExpanded(data_pp[i_data]) ) {                          if ( isExpanded(data_pp[i_data]) ) {
215                              rtmp=0.;                              rtmp=0.;
# Line 257  void Finley_Mesh_saveDX(const char * fil Line 226  void Finley_Mesh_saveDX(const char * fil
226           } else {           } else {
227               fprintf(fileHandle_p, "items %d data follows\n", numPoints);               fprintf(fileHandle_p, "items %d data follows\n", numPoints);
228               for (i=0;i<numPoints;i++) {               for (i=0;i<numPoints;i++) {
229                     values=getSampleData(data_pp[i_data],i);                     values=getSampleDataRO(data_pp[i_data],i);
230                     for (k=0;k<nComp;k++) fprintf(fileHandle_p, " %g", values[k]);                     for (k=0;k<nComp;k++) fprintf(fileHandle_p, " %g", values[k]);
231                 fprintf(fileHandle_p, "\n");                 fprintf(fileHandle_p, "\n");
232               }               }

Legend:
Removed from v.1387  
changed lines
  Added in v.3090

  ViewVC Help
Powered by ViewVC 1.1.26