From 00410fe05b6b43d7fdf009cc340ef3274d391a1e Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 4 Nov 2025 08:26:59 +0100 Subject: [PATCH] Apply new factory registration mechanism --- .../MORUnilateralInteractionConstraint.cpp | 8 +-- .../component/contact/MORpointModel.cpp | 12 +++-- .../HyperReducedHexahedronFEMForceField.cpp | 8 +-- ...HyperReducedRestShapeSpringsForceField.cpp | 9 ++-- ...edTetrahedralCorotationalFEMForceField.cpp | 8 +-- .../HyperReducedTetrahedronFEMForceField.cpp | 8 +-- ...etrahedronHyperelasticityFEMForceField.cpp | 8 +-- .../HyperReducedTriangleFEMForceField.cpp | 8 +-- .../component/mapping/MORContactMapping.cpp | 16 +++--- .../mapping/ModelOrderReductionMapping.cpp | 8 +-- src/ModelOrderReduction/config.h.in | 11 ++-- .../initModelOrderReduction.cpp | 52 +++++++++++++++++-- 12 files changed, 107 insertions(+), 49 deletions(-) diff --git a/src/ModelOrderReduction/component/contact/MORUnilateralInteractionConstraint.cpp b/src/ModelOrderReduction/component/contact/MORUnilateralInteractionConstraint.cpp index 77050282..431f74e7 100644 --- a/src/ModelOrderReduction/component/contact/MORUnilateralInteractionConstraint.cpp +++ b/src/ModelOrderReduction/component/contact/MORUnilateralInteractionConstraint.cpp @@ -31,9 +31,11 @@ namespace sofa::component::constraint::lagrangian::model using namespace sofa::defaulttype; using namespace sofa::helper; -int MORUnilateralInteractionConstraintClass = core::RegisterObject("Unilateral constraint in a reduced model") - .add< MORUnilateralInteractionConstraint >() - ; +void registerMORUnilateralInteractionConstraint(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Unilateral constraint in a reduced model") + .add< MORUnilateralInteractionConstraint >()); +} template class SOFA_MODELORDERREDUCTION_API MORUnilateralInteractionConstraint; } // namespace sofa::component::constraint::lagrangian::model diff --git a/src/ModelOrderReduction/component/contact/MORpointModel.cpp b/src/ModelOrderReduction/component/contact/MORpointModel.cpp index c634c5c5..36a4bb45 100644 --- a/src/ModelOrderReduction/component/contact/MORpointModel.cpp +++ b/src/ModelOrderReduction/component/contact/MORpointModel.cpp @@ -32,11 +32,13 @@ using namespace sofa::defaulttype; using namespace sofa::core::collision; using namespace helper; -int MORPointCollisionModelClass = core::RegisterObject("Collision model which represents a set of points") - .add< MORPointCollisionModel >() - - .addAlias("MORPoint") - ; +void registerMORPointCollisionModel(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Collision model which represents a set of points") + .add< MORPointCollisionModel >() + .addAlias("MORPoint") + ); +} template class SOFA_MODELORDERREDUCTION_API MORPointCollisionModel; } // namespace sofa::component::collision::geometry diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedHexahedronFEMForceField.cpp b/src/ModelOrderReduction/component/forcefield/HyperReducedHexahedronFEMForceField.cpp index c37f82dd..94e4e7fe 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedHexahedronFEMForceField.cpp +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedHexahedronFEMForceField.cpp @@ -29,9 +29,11 @@ using namespace sofa::defaulttype; //SOFA_DECL_CLASS(HyperReducedHexahedronFEMForceField) // Register in the Factory -int HyperReducedHexahedronFEMForceFieldClass = core::RegisterObject("Hexahedral finite elements") - .add< HyperReducedHexahedronFEMForceField >() - ; +void registerHyperReducedHexahedronFEMForceField(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Hexahedral finite elements") + .add< HyperReducedHexahedronFEMForceField >()); +} template class SOFA_MODELORDERREDUCTION_API HyperReducedHexahedronFEMForceField; diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.cpp b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.cpp index 472fc9a7..0f85b1d7 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.cpp +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedRestShapeSpringsForceField.cpp @@ -29,10 +29,11 @@ using namespace sofa::defaulttype; SOFA_DECL_CLASS(HyperReducedRestShapeSpringsForceField) - -int HyperReducedRestShapeSpringsForceFieldClass = core::RegisterObject("Simple elastic springs applied to given degrees of freedom between their current and rest shape position") - .add< HyperReducedRestShapeSpringsForceField >() - ; +void registerHyperReducedRestShapeSpringsForceField(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Simple elastic springs applied to given degrees of freedom between their current and rest shape position") + .add< HyperReducedRestShapeSpringsForceField >()); +} template class SOFA_MODELORDERREDUCTION_API HyperReducedRestShapeSpringsForceField; } // namespace sofa::component::solidmechanics::spring diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedralCorotationalFEMForceField.cpp b/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedralCorotationalFEMForceField.cpp index 39b8d42c..35a2cda1 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedralCorotationalFEMForceField.cpp +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedralCorotationalFEMForceField.cpp @@ -31,9 +31,11 @@ using namespace sofa::defaulttype; SOFA_DECL_CLASS(HyperReducedTetrahedralCorotationalFEMForceField) // Register in the Factory -int HyperReducedTetrahedralCorotationalFEMForceFieldClass = core::RegisterObject("Corotational FEM Tetrahedral finite elements") - .add< HyperReducedTetrahedralCorotationalFEMForceField >() - ; +void registerHyperReducedTetrahedralCorotationalFEMForceField(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Corotational FEM Tetrahedral finite elements") + .add< HyperReducedTetrahedralCorotationalFEMForceField >()); +} template class SOFA_MODELORDERREDUCTION_API HyperReducedTetrahedralCorotationalFEMForceField; } // namespace sofa::component::solidmechanics::fem::elastic diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedronFEMForceField.cpp b/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedronFEMForceField.cpp index b8975db9..d7a88767 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedronFEMForceField.cpp +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedronFEMForceField.cpp @@ -30,9 +30,11 @@ using namespace sofa::defaulttype; SOFA_DECL_CLASS(HyperReducedTetrahedronFEMForceField) // Register in the Factory -int HyperReducedTetrahedronFEMForceFieldClass = core::RegisterObject("Tetrahedral finite elements") - .add< HyperReducedTetrahedronFEMForceField >() - ; +void registerHyperReducedTetrahedronFEMForceField(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Tetrahedral finite elements") + .add< HyperReducedTetrahedronFEMForceField >()); +} template class SOFA_MODELORDERREDUCTION_API HyperReducedTetrahedronFEMForceField; } // namespace sofa::component::forcefield diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedronHyperelasticityFEMForceField.cpp b/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedronHyperelasticityFEMForceField.cpp index 59c6ddd4..f2999744 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedronHyperelasticityFEMForceField.cpp +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedTetrahedronHyperelasticityFEMForceField.cpp @@ -31,9 +31,11 @@ using namespace sofa::defaulttype; SOFA_DECL_CLASS(HyperReducedTetrahedronHyperelasticityFEMForceField) // Register in the Factory -int HyperReducedTetrahedronHyperelasticityFEMForceFieldClass = core::RegisterObject("Generic Tetrahedral finite elements") - .add< HyperReducedTetrahedronHyperelasticityFEMForceField >() - ; +void registerHyperReducedTetrahedronHyperelasticityFEMForceField(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Generic Tetrahedral finite elements") + .add< HyperReducedTetrahedronHyperelasticityFEMForceField >()); +} template class SOFA_MODELORDERREDUCTION_API HyperReducedTetrahedronHyperelasticityFEMForceField; } // namespace sofa::component::forcefield diff --git a/src/ModelOrderReduction/component/forcefield/HyperReducedTriangleFEMForceField.cpp b/src/ModelOrderReduction/component/forcefield/HyperReducedTriangleFEMForceField.cpp index 172404f7..6dbde299 100644 --- a/src/ModelOrderReduction/component/forcefield/HyperReducedTriangleFEMForceField.cpp +++ b/src/ModelOrderReduction/component/forcefield/HyperReducedTriangleFEMForceField.cpp @@ -30,9 +30,11 @@ SOFA_DECL_CLASS(HyperReducedTriangleFEMForceField) using namespace sofa::defaulttype; // Register in the Factory -int HyperReducedTriangleFEMForceFieldClass = core::RegisterObject("Triangular finite elements") - .add< HyperReducedTriangleFEMForceField >() - ; +void registerHyperReducedTriangleFEMForceField(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Triangular finite elements") + .add< HyperReducedTriangleFEMForceField >()); +} template class SOFA_MODELORDERREDUCTION_API HyperReducedTriangleFEMForceField; } // namespace sofa::component::solidmechanics::fem::elastic diff --git a/src/ModelOrderReduction/component/mapping/MORContactMapping.cpp b/src/ModelOrderReduction/component/mapping/MORContactMapping.cpp index 8e57741d..c40f7c32 100644 --- a/src/ModelOrderReduction/component/mapping/MORContactMapping.cpp +++ b/src/ModelOrderReduction/component/mapping/MORContactMapping.cpp @@ -40,13 +40,13 @@ using namespace core::behavior; // Register in the Factory -int MORContactMappingClass = core::RegisterObject("Special case of mapping where the child points are the same as the parent points") - .add< MORContactMapping< Vec3dTypes, Vec3dTypes > >() - .add< MORContactMapping< Vec2Types, Vec2Types > >() - .add< MORContactMapping< Vec1Types, Vec1Types > >() - - ; - +void registerMORContactMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Special case of mapping where the child points are the same as the parent points") + .add< MORContactMapping< Vec3dTypes, Vec3dTypes > >() + .add< MORContactMapping< Vec2Types, Vec2Types > >() + .add< MORContactMapping< Vec1Types, Vec1Types > >()); +} template class MORContactMapping< Vec3dTypes, Vec3dTypes >; template class MORContactMapping< Vec2Types, Vec2Types >; @@ -54,8 +54,6 @@ template class MORContactMapping< Vec1Types, Vec1Types >; - - } // namespace mapping } // namespace component diff --git a/src/ModelOrderReduction/component/mapping/ModelOrderReductionMapping.cpp b/src/ModelOrderReduction/component/mapping/ModelOrderReductionMapping.cpp index 740a56ed..e635a7c6 100644 --- a/src/ModelOrderReduction/component/mapping/ModelOrderReductionMapping.cpp +++ b/src/ModelOrderReduction/component/mapping/ModelOrderReductionMapping.cpp @@ -36,9 +36,11 @@ using namespace core::behavior; SOFA_DECL_CLASS(ModelOrderReductionMapping) // Register in the Factory -static int ModelOrderReductionMappingClass = core::RegisterObject("Reduced model") - .add< ModelOrderReductionMapping< Vec1Types, Vec3Types > >(true) - ; +void registerModelOrderReductionMapping(sofa::core::ObjectFactory* factory) +{ + factory->registerObjects(sofa::core::ObjectRegistrationData("Reduced model") + .add< ModelOrderReductionMapping< Vec1Types, Vec3Types > >(true)); +} template class SOFA_MODELORDERREDUCTION_API ModelOrderReductionMapping< Vec1Types, Vec3Types >; diff --git a/src/ModelOrderReduction/config.h.in b/src/ModelOrderReduction/config.h.in index edcb30ab..40049cd8 100644 --- a/src/ModelOrderReduction/config.h.in +++ b/src/ModelOrderReduction/config.h.in @@ -14,9 +14,7 @@ * * * Contact information: https://project.inria.fr/modelorderreduction/contact * ******************************************************************************/ -#ifndef INITMODELORDERREDUCTION_H -#define INITMODELORDERREDUCTION_H - +#pragma once #include @@ -27,6 +25,9 @@ #define SOFA_MODELORDERREDUCTION_API SOFA_IMPORT_DYNAMIC_LIBRARY #endif -#endif // INITINITMODELORDERREDUCTION_H - +namespace modelorderreduction +{ + constexpr const char* MODULE_NAME = "@PROJECT_NAME@"; + constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@"; +} // namespace modelorderreduction diff --git a/src/ModelOrderReduction/initModelOrderReduction.cpp b/src/ModelOrderReduction/initModelOrderReduction.cpp index c4a664ca..dfbc6b35 100644 --- a/src/ModelOrderReduction/initModelOrderReduction.cpp +++ b/src/ModelOrderReduction/initModelOrderReduction.cpp @@ -16,9 +16,39 @@ ******************************************************************************/ #include #include +#include #include +namespace sofa::component::solidmechanics::spring +{ + extern void registerHyperReducedRestShapeSpringsForceField(sofa::core::ObjectFactory* factory); +} +namespace sofa::component::solidmechanics::fem::elastic +{ + extern void registerHyperReducedTetrahedralCorotationalFEMForceField(sofa::core::ObjectFactory* factory); + extern void registerHyperReducedTriangleFEMForceField(sofa::core::ObjectFactory* factory); +} +namespace sofa::component::forcefield +{ + extern void registerHyperReducedHexahedronFEMForceField(sofa::core::ObjectFactory* factory); + extern void registerHyperReducedTetrahedronHyperelasticityFEMForceField(sofa::core::ObjectFactory* factory); + extern void registerHyperReducedTetrahedronFEMForceField(sofa::core::ObjectFactory* factory); +} +namespace sofa::component::mapping +{ + extern void registerMORContactMapping(sofa::core::ObjectFactory* factory); + extern void registerModelOrderReductionMapping(sofa::core::ObjectFactory* factory); +} +namespace sofa::component::constraint::lagrangian::model +{ + extern void registerMORUnilateralInteractionConstraint(sofa::core::ObjectFactory* factory); +} +namespace sofa::component::collision::geometry +{ + extern void registerMORPointCollisionModel(sofa::core::ObjectFactory* factory); +} + namespace modelorderreduction { //Here are just several convenient functions to help user to know what contains the plugin @@ -29,7 +59,7 @@ extern "C" { SOFA_MODELORDERREDUCTION_API const char* getModuleVersion(); SOFA_MODELORDERREDUCTION_API const char* getModuleLicense(); SOFA_MODELORDERREDUCTION_API const char* getModuleDescription(); - SOFA_MODELORDERREDUCTION_API const char* getModuleComponentList(); + SOFA_MODELORDERREDUCTION_API void registerObjects(sofa::core::ObjectFactory* factory); } void initExternalModule() @@ -37,18 +67,21 @@ void initExternalModule() 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; } } const char* getModuleName() { - return "ModelOrderReduction"; + return MODULE_NAME; } const char* getModuleVersion() { - return "1.0"; + return MODULE_VERSION; } const char* getModuleLicense() @@ -57,9 +90,18 @@ const char* getModuleLicense() } -const char* getModuleDescription() +void registerObjects(sofa::core::ObjectFactory* factory) { - return "The ModelOrderReduction plugin builds reduced models by reducing the computational complexity of the system"; + sofa::component::solidmechanics::spring::registerHyperReducedRestShapeSpringsForceField(factory); + sofa::component::solidmechanics::fem::elastic::registerHyperReducedTetrahedralCorotationalFEMForceField( factory); + sofa::component::solidmechanics::fem::elastic::registerHyperReducedTriangleFEMForceField(factory); + sofa::component::forcefield::registerHyperReducedHexahedronFEMForceField(factory); + sofa::component::forcefield::registerHyperReducedTetrahedronHyperelasticityFEMForceField(factory); + sofa::component::forcefield::registerHyperReducedTetrahedronFEMForceField(factory); + sofa::component::mapping::registerMORContactMapping(factory); + sofa::component::mapping::registerModelOrderReductionMapping(factory); + sofa::component::constraint::lagrangian::model::registerMORUnilateralInteractionConstraint(factory); + sofa::component::collision::geometry::registerMORPointCollisionModel(factory); } }