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

trunk/finley/src/Mesh_saveDX.c revision 1028 by gross, Wed Mar 14 00:15:24 2007 UTC temp/finley/src/Mesh_saveDX.c revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC
# Line 1  Line 1 
 /*  
  ************************************************************  
  *          Copyright 2006 by ACcESS MNRF                   *  
  *                                                          *  
  *              http://www.access.edu.au                    *  
  *       Primary Business: Queensland, Australia            *  
  *  Licensed under the Open Software License version 3.0    *  
  *     http://www.opensource.org/licenses/osl-3.0.php       *  
  *                                                          *  
  ************************************************************  
 */  
1    
2    /* $Id$ */
3    
4  /**************************************************************/  /*******************************************************
5     *
6  /*   writes data and mesh in an opendx file */   *           Copyright 2003-2007 by ACceSS MNRF
7     *       Copyright 2007 by University of Queensland
8     *
9     *                http://esscc.uq.edu.au
10     *        Primary Business: Queensland, Australia
11     *  Licensed under the Open Software License version 3.0
12     *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  /**************************************************************/  /**************************************************************/
17    
18  /*   Author: Lutz Gross, gross@access.edu.au */  /*   writes data and mesh in an opendx file                      */
19  /*   Version: $Id$ */  /*   the input data needs to be cell centered or on reducedNodes */
20    
21  /**************************************************************/  /**************************************************************/
22    
23  #include "Mesh.h"  #include "Mesh.h"
24    #include "Assemble.h"
25    
26  /**************************************************************/  /**************************************************************/
27    
# Line 37  void Finley_Mesh_saveDX(const char * fil Line 36  void Finley_Mesh_saveDX(const char * fil
36                      {3,0,7,4,2,1,6,5}, /* hexahedron */                      {3,0,7,4,2,1,6,5}, /* hexahedron */
37                     };                     };
38    FILE * fileHandle_p = NULL;    FILE * fileHandle_p = NULL;
39    int i,j,k,i_data, nodetype, elementtype, numPoints = 0, nDim, *resortIndex=NULL,    int i,j,k,i_data, elementtype, numPoints = 0, nDim, *resortIndex=NULL, p,
40        numDXNodesPerElement=0, numCells, NN, object_count, rank, nComp;        numDXNodesPerElement=0, numCells, NN, object_count, rank, nComp, numPointsPerSample;
41    double* values,rtmp;    double* values,rtmp;
42    bool_t *isCellCentered=NULL;    bool_t *isCellCentered=NULL;
43    Finley_ElementFile* elements=NULL;    Finley_ElementFile* elements=NULL;
# Line 59  void Finley_Mesh_saveDX(const char * fil Line 58  void Finley_Mesh_saveDX(const char * fil
58      return;      return;
59    }    }
60    /* find the mesh type to be written */    /* find the mesh type to be written */
   nodetype=FINLEY_DEGREES_OF_FREEDOM;  
61    elementtype=FINLEY_UNKNOWN;    elementtype=FINLEY_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_DEGREES_OF_FREEDOM:             case FINLEY_REDUCED_NODES:
              nodetype = (nodetype == FINLEY_REDUCED_DEGREES_OF_FREEDOM) ? FINLEY_REDUCED_DEGREES_OF_FREEDOM : FINLEY_DEGREES_OF_FREEDOM;  
              if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {  
                  elementtype=FINLEY_ELEMENTS;  
              } else {  
                  Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");  
                  MEMFREE(isCellCentered);  
                  fclose(fileHandle_p);  
                  return;  
              }  
              isCellCentered[i_data]=FALSE;  
              break;  
            case FINLEY_REDUCED_DEGREES_OF_FREEDOM:  
              nodetype = FINLEY_REDUCED_DEGREES_OF_FREEDOM;  
