Commit 0c5f7db7 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Adding analytic operators to test function.

parent 57aa7d99
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
ADD_SUBDIRECTORY( Operators )
ADD_SUBDIRECTORY( Solvers )
#ADD_SUBDIRECTORY( Solvers )
+103 −88
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ class TestFunction : public Domain< FunctionDimensions, SpaceDomain >
                            quadratic,
                            cosine };

      enum Operators { identity,
                       heaviside };

   public:

      enum{ Dimensions = FunctionDimensions };
@@ -115,9 +118,17 @@ class TestFunction : public Domain< FunctionDimensions, SpaceDomain >
      bool setupFunction( const Config::ParameterContainer& parameters,
                         const String& prefix = "" );
      
      template< typename OperatorType >
      bool setupOperator( const Config::ParameterContainer& parameters,
                          const String& prefix = "" );


      template< typename FunctionType >
      void deleteFunction();

      template< typename OperatorType >
      void deleteOperator();

      void deleteFunctions();

      template< typename FunctionType >
@@ -128,8 +139,12 @@ class TestFunction : public Domain< FunctionDimensions, SpaceDomain >

      void* function;

      void* operator_;

      TestFunctions functionType;
      
      Operators operatorType;

      TimeDependence timeDependence;

      Real timeScale;
+205 −27
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@
#include <TNL/Functions/Analytic/SinWaveSDF.h>
#include <TNL/Functions/Analytic/ParaboloidSDF.h>

#include <TNL/Operators/Analytic/Identity.h>
#include <TNL/Operators/Analytic/Heaviside.h>

