diff --git a/opm/simulators/linalg/bda/opencl/BILU0.cpp b/opm/simulators/linalg/bda/opencl/BILU0.cpp index 81f3be4ec..ed2f9c977 100644 --- a/opm/simulators/linalg/bda/opencl/BILU0.cpp +++ b/opm/simulators/linalg/bda/opencl/BILU0.cpp @@ -31,17 +31,14 @@ #include -namespace Opm -{ -namespace Accelerator -{ +namespace Opm::Accelerator { -using Opm::OpmLog; using Dune::Timer; template -BILU0::BILU0(bool opencl_ilu_parallel_, int verbosity_) : - Preconditioner(verbosity_), opencl_ilu_parallel(opencl_ilu_parallel_) +BILU0::BILU0(bool opencl_ilu_parallel_, int verbosity_) + : Base(verbosity_) + , opencl_ilu_parallel(opencl_ilu_parallel_) { #if CHOW_PATEL chowPatelIlu.setVerbosity(verbosity); @@ -319,5 +316,4 @@ INSTANTIATE_BDA_FUNCTIONS(6); #undef INSTANTIATE_BDA_FUNCTIONS -} // namespace Accelerator -} // namespace Opm +} // namespace Opm::Accelerator diff --git a/opm/simulators/linalg/bda/opencl/BILU0.hpp b/opm/simulators/linalg/bda/opencl/BILU0.hpp index e7818f22c..d4875b6ae 100644 --- a/opm/simulators/linalg/bda/opencl/BILU0.hpp +++ b/opm/simulators/linalg/bda/opencl/BILU0.hpp @@ -29,18 +29,15 @@ #include -namespace Opm -{ -namespace Accelerator -{ +namespace Opm::Accelerator { /// This class implements a Blocked ILU0 preconditioner /// The decomposition is done on GPU, using exact decomposition, or ChowPatel decomposition /// The preconditioner is applied via two exact triangular solves template -class BILU0 : public Preconditioner +class BILU0 : public Preconditioner { - typedef Preconditioner Base; + using Base = Preconditioner; using Base::N; using Base::Nb; @@ -53,9 +50,9 @@ class BILU0 : public Preconditioner using Base::err; private: - std::unique_ptr> LUmat = nullptr; + std::unique_ptr> LUmat{}; #if CHOW_PATEL - std::unique_ptr> Lmat = nullptr, Umat = nullptr; + std::unique_ptr> Lmat{}, Umat{}; #endif std::vector invDiagVals; std::vector diagIndex; @@ -122,8 +119,7 @@ public: } }; -} // namespace Accelerator -} // namespace Opm +} // namespace Opm::Accelerator #endif diff --git a/opm/simulators/linalg/bda/opencl/BISAI.cpp b/opm/simulators/linalg/bda/opencl/BISAI.cpp index ffb6497f6..cf65628b6 100644 --- a/opm/simulators/linalg/bda/opencl/BISAI.cpp +++ b/opm/simulators/linalg/bda/opencl/BISAI.cpp @@ -34,17 +34,14 @@ #include -namespace Opm -{ -namespace Accelerator -{ +namespace Opm::Accelerator { using Opm::OpmLog; using Dune::Timer; template -BISAI::BISAI(bool opencl_ilu_parallel_, int verbosity_) : - Preconditioner(verbosity_) +BISAI::BISAI(bool opencl_ilu_parallel_, int verbosity_) + : Base(verbosity_) { #if CHOW_PATEL OPM_THROW(std::logic_error, "Error --linear-solver=isai cannot be used if ChowPatelIlu is used, probably defined by CMake\n"); @@ -312,5 +309,4 @@ INSTANTIATE_BDA_FUNCTIONS(6); #undef INSTANTIATE_BDA_FUNCTIONS -} -} +} // namespace Opm::Accelerator diff --git a/opm/simulators/linalg/bda/opencl/BISAI.hpp b/opm/simulators/linalg/bda/opencl/BISAI.hpp index 31b1a7e50..f7f36e224 100644 --- a/opm/simulators/linalg/bda/opencl/BISAI.hpp +++ b/opm/simulators/linalg/bda/opencl/BISAI.hpp @@ -26,19 +26,16 @@ #include #include -namespace Opm -{ -namespace Accelerator -{ +namespace Opm::Accelerator { template class BlockedMatrix; /// This class implements a Blocked version of the Incomplete Sparse Approximate Inverse (ISAI) preconditioner. /// Inspired by the paper "Incomplete Sparse Approximate Inverses for Parallel Preconditioning" by Anzt et. al. template -class BISAI : public Preconditioner +class BISAI : public Preconditioner { - typedef Preconditioner Base; + using Base = Preconditioner; using Base::N; using Base::Nb; @@ -134,7 +131,6 @@ public: /// in the csrToCscOffsetMap[i]-th position in the CSC representation. std::vector buildCsrToCscOffsetMap(std::vector colPointers, std::vector rowIndices); -} // namespace Accelerator -} // namespace Opm +} // namespace Opm::Accelerator #endif diff --git a/opm/simulators/linalg/bda/opencl/CPR.cpp b/opm/simulators/linalg/bda/opencl/CPR.cpp index 6ef60e0c2..a4faa6fd3 100644 --- a/opm/simulators/linalg/bda/opencl/CPR.cpp +++ b/opm/simulators/linalg/bda/opencl/CPR.cpp @@ -35,17 +35,15 @@ #include -namespace Opm -{ -namespace Accelerator -{ +namespace Opm::Accelerator { using Opm::OpmLog; using Dune::Timer; template -CPR::CPR(bool opencl_ilu_parallel_, int verbosity_) : - Preconditioner(verbosity_), opencl_ilu_parallel(opencl_ilu_parallel_) +CPR::CPR(bool opencl_ilu_parallel_, int verbosity_) + : Base(verbosity_) + , opencl_ilu_parallel(opencl_ilu_parallel_) { bilu0 = std::make_unique >(opencl_ilu_parallel, verbosity_); diagIndices.resize(1); @@ -570,7 +568,6 @@ INSTANTIATE_BDA_FUNCTIONS(6); #undef INSTANTIATE_BDA_FUNCTIONS -} // namespace Accelerator -} // namespace Opm +} // namespace Opm::Accelerator diff --git a/opm/simulators/linalg/bda/opencl/CPR.hpp b/opm/simulators/linalg/bda/opencl/CPR.hpp index 39bf4de18..3e6b7c900 100644 --- a/opm/simulators/linalg/bda/opencl/CPR.hpp +++ b/opm/simulators/linalg/bda/opencl/CPR.hpp @@ -33,18 +33,15 @@ #include -namespace Opm -{ -namespace Accelerator -{ +namespace Opm::Accelerator { template class BlockedMatrix; /// This class implements a Constrained Pressure Residual (CPR) preconditioner template -class CPR : public Preconditioner +class CPR : public Preconditioner { - typedef Preconditioner Base; + using Base = Preconditioner; using Base::N; using Base::Nb; @@ -138,8 +135,7 @@ public: // x and b are vectors with 3 elements void solve_transposed_3x3(const double *A, const double *b, double *x); -} // namespace Accelerator -} // namespace Opm +} // namespace Opm::Accelerator #endif diff --git a/opm/simulators/linalg/bda/opencl/Preconditioner.cpp b/opm/simulators/linalg/bda/opencl/Preconditioner.cpp index f6698cd71..f476bd44f 100644 --- a/opm/simulators/linalg/bda/opencl/Preconditioner.cpp +++ b/opm/simulators/linalg/bda/opencl/Preconditioner.cpp @@ -30,21 +30,20 @@ #include #include -namespace Opm -{ -namespace Accelerator -{ +namespace Opm::Accelerator { - -template -void Preconditioner::setOpencl(std::shared_ptr& context_, std::shared_ptr& queue_) { +template +void Preconditioner:: + setOpencl(std::shared_ptr& context_, + std::shared_ptr& queue_) +{ context = context_; queue = queue_; } -template -std::unique_ptr> -Preconditioner::create(Type type, bool opencl_ilu_parallel, int verbosity) +template +std::unique_ptr> +Preconditioner::create(Type type, bool opencl_ilu_parallel, int verbosity) { switch (type ) { case Type::BILU0: @@ -59,37 +58,30 @@ Preconditioner::create(Type type, bool opencl_ilu_parallel, int verb "Invalid preconditioner type " + std::to_string(static_cast(type))); } -template -bool Preconditioner:: -analyze_matrix(BlockedMatrix* mat, - [[maybe_unused]] BlockedMatrix* jacMat) +template +bool Preconditioner:: +analyze_matrix(BlockedMatrix* mat, + [[maybe_unused]] BlockedMatrix* jacMat) { return analyze_matrix(mat); } -template -bool Preconditioner:: -create_preconditioner(BlockedMatrix* mat, - [[maybe_unused]] BlockedMatrix* jacMat) +template +bool Preconditioner:: +create_preconditioner(BlockedMatrix* mat, + [[maybe_unused]] BlockedMatrix* jacMat) { return create_preconditioner(mat); } -#define INSTANTIATE_BDA_FUNCTIONS(n) \ -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 *); +#define INSTANCE_TYPE(T) \ + template class Preconditioner; \ + template class Preconditioner; \ + template class Preconditioner; \ + template class Preconditioner; \ + template class Preconditioner; \ + template class Preconditioner; -INSTANTIATE_BDA_FUNCTIONS(1); -INSTANTIATE_BDA_FUNCTIONS(2); -INSTANTIATE_BDA_FUNCTIONS(3); -INSTANTIATE_BDA_FUNCTIONS(4); -INSTANTIATE_BDA_FUNCTIONS(5); -INSTANTIATE_BDA_FUNCTIONS(6); - -#undef INSTANTIATE_BDA_FUNCTIONS - -} //namespace Accelerator -} //namespace Opm +INSTANCE_TYPE(double) +} // namespace Opm::Accelerator diff --git a/opm/simulators/linalg/bda/opencl/Preconditioner.hpp b/opm/simulators/linalg/bda/opencl/Preconditioner.hpp index de03b47dc..d2717c3df 100644 --- a/opm/simulators/linalg/bda/opencl/Preconditioner.hpp +++ b/opm/simulators/linalg/bda/opencl/Preconditioner.hpp @@ -24,17 +24,13 @@ #include -namespace Opm -{ -namespace Accelerator -{ +namespace Opm::Accelerator { template class BlockedMatrix; -template +template class Preconditioner { - protected: int N = 0; // number of rows of the matrix int Nb = 0; // number of blockrows of the matrix @@ -65,7 +61,8 @@ public: virtual ~Preconditioner() = default; // nested Preconditioners might need to override this - virtual void setOpencl(std::shared_ptr& context, std::shared_ptr& queue); + virtual void setOpencl(std::shared_ptr& context, + std::shared_ptr& queue); // apply preconditioner, x = prec(y) virtual void apply(const cl::Buffer& y, cl::Buffer& x) = 0; @@ -73,18 +70,17 @@ public: // analyze matrix, e.g. the sparsity pattern // probably only called once // the version with two params can be overloaded, if not, it will default to using the one param version - virtual bool analyze_matrix(BlockedMatrix* mat) = 0; - virtual bool analyze_matrix(BlockedMatrix* mat, - BlockedMatrix* jacMat); + virtual bool analyze_matrix(BlockedMatrix* mat) = 0; + virtual bool analyze_matrix(BlockedMatrix* mat, + BlockedMatrix* jacMat); // create/update preconditioner, probably used every linear solve // the version with two params can be overloaded, if not, it will default to using the one param version - virtual bool create_preconditioner(BlockedMatrix* mat) = 0; - virtual bool create_preconditioner(BlockedMatrix* mat, - BlockedMatrix* jacMat); + virtual bool create_preconditioner(BlockedMatrix* mat) = 0; + virtual bool create_preconditioner(BlockedMatrix* mat, + BlockedMatrix* jacMat); }; -} //namespace Accelerator -} //namespace Opm +} // namespace Opm::Accelerator #endif diff --git a/opm/simulators/linalg/bda/opencl/openclSolverBackend.cpp b/opm/simulators/linalg/bda/opencl/openclSolverBackend.cpp index 4cca15e7e..f4bd8b77d 100644 --- a/opm/simulators/linalg/bda/opencl/openclSolverBackend.cpp +++ b/opm/simulators/linalg/bda/opencl/openclSolverBackend.cpp @@ -65,13 +65,16 @@ openclSolverBackend::openclSolverBackend(int verbosity_, int maxit_, OPM_THROW(std::logic_error, "Error unknown value for argument --linear-solver, " + linsolver); } - using PreconditionerType = typename Preconditioner::Type; + using PreconditionerType = Preconditioner; if (use_cpr) { - prec = Preconditioner::create(PreconditionerType::CPR, opencl_ilu_parallel, verbosity); + prec = PreconditionerType::create(PreconditionerType::Type::CPR, + opencl_ilu_parallel, verbosity); } else if (use_isai) { - prec = Preconditioner::create(PreconditionerType::BISAI, opencl_ilu_parallel, verbosity); + prec = PreconditionerType::create(PreconditionerType::Type::BISAI, + opencl_ilu_parallel, verbosity); } else { - prec = Preconditioner::create(PreconditionerType::BILU0, opencl_ilu_parallel, verbosity); + prec = PreconditionerType::create(PreconditionerType::Type::BILU0, + opencl_ilu_parallel, verbosity); } std::ostringstream out; diff --git a/opm/simulators/linalg/bda/opencl/openclSolverBackend.hpp b/opm/simulators/linalg/bda/opencl/openclSolverBackend.hpp index f0d0d73a0..916e70f11 100644 --- a/opm/simulators/linalg/bda/opencl/openclSolverBackend.hpp +++ b/opm/simulators/linalg/bda/opencl/openclSolverBackend.hpp @@ -63,7 +63,7 @@ private: bool useJacMatrix = false; - std::unique_ptr > prec; + std::unique_ptr > prec; // can perform blocked ILU0 and AMG on pressure component bool is_root; // allow for nested solvers, the root solver is called by BdaBridge bool analysis_done = false;