25#ifndef DUMUX_PARALLEL_AMGBACKEND_HH
26#define DUMUX_PARALLEL_AMGBACKEND_HH
30#include <dune/common/exceptions.hh>
31#include <dune/common/parallel/indexset.hh>
32#include <dune/common/parallel/mpicollectivecommunication.hh>
33#include <dune/grid/common/capabilities.hh>
34#include <dune/istl/paamg/amg.hh>
35#include <dune/istl/paamg/pinfo.hh>
36#include <dune/istl/solvers.hh>
51template <
class Matrix,
class Vector>
54 typename Matrix::RowIterator row = matrix.begin();
55 for(; row != matrix.end(); ++row)
57 using size_type =
typename Matrix::size_type;
58 size_type rowIdx = row.index();
60 using MatrixBlock =
typename Matrix::block_type;
61 MatrixBlock diagonal = matrix[rowIdx][rowIdx];
64 using VectorBlock =
typename Vector::block_type;
65 const VectorBlock b = rhs[rowIdx];
66 diagonal.mv(b, rhs[rowIdx]);
68 typename Matrix::ColIterator col = row->begin();
69 for (; col != row->end(); ++col)
70 col->leftmultiply(diagonal);
79template <
class Gr
idView,
class AmgTraits>
82 using Grid =
typename GridView::Grid;
83 using LinearOperator =
typename AmgTraits::LinearOperator;
84 using ScalarProduct =
typename AmgTraits::ScalarProduct;
85 using VType =
typename AmgTraits::VType;
86 using Comm =
typename AmgTraits::Comm;
87 using Smoother =
typename AmgTraits::Smoother;
88 using AMGType = Dune::Amg::AMG<typename AmgTraits::LinearOperator, VType, Smoother,Comm>;
89 using BCRSMat =
typename AmgTraits::LinearOperator::matrix_type;
90 using DofMapper =
typename AmgTraits::DofMapper;
101 if (Dune::MPIHelper::getCollectiveCommunication().size() > 1)
102 DUNE_THROW(Dune::InvalidStateException,
"Using sequential constructor for parallel run. Use signature with gridView and dofMapper!");
113 const DofMapper& dofMapper,
127 template<
class Matrix,
class Vector>
128 bool solve(Matrix& A, Vector& x, Vector& b)
131 std::shared_ptr<Comm> comm;
132 std::shared_ptr<LinearOperator> fop;
133 std::shared_ptr<ScalarProduct> sp;
134 static const bool isParallel = AmgTraits::isParallel;
135 prepareLinearAlgebra_<Matrix, Vector, isParallel>(A, b, rank, comm, fop, sp);
137 using SmootherArgs =
typename Dune::Amg::SmootherTraits<Smoother>::Arguments;
138 using Criterion = Dune::Amg::CoarsenCriterion<Dune::Amg::SymmetricCriterion<BCRSMat, Dune::Amg::FirstDiagonal>>;
142 Dune::Amg::Parameters params(15,2000,1.2,1.6,Dune::Amg::atOnceAccu);
143 params.setDefaultValuesIsotropic(Grid::dimension);
145 Criterion criterion(params);
146 SmootherArgs smootherArgs;
147 smootherArgs.iterations = 1;
148 smootherArgs.relaxationFactor = 1;
150 AMGType amg(*fop, criterion, smootherArgs, *comm);
154 solver.apply(x, b, result_);
156 return result_.converged;
164 return "AMG preconditioned BiCGSTAB solver";
170 const Dune::InverseOperatorResult&
result()
const
194 template<
class Matrix,
class Vector,
bool isParallel>
195 void prepareLinearAlgebra_(Matrix& A, Vector& b,
int& rank,
196 std::shared_ptr<Comm>& comm,
197 std::shared_ptr<LinearOperator>& fop,
198 std::shared_ptr<ScalarProduct>& sp)
202 *phelper_, firstCall_);
205 std::shared_ptr<ParallelISTLHelper<GridView, AmgTraits>> phelper_;
206 Dune::InverseOperatorResult result_;
223template<
class TypeTag>
Provides a helper class for nonoverlapping decomposition using the ISTL AMG.
Define traits for the AMG backend.
void scaleLinearSystem(Matrix &matrix, Vector &rhs)
Scale the linear system by the inverse of its (block-)diagonal entries.
Definition: amgbackend.hh:52
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
A linear solver based on the ISTL AMG preconditioner and the ISTL BiCGSTAB solver.
Definition: amgbackend.hh:81
ParallelAMGBackend(const std::string ¶mGroup="")
Construct the backend for the sequential case only.
Definition: amgbackend.hh:97
ParallelAMGBackend(const GridView &gridView, const DofMapper &dofMapper, const std::string ¶mGroup="")
Construct the backend for parallel or sequential runs.
Definition: amgbackend.hh:112
std::string name() const
The name of the solver.
Definition: amgbackend.hh:162
bool solve(Matrix &A, Vector &x, Vector &b)
Solve a linear system.
Definition: amgbackend.hh:128
const Dune::InverseOperatorResult & result() const
The result containing the convergence history.
Definition: amgbackend.hh:170
A parallel helper class providing a nonoverlapping decomposition of all degrees of freedom.
Definition: amgparallelhelpers.hh:45
static void prepareLinearAlgebra(Matrix &A, Vector &b, int &rank, std::shared_ptr< Comm > &comm, std::shared_ptr< LinearOperator > &fop, std::shared_ptr< ScalarProduct > &sp, ParallelHelper &pHelper, const bool firstCall)
Definition: amgparallelhelpers.hh:1032
The implementation is specialized for the different discretizations.
Definition: amgtraits.hh:71
Base class for linear solvers.
Definition: dumux/linear/solver.hh:37
double residReduction() const
the linear solver residual reduction
Definition: dumux/linear/solver.hh:97
int maxIter() const
the maximum number of linear solver iterations
Definition: dumux/linear/solver.hh:89
const std::string & paramGroup() const
the parameter group for getting parameter from the parameter tree
Definition: dumux/linear/solver.hh:77
int verbosity() const
the verbosity level
Definition: dumux/linear/solver.hh:81
Declares all properties used in Dumux.
Base class for linear solvers.