Skip to content
Snippets Groups Projects
Commit 01255a6c authored by Jonathan Youett's avatar Jonathan Youett
Browse files

Make baseSolver protected, store it as shared_ptr and add setter

parent 5025cb8e
No related branches found
No related tags found
1 merge request!15Reduce raw pointer
...@@ -141,14 +141,14 @@ void MultigridStep<MatrixType, VectorType, BitVectorType>::preprocess() ...@@ -141,14 +141,14 @@ void MultigridStep<MatrixType, VectorType, BitVectorType>::preprocess()
if (basesolver_) if (basesolver_)
{ {
// If the base solver can ignore dofs give it the ignoreNodes field // If the base solver can ignore dofs give it the ignoreNodes field
if (dynamic_cast<CanIgnore<BitVectorType>*>(this->basesolver_)) if (dynamic_cast<CanIgnore<BitVectorType>*>(this->basesolver_.get()))
dynamic_cast<CanIgnore<BitVectorType>*>(this->basesolver_)->ignoreNodes_ = ignoreNodesHierarchy_[0]; dynamic_cast<CanIgnore<BitVectorType>*>(this->basesolver_.get())->setIgnore(*ignoreNodesHierarchy_[0]);
typedef ::LoopSolver<VectorType> DuneSolversLoopSolver; typedef ::LoopSolver<VectorType> DuneSolversLoopSolver;
if (dynamic_cast<DuneSolversLoopSolver*>(this->basesolver_)) { if (dynamic_cast<DuneSolversLoopSolver*>(this->basesolver_.get())) {
DuneSolversLoopSolver* loopBaseSolver = dynamic_cast<DuneSolversLoopSolver*> (this->basesolver_); DuneSolversLoopSolver* loopBaseSolver = dynamic_cast<DuneSolversLoopSolver*> (this->basesolver_.get());
typedef LinearIterationStep<MatrixType, VectorType> SmootherType; typedef LinearIterationStep<MatrixType, VectorType> SmootherType;
assert(dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_)); assert(dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_));
...@@ -157,9 +157,9 @@ void MultigridStep<MatrixType, VectorType, BitVectorType>::preprocess() ...@@ -157,9 +157,9 @@ void MultigridStep<MatrixType, VectorType, BitVectorType>::preprocess()
dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_)->ignoreNodes_ = ignoreNodesHierarchy_[0]; dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_)->ignoreNodes_ = ignoreNodesHierarchy_[0];
} }
else if (dynamic_cast<LinearSolver<MatrixType, VectorType>*>(this->basesolver_)) { else if (dynamic_cast<LinearSolver<MatrixType, VectorType>*>(this->basesolver_.get())) {
LinearSolver<MatrixType,VectorType>* linearBaseSolver = dynamic_cast<LinearSolver<MatrixType,VectorType>*> (this->basesolver_); LinearSolver<MatrixType,VectorType>* linearBaseSolver = dynamic_cast<LinearSolver<MatrixType,VectorType>*> (this->basesolver_.get());
linearBaseSolver->setProblem(*(this->matrixHierarchy_[0]), *this->xHierarchy_[0], this->rhsHierarchy_[0]); linearBaseSolver->setProblem(*(this->matrixHierarchy_[0]), *this->xHierarchy_[0], this->rhsHierarchy_[0]);
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <dune/solvers/transferoperators/multigridtransfer.hh> #include <dune/solvers/transferoperators/multigridtransfer.hh>
#include <dune/solvers/solvers/iterativesolver.hh> #include <dune/solvers/solvers/iterativesolver.hh>
#include <dune/solvers/common/wrapownshare.hh>
#include "lineariterationstep.hh" #include "lineariterationstep.hh"
...@@ -179,6 +180,13 @@ namespace Dune { ...@@ -179,6 +180,13 @@ namespace Dune {
levelWiseSmoothers_[level] = smoother; levelWiseSmoothers_[level] = smoother;
} }
/** \brief Set base solver */
template <class BaseSolver>
void setBaseSolver(BaseSolver&& baseSolver)
{
basesolver_ = wrap_own_share<Solver>(std::forward<BaseSolver>(baseSolver));
}
protected: protected:
/** \brief The presmoothers, one for each level */ /** \brief The presmoothers, one for each level */
std::vector<std::shared_ptr<LinearIterationStep<MatrixType, VectorType> > > presmoother_; std::vector<std::shared_ptr<LinearIterationStep<MatrixType, VectorType> > > presmoother_;
...@@ -186,11 +194,9 @@ namespace Dune { ...@@ -186,11 +194,9 @@ namespace Dune {
/** \brief The postsmoothers, one for each level */ /** \brief The postsmoothers, one for each level */
std::vector<std::shared_ptr<LinearIterationStep<MatrixType, VectorType> > > postsmoother_; std::vector<std::shared_ptr<LinearIterationStep<MatrixType, VectorType> > > postsmoother_;
public:
/** \brief The base solver */ /** \brief The base solver */
Solver* basesolver_; std::shared_ptr<Solver> basesolver_;
protected:
//! Number of presmoothing steps //! Number of presmoothing steps
int nu1_; int nu1_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment