Commit a9202c3f authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Jakub Klinkovský
Browse files

Fixes for nvcc.

parent 19a9385e
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -42,8 +42,8 @@ class StaticEuler : public StaticExplicitSolver< Real, int >
      __cuda_callable__
      __cuda_callable__
      const RealType& getCFLCondition() const;
      const RealType& getCFLCondition() const;


      __cuda_callable__
      template< typename RHSFunction >
      template< typename RHSFunction >
      __cuda_callable__
      bool solve( VectorType& u, RHSFunction&& rhs );
      bool solve( VectorType& u, RHSFunction&& rhs );


   protected:
   protected:
@@ -81,8 +81,8 @@ class StaticEuler< TNL::Containers::StaticVector< Size_, Real > >
      __cuda_callable__
      __cuda_callable__
      const RealType& getCFLCondition() const;
      const RealType& getCFLCondition() const;


      __cuda_callable__
      template< typename RHSFunction >
      template< typename RHSFunction >
      __cuda_callable__
      bool solve( VectorType& u, RHSFunction&& rhs );
      bool solve( VectorType& u, RHSFunction&& rhs );


   protected:
   protected:
+4 −4
Original line number Original line Diff line number Diff line
@@ -132,23 +132,23 @@ checkConvergence()
{
{
   if( std::isnan( this->getResidue() ) )
   if( std::isnan( this->getResidue() ) )
   {
   {
      std::cerr << std::endl << "The residue is NaN." << std::endl;
      //std::cerr << std::endl << "The residue is NaN." << std::endl;
      return false;
      return false;
   }
   }
   if(( this->getResidue() > this->getDivergenceResidue() &&
   if(( this->getResidue() > this->getDivergenceResidue() &&
         this->getIterations() > this->minIterations ) )
         this->getIterations() > this->minIterations ) )
   {
   {
      std::cerr << std::endl  << "The residue has exceeded allowed tolerance " << this->getDivergenceResidue() << "." << std::endl;
      //std::cerr << std::endl  << "The residue has exceeded allowed tolerance " << this->getDivergenceResidue() << "." << std::endl;
      return false;
      return false;
   }
   }
   if( this->getIterations() >= this->getMaxIterations() )
   if( this->getIterations() >= this->getMaxIterations() )
   {
   {
      std::cerr << std::endl  << "The solver has exceeded maximal allowed number of iterations " << this->getMaxIterations() << "." << std::endl;
      //std::cerr << std::endl  << "The solver has exceeded maximal allowed number of iterations " << this->getMaxIterations() << "." << std::endl;
      return false;
      return false;
   }
   }
   if( this->getResidue() > this->getConvergenceResidue() )
   if( this->getResidue() > this->getConvergenceResidue() )
   {
   {
      std::cerr << std::endl  << "The residue ( = " << this->getResidue() << " ) is too large( > " << this->getConvergenceResidue() << " )." << std::endl;
      //std::cerr << std::endl  << "The residue ( = " << this->getResidue() << " ) is too large( > " << this->getConvergenceResidue() << " )." << std::endl;
      return false;
      return false;
   }
   }
   return true;
   return true;
+31 −16
Original line number Original line Diff line number Diff line
@@ -49,35 +49,41 @@ TYPED_TEST_SUITE( ODENumericSolverTest, DofNumericTypes );


TYPED_TEST_SUITE( ODEStaticSolverTest, DofStaticVectorTypes );
TYPED_TEST_SUITE( ODEStaticSolverTest, DofStaticVectorTypes );


TYPED_TEST( ODENumericSolverTest, LinearFunctionTest )
template< typename RealType, typename SolverType >
void ODENumericSolverTest_LinearFunctionTest()
{
{
   using DofContainerType = typename TestFixture::DofContainerType;
   const RealType final_time = 10.0;
   using SolverType = ODETestSolver< DofContainerType >;
   using Real = DofContainerType;

   const Real final_time = 10.0;
   SolverType solver;
   SolverType solver;
   solver.setTime( 0.0 );
   solver.setTime( 0.0 );
   solver.setStopTime( final_time );
   solver.setStopTime( final_time );
   solver.setTau( 0.005 );
   solver.setTau( 0.005 );
   solver.setConvergenceResidue( 0.0 );
   solver.setConvergenceResidue( 0.0 );


   DofContainerType u( 0.0 );
   RealType u( 0.0 );
   solver.solve( u, [] ( const Real& time, const Real& tau, const auto& u, auto& fu ) {
   solver.solve( u, [] __cuda_callable__ ( const RealType& time, const RealType& tau, const RealType& u, RealType& fu ) {
      fu = time;
      fu = time;
   } );
   } );


   Real exact_solution = 0.5 * final_time * final_time;
   RealType exact_solution = 0.5 * final_time * final_time;
   EXPECT_NEAR( TNL::abs( u - exact_solution ), ( Real ) 0.0, 0.1 );
   EXPECT_NEAR( TNL::abs( u - exact_solution ), ( RealType ) 0.0, 0.1 );
}
}


TYPED_TEST( ODEStaticSolverTest, LinearFunctionTest )
TYPED_TEST( ODENumericSolverTest, LinearFunctionTest )
{
{
   using DofContainerType = typename TestFixture::DofContainerType;
   using DofContainerType = typename TestFixture::DofContainerType;
   using SolverType = ODETestSolver< DofContainerType >;
   using SolverType = ODETestSolver< DofContainerType >;
   using Real = typename DofContainerType::RealType;
   using Real = DofContainerType;

   ODENumericSolverTest_LinearFunctionTest< Real, SolverType >();
}

template< typename DofContainerType, typename SolverType >
void ODEStaticSolverTest_LinearFunctionTest()
{
   using StaticVectorType = DofContainerType;
   using RealType = typename DofContainerType::RealType;


   const Real final_time = 10.0;
   const RealType final_time = 10.0;
   SolverType solver;
   SolverType solver;
   solver.setTime( 0.0 );
   solver.setTime( 0.0 );
   solver.setStopTime( final_time );
   solver.setStopTime( final_time );
@@ -85,12 +91,21 @@ TYPED_TEST( ODEStaticSolverTest, LinearFunctionTest )
   solver.setConvergenceResidue( 0.0 );
   solver.setConvergenceResidue( 0.0 );


   DofContainerType u( 0.0 );
   DofContainerType u( 0.0 );
   solver.solve( u, [] ( const Real& time, const Real& tau, const auto& u, auto& fu ) {
   solver.solve( u, [] __cuda_callable__ ( const RealType& time, const RealType& tau, const StaticVectorType& u, StaticVectorType& fu ) {
      fu = time;
      fu = time;
   } );
   } );


   Real exact_solution = 0.5 * final_time * final_time;
   RealType exact_solution = 0.5 * final_time * final_time;
   EXPECT_NEAR( TNL::max( TNL::abs( u - exact_solution ) ), ( Real ) 0.0, 0.1 );
   EXPECT_NEAR( TNL::max( TNL::abs( u - exact_solution ) ), ( RealType ) 0.0, 0.1 );
}

TYPED_TEST( ODEStaticSolverTest, LinearFunctionTest )
{
   using DofContainerType = typename TestFixture::DofContainerType;
   using SolverType = ODETestSolver< DofContainerType >;
   using Real = typename DofContainerType::RealType;

   ODEStaticSolverTest_LinearFunctionTest< DofContainerType, SolverType >();
}
}


#endif
#endif