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 !29
parents 14b20ebd 82aec907
No related branches found
No related tags found
1 merge request!29CGStep: hold preconditioner in a `shared_ptr`
Pipeline #13017 passed
......@@ -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 */
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment