Commit b65b6429 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Added writeMetadata to VTKWriter

parent 18143ecb
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -50,6 +50,10 @@ public:
         throw std::domain_error("The Legacy VTK file formats support only ASCII and BINARY formats.");
   }

   // If desired, cycle and time of the simulation can put into the file. This follows the instructions at
   // http://www.visitusers.org/index.php?title=Time_and_Cycle_in_VTK_files
   void writeMetadata( std::int32_t cycle = -1, double time = -1 );

   template< int EntityDimension = Mesh::getMeshDimension() >
   void writeEntities( const Mesh& mesh );

@@ -60,7 +64,7 @@ public:
                        VTK::DataType dataType = VTK::DataType::CellData );

protected:
   void writeHeader( const Mesh& mesh );
   void writeHeader();

   void writePoints( const Mesh& mesh );

@@ -74,6 +78,9 @@ protected:
   // number of points written to the file
   IndexType pointsCount = 0;

   // indicator if the header has been written
   bool headerWritten = false;

   // number of data arrays written in each section
   int cellDataArrays = 0;
   int pointDataArrays = 0;
+30 −2
Original line number Diff line number Diff line
@@ -404,12 +404,39 @@ struct MeshEntityTypesVTKWriter< Grid< Dimension, MeshReal, Device, MeshIndex >,

} // namespace details

template< typename Mesh >
void
VTKWriter< Mesh >::writeMetadata( int cycle, double time )
{
   if( ! headerWritten )
      writeHeader();

   int n_metadata = 0;
   if( cycle >= 0 )
      ++n_metadata;
   if( time >= 0 )
      ++n_metadata;
   if( n_metadata > 0 )
      str << "FIELD FieldData " << n_metadata << "\n";
   if( cycle >= 0 ) {
      str << "CYCLE 1 1 int\n";
      details::writeInt( format, str, cycle );
      str << "\n";
   }
   if( time >= 0 ) {
      str << "TIME 1 1 double\n";
      details::writeReal( format, str, time );
      str << "\n";
   }
}

template< typename Mesh >
   template< int EntityDimension >
void
VTKWriter< Mesh >::writeEntities( const Mesh& mesh )
{
   writeHeader( mesh );
   if( ! headerWritten )
      writeHeader();
   writePoints( mesh );

   using EntityType = typename Mesh::template EntityType< EntityDimension >;
@@ -487,12 +514,13 @@ VTKWriter< Mesh >::writeDataArray( const Array& array,

template< typename Mesh >
void
VTKWriter< Mesh >::writeHeader( const Mesh& mesh )
VTKWriter< Mesh >::writeHeader()
{
    str << "# vtk DataFile Version 2.0\n"
        << "TNL DATA\n"
        << ((format == VTK::FileFormat::ascii) ? "ASCII\n" : "BINARY\n")
        << "DATASET UNSTRUCTURED_GRID\n";
    headerWritten = true;
}

template< typename Mesh >