diff --git a/dumux/linear/amgbackend.hh b/dumux/linear/amgbackend.hh index e0f986a39ca3d06718723f1691196e2c44863cb7..840933a97afea369ecc0b55a7bbe74cf0ba5642e 100644 --- a/dumux/linear/amgbackend.hh +++ b/dumux/linear/amgbackend.hh @@ -64,10 +64,11 @@ public: AMGBiCGSTABBackend(const std::string& paramGroup = "") : LinearSolver(paramGroup) , isParallel_(Dune::MPIHelper::getCollectiveCommunication().size() > 1) - , firstCall_(true) { if (isParallel_) DUNE_THROW(Dune::InvalidStateException, "Using sequential constructor for parallel run. Use signature with gridView and dofMapper!"); + + reset(); } /*! @@ -83,8 +84,9 @@ public: : LinearSolver(paramGroup) , phelper_(std::make_shared<ParallelISTLHelper<LinearSolverTraits>>(gridView, dofMapper)) , isParallel_(Dune::MPIHelper::getCollectiveCommunication().size() > 1) - , firstCall_(true) - {} + { + reset(); + } /*! * \brief Solve a linear system. @@ -105,6 +107,12 @@ public: return result_.converged; } + //! reset the linear solver + void reset() + { + firstCall_ = true; + } + /*! * \brief The name of the solver */ @@ -158,10 +166,13 @@ private: using LinearOperator = typename ParallelTraits::LinearOperator; using ScalarProduct = typename ParallelTraits::ScalarProduct; + if (firstCall_) + phelper_->initGhostsAndOwners(); + std::shared_ptr<Comm> comm; std::shared_ptr<LinearOperator> linearOperator; std::shared_ptr<ScalarProduct> scalarProduct; - prepareLinearAlgebraParallel<LinearSolverTraits, ParallelTraits>(A, b, comm, linearOperator, scalarProduct, *phelper_, firstCall_); + prepareLinearAlgebraParallel<LinearSolverTraits, ParallelTraits>(A, b, comm, linearOperator, scalarProduct, *phelper_); using SeqSmoother = Dune::SeqSSOR<Matrix, Vector, Vector>; using Smoother = typename ParallelTraits::template Preconditioner<SeqSmoother>; diff --git a/dumux/linear/parallelhelpers.hh b/dumux/linear/parallelhelpers.hh index f7346ff93e382846e582593292a9ea4af9df7462..1f825e3ddf32cb930a4a1eb52c214a5e405a2985 100644 --- a/dumux/linear/parallelhelpers.hh +++ b/dumux/linear/parallelhelpers.hh @@ -792,11 +792,8 @@ 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, - const bool firstCall) + ParallelHelper& pHelper) { - if (firstCall) pHelper.initGhostsAndOwners(); - if constexpr (ParallelTraits::isNonOverlapping) { // extend the matrix pattern such that it is usable for a parallel solver