66               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {
67                   elementtype=FINLEY_ELEMENTS;                   elementtype=FINLEY_ELEMENTS;
68               } else {               } else {
69                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");
                  MEMFREE(isCellCentered);  
                  fclose(fileHandle_p);  
                  return;  
              }  
              isCellCentered[i_data]=FALSE;  
              break;  
            case FINLEY_NODES:  
              nodetype = (nodetype == FINLEY_REDUCED_DEGREES_OF_FREEDOM) ? FINLEY_REDUCED_DEGREES_OF_FREEDOM : FINLEY_DEGREES_OF_FREEDOM;  
              if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {  
                  elementtype=FINLEY_ELEMENTS;  
              } else {  
                  Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");  
70                   MEMFREE(isCellCentered);                   MEMFREE(isCellCentered);
71                   fclose(fileHandle_p);                   fclose(fileHandle_p);
72                   return;                   return;
# Line 101  void Finley_Mesh_saveDX(const char * fil Line 74  void Finley_Mesh_saveDX(const char * fil
74               isCellCentered[i_data]=FALSE;               isCellCentered[i_data]=FALSE;
75               break;               break;
76             case FINLEY_ELEMENTS:             case FINLEY_ELEMENTS:
77               nodetype = (nodetype == FINLEY_REDUCED_DEGREES_OF_FREEDOM) ? FINLEY_REDUCED_DEGREES_OF_FREEDOM : FINLEY_DEGREES_OF_FREEDOM;             case FINLEY_REDUCED_ELEMENTS:
78               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_ELEMENTS) {
79                   elementtype=FINLEY_ELEMENTS;                   elementtype=FINLEY_ELEMENTS;
80               } else {               } else {
81                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_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;
# Line 113  void Finley_Mesh_saveDX(const char * fil Line 86  void Finley_Mesh_saveDX(const char * fil
86               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
87               break;               break;
88             case FINLEY_FACE_ELEMENTS:             case FINLEY_FACE_ELEMENTS:
89               nodetype = (nodetype == FINLEY_REDUCED_DEGREES_OF_FREEDOM) ? FINLEY_REDUCED_DEGREES_OF_FREEDOM : FINLEY_DEGREES_OF_FREEDOM;             case FINLEY_REDUCED_FACE_ELEMENTS:
90               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_FACE_ELEMENTS) {               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_FACE_ELEMENTS) {
91                   elementtype=FINLEY_FACE_ELEMENTS;                   elementtype=FINLEY_FACE_ELEMENTS;
92               } else {               } else {
93                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_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;
# Line 125  void Finley_Mesh_saveDX(const char * fil Line 98  void Finley_Mesh_saveDX(const char * fil
98               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
99               break;               break;
100             case FINLEY_POINTS:             case FINLEY_POINTS:
              nodetype = (nodetype == FINLEY_REDUCED_DEGREES_OF_FREEDOM) ? FINLEY_REDUCED_DEGREES_OF_FREEDOM : FINLEY_DEGREES_OF_FREEDOM;  
101               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_POINTS) {               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_POINTS) {
102                   elementtype=FINLEY_POINTS;                   elementtype=FINLEY_POINTS;
103               } else {               } else {
104                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_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 137  void Finley_Mesh_saveDX(const char * fil Line 109  void Finley_Mesh_saveDX(const char * fil
109               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
110               break;               break;
111             case FINLEY_CONTACT_ELEMENTS_1:             case FINLEY_CONTACT_ELEMENTS_1:
112               nodetype = (nodetype == FINLEY_REDUCED_DEGREES_OF_FREEDOM) ? FINLEY_REDUCED_DEGREES_OF_FREEDOM : FINLEY_DEGREES_OF_FREEDOM;             case FINLEY_REDUCED_CONTACT_ELEMENTS_1:
113               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_CONTACT_ELEMENTS_1) {               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_CONTACT_ELEMENTS_1) {
114                   elementtype=FINLEY_CONTACT_ELEMENTS_1;                   elementtype=FINLEY_CONTACT_ELEMENTS_1;
115               } else {               } else {
116                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");
117                   MEMFREE(isCellCentered);                   MEMFREE(isCellCentered);
118                   fclose(fileHandle_p);                   fclose(fileHandle_p);
119                   return;                   return;
# Line 149  void Finley_Mesh_saveDX(const char * fil Line 121  void Finley_Mesh_saveDX(const char * fil
121               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
122               break;               break;
123             case FINLEY_CONTACT_ELEMENTS_2:             case FINLEY_CONTACT_ELEMENTS_2:
124               nodetype = (nodetype == FINLEY_REDUCED_DEGREES_OF_FREEDOM) ? FINLEY_REDUCED_DEGREES_OF_FREEDOM : FINLEY_DEGREES_OF_FREEDOM;             case FINLEY_REDUCED_CONTACT_ELEMENTS_2:
125               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_CONTACT_ELEMENTS_1) {               if (elementtype==FINLEY_UNKNOWN || elementtype==FINLEY_CONTACT_ELEMENTS_1) {
126                   elementtype=FINLEY_CONTACT_ELEMENTS_1;                   elementtype=FINLEY_CONTACT_ELEMENTS_1;
127               } else {               } else {
128                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data in single file.");                   Finley_setError(TYPE_ERROR,"saveDX: cannot write given data into single file.");
129                   MEMFREE(isCellCentered);                   MEMFREE(isCellCentered);
130                   fclose(fileHandle_p);                   fclose(fileHandle_p);
131                   return;                   return;
# Line 161  void Finley_Mesh_saveDX(const char * fil Line 133  void Finley_Mesh_saveDX(const char * fil
133               isCellCentered[i_data]=TRUE;               isCellCentered[i_data]=TRUE;
134               break;               break;
135             default:             default:
136               sprintf(error_msg,"saveDX: Finley does not know anything about 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]));
137               Finley_setError(TYPE_ERROR,error_msg);               Finley_setError(TYPE_ERROR,error_msg);
138               MEMFREE(isCellCentered);               MEMFREE(isCellCentered);
139               fclose(fileHandle_p);               fclose(fileHandle_p);
# Line 170  void Finley_Mesh_saveDX(const char * fil Line 142  void Finley_Mesh_saveDX(const char * fil
142       }       }
143    }    }
144    /* select number of points and the mesh component */    /* select number of points and the mesh component */
145    numPoints = mesh_p->Nodes->numNodes;    numPoints = mesh_p->Nodes->reducedNodesMapping->numTargets;
146    nDim = mesh_p->Nodes->numDim;    nDim = mesh_p->Nodes->numDim;
   if (nodetype==FINLEY_REDUCED_DEGREES_OF_FREEDOM) {  
        numPoints = mesh_p->Nodes->reducedNumNodes;  
   } else {  
        numPoints = mesh_p->Nodes->numNodes;  
   }  
147    if (elementtype==FINLEY_UNKNOWN) elementtype=FINLEY_ELEMENTS;    if (elementtype==FINLEY_UNKNOWN) elementtype=FINLEY_ELEMENTS;
148    switch(elementtype) {    switch(elementtype) {
149      case FINLEY_ELEMENTS:      case FINLEY_ELEMENTS:
# Line 188  void Finley_Mesh_saveDX(const char * fil Line 155  void Finley_Mesh_saveDX(const char * fil
155      case FINLEY_POINTS:      case FINLEY_POINTS:
156        elements=mesh_p->Points;        elements=mesh_p->Points;
157        break;        break;
158        case FINLEY_CONTACT_ELEMENTS_2:
159          elements=mesh_p->ContactElements;
160          break;
161      case FINLEY_CONTACT_ELEMENTS_1:      case FINLEY_CONTACT_ELEMENTS_1:
162        elements=mesh_p->ContactElements;        elements=mesh_p->ContactElements;
163        break;        break;
# Line 232  void Finley_Mesh_saveDX(const char * fil Line 202  void Finley_Mesh_saveDX(const char * fil
202     }     }
203    
204    /* positions */    /* positions */
205    fprintf(fileHandle_p, "object 1 class array type float rank 1 shape %d items %d data follows\n",nDim, mesh_p->Nodes->reducedNumNodes);    fprintf(fileHandle_p, "object 1 class array type float rank 1 shape %d items %d data follows\n",nDim, numPoints);
206    for (i = 0; i < mesh_p->Nodes->numNodes; i++) {    for (i = 0; i < numPoints; i++) {
207      if (mesh_p->Nodes->toReduced[i]>=0) {         p=mesh_p->Nodes->reducedNodesMapping->map[i];
208         for (j = 0; j < nDim; j++) fprintf(fileHandle_p, " %g",mesh_p->Nodes->Coordinates[INDEX2(j, i, nDim)]);         for (j = 0; j < nDim; j++) fprintf(fileHandle_p, " %g",mesh_p->Nodes->Coordinates[INDEX2(j, p, nDim)]);
209         fprintf(fileHandle_p, "\n");         fprintf(fileHandle_p, "\n");
     }  
210    }    }
211    /* connection table */    /* connection table */
212    NN=elements->ReferenceElement->Type->numNodes;    NN=elements->numNodes;
213    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);
214    for (i = 0; i < numCells; i++) {    for (i = 0; i < numCells; i++) {
215        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++)
216                fprintf(fileHandle_p," %d",mesh_p->Nodes->reducedNodesMapping->target[elements->Nodes[INDEX2(resortIndex[j], i, NN)]]);
217        fprintf(fileHandle_p, "\n");        fprintf(fileHandle_p, "\n");
218    }    }
219    fprintf(fileHandle_p, "attribute \"element type\" string \"%s\"\n",elemTypeStr);    fprintf(fileHandle_p, "attribute \"element type\" string \"%s\"\n",elemTypeStr);
# Line 262  void Finley_Mesh_saveDX(const char * fil Line 232  void Finley_Mesh_saveDX(const char * fil
232              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));
233           }           }
234           if (isCellCentered[i_data]) {           if (isCellCentered[i_data]) {
235               int numPointsPerSample=elements->ReferenceElement->numQuadNodes;               if (Finley_Assemble_reducedIntegrationOrder(data_pp[i_data])) {
236                    numPointsPerSample=elements->ReferenceElementReducedOrder->numQuadNodes;
237                 } else {
238                    numPointsPerSample=elements->ReferenceElement->numQuadNodes;
239                 }
240               if (numPointsPerSample>0) {               if (numPointsPerSample>0) {
241                  fprintf(fileHandle_p, "items %d data follows\n", numCells);                  fprintf(fileHandle_p, "items %d data follows\n", numCells);
242                  for (i=0;i<elements->numElements;i++) {                  for (i=0;i<elements->numElements;i++) {
# Line 281  void Finley_Mesh_saveDX(const char * fil Line 255  void Finley_Mesh_saveDX(const char * fil
255                  fprintf(fileHandle_p, "attribute \"dep\" string \"connections\"\n");                  fprintf(fileHandle_p, "attribute \"dep\" string \"connections\"\n");
256              }              }
257           } else {           } else {
258               fprintf(fileHandle_p, "items %d data follows\n", mesh_p->Nodes->reducedNumNodes);               fprintf(fileHandle_p, "items %d data follows\n", numPoints);
259               for (i=0;i<mesh_p->Nodes->numNodes;i++) {               for (i=0;i<numPoints;i++) {
260                   if (mesh_p->Nodes->toReduced[i]>=0) {                     values=getSampleData(data_pp[i_data],i);
261                      switch (getFunctionSpaceType(data_pp[i_data])) {                     for (k=0;k<nComp;k++) fprintf(fileHandle_p, " %g", values[k]);
262                         case FINLEY_DEGREES_OF_FREEDOM:                 fprintf(fileHandle_p, "\n");
                           values=getSampleData(data_pp[i_data],mesh_p->Nodes->degreeOfFreedom[i]);  
                           break;  
                        case FINLEY_REDUCED_DEGREES_OF_FREEDOM:  
                           values=getSampleData(data_pp[i_data],mesh_p->Nodes->reducedDegreeOfFreedom[i]);  
                           break;  
                        case FINLEY_NODES:  
                           values=getSampleData(data_pp[i_data],i);  
                           break;  
                     }  
                     for (k=0;k<nComp;k++) fprintf(fileHandle_p, " %g", values[k]);  
                 fprintf(fileHandle_p, "\n");  
                  }  
263               }               }
264               fprintf(fileHandle_p, "attribute \"dep\" string \"positions\"\n");               fprintf(fileHandle_p, "attribute \"dep\" string \"positions\"\n");
265           }           }

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

  ViewVC Help
Powered by ViewVC 1.1.26