12#ifndef DUMUX_SEQ_SOLVER_BACKEND_HH 
   13#define DUMUX_SEQ_SOLVER_BACKEND_HH 
   19#include <dune/istl/preconditioners.hh> 
   20#include <dune/istl/solvers.hh> 
   21#include <dune/istl/io.hh> 
   22#include <dune/common/indices.hh> 
   23#include <dune/common/hybridutilities.hh> 
   56    template<
class Preconditioner, 
class Solver, 
class Matrix, 
class Vector>
 
   58                                   const Dune::ParameterTree& params)
 
   61        using MatrixAdapter = Dune::MatrixAdapter<Matrix, Vector, Vector>;
 
   62        const auto linearOperator = std::make_shared<MatrixAdapter>(A);
 
   64        auto precond = std::make_shared<Preconditioner>(linearOperator, params.sub(
"preconditioner"));
 
   65        Solver solver(linearOperator, precond, params);
 
   69        Dune::InverseOperatorResult result;
 
   70        solver.apply(x, bTmp, result);
 
   72        return result.converged;
 
 
 
  100    template<
class Matrix, 
class Vector>
 
  101    bool solve(
const Matrix& A, Vector& x, 
const Vector& b)
 
  105        Dune::SeqJac<Matrix, Vector, Vector, precondBlockLevel> jac(A, 1, 1.0);
 
 
  114        return "Explicit diagonal matrix solver";
 
 
 
  127template <
class LinearSolverTraits>
 
  133    template<
class Matrix, 
class Vector>
 
  134    bool solve(
const Matrix& A, Vector& x, 
const Vector& b)
 
  137        using Solver = Dune::BiCGSTABSolver<Vector>;
 
  139        return IterativePreconditionedSolverImpl::template solveWithParamTree<Preconditioner, Solver>(A, x, b, solverParams);
 
 
  144        return "Uzawa preconditioned BiCGSTAB solver";
 
 
 
  152template<
class M, 
class X, 
class Y, 
int blockLevel = 2>
 
  155    template<std::
size_t i>
 
  156    using DiagBlockType = std::decay_t<decltype(std::declval<M>()[Dune::index_constant<i>{}][Dune::index_constant<i>{}])>;
 
  158    template<std::
size_t i>
 
  159    using VecBlockType = std::decay_t<decltype(std::declval<X>()[Dune::index_constant<i>{}])>;
 
  161    template<std::
size_t i>
 
  162    using BlockILU = Dune::SeqILU<DiagBlockType<i>, VecBlockType<i>, VecBlockType<i>, blockLevel-1>;
 
  164    using ILUTuple = 
typename makeFromIndexedType<std::tuple, BlockILU, std::make_index_sequence<M::N()> >::type;
 
  185        static_assert(blockLevel >= 2, 
"Only makes sense for MultiTypeBlockMatrix!");
 
 
  188    void pre (X& v, Y& d) 
