19#include "dune/istl/bvector.hh"
36 template <
int d,
class Real=
double>
57 VectorB const& cons,
int activeSetChanges,
58 std::vector<VectorX> &correctionStack,
59 std::vector<std::tuple<double,double,double>> &coarseRes)
91 template <
int d,
class Pro
longation,
class Smoother,
class CoarseSmoother=Smoother,
class Real=
double>
104 static constexpr bool smoothersEqual = std::is_same<Smoother,CoarseSmoother>::value;
107 std::variant<Smoother,CoarseSmoother>>;
125 Real smootherRegularization=0,
bool blocks=
true,
bool directOnCoarse=
true);
246 std::vector<MatrixB> mgStackB;
247 mutable std::vector<VectorX> correctionStack;
248 mutable std::vector<std::tuple<double,double,double>> coarseResidual;
256 std::unique_ptr<MGSolverStatistics<d,Real>> dummyLogger;
264 template <
int d,
class Real, QPStructure sparsity=QPStructure::DENSE>
310 template <
int d,
class Pro
longation,
class Real=
double,
class Smoother=QPPenaltySmoother<d,Real>,
class CoarseSmoother=QPPenaltySmoother<d,Real>>
340 Real smootherRegularization=0,
bool blocks=
true,
bool directOnCoarse=
true);
461 template <
int d,
class Real, QPStructure sparsity=QPStructure::DENSE>
464 template <
int d,
class Pro
longation,
class Real=
double,
class Smoother=QPSmoother<d,Real>,
class CoarseSmoother=QPSmoother<d,Real>>
493 Real smootherRegularization=0,
bool blocks=
true,
bool directOnCoarse=
true);
An interface for gathering multigrid solver statistics.
virtual void enterPostSmoothingCorrection(int level, VectorX const &dx)
virtual void enterVCycleCorrection(int iter, VectorX const &dx, Real energy, VectorX const &grad, VectorX const &grad0, VectorX const &grad1, VectorB const &cons, int activeSetChanges, std::vector< VectorX > &correctionStack, std::vector< std::tuple< double, double, double > > &coarseRes)
At the end of a V-cycle, specify the iteration number, the correction, and the resulting energy at th...
virtual void enterPreSmoothingCorrection(int level, VectorX const &dx)
virtual void enterCoarseGridCorrection(int level, VectorX const &dx)
Class for multigrid stacks.
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
A base class for multigrid solver for QPs.
QPMultiGridBase(MatrixA A, MatrixB const &B, std::vector< Prolongation > &&prolongations, Real smootherRegularization=0, bool blocks=true, bool directOnCoarse=true)
Constructs the solver, providing the matrices and .
virtual double qpLinesearch(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &dx) const =0
Compute the optimal step size in direction of dx.
Dune::BlockVector< Dune::FieldVector< Real, d > > VectorX
NumaBCRSMatrix< EntryA > MatrixA
MatrixB const & B() const
Provides a reference to the fine grid constraints.
virtual std::tuple< VectorX, VectorB, int > gradient(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x) const =0
Compute the problem gradient of current iterate.
virtual double computeEnergy(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x) const =0
Compute the problem energy of current iterate for logging purposes.
virtual std::tuple< VectorX, VectorX, VectorX, VectorB, int > gradient_extended(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x) const =0
Computes the gradient of current iterate, giving more information on the components of the gradient....
VectorX step(VectorX const &x, VectorX c, VectorB b) const
Computes a single V-cycle correction for approximately solving the QP for the given right hand side v...
std::vector< SmootherType > smoothers
NumaBCRSMatrix< Dune::FieldMatrix< Real, 1, d > > MatrixB
static constexpr bool smoothersEqual
std::conditional_t< smoothersEqual, Smoother, std::variant< Smoother, CoarseSmoother > > SmootherType
virtual ~QPMultiGridBase()
Destructor.
Self & setBulkMode(ParallelMode m)
Defines the smoothing strategy to use for unconstrained degrees of freedom.
Dune::BlockVector< Dune::FieldVector< Real, 1 > > VectorB
std::tuple< VectorX, int > solve(VectorX x, VectorX const &c, VectorB const &b, double tol, int vcycles) const
Approximately solves the QP for the given right hand side vectors up to a given tolerance.
Self & setLogger(MGSolverStatistics< d, Real > *logger)
Sets the logging facility for reporting solver statistics.
Self & setSmoothings(int pre, int post)
Self & setCoarseCorrections(int n)
Sets the number of coarse corrections to compute and apply.
Self & setCoarseLevel(int coarselevel)
Defines the grid level to be used as coarse grid.
A multigrid solver for convex QPs.
virtual double qpLinesearch(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &dx) const
QPMultiGrid(MatrixA const &A, MatrixB const &B, std::vector< Prolongation > &&prolongations, Real smootherRegularization=0, bool blocks=true, bool directOnCoarse=true)
Constructs the solver, providing the matrices and .
double getPenalty()
Returns the current penalty factor .
Self & setConstraintsMode(ParallelMode m)
std::tuple< VectorX, VectorB, int > solve(VectorX x, VectorX const &c, VectorB const &b, VectorB const &lambda, double tol, int vcycles) const
Approximately solves the QP for the given right hand side vectors up to a given tolerance.
virtual std::tuple< VectorX, VectorX, VectorX, VectorB, int > gradient_extended(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x) const
Computes the gradient of the penalized energy function.
~QPMultiGrid()
Destructor.
Self & setPenalty(Real gamma, bool levelDependent=false)
Sets the penalty factor .
virtual double computeEnergy(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x) const
Computes the energy, given by the penalized energy function.
Self & setGlobalMode(ParallelMode m)
virtual std::tuple< VectorX, VectorB, int > gradient(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x) const
Computes the gradient of the penalized energy function.
VectorB firstOrderUpdate(VectorX const &x, VectorB const &b, VectorB const &lambda) const
A first order update for the Lagrange multiplier.
QPMultiGridStrict(MatrixA const &A, MatrixB const &B, std::vector< Prolongation > &&prolongations, Real smootherRegularization=0, bool blocks=true, bool directOnCoarse=true)
Constructs the solver, providing the matrices and .
std::tuple< VectorX, int > solve(VectorX x, VectorX const &c, VectorB const &b, double tol, int vcycles) const
Approximately solves the QP for the given right hand side vectors up to a given tolerance.
virtual std::tuple< VectorX, VectorB, int > gradient(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x) const
Computes the gradient of the (non-augmented) Lagrangian.
virtual double qpLinesearch(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &dx) const
~QPMultiGridStrict()
Destructor.
virtual std::tuple< VectorX, VectorX, VectorX, VectorB, int > gradient_extended(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x) const
Computes the gradient of the (non-augmented) Lagrangian.
virtual double computeEnergy(MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &x) const
ParallelMode
Whether to execute some algorithm in sequential or parallel manner.