/[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 1705 by ksteube, Thu Aug 14 05:56:40 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 49  void Finley_Mesh_saveVTK(const char * fi Line 50  void Finley_Mesh_saveVTK(const char * fi
50                           char* *names_p,                           char* *names_p,
51                           escriptDataC* *data_pp)                           escriptDataC* *data_pp)
52  {  {
53    #ifdef USE_VTK
54    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];
55    double sampleAvg[NCOMP_MAX], *values, rtmp;    double sampleAvg[NCOMP_MAX], *values, rtmp;
56    size_t len_txt_buffer, max_len_names, txt_buffer_in_use;    size_t txt_buffer_in_use;
57      dim_t len_txt_buffer,  max_len_names;
58    FILE * fileHandle_p = NULL;    FILE * fileHandle_p = NULL;
59    int mpi_size, i_data, i,j , cellType;    int mpi_size, i, j, cellType;
60    dim_t nDim, globalNumPoints, numCells, globalNumCells, numVTKNodesPerElement, myNumPoints, numPointsPerSample, rank, nComp, nCompReqd, shape, NN, numCellFactor, myNumCells, max_name_len;    dim_t i_data;
61    bool_t do_write, *isCellCentered=NULL,write_celldata=FALSE,write_pointdata=FALSE;    dim_t nDim, globalNumPoints, numCells, globalNumCells, numVTKNodesPerElement;
62      dim_t myNumPoints, numPointsPerSample, rank, nComp, nCompReqd;
63      dim_t shape, NN, numCellFactor, myNumCells, max_name_len;
64      bool_t *isCellCentered=NULL,write_celldata=FALSE,write_pointdata=FALSE;
65    bool_t set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;    bool_t set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
66    index_t myFirstNode, myLastNode, *globalNodeIndex, k, *node_index, myFirstCell;    index_t myFirstNode, myLastNode, *globalNodeIndex, k, *node_index, myFirstCell;
67    #ifdef PASO_MPI    #ifdef PASO_MPI
68    int ierr;    int ierr;
69    int amode = MPI_MODE_CREATE | MPI_MODE_WRONLY |  MPI_MODE_SEQUENTIAL;    /* int amode = MPI_MODE_CREATE | MPI_MODE_WRONLY |  MPI_MODE_SEQUENTIAL;  */
70      const int amode = MPI_MODE_CREATE | MPI_MODE_WRONLY | MPI_MODE_UNIQUE_OPEN;
71    MPI_File mpi_fileHandle_p;    MPI_File mpi_fileHandle_p;
72    MPI_Status mpi_status;    MPI_Status mpi_status;
73    MPI_Request mpi_req;    MPI_Request mpi_req;
# Line 127  void Finley_Mesh_saveVTK(const char * fi Line 134  void Finley_Mesh_saveVTK(const char * fi
134              /*XFS only */              /*XFS only */
135              /*   MPI_Info_set(mpi_info, "direct_write",          "true"); */              /*   MPI_Info_set(mpi_info, "direct_write",          "true"); */
136            #endif            #endif
137              if ( my_mpi_rank == 0) {
138                  if  (Paso_fileExists(filename_p)) remove(filename_p);
139              }
140            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);
141            if (! ierr) {            if (ierr != MPI_SUCCESS) {
142            perror(filename_p);            perror(filename_p);
143                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);
144                Finley_setError(IO_ERROR,error_msg);                Finley_setError(IO_ERROR,error_msg);
# Line 227  void Finley_Mesh_saveVTK(const char * fi Line 237  void Finley_Mesh_saveVTK(const char * fi
237           } else {           } else {
238             write_pointdata=TRUE;             write_pointdata=TRUE;
239           }           }
240           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]));
241         }         }
242       }       }
243       nodetype = (nodetype == FINLEY_UNKNOWN) ? FINLEY_NODES : nodetype;       nodetype = (nodetype == FINLEY_UNKNOWN) ? FINLEY_NODES : nodetype;
# Line 274  void Finley_Mesh_saveVTK(const char * fi Line 284  void Finley_Mesh_saveVTK(const char * fi
284         myNumCells= Finley_ElementFile_getMyNumElements(elements);         myNumCells= Finley_ElementFile_getMyNumElements(elements);
285         myFirstCell= Finley_ElementFile_getFirstElement(elements);         myFirstCell= Finley_ElementFile_getFirstElement(elements);
286         NN = elements->numNodes;         NN = elements->numNodes;
287         if (nodetype==FINLEY_REDUCED_NODES || nodetype==FINLEY_REDUCED_NODES) {         if (nodetype==FINLEY_REDUCED_NODES) {
288            TypeId = elements->LinearReferenceElement->Type->TypeId;            TypeId = elements->LinearReferenceElement->Type->TypeId;
289         } else {         } else {
290            TypeId = elements->ReferenceElement->Type->TypeId;            TypeId = elements->ReferenceElement->Type->TypeId;
# Line 397  void Finley_Mesh_saveVTK(const char * fi Line 407  void Finley_Mesh_saveVTK(const char * fi
407    /*   allocate text buffer              */    /*   allocate text buffer              */
408    /*                                     */    /*                                     */
409    max_name_len=0;    max_name_len=0;
410    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]));
411    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 */
412    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);
413    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));
414    len_txt_buffer=MAX(len_txt_buffer,200+3*max_len_names);    len_txt_buffer=MAX(len_txt_buffer,200+3*max_len_names);
415    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);
416    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);
417    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);
418    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 576  void Finley_Mesh_saveVTK(const char * fi
576       if ( mpi_size > 1) {       if ( mpi_size > 1) {
577          txt_buffer[0] = '\0';          txt_buffer[0] = '\0';
578          txt_buffer_in_use=0;          txt_buffer_in_use=0;
579          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) {
580             sprintf(tmp_buffer, INT_NEWLINE_FORMAT, i);              sprintf(tmp_buffer, INT_NEWLINE_FORMAT, i);
581             __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);              __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
582           }           }
583           #ifdef PASO_MPI           #ifdef PASO_MPI
584              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 600  void Finley_Mesh_saveVTK(const char * fi
600      } else {      } else {
601         fprintf(fileHandle_p,tags_End_Offset_and_Start_Type);         fprintf(fileHandle_p,tags_End_Offset_and_Start_Type);
602      }      }
       
         
603       /* write element type */       /* write element type */
604       sprintf(tmp_buffer, INT_NEWLINE_FORMAT, cellType);       sprintf(tmp_buffer, INT_NEWLINE_FORMAT, cellType);
605       if ( mpi_size > 1) {       if ( mpi_size > 1) {
# Line 943  void Finley_Mesh_saveVTK(const char * fi Line 951  void Finley_Mesh_saveVTK(const char * fi
951          if ( mpi_size > 1) {          if ( mpi_size > 1) {
952            if ( my_mpi_rank == 0) {            if ( my_mpi_rank == 0) {
953               #ifdef PASO_MPI               #ifdef PASO_MPI
954                  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);
955                  MPI_Wait(&mpi_req,&mpi_status);                  MPI_Wait(&mpi_req,&mpi_status);
956               #endif               #endif
957            }            }
# Line 961  void Finley_Mesh_saveVTK(const char * fi Line 969  void Finley_Mesh_saveVTK(const char * fi
969                 MPI_Info_free(&mpi_info);                 MPI_Info_free(&mpi_info);
970                 #undef MPIO_HINTS                 #undef MPIO_HINTS
971               #endif               #endif
              MPI_File_close(&mpi_fileHandle_p);  
972            #endif            #endif
973          }          }
974            #ifdef PASO_MPI
975               MPI_File_close(&mpi_fileHandle_p);
976            #endif
977       } else {       } else {
978           fprintf(fileHandle_p,footer);           fprintf(fileHandle_p,footer);
979           fclose(fileHandle_p);           fclose(fileHandle_p);
# Line 972  void Finley_Mesh_saveVTK(const char * fi Line 982  void Finley_Mesh_saveVTK(const char * fi
982    TMPMEMFREE(isCellCentered);    TMPMEMFREE(isCellCentered);
983    TMPMEMFREE(txt_buffer);    TMPMEMFREE(txt_buffer);
984    return;    return;
985    #else
986      /* Don't kill the job if saveVTK() doesn't work */
987      fprintf(stderr, "\n\nsaveVTK warning: VTK is not available\n\n\n");
988    #endif
989  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26