final {}
 
  192        using namespace Dune::Hybrid;
 
  193        forEach(integralRange(Dune::Hybrid::size(ilu_)), [&](
const auto i)
 
  195            std::get<decltype(i)::value>(ilu_).apply(v[i], d[i]);
 
 
  202    Dune::SolverCategory::Category 
category() const final
 
  204        return Dune::SolverCategory::sequential;
 
 
  208    template<std::size_t... Is>
 
  210    : ilu_(std::make_tuple(BlockILU<Is>(m[
Dune::index_constant<Is>{}][Dune::index_constant<Is>{}], 
w)...))
 
 
  230    template<
class Matrix, 
class Vector>
 
  231    bool solve(
const Matrix& M, Vector& x, 
const Vector& b)
 
  235        Dune::BiCGSTABSolver<Vector> solver(op, preconditioner, this->
residReduction(),
 
  238        solver.apply(x, bTmp, result_);
 
  240        return result_.converged;
 
 
  243    const Dune::InverseOperatorResult& 
result()
 const 
 
  249    { 
return "block-diagonal ILU0-preconditioned BiCGSTAB solver"; }
 
 
  252    Dune::InverseOperatorResult result_;
 
 
  268    template<
int precondBlockLevel = 2, 
class Matrix, 
class Vector>
 
  269    bool solve(
const Matrix& M, Vector& x, 
const Vector& b)
 
  274        Dune::RestartedGMResSolver<Vector> solver(op, preconditioner, this->
residReduction(), restartGMRes,
 
  277        solver.apply(x, bTmp, result_);
 
  279        return result_.converged;
 
 
  282    const Dune::InverseOperatorResult& 
result()
 const 
 
  288    { 
return "block-diagonal ILU0-preconditioned restarted GMRes solver"; }
 
 
  291    Dune::InverseOperatorResult result_;
 
 
  298template<
class M, 
class X, 
class Y, 
int blockLevel = 2>
 
  301    template<std::
size_t i>
 
  302    using DiagBlockType = std::decay_t<decltype(std::declval<M>()[Dune::index_constant<i>{}][Dune::index_constant<i>{}])>;
 
  304    template<std::
size_t i>
 
  305    using VecBlockType = std::decay_t<decltype(std::declval<X>()[Dune::index_constant<i>{}])>;
 
  307    template<std::
size_t i>
 
  308    using Smoother = Dune::SeqSSOR<DiagBlockType<i>, VecBlockType<i>, VecBlockType<i>>;
 
  310    template<std::
size_t i>
 
  311    using LinearOperator = Dune::MatrixAdapter<DiagBlockType<i>, VecBlockType<i>, VecBlockType<i>>;
 
  313    template<std::
size_t i>
 
  314    using ScalarProduct = Dune::SeqScalarProduct<VecBlockType<i>>;
 
  316    template<std::
size_t i>
 
  317    using BlockAMG = Dune::Amg::AMG<LinearOperator<i>, VecBlockType<i>, Smoother<i>>;
 
  319    using AMGTuple = 
typename makeFromIndexedType<std::tuple, BlockAMG, std::make_index_sequence<M::N()> >::type;
 
  338    template<
class LOP, 
class Criterion, 
class SmootherArgs>
 
  342        static_assert(blockLevel >= 2, 
"Only makes sense for MultiTypeBlockMatrix!");
 
 
  361    void pre (X& v, Y& d) 
final 
  363        using namespace Dune::Hybrid;
 
  364        forEach(integralRange(Dune::Hybrid::size(amg_)), [&](
const auto i)
 
  366            std::get<decltype(i)::value>(amg_).pre(v[i], d[i]);
 
 
  383        using namespace Dune::Hybrid;
 
  384        forEach(integralRange(Dune::Hybrid::size(amg_)), [&](
const auto i)
 
  386            std::get<decltype(i)::value>(amg_).apply(v[i], d[i]);
 
 
  401        using namespace Dune::Hybrid;
 
  402        forEach(integralRange(Dune::Hybrid::size(amg_)), [&](
const auto i)
 
  404            std::get<decltype(i)::value>(amg_).post(v[i]);
 
 
  409    Dune::SolverCategory::Category 
category() const final
 
  411        return Dune::SolverCategory::sequential;
 
 
  415    template<
class LOP, 
class Criterion, 
class SmootherArgs, std::size_t... Is>
 
  417    : amg_(std::make_tuple(BlockAMG<Is>(*std::get<Is>(lop), *std::get<Is>(c), *std::get<Is>(sa))...))
 
 
  432    template<
class M, std::
size_t i>
 
  433    using DiagBlockType = std::decay_t<decltype(std::declval<M>()[Dune::index_constant<i>{}][Dune::index_constant<i>{}])>;
 
  435    template<
class X, std::
size_t i>
 
  436    using VecBlockType = std::decay_t<decltype(std::declval<X>()[Dune::index_constant<i>{}])>;
 
  438    template<
class M, 
class X, std::
size_t i>
 
  439    using Smoother = Dune::SeqSSOR<DiagBlockType<M, i>, VecBlockType<X, i>, VecBlockType<X, i>>;
 
  441    template<
class M, 
class X, std::
size_t i>
 
  442    using SmootherArgs = 
typename Dune::Amg::SmootherTraits<Smoother<M, X, i>>::Arguments;
 
  444    template<
class M, std::
size_t i>
 
  445    using Criterion = Dune::Amg::CoarsenCriterion<Dune::Amg::SymmetricCriterion<DiagBlockType<M, i>, Dune::Amg::FirstDiagonal>>;
 
  447    template<
class M, 
class X, std::
size_t i>
 
  448    using LinearOperator = Dune::MatrixAdapter<DiagBlockType<M, i>, VecBlockType<X, i>, VecBlockType<X, i>>;
 
  454    template<
class Matrix, 
class Vector>
 
  455    bool solve(
const Matrix& m, Vector& x, 
const Vector& b)
 
  459        Dune::Amg::Parameters params(15, 2000, 1.2, 1.6, Dune::Amg::atOnceAccu);
 
  460        params.setDefaultValuesIsotropic(3);
 
  463        auto criterion = makeCriterion_<Criterion, Matrix>(params, std::make_index_sequence<Matrix::N()>{});
 
  464        auto smootherArgs = makeSmootherArgs_<SmootherArgs, Matrix, Vector>(std::make_index_sequence<Matrix::N()>{});
 
  466        using namespace Dune::Hybrid;
 
  467        forEach(std::make_index_sequence<Matrix::N()>{}, [&](
const auto i)
 
  469            auto& args = std::get<decltype(i)::value>(smootherArgs);
 
  470            args->iterations = 1;
 
  471            args->relaxationFactor = 1;
 
  474        auto linearOperator = makeLinearOperator_<LinearOperator, Matrix, Vector>(m, std::make_index_sequence<Matrix::N()>{});
 
  479        Dune::BiCGSTABSolver<Vector> solver(op, preconditioner, this->
residReduction(),
 
  482        solver.apply(x, bTmp, result_);
 
  484        return result_.converged;
 
 
  487    const Dune::InverseOperatorResult& 
result()
 const 
 
  493    { 
return "block-diagonal AMG-preconditioned BiCGSTAB solver"; }
 
 
  496    template<
template<
class M, std::
size_t i> 
class Criterion, 
class Matrix, 
class Params, std::size_t... Is>
 
  497    auto makeCriterion_(
const Params& p, std::index_sequence<Is...>)
 
  499        return std::make_tuple(std::make_shared<Criterion<Matrix, Is>>(p)...);
 
  502    template<
template<
class M, 
class X, std::
size_t i> 
class SmootherArgs, 
class Matrix, 
class Vector, std::size_t... Is>
 
  503    auto makeSmootherArgs_(std::index_sequence<Is...>)
 
  505        return std::make_tuple(std::make_shared<SmootherArgs<Matrix, Vector, Is>>()...);
 
  508    template<
template<
class M, 
class X, std::
size_t i> 
class LinearOperator, 
class Matrix, 
class Vector, std::size_t... Is>
 
  509    auto makeLinearOperator_(
const Matrix& m, std::index_sequence<Is...>)
 
  511        return std::make_tuple(std::make_shared<LinearOperator<Matrix, Vector, Is>>(m[Dune::index_constant<Is>{}][Dune::index_constant<Is>{}])...);
 
  514    Dune::InverseOperatorResult result_;
 
 
A simple ilu0 block diagonal preconditioned BiCGSTABSolver.
Definition seqsolverbackend.hh:431
const Dune::InverseOperatorResult & result() const
Definition seqsolverbackend.hh:487
LinearSolver(const std::string ¶mGroup="")
Construct the solver.
Definition solver.hh:43
std::string name() const
Definition seqsolverbackend.hh:492
bool solve(const Matrix &m, Vector &x, const Vector &b)
Definition seqsolverbackend.hh:455
A simple ilu0 block diagonal preconditioner.
Definition seqsolverbackend.hh:300
void post(X &v) final
Clean up.
Definition seqsolverbackend.hh:399
typename std::decay_t< M > matrix_type
The matrix type the preconditioner is for.
Definition seqsolverbackend.hh:323
void apply(X &v, const Y &d) final
Apply one step of the preconditioner to the system A(v)=d.
Definition seqsolverbackend.hh:381
Dune::SolverCategory::Category category() const final
Category of the preconditioner (see SolverCategory::Category)
Definition seqsolverbackend.hh:409
Y range_type
The range type of the preconditioner.
Definition seqsolverbackend.hh:327
void pre(X &v, Y &d) final
Prepare the preconditioner.
Definition seqsolverbackend.hh:361
typename X::field_type field_type
The field type of the preconditioner.
Definition seqsolverbackend.hh:329
BlockDiagAMGPreconditioner(const LOP &lop, const Criterion &c, const SmootherArgs &sa)
Constructor.
Definition seqsolverbackend.hh:339
X domain_type
The domain type of the preconditioner.
Definition seqsolverbackend.hh:325
A simple ilu0 block diagonal preconditioned BiCGSTABSolver.
Definition seqsolverbackend.hh:225
std::string name() const
Definition seqsolverbackend.hh:248
const Dune::InverseOperatorResult & result() const
Definition seqsolverbackend.hh:243
bool solve(const Matrix &M, Vector &x, const Vector &b)
Definition seqsolverbackend.hh:231
LinearSolver(const std::string ¶mGroup="")
Construct the solver.
Definition solver.hh:43
A simple ilu0 block diagonal preconditioner.
Definition seqsolverbackend.hh:154
typename X::field_type field_type
The field type of the preconditioner.
Definition seqsolverbackend.hh:174
typename std::decay_t< M > matrix_type
The matrix type the preconditioner is for.
Definition seqsolverbackend.hh:168
Y range_type
The range type of the preconditioner.
Definition seqsolverbackend.hh:172
void pre(X &v, Y &d) final
Definition seqsolverbackend.hh:188
X domain_type
The domain type of the preconditioner.
Definition seqsolverbackend.hh:170
void post(X &) final
Definition seqsolverbackend.hh:199
Dune::SolverCategory::Category category() const final
Category of the preconditioner (see SolverCategory::Category)
Definition seqsolverbackend.hh:202
void apply(X &v, const Y &d) final
Definition seqsolverbackend.hh:190
BlockDiagILU0Preconditioner(const M &m, double w=1.0)
Constructor.
Definition seqsolverbackend.hh:182
A simple ilu0 block diagonal preconditioned RestartedGMResSolver.
Definition seqsolverbackend.hh:263
std::string name() const
Definition seqsolverbackend.hh:287
const Dune::InverseOperatorResult & result() const
Definition seqsolverbackend.hh:282
LinearSolver(const std::string ¶mGroup="")
Construct the solver.
Definition solver.hh:43
bool solve(const Matrix &M, Vector &x, const Vector &b)
Definition seqsolverbackend.hh:269
Solver for simple block-diagonal matrices (e.g. from explicit time stepping schemes)
Definition seqsolverbackend.hh:96
bool solve(const Matrix &A, Vector &x, const Vector &b)
Definition seqsolverbackend.hh:101
std::string name() const
Definition seqsolverbackend.hh:112
LinearSolver(const std::string ¶mGroup="")
Construct the solver.
Definition solver.hh:43
A general solver backend allowing arbitrary preconditioners and solvers.
Definition seqsolverbackend.hh:52
static bool solveWithParamTree(const Matrix &A, Vector &x, const Vector &b, const Dune::ParameterTree ¶ms)
Definition seqsolverbackend.hh:57
Scalar residReduction() const
the linear solver residual reduction
Definition solver.hh:98
int maxIter() const
the maximum number of linear solver iterations
Definition solver.hh:90
const std::string & paramGroup() const
the parameter group for getting parameter from the parameter tree
Definition solver.hh:78
LinearSolver(const std::string ¶mGroup="")
Construct the solver.
Definition solver.hh:43
int verbosity() const
the verbosity level
Definition solver.hh:82
static Dune::ParameterTree createParameterTree(const std::string ¶mGroup="")
Create a tree containing parameters required for the linear solvers and precondioners of the Dune IST...
Definition linearsolverparameters.hh:47
Adapter to turn a multi-type matrix into a thread-parallel linear operator. Adapts a matrix to the as...
Definition parallelmatrixadapter.hh:28
A preconditioner based on the Uzawa algorithm for saddle-point problems of the form                  ...
Definition preconditioners.hh:70
A Uzawa preconditioned BiCGSTAB solver for saddle-point problems.
Definition seqsolverbackend.hh:129
bool solve(const Matrix &A, Vector &x, const Vector &b)
Definition seqsolverbackend.hh:134
LinearSolver(const std::string ¶mGroup="")
Construct the solver.
Definition solver.hh:43
std::string name() const
Definition seqsolverbackend.hh:142
constexpr std::size_t preconditionerBlockLevel() noexcept
Returns the block level for the preconditioner for a given matrix.
Definition seqsolverbackend.hh:83
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:149
Generates a parameter tree required for the linear solvers and precondioners of the Dune ISTL.
Type traits to be used with matrix types.
const Scalar PengRobinsonMixture< Scalar, StaticParameters >::w
Definition pengrobinsonmixture.hh:140
Definition common/pdesolver.hh:24
A parallel version of a linear operator.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Dumux preconditioners for iterative solvers.
Base class for linear solvers.
Helper type to determine whether a given type is a Dune::MultiTypeBlockMatrix.
Definition matrix.hh:37
Utilities for template meta programming.