Skip to content

Commit

Permalink
apply new register mechanism to linearsolver
Browse files Browse the repository at this point in the history
  • Loading branch information
fredroy committed Sep 23, 2024
1 parent b5f6420 commit 4e96586
Show file tree
Hide file tree
Showing 33 changed files with 353 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ namespace sofa::component::linearsolver::direct
using linearalgebra::CompressedRowSparseMatrix;
using linearalgebra::FullVector;

int AsyncSparseLDLSolverClass = core::RegisterObject("Asynchronous direct Linear Solver using a Sparse LDL^T factorization.")
.add< AsyncSparseLDLSolver< CompressedRowSparseMatrix<SReal> , FullVector<SReal> > >(true)
.add< AsyncSparseLDLSolver< CompressedRowSparseMatrix<type::Mat<3,3,SReal> >, FullVector<SReal> > >()
;
void registerAsyncSparseLDLSolver(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Asynchronous direct Linear Solver using a Sparse LDL^T factorization.")
.add< AsyncSparseLDLSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >(true)
.add< AsyncSparseLDLSolver< CompressedRowSparseMatrix<type::Mat<3, 3, SReal> >, FullVector<SReal> > >());
}

template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API AsyncSparseLDLSolver< CompressedRowSparseMatrix<SReal> ,FullVector<SReal> >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API AsyncSparseLDLSolver< CompressedRowSparseMatrix< type::Mat<3,3,SReal> >,FullVector<SReal> >;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@

namespace sofa::component::linearsolver::direct
{
int BTDLinearSolverClass = core::RegisterObject("Linear system solver using Thomas Algorithm for Block Tridiagonal matrices")
.add< BTDLinearSolver<linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> > >(true)
;

void registerBTDLinearSolver(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system solver using Thomas Algorithm for Block Tridiagonal matrices.")
.add< BTDLinearSolver<linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> > >(true));
}

template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API BTDLinearSolver< linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> >;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ namespace sofa::component::linearsolver::direct
using namespace sofa::defaulttype;
using namespace sofa::linearalgebra;

int CholeskySolverClass = core::RegisterObject("Direct linear solver based on Cholesky factorization, for dense matrices")
void registerCholeskySolver(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Direct linear solver based on Cholesky factorization, for dense matrices.")
.add< CholeskySolver< SparseMatrix<SReal>, FullVector<SReal> > >(true)
.add< CholeskySolver< FullMatrix<SReal>, FullVector<SReal> > >();
.add< CholeskySolver< FullMatrix<SReal>, FullVector<SReal> > >());
}

template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API CholeskySolver< SparseMatrix<SReal>, FullVector<SReal> >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API CholeskySolver< FullMatrix<SReal>, FullVector<SReal> >;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ namespace sofa::component::linearsolver::direct
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLDLT< SReal >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLDLT< sofa::type::Mat<3,3,SReal> >;

int EigenSimplicialLDLTCRSClass = sofa::core::RegisterObject("Direct Linear Solver using a Sparse LDL^T factorization.")
.add< EigenSimplicialLDLT< SReal > >()
.add< EigenSimplicialLDLT< sofa::type::Mat<3,3,SReal> > >()
;
void registerEigenSimplicialLDLT(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Direct Linear Solver using a Sparse LDL^T factorization.")
.add< EigenSimplicialLDLT< SReal > >()
.add< EigenSimplicialLDLT< sofa::type::Mat<3, 3, SReal> > >());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@

