diff --git a/dumux/linear/istlsolvers.hh b/dumux/linear/istlsolvers.hh index 42dfbf1914e04d1569cf53709977536ec6c2ef42..6d29313ed955623e3c2a5a847b2e81dfcc063f34 100644 --- a/dumux/linear/istlsolvers.hh +++ b/dumux/linear/istlsolvers.hh @@ -144,12 +144,18 @@ public: initializeParameters_(paramGroup); #if HAVE_MPI solverCategory_ = Detail::solverCategory<LinearSolverTraits>(gridView); - if (solverCategory_ != Dune::SolverCategory::sequential) + if constexpr (LinearSolverTraits::canCommunicate) { - parallelHelper_ = std::make_unique<ParallelISTLHelper<LinearSolverTraits>>(gridView, dofMapper); - communication_ = std::make_shared<Comm>(gridView.comm(), solverCategory_); - scalarProduct_ = Dune::createScalarProduct<XVector>(*communication_, solverCategory_); - parallelHelper_->createParallelIndexSet(*communication_); + + if (solverCategory_ != Dune::SolverCategory::sequential) + { + parallelHelper_ = std::make_unique<ParallelISTLHelper<LinearSolverTraits>>(gridView, dofMapper); + communication_ = std::make_shared<Comm>(gridView.comm(), solverCategory_); + scalarProduct_ = Dune::createScalarProduct<XVector>(*communication_, solverCategory_); + parallelHelper_->createParallelIndexSet(*communication_); + } + else + scalarProduct_ = std::make_shared<ScalarProduct>(); } else scalarProduct_ = std::make_shared<ScalarProduct>(); @@ -174,10 +180,13 @@ public: solverCategory_ = Detail::solverCategory(gridView); scalarProduct_ = scalarProduct; communication_ = communication; - if (solverCategory_ != Dune::SolverCategory::sequential) + if constexpr (LinearSolverTraits::canCommunicate) { - parallelHelper_ = std::make_unique<ParallelISTLHelper<LinearSolverTraits>>(gridView, dofMapper); - parallelHelper_->createParallelIndexSet(communication); + if (solverCategory_ != Dune::SolverCategory::sequential) + { + parallelHelper_ = std::make_unique<ParallelISTLHelper<LinearSolverTraits>>(gridView, dofMapper); + parallelHelper_->createParallelIndexSet(communication); + } } } #endif diff --git a/dumux/linear/parallelhelpers.hh b/dumux/linear/parallelhelpers.hh index a0903c215fa3b2d94199190229cdfc916b17abd6..a950abd4272113b84637b14e8bd6f28e5b2c46f4 100644 --- a/dumux/linear/parallelhelpers.hh +++ b/dumux/linear/parallelhelpers.hh @@ -30,6 +30,8 @@ #include <dune/grid/common/partitionset.hh> #include <dune/istl/owneroverlapcopy.hh> #include <dune/istl/paamg/pinfo.hh> +#include <dune/istl/bvector.hh> +#include <dune/istl/multitypeblockvector.hh> #include <dumux/parallel/vectorcommdatahandle.hh> #include <dumux/common/gridcapabilities.hh> @@ -489,7 +491,7 @@ public: : gridView_(gridView), mapper_(mapper) {} - // \brief Make a vector of the box model consistent. + //! \brief Make a vector consistent for non-overlapping domain decomposition methods template<class Block, class Alloc> void makeNonOverlappingConsistent(Dune::BlockVector<Block, Alloc>& v) const { @@ -504,6 +506,13 @@ public: DUNE_THROW(Dune::InvalidStateException, "Cannot call makeNonOverlappingConsistent for a grid that cannot communicate codim-" << dofCodim << "-entities."); } + //! \brief Make a vector consistent for non-overlapping domain decomposition methods + template<class... Blocks> + void makeNonOverlappingConsistent(Dune::MultiTypeBlockVector<Blocks...>& v) const + { + DUNE_THROW(Dune::NotImplemented, "makeNonOverlappingConsistent for Dune::MultiTypeBlockVector"); + } + private: const GridView gridView_; //!< the grid view const DofMapper& mapper_; //!< the dof mapper diff --git a/dumux/linear/solvercategory.hh b/dumux/linear/solvercategory.hh index 16ab7226aeb901df1278d4705c01d14f5e7bead8..3943680d0020277ee06243e6d2a843ccb372deec 100644 --- a/dumux/linear/solvercategory.hh +++ b/dumux/linear/solvercategory.hh @@ -37,7 +37,15 @@ Dune::SolverCategory::Category solverCategory(const GridView& gridView) return Dune::SolverCategory::overlapping; } else - return Dune::SolverCategory::sequential; + { + if (gridView.comm().size() > 1) + DUNE_THROW(Dune::InvalidStateException, + "Attempt to construct parallel solver but LinearSolverTraits::canCommunicate is false. " << + "Maybe the grid implementation does not support distributed parallelism." + ); + } + + return Dune::SolverCategory::sequential; } } // end namespace Dumux::Detail diff --git a/test/porousmediumflow/mpnc/thermalnonequilibrium/main.cc b/test/porousmediumflow/mpnc/thermalnonequilibrium/main.cc index af9fafb9a2dc99b7ff21e2fd0f0892ba5144c2d3..9b37025a83d83664cda735d661f99ba505f2c68d 100644 --- a/test/porousmediumflow/mpnc/thermalnonequilibrium/main.cc +++ b/test/porousmediumflow/mpnc/thermalnonequilibrium/main.cc @@ -33,8 +33,9 @@ #include <dumux/common/parameters.hh> #include <dumux/common/dumuxmessage.hh> -#include <dumux/linear/amgbackend.hh> +#include <dumux/linear/istlsolvers.hh> #include <dumux/linear/linearsolvertraits.hh> +#include <dumux/linear/linearalgebratraits.hh> #include <dumux/porousmediumflow/nonequilibrium/newtonsolver.hh> #include <dumux/assembly/fvassembler.hh> @@ -123,7 +124,7 @@ int main(int argc, char** argv) auto assembler = std::make_shared<Assembler>(problem, gridGeometry, gridVariables, timeLoop, xOld); // the linear solver - using LinearSolver = AMGBiCGSTABBackend<LinearSolverTraits<GridGeometry>>; + using LinearSolver = AMGBiCGSTABIstlSolver<LinearSolverTraits<GridGeometry>, LinearAlgebraTraitsFromAssembler<Assembler>>; auto linearSolver = std::make_shared<LinearSolver>(leafGridView, gridGeometry->dofMapper()); // the non-linear solver