From 42c6652dfecf125cb3496b41a8b960cc6ad79a07 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 12 May 2025 18:11:59 +0200 Subject: [PATCH 1/7] [Framework] Apply template method design pattern to BaseMass --- .../src/sofa/component/mass/DiagonalMass.h | 2 +- .../src/sofa/component/mass/DiagonalMass.inl | 2 +- .../src/sofa/component/mass/MeshMatrixMass.h | 2 +- .../sofa/component/mass/MeshMatrixMass.inl | 2 +- .../src/sofa/component/mass/UniformMass.h | 2 +- .../src/sofa/component/mass/UniformMass.inl | 2 +- .../elastic/HexahedronFEMForceFieldAndMass.h | 4 +- .../HexahedronFEMForceFieldAndMass.inl | 2 +- .../Core/src/sofa/core/behavior/BaseMass.cpp | 2 +- .../Core/src/sofa/core/behavior/BaseMass.h | 62 ++++++++++++++++--- .../Core/src/sofa/core/behavior/Mass.h | 16 ++--- .../Core/src/sofa/core/behavior/Mass.inl | 36 +++++------ 12 files changed, 84 insertions(+), 50 deletions(-) diff --git a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h index e54db5c837c..f63980ac004 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h @@ -307,7 +307,7 @@ class DiagonalMass : public core::behavior::Mass, public virtual sofa /// Add Mass contribution to global Matrix assembling void addMToMatrix(sofa::linearalgebra::BaseMatrix * mat, SReal mFact, unsigned int &offset) override; - void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override; + void doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override; void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} diff --git a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl index 3ec1e820647..ed585fcd010 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl @@ -627,7 +627,7 @@ void DiagonalMass::addMToMatrix(sofa::linearalgebra } template -void DiagonalMass::buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) +void DiagonalMass::doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) { const MassVector &masses= d_vertexMass.getValue(); static constexpr auto N = Deriv::total_size; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h index eac01a2eedf..4392cf9573a 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h @@ -221,7 +221,7 @@ class MeshMatrixMass : public core::behavior::Mass, public virtual co /// Add Mass contribution to global Matrix assembling using Inherited::addMToMatrix; void addMToMatrix(sofa::linearalgebra::BaseMatrix * mat, SReal mFact, unsigned int &offset) override; - void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override; + void doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override; void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} diff --git a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl index 79af714bbff..547d0c10f77 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl @@ -2258,7 +2258,7 @@ void MeshMatrixMass::addMToMatrix(sofa::linearalgeb } template -void MeshMatrixMass::buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) +void MeshMatrixMass::doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) { const MassVector &vertexMass= d_vertexMass.getValue(); const MassVector &edgeMass= d_edgeMass.getValue(); diff --git a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h index e5ce1c12bf3..b29bd936b03 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h @@ -146,7 +146,7 @@ class UniformMass : public core::behavior::Mass, public virtual core: using Inherited::addMToMatrix; void addMToMatrix(sofa::linearalgebra::BaseMatrix * mat, SReal mFact, unsigned int &offset) override; /// Add Mass contribution to global Matrix assembling - void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override; + void doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override; void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} diff --git a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl index e69dee976cc..130f76a1ba5 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl @@ -572,7 +572,7 @@ void UniformMass::addMToMatrix (sofa::linearalgebra::BaseMatrix * mat } template -void UniformMass::buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) +void UniformMass::doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) { if (!this->isComponentStateValid()) { diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.h index d6e8b1531a1..203beb4a5a1 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.h @@ -85,7 +85,7 @@ class HexahedronFEMForceFieldAndMass : virtual public core::behavior::Mass::buildStiffnessMatrix(core::behav } template -void HexahedronFEMForceFieldAndMass::buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) +void HexahedronFEMForceFieldAndMass::doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) { int e = 0; for(auto it = this->getIndexedElements()->begin(); it != this->getIndexedElements()->end() ; ++it, ++e) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.cpp b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.cpp index 340ee5a4ae9..b7ea909e3b6 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.cpp +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.cpp @@ -49,7 +49,7 @@ bool BaseMass::removeInNode( objectmodel::BaseNode* node ) return true; } -void BaseMass::buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) +void BaseMass::doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) { static std::set hasEmittedWarning; if (hasEmittedWarning.insert(this).second) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h index d2e28de59b5..82a1107faf1 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h @@ -47,9 +47,17 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor protected: BaseMass(); - ~BaseMass() override = default; + virtual void doAddMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) = 0; + virtual void doAccFromF(const MechanicalParams* mparams, MultiVecDerivId aid) = 0; + virtual void doAddGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) = 0; + virtual SReal doGetKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; + virtual SReal doGetPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; + virtual type::Vec6 doGetMomentum(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; + virtual void doAddMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) = 0; + virtual void doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices); + private: BaseMass(const BaseMass& n) = delete; BaseMass& operator=(const BaseMass& n) = delete; @@ -58,24 +66,52 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor /// @name Vector operations /// @{ + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doAddMDx", internally, + * which is the method to override from now on. + * + **/ + /// f += factor M dx - virtual void addMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) =0; + virtual void addMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) final + { + doAddMDx(mparams, fid, factor); + } /// dx = M^-1 f - virtual void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) = 0; + virtual void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) final + { + doAccFromF(mparams, aid); + } /// \brief Perform v += dt*g operation. Used if mass wants to added G separately from the other forces to v. /// /// \param mparams \a sofa::core::mechanicalparams::dt(mparams) is the time step of for temporal discretization. - virtual void addGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) = 0; + virtual void addGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) final + { + doAddGravityToV(mparams, vid); + } /// vMv/2 - virtual SReal getKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; + virtual SReal getKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final + { + return doGetKineticEnergy(mparams); + } + /// Mgx - virtual SReal getPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; + virtual SReal getPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final + { + return doGetPotentialEnergy(mparams); + } /// (Mv,xMv+Iw) (linear and angular momenta against world origin) - virtual type::Vec6 getMomentum(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; + virtual type::Vec6 getMomentum(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final + { + return doGetMomentum(mparams); + } /// @} @@ -87,9 +123,15 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor /// This method must be implemented by the component. /// \param matrix matrix to add the result to /// \param mparams \a mparams->mFactor() is the coefficient for mass contributions (i.e. second-order derivatives term in the ODE) - virtual void addMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) = 0; - - virtual void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices); + virtual void addMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) final + { + doAddMToMatrix(mparams, matrix); + } + + virtual void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) final + { + doBuildMassMatrix(matrices); + } /// @} diff --git a/Sofa/framework/Core/src/sofa/core/behavior/Mass.h b/Sofa/framework/Core/src/sofa/core/behavior/Mass.h index 1dec7f93119..bc7f01f6a5a 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Mass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/Mass.h @@ -54,8 +54,8 @@ class Mass : virtual public ForceField, public BaseMass protected: Mass(MechanicalState *mm = nullptr); - ~Mass() override; + public: /// @name Vector operations @@ -64,7 +64,7 @@ class Mass : virtual public ForceField, public BaseMass /// /// This method retrieves the force and dx vector and call the internal /// addMDx(const MechanicalParams*, DataVecDeriv&, const DataVecDeriv&, SReal) method implemented by the component. - void addMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) override; + void doAddMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) override; virtual void addMDx(const MechanicalParams* mparams, DataVecDeriv& f, const DataVecDeriv& dx, SReal factor); @@ -72,7 +72,7 @@ class Mass : virtual public ForceField, public BaseMass /// /// This method retrieves the force and dx vector and call the internal /// accFromF(VecDeriv&,const VecDeriv&) method implemented by the component. - void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) override; + void doAccFromF(const MechanicalParams* mparams, MultiVecDerivId aid) override; virtual void accFromF(const MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f); @@ -96,14 +96,14 @@ class Mass : virtual public ForceField, public BaseMass /// /// This method retrieves the velocity vector and call the internal /// getKineticEnergy(const MechanicalParams*, const DataVecDeriv&) method implemented by the component. - SReal getKineticEnergy( const MechanicalParams* mparams) const override; + SReal doGetKineticEnergy( const MechanicalParams* mparams) const override; virtual SReal getKineticEnergy( const MechanicalParams* mparams, const DataVecDeriv& v) const; /// $ e = M g x $ /// /// This method retrieves the positions vector and call the internal /// getPotentialEnergy(const MechanicalParams*, const VecCoord&) method implemented by the component. - SReal getPotentialEnergy( const MechanicalParams* mparams) const override; + SReal doGetPotentialEnergy( const MechanicalParams* mparams) const override; SReal getPotentialEnergy( const MechanicalParams* mparams, const DataVecCoord& x ) const override; @@ -112,7 +112,7 @@ class Mass : virtual public ForceField, public BaseMass /// /// This method retrieves the positions and velocity vectors and call the internal /// getMomentum(const MechanicalParams*, const VecCoord&, const VecDeriv&) method implemented by the component. - type::Vec6 getMomentum( const MechanicalParams* mparams ) const override; + type::Vec6 doGetMomentum( const MechanicalParams* mparams ) const override; virtual type::Vec6 getMomentum( const MechanicalParams* , const DataVecCoord& , const DataVecDeriv& ) const; @@ -125,7 +125,7 @@ class Mass : virtual public ForceField, public BaseMass void addKToMatrix(sofa::linearalgebra::BaseMatrix * /*matrix*/, SReal /*kFact*/, unsigned int &/*offset*/) override {} void addBToMatrix(sofa::linearalgebra::BaseMatrix * /*matrix*/, SReal /*bFact*/, unsigned int &/*offset*/) override {} - void addMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doAddMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; virtual void addMToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal mFact, unsigned int &offset); @@ -146,7 +146,7 @@ class Mass : virtual public ForceField, public BaseMass void exportGnuplot(const MechanicalParams* mparams, SReal time) override; /// perform v += dt*g operation. Used if mass wants to added G separately from the other forces to v. - void addGravityToV(const MechanicalParams* mparams, MultiVecDerivId /*vid*/) override; + void doAddGravityToV(const MechanicalParams* mparams, MultiVecDerivId /*vid*/) override; virtual void addGravityToV(const MechanicalParams* /* mparams */, DataVecDeriv& /* d_v */); diff --git a/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl b/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl index ddfc9869433..650abfb8e00 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl @@ -45,7 +45,7 @@ Mass::~Mass() } template -void Mass::addMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) +void Mass::doAddMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) { if (mparams) { @@ -66,7 +66,7 @@ void Mass::addMDx(const MechanicalParams* /*mparams*/, DataVecDeriv& template -void Mass::accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) +void Mass::doAccFromF(const MechanicalParams* mparams, MultiVecDerivId aid) { if(mparams) { @@ -102,7 +102,7 @@ void Mass::addMBKdx(const MechanicalParams* mparams, MultiVecDerivId } template -SReal Mass::getKineticEnergy(const MechanicalParams* mparams) const +SReal Mass::doGetKineticEnergy(const MechanicalParams* mparams) const { if (this->mstate) return getKineticEnergy(mparams /* PARAMS FIRST */, *mparams->readV(this->mstate.get())); @@ -118,7 +118,7 @@ SReal Mass::getKineticEnergy(const MechanicalParams* /*mparams*/, con template -SReal Mass::getPotentialEnergy(const MechanicalParams* mparams) const +SReal Mass::doGetPotentialEnergy(const MechanicalParams* mparams) const { if (this->mstate) return getPotentialEnergy(mparams /* PARAMS FIRST */, *mparams->readX(this->mstate.get())); @@ -134,7 +134,7 @@ SReal Mass::getPotentialEnergy(const MechanicalParams* /*mparams*/, c template -type::Vec6 Mass::getMomentum( const MechanicalParams* mparams ) const +type::Vec6 Mass::doGetMomentum( const MechanicalParams* mparams ) const { auto state = this->mstate.get(); if (state) @@ -152,7 +152,7 @@ type::Vec6 Mass::getMomentum( const MechanicalParams* /*mparams*/, co template -void Mass::addMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void Mass::doAddMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { sofa::core::behavior::MultiMatrixAccessor::MatrixRef r = matrix->getMatrix(this->mstate); if (r) @@ -162,11 +162,7 @@ void Mass::addMToMatrix(const MechanicalParams* mparams, const sofa:: template void Mass::addMToMatrix(sofa::linearalgebra::BaseMatrix * /*mat*/, SReal /*mFact*/, unsigned int &/*offset*/) { - static int i=0; - if (i < 10) { - msg_warning() << "Method addMToMatrix with Scalar not implemented"; - i++; - } + msg_warning() << "Method addMToMatrix with Scalar not implemented"; } template @@ -174,11 +170,11 @@ void Mass::addMBKToMatrix(const MechanicalParams* mparams, const sofa { this->ForceField::addMBKToMatrix(mparams, matrix); if (mparams->mFactorIncludingRayleighDamping(rayleighMass.getValue()) != 0.0) - addMToMatrix(mparams, matrix); + BaseMass::addMToMatrix(mparams, matrix); } template -void Mass::addGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) +void Mass::doAddGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) { if(this->mstate) { @@ -190,11 +186,7 @@ void Mass::addGravityToV(const MechanicalParams* mparams, MultiVecDer template void Mass::addGravityToV(const MechanicalParams* /* mparams */, DataVecDeriv& /* d_v */) { - static int i=0; - if (i < 10) { - msg_warning() << "Method addGravityToV with Scalar not implemented"; - i++; - } + msg_warning() << "Method addGravityToV with Scalar not implemented"; } @@ -215,10 +207,10 @@ void Mass::exportGnuplot(const MechanicalParams* mparams, SReal time) { if (m_gnuplotFileEnergy!=nullptr) { - (*m_gnuplotFileEnergy) << time <<"\t"<< this->getKineticEnergy(mparams) - <<"\t"<< this->getPotentialEnergy(mparams) - <<"\t"<< this->getPotentialEnergy(mparams) - +this->getKineticEnergy(mparams)<< std::endl; + (*m_gnuplotFileEnergy) << time <<"\t"<< BaseMass::getKineticEnergy(mparams) + <<"\t"<< BaseMass::getPotentialEnergy(mparams) + <<"\t"<< BaseMass::getPotentialEnergy(mparams) + +BaseMass::getKineticEnergy(mparams)<< std::endl; } } From 1cb01c866668db8a6830cfd83f61fd87f5ac4990 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 12 May 2025 18:15:29 +0200 Subject: [PATCH 2/7] Add all associated warning comments --- .../Core/src/sofa/core/behavior/BaseMass.h | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h index 82a1107faf1..923dedd51c2 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h @@ -81,12 +81,30 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor doAddMDx(mparams, fid, factor); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doAccFromF", internally, + * which is the method to override from now on. + * + **/ + /// dx = M^-1 f virtual void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) final { doAccFromF(mparams, aid); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doAddGravityToV", internally, + * which is the method to override from now on. + * + **/ + /// \brief Perform v += dt*g operation. Used if mass wants to added G separately from the other forces to v. /// /// \param mparams \a sofa::core::mechanicalparams::dt(mparams) is the time step of for temporal discretization. @@ -95,18 +113,45 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor doAddGravityToV(mparams, vid); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetKineticEnergy", internally, + * which is the method to override from now on. + * + **/ + /// vMv/2 virtual SReal getKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final { return doGetKineticEnergy(mparams); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetPotentialEnergy", internally, + * which is the method to override from now on. + * + **/ + /// Mgx virtual SReal getPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final { return doGetPotentialEnergy(mparams); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetMomentum", internally, + * which is the method to override from now on. + * + **/ + /// (Mv,xMv+Iw) (linear and angular momenta against world origin) virtual type::Vec6 getMomentum(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final { @@ -118,6 +163,15 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor /// @name Matrix operations /// @{ + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doAddMToMatrix", internally, + * which is the method to override from now on. + * + **/ + /// \brief Add Mass contribution to global Matrix assembling. /// /// This method must be implemented by the component. @@ -128,6 +182,15 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor doAddMToMatrix(mparams, matrix); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doBuildMassMatrix", internally, + * which is the method to override from now on. + * + **/ + virtual void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) final { doBuildMassMatrix(matrices); From bca34f390d14ecbeaa746f5492a929728d590d65 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 12 May 2025 19:18:38 +0200 Subject: [PATCH 3/7] fix warnings --- Sofa/framework/Core/src/sofa/core/behavior/Mass.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/Mass.h b/Sofa/framework/Core/src/sofa/core/behavior/Mass.h index bc7f01f6a5a..0c9daf1f1a9 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Mass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/Mass.h @@ -58,6 +58,15 @@ class Mass : virtual public ForceField, public BaseMass public: + // Avoid warning : hidden [-Woverloaded-virtual=] + using BaseMass::addMDx; + using BaseMass::accFromF; + using BaseMass::getKineticEnergy; + using BaseMass::getPotentialEnergy; + using BaseMass::getMomentum; + using BaseMass::addMToMatrix; + using BaseMass::addGravityToV; + /// @name Vector operations /// @{ /// $ f += factor M dx $ From 4bf0b943f8493dc651ebed4db702d12903980752 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 12 May 2025 19:22:59 +0200 Subject: [PATCH 4/7] Pursue rest of the API --- .../src/sofa/component/mass/DiagonalMass.h | 4 +- .../src/sofa/component/mass/DiagonalMass.inl | 4 +- .../src/sofa/component/mass/MeshMatrixMass.h | 4 +- .../sofa/component/mass/MeshMatrixMass.inl | 4 +- .../src/sofa/component/mass/UniformMass.h | 4 +- .../src/sofa/component/mass/UniformMass.inl | 4 +- .../elastic/HexahedralFEMForceFieldAndMass.h | 2 +- .../HexahedralFEMForceFieldAndMass.inl | 2 +- .../elastic/HexahedronFEMForceFieldAndMass.h | 2 +- .../HexahedronFEMForceFieldAndMass.inl | 2 +- .../Core/src/sofa/core/behavior/BaseMass.h | 62 +++++++++++++++++-- .../Core/src/sofa/core/behavior/Mass.h | 10 +-- .../Core/src/sofa/core/behavior/Mass.inl | 8 +-- 13 files changed, 83 insertions(+), 29 deletions(-) diff --git a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h index f63980ac004..8fce8c429db 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h @@ -311,8 +311,8 @@ class DiagonalMass : public core::behavior::Mass, public virtual sofa void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} - SReal getElementMass(sofa::Index index) const override; - void getElementMass(sofa::Index, linearalgebra::BaseMatrix *m) const override; + SReal doGetElementMass(sofa::Index index) const override; + void doGetElementMass(sofa::Index, linearalgebra::BaseMatrix *m) const override; bool isDiagonal() const override {return true;} diff --git a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl index ed585fcd010..156ec32dc34 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl @@ -641,7 +641,7 @@ void DiagonalMass::doBuildMassMatrix(sofa::core::be template -SReal DiagonalMass::getElementMass(sofa::Index index) const +SReal DiagonalMass::doGetElementMass(sofa::Index index) const { return SReal(d_vertexMass.getValue()[index]); } @@ -649,7 +649,7 @@ SReal DiagonalMass::getElementMass(sofa::Index inde //TODO: special case for Rigid Mass template -void DiagonalMass::getElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const +void DiagonalMass::doGetElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const { static const linearalgebra::BaseMatrix::Index dimension = linearalgebra::BaseMatrix::Index(defaulttype::DataTypeInfo::size()); if (m->rowSize() != dimension || m->colSize() != dimension) m->resize(dimension,dimension); diff --git a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h index 4392cf9573a..a8e2bcbc957 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h @@ -225,8 +225,8 @@ class MeshMatrixMass : public core::behavior::Mass, public virtual co void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} - SReal getElementMass(Index index) const override; - void getElementMass(Index index, linearalgebra::BaseMatrix *m) const override; + SReal doGetElementMass(Index index) const override; + void doGetElementMass(Index index, linearalgebra::BaseMatrix *m) const override; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl index 547d0c10f77..4bbfc701a71 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl @@ -2299,7 +2299,7 @@ void MeshMatrixMass::doBuildMassMatrix(sofa::core:: template -SReal MeshMatrixMass::getElementMass(Index index) const +SReal MeshMatrixMass::doGetElementMass(Index index) const { const auto &vertexMass= d_vertexMass.getValue(); const SReal mass = vertexMass[index] * m_massLumpingCoeff; @@ -2310,7 +2310,7 @@ SReal MeshMatrixMass::getElementMass(Index index) c //TODO: special case for Rigid Mass template -void MeshMatrixMass::getElementMass(Index index, linearalgebra::BaseMatrix *m) const +void MeshMatrixMass::doGetElementMass(Index index, linearalgebra::BaseMatrix *m) const { static const linearalgebra::BaseMatrix::Index dimension = linearalgebra::BaseMatrix::Index(defaulttype::DataTypeInfo::size()); if (m->rowSize() != dimension || m->colSize() != dimension) m->resize(dimension,dimension); diff --git a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h index b29bd936b03..b0c06daf2f0 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h @@ -150,8 +150,8 @@ class UniformMass : public core::behavior::Mass, public virtual core: void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} - SReal getElementMass(sofa::Index index) const override; - void getElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const override; + SReal doGetElementMass(sofa::Index index) const override; + void doGetElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const override; bool isDiagonal() const override {return true;} diff --git a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl index 130f76a1ba5..ad1740c856b 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl @@ -593,14 +593,14 @@ void UniformMass::doBuildMassMatrix(sofa::core::behavior::MassMatrixA template -SReal UniformMass::getElementMass (sofa::Index ) const +SReal UniformMass::doGetElementMass (sofa::Index ) const { return (SReal ( d_vertexMass.getValue() )); } template -void UniformMass::getElementMass (sofa::Index index, BaseMatrix *m ) const +void UniformMass::doGetElementMass (sofa::Index index, BaseMatrix *m ) const { SOFA_UNUSED(index); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.h index e85613ce8d1..92d007aa158 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.h @@ -106,7 +106,7 @@ class HexahedralFEMForceFieldAndMass : virtual public sofa::core::behavior::Mass void draw(const core::visual::VisualParams* vparams) override; - SReal getElementMass(sofa::Index index) const override; + SReal doGetElementMass(sofa::Index index) const override; void setDensity(Real d) {d_density.setValue(d );} Real getDensity() {return d_density.getValue();} diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl index eccde4589d2..d99f301afd0 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl @@ -436,7 +436,7 @@ void HexahedralFEMForceFieldAndMass::addDForce(const core::Mechanical template -SReal HexahedralFEMForceFieldAndMass::getElementMass(sofa::Index /*index*/) const +SReal HexahedralFEMForceFieldAndMass::doGetElementMass(sofa::Index /*index*/) const { msg_error() << "HexahedralFEMForceFieldAndMass::getElementMass not yet implemented"; return 0.0; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.h index 203beb4a5a1..f75b482a5f9 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceFieldAndMass.h @@ -113,7 +113,7 @@ class HexahedronFEMForceFieldAndMass : virtual public core::behavior::Mass::addDForce(const core::Mechanical template -SReal HexahedronFEMForceFieldAndMass::getElementMass(sofa::Index /*index*/) const +SReal HexahedronFEMForceFieldAndMass::doGetElementMass(sofa::Index /*index*/) const { msg_warning()<<"HexahedronFEMForceFieldAndMass::getElementMass not yet implemented"<, public BaseMass using BaseMass::getMomentum; using BaseMass::addMToMatrix; using BaseMass::addGravityToV; - + /// @name Vector operations /// @{ /// $ f += factor M dx $ @@ -149,10 +149,10 @@ class Mass : virtual public ForceField, public BaseMass /// @} /// initialization to export kinetic and potential energy to gnuplot files format - void initGnuplot(const std::string path) override; + void doInitGnuplot(const std::string path) override; /// export kinetic and potential energy state at "time" to a gnuplot file - void exportGnuplot(const MechanicalParams* mparams, SReal time) override; + void doExportGnuplot(const MechanicalParams* mparams, SReal time) override; /// perform v += dt*g operation. Used if mass wants to added G separately from the other forces to v. void doAddGravityToV(const MechanicalParams* mparams, MultiVecDerivId /*vid*/) override; @@ -160,8 +160,8 @@ class Mass : virtual public ForceField, public BaseMass /// recover the mass of an element - SReal getElementMass(sofa::Index) const override; - void getElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const override; + SReal doGetElementMass(sofa::Index) const override; + void doGetElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const override; protected: /// stream to export Kinematic, Potential and Mechanical Energy to gnuplot files diff --git a/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl b/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl index 650abfb8e00..cbc7aadadad 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl @@ -191,7 +191,7 @@ void Mass::addGravityToV(const MechanicalParams* /* mparams */, DataV template -void Mass::initGnuplot(const std::string path) +void Mass::doInitGnuplot(const std::string path) { if (!this->getName().empty()) { @@ -203,7 +203,7 @@ void Mass::initGnuplot(const std::string path) } template -void Mass::exportGnuplot(const MechanicalParams* mparams, SReal time) +void Mass::doExportGnuplot(const MechanicalParams* mparams, SReal time) { if (m_gnuplotFileEnergy!=nullptr) { @@ -215,14 +215,14 @@ void Mass::exportGnuplot(const MechanicalParams* mparams, SReal time) } template -SReal Mass::getElementMass(sofa::Index ) const +SReal Mass::doGetElementMass(sofa::Index ) const { msg_warning() << "Method getElementMass with Scalar not implemented"; return 0.0; } template -void Mass::getElementMass(sofa::Index, linearalgebra::BaseMatrix *m) const +void Mass::doGetElementMass(sofa::Index, linearalgebra::BaseMatrix *m) const { static const linearalgebra::BaseMatrix::Index dimension = (linearalgebra::BaseMatrix::Index) defaulttype::DataTypeInfo::size(); if (m->rowSize() != dimension || m->colSize() != dimension) m->resize(dimension,dimension); From 926527c8b0bb006db2036208ad8e394c3f52ae87 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 14 May 2025 11:53:52 +0200 Subject: [PATCH 5/7] Move all functions in BaseMass.cpp and add comment message --- .../Core/src/sofa/core/behavior/BaseMass.cpp | 72 +++++++++++++++++++ .../Core/src/sofa/core/behavior/BaseMass.h | 67 ++++------------- 2 files changed, 87 insertions(+), 52 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.cpp b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.cpp index b7ea909e3b6..ecb44d8e02d 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.cpp +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.cpp @@ -35,6 +35,78 @@ BaseMass::BaseMass() { } +void BaseMass::addMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doAddMDx(mparams, fid, factor); +} + +void BaseMass::accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doAccFromF(mparams, aid); +} + +void BaseMass::addGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doAddGravityToV(mparams, vid); +} + +SReal BaseMass::getKineticEnergy(const MechanicalParams* mparams) const +{ + //TODO (SPRINT SED 2025): Component state mechanism + return doGetKineticEnergy(mparams); +} + +SReal BaseMass::getPotentialEnergy(const MechanicalParams* mparams) const +{ + //TODO (SPRINT SED 2025): Component state mechanism + return doGetPotentialEnergy(mparams); +} + +type::Vec6 BaseMass::getMomentum(const MechanicalParams* mparams) const +{ + //TODO (SPRINT SED 2025): Component state mechanism + return doGetMomentum(mparams); +} + +void BaseMass::addMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doAddMToMatrix(mparams, matrix); +} + +void BaseMass::buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doBuildMassMatrix(matrices); +} + +void BaseMass::initGnuplot(const std::string path) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doInitGnuplot(path); +} + +void BaseMass::exportGnuplot(const MechanicalParams* mparams, SReal time) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doExportGnuplot(mparams, time); +} + +SReal BaseMass::getElementMass(sofa::Index index) const +{ + //TODO (SPRINT SED 2025): Component state mechanism + return doGetElementMass(index); +} + +void BaseMass::getElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const +{ + //TODO (SPRINT SED 2025): Component state mechanism + doGetElementMass(index, m); +} + bool BaseMass::insertInNode( objectmodel::BaseNode* node ) { node->addMass(this); diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h index c2bbec19069..e32e90b70fd 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h @@ -52,9 +52,9 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual void doAddMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) = 0; virtual void doAccFromF(const MechanicalParams* mparams, MultiVecDerivId aid) = 0; virtual void doAddGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) = 0; - virtual SReal doGetKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; - virtual SReal doGetPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; - virtual type::Vec6 doGetMomentum(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; + virtual SReal doGetKineticEnergy(const MechanicalParams* mparams) const = 0; + virtual SReal doGetPotentialEnergy(const MechanicalParams* mparams) const = 0; + virtual type::Vec6 doGetMomentum(const MechanicalParams* mparams) const = 0; virtual void doAddMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) = 0; virtual void doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices); virtual void doInitGnuplot(const std::string path) = 0; @@ -80,10 +80,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor **/ /// f += factor M dx - virtual void addMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) final - { - doAddMDx(mparams, fid, factor); - } + virtual void addMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) final; /** * !!! WARNING since v25.12 !!! @@ -95,10 +92,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor **/ /// dx = M^-1 f - virtual void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) final - { - doAccFromF(mparams, aid); - } + virtual void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) final; /** * !!! WARNING since v25.12 !!! @@ -112,10 +106,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor /// \brief Perform v += dt*g operation. Used if mass wants to added G separately from the other forces to v. /// /// \param mparams \a sofa::core::mechanicalparams::dt(mparams) is the time step of for temporal discretization. - virtual void addGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) final - { - doAddGravityToV(mparams, vid); - } + virtual void addGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) final; /** * !!! WARNING since v25.12 !!! @@ -127,10 +118,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor **/ /// vMv/2 - virtual SReal getKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final - { - return doGetKineticEnergy(mparams); - } + virtual SReal getKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final; /** * !!! WARNING since v25.12 !!! @@ -142,10 +130,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor **/ /// Mgx - virtual SReal getPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final - { - return doGetPotentialEnergy(mparams); - } + virtual SReal getPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final; /** * !!! WARNING since v25.12 !!! @@ -157,10 +142,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor **/ /// (Mv,xMv+Iw) (linear and angular momenta against world origin) - virtual type::Vec6 getMomentum(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final - { - return doGetMomentum(mparams); - } + virtual type::Vec6 getMomentum(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final; /// @} @@ -181,10 +163,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor /// This method must be implemented by the component. /// \param matrix matrix to add the result to /// \param mparams \a mparams->mFactor() is the coefficient for mass contributions (i.e. second-order derivatives term in the ODE) - virtual void addMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) final - { - doAddMToMatrix(mparams, matrix); - } + virtual void addMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) final; /** * !!! WARNING since v25.12 !!! @@ -195,10 +174,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor * **/ - virtual void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) final - { - doBuildMassMatrix(matrices); - } + virtual void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) final; /// @} @@ -212,11 +188,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor **/ /// initialization to export kinetic and potential energy to gnuplot files format - virtual void initGnuplot(const std::string path) final - { - doInitGnuplot(path); - } - + virtual void initGnuplot(const std::string path) final; /** * !!! WARNING since v25.12 !!! @@ -228,10 +200,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor **/ /// export kinetic and potential energy state at "time" to a gnuplot file - virtual void exportGnuplot(const MechanicalParams* mparams, SReal time) final - { - doExportGnuplot(mparams, time); - } + virtual void exportGnuplot(const MechanicalParams* mparams, SReal time) final; /** * !!! WARNING since v25.12 !!! @@ -243,10 +212,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor **/ /// Get the mass relative to the DOF at \a index. - virtual SReal getElementMass(sofa::Index index) const final - { - return doGetElementMass(index); - } + virtual SReal getElementMass(sofa::Index index) const final; /** * !!! WARNING since v25.12 !!! @@ -258,10 +224,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor **/ /// Get the matrix relative to the DOF at \a index. - virtual void getElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const final - { - doGetElementMass(index, m); - } + virtual void getElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const final; virtual bool isDiagonal() const = 0; From 0894ff9139411b78c43a7b9f2b751e770c5c3343 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 14 May 2025 12:06:37 +0200 Subject: [PATCH 6/7] Fix compilation CUDA --- .../Component/src/SofaCUDA/component/mass/CudaUniformMass.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl index 617699b79b5..23b60031211 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl @@ -205,7 +205,7 @@ SReal UniformMass::getPotentialEnergy(const core::M } template <> -SReal UniformMass::getElementMass(sofa::Index) const +SReal UniformMass::doGetElementMass(sofa::Index) const { return (SReal)(d_vertexMass.getValue().mass); } From 742ab3703d675879a3151bc4a2730e02af358636 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Thu, 15 May 2025 16:04:08 +0200 Subject: [PATCH 7/7] fix CUDA compilation on doGetElementMass --- .../Component/src/SofaCUDA/component/mass/CudaUniformMass.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl index 23b60031211..ac27f18d80c 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl @@ -374,7 +374,7 @@ SReal UniformMass::getPotentialEnergy(const core::M } template <> -SReal UniformMass::getElementMass(sofa::Index) const +SReal UniformMass::doGetElementMass(sofa::Index) const { return (SReal)(d_vertexMass.getValue().mass); }