| 
        
Go to the documentation of this file.
   21#ifndef OPM_FLEXIBLE_SOLVER_IMPL_HEADER_INCLUDED    22#define OPM_FLEXIBLE_SOLVER_IMPL_HEADER_INCLUDED    24#include <opm/common/ErrorMacros.hpp>    25#include <opm/common/TimingMacros.hpp>    35#include <dune/common/fmatrix.hh>    36#include <dune/istl/bcrsmatrix.hh>    37#include <dune/istl/solvers.hh>    38#include <dune/istl/umfpack.hh>    39#include <dune/istl/owneroverlapcopy.hh>    40#include <dune/istl/paamg/pinfo.hh>    45#include <opm/simulators/linalg/gpuistl_hip/SolverAdapter.hpp>    54    template <class  Operator>    58                   const std::function<VectorType ()>& weightsCalculator,    59                   std::size_t pressureIndex)    61        init(op, Dune::Amg::SequentialInformation(), prm, weightsCalculator,    66    template <class  Operator>    72                   const std::function<VectorType ()>& weightsCalculator,    73                   std::size_t pressureIndex)    75        init(op, comm, prm, weightsCalculator, pressureIndex);    78    template <class  Operator>    84            recreateDirectSolver();    86        linsolver_->apply(x, rhs, res);    89    template <class  Operator>    95            recreateDirectSolver();    97        linsolver_->apply(x, rhs, reduction, res);   101    template <class  Operator>   106        return *preconditioner_;   109    template <class  Operator>   110    Dune::SolverCategory::Category   114        return linearoperator_for_solver_->category();   118    template <class  Operator>   119    template <class  Comm>   124                 const std::function<VectorType()> weightsCalculator,   126                 std::size_t pressureIndex)   129        linearoperator_for_solver_ = &op;   136        scalarproduct_ = Dune::createScalarProduct<VectorType, Comm>(comm, op.category());   139    template <class  Operator>   141    FlexibleSolver<Operator>::   142    initOpPrecSp(Operator& op,   144                 const std::function<VectorType()> weightsCalculator,   145                 const Dune::Amg::SequentialInformation&,   146                 std::size_t pressureIndex)   149        linearoperator_for_solver_ = &op;   155        scalarproduct_ = std::make_shared<Dune::SeqScalarProduct<VectorType>>();   159    template <class  Operator>   160    template <class  Comm>   162    FlexibleSolver<Operator>::   165        const bool is_iorank = comm.communicator().rank() == 0;   166        const double tol = prm.get <double >("tol" , 1e-2);   167        const int maxiter = prm.get <int >("maxiter" , 200);   168        const int verbosity = is_iorank ? prm.get <int >("verbosity" , 0) : 0;   169        const std::string solver_type = prm.get <std::string>("solver" , "bicgstab" );   177        if (solver_type == "bicgstab" ) {   178            linsolver_ = std::make_shared<Dune::BiCGSTABSolver<VectorType>>(*linearoperator_for_solver_,   184        } else if  (solver_type == "loopsolver" ) {   185            linsolver_ = std::make_shared<Dune::LoopSolver<VectorType>>(*linearoperator_for_solver_,   191        } else if  (solver_type == "gmres" ) {   192            int restart = prm.get <int >("restart" , 15);   193            linsolver_ = std::make_shared<Dune::RestartedGMResSolver<VectorType>>(*linearoperator_for_solver_,   202            if constexpr (!Opm::is_gpu_operator_v<Operator>) {   203                if (solver_type == "flexgmres" ) {   204                    int restart = prm.get <int >("restart" , 15);   205                    linsolver_ = std::make_shared<Dune::RestartedFlexibleGMResSolver<VectorType>>(*linearoperator_for_solver_,   212#if HAVE_SUITESPARSE_UMFPACK   213                } else if  (solver_type == "umfpack" ) {   214                    if constexpr (std::is_same_v<typename VectorType::field_type,float>) {   215                        OPM_THROW(std::invalid_argument, "UMFPack cannot be used with floats" );   217                        using MatrixType = std::remove_const_t<std::remove_reference_t<decltype (linearoperator_for_solver_->getmat())>>;   218                        linsolver_ = std::make_shared<Dune::UMFPack<MatrixType>>(linearoperator_for_solver_->getmat(), verbosity, false );   219                        direct_solver_ = true ;   223                } else if  (solver_type == "gpubicgstab" ) {   225                        *linearoperator_for_solver_,   237            OPM_THROW(std::invalid_argument,   238                      "Properties: Solver " + solver_type + " not known." );   248    template <class  Operator>   250    FlexibleSolver<Operator>::   251    recreateDirectSolver()   253#if HAVE_SUITESPARSE_UMFPACK   254        if constexpr (!Opm::is_gpu_operator_v<Operator>) {   255            if constexpr (std::is_same_v<typename VectorType::field_type, float>) {   256                OPM_THROW(std::invalid_argument, "UMFPack cannot be used with floats" );   258                using MatrixType = std::remove_const_t<std::remove_reference_t<decltype (linearoperator_for_solver_->getmat())>>;   259                linsolver_ = std::make_shared<Dune::UMFPack<MatrixType>>(linearoperator_for_solver_->getmat(), 0, false );   263        OPM_THROW(std::logic_error, "Direct solver specified, but the FlexibleSolver class was not compiled with SuiteSparse support." );   270    template <class  Operator>   271    template <class  Comm>   273    FlexibleSolver<Operator>::   277         const std::function<VectorType()> weightsCalculator,   278         std::size_t pressureIndex)   280        initOpPrecSp(op, prm, weightsCalculator, comm, pressureIndex);   281        initSolver(prm, comm);   290template<class  Scalar, int  N>   291using BV = Dune::BlockVector<Dune::FieldVector<Scalar, N>>;   292template<class  Scalar, int  N>   293using OBM = Dune::BCRSMatrix<Opm::MatrixBlock<Scalar, N, N>>;   296template<class  Scalar, int  N>   298template<class  Scalar, int  N>   304using Comm = Dune::OwnerOverlapCopyCommunication<int, int>;   305template<class  Scalar, int  N>   307template<class  Scalar, int  N>   309template<class  Scalar, int  N>   316#define INSTANTIATE_FLEXIBLESOLVER_OP(...)                                                          \   317    template class Dune::FlexibleSolver<__VA_ARGS__>;                                               \   318    template Dune::FlexibleSolver<__VA_ARGS__>::                                                    \   319        FlexibleSolver(__VA_ARGS__& op,                                                             \   321                       const Opm::PropertyTree& prm,                                                \   322                       const std::function<typename __VA_ARGS__::domain_type()>& weightsCalculator, \   323                       std::size_t pressureIndex);   325#define INSTANTIATE_FLEXIBLESOLVER(T,N)         \   326    INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpM<T,N>); \   327    INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpW<T,N>); \   328    INSTANTIATE_FLEXIBLESOLVER_OP(ParOpM<T,N>); \   329    INSTANTIATE_FLEXIBLESOLVER_OP(ParOpW<T,N>); \   330    INSTANTIATE_FLEXIBLESOLVER_OP(ParOpD<T,N>);   334#define INSTANTIATE_FLEXIBLESOLVER_OP(...) \   335    template class Dune::FlexibleSolver<__VA_ARGS__>;   337#define INSTANTIATE_FLEXIBLESOLVER(T,N)         \   338    INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpM<T,N>); \   339    INSTANTIATE_FLEXIBLESOLVER_OP(SeqOpW<T,N>); Dune::OverlappingSchwarzOperator< OBM< Scalar, N >, BV< Scalar, N >, BV< Scalar, N >, Comm > ParOpD Definition: FlexibleSolver_impl.hpp:310Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, N, N > > OBM Definition: FlexibleSolver_impl.hpp:293Dune::BlockVector< Dune::FieldVector< Scalar, N > > BV Definition: FlexibleSolver_impl.hpp:291Dune::OwnerOverlapCopyCommunication< int, int > Comm Definition: FlexibleSolver_impl.hpp:304Dune::MatrixAdapter< OBM< Scalar, N >, BV< Scalar, N >, BV< Scalar, N > > SeqOpM Definition: FlexibleSolver_impl.hpp:297Definition: FlexibleSolver.hpp:45virtual Dune::SolverCategory::Category category() const override Definition: FlexibleSolver_impl.hpp:112virtual void apply(VectorType &x, VectorType &rhs, Dune::InverseOperatorResult &res) override Definition: FlexibleSolver_impl.hpp:81typename Operator::domain_type VectorType Definition: FlexibleSolver.hpp:47FlexibleSolver(Operator &op, const Opm::PropertyTree &prm, const std::function< VectorType()> &weightsCalculator, std::size_t pressureIndex) Create a sequential solver. Definition: FlexibleSolver_impl.hpp:56AbstractPrecondType & preconditioner() Access the contained preconditioner. Definition: FlexibleSolver_impl.hpp:104Dune linear operator that assumes ghost rows are ordered after interior rows. Avoids some computation... Definition: WellOperators.hpp:402static PrecPtr create(const Operator &op, const PropertyTree &prm, const std::function< Vector()> &weightsCalculator={}, std::size_t pressureIndex=std::numeric_limits< std::size_t >::max()) Definition: PreconditionerFactory_impl.hpp:154Hierarchical collection of key/value pairs. Definition: PropertyTree.hpp:39T get(const std::string &key) conststd::optional< PropertyTree > get_child_optional(const std::string &key) constAdapter to combine a matrix and another linear operator into a combined linear operator. Definition: WellOperators.hpp:299Adapter to combine a matrix and another linear operator into a combined linear operator. Definition: WellOperators.hpp:225Wraps a CUDA solver to work with CPU data. Definition: SolverAdapter.hpp:52Definition: fvbaseprimaryvariables.hh:141Dune::InverseOperatorResult InverseOperatorResult Definition: GpuBridge.hpp:32   |