Skip to content
Snippets Groups Projects
Commit 8458e9cf authored by Tomas Sobotik's avatar Tomas Sobotik
Browse files

fast-sweeping-map solver added, narrow band in progress.

parent d8d67b1d
No related branches found
No related tags found
No related merge requests found
Showing
with 5062 additions and 0 deletions
......@@ -5,3 +5,4 @@ add_subdirectory( navier-stokes )
add_subdirectory( hamilton-jacobi-parallel )
add_subdirectory( fast-sweeping )
add_subdirectory( hamilton-jacobi-parallel-map )
add_subdirectory( fast-sweeping-map )
set( tnl_fast_sweeping_map_SOURCES
# MainBuildConfig.h
# tnlFastSweepingMap2D_impl.h
# tnlFastSweepingMap.h
# fastSweepingMapConfig.h
main.cpp)
IF( BUILD_CUDA )
CUDA_ADD_EXECUTABLE(fast-sweeping-map${debugExt} main.cu)
ELSE( BUILD_CUDA )
ADD_EXECUTABLE(fast-sweeping-map${debugExt} main.cpp)
ENDIF( BUILD_CUDA )
target_link_libraries (fast-sweeping-map${debugExt} tnl${debugExt}-${tnlVersion} )
INSTALL( TARGETS fast-sweeping-map${debugExt}
RUNTIME DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE )
#INSTALL( FILES ${tnl_fast_sweeping_map_SOURCES}
# DESTINATION share/tnl-${tnlVersion}/examples/fast-sweeping-map )
/***************************************************************************
MainBuildConfig.h - description
-------------------
begin : Jul 7, 2014
copyright : (C) 2014 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef MAINBUILDCONFIG_H_
#define MAINBUILDCONFIG_H_
#include <solvers/tnlBuildConfigTags.h>
class MainBuildConfig
{
public:
static void print() { cerr << "MainBuildConfig" << endl; }
};
/****
* Turn off support for float and long double.
*/
template<> struct tnlConfigTagReal< MainBuildConfig, float > { enum { enabled = false }; };
template<> struct tnlConfigTagReal< MainBuildConfig, long double > { enum { enabled = false }; };
/****
* Turn off support for short int and long int indexing.
*/
template<> struct tnlConfigTagIndex< MainBuildConfig, short int >{ enum { enabled = false }; };
template<> struct tnlConfigTagIndex< MainBuildConfig, long int >{ enum { enabled = false }; };
/****
* Use of tnlGrid is enabled for allowed dimensions and Real, Device and Index types.
*/
template< int Dimensions, typename Real, typename Device, typename Index >
struct tnlConfigTagMesh< MainBuildConfig, tnlGrid< Dimensions, Real, Device, Index > >
{ enum { enabled = tnlConfigTagDimensions< MainBuildConfig, Dimensions >::enabled &&
tnlConfigTagReal< MainBuildConfig, Real >::enabled &&
tnlConfigTagDevice< MainBuildConfig, Device >::enabled &&
tnlConfigTagIndex< MainBuildConfig, Index >::enabled }; };
/****
* Please, chose your preferred time discretisation here.
*/
template<> struct tnlConfigTagTimeDiscretisation< MainBuildConfig, tnlExplicitTimeDiscretisationTag >{ enum { enabled = true }; };
template<> struct tnlConfigTagTimeDiscretisation< MainBuildConfig, tnlSemiImplicitTimeDiscretisationTag >{ enum { enabled = false}; };
template<> struct tnlConfigTagTimeDiscretisation< MainBuildConfig, tnlImplicitTimeDiscretisationTag >{ enum { enabled = false }; };
/****
* Only the Runge-Kutta-Merson solver is enabled by default.
*/
template<> struct tnlConfigTagExplicitSolver< MainBuildConfig, tnlExplicitEulerSolverTag >{ enum { enabled = false }; };
#endif /* MAINBUILDCONFIG_H_ */
/***************************************************************************
fastSweepingConfig.h - description
-------------------
begin : Oct 15, 2015
copyright : (C) 2015 by Tomas Sobotik
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef FASTSWEEPINGCONFIG_H_
#define FASTSWEEPINGCONFIG_H_
#include <config/tnlConfigDescription.h>
template< typename ConfigTag >
class fastSweepingMapConfig
{
public:
static void configSetup( tnlConfigDescription& config )
{
config.addDelimiter( "Parallel Eikonal solver settings:" );
config.addEntry < tnlString > ( "problem-name", "This defines particular problem.", "fast-sweeping" );
config.addRequiredEntry < tnlString > ( "initial-condition", "Initial condition for solver");
config.addRequiredEntry < int > ( "dim", "Dimension of problem.");
config.addEntry < tnlString > ( "mesh", "Name of mesh.", "mesh.tnl" );
config.addEntry < tnlString > ( "exact-input", "Are the function values near the curve equal to the SDF? (yes/no)", "no" );
config.addRequiredEntry < tnlString > ( "map", "Gradient map for solver");
}
};
#endif /* FASTSWEEPINGCONFIG_H_ */
/***************************************************************************
main.cpp - description
-------------------
begin : Oct 15 , 2015
copyright : (C) 2015 by Tomas Sobotik
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "main.h"
/***************************************************************************
main.cpp - description
-------------------
begin : Oct 15 , 2015
copyright : (C) 2015 by Tomas Sobotik
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "main.h"
/***************************************************************************
main.h - description
-------------------
begin : Oct 15 , 2015
copyright : (C) 2015 by Tomas Sobotik
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "MainBuildConfig.h"
//for HOST versions:
//#include "tnlFastSweepingMap.h"
//for DEVICE versions:
#include "tnlFastSweepingMap_CUDA.h"
#include "fastSweepingMapConfig.h"
#include <solvers/tnlBuildConfigTags.h>
#include <mesh/tnlGrid.h>
#include <core/tnlDevice.h>
#include <time.h>
#include <ctime>
typedef MainBuildConfig BuildConfig;
int main( int argc, char* argv[] )
{
time_t start;
time_t stop;
time(&start);
std::clock_t start2= std::clock();
tnlParameterContainer parameters;
tnlConfigDescription configDescription;
fastSweepingMapConfig< BuildConfig >::configSetup( configDescription );
if( ! parseCommandLine( argc, argv, configDescription, parameters ) )
return false;
const int& dim = parameters.getParameter< int >( "dim" );
if(dim == 2)
{
tnlFastSweepingMap<tnlGrid<2,double,tnlHost, int>, double, int> solver;
if(!solver.init(parameters))
{
cerr << "Solver failed to initialize." << endl;
return EXIT_FAILURE;
}
checkCudaDevice;
cout << "-------------------------------------------------------------" << endl;
cout << "Starting solver..." << endl;
solver.run();
}
// else if(dim == 3)
// {
// tnlFastSweepingMap<tnlGrid<3,double,tnlHost, int>, double, int> solver;
// if(!solver.init(parameters))
// {
// cerr << "Solver failed to initialize." << endl;
// return EXIT_FAILURE;
// }
// checkCudaDevice;
// cout << "-------------------------------------------------------------" << endl;
// cout << "Starting solver..." << endl;
// solver.run();
// }
else
{
cerr << "Unsupported number of dimensions: " << dim << "!" << endl;
return EXIT_FAILURE;
}
time(&stop);
cout << "Solver stopped..." << endl;
cout << endl;
cout << "Running time was: " << difftime(stop,start) << " .... " << (std::clock() - start2) / (double)(CLOCKS_PER_SEC) << endl;
return EXIT_SUCCESS;
}
/***************************************************************************
tnlFastSweepingMap.h - description
-------------------
begin : Oct 15 , 2015
copyright : (C) 2015 by Tomas Sobotik
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef TNLFASTSWEEPING_H_
#define TNLFASTSWEEPING_H_
#include <config/tnlParameterContainer.h>
#include <core/vectors/tnlVector.h>
#include <core/vectors/tnlStaticVector.h>
#include <functions/tnlMeshFunction.h>
#include <core/tnlHost.h>
#include <mesh/tnlGrid.h>
#include <mesh/grids/tnlGridEntity.h>
#include <limits.h>
#include <core/tnlDevice.h>
#include <ctime>
#ifdef HAVE_OPENMP
#include <omp.h>
#endif
template< typename Mesh,
typename Real,
typename Index >
class tnlFastSweepingMap
{};
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
class tnlFastSweepingMap< tnlGrid< 2,MeshReal, Device, MeshIndex >, Real, Index >
{
public:
typedef Real RealType;
typedef Device DeviceType;
typedef Index IndexType;
typedef tnlGrid< 2, Real, Device, Index > MeshType;
typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType;
typedef typename MeshType::CoordinatesType CoordinatesType;
tnlFastSweepingMap();
static tnlString getType();
bool init( const tnlParameterContainer& parameters );
bool initGrid();
bool run();
//for single core version use this implementation:
void updateValue(const Index i, const Index j);
//for parallel version use this one instead:
// void updateValue(const Index i, const Index j, DofVectorType* grid);
void setupSquare1000(Index i, Index j);
void setupSquare1100(Index i, Index j);
void setupSquare1010(Index i, Index j);
void setupSquare1001(Index i, Index j);
void setupSquare1110(Index i, Index j);
void setupSquare1101(Index i, Index j);
void setupSquare1011(Index i, Index j);
void setupSquare1111(Index i, Index j);
void setupSquare0000(Index i, Index j);
void setupSquare0100(Index i, Index j);
void setupSquare0010(Index i, Index j);
void setupSquare0001(Index i, Index j);
void setupSquare0110(Index i, Index j);
void setupSquare0101(Index i, Index j);
void setupSquare0011(Index i, Index j);
void setupSquare0111(Index i, Index j);
Real fabsMin(const Real x, const Real y);
protected:
MeshType Mesh;
bool exactInput;
tnlMeshFunction<MeshType> dofVector, dofVector2;
DofVectorType data;
RealType h;
tnlGridEntity< MeshType, 2, tnlGridEntityNoStencilStorage > Entity;
#ifdef HAVE_OPENMP
// omp_lock_t* gridLock;
#endif
};
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
class tnlFastSweepingMap< tnlGrid< 3,MeshReal, Device, MeshIndex >, Real, Index >
{
public:
typedef Real RealType;
typedef Device DeviceType;
typedef Index IndexType;
typedef tnlGrid< 3, Real, Device, Index > MeshType;
typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType;
typedef typename MeshType::CoordinatesType CoordinatesType;
tnlFastSweepingMap();
static tnlString getType();
bool init( const tnlParameterContainer& parameters );
bool initGrid();
bool run();
//for single core version use this implementation:
void updateValue(const Index i, const Index j, const Index k);
//for parallel version use this one instead:
// void updateValue(const Index i, const Index j, DofVectorType* grid);
Real fabsMin(const Real x, const Real y);
protected:
MeshType Mesh;
bool exactInput;
tnlMeshFunction<MeshType> dofVector, dofVector2;
DofVectorType data;
RealType h;
tnlGridEntity< MeshType, 3, tnlGridEntityNoStencilStorage > Entity;
#ifdef HAVE_OPENMP
// omp_lock_t* gridLock;
#endif
};
//for single core version use this implementation:
#include "tnlFastSweepingMap2D_impl.h"
//for parallel version use this one instead:
// #include "tnlFastSweepingMap2D_openMP_impl.h"
// #include "tnlFastSweepingMap3D_impl.h"
#endif /* TNLFASTSWEEPING_H_ */
This diff is collapsed.
This diff is collapsed.
/***************************************************************************
tnlFastSweepingMap_CUDA.h - description
-------------------
begin : Oct 15 , 2015
copyright : (C) 2015 by Tomas Sobotik
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef TNLFASTSWEEPING_H_
#define TNLFASTSWEEPING_H_
#include <config/tnlParameterContainer.h>
#include <core/vectors/tnlVector.h>
#include <core/vectors/tnlStaticVector.h>
#include <core/tnlHost.h>
#include <mesh/tnlGrid.h>
#include <mesh/grids/tnlGridEntity.h>
#include <functions/tnlMeshFunction.h>
#include <limits.h>
#include <core/tnlDevice.h>
#include <ctime>
template< typename Mesh,
typename Real,
typename Index >
class tnlFastSweepingMap
{};
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
class tnlFastSweepingMap< tnlGrid< 2,MeshReal, Device, MeshIndex >, Real, Index >
{
public:
typedef Real RealType;
typedef Device DeviceType;
typedef Index IndexType;
typedef tnlGrid< 2, Real, Device, Index > MeshType;
typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType;
typedef typename MeshType::CoordinatesType CoordinatesType;
tnlFastSweepingMap();
__host__ static tnlString getType();
__host__ bool init( const tnlParameterContainer& parameters );
__host__ bool run();
#ifdef HAVE_CUDA
__device__ bool initGrid();
__device__ void updateValue(const Index i, const Index j, Index* something_changed);
__device__ void updateValue(const Index i, const Index j, double** sharedMem, const int k3);
__device__ Real fabsMin(const Real x, const Real y);
tnlFastSweepingMap< tnlGrid< 2,MeshReal, Device, MeshIndex >, Real, Index >* cudaSolver;
double* cudaDofVector;
double* cudaDofVector2;
double* map_cuda;
int counter;
int* changed;
__device__ void setupSquare1000(Index i, Index j);
__device__ void setupSquare1100(Index i, Index j);
__device__ void setupSquare1010(Index i, Index j);
__device__ void setupSquare1001(Index i, Index j);
__device__ void setupSquare1110(Index i, Index j);
__device__ void setupSquare1101(Index i, Index j);
__device__ void setupSquare1011(Index i, Index j);
__device__ void setupSquare1111(Index i, Index j);
__device__ void setupSquare0000(Index i, Index j);
__device__ void setupSquare0100(Index i, Index j);
__device__ void setupSquare0010(Index i, Index j);
__device__ void setupSquare0001(Index i, Index j);
__device__ void setupSquare0110(Index i, Index j);
__device__ void setupSquare0101(Index i, Index j);
__device__ void setupSquare0011(Index i, Index j);
__device__ void setupSquare0111(Index i, Index j);
#endif
MeshType Mesh;
protected:
bool exactInput;
tnlMeshFunction<MeshType> dofVector;
DofVectorType data, map;
RealType h;
};
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
class tnlFastSweepingMap< tnlGrid< 3,MeshReal, Device, MeshIndex >, Real, Index >
{
public:
typedef Real RealType;
typedef Device DeviceType;
typedef Index IndexType;
typedef tnlGrid< 3, Real, Device, Index > MeshType;
typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType;
typedef typename MeshType::CoordinatesType CoordinatesType;
__host__ static tnlString getType();
__host__ bool init( const tnlParameterContainer& parameters );
__host__ bool run();
#ifdef HAVE_CUDA
__device__ bool initGrid(int i, int j, int k);
__device__ void updateValue(const Index i, const Index j, const Index k);
__device__ void updateValue(const Index i, const Index j, const Index k, double** sharedMem, const int k3);
__device__ Real fabsMin(const Real x, const Real y);
tnlFastSweepingMap< tnlGrid< 3,MeshReal, Device, MeshIndex >, Real, Index >* cudaSolver;
double* cudaDofVector;
double* cudaDofVector2;
int counter;
#endif
MeshType Mesh;
protected:
bool exactInput;
tnlMeshFunction<MeshType> dofVector;
DofVectorType data;
RealType h;
};
#ifdef HAVE_CUDA
//template<int sweep_t>
__global__ void runCUDA(tnlFastSweepingMap< tnlGrid< 2,double, tnlHost, int >, double, int >* solver, int sweep, int i, int* changed);
//__global__ void runCUDA(tnlFastSweepingMap< tnlGrid< 3,double, tnlHost, int >, double, int >* solver, int sweep, int i);
__global__ void initCUDA(tnlFastSweepingMap< tnlGrid< 2,double, tnlHost, int >, double, int >* solver);
//__global__ void initCUDA(tnlFastSweepingMap< tnlGrid< 3,double, tnlHost, int >, double, int >* solver);
#endif
/*various implementtions.... choose one*/
//#include "tnlFastSweepingMap2D_CUDA_impl.h"
//#include "tnlFastSweepingMap2D_CUDA_v2_impl.h"
//#include "tnlFastSweepingMap2D_CUDA_v3_impl.h"
#include "tnlFastSweepingMap2D_CUDA_v4_impl.h"
//#include "tnlFastSweepingMap2D_CUDA_v5_impl.h"
// #include "tnlFastSweepingMap3D_CUDA_impl.h"
#endif /* TNLFASTSWEEPING_H_ */
set( tnl_fast_sweeping_SOURCES
# MainBuildConfig.h
# tnlFastSweeping2D_impl.h
# tnlFastSweeping.h
# fastSweepingConfig.h
main.cpp)
IF( BUILD_CUDA )
CUDA_ADD_EXECUTABLE(fast-sweeping${debugExt} main.cu)
ELSE( BUILD_CUDA )
ADD_EXECUTABLE(fast-sweeping${debugExt} main.cpp)
ENDIF( BUILD_CUDA )
target_link_libraries (fast-sweeping${debugExt} tnl${debugExt}-${tnlVersion} )
INSTALL( TARGETS fast-sweeping${debugExt}
RUNTIME DESTINATION bin
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE )
#INSTALL( FILES ${tnl_fast_sweeping_SOURCES}
# DESTINATION share/tnl-${tnlVersion}/examples/fast-sweeping )
/***************************************************************************
MainBuildConfig.h - description
-------------------
begin : Jul 7, 2014
copyright : (C) 2014 by Tomas Oberhuber
email : tomas.oberhuber@fjfi.cvut.cz
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef MAINBUILDCONFIG_H_
#define MAINBUILDCONFIG_H_
#include <solvers/tnlBuildConfigTags.h>
class MainBuildConfig
{
public:
static void print() { cerr << "MainBuildConfig" << endl; }
};
/****
* Turn off support for float and long double.
*/
template<> struct tnlConfigTagReal< MainBuildConfig, float > { enum { enabled = false }; };
template<> struct tnlConfigTagReal< MainBuildConfig, long double > { enum { enabled = false }; };
/****
* Turn off support for short int and long int indexing.
*/
template<> struct tnlConfigTagIndex< MainBuildConfig, short int >{ enum { enabled = false }; };
template<> struct tnlConfigTagIndex< MainBuildConfig, long int >{ enum { enabled = false }; };
/****
* Use of tnlGrid is enabled for allowed dimensions and Real, Device and Index types.
*/
template< int Dimensions, typename Real, typename Device, typename Index >
struct tnlConfigTagMesh< MainBuildConfig, tnlGrid< Dimensions, Real, Device, Index > >
{ enum { enabled = tnlConfigTagDimensions< MainBuildConfig, Dimensions >::enabled &&
tnlConfigTagReal< MainBuildConfig, Real >::enabled &&
tnlConfigTagDevice< MainBuildConfig, Device >::enabled &&
tnlConfigTagIndex< MainBuildConfig, Index >::enabled }; };
/****
* Please, chose your preferred time discretisation here.
*/
template<> struct tnlConfigTagTimeDiscretisation< MainBuildConfig, tnlExplicitTimeDiscretisationTag >{ enum { enabled = true }; };
template<> struct tnlConfigTagTimeDiscretisation< MainBuildConfig, tnlSemiImplicitTimeDiscretisationTag >{ enum { enabled = false}; };
template<> struct tnlConfigTagTimeDiscretisation< MainBuildConfig, tnlImplicitTimeDiscretisationTag >{ enum { enabled = false }; };
/****
* Only the Runge-Kutta-Merson solver is enabled by default.
*/
template<> struct tnlConfigTagExplicitSolver< MainBuildConfig, tnlExplicitEulerSolverTag >{ enum { enabled = false }; };
#endif /* MAINBUILDCONFIG_H_ */
/***************************************************************************
main.cpp - description
-------------------
begin : Oct 15 , 2015
copyright : (C) 2015 by Tomas Sobotik
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "main.h"
/***************************************************************************
main.cpp - description
-------------------
begin : Oct 15 , 2015
copyright : (C) 2015 by Tomas Sobotik
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "main.h"
/***************************************************************************
main.h - description
-------------------
begin : Oct 15 , 2015
copyright : (C) 2015 by Tomas Sobotik
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "MainBuildConfig.h"
//for HOST versions:
//#include "tnlNarrowBand.h"
//for DEVICE versions:
#include "tnlNarrowBand_CUDA.h"
#include "narrowBandConfig.h"
#include <solvers/tnlBuildConfigTags.h>
#include <mesh/tnlGrid.h>
#include <core/tnlDevice.h>
#include <time.h>
#include <ctime>
typedef MainBuildConfig BuildConfig;
int main( int argc, char* argv[] )
{
time_t start;
time_t stop;
time(&start);
std::clock_t start2= std::clock();
tnlParameterContainer parameters;
tnlConfigDescription configDescription;
narrowBandConfig< BuildConfig >::configSetup( configDescription );
if( ! parseCommandLine( argc, argv, configDescription, parameters ) )
return false;
const int& dim = parameters.getParameter< int >( "dim" );
if(dim == 2)
{
tnlNarrowBand<tnlGrid<2,double,tnlHost, int>, double, int> solver;
if(!solver.init(parameters))
{
cerr << "Solver failed to initialize." << endl;
return EXIT_FAILURE;
}
checkCudaDevice;
cout << "-------------------------------------------------------------" << endl;
cout << "Starting solver..." << endl;
solver.run();
}
// else if(dim == 3)
// {
// tnlNarrowBand<tnlGrid<3,double,tnlHost, int>, double, int> solver;
// if(!solver.init(parameters))
// {
// cerr << "Solver failed to initialize." << endl;
// return EXIT_FAILURE;
// }
// checkCudaDevice;
// cout << "-------------------------------------------------------------" << endl;
// cout << "Starting solver..." << endl;
// solver.run();
// }
else
{
cerr << "Unsupported number of dimensions: " << dim << "!" << endl;
return EXIT_FAILURE;
}
time(&stop);
cout << "Solver stopped..." << endl;
cout << endl;
cout << "Running time was: " << difftime(stop,start) << " .... " << (std::clock() - start2) / (double)(CLOCKS_PER_SEC) << endl;
return EXIT_SUCCESS;
}
/***************************************************************************
narrowBandConfig.h - description
-------------------
begin : Oct 15, 2015
copyright : (C) 2015 by Tomas Sobotik
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef NARROWBANDCONFIG_H_
#define NARROWBANDCONFIG_H_
#include <config/tnlConfigDescription.h>
template< typename ConfigTag >
class narrowBandConfig
{
public:
static void configSetup( tnlConfigDescription& config )
{
config.addDelimiter( "Parallel Eikonal solver settings:" );
config.addEntry < tnlString > ( "problem-name", "This defines particular problem.", "fast-sweeping" );
config.addRequiredEntry < tnlString > ( "initial-condition", "Initial condition for solver");
config.addRequiredEntry < int > ( "dim", "Dimension of problem.");
config.addRequiredEntry < double > ( "tau", "Time step.");
config.addRequiredEntry < double > ( "final-time", "Final time.");
config.addEntry < tnlString > ( "mesh", "Name of mesh.", "mesh.tnl" );
config.addEntry < tnlString > ( "exact-input", "Are the function values near the curve equal to the SDF? (yes/no)", "no" );
}
};
#endif /* NARROWBANDCONFIG_H_ */
/***************************************************************************
tnlNarrowBand.h - description
-------------------
begin : Oct 15 , 2015
copyright : (C) 2015 by Tomas Sobotik
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef TNLNARROWBAND_H_
#define TNLNARROWBAND_H_
#include <config/tnlParameterContainer.h>
#include <core/vectors/tnlVector.h>
#include <core/vectors/tnlStaticVector.h>
#include <functions/tnlMeshFunction.h>
#include <core/tnlHost.h>
#include <mesh/tnlGrid.h>
#include <mesh/grids/tnlGridEntity.h>
#include <limits.h>
#include <core/tnlDevice.h>
#include <ctime>
#ifdef HAVE_OPENMP
#include <omp.h>
#endif
template< typename Mesh,
typename Real,
typename Index >
class tnlNarrowBand
{};
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
class tnlNarrowBand< tnlGrid< 2,MeshReal, Device, MeshIndex >, Real, Index >
{
public:
typedef Real RealType;
typedef Device DeviceType;
typedef Index IndexType;
typedef tnlGrid< 2, Real, Device, Index > MeshType;
typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType;
typedef typename MeshType::CoordinatesType CoordinatesType;
tnlNarrowBand();
static tnlString getType();
bool init( const tnlParameterContainer& parameters );
bool initGrid();
bool run();
//for single core version use this implementation:
void updateValue(const Index i, const Index j);
//for parallel version use this one instead:
// void updateValue(const Index i, const Index j, DofVectorType* grid);
void setupSquare1000(Index i, Index j);
void setupSquare1100(Index i, Index j);
void setupSquare1010(Index i, Index j);
void setupSquare1001(Index i, Index j);
void setupSquare1110(Index i, Index j);
void setupSquare1101(Index i, Index j);
void setupSquare1011(Index i, Index j);
void setupSquare1111(Index i, Index j);
void setupSquare0000(Index i, Index j);
void setupSquare0100(Index i, Index j);
void setupSquare0010(Index i, Index j);
void setupSquare0001(Index i, Index j);
void setupSquare0110(Index i, Index j);
void setupSquare0101(Index i, Index j);
void setupSquare0011(Index i, Index j);
void setupSquare0111(Index i, Index j);
Real fabsMin(const Real x, const Real y);
protected:
MeshType Mesh;
bool exactInput;
tnlMeshFunction<MeshType> dofVector, dofVector2;
DofVectorType data;
RealType h;
tnlGridEntity< MeshType, 2, tnlGridEntityNoStencilStorage > Entity;
#ifdef HAVE_OPENMP
// omp_lock_t* gridLock;
#endif
};
template< typename MeshReal,
typename Device,
typename MeshIndex,
typename Real,
typename Index >
class tnlNarrowBand< tnlGrid< 3,MeshReal, Device, MeshIndex >, Real, Index >
{
public:
typedef Real RealType;
typedef Device DeviceType;
typedef Index IndexType;
typedef tnlGrid< 3, Real, Device, Index > MeshType;
typedef tnlVector< RealType, DeviceType, IndexType> DofVectorType;
typedef typename MeshType::CoordinatesType CoordinatesType;
tnlNarrowBand();
static tnlString getType();
bool init( const tnlParameterContainer& parameters );
bool initGrid();
bool run();
//for single core version use this implementation:
void updateValue(const Index i, const Index j, const Index k);
//for parallel version use this one instead:
// void updateValue(const Index i, const Index j, DofVectorType* grid);
Real fabsMin(const Real x, const Real y);
protected:
MeshType Mesh;
bool exactInput;
tnlMeshFunction<MeshType> dofVector, dofVector2;
DofVectorType data;
RealType h;
tnlGridEntity< MeshType, 3, tnlGridEntityNoStencilStorage > Entity;
#ifdef HAVE_OPENMP
// omp_lock_t* gridLock;
#endif
};
//for single core version use this implementation:
#include "tnlNarrowBand2D_impl.h"
//for parallel version use this one instead:
// #include "tnlNarrowBand2D_openMP_impl.h"
#include "tnlNarrowBand3D_impl.h"
#endif /* TNLNARROWBAND_H_ */
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment