diff --git a/dune/solvers/iterationsteps/cgstep.cc b/dune/solvers/iterationsteps/cgstep.cc index 5985a01cc5bc3b60cbff72177dbb58e8c40bc38e..1a48ca2508d3e486d6eb0c620c3643f525ae9cac 100644 --- a/dune/solvers/iterationsteps/cgstep.cc +++ b/dune/solvers/iterationsteps/cgstep.cc @@ -4,6 +4,9 @@ #include <dune/solvers/common/canignore.hh> #include <dune/matrix-vector/genericvectortools.hh> +namespace Dune { +namespace Solvers { + template <class MatrixType, class VectorType, class Ignore> void CGStep<MatrixType, VectorType, Ignore>::check() const { @@ -19,7 +22,7 @@ void CGStep<MatrixType, VectorType, Ignore>::preprocess() if (preconditioner_) { using CanIgnore_t = CanIgnore<Ignore>; - CanIgnore_t *asCanIgnore = dynamic_cast<CanIgnore_t*>(preconditioner_); + CanIgnore_t *asCanIgnore = dynamic_cast<CanIgnore_t*>(preconditioner_.get()); if (asCanIgnore != nullptr and this->hasIgnore()) asCanIgnore->setIgnore(this->ignore()); @@ -59,3 +62,6 @@ void CGStep<MatrixType, VectorType, Ignore>::iterate() p_ += q; r_squared_old_ = r_squared; } + +} /* namespace Solvers */ +} /* namespace Dune */ diff --git a/dune/solvers/iterationsteps/cgstep.hh b/dune/solvers/iterationsteps/cgstep.hh index 5e4e5bcc9ce9e46a623d6230dbabb325c250ecc7..d4f8749a7c6ff9aa3403003b68f3d0ee71ceebe3 100644 --- a/dune/solvers/iterationsteps/cgstep.hh +++ b/dune/solvers/iterationsteps/cgstep.hh @@ -3,8 +3,11 @@ #ifndef DUNE_SOLVERS_ITERATIONSTEPS_CGSTEP_HH #define DUNE_SOLVERS_ITERATIONSTEPS_CGSTEP_HH +#include <memory> + #include <dune/solvers/common/preconditioner.hh> #include <dune/solvers/common/defaultbitvector.hh> +#include <dune/solvers/common/wrapownshare.hh> #include <dune/solvers/iterationsteps/lineariterationstep.hh> namespace Dune { @@ -18,23 +21,21 @@ namespace Dune { using Preconditioner = Dune::Solvers::Preconditioner<MatrixType, VectorType, Ignore>; public: - CGStep() - : preconditioner_(nullptr) - {} + CGStep() = default; CGStep(const MatrixType& matrix, VectorType& x, const VectorType& rhs) - : Base(matrix,x), p_(rhs.size()), r_(rhs), - preconditioner_(nullptr) + : Base(matrix,x), p_(rhs.size()), r_(rhs) {} + template<typename P> CGStep(const MatrixType& matrix, VectorType& x, const VectorType& rhs, - Preconditioner& preconditioner) + P&& preconditioner) : Base(matrix,x), p_(rhs.size()), r_(rhs), - preconditioner_(&preconditioner) + preconditioner_(wrap_own_share<Preconditioner>(std::forward<P>(preconditioner))) {} //! Set linear operator, solution and right hand side @@ -57,12 +58,12 @@ namespace Dune { VectorType r_; // residual using Base::x_; double r_squared_old_; - Preconditioner* preconditioner_; + std::shared_ptr<Preconditioner> preconditioner_; }; - -#include "cgstep.cc" } } +#include "cgstep.cc" + #endif