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

IterationStep_ and errorNorm_ are now shared pointer and protected

parent 2ae7a612
No related branches found
No related tags found
No related merge requests found
...@@ -74,8 +74,8 @@ preprocess() ...@@ -74,8 +74,8 @@ preprocess()
typedef ProjectedBlockGSStep<MatrixType, VectorType> SmootherType; typedef ProjectedBlockGSStep<MatrixType, VectorType> SmootherType;
dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_)->hasObstacle_ = hasObstacleHierarchy_[0]; dynamic_cast<SmootherType*>(&loopBaseSolver->getIterationStep())->hasObstacle_ = hasObstacleHierarchy_[0];
dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_)->obstacles_ = obstacleHierarchy_[0]; dynamic_cast<SmootherType*>(&loopBaseSolver->getIterationStep())->obstacles_ = obstacleHierarchy_[0];
#if HAVE_IPOPT #if HAVE_IPOPT
} else if (typeid(*this->basesolver_) == typeid(QuadraticIPOptSolver<MatrixType,VectorType>)) { } else if (typeid(*this->basesolver_) == typeid(QuadraticIPOptSolver<MatrixType,VectorType>)) {
......
...@@ -151,10 +151,10 @@ void MultigridStep<MatrixType, VectorType, BitVectorType>::preprocess() ...@@ -151,10 +151,10 @@ void MultigridStep<MatrixType, VectorType, BitVectorType>::preprocess()
DuneSolversLoopSolver* loopBaseSolver = dynamic_cast<DuneSolversLoopSolver*> (this->basesolver_.get()); 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->getIterationStep()));
dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_)->setProblem(*(this->matrixHierarchy_[0]), *this->xHierarchy_[0], this->rhsHierarchy_[0]); dynamic_cast<SmootherType*>(&loopBaseSolver->getIterationStep())->setProblem(*(this->matrixHierarchy_[0]), *this->xHierarchy_[0], this->rhsHierarchy_[0]);
dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_)->ignoreNodes_ = ignoreNodesHierarchy_[0]; dynamic_cast<SmootherType*>(&loopBaseSolver->getIterationStep())->setIgnore(*ignoreNodesHierarchy_[0]);
} }
else if (dynamic_cast<LinearSolver<MatrixType, VectorType>*>(this->basesolver_.get())) { else if (dynamic_cast<LinearSolver<MatrixType, VectorType>*>(this->basesolver_.get())) {
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#ifndef LOOP_SOLVER_HH #ifndef LOOP_SOLVER_HH
#define LOOP_SOLVER_HH #define LOOP_SOLVER_HH
#include <type_traits>
#include <dune/solvers/solvers/iterativesolver.hh> #include <dune/solvers/solvers/iterativesolver.hh>
#include <dune/solvers/iterationsteps/iterationstep.hh> #include <dune/solvers/iterationsteps/iterationstep.hh>
#include <dune/solvers/norms/norm.hh> #include <dune/solvers/norms/norm.hh>
...@@ -30,6 +32,7 @@ class LoopSolver : public IterativeSolver<VectorType, BitVectorType> ...@@ -30,6 +32,7 @@ class LoopSolver : public IterativeSolver<VectorType, BitVectorType>
public: public:
/** \brief Constructor taking all relevant data */ /** \brief Constructor taking all relevant data */
DUNE_DEPRECATED_MSG("Handing over raw pointer in the constructor is deprecated!")
LoopSolver(IterationStep<VectorType, BitVectorType>* iterationStep, LoopSolver(IterationStep<VectorType, BitVectorType>* iterationStep,
int maxIterations, int maxIterations,
double tolerance, double tolerance,
...@@ -39,12 +42,32 @@ public: ...@@ -39,12 +42,32 @@ public:
const VectorType* referenceSolution=0) const VectorType* referenceSolution=0)
: IterativeSolver<VectorType, BitVectorType>(maxIterations, : IterativeSolver<VectorType, BitVectorType>(maxIterations,
tolerance, tolerance,
errorNorm, *errorNorm,
verbosity,
useRelativeError),
referenceSolution_(referenceSolution)
{
this->setIterationStep(*iterationStep);
}
/** \brief Constructor taking all relevant data */
template <class Step, class RealNorm, class Enable = std::enable_if_t<
not std::is_pointer<Step>::value and not std::is_pointer<RealNorm>::value> >
LoopSolver(Step&& iterationStep,
int maxIterations,
double tolerance,
RealNorm&& errorNorm,
Solver::VerbosityMode verbosity,
bool useRelativeError=true,
const VectorType* referenceSolution=0)
: IterativeSolver<VectorType, BitVectorType>(maxIterations,
tolerance,
std::forward<RealNorm>(errorNorm),
verbosity, verbosity,
useRelativeError), useRelativeError),
referenceSolution_(referenceSolution) referenceSolution_(referenceSolution)
{ {
this->iterationStep_ = iterationStep; this->setIterationStep(std::forward<Step>(iterationStep));
} }
/** /**
......
...@@ -16,7 +16,7 @@ void TrustRegionSolver<ProblemType,VectorType,MatrixType>::solve() ...@@ -16,7 +16,7 @@ void TrustRegionSolver<ProblemType,VectorType,MatrixType>::solve()
// if the inner solver is a monotone multigrid set up a max-norm trust-region // if the inner solver is a monotone multigrid set up a max-norm trust-region
if (dynamic_cast<::LoopSolver<VectorType>*>(innerSolver_.get())) { if (dynamic_cast<::LoopSolver<VectorType>*>(innerSolver_.get())) {
mgStep = dynamic_cast<MonotoneMGStep<MatrixType,VectorType>*>(dynamic_cast<::LoopSolver<VectorType>*>(innerSolver_.get())->iterationStep_); mgStep = dynamic_cast<MonotoneMGStep<MatrixType,VectorType>*>(dynamic_cast<::LoopSolver<VectorType>*>(&innerSolver_.get()).getIterationStep());
} }
......
...@@ -79,12 +79,13 @@ public: ...@@ -79,12 +79,13 @@ public:
/** \brief Set up the solver. */ /** \brief Set up the solver. */
template <class Norm>
void setup(const Dune::ParameterTree& trConfig, void setup(const Dune::ParameterTree& trConfig,
Norm<VectorType>& errorNorm, Norm&& errorNorm,
ProblemType& problem, Solver& innerSolver) { ProblemType& problem, Solver& innerSolver) {
setupTrParameter(trConfig); setupTrParameter(trConfig);
this->errorNorm_ = &errorNorm; this->setErrorNorm(std::forward<Norm>(errorNorm));
problem_ = Dune::stackobject_to_shared_ptr(problem); problem_ = Dune::stackobject_to_shared_ptr(problem);
innerSolver_ = Dune::stackobject_to_shared_ptr(innerSolver); innerSolver_ = Dune::stackobject_to_shared_ptr(innerSolver);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment