Skip to content
Snippets Groups Projects
Commit 0007a32f authored by Carsten Gräser's avatar Carsten Gräser
Browse files

[examples] Add convenience functions for creating a Dune::FastAMG preconditioner

parent c4921b6d
Branches
No related tags found
1 merge request!249[examples] Add convenience utility for FastAMG preconditioner and use it in Poisson example
......@@ -67,25 +67,6 @@ using namespace Dune;
#if DUNE_VERSION_GT(DUNE_ISTL, 2, 10)
template<class V, class M>
auto makeAMGPreconditioner(const V& x, const M& m)
{
using Operator = Dune::MatrixAdapter<M,V,V>;
using Criterion = Dune::Amg::SymmetricCriterion<M, Dune::Amg::RowSum>;
using AMG = Dune::Amg::FastAMG<Operator, V>;
auto parameters = Dune::Amg::Parameters();
parameters.setDebugLevel(0);
parameters.setNoPreSmoothSteps(1);
parameters.setNoPostSmoothSteps(1);
auto criterion = Criterion();
criterion.setDebugLevel(0);
auto opPtr = std::make_shared<Operator>(m);
return AMG(opPtr, criterion, parameters);
}
template<class V, class... P>
class BlockDiagonalPreconditioner : public Preconditioner<V,V> {
......@@ -355,8 +336,8 @@ int main (int argc, char *argv[]) try
using namespace Dune::Indices;
auto preconditioner = BlockDiagonalPreconditioner(x,
makeAMGPreconditioner(x[_0], stiffnessMatrix[_0][_0]),
makeAMGPreconditioner(x[_1], pressureMassMatrix));
makeAMGPreconditioner(stiffnessMatrix[_0][_0], x[_0]),
makeAMGPreconditioner(pressureMassMatrix, x[_1]));
// Construct the actual iterative solver
MINRESSolver<Vector> solver(
......
......@@ -10,6 +10,10 @@
#include <dune/common/typetraits.hh>
#include <dune/common/concept.hh>
#if DUNE_VERSION_GT(DUNE_ISTL, 2, 10)
#include <dune/istl/paamg/fastamg.hh>
#endif
#include <dune/grid/common/rangegenerators.hh>
#include <dune/functions/backends/concepts.hh>
......@@ -141,6 +145,51 @@ void incorporateEssentialConstraints(const Basis& basis, Matrix& matrix, Vector&
/**
* \brief Create a FastAMG preconditioner
* \tparam Matrix Type of the matrix the preconditioner should act on.
* \tparam Vector Type of vectors the preconditioner should act on.
* \param matrix The matrix used in the preconditioner
*
* This constructs a Dune::FastAMG preconditioner. With some
* standard arguments that are not defaulted in dune-istl.
*/
template<class Vector, class Matrix>
auto makeAMGPreconditioner(const Matrix& matrix)
{
using Operator = Dune::MatrixAdapter<Matrix,Vector,Vector>;
using Criterion = Dune::Amg::SymmetricCriterion<Matrix, Dune::Amg::RowSum>;
using AMG = Dune::Amg::FastAMG<Operator, Vector>;
auto parameters = Dune::Amg::Parameters();
parameters.setDebugLevel(0);
parameters.setNoPreSmoothSteps(1);
parameters.setNoPostSmoothSteps(1);
auto criterion = Criterion();
criterion.setDebugLevel(0);
auto opPtr = std::make_shared<Operator>(matrix);
return AMG(opPtr, criterion, parameters);
}
/**
* \brief Create a FastAMG preconditioner
* \tparam Matrix Type of the matrix the preconditioner should act on.
* \tparam Vector Type of vectors the preconditioner should act on.
* \param matrix The matrix used in the preconditioner
* \param dummy A dummy vector argument to enable type deduction for the Vector type.
*
* This constructs a Dune::FastAMG preconditioner.
*/
template<class Vector, class Matrix>
auto makeAMGPreconditioner(const Matrix& matrix, const Vector& dummy)
{
return makeAMGPreconditioner<Vector>(matrix);
}
// Compute the (i,j)-th cofactor of F
template<class K, int d>
constexpr K cofactor(const Dune::FieldMatrix<K,d,d>& F, std::size_t i, std::size_t j)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment