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

Linear Jacobi solver refactoring.

parent f52140d2
Loading
Loading
Loading
Loading
+126 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlSORSolver.h  -  description
                          Jacobi.h  -  description
                             -------------------
    begin                : 2007/07/30
    begin                : Jul 30, 2007
    copyright            : (C) 2007 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/
@@ -15,22 +15,24 @@
 *                                                                         *
 ***************************************************************************/

#ifndef tnlJacobiSolverH
#define tnlJacobiSolverH
#pragma once 

#include <math.h>
#include <core/tnlObject.h>
#include <solvers/preconditioners/tnlDummyPreconditioner.h>
#include <solvers/tnlIterativeSolver.h>
#include <solvers/linear/tnlLinearResidueGetter.h>
#include <TNL/Object.h>
#include <TNL/Solvers/Preconditioners/Dummy.h>
#include <TNL/Solvers/IterativeSolver.h>
#include <TNL/Solvers/Linear/LinearResidueGetter.h>

namespace TNL {
   namespace Solvers {
      namespace Linear {

template< typename Matrix,
          typename Preconditioner = tnlDummyPreconditioner< typename Matrix :: RealType,
          typename Preconditioner = DummyPreconditioner< typename Matrix :: RealType,
                                                         typename Matrix :: DeviceType,
                                                         typename Matrix :: IndexType> >
class tnlJacobiSolver : public tnlObject,
                     public tnlIterativeSolver< typename Matrix :: RealType,
class Jacobi : public Object,
               public IterativeSolver< typename Matrix :: RealType,
                                       typename Matrix :: IndexType >
{
   public:
@@ -42,20 +44,23 @@ class tnlJacobiSolver : public tnlObject,
   typedef Preconditioner PreconditionerType;


   tnlJacobiSolver():omega(0){}
   Jacobi():omega(0){}

   tnlString getType() const
   String getType() const
   {
      return tnlString( "tnlJacobiSolver< " ) + this -> matrix -> getType() + ", " +	this -> preconditioner -> getType() + " >";
      return String( "Jacobi< " ) + this -> matrix -> getType() + ", " +	this -> preconditioner -> getType() + " >";
   }

   static void configSetup( tnlConfigDescription& config,
                            const tnlString& prefix = "" ) {config.addEntry< double >( prefix + "jacobi-omega", "Relaxation parameter of the weighted/damped Jacobi method.", 1.0 );}
                            const String& prefix = "" )
   {
      config.addEntry< double >( prefix + "jacobi-omega", "Relaxation parameter of the weighted/damped Jacobi method.", 1.0 );
   }

   bool setup( const tnlParameterContainer& parameters,
              const tnlString& prefix = "" )
   bool setup( const Config::ParameterContainer& parameters,
               const String& prefix = "" )
   { 
		tnlIterativeSolver< RealType, IndexType >::setup( parameters, prefix );
		IterativeSolver< RealType, IndexType >::setup( parameters, prefix );
		this->setOmega( parameters.getParameter< double >( prefix + "jacobi-omega" ) );
		if( this->omega <= 0.0 || this->omega > 2.0 )
		{
@@ -64,21 +69,29 @@ class tnlJacobiSolver : public tnlObject,
		return true;   
   }

   void setOmega( const RealType& omega ) {this->omega = omega;}
   const RealType& getOmega() const {return omega;}
   void setOmega( const RealType& omega )
   {
      this->omega = omega;
   }
   
   void setMatrix( const MatrixType& matrix ){this -> matrix = &matrix;}
   void setPreconditioner( const Preconditioner& preconditioner ){this -> preconditioner = &preconditioner;}
   const RealType& getOmega() const
   {
      return omega;
   }

   void setMatrix( const MatrixType& matrix )
   {
      this -> matrix = &matrix;
   }
   
   void setPreconditioner( const Preconditioner& preconditioner )
   {
      this -> preconditioner = &preconditioner;
   }

#ifdef HAVE_NOT_CXX11
   template< typename Vector,
             typename ResidueGetter >
   bool solve( const Vector& b, Vector& x )
#else
   template< typename Vector,
             typename ResidueGetter = tnlLinearResidueGetter< Matrix, Vector > >
             typename ResidueGetter = LinearResidueGetter< Matrix, Vector > >
   bool solve( const Vector& b, Vector& x, Vector& aux)
#endif
   {
      const IndexType size = matrix -> getRows();

@@ -100,7 +113,6 @@ class tnlJacobiSolver : public tnlObject,
      return this->checkConvergence();
   }


   protected:

      RealType omega;
@@ -109,4 +121,6 @@ class tnlJacobiSolver : public tnlObject,

};
         
#endif
      } // namespace Linear
   }  // namespace Solvers
} // namespace TNL