diff --git a/opm/simulators/linalg/bda/opencl/CPR.cpp b/opm/simulators/linalg/bda/opencl/CPR.cpp index 9e63d5fe4..3c2003514 100644 --- a/opm/simulators/linalg/bda/opencl/CPR.cpp +++ b/opm/simulators/linalg/bda/opencl/CPR.cpp @@ -44,7 +44,7 @@ using Opm::OpmLog; using Dune::Timer; template -CPR::CPR(int verbosity_, bool opencl_ilu_parallel_) : +CPR::CPR(bool opencl_ilu_parallel_, int verbosity_) : Preconditioner(verbosity_), opencl_ilu_parallel(opencl_ilu_parallel_) { bilu0 = std::make_unique >(opencl_ilu_parallel, verbosity_); diff --git a/opm/simulators/linalg/bda/opencl/CPR.hpp b/opm/simulators/linalg/bda/opencl/CPR.hpp index 515000ec5..8afe7f497 100644 --- a/opm/simulators/linalg/bda/opencl/CPR.hpp +++ b/opm/simulators/linalg/bda/opencl/CPR.hpp @@ -115,8 +115,7 @@ private: void create_preconditioner_amg(BlockedMatrix *mat); public: - - CPR(int verbosity, bool opencl_ilu_parallel); + CPR(bool opencl_ilu_parallel, int verbosity); bool analyze_matrix(BlockedMatrix *mat) override; bool analyze_matrix(BlockedMatrix *mat, BlockedMatrix *jacMat) override; diff --git a/opm/simulators/linalg/bda/opencl/Preconditioner.cpp b/opm/simulators/linalg/bda/opencl/Preconditioner.cpp index 1cf554a05..4e61ad592 100644 --- a/opm/simulators/linalg/bda/opencl/Preconditioner.cpp +++ b/opm/simulators/linalg/bda/opencl/Preconditioner.cpp @@ -18,14 +18,17 @@ */ #include -#include +#include + #include #include #include #include #include -#include + +#include +#include namespace Opm { @@ -40,16 +43,20 @@ void Preconditioner::setOpencl(std::shared_ptr& context } template -std::unique_ptr > Preconditioner::create(PreconditionerType type, int verbosity, bool opencl_ilu_parallel) { - if (type == PreconditionerType::BILU0) { - return std::make_unique >(opencl_ilu_parallel, verbosity); - } else if (type == PreconditionerType::CPR) { - return std::make_unique >(verbosity, opencl_ilu_parallel); - } else if (type == PreconditionerType::BISAI) { - return std::make_unique >(opencl_ilu_parallel, verbosity); - } else { - OPM_THROW(std::logic_error, "Invalid PreconditionerType"); +std::unique_ptr> +Preconditioner::create(Type type, bool opencl_ilu_parallel, int verbosity) +{ + switch (type ) { + case Type::BILU0: + return std::make_unique >(opencl_ilu_parallel, verbosity); + case Type::CPR: + return std::make_unique >(opencl_ilu_parallel, verbosity); + case Type::BISAI: + return std::make_unique >(opencl_ilu_parallel, verbosity); } + + OPM_THROW(std::logic_error, + "Invalid preconditioner type " + std::to_string(static_cast(type))); } template @@ -63,7 +70,7 @@ bool Preconditioner::create_preconditioner(BlockedMatrix *mat, [[may } #define INSTANTIATE_BDA_FUNCTIONS(n) \ -template std::unique_ptr > Preconditioner::create(PreconditionerType, int, bool); \ +template std::unique_ptr > Preconditioner::create(Type, bool, int); \ template void Preconditioner::setOpencl(std::shared_ptr&, std::shared_ptr&); \ template bool Preconditioner::analyze_matrix(BlockedMatrix *, BlockedMatrix *); \ template bool Preconditioner::create_preconditioner(BlockedMatrix *, BlockedMatrix *); diff --git a/opm/simulators/linalg/bda/opencl/Preconditioner.hpp b/opm/simulators/linalg/bda/opencl/Preconditioner.hpp index 4e450bf33..4b535fded 100644 --- a/opm/simulators/linalg/bda/opencl/Preconditioner.hpp +++ b/opm/simulators/linalg/bda/opencl/Preconditioner.hpp @@ -22,12 +22,13 @@ #include +#include + namespace Opm { namespace Accelerator { - class BlockedMatrix; template @@ -51,13 +52,15 @@ protected: {}; public: - enum PreconditionerType { + enum class Type { BILU0, CPR, BISAI }; - static std::unique_ptr create(PreconditionerType type, int verbosity, bool opencl_ilu_parallel); + static std::unique_ptr create(Type type, + bool opencl_ilu_parallel, + int verbosity); virtual ~Preconditioner() = default; diff --git a/opm/simulators/linalg/bda/opencl/openclSolverBackend.cpp b/opm/simulators/linalg/bda/opencl/openclSolverBackend.cpp index d515137f3..bc66e74c3 100644 --- a/opm/simulators/linalg/bda/opencl/openclSolverBackend.cpp +++ b/opm/simulators/linalg/bda/opencl/openclSolverBackend.cpp @@ -65,13 +65,13 @@ openclSolverBackend::openclSolverBackend(int verbosity_, int maxit_, OPM_THROW(std::logic_error, "Error unknown value for argument --linear-solver, " + linsolver); } - using PreconditionerType = typename Preconditioner::PreconditionerType; + using PreconditionerType = typename Preconditioner::Type; if (use_cpr) { - prec = Preconditioner::create(PreconditionerType::CPR, verbosity, opencl_ilu_parallel); + prec = Preconditioner::create(PreconditionerType::CPR, opencl_ilu_parallel, verbosity); } else if (use_isai) { - prec = Preconditioner::create(PreconditionerType::BISAI, verbosity, opencl_ilu_parallel); + prec = Preconditioner::create(PreconditionerType::BISAI, opencl_ilu_parallel, verbosity); } else { - prec = Preconditioner::create(PreconditionerType::BILU0, verbosity, opencl_ilu_parallel); + prec = Preconditioner::create(PreconditionerType::BILU0, opencl_ilu_parallel, verbosity); } std::ostringstream out;