Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Unique ptr for factories #186

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions plugins/ginkgo/include/alien/ginkgo/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class Vector;

class Options;

extern IInternalLinearSolver<Matrix, Vector>* InternalLinearSolverFactory(const Options& options);
extern std::unique_ptr<IInternalLinearSolver<Matrix, Vector>> InternalLinearSolverFactory(const Options& options);

extern IInternalLinearSolver<Matrix, Vector>* InternalLinearSolverFactory();
extern std::unique_ptr<IInternalLinearSolver<Matrix, Vector>> InternalLinearSolverFactory();

extern IInternalLinearAlgebra<Matrix, Vector>* InternalLinearAlgebraFactory();
extern std::unique_ptr<IInternalLinearAlgebra<Matrix, Vector>> InternalLinearAlgebraFactory();
} // namespace Alien::Ginkgo

namespace Alien::BackEnd::tag
Expand All @@ -58,19 +58,19 @@ struct AlgebraTraits<BackEnd::tag::ginkgo>
using solver_type = IInternalLinearSolver<matrix_type, vector_type>;

// factory to build algebra
static auto algebra_factory()
static std::unique_ptr<algebra_type> algebra_factory()
{
return Ginkgo::InternalLinearAlgebraFactory();
}

// factories to build solver
static auto solver_factory(const options_type& options)
static std::unique_ptr<solver_type> solver_factory(const options_type& options)
{
return Ginkgo::InternalLinearSolverFactory(options);
}

// factories to build default solver
static auto solver_factory() { return Ginkgo::InternalLinearSolverFactory(); }
static std::unique_ptr<solver_type> solver_factory() { return Ginkgo::InternalLinearSolverFactory(); }

static BackEndId name() { return "ginkgo"; }
};
Expand Down
4 changes: 2 additions & 2 deletions plugins/ginkgo/src/ginkgo_linear_algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ void InternalLinearAlgebra::scal(Arccore::Real alpha, Vector& x) const
}

ALIEN_GINKGO_EXPORT
IInternalLinearAlgebra<Ginkgo::Matrix, Ginkgo::Vector>*
std::unique_ptr<IInternalLinearAlgebra<Ginkgo::Matrix, Ginkgo::Vector>>
InternalLinearAlgebraFactory()
{
return new Ginkgo::InternalLinearAlgebra();
return std::make_unique<Ginkgo::InternalLinearAlgebra>();
}
} // namespace Alien::Ginkgo
8 changes: 4 additions & 4 deletions plugins/ginkgo/src/ginkgo_linear_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ InternalLinearSolver::algebra() const
}

ALIEN_GINKGO_EXPORT
IInternalLinearSolver<Matrix, Vector>*
std::unique_ptr<IInternalLinearSolver<Matrix, Vector>>
InternalLinearSolverFactory(const Options& options)
{
return new InternalLinearSolver(options);
return std::make_unique<InternalLinearSolver>(options);
}

ALIEN_GINKGO_EXPORT
IInternalLinearSolver<Matrix, Vector>*
std::unique_ptr<IInternalLinearSolver<Matrix, Vector>>
InternalLinearSolverFactory()
{
return new InternalLinearSolver();
return std::make_unique<InternalLinearSolver>();
}
} // namespace Alien::Ginkgo
12 changes: 6 additions & 6 deletions plugins/hypre/include/alien/hypre/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class Vector;

class Options;

extern IInternalLinearSolver<Matrix, Vector>* InternalLinearSolverFactory(const Options& options);
extern std::unique_ptr<IInternalLinearSolver<Matrix, Vector>> InternalLinearSolverFactory(const Options& options);

extern IInternalLinearSolver<Matrix, Vector>* InternalLinearSolverFactory();
extern std::unique_ptr<IInternalLinearSolver<Matrix, Vector>> InternalLinearSolverFactory();

extern IInternalLinearAlgebra<Matrix, Vector>* InternalLinearAlgebraFactory();
extern std::unique_ptr<IInternalLinearAlgebra<Matrix, Vector>> InternalLinearAlgebraFactory();
} // namespace Alien::Hypre

namespace Alien
Expand All @@ -60,19 +60,19 @@ struct AlgebraTraits<BackEnd::tag::hypre>
using solver_type = IInternalLinearSolver<matrix_type, vector_type>;

// factory to build algebra
static auto* algebra_factory()
static std::unique_ptr<algebra_type> algebra_factory()
{
return Hypre::InternalLinearAlgebraFactory();
}

