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

CGStep: hold preconditioner in a `shared_ptr`

parent 8e26106f
No related branches found
No related tags found
1 merge request!29CGStep: hold preconditioner in a `shared_ptr`
Pipeline #13013 passed
......@@ -22,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());
......
......@@ -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,7 +58,7 @@ namespace Dune {
VectorType r_; // residual
using Base::x_;
double r_squared_old_;
Preconditioner* preconditioner_;
std::shared_ptr<Preconditioner> preconditioner_;
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment