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

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

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

revision 1027 by gross, Fri Nov 17 01:59:49 2006 UTC revision 1028 by gross, Wed Mar 14 00:15:24 2007 UTC
# Line 1203  void Finley_Mesh_saveVTK_MPIO(const char Line 1203  void Finley_Mesh_saveVTK_MPIO(const char
1203    
1204  void Finley_Mesh_saveVTK(const char * filename_p, Finley_Mesh *mesh_p, const dim_t num_data,char* *names_p, escriptDataC* *data_pp)  void Finley_Mesh_saveVTK(const char * filename_p, Finley_Mesh *mesh_p, const dim_t num_data,char* *names_p, escriptDataC* *data_pp)
1205  {  {
1206      #define NCOMP_MAX 9
1207    char error_msg[LenErrorMsg_MAX];    char error_msg[LenErrorMsg_MAX];
1208      double sampleAvg[NCOMP_MAX];
1209    /* if there is no mesh we just return */    /* if there is no mesh we just return */
   if (mesh_p==NULL) return;  
1210    
1211    int i, j, k, numVTKNodesPerElement,i_data,m, count, n, rank,shape, numPoints, cellType, numCells,    int i, j, k, numVTKNodesPerElement,i_data,m, count, n, rank,shape, numPoints, cellType, numCells,
1212    nDim, numPointsPerSample, nComp, nCompReqd;    nDim, numPointsPerSample, nComp, nCompReqd, NN;
   
1213    index_t j2;    index_t j2;
1214      int nodetype=FINLEY_DEGREES_OF_FREEDOM;
1215      int elementtype=FINLEY_UNKNOWN;
1216    double* values, rtmp;    double* values, rtmp;
1217    char elemTypeStr[32];    char elemTypeStr[32];
1218      FILE * fileHandle_p = NULL;
1219      bool_t do_write, *isCellCentered=NULL,write_celldata=FALSE,write_pointdata=FALSE;
1220      Finley_ElementFile* elements=NULL;
1221      ElementTypeId TypeId;
1222    
1223    printf("ddsafddfdafdf\n");
1224    /* open the file and check handle */    /* open the file and check handle */
1225      if (mesh_p==NULL) return;
1226    
1227    FILE * fileHandle_p = fopen(filename_p, "w");    fileHandle_p = fopen(filename_p, "w");
1228    if (fileHandle_p==NULL)    if (fileHandle_p==NULL)
1229    {    {
1230      sprintf(error_msg, "saveVTK: File %s could not be opened for writing.", filename_p);      sprintf(error_msg, "saveVTK: File %s could not be opened for writing.", filename_p);
# Line 1224  void Finley_Mesh_saveVTK(const char * fi Line 1232  void Finley_Mesh_saveVTK(const char * fi
1232      return;      return;
1233    }    }
1234    /* find the mesh type to be written */    /* find the mesh type to be written */
1235    int nodetype=FINLEY_DEGREES_OF_FREEDOM;    isCellCentered=TMPMEMALLOC(num_data,bool_t);
1236    int elementtype=FINLEY_UNKNOWN;  
1237    bool_t isCellCentered[num_data],write_celldata=FALSE,write_pointdata=FALSE;  
1238      if (Finley_checkPtr(isCellCentered)) {
1239         fclose(fileHandle_p);
1240         return;
1241      }
1242    for (i_data=0;i_data<num_data;++i_data)    for (i_data=0;i_data<num_data;++i_data)
1243    {    {
1244      if (! isEmpty(data_pp[i_data]))      if (! isEmpty(data_pp[i_data]))
# Line 1243  void Finley_Mesh_saveVTK(const char * fi Line 1255  void Finley_Mesh_saveVTK(const char * fi
1255          {          {
1256            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
1257            fclose(fileHandle_p);            fclose(fileHandle_p);
1258              TMPMEMFREE(isCellCentered);
1259            return;            return;
1260          }          }
1261          isCellCentered[i_data]=FALSE;          isCellCentered[i_data]=FALSE;
# Line 1257  void Finley_Mesh_saveVTK(const char * fi Line 1270  void Finley_Mesh_saveVTK(const char * fi
1270          {          {
1271            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
1272            fclose(fileHandle_p);            fclose(fileHandle_p);
1273              TMPMEMFREE(isCellCentered);
1274            return;            return;
1275          }          }
1276          isCellCentered[i_data]=FALSE;          isCellCentered[i_data]=FALSE;
# Line 1271  void Finley_Mesh_saveVTK(const char * fi Line 1285  void Finley_Mesh_saveVTK(const char * fi
1285          {          {
1286            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
1287            fclose(fileHandle_p);            fclose(fileHandle_p);
1288              TMPMEMFREE(isCellCentered);
1289            return;            return;
1290          }          }
1291          isCellCentered[i_data]=FALSE;          isCellCentered[i_data]=FALSE;
# Line 1286  void Finley_Mesh_saveVTK(const char * fi Line 1301  void Finley_Mesh_saveVTK(const char * fi
1301            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
1302            fclose(fileHandle_p);            fclose(fileHandle_p);
1303            return;            return;
1304              TMPMEMFREE(isCellCentered);
1305          }          }
1306          isCellCentered[i_data]=TRUE;          isCellCentered[i_data]=TRUE;
1307          break;          break;
# Line 1299  void Finley_Mesh_saveVTK(const char * fi Line 1315  void Finley_Mesh_saveVTK(const char * fi
1315          {          {
1316            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
1317            fclose(fileHandle_p);            fclose(fileHandle_p);
1318              TMPMEMFREE(isCellCentered);
1319            return;            return;
1320          }          }
1321          isCellCentered[i_data]=TRUE;          isCellCentered[i_data]=TRUE;
# Line 1313  void Finley_Mesh_saveVTK(const char * fi Line 1330  void Finley_Mesh_saveVTK(const char * fi
1330          {          {
1331            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
1332            fclose(fileHandle_p);            fclose(fileHandle_p);
1333              TMPMEMFREE(isCellCentered);
1334            return;            return;
1335          }          }
1336          isCellCentered[i_data]=TRUE;          isCellCentered[i_data]=TRUE;
# Line 1327  void Finley_Mesh_saveVTK(const char * fi Line 1345  void Finley_Mesh_saveVTK(const char * fi
1345          {          {
1346            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
1347            fclose(fileHandle_p);            fclose(fileHandle_p);
1348              TMPMEMFREE(isCellCentered);
1349            return;            return;
1350          }          }
1351          isCellCentered[i_data]=TRUE;          isCellCentered[i_data]=TRUE;
# Line 1341  void Finley_Mesh_saveVTK(const char * fi Line 1360  void Finley_Mesh_saveVTK(const char * fi
1360          {          {
1361            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");            Finley_setError(TYPE_ERROR,"saveVTK: cannot write given data in single file.");
1362            fclose(fileHandle_p);            fclose(fileHandle_p);
1363              TMPMEMFREE(isCellCentered);
1364            return;            return;
1365          }          }
1366          isCellCentered[i_data]=TRUE;          isCellCentered[i_data]=TRUE;
# Line 1349  void Finley_Mesh_saveVTK(const char * fi Line 1369  void Finley_Mesh_saveVTK(const char * fi
1369          sprintf(error_msg,"saveVTK: Finley does not know anything about function space type %d",getFunctionSpaceType(data_pp[i_data]));          sprintf(error_msg,"saveVTK: Finley does not know anything about function space type %d",getFunctionSpaceType(data_pp[i_data]));
1370          Finley_setError(TYPE_ERROR,error_msg);          Finley_setError(TYPE_ERROR,error_msg);
1371          fclose(fileHandle_p);          fclose(fileHandle_p);
1372            TMPMEMFREE(isCellCentered);
1373          return;          return;
1374        }        }
1375        if (isCellCentered[i_data])        if (isCellCentered[i_data])
# Line 1372  void Finley_Mesh_saveVTK(const char * fi Line 1393  void Finley_Mesh_saveVTK(const char * fi
1393      numPoints = mesh_p->Nodes->numNodes;      numPoints = mesh_p->Nodes->numNodes;
1394    }    }
1395    if (elementtype==FINLEY_UNKNOWN) elementtype=FINLEY_ELEMENTS;    if (elementtype==FINLEY_UNKNOWN) elementtype=FINLEY_ELEMENTS;
   Finley_ElementFile* elements=NULL;  
