Commit 9a6c3d4c authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Merge branch 'JK/writers' into 'develop'

Mesh writers cleanup + NDMetaGrid

See merge request !114
parents 64eb38a3 7c47147f
Loading
Loading
Loading
Loading
+101 −0
Original line number Diff line number Diff line
/***************************************************************************
                          NDMetaGrid.h  -  description
                             -------------------
    begin                : Dec 09, 2021
    copyright            : (C) 2021 by Tomas Oberhuber et al.
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

// Implemented by: Jakub Klinkovský

#pragma once

#include <TNL/Containers/StaticVector.h>

namespace TNL {
namespace Meshes {

/**
 * \brief Minimal class usable as \e Mesh in the \ref VTIWriter.
 *
 * It does not have a \e Device template argument, because it does not describe
 * a data structure - it contains only the information describing the domain of
 * the grid (i.e., the metadata of the \e ImageData tag in the VTI file
 * format). Note that VTK supports only 1, 2, or 3-dimensional grids.
 */
template< int Dimension, typename Real, typename Index >
class NDMetaGrid
{
public:
   using RealType = Real;
   using GlobalIndexType = Index;
   using PointType = Containers::StaticVector< Dimension, Real >;
   using CoordinatesType = Containers::StaticVector< Dimension, Index >;

   //! \brief Returns the spatial dimension of the grid.
   static constexpr int getMeshDimension()
   {
      return Dimension;
   }

   //! \brief Sets the grid dimensions/size.
   void setDimensions( const CoordinatesType& dimensions )
   {
      this->dimensions = dimensions;
   }

   //! \brief Returns the grid dimensions/size.
   const CoordinatesType& getDimensions() const
   {
      return dimensions;
   }

   //! \brief Sets the origin of the grid (coordinates of the left bottom front
   //! corner).
   void setOrigin( const PointType& origin )
   {
      this->origin = origin;
   }

   //! \brief Returns the origin of the grid (coordinates of the left bottom
   //! front corner).
   const PointType& getOrigin() const
   {
      return origin;
   }

   //! \brief Sets the domain of the grid (i.e., the origin and
   //! proportions/length). Note that space steps are computed using the
   //! current grid dimensions.
   void setDomain( const PointType& origin,
                   const PointType& proportions )
   {
      this->origin = origin;
      this->spaceSteps = proportions / dimensions;
   }

   //! \brief Sets the space steps of the grid, i.e. the parameters usually
   //! denoted as \e hx, \e hy, \e hz.
   void setSpaceSteps( const PointType& spaceSteps )
   {
      this->spaceSteps = spaceSteps;
   }

   //! \brief Returns the space steps of the grid.
   const PointType& getSpaceSteps() const
   {
      return spaceSteps;
   }

protected:
   CoordinatesType dimensions;

   PointType origin;

   PointType spaceSteps;
};

} // namespace Meshes
} // namespace TNL
+0 −2
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ class PVTIWriter
   // LOL, VTK does not support signed header types (but the GridTypeResolver maps unsigned types to signed, so we are good)
   using HeaderType = std::make_unsigned_t< typename Grid::GlobalIndexType >;
public:
   using MeshRealType = typename Grid::RealType;
   using IndexType = typename Grid::GlobalIndexType;

   PVTIWriter() = delete;

+8 −8
Original line number Diff line number Diff line
@@ -67,24 +67,24 @@ PVTIWriter< Grid >::writeImageData( const Grid& globalGrid,
   std::stringstream extent, origin, spacing;

   auto dims = globalGrid.getDimensions();
   for( IndexType j = 0; j < dims.getSize(); j++ )
   for( int j = 0; j < dims.getSize(); j++ )
      extent << "0 " << dims[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = dims.getSize(); j < 3; j++ )
   for( int j = dims.getSize(); j < 3; j++ )
      extent << "0 0 ";

   auto o = globalGrid.getOrigin();
   for( IndexType j = 0; j < o.getSize(); j++ )
   for( int j = 0; j < o.getSize(); j++ )
      origin << std::scientific << o[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = o.getSize(); j < 3; j++ )
   for( int j = o.getSize(); j < 3; j++ )
      origin << 0 << " ";

   auto h = globalGrid.getSpaceSteps();
   for( IndexType j = 0; j < h.getSize(); j++ )
   for( int j = 0; j < h.getSize(); j++ )
      spacing << std::scientific << h[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = h.getSize(); j < 3; j++ )
   for( int j = h.getSize(); j < 3; j++ )
      spacing << 0 << " ";

   str << "<PImageData"
@@ -177,10 +177,10 @@ PVTIWriter< Grid >::addPiece( const String& mainFileName,

   // prepare the extent
   std::stringstream extent;
   for( IndexType j = 0; j < Grid::getMeshDimension(); j++ )
   for( int j = 0; j < Grid::getMeshDimension(); j++ )
      extent << globalBegin[ j ] <<  " " << globalEnd[ j ] << " ";
   // VTK knows only 3D grids
   for( IndexType j = Grid::getMeshDimension(); j < 3; j++ )
   for( int j = Grid::getMeshDimension(); j < 3; j++ )
      extent << "0 0 ";

   namespace fs = std::experimental::filesystem;
+0 −2
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ class PVTUWriter
{
   using HeaderType = std::uint64_t;
public:
   using MeshRealType = typename Mesh::RealType;
   using IndexType = typename Mesh::GlobalIndexType;

   PVTUWriter() = delete;

+2 −5
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@

#include <type_traits>

#include <TNL/Meshes/Grid.h>
#include <TNL/Meshes/VTKTraits.h>

namespace TNL {
@@ -30,8 +29,6 @@ class VTIWriter
   // LOL, VTK does not support signed header types (but the GridTypeResolver maps unsigned types to signed, so we are good)
   using HeaderType = std::make_unsigned_t< typename Mesh::GlobalIndexType >;
public:
   using MeshRealType = typename Mesh::RealType;
   using IndexType = typename Mesh::GlobalIndexType;

   VTIWriter() = delete;

@@ -82,10 +79,10 @@ protected:
   VTK::FileFormat format;

   // number of points written to the file
   IndexType pointsCount = 0;
   std::uint64_t pointsCount = 0;

   // number of cells (in the VTK sense) written to the file
   IndexType cellsCount = 0;
   std::uint64_t cellsCount = 0;

   // indicator if the <VTKFile> tag is open
   bool vtkfileOpen = false;
Loading