Commit 1ed2b029 authored by oliver.sander_at_tu-dresden.de's avatar oliver.sander_at_tu-dresden.de
Browse files

Accept a LinearIterationStep for the linear correction

There are two alternatives now for the linear correction:
You can either provide a solver or an iteration step.
parent 74ecbecb
Pipeline #5320 failed with stage
in 15 seconds
......@@ -38,7 +38,7 @@ public:
using Functional = F;
using LinearSolver = Solvers::IterativeSolver<typename Linearization::ConstrainedVector, Solvers::DefaultBitVector_t<Vector> >;
/** \brief Constructor
/** \brief Constructor with a solver object for the linear correction
* \param linearSolver This is a callback used to solve the constrained linearized system
* \param projection This is a callback used to compute a projection into a defect-admissible set
* \param lineSolver This is a callback used to minimize a directional restriction of the functional
......@@ -59,6 +59,29 @@ public:
lineSolver_(lineSolver)
{}
/** \brief Constructor with a LinearIterationStep object for the linear correction
* \param linearIterationStep This is a callback used to solve the constrained linearized system
* \param projection This is a callback used to compute a projection into a defect-admissible set
* \param lineSolver This is a callback used to minimize a directional restriction of the functional
* for computing a damping parameter
*/
TNNMGStep(const Functional& f,
Vector& x,
std::shared_ptr<Solvers::IterationStep<Vector,BitVector> > nonlinearSmoother,
std::shared_ptr<Solvers::LinearIterationStep<typename Linearization::Matrix,typename Linearization::Vector> > linearIterationStep,
unsigned int noOfLinearIterationSteps,
const DefectProjection& projection,
const LineSearchSolver& lineSolver)
: Base(x),
f_(&f),
nonlinearSmoother_(nonlinearSmoother),
preSmoothingSteps_(1),
linearIterationStep_(linearIterationStep),
noOfLinearIterationSteps_(noOfLinearIterationSteps),
projection_(projection),
lineSolver_(lineSolver)
{}
//! destructor
~TNNMGStep()
{}
......@@ -106,6 +129,18 @@ public:
auto emptyIgnore = ignore;
Solvers::resizeInitialize(emptyIgnore, constrainedCorrection_, false);
// Do the linear correction with a LinearIterationStep object
if (linearIterationStep_)
{
linearIterationStep_->setIgnore(emptyIgnore);
linearIterationStep_->setProblem(A, constrainedCorrection_, r);
linearIterationStep_->preprocess();
for (unsigned int i=0; i<noOfLinearIterationSteps_; i++)
linearIterationStep_->iterate();
}
else // Do the linear correction with a Solver object
{
// 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.
......@@ -131,6 +166,7 @@ public:
linearSolver_->preprocess();
linearSolver_->solve();
}
linearization_->extendCorrection(constrainedCorrection_, correction_);
......@@ -172,7 +208,16 @@ private:
std::size_t preSmoothingSteps_;
std::shared_ptr<Linearization> linearization_;
// The following members cannot all be used at once:
// either we have a Dune::Solvers::Solver that implements the linear correction...
std::shared_ptr<LinearSolver> linearSolver_;
// ... or we have a mere LinearIterationStep, together with a number of times
// it is supposed to be called. You cannot have both at once.
std::shared_ptr<LinearIterationStep<typename Linearization::Matrix,typename Linearization::Vector> > linearIterationStep_;
unsigned int noOfLinearIterationSteps_;
typename Linearization::ConstrainedVector constrainedCorrection_;
Vector correction_;
DefectProjection projection_;
......
Supports Markdown
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