1396    switch(elementtype)    switch(elementtype)
1397    {    {
1398    case FINLEY_ELEMENTS:    case FINLEY_ELEMENTS:
# Line 1392  void Finley_Mesh_saveVTK(const char * fi Line 1412  void Finley_Mesh_saveVTK(const char * fi
1412    {    {
1413      Finley_setError(SYSTEM_ERROR,"saveVTK: undefined element file");      Finley_setError(SYSTEM_ERROR,"saveVTK: undefined element file");
1414      fclose(fileHandle_p);      fclose(fileHandle_p);
1415        TMPMEMFREE(isCellCentered);
1416      return;      return;
1417    }    }
1418    /* map finley element type to VTK element type */    /* map finley element type to VTK element type */
1419    numCells = elements->numElements;    numCells = elements->numElements;
   ElementTypeId TypeId;  
1420    if (nodetype==FINLEY_REDUCED_DEGREES_OF_FREEDOM)    if (nodetype==FINLEY_REDUCED_DEGREES_OF_FREEDOM)
1421    {    {
1422      TypeId = elements->LinearReferenceElement->Type->TypeId;      TypeId = elements->LinearReferenceElement->Type->TypeId;
# Line 1505  void Finley_Mesh_saveVTK(const char * fi Line 1525  void Finley_Mesh_saveVTK(const char * fi
1525      sprintf(error_msg, "saveVTK: Element type %s is not supported by VTK",elements->ReferenceElement->Type->Name);      sprintf(error_msg, "saveVTK: Element type %s is not supported by VTK",elements->ReferenceElement->Type->Name);
1526      Finley_setError(VALUE_ERROR,error_msg);      Finley_setError(VALUE_ERROR,error_msg);
1527      fclose(fileHandle_p);      fclose(fileHandle_p);
1528        TMPMEMFREE(isCellCentered);
1529      return;      return;
1530    }    }
1531    /* xml header */    /* xml header */
# Line 1563  void Finley_Mesh_saveVTK(const char * fi Line 1584  void Finley_Mesh_saveVTK(const char * fi
1584    
1585    /* write out the DataArray element for the connectivity */    /* write out the DataArray element for the connectivity */
1586    
1587    int NN = elements->ReferenceElement->Type->numNodes;    NN = elements->ReferenceElement->Type->numNodes;
1588    fprintf(fileHandle_p, "<Cells>\n");    fprintf(fileHandle_p, "<Cells>\n");
1589    fprintf(fileHandle_p, "<DataArray Name=\"connectivity\" type=\"Int32\" format=\"ascii\">\n");    fprintf(fileHandle_p, "<DataArray Name=\"connectivity\" type=\"Int32\" format=\"ascii\">\n");
1590    
# Line 1675  void Finley_Mesh_saveVTK(const char * fi Line 1696  void Finley_Mesh_saveVTK(const char * fi
1696            sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);            sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);
1697            Finley_setError(VALUE_ERROR,error_msg);            Finley_setError(VALUE_ERROR,error_msg);
1698            fclose(fileHandle_p);            fclose(fileHandle_p);
1699              TMPMEMFREE(isCellCentered);
1700            return;            return;
1701          }          }
1702        }        }
# Line 1701  void Finley_Mesh_saveVTK(const char * fi Line 1723  void Finley_Mesh_saveVTK(const char * fi
1723            {            {
1724              Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");              Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");
1725              fclose(fileHandle_p);              fclose(fileHandle_p);
1726                TMPMEMFREE(isCellCentered);
1727              return;              return;
1728            }            }
1729            nCompReqd = 3;            nCompReqd = 3;
# Line 1712  void Finley_Mesh_saveVTK(const char * fi Line 1735  void Finley_Mesh_saveVTK(const char * fi
1735            {            {
1736              Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");              Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");
1737              fclose(fileHandle_p);              fclose(fileHandle_p);
1738                TMPMEMFREE(isCellCentered);
1739              return;              return;
1740            }            }
1741            nCompReqd = 9;            nCompReqd = 9;
1742          }          }
1743          fprintf(fileHandle_p, "<DataArray Name=\"%s\" type=\"Float64\" NumberOfComponents=\"%d\" format=\"ascii\">\n",names_p[i_data], nCompReqd);          fprintf(fileHandle_p, "<DataArray Name=\"%s\" type=\"Float64\" NumberOfComponents=\"%d\" format=\"ascii\">\n",names_p[i_data], nCompReqd);
1744    
         double sampleAvg[nComp];  
