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

temp_trunk_copy/finley/src/Mesh_saveVTK.c revision 1384 by phornby, Fri Jan 11 02:29:38 2008 UTC trunk/finley/src/Mesh_saveVTK.c revision 1677 by gross, Mon Jul 28 06:36:19 2008 UTC
# Line 24  Line 24 
24  #include "Mesh.h"  #include "Mesh.h"
25  #include "Assemble.h"  #include "Assemble.h"
26  #include "vtkCellType.h"  /* copied from vtk source directory !!! */  #include "vtkCellType.h"  /* copied from vtk source directory !!! */
27    #include "paso/PasoUtil.h"
28    
29  #define LEN_PRINTED_INT_FORMAT (9+1)  #define LEN_PRINTED_INT_FORMAT (9+1)
30  #define INT_FORMAT "%d "  #define INT_FORMAT "%d "
# Line 51  void Finley_Mesh_saveVTK(const char * fi Line 52  void Finley_Mesh_saveVTK(const char * fi
52  {  {
53    char error_msg[LenErrorMsg_MAX], *txt_buffer=NULL, tmp_buffer[LEN_TMP_BUFFER];    char error_msg[LenErrorMsg_MAX], *txt_buffer=NULL, tmp_buffer[LEN_TMP_BUFFER];
54    double sampleAvg[NCOMP_MAX], *values, rtmp;    double sampleAvg[NCOMP_MAX], *values, rtmp;
55    size_t len_txt_buffer, max_len_names, txt_buffer_in_use;    size_t txt_buffer_in_use;
56      dim_t len_txt_buffer,  max_len_names;
57    FILE * fileHandle_p = NULL;    FILE * fileHandle_p = NULL;
58    int mpi_size, i_data, i,j , cellType;    int mpi_size, i, j, cellType;
59    dim_t nDim, globalNumPoints, numCells, globalNumCells, numVTKNodesPerElement, myNumPoints, numPointsPerSample, rank, nComp, nCompReqd, shape, NN, numCellFactor, myNumCells, max_name_len;    dim_t i_data;
60    bool_t do_write, *isCellCentered=NULL,write_celldata=FALSE,write_pointdata=FALSE;    dim_t nDim, globalNumPoints, numCells, globalNumCells, numVTKNodesPerElement;
61      dim_t myNumPoints, numPointsPerSample, rank, nComp, nCompReqd;
62      dim_t shape, NN, numCellFactor, myNumCells, max_name_len;
63      bool_t *isCellCentered=NULL,write_celldata=FALSE,write_pointdata=FALSE;
64    bool_t set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;    bool_t set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
65    index_t myFirstNode, myLastNode, *globalNodeIndex, k, *node_index, myFirstCell;    index_t myFirstNode, myLastNode, *globalNodeIndex, k, *node_index, myFirstCell;
66    #ifdef PASO_MPI    #ifdef PASO_MPI
67    int ierr;    int ierr;
68    int amode = MPI_MODE_CREATE | MPI_MODE_WRONLY |  MPI_MODE_SEQUENTIAL;    /* int amode = MPI_MODE_CREATE | MPI_MODE_WRONLY |  MPI_MODE_SEQUENTIAL;  */
69      const int amode = MPI_MODE_CREATE | MPI_MODE_WRONLY | MPI_MODE_UNIQUE_OPEN;
70    MPI_File mpi_fileHandle_p;    MPI_File mpi_fileHandle_p;
71    MPI_Status mpi_status;    MPI_Status mpi_status;
72    MPI_Request mpi_req;    MPI_Request mpi_req;
# Line 127  void Finley_Mesh_saveVTK(const char * fi Line 133  void Finley_Mesh_saveVTK(const char * fi
133              /*XFS only */              /*XFS only */
134              /*   MPI_Info_set(mpi_info, "direct_write",          "true"); */              /*   MPI_Info_set(mpi_info, "direct_write",          "true"); */
135            #endif            #endif
136              if ( my_mpi_rank == 0) {
137                  if  (Paso_fileExists(filename_p)) remove(filename_p);
138              }
139            ierr=MPI_File_open(mesh_p->Nodes->MPIInfo->comm, (char*)filename_p, amode,mpi_info, &mpi_fileHandle_p);            ierr=MPI_File_open(mesh_p->Nodes->MPIInfo->comm, (char*)filename_p, amode,mpi_info, &mpi_fileHandle_p);
140            if (! ierr) {            if (ierr != MPI_SUCCESS) {
141            perror(filename_p);            perror(filename_p);
142                sprintf(error_msg, "saveVTK: File %s could not be opened for writing in parallel.", filename_p);                sprintf(error_msg, "saveVTK: File %s could not be opened for writing in parallel.", filename_p);
143                Finley_setError(IO_ERROR,error_msg);                Finley_setError(IO_ERROR,error_msg);
# Line 227  void Finley_Mesh_saveVTK(const char * fi Line 236  void Finley_Mesh_saveVTK(const char * fi
236           } else {           } else {
237             write_pointdata=TRUE;             write_pointdata=TRUE;
238           }           }
239           max_len_names =MAX(max_len_names,strlen(names_p[i_data]));           max_len_names =MAX(max_len_names,(dim_t)strlen(names_p[i_data]));
240         }         }
241       }       }
242       nodetype = (nodetype == FINLEY_UNKNOWN) ? FINLEY_NODES : nodetype;       nodetype = (nodetype == FINLEY_UNKNOWN) ? FINLEY_NODES : nodetype;
# Line 274  void Finley_Mesh_saveVTK(const char * fi Line 283  void Finley_Mesh_saveVTK(const char * fi
283         myNumCells= Finley_ElementFile_getMyNumElements(elements);         myNumCells= Finley_ElementFile_getMyNumElements(elements);
284         myFirstCell= Finley_ElementFile_getFirstElement(elements);         myFirstCell= Finley_ElementFile_getFirstElement(elements);
285         NN = elements->numNodes;         NN = elements->numNodes;
286         if (nodetype==FINLEY_REDUCED_NODES || nodetype==FINLEY_REDUCED_NODES) {         if (nodetype==FINLEY_REDUCED_NODES) {
287            TypeId = elements->LinearReferenceElement->Type->TypeId;            TypeId = elements->LinearReferenceElement->Type->TypeId;
288         } else {         } else {
289            TypeId = elements->ReferenceElement->Type->TypeId;            TypeId = elements->ReferenceElement->Type->TypeId;
# Line 397  void Finley_Mesh_saveVTK(const char * fi Line 406  void Finley_Mesh_saveVTK(const char * fi
406    /*   allocate text buffer              */    /*   allocate text buffer              */
407    /*                                     */    /*                                     */
408    max_name_len=0;    max_name_len=0;
409    for (i_data =0 ;i_data<num_data;++i_data) max_name_len=MAX(max_name_len,strlen(names_p[i_data]));    for (i_data =0 ;i_data<num_data;++i_data) max_name_len=MAX(max_name_len,(dim_t)strlen(names_p[i_data]));
410    len_txt_buffer= strlen(tags_header) + 3 * LEN_PRINTED_INT_FORMAT + (30+3*max_name_len); /* header */    len_txt_buffer= strlen(tags_header) + 3 * LEN_PRINTED_INT_FORMAT + (30+3*max_name_len); /* header */
411    if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, myNumPoints * LEN_TMP_BUFFER);    if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, myNumPoints * LEN_TMP_BUFFER);
412    if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, numCellFactor*myNumCells*(LEN_PRINTED_INT_FORMAT*numVTKNodesPerElement+1));    if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, numCellFactor*myNumCells*(LEN_PRINTED_INT_FORMAT*numVTKNodesPerElement+1));
413    len_txt_buffer=MAX(len_txt_buffer,200+3*max_len_names);    len_txt_buffer=MAX(len_txt_buffer,200+3*max_len_names);
414    len_txt_buffer=MAX(len_txt_buffer, strlen(tag_Float_DataArray) + LEN_PRINTED_INT_FORMAT + max_len_names);    len_txt_buffer=MAX(len_txt_buffer, (dim_t)strlen(tag_Float_DataArray) + LEN_PRINTED_INT_FORMAT + max_len_names);
415    if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, numCellFactor*myNumCells*LEN_PRINTED_FLOAT_TENSOR_FORMAT);    if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, numCellFactor*myNumCells*LEN_PRINTED_FLOAT_TENSOR_FORMAT);
416    if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, myNumPoints*LEN_PRINTED_FLOAT_TENSOR_FORMAT);    if (mpi_size > 1) len_txt_buffer=MAX(len_txt_buffer, myNumPoints*LEN_PRINTED_FLOAT_TENSOR_FORMAT);
417    txt_buffer=TMPMEMALLOC(len_txt_buffer+1,char);    txt_buffer=TMPMEMALLOC(len_txt_buffer+1,char);
# Line 566  void Finley_Mesh_saveVTK(const char * fi Line 575  void Finley_Mesh_saveVTK(const char * fi
575       if ( mpi_size > 1) {       if ( mpi_size > 1) {
576          txt_buffer[0] = '\0';          txt_buffer[0] = '\0';
577          txt_buffer_in_use=0;          txt_buffer_in_use=0;
578          for (i=numVTKNodesPerElement*(myFirstCell*numCellFactor+1); i<=numCells*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {          for (i=numVTKNodesPerElement*(myFirstCell*numCellFactor+1); i<=(myFirstCell+myNumCells)*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {
579             sprintf(tmp_buffer, INT_NEWLINE_FORMAT, i);              sprintf(tmp_buffer, INT_NEWLINE_FORMAT, i);
580             __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);              __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
581           }           }
582           #ifdef PASO_MPI           #ifdef PASO_MPI
583              MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);              MPI_File_write_ordered(mpi_fileHandle_p,txt_buffer,txt_buffer_in_use, MPI_CHAR, &mpi_status);
# Line 590  void Finley_Mesh_saveVTK(const char * fi Line 599  void Finley_Mesh_saveVTK(const char * fi
599      } else {      } else {
600         fprintf(fileHandle_p,tags_End_Offset_and_Start_Type);         fprintf(fileHandle_p,tags_End_Offset_and_Start_Type);
601      }      }
       
         
602       /* write element type */       /* write element type */
603       sprintf(tmp_buffer, INT_NEWLINE_FORMAT, cellType);       sprintf(tmp_buffer, INT_NEWLINE_FORMAT, cellType);
604       if ( mpi_size > 1) {       if ( mpi_size > 1) {
# Line 943  void Finley_Mesh_saveVTK(const char * fi Line 950  void Finley_Mesh_saveVTK(const char * fi
950          if ( mpi_size > 1) {          if ( mpi_size > 1) {
951            if ( my_mpi_rank == 0) {            if ( my_mpi_rank == 0) {
952               #ifdef PASO_MPI               #ifdef PASO_MPI
953                  MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_CellData,strlen(tag_End_PointData),MPI_CHAR,&mpi_req);                  MPI_File_iwrite_shared(mpi_fileHandle_p,tag_End_PointData,strlen(tag_End_PointData),MPI_CHAR,&mpi_req);
954                  MPI_Wait(&mpi_req,&mpi_status);                  MPI_Wait(&mpi_req,&mpi_status);
955               #endif               #endif
956            }            }
# Line 961  void Finley_Mesh_saveVTK(const char * fi Line 968  void Finley_Mesh_saveVTK(const char * fi
968                 MPI_Info_free(&mpi_info);                 MPI_Info_free(&mpi_info);
969                 #undef MPIO_HINTS                 #undef MPIO_HINTS
970               #endif               #endif
              MPI_File_close(&mpi_fileHandle_p);  
971            #endif            #endif
972          }          }
973            #ifdef PASO_MPI
974               MPI_File_close(&mpi_fileHandle_p);
975            #endif
976       } else {       } else {
977           fprintf(fileHandle_p,footer);           fprintf(fileHandle_p,footer);
978           fclose(fileHandle_p);           fclose(fileHandle_p);

Legend:
Removed from v.1384  
changed lines
  Added in v.1677

  ViewVC Help
Powered by ViewVC 1.1.26