Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
richardsonstep.hh 1.31 KiB
#ifndef DUNE_RICHARDSON_STEP_HH
#define DUNE_RICHARDSON_STEP_HH

#include <dune/common/bitsetvector.hh>

#include <dune/solvers/common/preconditioner.hh>
#include <dune/solvers/iterationsteps/iterationstep.hh>

/** \brief A single preconditioned and damped Richardson step
*/
template<class VectorType,
         class BitVectorType = Dune::BitSetVector<VectorType::block_type::dimension> >
         class RichardsonStep 
         : public IterationStep<VectorType, BitVectorType>
{

public:
        
    /** \brief Constructor */
    RichardsonStep(const Preconditioner<VectorType>* preconditioner,
                   double damping
    ) 
        : preconditioner_(preconditioner),
          damping_(damping)
    {}

    //! Perform one iteration
    virtual void iterate();

    /** \brief Retrieve the solution */
    virtual VectorType getSol();
    
    const Preconditioner<VectorType>* preconditioner_;

    double damping_;
    
};

template<class VectorType, class BitVectorType>
inline
VectorType RichardsonStep<VectorType, BitVectorType>::getSol()
{
    return *(this->x_);
}

template<class VectorType, class BitVectorType>
inline
void RichardsonStep<VectorType, BitVectorType>::iterate()
{
    VectorType residual;
    
    preconditioner_->apply(*this->x_, residual);
    
    this->x_->axpy(damping_, residual);
    
}

#endif