KASKADE 7 development version
Loading...
Searching...
No Matches
Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother > Class Template Reference

A multigrid solver for convex QPs. More...

#include <qpmg.hh>

Inheritance diagram for Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >:
Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >

Public Types

using VectorX = Dune::BlockVector<Dune::FieldVector<Real,d>>
using VectorB = Dune::BlockVector<Dune::FieldVector<Real,1>>
using MatrixA = NumaBCRSMatrix<EntryA>
using MatrixB = NumaBCRSMatrix<Dune::FieldMatrix<Real,1,d>>
using Self = QPMultiGrid<d,Prolongation,Real,Smoother,CoarseSmoother>
using SmootherType

Public Member Functions

 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 \( A \) and \( B \).
 ~QPMultiGrid ()
 Destructor.
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.
VectorB firstOrderUpdate (VectorX const &x, VectorB const &b, VectorB const &lambda) const
 A least-squares multiplier update.
Self & setPenalty (Real gamma, bool levelDependent=false)
 Sets the penalty factor \( \gamma \).
Self & setConstraintsMode (ParallelMode m)
Self & setGlobalMode (ParallelMode m)
double getPenalty ()
 Returns the current penalty factor \( \gamma \).
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 vectors.
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 & setCoarseLevel (int coarselevel)
 Defines the grid level to be used as coarse grid.
Self & setSmoothings (int pre, int post)
Self & setCoarseCorrections (int n)
 Sets the number of coarse corrections to compute and apply.
Self & setBulkMode (ParallelMode m)
 Defines the smoothing strategy to use for unconstrained degrees of freedom.
Self & setLogger (MGSolverStatistics< d, Real > *logger)
 Sets the logging facility for reporting solver statistics.

Static Public Attributes

static constexpr bool smoothersEqual = std::is_same<Smoother,CoarseSmoother>::value

Protected Member Functions

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.
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.
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.
virtual double qpLinesearch (MatrixA const &A, MatrixB const &B, VectorX const &c, VectorB const &b, VectorX const &dx) const
 Compute the optimal step size in direction of dx.
MatrixB const & B () const
 Provides a reference to the fine grid constraints.

Protected Attributes

std::vector< SmootherType > smoothers

Detailed Description

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
class Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >

A multigrid solver for convex QPs.

This solves QPs of the form

\[ \min \frac{1}{2} x^T A x + c^T x \quad \text{s.t.} \quad Bx\le b. \]

On the finest level, this works with the augmented Lagrangian formulation

\[ \min \frac{1}{2} x^T A x + c^T x + \frac{\gamma}{2} \|(Bx-(b-\lambda/\gamma))_+\|^2 \]

for some multiplier \( \lambda \ge 0 \), and an appropriate multiplier update.

