Commit 04e2e098 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

[WIP] Fixed loading of VTK files in tnl-view and PDESolver

Needs refactoring!
parent 268acecd
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -110,5 +110,55 @@ bool resolveMeshType( const String& fileName_,
   }
}

// TODO: reorganize
template< typename Mesh >
bool
loadMesh( const String& fileName_, Mesh& mesh )
{
   std::cout << "Loading mesh from file " << fileName_ << " ..." << std::endl;
   std::string fileName( fileName_.getString() );
   bool status = true;

   if( ends_with( fileName, ".tnl" ) )
      status = mesh.load( fileName_ );
   else if( ends_with( fileName, ".ng" ) ) {
      Readers::NetgenReader reader;
      status = reader.readMesh( fileName_, mesh );
   }
   else if( ends_with( fileName, ".vtk" ) ) {
      Readers::VTKReader<> reader;
      status = reader.readMesh( fileName_, mesh );
   }
   else {
      std::cerr << "File '" << fileName << "' has unknown extension. Supported extensions are '.tnl', '.vtk' and '.ng'." << std::endl;
      return false;
   }

   if( ! status )
   {
      std::cerr << "I am not able to load the mesh from the file " << fileName_ << ". "
                   "Perhaps the mesh stored in the file is not supported by the mesh "
                   "passed to the loadMesh function? The mesh type is "
                << Mesh::getType() << std::endl;
      return false;
   }
   return true;
}

template< int Dimension, typename Real, typename Device, typename Index >
bool
loadMesh( const String& fileName, Grid< Dimension, Real, Device, Index >& mesh )
{
   std::cout << "Loading mesh from file " << fileName << " ..." << std::endl;
   if( ! mesh.load( fileName ) )
   {
      std::cerr << "I am not able to load the grid from the file " << fileName << ". "
                   "You may create it with tools like tnl-grid-setup."
                << std::endl;
      return false;
   }
   return true;
}

} // namespace Meshes
} // namespace TNL
+1 −8
Original line number Diff line number Diff line
@@ -62,15 +62,8 @@ setup( const Config::ParameterContainer& parameters,
    * Load the mesh from the mesh file
    */
   const String& meshFile = parameters.getParameter< String >( "mesh" );
   std::cout << "Loading a mesh from the file " << meshFile << "...";
   if( ! this->meshPointer->load( meshFile ) )
   {
      std::cerr << std::endl;
      std::cerr << "I am not able to load the mesh from the file " << meshFile << "." << std::endl;
      std::cerr << " You may create it with tools like tnl-grid-setup or tnl-mesh-convert." << std::endl;
   if( ! Meshes::loadMesh( meshFile, *meshPointer ) )
      return false;
   }
  std::cout << " [ OK ] " << std::endl;

   /****
    * Setup the problem
+17 −2
Original line number Diff line number Diff line
@@ -13,8 +13,23 @@ target_link_libraries (tnl-grid-setup tnl )
ADD_EXECUTABLE(tnl-init tnl-init.cpp )
target_link_libraries (tnl-init tnl )

ADD_EXECUTABLE(tnl-view tnl-view.cpp )
# TODO: refactoring, this is useful in multiple places
find_package( VTK )
if( VTK_FOUND )
   include(${VTK_USE_FILE})

   AddCompilerFlag( "-DHAVE_VTK " )

   add_executable(tnl-view tnl-view.cpp )

   target_link_libraries( tnl-view
                          vtkCommonCore
                          vtkIOLegacy
                          tnl )
else( VTK_FOUND )
   add_executable(tnl-view tnl-view.cpp )
   target_link_libraries (tnl-view tnl )
endif( VTK_FOUND )

ADD_EXECUTABLE(tnl-diff tnl-diff.cpp )
target_link_libraries (tnl-diff tnl )
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ template<> struct GridIndexTag< TNLViewBuildConfigTag, long int >{ enum { enable
 * Unstructured meshes.
 */
template<> struct MeshCellTopologyTag< TNLViewBuildConfigTag, MeshEdgeTopology > { enum { enabled = true }; };
template<> struct MeshCellTopologyTag< TNLViewBuildConfigTag, MeshTriangleTopology > { enum { enabled = true }; };
template<> struct MeshCellTopologyTag< TNLViewBuildConfigTag, MeshTetrahedronTopology > { enum { enabled = true }; };

// Meshes are enabled only for the world dimension equal to the cell dimension.
template< typename CellTopology, int WorldDimension >
+1 −4
Original line number Diff line number Diff line
@@ -424,11 +424,8 @@ struct FilesProcessor
      MeshPointer meshPointer;
      
      if( meshFile != "" )
         if( ! meshPointer->load( meshFile ) )
         {
            std::cerr << "I am not able to load mesh from the file " << meshFile << "." << std::endl;
         if( ! loadMesh( meshFile, *meshPointer ) )
            return false;
         }
      //meshPointer->writeMesh( "mesh.asy", "asymptote" );

      bool checkOutputFile = parameters. getParameter< bool >( "check-output-file" );