// factories to build solver
static auto* solver_factory(const options_type& options)
static std::unique_ptr<solver_type> solver_factory(const options_type& options)
{
return Hypre::InternalLinearSolverFactory(options);
}

// factories to build default solver
static auto* solver_factory()
static std::unique_ptr<solver_type> solver_factory()
{
return Hypre::InternalLinearSolverFactory();
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/hypre/src/hypre_linear_algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ void InternalLinearAlgebra::scal(Arccore::Real alpha, Vector& x) const
}

ALIEN_HYPRE_EXPORT
IInternalLinearAlgebra<Hypre::Matrix, Hypre::Vector>*
std::unique_ptr<IInternalLinearAlgebra<Hypre::Matrix, Hypre::Vector>>
InternalLinearAlgebraFactory()
{
return new Hypre::InternalLinearAlgebra();
return std::make_unique<Hypre::InternalLinearAlgebra>();
}
} // namespace Alien::Hypre
8 changes: 4 additions & 4 deletions plugins/hypre/src/hypre_linear_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,16 @@ InternalLinearSolver::algebra() const
}

ALIEN_HYPRE_EXPORT
IInternalLinearSolver<Matrix, Vector>*
std::unique_ptr<IInternalLinearSolver<Matrix, Vector>>
InternalLinearSolverFactory(const Options& options)
{
return new InternalLinearSolver(options);
return std::make_unique<InternalLinearSolver>(options);
}

ALIEN_HYPRE_EXPORT
IInternalLinearSolver<Matrix, Vector>*
std::unique_ptr<IInternalLinearSolver<Matrix, Vector>>
InternalLinearSolverFactory()
{
return new InternalLinearSolver();
return std::make_unique<InternalLinearSolver>();
}
} // namespace Alien::Hypre
12 changes: 6 additions & 6 deletions plugins/petsc/include/alien/petsc/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class Vector;

class Options;

extern IInternalLinearSolver<Matrix, Vector>*
extern std::unique_ptr<IInternalLinearSolver<Matrix, Vector>>
InternalLinearSolverFactory(const Options& options);

extern IInternalLinearSolver<Matrix, Vector>* InternalLinearSolverFactory();
extern std::unique_ptr<IInternalLinearSolver<Matrix, Vector>> InternalLinearSolverFactory();

extern IInternalLinearAlgebra<Matrix, Vector>* InternalLinearAlgebraFactory();
extern std::unique_ptr<IInternalLinearAlgebra<Matrix, Vector>> InternalLinearAlgebraFactory();
} // namespace Alien::PETSc

namespace Alien::BackEnd::tag
Expand All @@ -59,19 +59,19 @@ struct AlgebraTraits<BackEnd::tag::petsc>
using solver_type = IInternalLinearSolver<matrix_type, vector_type>;

// factory to build algebra
static auto algebra_factory()
static std::unique_ptr<algebra_type> algebra_factory()
{
return PETSc::InternalLinearAlgebraFactory();
}

// factories to build solver
static auto solver_factory(const options_type& options)
static std::unique_ptr<solver_type> solver_factory(const options_type& options)
{
return PETSc::InternalLinearSolverFactory(options);
}

// factories to build default solver
static auto solver_factory() { return PETSc::InternalLinearSolverFactory(); }
static std::unique_ptr<solver_type> solver_factory() { return PETSc::InternalLinearSolverFactory(); }

static BackEndId name() { return "petsc"; }
};
Expand Down
4 changes: 2 additions & 2 deletions plugins/petsc/src/petsc_linear_algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ void InternalLinearAlgebra::scal(Arccore::Real alpha, Vector& x) const
}

ALIEN_PETSC_EXPORT
IInternalLinearAlgebra<PETSc::Matrix, PETSc::Vector>*
std::unique_ptr<IInternalLinearAlgebra<PETSc::Matrix, PETSc::Vector>>
InternalLinearAlgebraFactory()
{
return new PETSc::InternalLinearAlgebra();
return std::make_unique<PETSc::InternalLinearAlgebra>();
}
} // namespace Alien::PETSc
8 changes: 4 additions & 4 deletions plugins/petsc/src/petsc_linear_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ InternalLinearSolver::algebra() const
}

ALIEN_PETSC_EXPORT
IInternalLinearSolver<Matrix, Vector>*
std::unique_ptr<IInternalLinearSolver<Matrix, Vector>>
InternalLinearSolverFactory(const Options& options)
{
return new InternalLinearSolver(options);
return std::make_unique<InternalLinearSolver>(options);
}

