13#ifndef MG_AMULTIGRID_HH
14#define MG_AMULTIGRID_HH
20#include <dune/istl/preconditioner.hh>
45 template <
class Smoother,
class Pro
longation,
class CoarsePreconditioner=Smoother>
63 template <
class Entry,
class Index,
class MakeSmoother,
class MakeCoarsePreconditioner>
65 MakeCoarsePreconditioner
const& makeCoarsePreconditioner,
bool onlyLowerTriangle=
false)
66 : prolongations(std::move(Ps))
68 for (
int l=prolongations.size(); l>0; --l)
70 smoothers.insert(smoothers.begin(),makeSmoother(A,l));
71 A = conjugation(prolongations[l-1],A,onlyLowerTriangle);
73 coarsePreconditioner = std::make_unique<CoarsePreconditioner>(makeCoarsePreconditioner(A,0));
83 runMG(x,b,prolongations.size());
94 for (
auto const& s: smoothers)
95 if (s.requiresInitializedInput())
106 coarsePreconditioner->pre(x,r);
107 coarsePreconditioner->apply(x,r);
108 coarsePreconditioner->post(x);
113 auto const& p = prolongations[level-1];
122 auto coarseGridCorrectionTicket = std::async(std::launch::async,[&] ()
124 cx.resize(p.M()); cx = 0;
125 runMG(cx,cr,level-1);
129 auto& s = smoothers[level-1];
135 coarseGridCorrectionTicket.wait();
140 std::vector<Prolongation> prolongations;
141 std::vector<Smoother> smoothers;
142 std::unique_ptr<CoarsePreconditioner> coarsePreconditioner;
158 template <
class Entry,
class Index,
class Pro
longation,
class MakeSmoother,
class MakeCoarsePreconditioner>
160 MakeSmoother
const& makeSmoother, MakeCoarsePreconditioner
const& makeCoarsePreconditioner,
161 bool onlyLowerTriangle=
false)
179 template <
class Entry,
class Index,
class Gr
idMan>
215 template <
class Entry,
class Index,
class FineSpace,
class MakeSmoother,
class MakeCoarseSmoother>
218 MakeSmoother
const& makeSmoother, MakeCoarseSmoother
const& makeCoarseSmoother,
219 int coarseLevel=0,
bool onlyLowerTriangle=
false)
226 makeCoarseSmoother,makeCoarseSolver,onlyLowerTriangle);
228 std::vector<NumaBCRSMatrix<Dune::FieldMatrix<double,1,1>>> prolongations(1,
prolongation<Index>(p1Space,space));
229 return makeAdditiveMultiGrid(A,prolongations,makeSmoother,makeCoarsePreconditioner,onlyLowerTriangle);
253 template <
class StorageTag,
class Entry,
class Index,
class FineSpace>
255 StorageTag storageTag,
int coarseLevel=0,
bool onlyLowerTriangle=
false)
257 std::cout <<
"using w=2\n";
259 auto patchJacobi = [&space,storageTag](
auto const& a,
int level){
An additive multigrid preconditioner for P1 elements.
typename Smoother::domain_type domain_type
typename Smoother::range_type range_type
virtual void apply(domain_type &x, range_type const &r)
virtual bool requiresInitializedInput() const
Returns true if the target vector x has to be initialized to zero before calling apply or applyDp.
AdditiveMultiGrid(NumaBCRSMatrix< Entry, Index > A, std::vector< Prolongation > Ps, MakeSmoother const &makeSmoother, MakeCoarsePreconditioner const &makeCoarsePreconditioner, bool onlyLowerTriangle=false)
Constructor.
SymmetricPreconditioner< domain_type, range_type > Base
AdditiveMultiGrid()=default
Default constructor.
AdditiveMultiGrid(AdditiveMultiGrid &&other)=default
AdditiveMultiGrid & operator=(AdditiveMultiGrid &&other)=default
virtual Base::field_type applyDp(domain_type &x, range_type const &r)
Computes and returns .
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
An additive overlapping domain decomposition type preconditioner for higher order finite elements app...
Interface for symmetric preconditioners.
domain_type::field_type field_type
FEFunctionSpace< ContinuousLagrangeMapper< Scalar, typename Grid::LeafGridView > > H1Space
An conforming finite element space on the leaf grid view with Lagrange basis.
auto makePBPX(NumaBCRSMatrix< Entry, Index > A, FineSpace const &space, H1Space< typename FineSpace::Grid > const &p1Space, StorageTag storageTag, int coarseLevel=0, bool onlyLowerTriangle=false)
Convenience function creating additive multigrid preconditioner of V-cycle type with domain decomposi...
auto makeAdditivePMultiGrid(NumaBCRSMatrix< Entry, Index > A, FineSpace const &space, H1Space< typename FineSpace::Grid > const &p1Space, MakeSmoother const &makeSmoother, MakeCoarseSmoother const &makeCoarseSmoother, int coarseLevel=0, bool onlyLowerTriangle=false)
Convenience function creating additive multigrid preconditioner of V-cycle type for higher order elem...
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...
std::vector< NumaBCRSMatrix< Dune::FieldMatrix< typename Mapper::Scalar, 1, 1 >, SparseIndex > > prolongationStack(FEFunctionSpace< Mapper > const &space)
Computes a stack of prolongation matrices for higher order finite element spaces.
auto makeBPX(NumaBCRSMatrix< Entry, Index > const &A, GridMan const &gridman, bool onlyLowerTriangle=false)
Convenience function creating a BPX preconditioner for P1 elements.
auto makeAdditiveMultiGrid(NumaBCRSMatrix< Entry, Index > const &A, std::vector< Prolongation > const &prolongations, MakeSmoother const &makeSmoother, MakeCoarsePreconditioner const &makeCoarsePreconditioner, bool onlyLowerTriangle=false)
Convenience function creating additive multigrid preconditioners for P1 elements.
Convenience typedefs and creation functions for common function spaces.
Defines domain and range types for matrix classes.