Skip to content

Commit

Permalink
[LinearSystem] Apply new factory registration mechanism (#4981)
Browse files Browse the repository at this point in the history
* apply new register mechanism to linearsystem

* forgot to register matrixprojmethod

---------

Co-authored-by: erik pernod <[email protected]>
  • Loading branch information
fredroy and epernod authored Sep 19, 2024
1 parent 3b06793 commit 720db5d
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ template class SOFA_COMPONENT_LINEARSYSTEM_API CompositeLinearSystem< DiagonalMa
template class SOFA_COMPONENT_LINEARSYSTEM_API CompositeLinearSystem< BlockDiagonalMatrix<3,SReal>, FullVector<SReal> >;
template class SOFA_COMPONENT_LINEARSYSTEM_API CompositeLinearSystem< RotationMatrix<SReal>, FullVector<SReal> >;

int CompositeLinearSystemClass = sofa::core::RegisterObject("Component acting like a linear system, but delegates the linear system functionalities to a list of real linear systems")
.add<CompositeLinearSystem< FullMatrix<SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< SparseMatrix<SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<2,2,SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<3,3,SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<4,4,SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<6,6,SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<8,8,SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< DiagonalMatrix<SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< BlockDiagonalMatrix<3,SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< RotationMatrix<SReal>, FullVector<SReal> > >()
;
void registerCompositeLinearSystem(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Component acting like a linear system, but delegates the linear system functionalities to a list of real linear systems.")
.add<CompositeLinearSystem< FullMatrix<SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< SparseMatrix<SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<2, 2, SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<3, 3, SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<4, 4, SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<6, 6, SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< CompressedRowSparseMatrix<type::Mat<8, 8, SReal> >, FullVector<SReal> > >()
.add<CompositeLinearSystem< DiagonalMatrix<SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< BlockDiagonalMatrix<3, SReal>, FullVector<SReal> > >()
.add<CompositeLinearSystem< RotationMatrix<SReal>, FullVector<SReal> > >());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ namespace sofa::component::linearsystem

template class SOFA_COMPONENT_LINEARSYSTEM_API ConstantSparsityPatternSystem<linearalgebra::CompressedRowSparseMatrix<SReal>, linearalgebra::FullVector<SReal> >;

int ConstantSparsityPatternSystemClass = core::RegisterObject("Linear system taking advantage of the constant sparsity pattern of the global matrix to speed up the matrix assembly. Do not use if sparsity pattern is not constant (topological changes, ...).")
.add<ConstantSparsityPatternSystem<linearalgebra::CompressedRowSparseMatrix<SReal>, linearalgebra::FullVector<SReal>>>();
void registerConstantSparsityPatternSystem(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system taking advantage of the constant sparsity pattern of the global matrix to speed up the matrix assembly. Do not use if sparsity pattern is not constant (topological changes, ...).")
.add<ConstantSparsityPatternSystem<linearalgebra::CompressedRowSparseMatrix<SReal>, linearalgebra::FullVector<SReal>>>());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ namespace sofa::component::linearsystem
{
template class SOFA_COMPONENT_LINEARSYSTEM_API ConstantSparsityProjectionMethod<sofa::linearalgebra::CompressedRowSparseMatrix<SReal> >;

int ConstantSparsityProjectionMethodClass = core::RegisterObject("Matrix mapping computing the matrix projection taking advantage of the constant sparsity pattern")
.add< ConstantSparsityProjectionMethod<sofa::linearalgebra::CompressedRowSparseMatrix<SReal> > >(true)
;
void registerConstantSparsityProjectionMethod(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Matrix mapping computing the matrix projection taking advantage of the constant sparsity pattern.")
.add< ConstantSparsityProjectionMethod<sofa::linearalgebra::CompressedRowSparseMatrix<SReal> > >(true));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ template class SOFA_COMPONENT_LINEARSYSTEM_API MatrixLinearSystem< DiagonalMatri
template class SOFA_COMPONENT_LINEARSYSTEM_API MatrixLinearSystem< BlockDiagonalMatrix<3,SReal>, FullVector<SReal> >;
template class SOFA_COMPONENT_LINEARSYSTEM_API MatrixLinearSystem< RotationMatrix<SReal>, FullVector<SReal> >;

int AssemblingMatrixLinearSystemClass = core::RegisterObject("Linear system")
void registerMatrixLinearSystem(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Linear system.")
.add<MatrixLinearSystem< FullMatrix<SReal>, FullVector<SReal> > >()
.add<MatrixLinearSystem< SparseMatrix<SReal>, FullVector<SReal> > >()
.add<MatrixLinearSystem< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >(true)
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<2,2,SReal> >, FullVector<SReal> > >()
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<3,3,SReal> >, FullVector<SReal> > >()
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<4,4,SReal> >, FullVector<SReal> > >()
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<6,6,SReal> >, FullVector<SReal> > >()
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<8,8,SReal> >, FullVector<SReal> > >()
;
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<2, 2, SReal> >, FullVector<SReal> > >()
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<3, 3, SReal> >, FullVector<SReal> > >()
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<4, 4, SReal> >, FullVector<SReal> > >()
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<6, 6, SReal> >, FullVector<SReal> > >()
.add<MatrixLinearSystem< CompressedRowSparseMatrix<type::Mat<8, 8, SReal> >, FullVector<SReal> > >());
}

} //namespace sofa::component::linearsystem
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ namespace sofa::component::linearsystem
{
template class SOFA_COMPONENT_LINEARSYSTEM_API MatrixProjectionMethod<sofa::linearalgebra::CompressedRowSparseMatrix<SReal> >;

int EigenMatrixMappingClass = core::RegisterObject("Matrix mapping computing the matrix projection using the Eigen library")
.add< MatrixProjectionMethod<sofa::linearalgebra::CompressedRowSparseMatrix<SReal> > >(true)
;
void registerMatrixProjectionMethod(sofa::core::ObjectFactory* factory)
{
factory->registerObjects(core::ObjectRegistrationData("Matrix mapping computing the matrix projection using the Eigen library.")
.add< MatrixProjectionMethod<sofa::linearalgebra::CompressedRowSparseMatrix<SReal> > >(true));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,25 @@
#include <sofa/component/linearsystem/init.h>

#include <sofa/core/ObjectFactory.h>
using sofa::core::ObjectFactory;
#include <sofa/helper/system/PluginManager.h>

namespace sofa::component::linearsystem
{

extern void registerCompositeLinearSystem(sofa::core::ObjectFactory* factory);
extern void registerConstantSparsityPatternSystem(sofa::core::ObjectFactory* factory);
extern void registerConstantSparsityProjectionMethod(sofa::core::ObjectFactory* factory);
extern void registerMatrixLinearSystem(sofa::core::ObjectFactory* factory);
extern void registerMatrixProjectionMethod(sofa::core::ObjectFactory* 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);

first = false;
}
}
Expand All @@ -42,6 +51,7 @@ extern "C" {
SOFA_COMPONENT_LINEARSYSTEM_API const char* getModuleVersion();
SOFA_COMPONENT_LINEARSYSTEM_API const char* getModuleLicense();
SOFA_COMPONENT_LINEARSYSTEM_API const char* getModuleDescription();
SOFA_COMPONENT_LINEARSYSTEM_API void registerObjects(sofa::core::ObjectFactory* factory);
}

void initExternalModule()
Expand Down Expand Up @@ -69,4 +79,13 @@ const char* getModuleDescription()
return "This plugin defines a linear system and provides components able to assemble one from the scene.";
}

void registerObjects(sofa::core::ObjectFactory* factory)
{
registerCompositeLinearSystem(factory);
registerConstantSparsityPatternSystem(factory);
registerConstantSparsityProjectionMethod(factory);
registerMatrixLinearSystem(factory);
registerMatrixProjectionMethod(factory);
}

} // namespace sofa::component::linearsystem
1 change: 1 addition & 0 deletions Sofa/Component/src/sofa/component/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void registerObjects(sofa::core::ObjectFactory* factory)
factory->registerObjectsFromPlugin("Sofa.Component.Visual");
factory->registerObjectsFromPlugin("Sofa.Component.Playback");
factory->registerObjectsFromPlugin("Sofa.Component.SceneUtility");
factory->registerObjectsFromPlugin("Sofa.Component.LinearSystem");
factory->registerObjectsFromPlugin("Sofa.Component.IO");
factory->registerObjectsFromPlugin("Sofa.Component.Controller");
factory->registerObjectsFromPlugin("Sofa.Component.Haptics");
Expand Down

0 comments on commit 720db5d

Please sign in to comment.