66 , isParallel_(
Dune::MPIHelper::getCollectiveCommunication().size() > 1)
69 DUNE_THROW(Dune::InvalidStateException,
"Using sequential constructor for parallel run. Use signature with gridView and dofMapper!");
82 const typename LinearSolverTraits::DofMapper& dofMapper,
87 , isParallel_(
Dune::MPIHelper::getCollectiveCommunication().size() > 1)
100 template<
class Matrix,
class Vector>
101 bool solve(Matrix& A, Vector& x, Vector& b)
104 solveSequentialOrParallel_(A, x, b);
106 solveSequential_(A, x, b);
109 return result_.converged;
123 return "AMG-preconditioned BiCGSTAB solver";
129 const Dune::InverseOperatorResult&
result()
const
137 template<
class Matrix,
class Vector>
138 void solveSequentialOrParallel_(Matrix& A, Vector& x, Vector& b)
140 if constexpr (LinearSolverTraits::canCommunicate)
144 if (LinearSolverTraits::isNonOverlapping(phelper_->gridView()))
146 using PTraits =
typename LinearSolverTraits::template ParallelNonoverlapping<Matrix, Vector>;
147 solveParallel_<PTraits>(A, x, b);
151 using PTraits =
typename LinearSolverTraits::template ParallelOverlapping<Matrix, Vector>;
152 solveParallel_<PTraits>(A, x, b);
156 solveSequential_(A, x, b);
160 solveSequential_(A, x, b);
164 template<
class ParallelTraits,
class Matrix,
class Vector>
165 void solveParallel_(Matrix& A, Vector& x, Vector& b)
167 using Comm =
typename ParallelTraits::Comm;
168 using LinearOperator =
typename ParallelTraits::LinearOperator;
169 using ScalarProduct =
typename ParallelTraits::ScalarProduct;
172 phelper_->initGhostsAndOwners();
174 std::shared_ptr<Comm> comm;
175 std::shared_ptr<LinearOperator> linearOperator;
176 std::shared_ptr<ScalarProduct> scalarProduct;
179 using SeqSmoother = Dune::SeqSSOR<Matrix, Vector, Vector>;
180 using Smoother =
typename ParallelTraits::template Preconditioner<SeqSmoother>;
181 solveWithAmg_<Smoother>(A, x, b, linearOperator, comm, scalarProduct);
185 template<
class Matrix,
class Vector>
186 void solveSequential_(Matrix& A, Vector& x, Vector& b)
188 using Comm = Dune::Amg::SequentialInformation;
189 using Traits =
typename LinearSolverTraits::template Sequential<Matrix, Vector>;
190 using LinearOperator =
typename Traits::LinearOperator;
191 using ScalarProduct =
typename Traits::ScalarProduct;
193 auto comm = std::make_shared<Comm>();
194 auto linearOperator = std::make_shared<LinearOperator>(A);
195 auto scalarProduct = std::make_shared<ScalarProduct>();
197 using Smoother = Dune::SeqSSOR<Matrix, Vector, Vector>;
198 solveWithAmg_<Smoother>(A, x, b, linearOperator, comm, scalarProduct);
201 template<
class Smoother,
class Matrix,
class Vector,
class LinearOperator,
class Comm,
class ScalarProduct>
202 void solveWithAmg_(Matrix& A, Vector& x, Vector& b,
203 std::shared_ptr<LinearOperator>& linearOperator,
204 std::shared_ptr<Comm>& comm,
205 std::shared_ptr<ScalarProduct>& scalarProduct)
207 using SmootherArgs =
typename Dune::Amg::SmootherTraits<Smoother>::Arguments;
208 using Criterion = Dune::Amg::CoarsenCriterion<Dune::Amg::SymmetricCriterion<Matrix, Dune::Amg::FirstDiagonal>>;
212 Dune::Amg::Parameters params(15, 2000, 1.2, 1.6, Dune::Amg::atOnceAccu);
213 params.setDefaultValuesIsotropic(LinearSolverTraits::GridView::dimension);
215 Criterion criterion(params);
216 SmootherArgs smootherArgs;
217 smootherArgs.iterations = 1;
218 smootherArgs.relaxationFactor = 1;
220 using Amg = Dune::Amg::AMG<LinearOperator, Vector, Smoother, Comm>;
221 auto amg = std::make_shared<Amg>(*linearOperator, criterion, smootherArgs, *comm);
223 Dune::BiCGSTABSolver<Vector> solver(*linearOperator, *scalarProduct, *amg, this->
residReduction(), this->
maxIter(),
224 comm->communicator().rank() == 0 ? this->verbosity() : 0);
226 solver.apply(x, b, result_);
230 std::unique_ptr<ParallelISTLHelper<LinearSolverTraits>> phelper_;
232 Dune::InverseOperatorResult result_;
233 bool isParallel_ =
false;
void prepareLinearAlgebraParallel(Matrix &A, Vector &b, std::shared_ptr< typename ParallelTraits::Comm > &comm, std::shared_ptr< typename ParallelTraits::LinearOperator > &fop, std::shared_ptr< typename ParallelTraits::ScalarProduct > &sp, ParallelHelper &pHelper)
Prepare linear algebra variables for parallel solvers.
Definition parallelhelpers.hh:830