ALIEN_PETSC_EXPORT
IInternalLinearSolver<Matrix, Vector>*
std::unique_ptr<IInternalLinearSolver<Matrix, Vector>>
InternalLinearSolverFactory()
{
return new InternalLinearSolver();
return std::make_unique<InternalLinearSolver>();
}
} // namespace Alien::PETSc
12 changes: 6 additions & 6 deletions plugins/trilinos/include/alien/trilinos/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class Vector;

class Options;

extern IInternalLinearSolver<Matrix, Vector>* InternalLinearSolverFactory(const Options& options);
extern std::unique_ptr<IInternalLinearSolver<Matrix, Vector>> InternalLinearSolverFactory(const Options& options);

extern IInternalLinearSolver<Matrix, Vector>* InternalLinearSolverFactory();
extern std::unique_ptr<IInternalLinearSolver<Matrix, Vector>> InternalLinearSolverFactory();

extern IInternalLinearAlgebra<Matrix, Vector>* InternalLinearAlgebraFactory();
extern std::unique_ptr<IInternalLinearAlgebra<Matrix, Vector>> InternalLinearAlgebraFactory();
} // namespace Alien::Trilinos

namespace Alien
Expand All @@ -60,19 +60,19 @@ struct AlgebraTraits<BackEnd::tag::trilinos>
using solver_type = IInternalLinearSolver<matrix_type, vector_type>;

// factory to build algebra
static auto* algebra_factory()
static std::unique_ptr<algebra_type> algebra_factory()
{
return Trilinos::InternalLinearAlgebraFactory();
}

// factories to build solver
static auto* solver_factory(const options_type& options)
static std::unique_ptr<solver_type> solver_factory(const options_type& options)
{
return Trilinos::InternalLinearSolverFactory(options);
}

// factories to build default solver
static auto* solver_factory()
static std::unique_ptr<solver_type> solver_factory()
{
return Trilinos::InternalLinearSolverFactory();
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/trilinos/src/trilinos_linear_algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ void InternalLinearAlgebra::scal(Arccore::Real alpha, Vector& x) const
}

ALIEN_TRILINOS_EXPORT
IInternalLinearAlgebra<Trilinos::Matrix, Trilinos::Vector>*
std::unique_ptr<IInternalLinearAlgebra<Trilinos::Matrix, Trilinos::Vector>>
InternalLinearAlgebraFactory()
{
return new Trilinos::InternalLinearAlgebra();
return std::make_unique<Trilinos::InternalLinearAlgebra>();
}
} // namespace Alien::Trilinos
8 changes: 4 additions & 4 deletions plugins/trilinos/src/trilinos_linear_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@ InternalLinearSolver::algebra() const
}

ALIEN_TRILINOS_EXPORT
IInternalLinearSolver<Matrix, Vector>*
std::unique_ptr<IInternalLinearSolver<Matrix, Vector>>
InternalLinearSolverFactory(const Options& options)
{
return new InternalLinearSolver(options);
return std::make_unique<InternalLinearSolver>(options);
}

ALIEN_TRILINOS_EXPORT
IInternalLinearSolver<Matrix, Vector>*
std::unique_ptr<IInternalLinearSolver<Matrix, Vector>>
InternalLinearSolverFactory()
{
return new InternalLinearSolver();
return std::make_unique<InternalLinearSolver>();
}
} // namespace Alien::Trilinos
20 changes: 2 additions & 18 deletions src/core/alien/kernels/dok/DoKBackEnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ class DoKLinearSolver;
class DoKMatrix;
class DoKVector;
class Space;
template <class Matrix, class Vector>
class IInternalLinearAlgebra;
template <class Matrix, class Vector>
class IInternalLinearSolver;

extern IInternalLinearAlgebra<DoKMatrix, DoKVector>* DoKLinearAlgebraFactory();

extern IInternalLinearSolver<DoKMatrix, DoKVector>* DoKLinearSolverFactory(
IMessagePassingMng* p_mng);

/*---------------------------------------------------------------------------*/

Expand All @@ -52,15 +43,8 @@ namespace BackEnd::tag
template <>
struct AlgebraTraits<BackEnd::tag::DoK>
{
typedef DoKMatrix matrix_type;
typedef DoKVector vector_type;
typedef IInternalLinearAlgebra<matrix_type, vector_type> algebra_type;
typedef IInternalLinearSolver<matrix_type, vector_type> solver_type;
static algebra_type* algebra_factory() { return DoKLinearAlgebraFactory(); }
static solver_type* solver_factory(IMessagePassingMng* p_mng)
{
return DoKLinearSolverFactory(p_mng);
}
using matrix_type = DoKMatrix;
using vector_type = DoKVector;
static BackEndId name() { return "DoK"; }
};

