Skip to content
Snippets Groups Projects
Commit e42be9e6 authored by Ansgar Burchardt's avatar Ansgar Burchardt
Browse files

Merge branch 'cgstep-preconditioner-as-shared_ptr' into 'master'

CGStep: hold preconditioner in a `shared_ptr`

See merge request agnumpde/dune-solvers!29
parents 14b20ebd 82aec907
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include <dune/solvers/common/canignore.hh> #include <dune/solvers/common/canignore.hh>
#include <dune/matrix-vector/genericvectortools.hh> #include <dune/matrix-vector/genericvectortools.hh>
namespace Dune {
namespace Solvers {
template <class MatrixType, class VectorType, class Ignore> template <class MatrixType, class VectorType, class Ignore>
void CGStep<MatrixType, VectorType, Ignore>::check() const void CGStep<MatrixType, VectorType, Ignore>::check() const
{ {
...@@ -19,7 +22,7 @@ void CGStep<MatrixType, VectorType, Ignore>::preprocess() ...@@ -19,7 +22,7 @@ void CGStep<MatrixType, VectorType, Ignore>::preprocess()
if (preconditioner_) { if (preconditioner_) {
using CanIgnore_t = CanIgnore<Ignore>; 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()) if (asCanIgnore != nullptr and this->hasIgnore())
asCanIgnore->setIgnore(this->ignore()); asCanIgnore->setIgnore(this->ignore());
...@@ -59,3 +62,6 @@ void CGStep<MatrixType, VectorType, Ignore>::iterate() ...@@ -59,3 +62,6 @@ void CGStep<MatrixType, VectorType, Ignore>::iterate()
p_ += q; p_ += q;
r_squared_old_ = r_squared; r_squared_old_ = r_squared;
} }
} /* namespace Solvers */
} /* namespace Dune */
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
#ifndef DUNE_SOLVERS_ITERATIONSTEPS_CGSTEP_HH #ifndef DUNE_SOLVERS_ITERATIONSTEPS_CGSTEP_HH
#define DUNE_SOLVERS_ITERATIONSTEPS_CGSTEP_HH #define DUNE_SOLVERS_ITERATIONSTEPS_CGSTEP_HH
#include <memory>
#include <dune/solvers/common/preconditioner.hh> #include <dune/solvers/common/preconditioner.hh>
#include <dune/solvers/common/defaultbitvector.hh> #include <dune/solvers/common/defaultbitvector.hh>
#include <dune/solvers/common/wrapownshare.hh>
#include <dune/solvers/iterationsteps/lineariterationstep.hh> #include <dune/solvers/iterationsteps/lineariterationstep.hh>
namespace Dune { namespace Dune {
...@@ -18,23 +21,21 @@ namespace Dune { ...@@ -18,23 +21,21 @@ namespace Dune {
using Preconditioner = Dune::Solvers::Preconditioner<MatrixType, VectorType, Ignore>; using Preconditioner = Dune::Solvers::Preconditioner<MatrixType, VectorType, Ignore>;
public: public:
CGStep() CGStep() = default;
: preconditioner_(nullptr)
{}
CGStep(const MatrixType& matrix, CGStep(const MatrixType& matrix,
VectorType& x, VectorType& x,
const VectorType& rhs) const VectorType& rhs)
: Base(matrix,x), p_(rhs.size()), r_(rhs), : Base(matrix,x), p_(rhs.size()), r_(rhs)
preconditioner_(nullptr)
{} {}
template<typename P>
CGStep(const MatrixType& matrix, CGStep(const MatrixType& matrix,
VectorType& x, VectorType& x,
const VectorType& rhs, const VectorType& rhs,
Preconditioner& preconditioner) P&& preconditioner)
: Base(matrix,x), p_(rhs.size()), r_(rhs), : 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 //! Set linear operator, solution and right hand side
...@@ -57,12 +58,12 @@ namespace Dune { ...@@ -57,12 +58,12 @@ namespace Dune {
VectorType r_; // residual VectorType r_; // residual
using Base::x_; using Base::x_;
double r_squared_old_; double r_squared_old_;
Preconditioner* preconditioner_; std::shared_ptr<Preconditioner> preconditioner_;
}; };
#include "cgstep.cc"
} }
} }
#include "cgstep.cc"
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment