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

Diff of /trunk-mpi-branch/finley/src/Mesh_saveVTK.c

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

revision 1271 by ksteube, Wed Aug 22 08:55:03 2007 UTC revision 1272 by gross, Fri Aug 24 00:40:43 2007 UTC
# Line 33  Line 33 
33  #define LEN_PRINTED_INT_FORMAT (9+1)  #define LEN_PRINTED_INT_FORMAT (9+1)
34  #define INT_FORMAT "%d "  #define INT_FORMAT "%d "
35  #define INT_NEWLINE_FORMAT "%d\n"  #define INT_NEWLINE_FORMAT "%d\n"
36  #define FLOAT_SCALAR_FORMAT "%15.10e\n"  #define FLOAT_SCALAR_FORMAT "%12.6e\n"
37  #define FLOAT_VECTOR_FORMAT "%15.10e %15.10e %15.10e\n"  #define FLOAT_VECTOR_FORMAT "%12.6e %12.6e %12.6e\n"
38  #define FLOAT_TENSOR_FORMAT "%15.10e %15.10e %15.10e %15.10e %15.10e %15.10e %15.10e %15.10e %15.10e\n"  #define FLOAT_TENSOR_FORMAT "%12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e\n"
39  #define LEN_PRINTED_FLOAT_SCALAR_FORMAT (15+1)  #define LEN_PRINTED_FLOAT_SCALAR_FORMAT (12+1)
40  #define LEN_PRINTED_FLOAT_VECTOR_FORMAT (3*(15+1)+1)  #define LEN_PRINTED_FLOAT_VECTOR_FORMAT (3*(12+1)+1)
41  #define LEN_PRINTED_FLOAT_TENSOR_FORMAT (9*(15+1)+1)  #define LEN_PRINTED_FLOAT_TENSOR_FORMAT (9*(12+1)+1)
42  #define NEWLINE "\n"  #define NEWLINE "\n"
43  #define LEN_TMP_BUFFER LEN_PRINTED_FLOAT_TENSOR_FORMAT+(MAX_numNodes*LEN_PRINTED_INT_FORMAT+1)+2  #define LEN_TMP_BUFFER LEN_PRINTED_FLOAT_TENSOR_FORMAT+(MAX_numNodes*LEN_PRINTED_INT_FORMAT+1)+2
44  #define NCOMP_MAX 9  #define NCOMP_MAX 9
# Line 59  void Finley_Mesh_saveVTK(const char * fi Line 59  void Finley_Mesh_saveVTK(const char * fi
59    size_t len_txt_buffer, max_len_names, txt_buffer_in_use;    size_t len_txt_buffer, max_len_names, txt_buffer_in_use;
60    FILE * fileHandle_p = NULL;    FILE * fileHandle_p = NULL;
61    int mpi_size, i_data, i,j , cellType;    int mpi_size, i_data, i,j , cellType;
62    dim_t nDim, globalNumPoints, numCells, globalNumCells, numVTKNodesPerElement, myNumPoints, numPointsPerSample, rank, nComp, nCompReqd, shape, NN, numCellFactor, myNumCells;    dim_t nDim, globalNumPoints, numCells, globalNumCells, numVTKNodesPerElement, myNumPoints, numPointsPerSample, rank, nComp, nCompReqd, shape, NN, numCellFactor, myNumCells, max_name_len;
63    bool_t do_write, *isCellCentered=NULL,write_celldata=FALSE,write_pointdata=FALSE;    bool_t do_write, *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;
# Line 108  void Finley_Mesh_saveVTK(const char * fi Line 108  void Finley_Mesh_saveVTK(const char * fi
108    mpi_size  = mesh_p->Nodes->MPIInfo->size;    mpi_size  = mesh_p->Nodes->MPIInfo->size;
109    nDim = mesh_p->Nodes->numDim;    nDim = mesh_p->Nodes->numDim;
110    
111    if (! (nDim ==2) || (nDim == 3) ) {    if (! ( (nDim ==2) || (nDim == 3) ) ) {
112          Finley_setError(IO_ERROR, "saveVTK: spatial dimension 2 or 3 is supported only.");          Finley_setError(IO_ERROR, "saveVTK: spatial dimension 2 or 3 is supported only.");
113          return;            return;  
114    }    }
# Line 404  void Finley_Mesh_saveVTK(const char * fi Line 404  void Finley_Mesh_saveVTK(const char * fi
404    /*                                     */    /*                                     */
405    /*   allocate text buffer              */    /*   allocate text buffer              */
406    /*                                     */    /*                                     */
407    len_txt_buffer= strlen(tags_header) + 3 * LEN_PRINTED_INT_FORMAT; /* header */    max_name_len=0;
408      for (i_data =0 ;i_data<num_data;++i_data) max_name_len=MAX(max_name_len,strlen(names_p[i_data]));
409      len_txt_buffer= strlen(tags_header) + 3 * LEN_PRINTED_INT_FORMAT + (30+3*max_name_len); /* header */
410    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);
411    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));
412    len_txt_buffer=MAX(len_txt_buffer,200+3*max_len_names);    len_txt_buffer=MAX(len_txt_buffer,200+3*max_len_names);
# Line 493  void Finley_Mesh_saveVTK(const char * fi Line 495  void Finley_Mesh_saveVTK(const char * fi
495                  MPI_File_iwrite_shared(mpi_fileHandle_p, tags_End_Points_and_Start_Conn, strlen(tags_End_Points_and_Start_Conn), MPI_CHAR, &mpi_req);                  MPI_File_iwrite_shared(mpi_fileHandle_p, tags_End_Points_and_Start_Conn, strlen(tags_End_Points_and_Start_Conn), MPI_CHAR, &mpi_req);
496                  MPI_Wait(&mpi_req,&mpi_status);                  MPI_Wait(&mpi_req,&mpi_status);
497               #endif               #endif
           } else {  
              fprintf(fileHandle_p,tags_End_Points_and_Start_Conn);  
498            }            }
499              } else {
500         }           fprintf(fileHandle_p,tags_End_Points_and_Start_Conn);
501          }
502    
503       /* write the cells */       /* write the cells */
504       if (nodetype == FINLEY_REDUCED_NODES) {       if (nodetype == FINLEY_REDUCED_NODES) {
# Line 573  void Finley_Mesh_saveVTK(const char * fi Line 574  void Finley_Mesh_saveVTK(const char * fi
574       if ( mpi_size > 1) {       if ( mpi_size > 1) {
575          txt_buffer[0] = '\0';          txt_buffer[0] = '\0';
576          txt_buffer_in_use=0;          txt_buffer_in_use=0;
577          for (i=numVTKNodesPerElement*myFirstCell*numCellFactor; i<=numCells*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {          for (i=numVTKNodesPerElement*(myFirstCell*numCellFactor+1); i<=numCells*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {
578             sprintf(tmp_buffer, INT_NEWLINE_FORMAT, i);             sprintf(tmp_buffer, INT_NEWLINE_FORMAT, i);
579             __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);             __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
580           }           }
# Line 581  void Finley_Mesh_saveVTK(const char * fi Line 582  void Finley_Mesh_saveVTK(const char * fi
582              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);
583           #endif               #endif    
584       } else {       } else {
585          for (i=0; i<=numCells*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {          for (i=numVTKNodesPerElement; i<=numCells*numVTKNodesPerElement*numCellFactor; i+=numVTKNodesPerElement) {
586             fprintf(fileHandle_p, INT_NEWLINE_FORMAT, i);             fprintf(fileHandle_p, INT_NEWLINE_FORMAT, i);
587          }          }
588            
# Line 604  void Finley_Mesh_saveVTK(const char * fi Line 605  void Finley_Mesh_saveVTK(const char * fi
605       if ( mpi_size > 1) {       if ( mpi_size > 1) {
606          txt_buffer[0] = '\0';          txt_buffer[0] = '\0';
607          txt_buffer_in_use=0;          txt_buffer_in_use=0;
608          for (i=0; i<=numCells*numCellFactor; i++) __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);          for (i=0; i<numCells*numCellFactor; i++) __STRCAT(txt_buffer,tmp_buffer,txt_buffer_in_use);
609           #ifdef PASO_MPI           #ifdef PASO_MPI
610              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);
611           #endif               #endif    
612       } else {       } else {
613          for (i=0; i<=numCells*numCellFactor; i++) fprintf(fileHandle_p, tmp_buffer);          for (i=0; i<numCells*numCellFactor; i++) fprintf(fileHandle_p, tmp_buffer);
614       }       }
615       /* finalize cell information */       /* finalize cell information */
616       if ( mpi_size > 1) {       if ( mpi_size > 1) {
# Line 627  void Finley_Mesh_saveVTK(const char * fi Line 628  void Finley_Mesh_saveVTK(const char * fi
628   /* Write cell data */   /* Write cell data */
629   if (write_celldata && Finley_noError()) {   if (write_celldata && Finley_noError()) {
630        /* mark the active data arrays */        /* mark the active data arrays */
631          txt_buffer[0] = '\0';
632        set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;        set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
633        strcat(txt_buffer, "<CellData");        strcat(txt_buffer, "<CellData");
634        for (i_data =0 ;i_data<num_data;++i_data) {        for (i_data =0 ;i_data<num_data;++i_data) {
# Line 796  void Finley_Mesh_saveVTK(const char * fi Line 798  void Finley_Mesh_saveVTK(const char * fi
798    if (write_pointdata && Finley_noError()) {    if (write_pointdata && Finley_noError()) {
799        /* mark the active data arrays */        /* mark the active data arrays */
800        set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;        set_scalar=FALSE,set_vector=FALSE, set_tensor=FALSE;
801          txt_buffer[0] = '\0';
802        strcat(txt_buffer, "<PointData");        strcat(txt_buffer, "<PointData");
803        for (i_data =0 ;i_data<num_data;++i_data) {        for (i_data =0 ;i_data<num_data;++i_data) {
804          if (! isEmpty(data_pp[i_data]) && !isCellCentered[i_data]) {          if (! isEmpty(data_pp[i_data]) && !isCellCentered[i_data]) {
# Line 886  void Finley_Mesh_saveVTK(const char * fi Line 889  void Finley_Mesh_saveVTK(const char * fi
889                 for (i=0; i<mesh_p->Nodes->numNodes; i++) {                 for (i=0; i<mesh_p->Nodes->numNodes; i++) {
890                    k=globalNodeIndex[i];                    k=globalNodeIndex[i];
891                    if ( (myFirstNode <= k) && (k < myLastNode) ) {                    if ( (myFirstNode <= k) && (k < myLastNode) ) {
892                       values = getSampleData(data_pp[i_data], nodeMapping->map[i]);                       values = getSampleData(data_pp[i_data], nodeMapping->target[i]);
893                       /* if the number of mpi_required components is more than the number                       /* if the number of mpi_required components is more than the number
894                       * of actual components, pad with zeros                       * of actual components, pad with zeros
895                       */                       */

Legend:
Removed from v.1271  
changed lines
  Added in v.1272

  ViewVC Help
Powered by ViewVC 1.1.26