The multilevel minimization works with level-dependent penalty factors. On each level, the following computations ( \(\text{MGM}(A,B,x,c,b,\gamma)\) are performed:

  • pre-smoothing: apply a block Jacobi smoother to the augmented Lagrangian.
  • multiplier update (optional: is interleaving multigrid with multiplier updates a good idea?)
  • coarse grid correction: compute residuals \( c_r \) and \( b_r \) and compute a correction

    \[ (\delta x, \delta \lambda) = \text{MGM}(P^TAP,BP,0,P^Tc_r,b_r,\gamma/4) \]

  • post-smoothing: apply correction to primal variable and multiplier and perform block Jacobi
  • multiplier update

Rationale: The level-dependence of the penalty factor is based on the following idea. Enforcing the constraint by the penalty should allow sufficient slack such as not to impede convergence of Gauß-Seidel. On coarser levels, GS is supposed to take larger steps (the whole reason for multigrid) approximately by a factor of two for each grid level, and so the penalty should increase the permitted steps by a factor of two as well. This means decreasing the penalty factor by four.

The restriction of multipliers is not necessary for asymptotically optimal complexity, as the number of constraints is \( \mathcal{O}(N^{1-1/d}) \) and therefore the computational work of a single V-cycle is \( \mathcal{O}(N + N^{1-1/d}\log N) = \mathcal{O}(N) \). Nevertheless, restricting the constraints in an appropriate way (open how to do this) might be beneficial for performance.

Template Parameters
dthe dimension of (vector valued) optimization variables
Prolongationdefines the data type of the prolongation matrices defining the hierarchy
Realfloating point format
Smootherthe smoother for the local QPs on all grids but the coarse one
CoarseSmootherthe smoother for the coarse grid

Definition at line 311 of file qpmg.hh.

Member Typedef Documentation

◆ MatrixA

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
using Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::MatrixA = NumaBCRSMatrix<EntryA>

Definition at line 320 of file qpmg.hh.

◆ MatrixB

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
using Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::MatrixB = NumaBCRSMatrix<Dune::FieldMatrix<Real,1,d>>

Definition at line 321 of file qpmg.hh.

◆ Self

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
using Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::Self = QPMultiGrid<d,Prolongation,Real,Smoother,CoarseSmoother>

Definition at line 322 of file qpmg.hh.

◆ SmootherType

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
using Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::SmootherType
inherited
Initial value:
std::conditional_t<smoothersEqual,
Smoother,
std::variant<Smoother,CoarseSmoother>>
static constexpr bool smoothersEqual
Definition qpmg.hh:104

Definition at line 105 of file qpmg.hh.

◆ VectorB

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
using Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::VectorB = Dune::BlockVector<Dune::FieldVector<Real,1>>

Definition at line 319 of file qpmg.hh.

◆ VectorX

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
using Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::VectorX = Dune::BlockVector<Dune::FieldVector<Real,d>>

Definition at line 318 of file qpmg.hh.

Constructor & Destructor Documentation

◆ QPMultiGrid()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::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 \( A \) and \( B \).

Parameters
Athe Hessian. The matrix is copied internally and need not exist after solver construction.
Bthe constraints. The matrix is referenced internally and has to exist during the lifetime of the solver.
blocks
  • block=true: treat blocks of dof coupled by constraints jointly (default)
  • block=false: treat all dofs individually (only for testing and comparison purposes)
Warning
This is intended for testing purposes only and may be removed in future.
Parameters
directOnCoarse
  • directOnCoarse=true use direct solver for problem on coarse grid
  • directOnCoarse=false use a few iterative (smoothing) steps on coarse grid (block Jacobi/Gauss Seidel)

◆ ~QPMultiGrid()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::~QPMultiGrid ( )

Destructor.

Member Function Documentation

◆ B()

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
MatrixB const & Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::B ( ) const
protectedinherited

Provides a reference to the fine grid constraints.

◆ computeEnergy()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
virtual double Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::computeEnergy ( MatrixA const & A,
MatrixB const & B,
VectorX const & c,
VectorB const & b,
VectorX const & x ) const
protectedvirtual

Computes the energy, given by the penalized energy function.

\[ \frac{1}{2} x^T A x + c^T x + \frac{\gamma}{2} \|(Bx-b)_+\|^2 \]

Implements Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >.

◆ firstOrderUpdate()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
VectorB Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::firstOrderUpdate ( VectorX const & x,
VectorB const & b,
VectorB const & lambda ) const

A least-squares multiplier update.

This can be used if a good initial guess for \( x \) is available, but not for \( \lambda \). A common situation where this is typically the case is finite strain contact mechanics, where the constraints and hence the multiplier changes with deformation, after having solved a QP linearization.

A first order update for the Lagrange multiplier

Compute first order multiplier update \lambda <- (\lambda + \gamma*(B*x-b))_+, or equivalently \lambda <- \lambda + max(-\lambda, \gamma*(B*x-b)). This makes only sense, however, if we have actually minimized - otherwise there is no new information in the constraint violation. Thus the accuracy of minimization should be sufficient.

Parameters
xprimal variable
bconstant constraint term
lambdaapproximate multiplier
Returns
multiplier update \( \delta\lambda \)

◆ getPenalty()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
double Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::getPenalty ( )

Returns the current penalty factor \( \gamma \).

◆ gradient()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
virtual std::tuple< VectorX, VectorB, int > Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::gradient ( MatrixA const & A,
MatrixB const & B,
VectorX const & c,
VectorB const & b,
VectorX const & x ) const
protectedvirtual

Computes the gradient of the penalized energy function.

\[ \frac{1}{2} x^T A x + c^T x + \frac{\gamma}{2} \|(Bx-b)_+\|^2 \]

Returns
a tuple (grad, cons, nActive) consisting of:
  • grad: full gradient given by

    \[ Ax + c + \gamma*B^T(Bx-b)_+ \]

  • cons: vector of constraint violation give by

    \[ (Bx-b)_+ \]

  • nActive: number of active constraints, i.e.

    \[ | \{ i \colon (Bx-b)_i >= 0 \} | \]

Implements Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >.

◆ gradient_extended()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
virtual std::tuple< VectorX, VectorX, VectorX, VectorB, int > Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::gradient_extended ( MatrixA const & A,
MatrixB const & B,
VectorX const & c,
VectorB const & b,
VectorX const & x ) const
protectedvirtual

Computes the gradient of the penalized energy function.

\[ \frac{1}{2} x^T A x + c^T x + \frac{\gamma}{2} \|(Bx-b)_+\|^2 \]

Returns
a tuple (grad, grad0, grad1, cons, nActive) consisting of:
  • grad: full gradient given by

    \[ Ax + c + \gamma*B^T(Bx-b)_+ \]

  • grad0: enegry component of gradient given by

    \[ Ax + c \]

  • grad1: penalty component of gradient given by

    \[ \gamma*B^T(Bx-b)_+ \]

  • cons: vector of constraint violation give by

    \[ (Bx-b)_+ \]

  • nActive: number of active constraints, i.e.

    \[ | \{ i \colon (Bx-b)_i >= 0 \} | \]

Implements Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >.

◆ qpLinesearch()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
virtual double Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::qpLinesearch ( MatrixA const & A,
MatrixB const & B,
VectorX const & c,
VectorB const & b,
VectorX const & dx ) const
protectedvirtual

Compute the optimal step size in direction of dx.

Implements Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >.

◆ setBulkMode()

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
Self & Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::setBulkMode ( ParallelMode m)
inherited

Defines the smoothing strategy to use for unconstrained degrees of freedom.

In contact problems, those are usually the interior nodes, and the ones without potential contact partner. The smoother can operate in parallel (Jacobi) or sequentially (Gauss-Seidel). In the parallel way, an exact linesearch is performed after the smoothing in order to guarantee descent.

◆ setCoarseCorrections()

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
Self & Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::setCoarseCorrections ( int n)
inherited

Sets the number of coarse corrections to compute and apply.

Parameters
nnumber of coarse corrections
  • n=0: just the smoother on the fine grid is performed, no multigrid at all (for testing purposes only).
  • n=1: V-cycle (default)
  • n=2: W-cycle

◆ setCoarseLevel()

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
Self & Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::setCoarseLevel ( int coarselevel)
inherited

Defines the grid level to be used as coarse grid.

Parameters
coarselevelthe coarse grid level, between 0 and the max grid level

If coarselevel is outside its allowed range, it is projected onto that range.

◆ setConstraintsMode()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
Self & Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::setConstraintsMode ( ParallelMode m)

◆ setGlobalMode()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
Self & Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::setGlobalMode ( ParallelMode m)

◆ setLogger()

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
Self & Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::setLogger ( MGSolverStatistics< d, Real > * logger)
inherited

Sets the logging facility for reporting solver statistics.

Parameters
loggera pointer to the logger object. This can be a nullpointer, in which case logging is stopped.

Ownership of the logger object remains with the caller. The logger object needs to exist for the lifetime of the QPMultiGrid class or until it is replaced by a different logger (or none).

◆ setPenalty()

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
Self & Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::setPenalty ( Real gamma,
bool levelDependent = false )

Sets the penalty factor \( \gamma \).

The default on construction is \( \gamma = 10^3 \).

Warning
set methods in the base class return a reference to the base class, which impairs chaining of setters. Call the derived class setters first, e.g.
mg.setPenalty(1e3).setCoarseCorrections(2);
Parameters
gammathe penalty parameter
levelDependentif set true, we use level dependent penaltys, i.e., gamma on finest level and gamma/4 recursively on coarser levels

◆ setSmoothings()

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
Self & Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::setSmoothings ( int pre,
int post )
inherited

◆ solve() [1/2]

template<int d, class Prolongation, class Real = double, class Smoother = QPPenaltySmoother<d,Real>, class CoarseSmoother = QPPenaltySmoother<d,Real>>
std::tuple< VectorX, VectorB, int > Kaskade::QPMultiGrid< d, Prolongation, Real, Smoother, CoarseSmoother >::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.

Parameters
xinitial guess for the solution
clinear objective term
bconstant constraint term
lambdaapproximate multiplier
toltolerance
Returns
a tuple \( (x,\delta\lambda,\mathrm{iter}) \) of solution vector, multiplier update, and iteration count

◆ solve() [2/2]

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
std::tuple< VectorX, int > Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::solve ( VectorX x,
VectorX const & c,
VectorB const & b,
double tol,
int vcycles ) const
inherited

Approximately solves the QP for the given right hand side vectors up to a given tolerance.

Parameters
xinitial guess for the solution
clinear objective term
bconstant constraint term
toltolerance
Returns
a tuple \( (x,\mathrm{iter}) \) of solution vector, multiplier update, and iteration count

◆ step()

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
VectorX Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::step ( VectorX const & x,
VectorX c,
VectorB b ) const
inherited

Computes a single V-cycle correction for approximately solving the QP for the given right hand side vectors.

Parameters
xinitial guess for the solution
clinear objective term
bconstant constraint term
Returns
the correction dx

Member Data Documentation

◆ smoothers

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
std::vector<SmootherType> Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::smoothers
protectedinherited

Definition at line 228 of file qpmg.hh.

◆ smoothersEqual

template<int d, class Prolongation, class Smoother, class CoarseSmoother = Smoother, class Real = double>
bool Kaskade::QPMultiGridBase< d, Prolongation, Smoother, CoarseSmoother, Real >::smoothersEqual = std::is_same<Smoother,CoarseSmoother>::value
staticconstexprinherited

Definition at line 104 of file qpmg.hh.


The documentation for this class was generated from the following file: