diff --git a/dune-solvers/iterationsteps/istlseqilu0step.hh b/dune-solvers/iterationsteps/istlseqilu0step.hh new file mode 100644 index 0000000000000000000000000000000000000000..c93d4d6a7b5f0485450982f6833698c5d5b71388 --- /dev/null +++ b/dune-solvers/iterationsteps/istlseqilu0step.hh @@ -0,0 +1,89 @@ +#ifndef ISTL_SEQILU0_STEP_HH +#define ISTL_SEQILU0_STEP_HH + +/** \file + \brief A wrapper class for the ISTL SeqILU0 implementation + */ + +#include <memory> + +#include <dune-solvers/iterationsteps/lineariterationstep.hh> + +#include <dune/istl/preconditioners.hh> +#include <dune/istl/operators.hh> + +/** \brief A wrapper class for the ISTL SeqILU0 implementation + */ +template <class MatrixType, class VectorType> +class ISTLSeqILU0Step + : public LinearIterationStep<MatrixType, VectorType> +{ + typedef Dune::MatrixAdapter<MatrixType,VectorType,VectorType> Operator; + + typedef Dune::SeqILU0<MatrixType,VectorType,VectorType> SeqILU0; + +public: + + /** \brief Constructor which initializes and sets up an algebraic hierarchy + \param smootherArgs Arguments for the smoother. See the dune-istl documentation for details + \param coarseningCriterion Arguments for the coarsening. See the dune-istl documentation for details + */ + ISTLSeqILU0Step (const MatrixType* stiffnessMatrix, + VectorType& x, + VectorType& rhs, + double relaxationFactor) + : relaxationFactor_(relaxationFactor) + { + setProblem(*stiffnessMatrix, x, rhs); + + seqILU0_ = std::auto_ptr<SeqILU0>(new SeqILU0(*stiffnessMatrix, relaxationFactor)); + seqILU0_->pre(*this->x_,*this->rhs_); + } + + /** \brief Initialize the iteration step but don't actually build the matrix hierarchy yet */ + ISTLSeqILU0Step (const MatrixType* stiffnessMatrix, + VectorType& x, + VectorType& rhs) + { + setProblem(*stiffnessMatrix, x, rhs); + } + + /** \brief Sets up an algebraic hierarchy + */ + virtual void preprocess(); + + /** \brief Perform one iteration */ + virtual void iterate(); + + /** \brief Get the solution */ + virtual VectorType getSol(); + +private: + + /** \brief The dune-istl sequential ILU0 preconditioner */ + std::auto_ptr<SeqILU0> seqILU0_; + + /** \brief Some magic relaxation factor */ + double relaxationFactor_; +}; + +template <class MatrixType, class VectorType> +void ISTLSeqILU0Step<MatrixType,VectorType>::preprocess() +{ + seqILU0_ = std::auto_ptr<SeqILU0>(new SeqILU0(*this->mat_, relaxationFactor_)); + seqILU0_->pre(*this->x_,*this->rhs_); +} + +template <class MatrixType, class VectorType> +void ISTLSeqILU0Step<MatrixType,VectorType>::iterate() +{ + seqILU0_->apply(*this->x_,*this->rhs_); +} + +template <class MatrixType, class VectorType> +VectorType ISTLSeqILU0Step<MatrixType,VectorType>::getSol() +{ + return *this->x_; +} + +#endif