diff --git a/opm/autodiff/ISTLSolverEbosCpr.hpp b/opm/autodiff/ISTLSolverEbosCpr.hpp index f4680a959..3d07f3300 100644 --- a/opm/autodiff/ISTLSolverEbosCpr.hpp +++ b/opm/autodiff/ISTLSolverEbosCpr.hpp @@ -149,7 +149,7 @@ namespace Opm constexpr int category = Dune::SolverCategory::overlapping; typedef Dune::ScalarProductChooser ScalarProductChooser; typedef std::unique_ptr SPPointer; - SPPointer sp(ScalarProductChooser::construct(info)); + SPPointer sp(ScalarProductChooser::construct(*comm_)); sp_ = std::move(sp); #endif @@ -227,6 +227,9 @@ namespace Opm // Since DUNE 2.2 we also need to pass the smoother args instead of steps directly using AmgType = typename std::conditional::value, BlackoilAmgType, ParallelBlackoilAmgType>::type; + using SpType = typename std::conditional::value, + Dune::SeqScalarProduct, + Dune::OverlappingSchwarzScalarProduct >::type; using OperatorType = typename std::conditional::value, MatrixAdapter, ParallelMatrixAdapter>::type; typedef typename AmgType::Smoother Smoother; @@ -273,7 +276,7 @@ namespace Opm verbosity_linsolve = this->parameters_.linear_solver_verbosity_; } - linsolve_.reset(new Dune::BiCGSTABSolver(wellOpA, *sp_, *amg_, + linsolve_.reset(new Dune::BiCGSTABSolver(wellOpA, reinterpret_cast(*sp_), reinterpret_cast(*amg_), this->parameters_.linear_solver_reduction_, this->parameters_.linear_solver_maxiter_, verbosity_linsolve)); @@ -295,11 +298,6 @@ namespace Opm protected: -#if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 6) - typedef std::shared_ptr< Dune::ScalarProduct > SPPointer; -#else - typedef std::unique_ptr SPPointer; -#endif ///! \brief The dune-istl operator (either serial or parallel std::unique_ptr< Dune::LinearOperator > opA_; ///! \brief Serial well matrix adapter @@ -309,11 +307,12 @@ namespace Opm ///! \brief The preconditoner to use (either serial or parallel CPR with AMG) std::unique_ptr< Preconditioner > amg_; + using SPPointer = std::shared_ptr< Dune::ScalarProduct >; SPPointer sp_; std::shared_ptr< Dune::BiCGSTABSolver > linsolve_; - const void* oldMat; - using POrComm = Dune::OwnerOverlapCopyCommunication; - std::shared_ptr comm_; + const void* oldMat; + using POrComm = Dune::OwnerOverlapCopyCommunication; + std::shared_ptr comm_; }; // end ISTLSolver } // namespace Opm diff --git a/opm/autodiff/amgcpr.hh b/opm/autodiff/amgcpr.hh index f5ae6aa98..838b220b1 100644 --- a/opm/autodiff/amgcpr.hh +++ b/opm/autodiff/amgcpr.hh @@ -137,11 +137,19 @@ namespace Dune /** \copydoc Preconditioner::apply */ void apply(Domain& v, const Range& d); +#if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 6) //! Category of the preconditioner (see SolverCategory::Category) virtual SolverCategory::Category category() const { return category_; } +#else + enum { + //! \brief The category the preconditioner is part of. + category = std::is_same::value? + Dune::SolverCategory::sequential:Dune::SolverCategory::overlapping + }; +#endif /** \copydoc Preconditioner::post */ void post(Domain& x); @@ -299,8 +307,10 @@ namespace Dune bool additive; bool coarsesolverconverged; std::shared_ptr coarseSmoother_; +#if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 6) /** @brief The solver category. */ SolverCategory::Category category_; +#endif /** @brief The verbosity level. */ std::size_t verbosity_; }; @@ -315,7 +325,9 @@ namespace Dune buildHierarchy_(amg.buildHierarchy_), additive(amg.additive), coarsesolverconverged(amg.coarsesolverconverged), coarseSmoother_(amg.coarseSmoother_), +#if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 6) category_(amg.category_), +#endif verbosity_(amg.verbosity_) { if(amg.rhs_) @@ -337,8 +349,10 @@ namespace Dune postSteps_(parms.getNoPostSmoothSteps()), buildHierarchy_(false), additive(parms.getAdditive()), coarsesolverconverged(true), coarseSmoother_(), +#if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 6) // #warning should category be retrieved from matrices? category_(SolverCategory::category(*smoothers_->coarsest())), +#endif verbosity_(parms.debugLevel()) { assert(matrices_->isBuilt()); @@ -360,14 +374,15 @@ namespace Dune postSteps_(criterion.getNoPostSmoothSteps()), buildHierarchy_(true), additive(criterion.getAdditive()), coarsesolverconverged(true), coarseSmoother_(), +#if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 6) category_(SolverCategory::category(pinfo)), +#endif verbosity_(criterion.debugLevel()) { +#if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 6) if(SolverCategory::category(matrix) != SolverCategory::category(pinfo)) DUNE_THROW(InvalidSolverCategory, "Matrix and Communication must have the same SolverCategory!"); - // TODO: reestablish compile time checks. - //static_assert(static_cast(PI::category)==static_cast(S::category), - // "Matrix and Solver must match in terms of category!"); +#endif createHierarchies(criterion, const_cast(matrix), pinfo); } @@ -458,7 +473,16 @@ namespace Dune } coarseSmoother_.reset(ConstructionTraits::construct(cargs)); + +#if DUNE_VERSION_NEWER(DUNE_ISTL, 2, 6) scalarProduct_ = createScalarProduct(cargs.getComm(),category()); +#else + typedef Dune::ScalarProductChooser + ScalarProductChooser; + // the scalar product. + scalarProduct_.reset(ScalarProductChooser::construct(cargs.getComm())); +#endif + typedef DirectSolverSelector< typename M::matrix_type, X > SolverSelector; @@ -498,15 +522,23 @@ namespace Dune // we have to allocate these types using the rebound allocator // in order to ensure that we fulfill the alignement requirements solver_.reset(new BiCGSTABSolver(const_cast(matrices_->matrices().coarsest().getRedistributed()), - *scalarProduct_, + // Cast needed for Dune <=2.5 + reinterpret_cast::value, + Dune::SeqScalarProduct, + Dune::OverlappingSchwarzScalarProduct >::type&>(*scalarProduct_), *coarseSmoother_, 1E-2, 1000, 0)); else solver_.reset(); }else { solver_.reset(new BiCGSTABSolver(const_cast(*matrices_->matrices().coarsest()), - *scalarProduct_, - *coarseSmoother_, 1E-2, 1000, 0)); + // Cast needed for Dune <=2.5 + reinterpret_cast::value, + Dune::SeqScalarProduct, + Dune::OverlappingSchwarzScalarProduct >::type&>(*scalarProduct_), + *coarseSmoother_, 1E-2, 1000, 0)); // // we have to allocate these types using the rebound allocator // // in order to ensure that we fulfill the alignement requirements // using Alloc = typename A::template rebind>::other;