Commit 5d9c6f79 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Added tnl-lattice-init.

parent 8a1d5730
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ target_link_libraries (tnl-image-converter tnl ${PNG_LIBRARIES} ${JPEG_LIBRARIES
ADD_EXECUTABLE(tnl-dicom-reader tnl-dicom-reader.cpp )
target_link_libraries (tnl-dicom-reader tnl ${DCMTK_LIBRARIES} )

ADD_EXECUTABLE(tnl-lattice-init tnl-lattice-init.cpp )
target_link_libraries (tnl-lattice-init tnl )

ADD_EXECUTABLE( tnl-functions-benchmark functions-benchmark.cpp )
target_link_libraries( tnl-functions-benchmark tnl )

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

/* See Copyright Notice in tnl/Copyright */

#ifndef TNL_INIT_H_
#define TNL_INIT_H_
#pragma once 

#include <TNL/Config/ParameterContainer.h>
#include <TNL/Containers/Vector.h>
@@ -323,6 +322,3 @@ bool resolveMeshType( const Containers::List< String >& parsedMeshType,

   return false;
}
 No newline at end of file


#endif /* TNL_INIT_H_ */
+73 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnl-lattice-init.cpp  -  description
                             -------------------
    begin                : Jun 13, 2018
    copyright            : (C) 2018 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#include "tnl-lattice-init.h"

#include <TNL/Config/ConfigDescription.h>
#include <TNL/Config/ParameterContainer.h>


using namespace TNL;

void setupConfig( Config::ConfigDescription& config )
{
   config.addDelimiter                            ( "General settings:" );
   config.addEntry< String >( "mesh", "Mesh file of the 3D lattice.", "mesh.tnl" );
   config.addEntry< String >( "real-type", "Precision of the function evaluation.", "mesh-real-type" );
      config.addEntryEnum< String >( "mesh-real-type" );
      config.addEntryEnum< String >( "float" );
      config.addEntryEnum< String >( "double" );
      config.addEntryEnum< String >( "long-double" );
   config.addEntry< String >( "profile-mesh", "Mesh file of the 2D mesh function with geometry profile", "profile-mesh.tnl" );
   config.addEntry< String >( "profile-file", "The profile mesh function file.", "profile.tnl" );
   config.addEntry< String >( "output-file", "Output 3D mesh function file.", "init.tnl" );
   config.addEntry< String >( "operation", "Operation to be done with the profile.", "extrude" );
      config.addEntryEnum< String >( "extrude" );
   config.addEntry< String >( "profile-orientation", "Axis the profile is orthogonal to.", "z" );
      config.addEntryEnum< String >( "x" );
      config.addEntryEnum< String >( "y" );
      config.addEntryEnum< String >( "z" );
   config.addEntry< double >( "extrude-start", "Position where the extrude operation starts.", 0.0 );
   config.addEntry< double >( "extrude-stop", "Position where the extrude operation stops.", 1.0 );
}



int main( int argc, char* argv[] )
{

   Config::ParameterContainer parameters;
   Config::ConfigDescription configDescription;

   setupConfig( configDescription );
   

   if( ! parseCommandLine( argc, argv, configDescription, parameters ) )
      return EXIT_FAILURE;
   
   String meshFile = parameters. getParameter< String >( "mesh" );
   String meshType;
   if( ! getObjectType( meshFile, meshType ) )
   {
      std::cerr << "I am not able to detect the mesh type from the file " << meshFile << "." << std::endl;
      return EXIT_FAILURE;
   }
   std::cout << meshType << " detected in " << meshFile << " file." << std::endl;
   Containers::List< String > parsedMeshType;
   if( ! parseObjectType( meshType, parsedMeshType ) )
   {
      std::cerr << "Unable to parse the mesh type " << meshType << "." << std::endl;
      return EXIT_FAILURE;
   }
   if( ! resolveMeshType( parsedMeshType, parameters ) )
      return EXIT_FAILURE;

   return EXIT_SUCCESS;   
}
 No newline at end of file
+99 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnl-lattice-init.cpp  -  description
                             -------------------
    begin                : Jun 13, 2018
    copyright            : (C) 2018 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

#include <TNL/Config/ParameterContainer.h>

template< typename Mesh, typename Real >
bool resolveProfileMesh( const Config::ParameterContainer& parameters )
{
   
}

template< typename MeshType >
bool resolveRealType( const Config::ParameterContainer& parameters )
{
   String realType = parameters.getParameter< String >( "real-type" );
   if( realType == "mesh-real-type" )
      return resolveProfileMesh< MeshType, typename MeshType::RealType >( parameters );
   if( realType == "float" )
      return resolveProfileMesh< MeshType, float >( parameters );
   if( realType == "double" )
      return resolveProfileMesh< MeshType, double >( parameters );
   if( realType == "long-double" )
      return resolveProfileMesh< MeshType, long double >( parameters );
   return false;
}

template< int Dimension, typename RealType, typename IndexType >
bool resolveMesh( const Containers::List< String >& parsedMeshType,
                  const Config::ParameterContainer& parameters )
{
  std::cout << "+ -> Setting mesh type to " << parsedMeshType[ 0 ] << " ... " << std::endl;
   if( parsedMeshType[ 0 ] == "Meshes::Grid" ||
       parsedMeshType[ 0 ] == "tnlGrid" )  // TODO: remove deprecated type name
   {
      typedef Meshes::Grid< Dimension, RealType, Devices::Host, IndexType > MeshType;
      return resolveRealType< MeshType >( parameters );
   }
   std::cerr << "Unknown mesh type." << std::endl;
   return false;
}

template< int Dimension, typename RealType >
bool resolveIndexType( const Containers::List< String >& parsedMeshType,
                       const Config::ParameterContainer& parameters )
{
  std::cout << "+ -> Setting index type to " << parsedMeshType[ 4 ] << " ... " << std::endl;
   if( parsedMeshType[ 4 ] == "int" )
      return resolveMesh< Dimension, RealType, int >( parsedMeshType, parameters );

   if( parsedMeshType[ 4 ] == "long int" )
      return resolveMesh< Dimension, RealType, long int >( parsedMeshType, parameters );

   return false;
}

template< int Dimension >
bool resolveRealType( const Containers::List< String >& parsedMeshType,
                      const Config::ParameterContainer& parameters )
{
  std::cout << "+ -> Setting real type to " << parsedMeshType[ 2 ] << " ... " << std::endl;
   if( parsedMeshType[ 2 ] == "float" )
      return resolveIndexType< Dimension, float >( parsedMeshType, parameters );

   if( parsedMeshType[ 2 ] == "double" )
      return resolveIndexType< Dimension, double >( parsedMeshType, parameters );

   if( parsedMeshType[ 2 ] == "long-double" )
      return resolveIndexType< Dimension, long double >( parsedMeshType, parameters );

   return false;
}

bool resolveMeshType( const Containers::List< String >& parsedMeshType,
                      const Config::ParameterContainer& parameters )
{
  std::cout << "+ -> Setting dimensions to " << parsedMeshType[ 1 ] << " ... " << std::endl;
   int dimensions = atoi( parsedMeshType[ 1 ].getString() );

   if( dimensions == 1 )
      return resolveRealType< 1 >( parsedMeshType, parameters );

   if( dimensions == 2 )
      return resolveRealType< 2 >( parsedMeshType, parameters );


   if( dimensions == 3 )
      return resolveRealType< 3 >( parsedMeshType, parameters );

   return false;
}
 No newline at end of file