13#ifndef DUMUX_PARALLEL_AMGBACKEND_HH
14#define DUMUX_PARALLEL_AMGBACKEND_HH
16#warning "This header is deprecated and will be removed after release 3.7. Use the AMG solver from dumux/linear/istlsolvers.hh"
20#include <dune/common/exceptions.hh>
21#include <dune/common/parallel/indexset.hh>
22#include <dune/common/parallel/mpicommunication.hh>
23#include <dune/common/parallel/mpihelper.hh>
24#include <dune/grid/common/capabilities.hh>
25#include <dune/istl/paamg/amg.hh>
26#include <dune/istl/paamg/pinfo.hh>
27#include <dune/istl/solvers.hh>
36template <
class LinearSolverTraits>
45 [[deprecated(
"Use new AMGBiCGSTABIstlSolver<LinearSolverTraits, LinearAlgebraTraits> with 2nd template parameter from dumux/linear/istlsolvers.hh.")]]
48 , isParallel_(
Dune::MPIHelper::getCommunication().size() > 1)
51 DUNE_THROW(Dune::InvalidStateException,
"Using sequential constructor for parallel run. Use signature with gridView and dofMapper!");
53 checkAvailabilityOfDirectSolver_();
63 [[deprecated(
"Use new AMGBiCGSTABIstlSolver<LinearSolverTraits, LinearAlgebraTraits> with 2nd template parameter from dumux/linear/istlsolvers.hh.")]]
65 const typename LinearSolverTraits::DofMapper& dofMapper,
69 , isParallel_(
Dune::MPIHelper::getCommunication().size() > 1)
76 phelper_ = std::make_unique<ParallelISTLHelper<LinearSolverTraits>>(gridView, dofMapper);
79 checkAvailabilityOfDirectSolver_();
89 const typename LinearSolverTraits::DofMapper& dofMapper)
93 phelper_ = std::make_unique<ParallelISTLHelper<LinearSolverTraits>>(gridView, dofMapper);
104 template<
class Matrix,
class Vector>
105 bool solve(Matrix& A, Vector& x, Vector& b)
108 solveSequentialOrParallel_(A, x, b);
110 solveSequential_(A, x, b);
112 return result_.converged;
120 return "AMG-preconditioned BiCGSTAB solver";
126 const Dune::InverseOperatorResult&
result()
const
131 template<
class Vector>
136 void checkAvailabilityOfDirectSolver_()
138#if !HAVE_SUPERLU && !HAVE_UMFPACK
139 std::cout <<
"\nAMGBiCGSTABBackend: No direct solver backend found. Using iterative solver as coarse grid solver.\n"
140 <<
"Note that dune-istl currently hard-codes a tolerance of 1e-2 for the iterative coarse grid solver.\n"
141 <<
"This may result in reduced accuracy or performance depending on your setup.\nConsider installing "
142 <<
"UMFPack (SuiteSparse) or SuperLU or apply the istl patch, see dumux/patches/README.md." << std::endl;
147 template<
class Matrix,
class Vector>
148 void solveSequentialOrParallel_(Matrix& A, Vector& x, Vector& b)
154 if (LinearSolverTraits::isNonOverlapping(phelper_->gridView()))
156 using PTraits =
typename LinearSolverTraits::template ParallelNonoverlapping<Matrix, Vector>;
157 solveParallel_<PTraits>(A, x, b);
161 using PTraits =
typename LinearSolverTraits::template ParallelOverlapping<Matrix, Vector>;
162 solveParallel_<PTraits>(A, x, b);
166 solveSequential_(A, x, b);
170 solveSequential_(A, x, b);
174 template<
class ParallelTraits,
class Matrix,
class Vector>
175 void solveParallel_(Matrix& A, Vector& x, Vector& b)
177 using Comm =
typename ParallelTraits::Comm;
178 using LinearOperator =
typename ParallelTraits::LinearOperator;
179 using ScalarProduct =
typename ParallelTraits::ScalarProduct;
181 std::shared_ptr<Comm> comm;
182 std::shared_ptr<LinearOperator> linearOperator;
183 std::shared_ptr<ScalarProduct> scalarProduct;
184 prepareLinearAlgebraParallel<LinearSolverTraits, ParallelTraits>(A, b, comm, linearOperator, scalarProduct, *phelper_);
186 using SeqSmoother = Dune::SeqSSOR<Matrix, Vector, Vector>;
187 using Smoother =
typename ParallelTraits::template Preconditioner<SeqSmoother>;
188 solveWithAmg_<Smoother>(A, x, b, linearOperator, comm, scalarProduct);
192 template<
class Matrix,
class Vector>
193 void solveSequential_(Matrix& A, Vector& x, Vector& b)
195 using Comm = Dune::Amg::SequentialInformation;
196 using Traits =
typename LinearSolverTraits::template Sequential<Matrix, Vector>;
197 using LinearOperator =
typename Traits::LinearOperator;
198 using ScalarProduct =
typename Traits::ScalarProduct;
200 auto comm = std::make_shared<Comm>();
201 auto linearOperator = std::make_shared<LinearOperator>(A);
202 auto scalarProduct = std::make_shared<ScalarProduct>();
204 using Smoother = Dune::SeqSSOR<Matrix, Vector, Vector>;
205 solveWithAmg_<Smoother>(A, x, b, linearOperator, comm, scalarProduct);
208 template<
class Smoother,
class Matrix,
class Vector,
class LinearOperator,
class Comm,
class ScalarProduct>
209 void solveWithAmg_(Matrix& A, Vector& x, Vector& b,
210 std::shared_ptr<LinearOperator>& linearOperator,
211 std::shared_ptr<Comm>& comm,
212 std::shared_ptr<ScalarProduct>& scalarProduct)
214 using SmootherArgs =
typename Dune::Amg::SmootherTraits<Smoother>::Arguments;
215 using Criterion = Dune::Amg::CoarsenCriterion<Dune::Amg::SymmetricCriterion<Matrix, Dune::Amg::FirstDiagonal>>;
219 Dune::Amg::Parameters params(15, 2000, 1.2, 1.6, Dune::Amg::atOnceAccu);
220 params.setDefaultValuesIsotropic(LinearSolverTraits::GridView::dimension);
222 Criterion criterion(params);
223 SmootherArgs smootherArgs;
224 smootherArgs.iterations = 1;
225 smootherArgs.relaxationFactor = 1;
227 using Amg = Dune::Amg::AMG<LinearOperator, Vector, Smoother, Comm>;
228 auto amg = std::make_shared<Amg>(*linearOperator, criterion, smootherArgs, *comm);
230 Dune::BiCGSTABSolver<Vector> solver(*linearOperator, *scalarProduct, *amg, this->
residReduction(), this->
maxIter(),
231 comm->communicator().rank() == 0 ? this->verbosity() : 0);
233 solver.apply(x, b, result_);
237 std::unique_ptr<ParallelISTLHelper<LinearSolverTraits>> phelper_;
239 Dune::InverseOperatorResult result_;
240 bool isParallel_ =
false;
Definition: amgbackend.hh:38
const Dune::InverseOperatorResult & result() const
The result containing the convergence history.
Definition: amgbackend.hh:126
std::string name() const
The name of the solver.
Definition: amgbackend.hh:118
AMGBiCGSTABBackend(const std::string ¶mGroup="")
Construct the backend for the sequential case only.
Definition: amgbackend.hh:46
Scalar norm(const Vector &x) const =delete
AMGBiCGSTABBackend(const typename LinearSolverTraits::GridView &gridView, const typename LinearSolverTraits::DofMapper &dofMapper, const std::string ¶mGroup="")
Construct the backend for parallel or sequential runs.
Definition: amgbackend.hh:64
bool solve(Matrix &A, Vector &x, Vector &b)
Solve a linear system.
Definition: amgbackend.hh:105
void updateAfterGridAdaption(const typename LinearSolverTraits::GridView &gridView, const typename LinearSolverTraits::DofMapper &dofMapper)
Update the solver after grid adaption.
Definition: amgbackend.hh:88
Base class for linear solvers.
Definition: solver.hh:27
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
int verbosity() const
the verbosity level
Definition: solver.hh:82
double Scalar
Definition: solver.hh:31
static constexpr bool canCommunicate
Definition: gridcapabilities.hh:51
Definition: common/pdesolver.hh:24
Provides a helper class for nonoverlapping decomposition.
Base class for linear solvers.