1745          for (i=0; i<numCells; i++)          for (i=0; i<numCells; i++)
1746          {          {
1747            values = getSampleData(data_pp[i_data], i);            values = getSampleData(data_pp[i_data], i);
1748            /* averaging over the number of points in the sample */            /* averaging over the number of points in the sample */
1749            for (k=0; k<nComp; k++)            for (k=0; k<MIN(nComp,NCOMP_MAX); k++)
1750            {            {
1751              if (isExpanded(data_pp[i_data])) {              if (isExpanded(data_pp[i_data])) {
1752                 rtmp = 0.;                 rtmp = 0.;
# Line 1814  void Finley_Mesh_saveVTK(const char * fi Line 1837  void Finley_Mesh_saveVTK(const char * fi
1837            sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);            sprintf(error_msg, "saveVTK: data %s: Vtk can't handle objects with rank greater than 2.",names_p[i_data]);
1838            Finley_setError(VALUE_ERROR,error_msg);            Finley_setError(VALUE_ERROR,error_msg);
1839            fclose(fileHandle_p);            fclose(fileHandle_p);
1840              TMPMEMFREE(isCellCentered);
1841            return;            return;
1842          }          }
1843        }        }
# Line 1840  void Finley_Mesh_saveVTK(const char * fi Line 1864  void Finley_Mesh_saveVTK(const char * fi
1864            {            {
1865              Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");              Finley_setError(VALUE_ERROR, "saveVTK: rank 1 object must have less then 4 components");
1866              fclose(fileHandle_p);              fclose(fileHandle_p);
1867                TMPMEMFREE(isCellCentered);
1868              return;              return;
1869            }            }
1870            nCompReqd = 3;            nCompReqd = 3;
# Line 1851  void Finley_Mesh_saveVTK(const char * fi Line 1876  void Finley_Mesh_saveVTK(const char * fi
1876            {            {
1877              Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");              Finley_setError(VALUE_ERROR, "saveVTK: rank 2 object must have less then 4x4 components and must have a square shape");
1878              fclose(fileHandle_p);              fclose(fileHandle_p);
1879                TMPMEMFREE(isCellCentered);
1880              return;              return;
1881            }            }
1882            nCompReqd = 9;            nCompReqd = 9;
# Line 1860  void Finley_Mesh_saveVTK(const char * fi Line 1886  void Finley_Mesh_saveVTK(const char * fi
1886          /* if the number of required components is more than the number          /* if the number of required components is more than the number
1887          * of actual components, pad with zeros          * of actual components, pad with zeros
1888          */          */
1889          bool_t do_write=TRUE;          do_write=TRUE;
1890          for (i=0; i<mesh_p->Nodes->numNodes; i++)          for (i=0; i<mesh_p->Nodes->numNodes; i++)
1891          {          {
1892            if (nodetype==FINLEY_REDUCED_DEGREES_OF_FREEDOM)            if (nodetype==FINLEY_REDUCED_DEGREES_OF_FREEDOM)
# Line 1944  void Finley_Mesh_saveVTK(const char * fi Line 1970  void Finley_Mesh_saveVTK(const char * fi
1970    fprintf(fileHandle_p, "</VTKFile>\n");    fprintf(fileHandle_p, "</VTKFile>\n");
1971    /* close the file */    /* close the file */
1972    fclose(fileHandle_p);    fclose(fileHandle_p);
1973      TMPMEMFREE(isCellCentered);
1974    return;    return;
1975  }  }
1976  #endif  #endif

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

  ViewVC Help
Powered by ViewVC 1.1.26