Commit eab48a79 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Implementation of diagonal preconditioner

...and some simplifications in tnlSolverStarter - needs more!
parent b09a2585
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -269,11 +269,9 @@ bool tnlGMRESSolver< Matrix, Preconditioner > :: solve( const Vector& b, Vector&
      if( preconditioner )
      {
         matrix -> vectorProduct( x, _M_tmp );
         for( IndexType i = 0; i < _size; i ++ )
            M_tmp[ i ] = b[ i ] - M_tmp[ i ];
         //preconditioner -> solve( M_tmp, r );
         for( IndexType i = 0; i < _size; i ++ )
            beta += r[ i ] * r[ i ];
         _M_tmp.addVector( b, ( RealType ) 1.0, -1.0 );
         preconditioner -> solve( _M_tmp, _r );
         beta = _r. lpNorm( ( RealType ) 2.0 );
      }
      else
      {
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ class tnlSemiImplicitTimeStepper
   typedef typename ProblemType::DofVectorType DofVectorType;
   typedef typename ProblemType::MeshDependentDataType MeshDependentDataType;
   typedef LinearSystemSolver LinearSystemSolverType;
   typedef typename LinearSystemSolverType::PreconditionerType PreconditionerType;
   typedef typename ProblemType::MatrixType MatrixType;

   tnlSemiImplicitTimeStepper();
+7 −0
Original line number Diff line number Diff line
@@ -141,6 +141,10 @@ solve( const RealType& time,
   tnlAssert( this->problem != 0, );
   RealType t = time;
   this->linearSystemSolver->setMatrix( this->matrix );
   PreconditionerType preconditioner;
   tnlSolverStarterSolverPreconditionerSetter< LinearSystemSolverType, PreconditionerType >
       ::run( *(this->linearSystemSolver), preconditioner );

   while( t < stopTime )
   {
      RealType currentTau = Min( this->timeStep, stopTime - t );
@@ -173,6 +177,9 @@ solve( const RealType& time,
      if( verbose )
         cout << "                                                                  Solving the linear system for time " << t + currentTau << "             \r" << flush;

      // TODO: add timer
      preconditioner.update( this->matrix );

      this->linearSystemSolverTimer.start();
      if( ! this->linearSystemSolver->template solve< DofVectorType, tnlLinearResidueGetter< MatrixType, DofVectorType > >( this->rightHandSide, dofVector ) )
      {
+2 −0
Original line number Diff line number Diff line
SET( headers tnlDummyPreconditioner.h
             tnlDiagonalPreconditioner.h
             tnlDiagonalPreconditioner_impl.h
   )
   
INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/solvers/preconditioners )
+33 −0
Original line number Diff line number Diff line
#ifndef TNLDIAGONALPRECONDITIONER_H_
#define TNLDIAGONALPRECONDITIONER_H_

#include <core/tnlObject.h>
#include <core/vectors/tnlVector.h>

template< typename Real, typename Device, typename Index >
class tnlDiagonalPreconditioner
{
   public:
   typedef Real RealType;
   typedef Device DeviceType;
   typedef Index IndexType;
   typedef tnlVector< Real, Device, Index > VectorType;

   template< typename Matrix >
   void update( const Matrix& matrix );

   template< typename Vector1, typename Vector2 >
   bool solve( const Vector1& b, Vector2& x ) const;

   tnlString getType() const
   {
      return tnlString( "tnlDiagonalPreconditioner" );
   }

   protected:
   VectorType diagonal;
};

#include <solvers/preconditioners/tnlDiagonalPreconditioner_impl.h>

#endif /* TNLDIAGONALPRECONDITIONER_H_ */
Loading