13#ifndef TAYLORHOODPRECONDITIONER_HH
14#define TAYLORHOODPRECONDITIONER_HH
16#include "dune/common/config.h"
24#include "dune/grid/common/rangegenerators.hh"
25#include "dune/istl/preconditioner.hh"
82 template <
int dim,
class Real=
double>
88 template <
class R,
int n>
120 void apply(Vector<R,dim>& u, Vector<R,1>& p,
121 Vector<R,dim> f, Vector<R,1>
const& g)
const;
123 Matrix
const&
getInvK()
const {
return invK; }
127 std::vector<EntryA> D;
128 std::vector<int> idx;
212 :
public Dune::Preconditioner<X,X>
219 constexpr static int dim = X::template Component<0>::block_type::dimension;
247 template <
class AGOP,
class VelocitySpace>
249 VelocitySpace
const& velocitySpace)
261 template <
class MatrixA,
class MatrixB,
class MatrixBt,
class VelocitySpace>
263 VelocitySpace
const& velocitySpace)
265 auto const& gridView = velocitySpace.gridView();
266 static_assert(MatrixA::block_type::rows==
dim,
"matrix block row size should agree with domain");
267 static_assert(MatrixA::block_type::cols==
dim,
"matrix block col size should agree with domain");
268 assert(A.M() == A.N());
269 assert(A.M() == B.M());
272 vPatchDofs.resize(gridView.size(
dim));
273 pPatchDofs.resize(gridView.size(
dim));
276 assert(patches.size()==vPatchDofs.size());
279 velocityPatchCount.resize(A.N(),0);
280 pressurePatchCount.resize(B.N(),0);
290 for (
size_t i=0; i<patches.size(); ++i)
299 std::vector<size_t> pressureDofs;
300 for (
size_t const i: vDofs)
301 for (
auto ci=Bt[i].begin(); ci!=Bt[i].end(); ++ci)
302 pressureDofs.push_back(ci.index());
304 std::sort(pressureDofs.begin(),pressureDofs.end());
305 pressureDofs.erase(std::unique(pressureDofs.begin(),pressureDofs.end()),
317 std::vector<size_t> pDofs;
319 pDofs.push_back(pressureDofs[k]);
320 std::swap(pDofs,pressureDofs);
324 for (
size_t uIdx: vDofs)
325 ++velocityPatchCount[uIdx];
326 for (
size_t pIdx: pressureDofs)
327 ++pressurePatchCount[pIdx];
330 vPatchDofs[i] = std::move(vDofs);
331 pPatchDofs[i] = std::move(pressureDofs);
332 localInverse.push_back(std::move(invK));
336 std::cout <<
"checking " << pressurePatchCount.size() <<
" pressure constraints:\n";
337 for (
int i=0; i<pressurePatchCount.size(); ++i)
338 if (pressurePatchCount[i]==0)
339 std::cout <<
"pressure node " << i <<
" not covered!\n";
362 using VectorU =
typename domain_type::template Component<0>;
363 using VectorP =
typename domain_type::template Component<1>;
370 for (
int k=0; k<vPatchDofs.size(); ++k)
372 int const nu = vPatchDofs[k].size();
373 int const np = pPatchDofs[k].size();
380 for (
int i=0; i<nu; ++i)
382 auto uIdx = vPatchDofs[k][i];
383 double w = weight(velocityPatchCount[uIdx],
prolongation,flavour);
389 for (
int i=0; i<np; ++i)
391 auto pIdx = pPatchDofs[k][i];
392 double w = weight(pressurePatchCount[pIdx],
prolongation,flavour);
402 localInverse[k].apply(zu,zp,rf,rg);
410 for (
int i=0; i<nu; ++i)
412 auto uIdx = vPatchDofs[k][i];
413 double w = weight(velocityPatchCount[uIdx],
prolongation,flavour);
418 for (
int i=0; i<np; ++i)
420 auto pIdx = pPatchDofs[k][i];
421 double w = weight(pressurePatchCount[pIdx],
prolongation,flavour);
434 virtual Dune::SolverCategory::Category
category()
const override
436 return Dune::SolverCategory::sequential;
445 double w = 1.0/
count;
458 std::vector<std::vector<size_t>> vPatchDofs;
459 std::vector<std::vector<size_t>> pPatchDofs;
460 std::vector<std::array<std::vector<size_t>,2>> patchDofs;
463 std::vector<LocalSolver> localInverse;
466 std::vector<int> velocityPatchCount;
467 std::vector<int> pressurePatchCount;
480 template <
class AGOP>
483 typename AGOP::Domain>
488 static_assert(std::is_same_v<domain_type,range_type>,
"need a symmetric saddle point operator");
524 K->applyscaleadd(-1.0,z,r);
A LAPACK-compatible dense matrix class with shape specified at runtime.
Interface for symmetric preconditioners.
typename AGOP::Scalar field_type
SymmetricTaylorHoodPreconditioner(AGOP const &K_)
Constructor.
typename AGOP::Domain domain_type
void init(domain_type &x, range_type const &y) const
Computes an approximate solution satisfying the constraints.
virtual void apply(domain_type &x, range_type const &y) override
typename AGOP::Range range_type
Solves small Stokes systems even if incompressibility constraints are linearly dependent.
DynamicMatrix< EntryB > MatrixB
void apply(Vector< R, dim > &u, Vector< R, 1 > &p, Vector< R, dim > f, Vector< R, 1 > const &g) const
Applys the preconditioner to the right hand side .
LocalStokesSolver(MatrixA A, MatrixB B, Real tol)
std::vector< int > const & constraintIndices() const
the indices of B rows that are actually retained in the reduced system
DynamicMatrix< EntryA > MatrixA
Matrix const & getInvK() const
Constraint preconditioner for Taylor-Hood discretizations of incompressibility problems.
virtual Dune::SolverCategory::Category category() const override
virtual void post(domain_type &x) override
virtual bool requiresInitializedInput() const
TaylorHoodPreconditioner(AGOP const &K, VelocitySpace const &velocitySpace)
Constructor.
void apply(domain_type &x, range_type const &y, TaylorHoodPreconditionerFlavour flavour) const
Applies the preconditioner either as presmoother, postsmoother, or in its symmetric flavour.
virtual void pre(domain_type &x, range_type &) override
static constexpr int dim
The dimension of the velocity component.
X domain_type
The domain type of the saddle point system.
TaylorHoodPreconditioner(MatrixA const &A, MatrixB const &B, MatrixBt const &Bt, VelocitySpace const &velocitySpace)
Constructor.
virtual void apply(domain_type &x, range_type const &y) override
Appliess the symmetric preconditioner as .
typename X::field_type field_type
domain_type range_type
The range type of the saddle point system.
int count(Cell const &cell, int codim)
Computes the number of subentities of codimension c of a given entity.
std::vector< size_t > algebraicPatch(Space const &space, Range const &cells)
Computes the global indices of all ansatz functions whose support is a subset of the union of given c...
auto computePatches(GridView const &gridview)
Computes the patches around vertices of the grid view.
DynamicMatrix< MEntry > submatrix(DynamicMatrix< MEntry > const &A, int rowstart, int rowend, int colstart, int colend)
extracts contiguous submatrices, copying the data
NumaBCRSMatrix< Dune::FieldMatrix< typename FineSpace::Scalar, 1, 1 >, SparseIndex > prolongation(CoarseSpace const &coarseSpace, FineSpace const &fineSpace)
Computes an interpolation-based prolongation matrix from a (supposedly) coarser space to a finer spac...
TaylorHoodPreconditionerFlavour
tag for controlling the TaylorHoodPreconditioner flavour
auto & component(LinearProductSpace< Scalar, Sequence > &x)