Commit 743c1abc authored by oliver.sander_at_tu-dresden.de's avatar oliver.sander_at_tu-dresden.de
Browse files

Use the dune-solvers-style API to call the linear solver

parent 65aaecf2
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "dune/solvers/iterationsteps/iterationstep.hh" #include "dune/solvers/iterationsteps/iterationstep.hh"
#include "dune/solvers/iterationsteps/lineariterationstep.hh" #include "dune/solvers/iterationsteps/lineariterationstep.hh"
#include <dune/solvers/solvers/iterativesolver.hh>
#ifndef USE_OLD_TNNMG #ifndef USE_OLD_TNNMG
...@@ -23,7 +24,6 @@ namespace TNNMG { ...@@ -23,7 +24,6 @@ namespace TNNMG {
* \tparam BV Bit-vector type for marking ignored components * \tparam BV Bit-vector type for marking ignored components
*/ */
template<class F, class BV, class Linearization, template<class F, class BV, class Linearization,
class LinearSolver,
class DefectProjection, class DefectProjection,
class LineSearchSolver> class LineSearchSolver>
class TNNMGStep : class TNNMGStep :
...@@ -36,6 +36,7 @@ public: ...@@ -36,6 +36,7 @@ public:
using Vector = typename F::Vector; using Vector = typename F::Vector;
using BitVector = typename Base::BitVector; using BitVector = typename Base::BitVector;
using Functional = F; using Functional = F;
using LinearSolver = Solvers::IterativeSolver<typename Linearization::ConstrainedVector, Solvers::DefaultBitVector_t<Vector> >;
/** \brief Constructor /** \brief Constructor
* \param linearSolver This is a callback used to solve the constrained linearized system * \param linearSolver This is a callback used to solve the constrained linearized system
...@@ -104,8 +105,30 @@ public: ...@@ -104,8 +105,30 @@ public:
auto emptyIgnore = ignore; auto emptyIgnore = ignore;
Solvers::resizeInitialize(emptyIgnore, constrainedCorrection_, false); Solvers::resizeInitialize(emptyIgnore, constrainedCorrection_, false);
linearSolver_->step_->setIgnore(emptyIgnore);
linearSolver_->step_->setProblem(A, constrainedCorrection_, r); // Hand the linear problem to the linear solver.
// Currently we only support IterativeSolvers. The IterationStep member
// needs to be a LinearIterationStep, so we can give it the matrix.
using LinearIterationStepType = Solvers::LinearIterationStep<std::decay_t<decltype(A)>,
typename Linearization::ConstrainedVector,
decltype(emptyIgnore) >;
LinearIterationStepType* linearIterationStep;
auto iterativeSolver = std::dynamic_pointer_cast<Solvers::IterativeSolver<typename Linearization::ConstrainedVector> >(linearSolver_);
if (iterativeSolver)
{
iterativeSolver->iterationStep_->setIgnore(emptyIgnore);
linearIterationStep = dynamic_cast<LinearIterationStepType*>(iterativeSolver->iterationStep_);
} else
DUNE_THROW(Exception, "Linear solver has to be an IterativeSolver!");
if (linearIterationStep)
linearIterationStep->setProblem(A, constrainedCorrection_, r);
else
DUNE_THROW(Exception, "Linear solver does not accept matrices!");
linearSolver_->preprocess(); linearSolver_->preprocess();
linearSolver_->solve(); linearSolver_->solve();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment