diff --git a/dune/solvers/solvers/iterativesolver.cc b/dune/solvers/solvers/iterativesolver.cc index 604fefd6eda81cee0c4e2ea1f1dc00e7e6b109a6..419b6a1444f29311579515cf2a5d78890fa9917b 100644 --- a/dune/solvers/solvers/iterativesolver.cc +++ b/dune/solvers/solvers/iterativesolver.cc @@ -12,6 +12,11 @@ template <class VectorType, class BitVectorType> void IterativeSolver<VectorType, BitVectorType>::check() const { + if (!iterationStep_) + DUNE_THROW(SolverError, "You need to supply an iteration step to an iterative solver!"); + + iterationStep_->check(); + if (!errorNorm_) DUNE_THROW(SolverError, "You need to supply a norm-computing routine to an iterative solver!"); } diff --git a/dune/solvers/solvers/iterativesolver.hh b/dune/solvers/solvers/iterativesolver.hh index 86047e06e988ba7009975996fa4621bca20856d3..edb2d25fb46a4326b933785471b8d53e14631c54 100644 --- a/dune/solvers/solvers/iterativesolver.hh +++ b/dune/solvers/solvers/iterativesolver.hh @@ -59,6 +59,9 @@ namespace Dune { /** \brief Write the current iterate to disk (for convergence measurements) */ void writeIterate(const VectorType& iterate, int iterationNumber) const; + //! The iteration step used by the algorithm + IterationStep<VectorType, BitVectorType>* iterationStep_; + /** \brief The requested tolerance of the solver */ double tolerance_; diff --git a/dune/solvers/solvers/loopsolver.cc b/dune/solvers/solvers/loopsolver.cc index 4f076874cf9b42d47333be5a0311fde4f8b6afe2..248561874decff03dad42cfb22c29ac59abac214 100644 --- a/dune/solvers/solvers/loopsolver.cc +++ b/dune/solvers/solvers/loopsolver.cc @@ -7,18 +7,6 @@ #include <iomanip> #include <dune/solvers/solvers/solver.hh> -template <class VectorType, class BitVectorType> -void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::check() const -{ - if (!iterationStep_) - DUNE_THROW(SolverError, "You need to supply an iteration step to an iterative solver!"); - - iterationStep_->check(); - - // check base class - IterativeSolver<VectorType,BitVectorType>::check(); -} - template <class VectorType, class BitVectorType> void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::preprocess() { @@ -93,14 +81,14 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve() iter_ = i; // Backup of the current solution for the error computation later on - VectorType oldSolution = iterationStep_->getSol(); + VectorType oldSolution = this->iterationStep_->getSol(); // Perform one iteration step - iterationStep_->iterate(); + this->iterationStep_->iterate(); // write iteration to file, if requested if (this->historyBuffer_!="") - this->writeIterate(iterationStep_->getSol(), i); + this->writeIterate(this->iterationStep_->getSol(), i); // Compute error real_type oldNorm = this->errorNorm_->operator()(oldSolution); @@ -109,7 +97,7 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve() // Please don't replace this call to 'diff' by computing the norm of the difference. // In some nonlinear DD applications the 'diff' method may be nonlinear. - real_type normOfCorrection = this->errorNorm_->diff(oldSolution,iterationStep_->getSol()); + real_type normOfCorrection = this->errorNorm_->diff(oldSolution,this->iterationStep_->getSol()); real_type convRate = (normOfOldCorrection > 0) ? normOfCorrection / normOfOldCorrection : 0.0; error = normOfCorrection; @@ -118,7 +106,7 @@ void Dune::Solvers::LoopSolver<VectorType, BitVectorType>::solve() // If a reference solution has been provided compute the error with respect to it if (referenceSolution_) { - normOfError = this->errorNorm_->diff(iterationStep_->getSol(), *referenceSolution_); + normOfError = this->errorNorm_->diff(this->iterationStep_->getSol(), *referenceSolution_); convRate = (normOfOldError > 0) ? normOfError / normOfOldError : 0.0; error = normOfError; normOfOldError = normOfError; diff --git a/dune/solvers/solvers/loopsolver.hh b/dune/solvers/solvers/loopsolver.hh index 41e784ef0274746efb603d0b4d2f2aa4612e65d0..bb9c11c83a989ea0a28badb65b2843eed4d6b45c 100644 --- a/dune/solvers/solvers/loopsolver.hh +++ b/dune/solvers/solvers/loopsolver.hh @@ -42,14 +42,10 @@ public: errorNorm, verbosity, useRelativeError), - iterationStep_(iterationStep), referenceSolution_(referenceSolution) - {} - - /** \brief Checks whether all relevant member variables are set - * \exception SolverError if the iteration step is not set up properly - */ - virtual void check() const; + { + this->iterationStep_ = iterationStep; + } /** * \brief Add a convergence criterion @@ -95,9 +91,6 @@ public: */ virtual void solve(); - //! The iteration step used by the algorithm - IterationStep<VectorType, BitVectorType>* iterationStep_; - const VectorType* referenceSolution_; protected: std::vector<Dune::Solvers::Criterion> criteria_;