Expand Down
18 changes: 3 additions & 15 deletions src/core/alien/kernels/redistributor/RedistributorBackEnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ class IInternalLinearAlgebra;
template <class Matrix, class Vector>
class IInternalLinearSolver;

extern IInternalLinearAlgebra<RedistributorMatrix, RedistributorVector>*
redistributorLinearAlgebraFactory();

extern IInternalLinearSolver<RedistributorMatrix, RedistributorVector>*
redistributorLinearSolverFactory(IMessagePassingMng* p_mng);

/*---------------------------------------------------------------------------*/

namespace BackEnd
Expand All @@ -61,15 +55,9 @@ namespace BackEnd
template <>
struct AlgebraTraits<BackEnd::tag::redistributor>
{
typedef RedistributorMatrix matrix_type;
typedef RedistributorVector vector_type;
typedef IInternalLinearAlgebra<matrix_type, vector_type> algebra_type;
typedef IInternalLinearSolver<matrix_type, vector_type> solver_type;
static algebra_type* algebra_factory() { return redistributorLinearAlgebraFactory(); }
static solver_type* solver_factory(IMessagePassingMng* p_mng)
{
return redistributorLinearSolverFactory(p_mng);
}
using matrix_type = RedistributorMatrix;
using vector_type = RedistributorVector;

static BackEndId name() { return "redistributor"; }
};

Expand Down
26 changes: 13 additions & 13 deletions src/core/alien/kernels/simple_csr/SimpleCSRBackEnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ class SimpleCSRVector;
template <typename T>
struct SimpleCSRTraits
{
typedef SimpleCSRMatrix<T> MatrixType;
typedef SimpleCSRVector<T> VectorType;
typedef IInternalLinearAlgebra<MatrixType, VectorType> AlgebraType;
typedef IInternalLinearAlgebraExpr<MatrixType, VectorType> AlgebraExprType;
using MatrixType = SimpleCSRMatrix<T>;
using VectorType = SimpleCSRVector<T>;
using AlgebraType = IInternalLinearAlgebra<MatrixType, VectorType>;
using AlgebraExprType = IInternalLinearAlgebraExpr<MatrixType, VectorType>;
};

extern SimpleCSRTraits<Real>::AlgebraType* SimpleCSRInternalLinearAlgebraFactory();
extern SimpleCSRTraits<Real>::AlgebraExprType*
extern std::unique_ptr<SimpleCSRTraits<Real>::AlgebraType> SimpleCSRInternalLinearAlgebraFactory();
extern std::unique_ptr<SimpleCSRTraits<Real>::AlgebraExprType>
SimpleCSRInternalLinearAlgebraExprFactory();

/*---------------------------------------------------------------------------*/
Expand All @@ -72,19 +72,19 @@ template <>
struct AlgebraTraits<BackEnd::tag::simplecsr>
{
// clang-format off
typedef Real value_type;
typedef SimpleCSRTraits<Real>::MatrixType matrix_type;
typedef SimpleCSRTraits<Real>::VectorType vector_type;
typedef SimpleCSRTraits<Real>::AlgebraType algebra_type;
typedef SimpleCSRTraits<Real>::AlgebraExprType algebra_expr_type;
using value_type = Real;
using matrix_type = SimpleCSRTraits<Real>::MatrixType;
using vector_type = SimpleCSRTraits<Real>::VectorType;
using algebra_type = SimpleCSRTraits<Real>::AlgebraType;
using algebra_expr_type = SimpleCSRTraits<Real>::AlgebraExprType;
// clang-format off

static algebra_type* algebra_factory(
static std::unique_ptr<algebra_type> algebra_factory(
IMessagePassingMng* p_mng ALIEN_UNUSED_PARAM = nullptr)
{
return SimpleCSRInternalLinearAlgebraFactory();
}
static algebra_expr_type* algebra_expr_factory(
static std::unique_ptr<algebra_expr_type> algebra_expr_factory(
IMessagePassingMng* p_mng ALIEN_UNUSED_PARAM = nullptr)
{
return SimpleCSRInternalLinearAlgebraExprFactory();
Expand Down
Loading
Loading