changed: make PreconditionerType an enum class

this to avoid symbol clashes with the implementations.
while at it rename it to Type as Preconditioner::PreconditionerType is
redundant
This commit is contained in:
Arne Morten Kvarving
2024-04-16 09:06:13 +02:00
parent 4f53ea512b
commit cc5f362fdc
3 changed files with 15 additions and 12 deletions

View File

@@ -40,13 +40,15 @@ void Preconditioner<block_size>::setOpencl(std::shared_ptr<cl::Context>& context
}
template <unsigned int block_size>
std::unique_ptr<Preconditioner<block_size> > Preconditioner<block_size>::create(PreconditionerType type, int verbosity, bool opencl_ilu_parallel) {
if (type == PreconditionerType::BILU0) {
return std::make_unique<Opm::Accelerator::BILU0<block_size> >(opencl_ilu_parallel, verbosity);
} else if (type == PreconditionerType::CPR) {
return std::make_unique<Opm::Accelerator::CPR<block_size> >(verbosity, opencl_ilu_parallel);
} else if (type == PreconditionerType::BISAI) {
return std::make_unique<Opm::Accelerator::BISAI<block_size> >(opencl_ilu_parallel, verbosity);
std::unique_ptr<Preconditioner<block_size>>
Preconditioner<block_size>::create(Type type, int verbosity, bool opencl_ilu_parallel)
{
if (type == Type::BILU0) {
return std::make_unique<BILU0<block_size> >(opencl_ilu_parallel, verbosity);
} else if (type == Type::CPR) {
return std::make_unique<CPR<block_size> >(verbosity, opencl_ilu_parallel);
} else if (type == Type::BISAI) {
return std::make_unique<BISAI<block_size> >(opencl_ilu_parallel, verbosity);
} else {
OPM_THROW(std::logic_error, "Invalid PreconditionerType");
}
@@ -63,7 +65,7 @@ bool Preconditioner<block_size>::create_preconditioner(BlockedMatrix *mat, [[may
}
#define INSTANTIATE_BDA_FUNCTIONS(n) \
template std::unique_ptr<Preconditioner<n> > Preconditioner<n>::create(PreconditionerType, int, bool); \
template std::unique_ptr<Preconditioner<n> > Preconditioner<n>::create(Type, int, bool); \
template void Preconditioner<n>::setOpencl(std::shared_ptr<cl::Context>&, std::shared_ptr<cl::CommandQueue>&); \
template bool Preconditioner<n>::analyze_matrix(BlockedMatrix *, BlockedMatrix *); \
template bool Preconditioner<n>::create_preconditioner(BlockedMatrix *, BlockedMatrix *);

View File

@@ -22,12 +22,13 @@
#include <opm/simulators/linalg/bda/opencl/opencl.hpp>
#include <memory>
namespace Opm
{
namespace Accelerator
{
class BlockedMatrix;
template <unsigned int block_size>
@@ -51,13 +52,13 @@ protected:
{};
public:
enum PreconditionerType {
enum class Type {
BILU0,
CPR,
BISAI
};
static std::unique_ptr<Preconditioner> create(PreconditionerType type, int verbosity, bool opencl_ilu_parallel);
static std::unique_ptr<Preconditioner> create(Type type, int verbosity, bool opencl_ilu_parallel);
virtual ~Preconditioner() = default;

View File

@@ -65,7 +65,7 @@ openclSolverBackend<block_size>::openclSolverBackend(int verbosity_, int maxit_,
OPM_THROW(std::logic_error, "Error unknown value for argument --linear-solver, " + linsolver);
}
using PreconditionerType = typename Preconditioner<block_size>::PreconditionerType;
using PreconditionerType = typename Preconditioner<block_size>::Type;
if (use_cpr) {
prec = Preconditioner<block_size>::create(PreconditionerType::CPR, verbosity, opencl_ilu_parallel);
} else if (use_isai) {