namespace TNL {
namespace Functions {   

@@ -42,6 +45,7 @@ template< int FunctionDimensions,
TestFunction< FunctionDimensions, Real, Device >::
TestFunction()
: function( 0 ),
  operator_( 0 ),
  timeDependence( none ),
  timeScale( 1.0 )
{
@@ -69,6 +73,7 @@ configSetup( Config::ConfigDescription& config,
      config.addEntryEnum( "paraboloid-sdf" );      
      config.addEntryEnum( "sin-wave-sdf" );
      config.addEntryEnum( "sin-bumps-sdf" );
      config.addEntryEnum( "heaviside-of-paraboloid" );

   config.addEntry     < double >( prefix + "constant", "Value of the constant function.", 0.0 );
   config.addEntry     < double >( prefix + "wave-length", "Wave length of the sine based test functions.", 1.0 );
@@ -131,6 +136,36 @@ setupFunction( const Config::ParameterContainer& parameters,
   return true;
}

template< int FunctionDimensions,
          typename Real,
          typename Device >
   template< typename OperatorType >
bool
TestFunction< FunctionDimensions, Real, Device >::
setupOperator( const Config::ParameterContainer& parameters,
               const String& prefix )
{
   OperatorType* auxOperator = new OperatorType;
   if( ! auxOperator->setup( parameters, prefix ) )
   {
      delete auxOperator;
      return false;
   }

   if( std::is_same< Device, Devices::Host >::value )
   {
      this->operator_ = auxOperator;
   }
   if( std::is_same< Device, Devices::Cuda >::value )
   {
      this->operator_ = Devices::Cuda::passToDevice( *auxOperator );
      delete auxOperator;
      if( ! checkCudaDevice )
         return false;
   }
   return true;
}

template< int FunctionDimensions,
          typename Real,
          typename Device >
@@ -140,6 +175,7 @@ setup( const Config::ParameterContainer& parameters,
       const String& prefix )
{
   using namespace TNL::Functions::Analytic;
   using namespace TNL::Operators::Analytic;
   std::cout << "Test function setup ... " << std::endl;
   const String& timeDependence =
            parameters.getParameter< String >(
@@ -161,63 +197,129 @@ setup( const Config::ParameterContainer& parameters,
   std::cout << "Test function ... " << testFunction << std::endl;
   if( testFunction == "constant" )
   {
      typedef Analytic::Constant< Dimensions, Real > FunctionType;
      typedef Constant< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = constant;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "paraboloid" )
   {
      typedef Paraboloid< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = paraboloid;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }   
   if( testFunction == "exp-bump" )
   {
      typedef ExpBump< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = expBump;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "sin-bumps" )
   {
      typedef SinBumps< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = sinBumps;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "sin-wave" )
   {
      typedef SinWave< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = sinWave;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "cylinder" )
   {
      typedef Cylinder< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = cylinder;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "flowerpot" )
   {
      typedef Flowerpot< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = flowerpot;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "twins" )
   {
      typedef Twins< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = twins;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "pseudoSquare" )
   {
      typedef PseudoSquare< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = pseudoSquare;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "blob" )
   {
      typedef Blob< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = blob;
      return setupFunction< FunctionType >( parameters );
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "paraboloid-sdf" )
   {
      typedef ParaboloidSDF< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = paraboloidSDF;
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }   
   if( testFunction == "sin-bumps-sdf" )
   {
      typedef SinBumpsSDF< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = sinBumpsSDF;
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }   
   if( testFunction == "sin-wave-sdf" )
   {
      typedef SinWaveSDF< Dimensions, Real > FunctionType;
      typedef Identity< FunctionType > OperatorType;
      functionType = sinWaveSDF;
      operatorType = identity;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   if( testFunction == "heaviside-of-paraboloid" )
   {
      typedef Paraboloid< Dimensions, Real > FunctionType;
      typedef Heaviside< FunctionType > OperatorType;
      functionType = paraboloid;
      operatorType = heaviside;
      return ( setupFunction< FunctionType >( parameters, prefix ) && 
               setupOperator< OperatorType >( parameters, prefix ) );
   }
   std::cerr << "Unknown function " << testFunction << std::endl;
   return false;
@@ -452,6 +554,26 @@ deleteFunction()
   }
}

template< int FunctionDimensions,
          typename Real,
          typename Device >
   template< typename OperatorType >
void
TestFunction< FunctionDimensions, Real, Device >::
deleteOperator()
{
   if( std::is_same< Device, Devices::Host >::value )
   {
      if( operator_ )
         delete ( OperatorType * ) operator_;
   }
   if( std::is_same< Device, Devices::Cuda >::value )
   {
      if( operator_ )
         Devices::Cuda::freeFromDevice( ( OperatorType * ) operator_ );
   }
}

template< int FunctionDimensions,
          typename Real,
          typename Device >
@@ -460,50 +582,106 @@ TestFunction< FunctionDimensions, Real, Device >::
deleteFunctions()
{
   using namespace TNL::Functions::Analytic;
   using namespace TNL::Operators::Analytic;
   switch( functionType )
   {
      case constant:
         deleteFunction< Constant< Dimensions, Real> >();
      {
         typedef Constant< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case paraboloid:
         deleteFunction< Paraboloid< Dimensions, Real> >();
      {
         typedef Paraboloid< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         if( operatorType == identity )
            deleteOperator< Identity< FunctionType> >();
         if( operatorType == heaviside )
            deleteOperator< Heaviside< FunctionType> >();
         break;
      }
      case expBump:
         deleteFunction< ExpBump< Dimensions, Real> >();
      {
         typedef ExpBump< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case sinBumps:
         deleteFunction< SinBumps< Dimensions, Real> >();
      {
         typedef SinBumps< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case sinWave:
         deleteFunction< SinWave< Dimensions, Real> >();
      {
         typedef SinWave< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case cylinder:
         deleteFunction< Cylinder< Dimensions, Real> >();
      {
         typedef Cylinder< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case flowerpot:
         deleteFunction< Flowerpot< Dimensions, Real> >();
      {
         typedef Flowerpot< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case twins:
         deleteFunction< Twins< Dimensions, Real> >();
      {
         typedef Twins< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case pseudoSquare:
         deleteFunction< PseudoSquare< Dimensions, Real> >();
      {
         typedef PseudoSquare< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case blob:
         deleteFunction< Blob< Dimensions, Real> >();
      {
         typedef Blob< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      
      case paraboloidSDF:
         deleteFunction< ParaboloidSDF< Dimensions, Real> >();
      {
         typedef ParaboloidSDF< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case sinBumpsSDF:
         deleteFunction< SinBumpsSDF< Dimensions, Real> >();
      {
         typedef SinBumpsSDF< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
      case sinWaveSDF:
         deleteFunction< SinWaveSDF< Dimensions, Real> >();
      {
         typedef SinWaveSDF< Dimensions, Real> FunctionType;
         deleteFunction< FunctionType >();
         deleteOperator< Identity< FunctionType> >();
         break;
      }
   }
}

template< int FunctionDimensions,
          typename Real,
+1 −0
Original line number Diff line number Diff line
SET( headers Sign.h
             Heaviside.h
             Identity.h
             SmoothHeaviside.h
             Shift.h
             Rotation.h )
+8 −4
Original line number Diff line number Diff line
@@ -19,13 +19,13 @@ namespace Analytic {
   
   
template< typename Function >
class Heaviside : public Functions::Domain< Function::getDomainDimenions(), 
                                            Function::getDomainTyep() >
class Heaviside : public Functions::Domain< Function::getDomainDimensions(), 
                                            Function::getDomainType() >
{
   public:
      
      typedef typename Function::RealType RealType;
      typedef Containers::StaticVector< Function::getDomainDimenions(), 
      typedef Containers::StaticVector< Function::getDomainDimensions(), 
                                        RealType > VertexType;
      
      __cuda_callable__
@@ -33,9 +33,13 @@ class Heaviside : public Functions::Domain< Function::getDomainDimenions(),
                           const VertexType& vertex,
                           const RealType& time = 0 ) const
      {
         const RealType aux = function( vertex );
         const RealType aux = function( vertex, time );
         if( aux > 0.0 )
            return 1.0;
         return 0.0;
      }
};

} // namespace Analytic
} // namespace Operators
} // namespace TNL
 No newline at end of file
Loading