namespace sofa::component::linearsolver::direct
{
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLLT< SReal >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLLT< sofa::type::Mat<3,3,SReal> >;

int EigenSimplicialLLTCRSClass = sofa::core::RegisterObject("Direct Linear Solver using a Sparse LL^T factorization.")
.add< EigenSimplicialLLT< SReal > >()
.add< EigenSimplicialLLT< sofa::type::Mat<3,3,SReal> > >()
;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLLT< SReal >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSimplicialLLT< sofa::type::Mat<3,3,SReal> >;

void registerEigenSimplicialLLT(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Direct Linear Solver using a Sparse LL^T factorization.")
.add< EigenSimplicialLLT< SReal > >()
.add< EigenSimplicialLLT< sofa::type::Mat<3, 3, SReal> > >());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@

namespace sofa::component::linearsolver::direct
{
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseLU< SReal >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseLU< sofa::type::Mat<3,3,SReal> >;

int EigenSparseLUCRSClass = sofa::core::RegisterObject("Direct Linear Solver using a Sparse LU factorization.")
.add< EigenSparseLU< SReal > >()
.add< EigenSparseLU< sofa::type::Mat<3,3,SReal> > >()
;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseLU< SReal >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseLU< sofa::type::Mat<3,3,SReal> >;

void registerEigenSparseLU(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Direct Linear Solver using a Sparse LU factorization.")
.add< EigenSparseLU< SReal > >()
.add< EigenSparseLU< sofa::type::Mat<3, 3, SReal> > >());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@

namespace sofa::component::linearsolver::direct
{
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseQR< SReal >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseQR< sofa::type::Mat<3,3,SReal>>;

int EigenSparseQRCRSClass = sofa::core::RegisterObject("Direct Linear Solver using a Sparse QR factorization.")
.add< EigenSparseQR< SReal > >()
.add< EigenSparseQR< sofa::type::Mat<3,3,SReal> > >()
;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseQR< SReal >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API EigenSparseQR< sofa::type::Mat<3,3,SReal>>;

void registerEigenSparseQR(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Direct Linear Solver using a Sparse QR factorization.")
.add< EigenSparseQR< SReal > >()
.add< EigenSparseQR< sofa::type::Mat<3, 3, SReal> > >());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@

namespace sofa::component::linearsystem
{

template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API MatrixLinearSystem< linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> >;

int AssemblingMatrixLinearSystemBTDClass = core::RegisterObject("Linear system")
.add<MatrixLinearSystem< linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> > >();
;
void registerMatrixLinearSystemBTDMatrix(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system.")
.add<MatrixLinearSystem< linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> > >());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ namespace sofa::component::linearsolver::direct

using namespace sofa::linearalgebra;

int PrecomputedLinearSolverClass = core::RegisterObject("Linear system solver based on a precomputed inverse matrix")
.add< PrecomputedLinearSolver< CompressedRowSparseMatrix<SReal> , FullVector<SReal> > >()
;
void registerPrecomputedLinearSolver(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system solver based on a precomputed inverse matrix")
.add< PrecomputedLinearSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >());
}

template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API PrecomputedLinearSolver< CompressedRowSparseMatrix<SReal> , FullVector<SReal> >;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ namespace sofa::component::linearsolver::direct

using namespace sofa::linearalgebra;

int SVDLinearSolverClass = core::RegisterObject("Linear system solver using a SVD decomposition of a dense matrix")
void registerSVDLinearSolver(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system solver using a SVD decomposition of a dense matrix.")
.add< SVDLinearSolver< FullMatrix<SReal>, FullVector<SReal> > >()
.add< SVDLinearSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >()
.add< SVDLinearSolver< CompressedRowSparseMatrix<type::Mat<3,3, SReal>>, FullVector<SReal> > >()
.addAlias("SVDLinear")
.addAlias("SVD")
;
.add< SVDLinearSolver< CompressedRowSparseMatrix<type::Mat<3, 3, SReal>>, FullVector<SReal> > >());
}

template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API SVDLinearSolver< FullMatrix<SReal>, FullVector<SReal> >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API SVDLinearSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> >;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ namespace sofa::component::linearsolver::direct

using namespace sofa::linearalgebra;

int SparseLDLSolverClass = core::RegisterObject("Direct Linear Solver using a Sparse LDL^T factorization.")
.add< SparseLDLSolver< CompressedRowSparseMatrix<SReal>,FullVector<SReal> > >(true)
.add< SparseLDLSolver< CompressedRowSparseMatrix<type::Mat<3,3,SReal> >,FullVector<SReal> > >()

;
void registerSparseLDLSolver(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Direct Linear Solver using a Sparse LDL^T factorization.")
.add< SparseLDLSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >(true)
.add< SparseLDLSolver< CompressedRowSparseMatrix<type::Mat<3, 3, SReal> >, FullVector<SReal> > >());
}

template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API SparseLDLSolver< CompressedRowSparseMatrix<SReal>,FullVector<SReal> >;
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API SparseLDLSolver< CompressedRowSparseMatrix< type::Mat<3,3,SReal> >,FullVector<SReal> >;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
#include <sofa/component/linearsolver/direct/TypedMatrixLinearSystem[BTDMatrix].h>
#include <sofa/component/linearsystem/TypedMatrixLinearSystem.inl>

#include <sofa/core/ObjectFactory.h>

namespace sofa::component::linearsystem
{
template class SOFA_COMPONENT_LINEARSOLVER_DIRECT_API TypedMatrixLinearSystem< linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> >;

void registerTypedMatrixLinearSystemBTDMatrix(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system.")
.add<TypedMatrixLinearSystem< linearalgebra::BTDMatrix<6, SReal>, linearalgebra::BlockVector<6, SReal> > >());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,33 @@
#include <sofa/component/linearsolver/direct/EigenSolverFactory.h>
#include <sofa/component/linearsolver/direct/init.h>
#include <sofa/core/ObjectFactory.h>
#include <sofa/helper/system/PluginManager.h>

namespace sofa::component::linearsystem
{
extern void registerMatrixLinearSystemBTDMatrix(sofa::core::ObjectFactory* factory);
extern void registerTypedMatrixLinearSystemBTDMatrix(sofa::core::ObjectFactory* factory);
}

namespace sofa::component::linearsolver::direct
{


extern void registerAsyncSparseLDLSolver(sofa::core::ObjectFactory* factory);
extern void registerBTDLinearSolver(sofa::core::ObjectFactory* factory);
extern void registerCholeskySolver(sofa::core::ObjectFactory* factory);
extern void registerEigenSimplicialLDLT(sofa::core::ObjectFactory* factory);
extern void registerEigenSimplicialLLT(sofa::core::ObjectFactory* factory);
extern void registerEigenSparseLU(sofa::core::ObjectFactory* factory);
extern void registerEigenSparseQR(sofa::core::ObjectFactory* factory);
extern void registerPrecomputedLinearSolver(sofa::core::ObjectFactory* factory);
extern void registerSparseLDLSolver(sofa::core::ObjectFactory* factory);
extern void registerSVDLinearSolver(sofa::core::ObjectFactory* factory);

extern "C" {
SOFA_EXPORT_DYNAMIC_LIBRARY void initExternalModule();
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleName();
SOFA_EXPORT_DYNAMIC_LIBRARY const char* getModuleVersion();
SOFA_EXPORT_DYNAMIC_LIBRARY void registerObjects(sofa::core::ObjectFactory* factory);
}

void initExternalModule()
Expand Down Expand Up @@ -63,11 +83,30 @@ void registerOrderingMethods()
registerOrderingMethods<MainQRFactory, Scalar>();
}

void registerObjects(sofa::core::ObjectFactory* factory)
{
registerAsyncSparseLDLSolver(factory);
registerBTDLinearSolver(factory);
registerCholeskySolver(factory);
registerEigenSimplicialLDLT(factory);
registerEigenSimplicialLLT(factory);
registerEigenSparseLU(factory);
registerEigenSparseQR(factory);
linearsystem::registerMatrixLinearSystemBTDMatrix(factory);
registerPrecomputedLinearSolver(factory);
registerSparseLDLSolver(factory);
registerSVDLinearSolver(factory);
linearsystem::registerTypedMatrixLinearSystemBTDMatrix(factory);
}

void init()
{
static bool first = true;
if (first)
{
// make sure that this plugin is registered into the PluginManager
sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME);

registerOrderingMethods<float>();
registerOrderingMethods<double>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,19 @@ inline void CGLinearSolver<component::linearsolver::GraphScatteredMatrix,compone
}
using namespace sofa::linearalgebra;

int CGLinearSolverClass = core::RegisterObject("Linear system solver using the conjugate gradient iterative algorithm")
void registerCGLinearSolver(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system solver using the conjugate gradient iterative algorithm")
.add< CGLinearSolver< GraphScatteredMatrix, GraphScatteredVector > >(true)
.add< CGLinearSolver< FullMatrix<SReal>, FullVector<SReal> > >()
.add< CGLinearSolver< SparseMatrix<SReal>, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<2,2,SReal> >, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<3,3,SReal> >, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<4,4,SReal> >, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<6,6,SReal> >, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<8,8,SReal> >, FullVector<SReal> > >()

.addAlias("CGSolver")
.addAlias("ConjugateGradient")
;
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<2, 2, SReal> >, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<3, 3, SReal> >, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<4, 4, SReal> >, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<6, 6, SReal> >, FullVector<SReal> > >()
.add< CGLinearSolver< CompressedRowSparseMatrix<Mat<8, 8, SReal> >, FullVector<SReal> > >());
}

template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API CGLinearSolver< GraphScatteredMatrix, GraphScatteredVector >;
template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API CGLinearSolver< FullMatrix<SReal>, FullVector<SReal> >;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@

namespace sofa::component::linearsystem
{
using sofa::component::linearsolver::GraphScatteredMatrix;
using sofa::component::linearsolver::GraphScatteredVector;

template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API MatrixFreeSystem<linearsolver::GraphScatteredMatrix, GraphScatteredVector>;
using sofa::component::linearsolver::GraphScatteredMatrix;
using sofa::component::linearsolver::GraphScatteredVector;

int MatrixFreeSystemClass = core::RegisterObject("Matrix-free linear system")
.add< MatrixFreeSystem<GraphScatteredMatrix, GraphScatteredVector> >();
template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API MatrixFreeSystem<linearsolver::GraphScatteredMatrix, GraphScatteredVector>;

void registerMatrixFreeSystemGraphScattered(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Matrix-free linear system.")
.add< MatrixFreeSystem<GraphScatteredMatrix, GraphScatteredVector> >());
}

} //namespace sofa::component::linearsystem
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,19 @@ using namespace sofa::type;
using namespace sofa::defaulttype;
using namespace sofa::linearalgebra;


int MinResLinearSolverClass = core::RegisterObject("Linear system solver using the MINRES iterative algorithm")
void registerMinResLinearSolver(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system solver using the MINRES iterative algorithm.")
.add< MinResLinearSolver< GraphScatteredMatrix, GraphScatteredVector > >(true)
.add< MinResLinearSolver< FullMatrix<SReal>, FullVector<SReal> > >()
.add< MinResLinearSolver< SparseMatrix<SReal>, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<2,2,SReal> >, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<3,3,SReal> >, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<4,4,SReal> >, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<6,6,SReal> >, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<8,8,SReal> >, FullVector<SReal> > >()

.addAlias("MINRESSolver")
.addAlias("MinResSolver")
;
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<2, 2, SReal> >, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<3, 3, SReal> >, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<4, 4, SReal> >, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<6, 6, SReal> >, FullVector<SReal> > >()
.add< MinResLinearSolver< CompressedRowSparseMatrix<Mat<8, 8, SReal> >, FullVector<SReal> > >());
}

template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API MinResLinearSolver< GraphScatteredMatrix, GraphScatteredVector >;
template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API MinResLinearSolver< FullMatrix<SReal>, FullVector<SReal> >;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
namespace sofa::component::linearsolver::iterative
{

int ShewchukPCGLinearSolverClass = core::RegisterObject("Linear system solver using the conjugate gradient iterative algorithm")
.add< ShewchukPCGLinearSolver<GraphScatteredMatrix,GraphScatteredVector> >(true)
.addAlias("PCGLinearSolver");
void registerShewchukPCGLinearSolver(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system solver using the Shewchuk conjugate gradient iterative algorithm.")
.add< ShewchukPCGLinearSolver<GraphScatteredMatrix, GraphScatteredVector> >());
}

template class SOFA_COMPONENT_LINEARSOLVER_ITERATIVE_API ShewchukPCGLinearSolver<GraphScatteredMatrix, GraphScatteredVector>;

Expand Down
Loading

0 comments on commit 4e96586

Please sign in to comment.