From 8c30ba8ef4419f7fa8565370dfd8000a504fc2c2 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 12 May 2025 18:11:59 +0200 Subject: [PATCH 01/18] [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 47c53f8f8b8..2f7f7d188d5 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h @@ -311,7 +311,7 @@ class DiagonalMass : public core::behavior::Mass /// 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 390b5cb70fe..4f0a9b04ff7 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl @@ -628,7 +628,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 e67680dbcb4..a6e4f23e04d 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h @@ -220,7 +220,7 @@ class MeshMatrixMass : public core::behavior::Mass /// 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/MeshMatrixMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl index c21e3b62d45..1e42d86aef8 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl @@ -2271,7 +2271,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 258eb345e10..64237904cba 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h @@ -148,7 +148,7 @@ class UniformMass : public core::behavior::Mass void addGravityToV(const core::MechanicalParams* mparams, DataVecDeriv& d_v) override; 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 13668956420..0dfd6ddcb28 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl @@ -573,7 +573,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 c802ed94c79..7b74b65413f 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) { @@ -62,7 +62,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) { @@ -98,7 +98,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())); @@ -114,7 +114,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())); @@ -130,7 +130,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) @@ -148,7 +148,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) @@ -158,11 +158,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 @@ -170,11 +166,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) { @@ -186,11 +182,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"; } @@ -211,10 +203,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 46aea633e64ebe7778792d51506ad27397a47028 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 12 May 2025 18:15:29 +0200 Subject: [PATCH 02/18] 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 d77c4268b53e9c6242a9e8671c10c12f9f6d76c6 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 12 May 2025 19:18:38 +0200 Subject: [PATCH 03/18] 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 1be30df6515224ca0395b74aa14c6bf4b53e7e22 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Mon, 12 May 2025 19:22:59 +0200 Subject: [PATCH 04/18] 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 2f7f7d188d5..68eb629de8d 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h @@ -315,8 +315,8 @@ class DiagonalMass : public core::behavior::Mass 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 4f0a9b04ff7..4de50b04985 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl @@ -642,7 +642,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]); } @@ -650,7 +650,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 a6e4f23e04d..12cb7445807 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h @@ -224,8 +224,8 @@ class MeshMatrixMass : public core::behavior::Mass 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 1e42d86aef8..61511eaca5e 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl @@ -2312,7 +2312,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; @@ -2323,7 +2323,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 64237904cba..031c50b7c25 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h @@ -152,8 +152,8 @@ class UniformMass : public core::behavior::Mass 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 0dfd6ddcb28..b7aa028d331 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl @@ -594,14 +594,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 968e72cd24e..dfd778972a5 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 7b74b65413f..caffaa4828e 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl @@ -187,7 +187,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()) { @@ -199,7 +199,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) { @@ -211,14 +211,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 ac64d77956ef83a53fbd33b5cc715116a63ebf26 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 13 May 2025 12:11:30 +0200 Subject: [PATCH 05/18] [Framework] Apply template method design pattern to BaseForceField - start with addForce --- .../Core/src/sofa/core/behavior/BaseForceField.h | 16 +++++++++++++++- .../Core/src/sofa/core/behavior/ForceField.h | 6 +++++- .../Core/src/sofa/core/behavior/ForceField.inl | 2 +- .../core/behavior/MixedInteractionForceField.h | 10 ++++++---- .../core/behavior/MixedInteractionForceField.inl | 2 +- .../core/behavior/PairInteractionForceField.h | 5 ++++- .../core/behavior/PairInteractionForceField.inl | 2 +- 7 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h index 63a704eb319..ec78417d83b 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h @@ -55,6 +55,8 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor BaseForceField(); ~BaseForceField() override = default; + virtual void doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) = 0; + private: BaseForceField(const BaseForceField& n) = delete; BaseForceField& operator=(const BaseForceField& n) = delete; @@ -64,6 +66,15 @@ class SOFA_CORE_API BaseForceField : 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 "doAddForce" internally, + * which is the method to override from now on. + * + **/ + /// \brief Given the current position and velocity states, update the current force /// vector by computing and adding the forces associated with this /// ForceField. @@ -85,7 +96,10 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// - if \a mparams->energy() is true, the method computes and internally stores the potential energy, /// which will be subsequently returned by method getPotentialEnergy() /// \param fId the output vector of forces - virtual void addForce(const MechanicalParams* mparams, MultiVecDerivId fId )=0; + virtual void addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) final + { + doAddForce(mparams, fId); + } /// \brief Compute the force derivative given a small displacement from the /// position and velocity used in the previous call to addForce(). diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h index 2af976c952c..e3bb452301e 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h @@ -55,6 +55,10 @@ class ForceField : public BaseForceField, public SingleStateAccessor typedef typename DataTypes::VecDeriv VecDeriv; typedef core::objectmodel::Data DataVecCoord; typedef core::objectmodel::Data DataVecDeriv; + + // Avoid warning : hidden [-Woverloaded-virtual=] + using BaseForceField::addForce; + protected: explicit ForceField(MechanicalState *mm = nullptr); @@ -74,7 +78,7 @@ class ForceField : public BaseForceField, public SingleStateAccessor /// This method retrieves the force, x and v vector from the MechanicalState /// and call the internal addForce(const MechanicalParams*, DataVecDeriv&,const DataVecCoord&,const DataVecDeriv&) /// method implemented by the component. - void addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) override; + void doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) override; /// Given the current position and velocity states, update the current force /// vector by computing and adding the forces associated with this diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl index 954567d348c..4839442987b 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl @@ -41,7 +41,7 @@ template ForceField::~ForceField() = default; template -void ForceField::addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) +void ForceField::doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) { auto mstate = this->mstate.get(); if (mparams && mstate) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h index 8d7ee120809..e82693fa858 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h @@ -61,6 +61,11 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair typedef core::objectmodel::Data DataVecCoord2; typedef core::objectmodel::Data DataVecDeriv2; + // Avoid warning : hidden [-Woverloaded-virtual=] + using BaseForceField::addForce; + using BaseInteractionForceField::getMechModel1; + using BaseInteractionForceField::getMechModel2; + protected: explicit MixedInteractionForceField(MechanicalState *mm1 = nullptr, MechanicalState *mm2 = nullptr); @@ -80,7 +85,7 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair /// This method retrieves the force, x and v vector from the two MechanicalState /// and call the internal addForce(VecDeriv&,VecDeriv&,const VecCoord&,const VecCoord&,const VecDeriv&,const VecDeriv&) /// method implemented by the component. - void addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) override; + void doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) override; /// Compute the force derivative given a small displacement from the /// position and velocity used in the previous call to addForce(). @@ -152,9 +157,6 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair sofa::helper::replaceAll(name, "ForceField", "FF"); return name; } - - using Inherit2::getMechModel1; - using Inherit2::getMechModel2; }; #if !defined(SOFA_CORE_BEHAVIOR_MIXEDINTERACTIONFORCEFIELD_CPP) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl index 8cbd487f143..efc34c77e15 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl @@ -43,7 +43,7 @@ MixedInteractionForceField::~MixedInteractionForceField( } template -void MixedInteractionForceField::addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) +void MixedInteractionForceField::doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) { if (this->mstate1 && this->mstate2) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h index 20db861a697..99368c0ebed 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h @@ -51,6 +51,9 @@ class PairInteractionForceField : public BaseInteractionForceField, public PairS typedef core::objectmodel::Data DataVecCoord; typedef core::objectmodel::Data DataVecDeriv; + // Avoid warning : hidden [-Woverloaded-virtual=] + using BaseForceField::addForce; + protected: explicit PairInteractionForceField(MechanicalState *mm1 = nullptr, MechanicalState *mm2 = nullptr); @@ -80,7 +83,7 @@ class PairInteractionForceField : public BaseInteractionForceField, public PairS /// This method retrieves the force, x and v vector from the two MechanicalState /// and call the internal addForce(VecDeriv&,VecDeriv&,const VecCoord&,const VecCoord&,const VecDeriv&,const VecDeriv&) /// method implemented by the component. - void addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) override; + void doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) override; /// Given the current position and velocity states, update the current force /// vector by computing and adding the forces associated with this diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl index 61e666c2e87..66015634424 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl @@ -46,7 +46,7 @@ PairInteractionForceField::~PairInteractionForceField() } template -void PairInteractionForceField::addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) +void PairInteractionForceField::doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) { auto state1 = this->mstate1.get(); auto state2 = this->mstate2.get(); From f53eec9da18d37c84ba5cf432aac8800d029da9b Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 13 May 2025 16:01:22 +0200 Subject: [PATCH 06/18] Apply pattern : addDForce --- .../Core/src/sofa/core/behavior/BaseForceField.h | 15 ++++++++++++++- .../Core/src/sofa/core/behavior/ForceField.h | 3 ++- .../Core/src/sofa/core/behavior/ForceField.inl | 2 +- .../core/behavior/MixedInteractionForceField.h | 2 +- .../core/behavior/MixedInteractionForceField.inl | 2 +- .../core/behavior/PairInteractionForceField.h | 3 ++- .../core/behavior/PairInteractionForceField.inl | 2 +- 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h index ec78417d83b..6a5b60e8267 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h @@ -56,6 +56,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor ~BaseForceField() override = default; virtual void doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) = 0; + virtual void doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) = 0; private: BaseForceField(const BaseForceField& n) = delete; @@ -101,6 +102,15 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor doAddForce(mparams, fId); } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doAddDForce" internally, + * which is the method to override from now on. + * + **/ + /// \brief Compute the force derivative given a small displacement from the /// position and velocity used in the previous call to addForce(). /// @@ -120,7 +130,10 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// - \a mparams->kFactor() is the coefficient for stiffness contributions (i.e. DOFs term in the ODE) /// - \a mparams->readDx() input vector /// \param dfId the output vector - virtual void addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId )=0; + virtual void addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) final + { + doAddDForce(mparams, dfId); + } /// \brief Accumulate the contribution of M, B, and/or K matrices multiplied /// by the dx vector with the given coefficients. diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h index e3bb452301e..7a55193557d 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h @@ -58,6 +58,7 @@ class ForceField : public BaseForceField, public SingleStateAccessor // Avoid warning : hidden [-Woverloaded-virtual=] using BaseForceField::addForce; + using BaseForceField::addDForce; protected: explicit ForceField(MechanicalState *mm = nullptr); @@ -103,7 +104,7 @@ class ForceField : public BaseForceField, public SingleStateAccessor /// This method retrieves the force and dx vector from the MechanicalState /// and call the internal addDForce(VecDeriv&,const VecDeriv&,SReal,SReal) /// method implemented by the component. - void addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) override; + void doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) override; /// Internal addDForce /// Overloaded function, usually called from the generic addDForce version. diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl index 4839442987b..a235e4fb7e7 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl @@ -51,7 +51,7 @@ void ForceField::doAddForce(const MechanicalParams* mparams, MultiVec } template -void ForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) +void ForceField::doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) { if (mparams && this->mstate) { diff --git a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h index e82693fa858..aec3181d317 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h @@ -100,7 +100,7 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair /// This method retrieves the force and dx vector from the two MechanicalState /// and call the internal addDForce(VecDeriv1&,VecDeriv2&,const VecDeriv1&,const VecDeriv2&,SReal,SReal) /// method implemented by the component. - void addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) override; + void doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) override; /// Get the potential energy associated to this ForceField. diff --git a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl index efc34c77e15..a04a2bdd26a 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl @@ -58,7 +58,7 @@ void MixedInteractionForceField::doAddForce(const Mechan } template -void MixedInteractionForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) +void MixedInteractionForceField::doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) { if (this->mstate1 && this->mstate2) { diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h index 99368c0ebed..cdc9e2bfa5b 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h @@ -53,6 +53,7 @@ class PairInteractionForceField : public BaseInteractionForceField, public PairS // Avoid warning : hidden [-Woverloaded-virtual=] using BaseForceField::addForce; + using BaseForceField::addDForce; protected: explicit PairInteractionForceField(MechanicalState *mm1 = nullptr, MechanicalState *mm2 = nullptr); @@ -111,7 +112,7 @@ class PairInteractionForceField : public BaseInteractionForceField, public PairS /// This method retrieves the force and dx vector from the two MechanicalState /// and call the internal addDForce(VecDeriv&,VecDeriv&,const VecDeriv&,const VecDeriv&,SReal,SReal) /// method implemented by the component. - void addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) override; + void doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) override; /// Compute the force derivative given a small displacement from the /// position and velocity used in the previous call to addForce(). diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl index 66015634424..8fdb362af70 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl @@ -61,7 +61,7 @@ void PairInteractionForceField::doAddForce(const MechanicalParams* mp } template -void PairInteractionForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) +void PairInteractionForceField::doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) { auto state1 = this->mstate1.get(); auto state2 = this->mstate2.get(); From a5d88465d346ef134b94bd1bca8c0fc49d3bf249 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 13 May 2025 22:16:01 +0200 Subject: [PATCH 07/18] Apply pattern : getPotentialEnergy --- .../TetrahedralTensorMassForceField.h | 8 ++----- .../TetrahedralTensorMassForceField.inl | 6 ++--- .../src/sofa/core/behavior/BaseForceField.h | 15 +++++++++++- .../Core/src/sofa/core/behavior/ForceField.h | 3 ++- .../src/sofa/core/behavior/ForceField.inl | 2 +- .../behavior/MixedInteractionForceField.h | 23 +++++++++++-------- .../behavior/MixedInteractionForceField.inl | 2 +- .../core/behavior/PairInteractionForceField.h | 3 ++- .../behavior/PairInteractionForceField.inl | 2 +- 9 files changed, 39 insertions(+), 25 deletions(-) diff --git a/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.h b/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.h index 8a02630cb23..bdc09f79105 100644 --- a/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.h +++ b/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.h @@ -109,16 +109,12 @@ class TetrahedralTensorMassForceField : public core::behavior::ForceField::initNeighbourhoodPoints() {} template -SReal TetrahedralTensorMassForceField::getPotentialEnergy(const core::MechanicalParams* /* mparams */) const +SReal TetrahedralTensorMassForceField::getPotentialEnergy(const sofa::core::MechanicalParams* mparams, const DataVecCoord& pos) const { SCOPED_TIMER("getPotentialEnergy"); + SOFA_UNUSED(mparams); - const VecCoord& x = this->mstate->read(core::vec_id::read_access::position)->getValue(); - + sofa::helper::ReadAccessor< Data< VecCoord > > x = pos; SReal energy=0; unsigned int v0,v1; diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h index 6a5b60e8267..e7393e1d54e 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h @@ -57,6 +57,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor virtual void doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) = 0; virtual void doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) = 0; + virtual SReal doGetPotentialEnergy( const MechanicalParams* mparams = mechanicalparams::defaultInstance() ) const = 0; private: BaseForceField(const BaseForceField& n) = delete; @@ -159,12 +160,24 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// \param dfId the output vector virtual void addMBKdx(const MechanicalParams* mparams, MultiVecDerivId dfId); + /** + * !!! 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. + * + **/ + /// \brief Get the potential energy associated to this ForceField during the /// last call of addForce( const MechanicalParams* mparams ); /// /// Used to estimate the total energy of the system by some /// post-stabilization techniques. - virtual SReal getPotentialEnergy( const MechanicalParams* mparams = mechanicalparams::defaultInstance() ) const=0; + virtual SReal getPotentialEnergy( const MechanicalParams* mparams = mechanicalparams::defaultInstance() ) const final + { + return doGetPotentialEnergy(mparams); + } /// @} diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h index 7a55193557d..953fa07fd4d 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h @@ -59,6 +59,7 @@ class ForceField : public BaseForceField, public SingleStateAccessor // Avoid warning : hidden [-Woverloaded-virtual=] using BaseForceField::addForce; using BaseForceField::addDForce; + using BaseForceField::getPotentialEnergy; protected: explicit ForceField(MechanicalState *mm = nullptr); @@ -129,7 +130,7 @@ class ForceField : public BaseForceField, public SingleStateAccessor /// /// This method must be implemented by the component, and is usually called /// by the generic ForceField::getPotentialEnergy(const MechanicalParams* mparams) method. - SReal getPotentialEnergy(const MechanicalParams* mparams) const override; + SReal doGetPotentialEnergy(const MechanicalParams* mparams) const override; virtual SReal getPotentialEnergy(const MechanicalParams* /*mparams*/, const DataVecCoord& x) const = 0; diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl index a235e4fb7e7..e54b45e91f7 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl @@ -77,7 +77,7 @@ void ForceField::doAddDForce(const MechanicalParams* mparams, MultiVe } template -SReal ForceField::getPotentialEnergy(const MechanicalParams* mparams) const +SReal ForceField::doGetPotentialEnergy(const MechanicalParams* mparams) const { if (this->mstate) return getPotentialEnergy(mparams, *mparams->readX(this->mstate.get())); diff --git a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h index aec3181d317..efe5d4f0c90 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h @@ -63,6 +63,8 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair // Avoid warning : hidden [-Woverloaded-virtual=] using BaseForceField::addForce; + using BaseForceField::addDForce; + using BaseForceField::getPotentialEnergy; using BaseInteractionForceField::getMechModel1; using BaseInteractionForceField::getMechModel2; @@ -103,16 +105,6 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair void doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) override; - /// Get the potential energy associated to this ForceField. - /// - /// Used to estimate the total energy of the system by some - /// post-stabilization techniques. - /// - /// This method retrieves the x vector from the MechanicalState and call - /// the internal getPotentialEnergy(const VecCoord&,const VecCoord&) method implemented by - /// the component. - SReal getPotentialEnergy(const MechanicalParams* mparams) const override; - /// Given the current position and velocity states, update the current force /// vector by computing and adding the forces associated with this /// ForceField. @@ -140,6 +132,17 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair virtual void addDForce(const MechanicalParams* mparams, DataVecDeriv1& df1, DataVecDeriv2& df2, const DataVecDeriv1& dx1, const DataVecDeriv2& dx2)=0; + + /// Get the potential energy associated to this ForceField. + /// + /// Used to estimate the total energy of the system by some + /// post-stabilization techniques. + /// + /// This method retrieves the x vector from the MechanicalState and call + /// the internal getPotentialEnergy(const VecCoord&,const VecCoord&) method implemented by + /// the component. + SReal doGetPotentialEnergy(const MechanicalParams* mparams) const override; + /// Get the potential energy associated to this ForceField. /// /// Used to estimate the total energy of the system by some diff --git a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl index a04a2bdd26a..24b8b555106 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl @@ -73,7 +73,7 @@ void MixedInteractionForceField::doAddDForce(const Mecha template -SReal MixedInteractionForceField::getPotentialEnergy(const MechanicalParams* mparams) const +SReal MixedInteractionForceField::doGetPotentialEnergy(const MechanicalParams* mparams) const { if (this->mstate1 && this->mstate2) return getPotentialEnergy(mparams, *mparams->readX(this->mstate1.get()),*mparams->readX(this->mstate2.get())); diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h index cdc9e2bfa5b..8ff1c8bc2fc 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h @@ -54,6 +54,7 @@ class PairInteractionForceField : public BaseInteractionForceField, public PairS // Avoid warning : hidden [-Woverloaded-virtual=] using BaseForceField::addForce; using BaseForceField::addDForce; + using BaseForceField::getPotentialEnergy; protected: explicit PairInteractionForceField(MechanicalState *mm1 = nullptr, MechanicalState *mm2 = nullptr); @@ -142,7 +143,7 @@ class PairInteractionForceField : public BaseInteractionForceField, public PairS /// This method retrieves the x vector from the MechanicalState and call /// the internal getPotentialEnergy(const VecCoord&,const VecCoord&) method implemented by /// the component. - SReal getPotentialEnergy(const MechanicalParams* mparams) const override; + SReal doGetPotentialEnergy(const MechanicalParams* mparams) const override; /// Get the potential energy associated to this ForceField. /// diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl index 8fdb362af70..5552c9573f8 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl @@ -76,7 +76,7 @@ void PairInteractionForceField::doAddDForce(const MechanicalParams* m } template -SReal PairInteractionForceField::getPotentialEnergy(const MechanicalParams* mparams) const +SReal PairInteractionForceField::doGetPotentialEnergy(const MechanicalParams* mparams) const { auto state1 = this->mstate1.get(); auto state2 = this->mstate2.get(); From ef76b8d689a9a2bd3d103b4801b29aebe5828fe5 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 14 May 2025 12:18:41 +0200 Subject: [PATCH 08/18] Move all functions in BaseForceField.cpp and add comment message --- .../src/sofa/core/behavior/BaseForceField.cpp | 18 ++++++++++++++++++ .../src/sofa/core/behavior/BaseForceField.h | 17 ++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp index 03f74235b4e..ad847a320ab 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp @@ -36,6 +36,24 @@ BaseForceField::BaseForceField() { } +void BaseForceField::addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doAddForce(mparams, fId); +} + +void BaseForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doAddDForce(mparams, dfId); +} + +SReal BaseForceField::getPotentialEnergy( const MechanicalParams* mparams = mechanicalparams::defaultInstance() ) const +{ + //TODO (SPRINT SED 2025): Component state mechanism + return doGetPotentialEnergy(mparams); +} + void BaseForceField::addMBKdx(const MechanicalParams* mparams, MultiVecDerivId dfId) { if (sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams,rayleighStiffness.getValue()) != 0.0 || sofa::core::mechanicalparams::bFactor(mparams) != 0.0) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h index e7393e1d54e..a3c643e9abe 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h @@ -57,7 +57,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor virtual void doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) = 0; virtual void doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) = 0; - virtual SReal doGetPotentialEnergy( const MechanicalParams* mparams = mechanicalparams::defaultInstance() ) const = 0; + virtual SReal doGetPotentialEnergy( const MechanicalParams* mparams ) const = 0; private: BaseForceField(const BaseForceField& n) = delete; @@ -98,10 +98,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// - if \a mparams->energy() is true, the method computes and internally stores the potential energy, /// which will be subsequently returned by method getPotentialEnergy() /// \param fId the output vector of forces - virtual void addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) final - { - doAddForce(mparams, fId); - } + virtual void addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) final; /** * !!! WARNING since v25.12 !!! @@ -131,10 +128,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// - \a mparams->kFactor() is the coefficient for stiffness contributions (i.e. DOFs term in the ODE) /// - \a mparams->readDx() input vector /// \param dfId the output vector - virtual void addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) final - { - doAddDForce(mparams, dfId); - } + virtual void addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) final; /// \brief Accumulate the contribution of M, B, and/or K matrices multiplied /// by the dx vector with the given coefficients. @@ -174,10 +168,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// /// Used to estimate the total energy of the system by some /// post-stabilization techniques. - virtual SReal getPotentialEnergy( const MechanicalParams* mparams = mechanicalparams::defaultInstance() ) const final - { - return doGetPotentialEnergy(mparams); - } + virtual SReal getPotentialEnergy( const MechanicalParams* mparams = mechanicalparams::defaultInstance() ) const final; /// @} From 24065fd34ed533ffe51f72ef229638a71cd3eaea Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Thu, 15 May 2025 14:53:27 +0200 Subject: [PATCH 09/18] continue but compilation of TrianglePressureForceField and SurfacePressureForceField fails in ForceFieldTestCreation --- .../contact/PenalityContactForceField.h | 5 +- .../contact/PenalityContactForceField.inl | 4 +- .../TetrahedronDiffusionFEMForceField.h | 6 +-- .../TetrahedronDiffusionFEMForceField.inl | 21 +++----- .../tests/MatrixLinearSystem_test.cpp | 2 +- .../src/sofa/component/mass/DiagonalMass.h | 4 +- .../src/sofa/component/mass/MeshMatrixMass.h | 4 +- .../src/sofa/component/mass/UniformMass.h | 4 +- .../mechanicalload/ConicalForceField.h | 7 +-- .../mechanicalload/ConicalForceField.inl | 4 +- .../mechanicalload/ConstantForceField.h | 12 +++-- .../mechanicalload/ConstantForceField.inl | 2 +- .../DiagonalVelocityDampingForceField.h | 4 +- .../DiagonalVelocityDampingForceField.inl | 4 +- .../mechanicalload/EdgePressureForceField.h | 4 +- .../mechanicalload/EdgePressureForceField.inl | 4 +- .../mechanicalload/EllipsoidForceField.h | 4 +- .../mechanicalload/EllipsoidForceField.inl | 4 +- .../InteractionEllipsoidForceField.h | 2 +- .../InteractionEllipsoidForceField.inl | 2 +- .../mechanicalload/LinearForceField.h | 4 +- .../mechanicalload/LinearForceField.inl | 4 +- .../OscillatingTorsionPressureForceField.h | 4 +- .../OscillatingTorsionPressureForceField.inl | 4 +- .../mechanicalload/PlaneForceField.h | 7 ++- .../mechanicalload/PlaneForceField.inl | 14 ++---- .../mechanicalload/QuadPressureForceField.h | 7 +-- .../mechanicalload/QuadPressureForceField.inl | 4 +- .../mechanicalload/SphereForceField.h | 4 +- .../mechanicalload/SphereForceField.inl | 4 +- .../SurfacePressureForceField.h | 6 +-- .../SurfacePressureForceField.inl | 13 ++--- .../TaitSurfacePressureForceField.h | 6 +-- .../TaitSurfacePressureForceField.inl | 6 +-- .../mechanicalload/TorsionForceField.h | 4 +- .../mechanicalload/TorsionForceField.inl | 4 +- .../TrianglePressureForceField.h | 4 +- .../TrianglePressureForceField.inl | 2 +- .../UniformVelocityDampingForceField.h | 2 +- .../UniformVelocityDampingForceField.inl | 2 +- .../fem/elastic/BeamFEMForceField.h | 4 +- .../fem/elastic/BeamFEMForceField.inl | 4 +- .../FastTetrahedralCorotationalForceField.h | 4 +- .../FastTetrahedralCorotationalForceField.inl | 4 +- .../fem/elastic/HexahedralFEMForceField.h | 4 +- .../fem/elastic/HexahedralFEMForceField.inl | 4 +- .../fem/elastic/HexahedronFEMForceField.h | 4 +- .../fem/elastic/HexahedronFEMForceField.inl | 2 +- .../elastic/HexahedronFEMForceFieldAndMass.h | 2 +- .../HexahedronFEMForceFieldAndMass.inl | 4 +- .../fem/elastic/QuadBendingFEMForceField.h | 4 +- .../fem/elastic/QuadBendingFEMForceField.inl | 4 +- .../TetrahedralCorotationalFEMForceField.h | 4 +- .../TetrahedralCorotationalFEMForceField.inl | 4 +- .../fem/elastic/TetrahedronFEMForceField.h | 4 +- .../fem/elastic/TetrahedronFEMForceField.inl | 4 +- .../fem/elastic/TriangleFEMForceField.h | 4 +- .../fem/elastic/TriangleFEMForceField.inl | 4 +- .../fem/elastic/TriangularFEMForceField.h | 4 +- .../fem/elastic/TriangularFEMForceField.inl | 4 +- .../elastic/TriangularFEMForceFieldOptim.h | 4 +- .../elastic/TriangularFEMForceFieldOptim.inl | 4 +- .../StandardTetrahedralFEMForceField.h | 4 +- .../StandardTetrahedralFEMForceField.inl | 4 +- .../TetrahedronHyperelasticityFEMForceField.h | 4 +- ...etrahedronHyperelasticityFEMForceField.inl | 4 +- .../spring/AngularSpringForceField.h | 6 +-- .../spring/AngularSpringForceField.inl | 6 +-- .../spring/FastTriangularBendingSprings.h | 4 +- .../spring/FastTriangularBendingSprings.inl | 4 +- .../spring/FrameSpringForceField.h | 2 +- .../spring/FrameSpringForceField.inl | 2 +- .../spring/GearSpringForceField.h | 2 +- .../spring/GearSpringForceField.inl | 2 +- .../spring/JointSpringForceField.h | 2 +- .../spring/JointSpringForceField.inl | 2 +- .../PolynomialRestShapeSpringsForceField.h | 6 +-- .../PolynomialRestShapeSpringsForceField.inl | 6 +-- .../spring/PolynomialSpringsForceField.h | 6 +-- .../spring/PolynomialSpringsForceField.inl | 6 +-- .../spring/QuadularBendingSprings.h | 4 +- .../spring/QuadularBendingSprings.inl | 4 +- .../spring/RestShapeSpringsForceField.h | 6 +-- .../spring/RestShapeSpringsForceField.inl | 6 +-- .../solidmechanics/spring/SpringForceField.h | 6 +-- .../spring/SpringForceField.inl | 6 +-- .../spring/TriangularBendingSprings.h | 4 +- .../spring/TriangularBendingSprings.inl | 4 +- .../TriangularBiquadraticSpringsForceField.h | 2 +- ...TriangularBiquadraticSpringsForceField.inl | 2 +- .../TriangularQuadraticSpringsForceField.h | 2 +- .../TriangularQuadraticSpringsForceField.inl | 2 +- .../spring/VectorSpringForceField.h | 2 +- .../spring/VectorSpringForceField.inl | 2 +- .../TetrahedralTensorMassForceField.h | 4 +- .../TetrahedralTensorMassForceField.inl | 4 +- .../TriangularTensorMassForceField.h | 2 +- .../TriangularTensorMassForceField.inl | 2 +- .../src/sofa/core/behavior/BaseForceField.cpp | 34 ++++++++++--- .../src/sofa/core/behavior/BaseForceField.h | 50 ++++++++++++++++--- .../core/behavior/BaseInteractionForceField.h | 3 +- .../Core/src/sofa/core/behavior/ForceField.h | 8 ++- .../src/sofa/core/behavior/ForceField.inl | 4 +- .../gpu/cuda/CudaHexahedronTLEDForceField.h | 4 +- .../gpu/cuda/CudaTetrahedronTLEDForceField.h | 4 +- .../contact/CudaPenalityContactForceField.h | 2 +- .../contact/CudaPenalityContactForceField.inl | 2 +- 107 files changed, 293 insertions(+), 246 deletions(-) diff --git a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.h b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.h index 1ad75539831..c0dd9465043 100644 --- a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.h +++ b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.h @@ -119,9 +119,10 @@ class PenalityContactForceField : public core::behavior::PairInteractionForceFie void addDForce(const sofa::core::MechanicalParams* mparams, DataVecDeriv& data_df1, DataVecDeriv& data_df2, const DataVecDeriv& data_dx1, const DataVecDeriv& data_dx2) override; void addKToMatrix(const sofa::core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const sofa::core::MechanicalParams*, const DataVecCoord&, const DataVecCoord& ) const override; diff --git a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.inl b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.inl index 3e68dcad433..16dcbad670a 100644 --- a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.inl +++ b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.inl @@ -200,7 +200,7 @@ void PenalityContactForceField::addKToMatrix(const sofa::core::Mechan } template -void PenalityContactForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void PenalityContactForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { const type::vector& cc = contacts.getValue(); @@ -257,7 +257,7 @@ void PenalityContactForceField::buildStiffnessMatrix(core::behavior:: } template -void PenalityContactForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void PenalityContactForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.h b/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.h index 7b2afa1a710..636ca351352 100644 --- a/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.h +++ b/Sofa/Component/Diffusion/src/sofa/component/diffusion/TetrahedronDiffusionFEMForceField.h @@ -73,10 +73,10 @@ class TetrahedronDiffusionFEMForceField : public core::behavior::ForceField::addDForce(const sofa::core::M template -void TetrahedronDiffusionFEMForceField::addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void TetrahedronDiffusionFEMForceField::addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFactor, unsigned int &offset) { SCOPED_TIMER("addKToMatrix"); const auto N = defaulttype::DataTypeInfo::size(); - sofa::core::behavior::MultiMatrixAccessor::MatrixRef r = matrix->getMatrix(this->mstate); - sofa::linearalgebra::BaseMatrix* mat = r.matrix; - if((sofa::Size)(mat->colSize()) != (m_topology->getNbPoints()*N) || (sofa::Size)(mat->rowSize()) != (m_topology->getNbPoints()*N)) + if((sofa::Size)(matrix->colSize()) != (m_topology->getNbPoints()*N) || (sofa::Size)(matrix->rowSize()) != (m_topology->getNbPoints()*N)) { msg_error()<<"Wrong size of the input Matrix: need resize in addKToMatrix function."; - mat->resize(m_topology->getNbPoints()*N,m_topology->getNbPoints()*N); + matrix->resize(m_topology->getNbPoints()*N,m_topology->getNbPoints()*N); } - Real kFactor = mparams->kFactor(); - unsigned int &offset = r.offset; - sofa::Index v0,v1; const auto& edges = m_topology->getEdges(); @@ -381,15 +376,15 @@ void TetrahedronDiffusionFEMForceField::addKToMatrix(const core::Mech v0 = edges[i][0]; v1 = edges[i][1]; - mat->add(offset+N*v1, offset+N*v0, -kFactor * edgeDiffusionCoefficient[i]); - mat->add(offset+N*v0, offset+N*v1, -kFactor * edgeDiffusionCoefficient[i]); - mat->add(offset+N*v0, offset+N*v0, kFactor * edgeDiffusionCoefficient[i]); - mat->add(offset+N*v1, offset+N*v1, kFactor * edgeDiffusionCoefficient[i]); + matrix->add(offset+N*v1, offset+N*v0, -kFactor * edgeDiffusionCoefficient[i]); + matrix->add(offset+N*v0, offset+N*v1, -kFactor * edgeDiffusionCoefficient[i]); + matrix->add(offset+N*v0, offset+N*v0, kFactor * edgeDiffusionCoefficient[i]); + matrix->add(offset+N*v1, offset+N*v1, kFactor * edgeDiffusionCoefficient[i]); } } template -void TetrahedronDiffusionFEMForceField::buildStiffnessMatrix( +void TetrahedronDiffusionFEMForceField::doBuildStiffnessMatrix( core::behavior::StiffnessMatrix* matrix) { constexpr auto N = DataTypes::deriv_total_size; diff --git a/Sofa/Component/LinearSystem/tests/MatrixLinearSystem_test.cpp b/Sofa/Component/LinearSystem/tests/MatrixLinearSystem_test.cpp index c8163bfdb3d..c1c6c44c78c 100644 --- a/Sofa/Component/LinearSystem/tests/MatrixLinearSystem_test.cpp +++ b/Sofa/Component/LinearSystem/tests/MatrixLinearSystem_test.cpp @@ -244,7 +244,7 @@ template public: SOFA_CLASS(BuggyForceField, sofa::core::behavior::ForceField); - void buildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) override + void doBuildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) override { auto dfdx = matrix->getForceDerivativeIn(this->mstate).withRespectToPositionsIn(this->mstate); dfdx(10, 20) += 0.; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h index 68eb629de8d..43f000ef1ac 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h @@ -312,8 +312,8 @@ class DiagonalMass : public core::behavior::Mass /// Add Mass contribution to global Matrix assembling void addMToMatrix(sofa::linearalgebra::BaseMatrix * mat, SReal mFact, unsigned int &offset) override; void doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} - void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} + void doBuildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} SReal doGetElementMass(sofa::Index index) const override; void doGetElementMass(sofa::Index, linearalgebra::BaseMatrix *m) const override; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h index 12cb7445807..358b707dc2b 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h @@ -221,8 +221,8 @@ class MeshMatrixMass : public core::behavior::Mass /// Add Mass contribution to global Matrix assembling void addMToMatrix(sofa::linearalgebra::BaseMatrix * mat, SReal mFact, unsigned int &offset) override; void doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} - void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} + void doBuildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} SReal doGetElementMass(Index index) const override; void doGetElementMass(Index index, linearalgebra::BaseMatrix *m) const override; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h index 031c50b7c25..e0f10a12a22 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h @@ -149,8 +149,8 @@ class UniformMass : public core::behavior::Mass void addMToMatrix(sofa::linearalgebra::BaseMatrix * mat, SReal mFact, unsigned int &offset) override; /// Add Mass contribution to global Matrix assembling void doBuildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} - void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* /* matrix */) override {} + void doBuildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} SReal doGetElementMass(sofa::Index index) const override; void doGetElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConicalForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConicalForceField.h index 849d0e80b48..0978f031df2 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConicalForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConicalForceField.h @@ -105,14 +105,15 @@ class ConicalForceField : public core::behavior::ForceField void addForce(const sofa::core::MechanicalParams* /*mparams*/, DataVecDeriv & dataF, const DataVecCoord & dataX , const DataVecDeriv & dataV ) override; void addDForce(const sofa::core::MechanicalParams* /*mparams*/, DataVecDeriv& datadF , const DataVecDeriv& datadX ) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override { msg_warning() << "Method getPotentialEnergy not implemented yet."; return 0.0; } - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; - + virtual void updateStiffness( const VecCoord& x ); virtual bool isIn(Coord p); diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConicalForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConicalForceField.inl index 82be58c1f99..e104a662621 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConicalForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConicalForceField.inl @@ -157,7 +157,7 @@ void ConicalForceField::addDForce(const sofa::core::MechanicalParams* } template -void ConicalForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void ConicalForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { auto dfdx = matrix->getForceDerivativeIn(this->mstate) .withRespectToPositionsIn(this->mstate); @@ -174,7 +174,7 @@ void ConicalForceField::buildStiffnessMatrix(core::behavior::Stiffnes } template -void ConicalForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void ConicalForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConstantForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConstantForceField.h index d50ec09b740..a4c0b9f226b 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConstantForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConstantForceField.h @@ -85,8 +85,13 @@ class ConstantForceField : public core::behavior::ForceField /// Constant force has null variation virtual void addKToMatrix(const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/, SReal /*kFact*/) ; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final + { + // No damping in this ForceField + } + SReal getPotentialEnergy(const core::MechanicalParams* params, const DataVecCoord& x) const override; void draw(const core::visual::VisualParams* vparams) override; @@ -97,10 +102,7 @@ class ConstantForceField : public core::behavior::ForceField using Inherit::addAlias ; using Inherit::addKToMatrix; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final - { - // No damping in this ForceField - } + protected: diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConstantForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConstantForceField.inl index c9b1b4db71c..391ea4a3324 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConstantForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/ConstantForceField.inl @@ -443,7 +443,7 @@ void ConstantForceField::addKToMatrix(const sofa::core::behavior::Mul } template -void ConstantForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void ConstantForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { SOFA_UNUSED(matrix); } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/DiagonalVelocityDampingForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/DiagonalVelocityDampingForceField.h index 997a8330f9b..e425fe87f6d 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/DiagonalVelocityDampingForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/DiagonalVelocityDampingForceField.h @@ -58,10 +58,10 @@ class DiagonalVelocityDampingForceField : public core::behavior::ForceField::addDForce(const core::Mechani } template -void DiagonalVelocityDampingForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix*) +void DiagonalVelocityDampingForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix*) { // DiagonalVelocityDampingForceField is a pure damping component: stiffness is not computed } @@ -126,7 +126,7 @@ void DiagonalVelocityDampingForceField::addBToMatrix(sofa::linearalge } template -void DiagonalVelocityDampingForceField::buildDampingMatrix(core::behavior::DampingMatrix* matrix) +void DiagonalVelocityDampingForceField::doBuildDampingMatrix(core::behavior::DampingMatrix* matrix) { const auto& coefs = d_dampingCoefficients.getValue(); const std::size_t nbDampingCoeff = coefs.size(); diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EdgePressureForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EdgePressureForceField.h index c7710f0f137..d14095622b5 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EdgePressureForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EdgePressureForceField.h @@ -114,8 +114,8 @@ class EdgePressureForceField : public core::behavior::ForceField void setNormal(const Coord n) { d_normal.setValue(n);} void setPressure(Deriv _pressure) { this->d_pressure = _pressure; updateEdgeInformation(); } - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) final; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; protected : void selectEdgesAlongPlane(); diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EdgePressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EdgePressureForceField.inl index 8bb637ecb6b..004a7a8f15a 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EdgePressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EdgePressureForceField.inl @@ -317,13 +317,13 @@ void EdgePressureForceField::updateEdgeInformation() } template -void EdgePressureForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix*) +void EdgePressureForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix*) { // No stiffness in this ForceField } template -void EdgePressureForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void EdgePressureForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EllipsoidForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EllipsoidForceField.h index 3f8fffe9e93..2a41ed47814 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EllipsoidForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EllipsoidForceField.h @@ -105,8 +105,8 @@ class EllipsoidForceField : public core::behavior::ForceField void addDForce(const sofa::core::MechanicalParams* /*mparams*/, DataVecDeriv& datadF , const DataVecDeriv& datadX ) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EllipsoidForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EllipsoidForceField.inl index 49c6a8c2527..8a9fdc26346 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EllipsoidForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/EllipsoidForceField.inl @@ -165,7 +165,7 @@ void EllipsoidForceField::addDForce(const sofa::core::MechanicalParam } template -void EllipsoidForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void EllipsoidForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { auto dfdx = matrix->getForceDerivativeIn(this->mstate) .withRespectToPositionsIn(this->mstate); @@ -178,7 +178,7 @@ void EllipsoidForceField::buildStiffnessMatrix(core::behavior::Stiffn } template -void EllipsoidForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void EllipsoidForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.h index 0a9cccd4b7b..30beae528c8 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.h @@ -146,7 +146,7 @@ class InteractionEllipsoidForceField : public core::behavior::MixedInteractionFo SReal getPotentialEnergy(const sofa::core::MechanicalParams* mparams, const DataVecCoord1& x1, const DataVecCoord2& x2)const override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; void init() override; void reinit() override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.inl index c9af483eb15..88eabe19d06 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/InteractionEllipsoidForceField.inl @@ -358,7 +358,7 @@ SReal InteractionEllipsoidForceField::getPotentialEnergy } template -void InteractionEllipsoidForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void InteractionEllipsoidForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/LinearForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/LinearForceField.h index fc522be67de..fb233a6b99f 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/LinearForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/LinearForceField.h @@ -108,9 +108,9 @@ class LinearForceField : public core::behavior::ForceField void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* mparams, const DataVecCoord& x) const override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/LinearForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/LinearForceField.inl index f95f33738e1..66a12991f25 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/LinearForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/LinearForceField.inl @@ -183,13 +183,13 @@ void LinearForceField::addKToMatrix(linearalgebra::BaseMatrix* matrix } template -void LinearForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void LinearForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } template -void LinearForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void LinearForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { SOFA_UNUSED(matrix); } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/OscillatingTorsionPressureForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/OscillatingTorsionPressureForceField.h index 5524e63b383..67aa4417899 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/OscillatingTorsionPressureForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/OscillatingTorsionPressureForceField.h @@ -102,8 +102,8 @@ class OscillatingTorsionPressureForceField : public core::behavior::ForceField::getPotentialEnergy(const } template -void OscillatingTorsionPressureForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix*) +void OscillatingTorsionPressureForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix*) { } template -void OscillatingTorsionPressureForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void OscillatingTorsionPressureForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.h index 4114be3b96e..c2be371c931 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.h @@ -112,10 +112,9 @@ class PlaneForceField : public core::behavior::ForceField SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override; virtual void updateStiffness( const VecCoord& x ); - void addKToMatrix(const core::MechanicalParams* - mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) override; - void buildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override; + void doBuildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; void draw(const core::visual::VisualParams* vparams) override; void drawPlane(const core::visual::VisualParams*, float size=0.0f); diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.inl index 568531feee8..a2d56f62c33 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/PlaneForceField.inl @@ -226,17 +226,13 @@ void PlaneForceField::addDForce(const core::MechanicalParams* mparams } template -void PlaneForceField::addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) +void PlaneForceField::addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) { if(this->d_componentState.getValue() != ComponentState::Valid) return ; - const Real fact = (Real)(-this->d_stiffness.getValue()*sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams, this->rayleighStiffness.getValue())); Deriv normal; DataTypes::setDPos(normal, d_planeNormal.getValue()); - const sofa::core::behavior::MultiMatrixAccessor::MatrixRef mref = matrix->getMatrix(this->mstate); - sofa::linearalgebra::BaseMatrix* mat = mref.matrix; - unsigned int offset = mref.offset; for (unsigned int i=0; im_contacts.size(); i++) { @@ -244,14 +240,14 @@ void PlaneForceField::addKToMatrix(const core::MechanicalParams* mpar for (sofa::Index l=0; ladd(offset + p*Deriv::total_size + l, offset + p*Deriv::total_size + c, coef); + SReal coef = normal[l] * kFact * normal[c]; + matrix->add(offset + p*Deriv::total_size + l, offset + p*Deriv::total_size + c, coef); } } } template -void PlaneForceField::buildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) +void PlaneForceField::doBuildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) { if (!this->isComponentStateValid()) { @@ -273,7 +269,7 @@ void PlaneForceField::buildStiffnessMatrix(sofa::core::behavior::Stif } template -void PlaneForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void PlaneForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.h index 5880a219c41..0cd5132fb76 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.h @@ -112,11 +112,8 @@ class QuadPressureForceField : public core::behavior::ForceField /// Constant pressure has null variation void addKToMatrix(sofa::linearalgebra::BaseMatrix * /*m*/, SReal /*kFactor*/, unsigned int & /*offset*/) override {} - /// Constant pressure has null variation - void addKToMatrix(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/ ) override {} - - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* /*matrix*/) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* /*matrix*/) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override { msg_warning() << "Method getPotentialEnergy not implemented yet."; return 0.0; } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.inl index 0b869038c8c..fa00dce0d3d 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.inl @@ -220,14 +220,14 @@ bool QuadPressureForceField::isPointInPlane(Coord p) } template -void QuadPressureForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* ) +void QuadPressureForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* ) { // force does not depend on the position, so the derivative with respect // to position is null => stiffness matrix is null } template -void QuadPressureForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void QuadPressureForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SphereForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SphereForceField.h index abe3cff4ec4..bcb458b1a1c 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SphereForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SphereForceField.h @@ -109,8 +109,8 @@ class SphereForceField : public core::behavior::ForceField void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx) override; SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override; virtual void updateStiffness( const VecCoord& x ); - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; void addKToMatrix(sofa::linearalgebra::BaseMatrix *, SReal, unsigned int &) override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SphereForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SphereForceField.inl index b9599ff4f5f..01ce2c684e3 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SphereForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SphereForceField.inl @@ -180,7 +180,7 @@ void SphereForceField::updateStiffness( const VecCoord& x ) } template -void SphereForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void SphereForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { const Real fact = (Real)(-this->d_stiffness.getValue()); @@ -202,7 +202,7 @@ void SphereForceField::buildStiffnessMatrix(core::behavior::Stiffness } template -void SphereForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void SphereForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.h index e866cd70f32..5b90323d04e 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.h @@ -100,9 +100,9 @@ class SurfacePressureForceField : public core::behavior::ForceField void addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v) override; void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& /* d_df */, const DataVecDeriv& /* d_dx */) override; - void addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.inl index 95a4026e256..d38a2fe4fa6 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.inl @@ -237,13 +237,8 @@ void SurfacePressureForceField::addDForce(const core::MechanicalParam template -void SurfacePressureForceField::addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void SurfacePressureForceField::addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) { - const sofa::core::behavior::MultiMatrixAccessor::MatrixRef mref = matrix->getMatrix(this->mstate); - sofa::linearalgebra::BaseMatrix* mat = mref.matrix; - unsigned int offset = mref.offset; - Real kFact = (Real)sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams, this->rayleighStiffness.getValue()); - const int N = Coord::total_size; if (d_useTangentStiffness.getValue()) { @@ -258,7 +253,7 @@ void SurfacePressureForceField::addKToMatrix(const core::MechanicalPa { for (unsigned int c = 0; c < 3; c++) { - mat->add(offset + N * i + l, offset + N * v + c, kFact * Kiv[l][c]); + matrix->add(offset + N * i + l, offset + N * v + c, kFact * Kiv[l][c]); } } } @@ -267,7 +262,7 @@ void SurfacePressureForceField::addKToMatrix(const core::MechanicalPa } template -void SurfacePressureForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void SurfacePressureForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { if (d_useTangentStiffness.getValue()) { @@ -290,7 +285,7 @@ void SurfacePressureForceField::buildStiffnessMatrix(core::behavior:: } template -void SurfacePressureForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void SurfacePressureForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.h index 9620bb0272d..e1801974d8f 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.h @@ -105,12 +105,12 @@ class TaitSurfacePressureForceField : public core::behavior::ForceField void addKToMatrixT(const core::MechanicalParams* mparams, MatrixWriter mwriter); - void buildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.inl index e2fd21f2716..11344113976 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TaitSurfacePressureForceField.inl @@ -318,7 +318,7 @@ void TaitSurfacePressureForceField::addDForce(const core::MechanicalP } template -void TaitSurfacePressureForceField::addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) +void TaitSurfacePressureForceField::doAddKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) { core::behavior::BlocMatrixWriter writer; writer.addKToMatrix(this, mparams, matrix->getMatrix(this->mstate)); @@ -398,7 +398,7 @@ void TaitSurfacePressureForceField::addKToMatrixT(const core::Mechani } template -void TaitSurfacePressureForceField::buildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) +void TaitSurfacePressureForceField::doBuildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) { const auto mstateSize = this->mstate->getSize(); const helper::ReadAccessor< Data< SeqTriangles > > pressureTriangles = d_pressureTriangles; @@ -456,7 +456,7 @@ void TaitSurfacePressureForceField::buildStiffnessMatrix(sofa::core:: } template -void TaitSurfacePressureForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TaitSurfacePressureForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TorsionForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TorsionForceField.h index f1ac77d5e8b..6d0e68dbbb6 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TorsionForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TorsionForceField.h @@ -76,8 +76,8 @@ class TorsionForceField : public ForceField void addForce(const MechanicalParams *, DataVecDeriv &f, const DataVecCoord &x, const DataVecDeriv &v) override; void addDForce(const MechanicalParams *mparams, DataVecDeriv &df, const DataVecDeriv &dx) override; void addKToMatrix(linearalgebra::BaseMatrix *matrix, SReal kFact, unsigned int &offset) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TorsionForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TorsionForceField.inl index b3e092cf8cb..137a27f3bbc 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TorsionForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TorsionForceField.inl @@ -121,7 +121,7 @@ void TorsionForceField::addKToMatrix(linearalgebra::BaseMatrix* matri } template -void TorsionForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void TorsionForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { auto dfdx = matrix->getForceDerivativeIn(this->mstate) .withRespectToPositionsIn(this->mstate); @@ -143,7 +143,7 @@ void TorsionForceField::buildStiffnessMatrix(core::behavior::Stiffnes } template -void TorsionForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TorsionForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.h index 666841cbb07..300245fa93b 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.h @@ -117,9 +117,9 @@ class TrianglePressureForceField : public core::behavior::ForceField void addKToMatrix(sofa::linearalgebra::BaseMatrix * /*m*/, SReal /*kFactor*/, unsigned int & /*offset*/) override {} /// Constant pressure has null variation - void addKToMatrix(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/ ) override {} + void doAddKToMatrix(const core::MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/ ) override {} - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.inl b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.inl index a21fdac2882..63efc489d38 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.inl +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.inl @@ -229,7 +229,7 @@ void TrianglePressureForceField::draw(const core::visual::VisualParam } template -void TrianglePressureForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TrianglePressureForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/UniformVelocityDampingForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/UniformVelocityDampingForceField.h index 70ae8848ef6..8abafcf7f43 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/UniformVelocityDampingForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/UniformVelocityDampingForceField.h @@ -63,7 +63,7 @@ class UniformVelocityDampingForceField : public core::behavior::ForceField::addBToMatrix(sofa::linearalgeb } template -void UniformVelocityDampingForceField::buildDampingMatrix(core::behavior::DampingMatrix* matrix) +void UniformVelocityDampingForceField::doBuildDampingMatrix(core::behavior::DampingMatrix* matrix) { if( !d_implicit.getValue() ) return; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.h index 24cd94323d4..9cdc7e2cb46 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.h @@ -167,8 +167,8 @@ class BeamFEMForceField : public BaseLinearElasticityFEMForceField void addForce(const MechanicalParams* mparams, DataVecDeriv & dataF, const DataVecCoord & dataX , const DataVecDeriv & dataV ) override; void addDForce(const MechanicalParams* mparams, DataVecDeriv& datadF , const DataVecDeriv& datadX ) override; void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const MechanicalParams* mparams, const DataVecCoord& x) const override; void draw(const core::visual::VisualParams* vparams) override; void computeBBox(const core::ExecParams* params, bool onlyVisible) override; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.inl index b9def063f0f..de2668168eb 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/BeamFEMForceField.inl @@ -578,7 +578,7 @@ void BeamFEMForceField::addKToMatrix(sofa::linearalgebra::BaseMatrix } template -void BeamFEMForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void BeamFEMForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { auto dfdx = matrix->getForceDerivativeIn(this->mstate) .withRespectToPositionsIn(this->mstate); @@ -678,7 +678,7 @@ void BeamFEMForceField::buildStiffnessMatrix(core::behavior::Stiffnes } template -void BeamFEMForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void BeamFEMForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FastTetrahedralCorotationalForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FastTetrahedralCorotationalForceField.h index 770ea885bd2..dcf1e2d4e60 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FastTetrahedralCorotationalForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FastTetrahedralCorotationalForceField.h @@ -149,8 +149,8 @@ class FastTetrahedralCorotationalForceField : public BaseLinearElasticityFEMForc using Inherit1::addKToMatrix; void addKToMatrix(sofa::linearalgebra::BaseMatrix *m, SReal kFactor, unsigned int &offset) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* matrix) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* matrix) override; void updateTopologyInformation(); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FastTetrahedralCorotationalForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FastTetrahedralCorotationalForceField.inl index 1f90de5e5d4..bd3db60290d 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FastTetrahedralCorotationalForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/FastTetrahedralCorotationalForceField.inl @@ -466,7 +466,7 @@ void FastTetrahedralCorotationalForceField::addDForce(const sofa::cor } template -void FastTetrahedralCorotationalForceField::buildStiffnessMatrix( +void FastTetrahedralCorotationalForceField::doBuildStiffnessMatrix( core::behavior::StiffnessMatrix* matrix) { const sofa::Size nbEdges = this->l_topology->getNbEdges(); @@ -554,7 +554,7 @@ void FastTetrahedralCorotationalForceField::buildStiffnessMatrix( } template -void FastTetrahedralCorotationalForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void FastTetrahedralCorotationalForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.h index 27af165194a..7cc8efba877 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.h @@ -153,9 +153,9 @@ class HexahedralFEMForceField : virtual public BaseLinearElasticityFEMForceField } void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.inl index 8cc000680a6..e116a494933 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceField.inl @@ -613,7 +613,7 @@ void HexahedralFEMForceField::addKToMatrix(sofa::linearalgebra::BaseM } template -void HexahedralFEMForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void HexahedralFEMForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { const type::vector& hexahedronInf = d_hexahedronInfo.getValue(); @@ -646,7 +646,7 @@ void HexahedralFEMForceField::buildStiffnessMatrix(core::behavior::St } } template -void HexahedralFEMForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void HexahedralFEMForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.h index 9bed7b8db99..7e20c5f2156 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.h @@ -144,8 +144,8 @@ class HexahedronFEMForceField : virtual public BaseLinearElasticityFEMForceField using Inherit1::addKToMatrix; void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /* matrices */) override {} void computeBBox(const core::ExecParams* params, bool onlyVisible) override; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl index c19f55ab44a..2ee44b4b3d5 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedronFEMForceField.inl @@ -1146,7 +1146,7 @@ void HexahedronFEMForceField::addKToMatrix(sofa::linearalgebra::BaseM } template -void HexahedronFEMForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void HexahedronFEMForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { sofa::Index e { 0 }; //index of the element in the topology 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 f75b482a5f9..0f04fc1f8df 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 @@ -84,7 +84,7 @@ class HexahedronFEMForceFieldAndMass : virtual public core::behavior::Mass::addMToMatrix(sofa::linearalgebra } template -void HexahedronFEMForceFieldAndMass::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void HexahedronFEMForceFieldAndMass::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { - HexahedronFEMForceFieldT::buildStiffnessMatrix(matrix); + HexahedronFEMForceFieldT::doBuildStiffnessMatrix(matrix); } template diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.h index 088ac6811f5..2da89185f69 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.h @@ -86,8 +86,8 @@ class QuadBendingFEMForceField : public core::behavior::ForceField void reinit() override; void addForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override; void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& df, const DataVecDeriv& dx) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* mparams, const DataVecCoord& x) const override; /// Class to store FEM information on each quad, for topology modification handling class QuadInformation diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.inl index 018f6e0805c..c1c32bbcd89 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/QuadBendingFEMForceField.inl @@ -713,7 +713,7 @@ void QuadBendingFEMForceField::addDForce(const core::MechanicalParams } template -void QuadBendingFEMForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void QuadBendingFEMForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { static constexpr auto N = Deriv::total_size; auto dfdx = matrix->getForceDerivativeIn(this->mstate) @@ -742,7 +742,7 @@ void QuadBendingFEMForceField::buildStiffnessMatrix(core::behavior::S } template -void QuadBendingFEMForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void QuadBendingFEMForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.h index bb48014af31..b58bcaef440 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.h @@ -191,9 +191,9 @@ class TetrahedralCorotationalFEMForceField : public BaseLinearElasticityFEMForce } void addKToMatrix(sofa::linearalgebra::BaseMatrix *m, SReal kFactor, unsigned int &offset) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; // Getting the rotation of the vertex by averaing the rotation of neighboring elements void getRotation(Transformation& R, Index nodeIdx); diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.inl index 224fd673b60..6a629bf1cd1 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedralCorotationalFEMForceField.inl @@ -1444,7 +1444,7 @@ void TetrahedralCorotationalFEMForceField::addKToMatrix(sofa::lineara } template -void TetrahedralCorotationalFEMForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void TetrahedralCorotationalFEMForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { StiffnessMatrix JKJt, RJKJtRt; sofa::type::Mat<3, 3, Real> localMatrix(type::NOINIT); @@ -1482,7 +1482,7 @@ void TetrahedralCorotationalFEMForceField::buildStiffnessMatrix(core: } } template -void TetrahedralCorotationalFEMForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TetrahedralCorotationalFEMForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.h index 809e330aaed..366865fdaca 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TetrahedronFEMForceField.h @@ -279,8 +279,8 @@ class TetrahedronFEMForceField : public BaseLinearElasticityFEMForceField::addKToMatrix(sofa::linearalgebra::Base } template -void TetrahedronFEMForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void TetrahedronFEMForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { StiffnessMatrix JKJt, RJKJtRt; sofa::type::Mat<3, 3, Real> localMatrix(type::NOINIT); @@ -2014,7 +2014,7 @@ void TetrahedronFEMForceField::buildStiffnessMatrix(core::behavior::S } template -void TetrahedronFEMForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TetrahedronFEMForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangleFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangleFEMForceField.h index b17f79a837b..b208439c6c7 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangleFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangleFEMForceField.h @@ -102,8 +102,8 @@ class TriangleFEMForceField : public BaseLinearElasticityFEMForceField::addKToMatrix(sofa::linearalgebra::BaseMat } template -void TriangleFEMForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void TriangleFEMForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { StiffnessMatrix JKJt, RJKJtRt; sofa::type::Mat<3, 3, Real> localMatrix(type::NOINIT); @@ -655,7 +655,7 @@ void TriangleFEMForceField::buildStiffnessMatrix(core::behavior::Stif } template -void TriangleFEMForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TriangleFEMForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceField.h index cd4b126c66c..fbac2dbbacc 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceField.h @@ -105,12 +105,12 @@ class TriangularFEMForceField : public BaseLinearElasticityFEMForceField& S, type::Mat<9, 9, Real>& SR, const MaterialStiffness& K, const StrainDisplacement& J, const Transformation& Rot); void addKToMatrix(sofa::linearalgebra::BaseMatrix *mat, SReal k, unsigned int &offset) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceField.inl index 1b5b2040195..099f67acc18 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceField.inl @@ -388,7 +388,7 @@ void TriangularFEMForceField::addKToMatrix(sofa::linearalgebra::BaseM } template -void TriangularFEMForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void TriangularFEMForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { type::Mat<9, 9, Real> JKJt, RJKJtRt; sofa::type::Mat<3, 3, Real> localMatrix(type::NOINIT); @@ -1199,7 +1199,7 @@ void TriangularFEMForceField::addDForce(const core::MechanicalParams* } template -void TriangularFEMForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TriangularFEMForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceFieldOptim.h b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceFieldOptim.h index 23ea6aa0a20..1161c96a05c 100644 --- a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceFieldOptim.h +++ b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/TriangularFEMForceFieldOptim.h @@ -105,8 +105,8 @@ class TriangularFEMForceFieldOptim : public BaseLinearElasticityFEMForceField::addKToMatrix(sofa::linearalgebra:: } template -void TriangularFEMForceFieldOptim::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void TriangularFEMForceFieldOptim::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { auto dfdx = matrix->getForceDerivativeIn(this->mstate) .withRespectToPositionsIn(this->mstate); @@ -537,7 +537,7 @@ void TriangularFEMForceFieldOptim::buildStiffnessMatrix(core::behavio } template -void TriangularFEMForceFieldOptim::buildDampingMatrix(core::behavior::DampingMatrix*) +void TriangularFEMForceFieldOptim::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.h index fc111a7b248..7bf4f495cc2 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.h @@ -184,8 +184,8 @@ public : msg_warning() << "Method getPotentialEnergy not implemented yet."; return 0.0; } - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.inl index ed8d2eaafd7..d7ed381e243 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/StandardTetrahedralFEMForceField.inl @@ -564,7 +564,7 @@ void StandardTetrahedralFEMForceField::addKToMatrix(sofa::linearalge } template -void StandardTetrahedralFEMForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void StandardTetrahedralFEMForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { const sofa::Size nbEdges = m_topology->getNbEdges(); const type::vector< Edge>& edgeArray=m_topology->getEdges(); @@ -593,7 +593,7 @@ void StandardTetrahedralFEMForceField::buildStiffnessMatrix(core::beh } template -void StandardTetrahedralFEMForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void StandardTetrahedralFEMForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.h b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.h index f089c097572..4733ac99d2b 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.h +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.h @@ -172,8 +172,8 @@ class TetrahedronHyperelasticityFEMForceField : public core::behavior::ForceFiel SReal getPotentialEnergy(const core::MechanicalParams*, const DataVecCoord&) const override; using Inherit1::addKToMatrix; void addKToMatrix(sofa::linearalgebra::BaseMatrix *mat, SReal k, unsigned int &offset) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.inl b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.inl index 34a5f4b2a51..cce41640815 100644 --- a/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.inl +++ b/Sofa/Component/SolidMechanics/FEM/HyperElastic/src/sofa/component/solidmechanics/fem/hyperelastic/TetrahedronHyperelasticityFEMForceField.inl @@ -537,7 +537,7 @@ void TetrahedronHyperelasticityFEMForceField::addKToMatrix(sofa::line } template -void TetrahedronHyperelasticityFEMForceField::buildStiffnessMatrix( +void TetrahedronHyperelasticityFEMForceField::doBuildStiffnessMatrix( core::behavior::StiffnessMatrix* matrix) { /// if the matrix needs to be updated @@ -579,7 +579,7 @@ void TetrahedronHyperelasticityFEMForceField::buildStiffnessMatrix( } template -void TetrahedronHyperelasticityFEMForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TetrahedronHyperelasticityFEMForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.h index 2244a33072f..6fa8c1b79f5 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.h @@ -89,9 +89,9 @@ class AngularSpringForceField : public core::behavior::ForceField } /// Brings ForceField contribution to the global system stiffness matrix. - void addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doAddKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; void draw(const core::visual::VisualParams* vparams) override; protected : diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.inl index c25fabfded0..7eb69bd794e 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/AngularSpringForceField.inl @@ -145,7 +145,7 @@ void AngularSpringForceField::addDForce(const core::MechanicalParams* template -void AngularSpringForceField::addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) +void AngularSpringForceField::doAddKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) { const int N = 6; const sofa::core::behavior::MultiMatrixAccessor::MatrixRef mref = matrix->getMatrix(this->mstate); @@ -163,7 +163,7 @@ void AngularSpringForceField::addKToMatrix(const core::MechanicalPara } template -void AngularSpringForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void AngularSpringForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { auto dfdx = matrix->getForceDerivativeIn(this->mstate) .withRespectToPositionsIn(this->mstate); @@ -193,7 +193,7 @@ void AngularSpringForceField::buildStiffnessMatrix(core::behavior::St } template -void AngularSpringForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void AngularSpringForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.h index f89a0514d21..a7e317938d0 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.h @@ -82,8 +82,8 @@ class FastTriangularBendingSprings : public core::behavior::ForceField< _DataTyp void addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v) override; void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx) override; void addKToMatrix(sofa::linearalgebra::BaseMatrix *mat, SReal k, unsigned int &offset) override; // compute and add all the element stiffnesses to the global stiffness matrix - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* mparams, const DataVecCoord& d_x) const override; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.inl index 5ccd4f0d392..048dacf7e44 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FastTriangularBendingSprings.inl @@ -433,7 +433,7 @@ void FastTriangularBendingSprings::addKToMatrix(sofa::linearalgebra:: } template -void FastTriangularBendingSprings<_DataTypes>::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void FastTriangularBendingSprings<_DataTypes>::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { static constexpr auto blockSize = DataTypes::deriv_total_size; static constexpr auto spatialDimension = DataTypes::spatial_dimensions; @@ -458,7 +458,7 @@ void FastTriangularBendingSprings<_DataTypes>::buildStiffnessMatrix(core::behavi } template -void FastTriangularBendingSprings<_DataTypes>::buildDampingMatrix(core::behavior::DampingMatrix*) +void FastTriangularBendingSprings<_DataTypes>::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.h index 6896b63d2e2..1d7ac74e12f 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/FrameSpringForceField.h @@ -186,7 +186,7 @@ class FrameSpringForceField : public core::behavior::PairInteractionForceField::addDForce(const core::MechanicalParams* / } template -void FrameSpringForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void FrameSpringForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/GearSpringForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/GearSpringForceField.h index e75c0dde5b5..8849a1dc695 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/GearSpringForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/GearSpringForceField.h @@ -213,7 +213,7 @@ class GearSpringForceField : public core::behavior::PairInteractionForceField::addDForce(const core::MechanicalParams *mp } template -void GearSpringForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void GearSpringForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/JointSpringForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/JointSpringForceField.h index c3d0c4e2251..aa48818f613 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/JointSpringForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/JointSpringForceField.h @@ -123,7 +123,7 @@ class JointSpringForceField : public core::behavior::PairInteractionForceField::addDForce(const core::MechanicalParams *m } template -void JointSpringForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void JointSpringForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialRestShapeSpringsForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialRestShapeSpringsForceField.h index 0186434fb40..febab011bb2 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialRestShapeSpringsForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialRestShapeSpringsForceField.h @@ -126,10 +126,10 @@ class PolynomialRestShapeSpringsForceField : public core::behavior::ForceField::draw(const core::visual::V template -void PolynomialRestShapeSpringsForceField::addKToMatrix(const core::MechanicalParams* mparams, +void PolynomialRestShapeSpringsForceField::doAddKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) { msg_info() << "[" << this->getName() << "]: addKToMatrix"; @@ -477,7 +477,7 @@ void PolynomialRestShapeSpringsForceField::addKToMatrix(const core::M } template -void PolynomialRestShapeSpringsForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void PolynomialRestShapeSpringsForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { static constexpr sofa::SignedIndex Dimension = Coord::total_size; @@ -496,7 +496,7 @@ void PolynomialRestShapeSpringsForceField::buildStiffnessMatrix(core: } template -void PolynomialRestShapeSpringsForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void PolynomialRestShapeSpringsForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.h index 6d8e692a021..06a12d50d49 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.h @@ -125,11 +125,11 @@ class PolynomialSpringsForceField : public core::behavior::PairInteractionForceF const DataVecDeriv& data_dx1, const DataVecDeriv& data_dx2) override; /// Brings ForceField contribution to the global system stiffness matrix. - virtual void addKToMatrix(const core::MechanicalParams* mparams, const core::behavior::MultiMatrixAccessor* matrix) override; + virtual void doAddKToMatrix(const core::MechanicalParams* mparams, const core::behavior::MultiMatrixAccessor* matrix) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; virtual void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.inl index c7c49613af1..06215e60661 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/PolynomialSpringsForceField.inl @@ -394,7 +394,7 @@ void PolynomialSpringsForceField::draw(const core::visual::VisualPara } template -void PolynomialSpringsForceField::addKToMatrix(const core::MechanicalParams* mparams, +void PolynomialSpringsForceField::doAddKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) { msg_info() << "[" << this->getName() << "]: addKToMatrix"; @@ -459,7 +459,7 @@ void PolynomialSpringsForceField::addKToMatrix(const core::Mechanical } template -void PolynomialSpringsForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void PolynomialSpringsForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { unsigned int firstIndex = 0; unsigned int secondIndex = 0; @@ -525,7 +525,7 @@ void PolynomialSpringsForceField::buildStiffnessMatrix(core::behavior } template -void PolynomialSpringsForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void PolynomialSpringsForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.h index c77f0e7ffa7..ce29058b5b2 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.h @@ -120,8 +120,8 @@ class QuadularBendingSprings : public core::behavior::ForceField void addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v) override; void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* /* mparams */, const DataVecCoord& /* d_x */) const override; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.inl index f15d473cb32..86475417533 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/QuadularBendingSprings.inl @@ -557,7 +557,7 @@ void QuadularBendingSprings::addDForce(const core::MechanicalParams* } template -void QuadularBendingSprings::buildStiffnessMatrix( +void QuadularBendingSprings::doBuildStiffnessMatrix( core::behavior::StiffnessMatrix* matrix) { auto dfdx = matrix->getForceDerivativeIn(this->mstate) @@ -586,7 +586,7 @@ void QuadularBendingSprings::buildStiffnessMatrix( } template -void QuadularBendingSprings::buildDampingMatrix(core::behavior::DampingMatrix*) +void QuadularBendingSprings::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.h index bba03aad7c0..387a56b58de 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.h @@ -111,9 +111,9 @@ class RestShapeSpringsForceField : public core::behavior::ForceField } /// Brings ForceField contribution to the global system stiffness matrix. - void addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* matrix) override; + void doAddKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) override; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* matrix) override; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.inl index 9f6d088de0c..9c70e6aa336 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/RestShapeSpringsForceField.inl @@ -543,7 +543,7 @@ void RestShapeSpringsForceField::draw(const VisualParams *vparams) } template -void RestShapeSpringsForceField::addKToMatrix(const MechanicalParams* mparams, const MultiMatrixAccessor* matrix ) +void RestShapeSpringsForceField::doAddKToMatrix(const MechanicalParams* mparams, const MultiMatrixAccessor* matrix ) { const MultiMatrixAccessor::MatrixRef mref = matrix->getMatrix(this->mstate); BaseMatrix* mat = mref.matrix; @@ -589,7 +589,7 @@ void RestShapeSpringsForceField::addKToMatrix(const MechanicalParams* } template -void RestShapeSpringsForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void RestShapeSpringsForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { const VecReal& k = d_stiffness.getValue(); const VecReal& k_a = d_angularStiffness.getValue(); @@ -628,7 +628,7 @@ void RestShapeSpringsForceField::buildStiffnessMatrix(core::behavior: } template -void RestShapeSpringsForceField::buildDampingMatrix( +void RestShapeSpringsForceField::doBuildDampingMatrix( core::behavior::DampingMatrix* matrix) { SOFA_UNUSED(matrix); diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/SpringForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/SpringForceField.h index 10917030043..93d9f7088dc 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/SpringForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/SpringForceField.h @@ -93,9 +93,9 @@ class SpringForceField : public core::behavior::PairInteractionForceField::addToMatrix(Matrix* globalMatrix, } template -void SpringForceField::addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void SpringForceField::doAddKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { const Real kFact = (Real)sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams,this->rayleighStiffness.getValue()); if (this->mstate1 == this->mstate2) @@ -733,7 +733,7 @@ void SpringForceField::addKToMatrix(const core::MechanicalParams* mpa } template -void SpringForceField::buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) +void SpringForceField::doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) { const sofa::type::vector& ss = this->d_springs.getValue(); const auto n = std::min(ss.size(), this->dfdx.size()); @@ -795,7 +795,7 @@ void SpringForceField::buildStiffnessMatrix(core::behavior::Stiffness } template -void SpringForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void SpringForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.h index 4d7c2a04e14..6b7efe7f088 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.h @@ -139,8 +139,8 @@ class TriangularBendingSprings : public core::behavior::ForceField void addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v) override; void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx) override; - void buildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.inl index a1dd62736d6..78b9b27ecf6 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBendingSprings.inl @@ -526,7 +526,7 @@ void TriangularBendingSprings::addDForce(const core::MechanicalParams } template -void TriangularBendingSprings::buildStiffnessMatrix( +void TriangularBendingSprings::doBuildStiffnessMatrix( core::behavior::StiffnessMatrix* matrix) { auto dfdx = matrix->getForceDerivativeIn(this->mstate) @@ -553,7 +553,7 @@ void TriangularBendingSprings::buildStiffnessMatrix( } template -void TriangularBendingSprings::buildDampingMatrix(core::behavior::DampingMatrix*) +void TriangularBendingSprings::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.h index ca2da174cd8..afd9e497ad4 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.h @@ -152,7 +152,7 @@ class TriangularBiquadraticSpringsForceField : public core::behavior::ForceField void addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v) override; void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override { msg_warning() << "Method getPotentialEnergy not implemented yet."; diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.inl b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.inl index 71f30cb6252..28611c8c475 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.inl +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularBiquadraticSpringsForceField.inl @@ -520,7 +520,7 @@ void TriangularBiquadraticSpringsForceField::addDForce(const core::Me } template -void TriangularBiquadraticSpringsForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TriangularBiquadraticSpringsForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularQuadraticSpringsForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularQuadraticSpringsForceField.h index 5d0ef97bf44..2b958f5c4b2 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularQuadraticSpringsForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/TriangularQuadraticSpringsForceField.h @@ -136,7 +136,7 @@ class TriangularQuadraticSpringsForceField : public core::behavior::ForceField::addDForce(const core::Mech } template -void TriangularQuadraticSpringsForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TriangularQuadraticSpringsForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/VectorSpringForceField.h b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/VectorSpringForceField.h index b896bfd5a1a..8a5b02b6933 100644 --- a/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/VectorSpringForceField.h +++ b/Sofa/Component/SolidMechanics/Spring/src/sofa/component/solidmechanics/spring/VectorSpringForceField.h @@ -139,7 +139,7 @@ class VectorSpringForceField: public core::behavior::PairInteractionForceField::addDForce(const core::MechanicalParams* } template -void VectorSpringForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void VectorSpringForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.h b/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.h index bdc09f79105..f01cbc164f9 100644 --- a/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.h +++ b/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TetrahedralTensorMassForceField.h @@ -107,8 +107,8 @@ class TetrahedralTensorMassForceField : public core::behavior::ForceField::addDForce(const core::Mechanica } template -void TetrahedralTensorMassForceField::buildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) +void TetrahedralTensorMassForceField::doBuildStiffnessMatrix(sofa::core::behavior::StiffnessMatrix* matrix) { auto dfdx = matrix->getForceDerivativeIn(this->mstate) .withRespectToPositionsIn(this->mstate); @@ -474,7 +474,7 @@ void TetrahedralTensorMassForceField::buildStiffnessMatrix(sofa::core } template -void TetrahedralTensorMassForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TetrahedralTensorMassForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TriangularTensorMassForceField.h b/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TriangularTensorMassForceField.h index 1a1778334aa..9265b16c710 100644 --- a/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TriangularTensorMassForceField.h +++ b/Sofa/Component/SolidMechanics/TensorMass/src/sofa/component/solidmechanics/tensormass/TriangularTensorMassForceField.h @@ -137,7 +137,7 @@ class TriangularTensorMassForceField : public core::behavior::ForceField::addDForce(const core::Mechanical } template -void TriangularTensorMassForceField::buildDampingMatrix(core::behavior::DampingMatrix*) +void TriangularTensorMassForceField::doBuildDampingMatrix(core::behavior::DampingMatrix*) { // No damping in this ForceField } diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp index ad847a320ab..b7fd32fe078 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp @@ -48,20 +48,28 @@ void BaseForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId doAddDForce(mparams, dfId); } -SReal BaseForceField::getPotentialEnergy( const MechanicalParams* mparams = mechanicalparams::defaultInstance() ) const +SReal BaseForceField::getPotentialEnergy( const MechanicalParams* mparams ) const { //TODO (SPRINT SED 2025): Component state mechanism return doGetPotentialEnergy(mparams); } -void BaseForceField::addMBKdx(const MechanicalParams* mparams, MultiVecDerivId dfId) +void BaseForceField::addKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) { - if (sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams,rayleighStiffness.getValue()) != 0.0 || sofa::core::mechanicalparams::bFactor(mparams) != 0.0) - addDForce(mparams, dfId); + //TODO (SPRINT SED 2025): Component state mechanism + doAddKToMatrix(mparams, matrix); } -void BaseForceField::addBToMatrix(const MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/) +void BaseForceField::addBToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) { + //TODO (SPRINT SED 2025): Component state mechanism + doAddBToMatrix(mparams, matrix); +} + +void BaseForceField::addMBKdx(const MechanicalParams* mparams, MultiVecDerivId dfId) +{ + if (sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams,rayleighStiffness.getValue()) != 0.0 || sofa::core::mechanicalparams::bFactor(mparams) != 0.0) + addDForce(mparams, dfId); } void BaseForceField::addMBKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) @@ -73,6 +81,12 @@ void BaseForceField::addMBKToMatrix(const MechanicalParams* mparams, const sofa: } void BaseForceField::buildStiffnessMatrix(StiffnessMatrix* matrix) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doBuildStiffnessMatrix(matrix); +} + +void BaseForceField::doBuildStiffnessMatrix(StiffnessMatrix* matrix) { static std::set hasEmittedWarning; if (hasEmittedWarning.insert(this).second) @@ -114,10 +128,16 @@ void BaseForceField::buildStiffnessMatrix(StiffnessMatrix* matrix) params.setKFactor(1.); params.setMFactor(1.); - addKToMatrix(¶ms, &accessor); + doAddKToMatrix(¶ms, &accessor); } void BaseForceField::buildDampingMatrix(DampingMatrix* matrix) +{ + //TODO (SPRINT SED 2025): Component state mechanism + doBuildDampingMatrix(matrix); +} + +void BaseForceField::doBuildDampingMatrix(DampingMatrix* matrix) { static std::set hasEmittedWarning; if (hasEmittedWarning.insert(this).second) @@ -159,7 +179,7 @@ void BaseForceField::buildDampingMatrix(DampingMatrix* matrix) params.setKFactor(1.); params.setMFactor(1.); - addBToMatrix(¶ms, &accessor); + doAddBToMatrix(¶ms, &accessor); } bool BaseForceField::insertInNode( objectmodel::BaseNode* node ) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h index a3c643e9abe..f40d8adb963 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h @@ -58,6 +58,10 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor virtual void doAddForce(const MechanicalParams* mparams, MultiVecDerivId fId ) = 0; virtual void doAddDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) = 0; virtual SReal doGetPotentialEnergy( const MechanicalParams* mparams ) const = 0; + virtual void doAddKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) = 0; + virtual void doAddBToMatrix(const MechanicalParams* /*mparams*/, const sofa::core::behavior::MultiMatrixAccessor* /*matrix*/ ) { }; + virtual void doBuildStiffnessMatrix(StiffnessMatrix* matrix); + virtual void doBuildDampingMatrix(DampingMatrix* matrix); private: BaseForceField(const BaseForceField& n) = delete; @@ -175,18 +179,35 @@ class SOFA_CORE_API BaseForceField : 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 "doAddKToMatrix" internally, + * which is the method to override from now on. + * + **/ + /// \brief Compute the system matrix corresponding to \f$ k K \f$ /// /// \param mparams \a mparams->kFactor() is the coefficient for stiffness contributions (i.e. DOFs term in the ODE) /// \param matrix the matrix to add the result to - virtual void addKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) = 0; + virtual void addKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) final; + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doAddBToMatrix" internally, + * which is the method to override from now on. + * + **/ /// \brief Compute the system matrix corresponding to \f$ b B \f$ /// /// \param mparams \a sofa::core::mechanicalparams::bFactor(mparams) is the coefficient for damping contributions (i.e. first derivatives term in the ODE) /// \param matrix the matrix to add the result to - virtual void addBToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ); - //virtual void addBToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal bFact, unsigned int &offset); + virtual void addBToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) final; /// \brief Compute the system matrix corresponding to \f$ m M + b B + k K \f$ /// @@ -196,11 +217,28 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// - \a mparams->kFactor() is the coefficient for stiffness contributions (i.e. DOFs term in the ODE) /// \param matrix the matrix to add the result to virtual void addMBKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ); - ////virtual void addMBKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal mFact, SReal bFact, SReal kFact, unsigned int &offset); - virtual void buildStiffnessMatrix(StiffnessMatrix* 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 "doBuildStiffnessMatrix" internally, + * which is the method to override from now on. + * + **/ + + virtual void buildStiffnessMatrix(StiffnessMatrix* matrix) final; + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doBuildDampingMatrix" internally, + * which is the method to override from now on. + * + **/ - virtual void buildDampingMatrix(DampingMatrix* matrix); + virtual void buildDampingMatrix(DampingMatrix* matrix) final; /// @} diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionForceField.h index 3bf36e8d422..84977c70edd 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionForceField.h @@ -48,12 +48,11 @@ class SOFA_CORE_API BaseInteractionForceField : public BaseForceField /// \todo Rename to getMechState2() virtual BaseMechanicalState* getMechModel2(); - void addKToMatrix(const MechanicalParams* /* mparams */, const sofa::core::behavior::MultiMatrixAccessor* /* matrix */ ) override + void doAddKToMatrix(const MechanicalParams* /* mparams */, const sofa::core::behavior::MultiMatrixAccessor* /* matrix */ ) override { msg_error() << "addKToMatrix not implemented."; } - /// initialization to export potential energy to gnuplot files format virtual void initGnuplot(const std::string path) { diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h index 953fa07fd4d..bc90483f6ea 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h @@ -60,6 +60,10 @@ class ForceField : public BaseForceField, public SingleStateAccessor using BaseForceField::addForce; using BaseForceField::addDForce; using BaseForceField::getPotentialEnergy; + using BaseForceField::addKToMatrix; + using BaseForceField::addBToMatrix; + using BaseForceField::buildStiffnessMatrix; + using BaseForceField::buildDampingMatrix; protected: explicit ForceField(MechanicalState *mm = nullptr); @@ -140,7 +144,7 @@ class ForceField : public BaseForceField, public SingleStateAccessor /// @name Matrix operations /// @{ - void addKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) override; + void doAddKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) override; /// Internal addKToMatrix /// Overloaded function, usually called from the generic addKToMatrix version. @@ -154,7 +158,7 @@ class ForceField : public BaseForceField, public SingleStateAccessor /// @param offset Starting index of the submatrix to fill in the global matrix. virtual void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset); - void addBToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doAddBToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; /** Accumulate an element matrix to a global assembly matrix. This is a helper for addKToMatrix, to accumulate each (square) element matrix in the (square) assembled matrix. \param bm the global assembly matrix diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl index e54b45e91f7..225b2ef99e7 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl @@ -85,7 +85,7 @@ SReal ForceField::doGetPotentialEnergy(const MechanicalParams* mparam } template -void ForceField::addKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) +void ForceField::doAddKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) { if (this->mstate) { @@ -111,7 +111,7 @@ void ForceField::addKToMatrix(sofa::linearalgebra::BaseMatrix * /*mat } template -void ForceField::addBToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void ForceField::doAddBToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { if (this->mstate) { diff --git a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaHexahedronTLEDForceField.h b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaHexahedronTLEDForceField.h index b912b1c3e17..194273e5b5c 100644 --- a/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaHexahedronTLEDForceField.h +++ b/applications/plugins/SofaCUDA/sofa/gpu/cuda/CudaHexahedronTLEDForceField.h @@ -105,8 +105,8 @@ class CudaHexahedronTLEDForceField : public core::behavior::ForceField : public core::behavior::PairInt virtual void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df1, DataVecDeriv& d_df2, const DataVecDeriv& d_dx1, const DataVecDeriv& d_dx2) override; - void buildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; + void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; virtual SReal getPotentialEnergy(const core::MechanicalParams* mparams, const DataVecCoord& x1, const DataVecCoord& x2) const override; diff --git a/applications/plugins/SofaCUDA/src/SofaCUDA/component/collision/response/contact/CudaPenalityContactForceField.inl b/applications/plugins/SofaCUDA/src/SofaCUDA/component/collision/response/contact/CudaPenalityContactForceField.inl index 0b6a42d0858..c6e3089b706 100644 --- a/applications/plugins/SofaCUDA/src/SofaCUDA/component/collision/response/contact/CudaPenalityContactForceField.inl +++ b/applications/plugins/SofaCUDA/src/SofaCUDA/component/collision/response/contact/CudaPenalityContactForceField.inl @@ -195,7 +195,7 @@ void PenalityContactForceField::addDForce(const core::Mechanical d_df2.endEdit(); } -inline void PenalityContactForceField, Vec<3>>>::buildDampingMatrix(core::behavior::DampingMatrix* damping_matrix) +inline void PenalityContactForceField, Vec<3>>>::doBuildDampingMatrix(core::behavior::DampingMatrix* damping_matrix) { // No damping in this ForceField } From e7557fe6962500cda2d458b9cb692e4d9fb46f1b Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Thu, 15 May 2025 15:39:53 +0200 Subject: [PATCH 10/18] Fix compilation for SOFA, TODO: plugins --- .../response/contact/PenalityContactForceField.h | 2 +- .../response/contact/PenalityContactForceField.inl | 2 +- .../mechanicalload/QuadPressureForceField.h | 1 + .../mechanicalload/SurfacePressureForceField.h | 1 + .../mechanicalload/TrianglePressureForceField.h | 1 + .../Core/src/sofa/core/behavior/ForceField.h | 2 +- .../Core/src/sofa/core/behavior/ForceField.inl | 13 ++++--------- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.h b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.h index c0dd9465043..45726200615 100644 --- a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.h +++ b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.h @@ -118,7 +118,7 @@ class PenalityContactForceField : public core::behavior::PairInteractionForceFie void addDForce(const sofa::core::MechanicalParams* mparams, DataVecDeriv& data_df1, DataVecDeriv& data_df2, const DataVecDeriv& data_dx1, const DataVecDeriv& data_dx2) override; - void addKToMatrix(const sofa::core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void doAddKToMatrix(const sofa::core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; diff --git a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.inl b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.inl index 16dcbad670a..cead7f35c97 100644 --- a/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.inl +++ b/Sofa/Component/Collision/Response/Contact/src/sofa/component/collision/response/contact/PenalityContactForceField.inl @@ -133,7 +133,7 @@ void PenalityContactForceField::addDForce(const sofa::core::Mechanica } template -void PenalityContactForceField::addKToMatrix(const sofa::core::MechanicalParams* mparams, +void PenalityContactForceField::doAddKToMatrix(const sofa::core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) { static constexpr auto N = DataTypes::spatial_dimensions; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.h index 0cd5132fb76..426e95d0b1a 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/QuadPressureForceField.h @@ -110,6 +110,7 @@ class QuadPressureForceField : public core::behavior::ForceField void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx) override; /// Constant pressure has null variation + using Inherit1::addKToMatrix; void addKToMatrix(sofa::linearalgebra::BaseMatrix * /*m*/, SReal /*kFactor*/, unsigned int & /*offset*/) override {} void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* /*matrix*/) override; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.h index 5b90323d04e..6afbe372fc4 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/SurfacePressureForceField.h @@ -100,6 +100,7 @@ class SurfacePressureForceField : public core::behavior::ForceField void addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v) override; void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& /* d_df */, const DataVecDeriv& /* d_dx */) override; + using Inherit1::addKToMatrix; void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override; void doBuildStiffnessMatrix(core::behavior::StiffnessMatrix* matrix) override; void doBuildDampingMatrix(core::behavior::DampingMatrix* /*matrix*/) final; diff --git a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.h b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.h index 300245fa93b..30b16013009 100644 --- a/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.h +++ b/Sofa/Component/MechanicalLoad/src/sofa/component/mechanicalload/TrianglePressureForceField.h @@ -114,6 +114,7 @@ class TrianglePressureForceField : public core::behavior::ForceField void addDForce(const core::MechanicalParams* mparams, DataVecDeriv& d_df, const DataVecDeriv& d_dx) override; /// Constant pressure has null variation + using Inherit1::addKToMatrix; void addKToMatrix(sofa::linearalgebra::BaseMatrix * /*m*/, SReal /*kFactor*/, unsigned int & /*offset*/) override {} /// Constant pressure has null variation diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h index bc90483f6ea..f77951f1625 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h @@ -67,8 +67,8 @@ class ForceField : public BaseForceField, public SingleStateAccessor protected: explicit ForceField(MechanicalState *mm = nullptr); - ~ForceField() override; + public: /// @name Vector operations diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl index 225b2ef99e7..7d57ce60282 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.inl @@ -99,15 +99,10 @@ void ForceField::doAddKToMatrix(const MechanicalParams* mparams, cons template void ForceField::addKToMatrix(sofa::linearalgebra::BaseMatrix * /*mat*/, SReal /*kFact*/, unsigned int &/*offset*/) { - static int i=0; - if (i < 10) - { - // This function is called for implicit time integration where stiffness matrix assembly is expected - msg_warning() << "This force field does not support stiffness matrix assembly. " - "Therefore, the forces are integrated explicitly. " - "To support stiffness matrix assembly, addKToMatrix must be implemented."; - i++; - } + // This function is called for implicit time integration where stiffness matrix assembly is expected + msg_warning() << "This force field does not support stiffness matrix assembly. " + "Therefore, the forces are integrated explicitly. " + "To support stiffness matrix assembly, addKToMatrix must be implemented."; } template From 59f8466e65c9597e0d1895cda37f04c9b54a95cf Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Tue, 13 May 2025 00:57:06 +0200 Subject: [PATCH 11/18] [Engine.Select] Automatically find topology in MeshBoundaryROI (#5116) * [Engine.Select] Automatically find topology in MeshBoundaryROI * add warning when no topology is provided --- .../sofa/component/engine/select/BaseROI.h | 8 ++--- .../engine/select/MeshBoundaryROI.cpp | 34 +++++++++++++++++++ .../Engine/Select/MeshBoundaryROI.scn | 9 ++--- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BaseROI.h b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BaseROI.h index 70d96c0ba88..4e1b6486250 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BaseROI.h +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/BaseROI.h @@ -66,10 +66,10 @@ class BaseROI : public core::DataEngine void draw(const core::visual::VisualParams* vparams) final; void computeBBox(const core::ExecParams* params, bool onlyVisible) final; - virtual void roiInit() {}; - virtual bool roiDoUpdate() { return true; }; - virtual void roiDraw(const core::visual::VisualParams*) {}; - virtual void roiComputeBBox(const core::ExecParams*, type::BoundingBox&) {}; + virtual void roiInit() {} + virtual bool roiDoUpdate() { return true; } + virtual void roiDraw(const core::visual::VisualParams*) {} + virtual void roiComputeBBox(const core::ExecParams*, type::BoundingBox&) {} public: //Input diff --git a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp index e866d610604..5bfffad4642 100644 --- a/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp +++ b/Sofa/Component/Engine/Select/src/sofa/component/engine/select/MeshBoundaryROI.cpp @@ -46,6 +46,40 @@ MeshBoundaryROI::MeshBoundaryROI(): Inherit1() void MeshBoundaryROI::init() { + Inherit1::init(); + + if (!d_triangles.isSet() || !d_quads.isSet() ) + { + msg_info(this) << "No topology given. Searching for a BaseMeshTopology in the current context.\n"; + core::topology::BaseMeshTopology* topology = nullptr; + this->getContext()->get(topology, core::objectmodel::BaseContext::Local); + + if (topology) + { + if (!d_triangles.isSet()) + { + if (core::BaseData* tparent = topology->findData("triangles")) + { + d_triangles.setParent(tparent); + d_triangles.setReadOnly(true); + } + } + if (!d_quads.isSet()) + { + if (core::BaseData* tparent = topology->findData("quads")) + { + d_quads.setParent(tparent); + d_quads.setReadOnly(true); + } + } + } + } + + if (!d_triangles.isSet() && !d_quads.isSet()) + { + msg_warning() << "No topology given. No mesh to process.\n"; + } + setDirtyValue(); } diff --git a/examples/Component/Engine/Select/MeshBoundaryROI.scn b/examples/Component/Engine/Select/MeshBoundaryROI.scn index 268abb6cc96..afb2728a52d 100644 --- a/examples/Component/Engine/Select/MeshBoundaryROI.scn +++ b/examples/Component/Engine/Select/MeshBoundaryROI.scn @@ -14,15 +14,16 @@ - + - - - + + + + From e2e5f6a227b8f8886f2ed217f6a971d4ee693447 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Tue, 13 May 2025 10:05:33 +0200 Subject: [PATCH 12/18] [Core] Rename BaseConstraint to BaseLagrangianConstraint (#5423) * [Core] Rename BaseConstraint to BaseLagrangianConstraint * restore toBaseConstraint and deprecate it * fix? --------- Co-authored-by: Hugo --- .../animationloop/ConstraintAnimationLoop.cpp | 2 +- .../model/BaseContactLagrangianConstraint.h | 18 +-- .../model/BilateralConstraintResolution.h | 2 +- .../model/BilateralLagrangianConstraint.h | 4 +- .../solver/GenericConstraintSolver.h | 2 +- .../lagrangian/solver/LCPConstraintSolver.cpp | 2 +- .../lagrangian/solver/LCPConstraintSolver.h | 24 ++-- .../visitors/ConstraintStoreLambdaVisitor.cpp | 4 +- ...chanicalGetConstraintResolutionVisitor.cpp | 4 +- Sofa/framework/Core/CMakeLists.txt | 3 +- .../src/sofa/core/behavior/BaseConstraint.h | 102 +-------------- .../core/behavior/BaseInteractionConstraint.h | 6 +- ...raint.cpp => BaseLagrangianConstraint.cpp} | 12 +- .../core/behavior/BaseLagrangianConstraint.h | 123 ++++++++++++++++++ .../Core/src/sofa/core/behavior/Constraint.h | 7 +- .../Core/src/sofa/core/behavior/Mass.inl | 2 +- .../Core/src/sofa/core/behavior/fwd.h | 2 +- Sofa/framework/Core/src/sofa/core/config.h.in | 8 ++ Sofa/framework/Core/src/sofa/core/fwd.cpp | 2 +- Sofa/framework/Core/src/sofa/core/fwd.h | 2 +- .../Core/src/sofa/core/objectmodel/Base.h | 5 +- .../MechanicalGetConstraintInfoVisitor.cpp | 2 +- .../MechanicalGetConstraintInfoVisitor.h | 12 +- 23 files changed, 197 insertions(+), 153 deletions(-) rename Sofa/framework/Core/src/sofa/core/behavior/{BaseConstraint.cpp => BaseLagrangianConstraint.cpp} (82%) create mode 100644 Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.h diff --git a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp index d732bd93605..c37dc40f555 100644 --- a/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp +++ b/Sofa/Component/AnimationLoop/src/sofa/component/animationloop/ConstraintAnimationLoop.cpp @@ -43,7 +43,7 @@ #include -#include ///< ConstraintResolution. +#include ///< ConstraintResolution. #include diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BaseContactLagrangianConstraint.h b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BaseContactLagrangianConstraint.h index 512a06ebd5b..e1e30c63c21 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BaseContactLagrangianConstraint.h +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BaseContactLagrangianConstraint.h @@ -61,15 +61,15 @@ class BaseContactLagrangianConstraint : public core::behavior::PairInteractionCo typedef typename Coord::value_type Real; typedef typename core::behavior::MechanicalState MechanicalState; - typedef core::behavior::BaseConstraint::ConstraintBlockInfo ConstraintBlockInfo; - typedef core::behavior::BaseConstraint::PersistentID PersistentID; - typedef core::behavior::BaseConstraint::ConstCoord ConstCoord; - - typedef core::behavior::BaseConstraint::VecConstraintBlockInfo VecConstraintBlockInfo; - typedef core::behavior::BaseConstraint::VecPersistentID VecPersistentID; - typedef core::behavior::BaseConstraint::VecConstCoord VecConstCoord; - typedef core::behavior::BaseConstraint::VecConstDeriv VecConstDeriv; - typedef core::behavior::BaseConstraint::VecConstArea VecConstArea; + typedef core::behavior::BaseLagrangianConstraint::ConstraintBlockInfo ConstraintBlockInfo; + typedef core::behavior::BaseLagrangianConstraint::PersistentID PersistentID; + typedef core::behavior::BaseLagrangianConstraint::ConstCoord ConstCoord; + + typedef core::behavior::BaseLagrangianConstraint::VecConstraintBlockInfo VecConstraintBlockInfo; + typedef core::behavior::BaseLagrangianConstraint::VecPersistentID VecPersistentID; + typedef core::behavior::BaseLagrangianConstraint::VecConstCoord VecConstCoord; + typedef core::behavior::BaseLagrangianConstraint::VecConstDeriv VecConstDeriv; + typedef core::behavior::BaseLagrangianConstraint::VecConstArea VecConstArea; typedef core::objectmodel::Data DataVecCoord; typedef core::objectmodel::Data DataVecDeriv; diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralConstraintResolution.h b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralConstraintResolution.h index 3c4d0f1bcca..429f5e735ff 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralConstraintResolution.h +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralConstraintResolution.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include diff --git a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h index 4d7da7fdd4a..9168060cec0 100644 --- a/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h +++ b/Sofa/Component/Constraint/Lagrangian/Model/src/sofa/component/constraint/lagrangian/model/BilateralLagrangianConstraint.h @@ -41,7 +41,7 @@ namespace sofa::component::constraint::lagrangian::model /// These 'using' are in a per-file namespace so they will not leak /// and polluate the standard namespace. -using sofa::core::behavior::BaseConstraint ; +using sofa::core::behavior::BaseLagrangianConstraint ; using sofa::core::behavior::ConstraintResolution ; using sofa::core::behavior::PairInteractionConstraint ; using sofa::core::ConstraintParams ; @@ -81,7 +81,7 @@ class BilateralLagrangianConstraint : public PairInteractionConstraint MechanicalState; - typedef BaseConstraint::PersistentID PersistentID; + typedef BaseLagrangianConstraint::PersistentID PersistentID; typedef Data DataVecCoord; typedef Data DataVecDeriv; diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h index 761ec076298..e7a3a639cfc 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/GenericConstraintSolver.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.cpp index 541091eb613..c50fb7cb80a 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.cpp @@ -676,7 +676,7 @@ void LCPConstraintSolver::computeInitialGuess() for (const ConstraintBlockInfo& info : constraintBlockInfo) { if (!info.hasId) continue; - std::map::const_iterator previt = _previousConstraints.find(info.parent); + std::map::const_iterator previt = _previousConstraints.find(info.parent); if (previt == _previousConstraints.end()) continue; const ConstraintBlockBuf& buf = previt->second; const int c0 = info.const0; diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.h b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.h index cacdb319c29..b4217228f20 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.h +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/LCPConstraintSolver.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -147,17 +147,17 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ std::vector _cclist_elem1; std::vector _cclist_elem2; - typedef core::behavior::BaseConstraint::ConstraintBlockInfo ConstraintBlockInfo; - typedef core::behavior::BaseConstraint::PersistentID PersistentID; - typedef core::behavior::BaseConstraint::ConstCoord ConstCoord; - typedef core::behavior::BaseConstraint::ConstDeriv ConstDeriv; - typedef core::behavior::BaseConstraint::ConstArea ConstArea; + typedef core::behavior::BaseLagrangianConstraint::ConstraintBlockInfo ConstraintBlockInfo; + typedef core::behavior::BaseLagrangianConstraint::PersistentID PersistentID; + typedef core::behavior::BaseLagrangianConstraint::ConstCoord ConstCoord; + typedef core::behavior::BaseLagrangianConstraint::ConstDeriv ConstDeriv; + typedef core::behavior::BaseLagrangianConstraint::ConstArea ConstArea; - typedef core::behavior::BaseConstraint::VecConstraintBlockInfo VecConstraintBlockInfo; - typedef core::behavior::BaseConstraint::VecPersistentID VecPersistentID; - typedef core::behavior::BaseConstraint::VecConstCoord VecConstCoord; - typedef core::behavior::BaseConstraint::VecConstDeriv VecConstDeriv; - typedef core::behavior::BaseConstraint::VecConstArea VecConstArea; + typedef core::behavior::BaseLagrangianConstraint::VecConstraintBlockInfo VecConstraintBlockInfo; + typedef core::behavior::BaseLagrangianConstraint::VecPersistentID VecPersistentID; + typedef core::behavior::BaseLagrangianConstraint::VecConstCoord VecConstCoord; + typedef core::behavior::BaseLagrangianConstraint::VecConstDeriv VecConstDeriv; + typedef core::behavior::BaseLagrangianConstraint::VecConstArea VecConstArea; class ConstraintBlockBuf { @@ -166,7 +166,7 @@ class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_SOLVER_API LCPConstraintSolver : publ int nbLines; ///< how many dofs (i.e. lines in the matrix) are used by each constraint }; - std::map _previousConstraints; + std::map _previousConstraints; type::vector< SReal > _previousForces; type::vector< VecConstraintBlockInfo > hierarchy_constraintBlockInfo; diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/visitors/ConstraintStoreLambdaVisitor.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/visitors/ConstraintStoreLambdaVisitor.cpp index 398fc1feffc..fa5b3efd272 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/visitors/ConstraintStoreLambdaVisitor.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/visitors/ConstraintStoreLambdaVisitor.cpp @@ -19,7 +19,7 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include +#include #include #include @@ -35,7 +35,7 @@ ConstraintStoreLambdaVisitor::ConstraintStoreLambdaVisitor(const sofa::core::Con simulation::Visitor::Result ConstraintStoreLambdaVisitor::fwdConstraintSet(simulation::Node* node, core::behavior::BaseConstraintSet* cSet) { - if (core::behavior::BaseConstraint *c = dynamic_cast(cSet) ) + if (core::behavior::BaseLagrangianConstraint *c = dynamic_cast(cSet) ) { const ctime_t t0 = begin(node, c); c->storeLambda(m_cParams, m_cParams->lambda(), m_lambda); diff --git a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/visitors/MechanicalGetConstraintResolutionVisitor.cpp b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/visitors/MechanicalGetConstraintResolutionVisitor.cpp index 3eb9ce87fa3..29d67ff2571 100644 --- a/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/visitors/MechanicalGetConstraintResolutionVisitor.cpp +++ b/Sofa/Component/Constraint/Lagrangian/Solver/src/sofa/component/constraint/lagrangian/solver/visitors/MechanicalGetConstraintResolutionVisitor.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace sofa::component::constraint::lagrangian::solver { @@ -39,7 +39,7 @@ MechanicalGetConstraintResolutionVisitor::MechanicalGetConstraintResolutionVisit MechanicalGetConstraintResolutionVisitor::Result MechanicalGetConstraintResolutionVisitor::fwdConstraintSet(simulation::Node* node, core::behavior::BaseConstraintSet* cSet) { - if (core::behavior::BaseConstraint *c=cSet->toBaseConstraint()) + if (core::behavior::BaseLagrangianConstraint *c=cSet->toBaseLagrangianConstraint()) { const ctime_t t0 = begin(node, c); c->getConstraintResolution(cparams, _res, _offset); diff --git a/Sofa/framework/Core/CMakeLists.txt b/Sofa/framework/Core/CMakeLists.txt index 3574a69d674..5948823e627 100644 --- a/Sofa/framework/Core/CMakeLists.txt +++ b/Sofa/framework/Core/CMakeLists.txt @@ -58,6 +58,7 @@ set(HEADER_FILES ${SRC_ROOT}/behavior/BaseInteractionConstraint.h ${SRC_ROOT}/behavior/BaseInteractionForceField.h ${SRC_ROOT}/behavior/BaseInteractionProjectiveConstraintSet.h + ${SRC_ROOT}/behavior/BaseLagrangianConstraint.h ${SRC_ROOT}/behavior/BaseLinearSolver.h ${SRC_ROOT}/behavior/BaseLocalForceFieldMatrix.h ${SRC_ROOT}/behavior/BaseLocalMassMatrix.h @@ -234,11 +235,11 @@ set(SOURCE_FILES ${SRC_ROOT}/State.cpp ${SRC_ROOT}/VecId.cpp ${SRC_ROOT}/behavior/BaseAnimationLoop.cpp - ${SRC_ROOT}/behavior/BaseConstraint.cpp ${SRC_ROOT}/behavior/BaseConstraintCorrection.cpp ${SRC_ROOT}/behavior/BaseConstraintSet.cpp ${SRC_ROOT}/behavior/BaseForceField.cpp ${SRC_ROOT}/behavior/BaseInteractionForceField.cpp + ${SRC_ROOT}/behavior/BaseLagrangianConstraint.cpp ${SRC_ROOT}/behavior/BaseLinearSolver.cpp ${SRC_ROOT}/behavior/BaseMass.cpp ${SRC_ROOT}/behavior/BaseMatrixLinearSystem.cpp diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraint.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraint.h index ba176e79f8b..31ec84e088e 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraint.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraint.h @@ -21,103 +21,11 @@ ******************************************************************************/ #pragma once -#include -#include +#include -namespace sofa::core::behavior -{ +SOFA_HEADER_DEPRECATED("v25.06", "v26.06", "sofa/core/behavior/BaseLagrangianConstraint.h") -/** - * \brief Component computing constraints within a simulated body. - * - * This class defines the abstract API common to all constraints. - * A BaseConstraint computes constraints applied to one or more simulated body - * given its current position and velocity. - * - * Constraints can be internal to a given body (attached to one MechanicalState, - * see the Constraint class), or link several bodies together (such as contacts, - * see the InteractionConstraint class). - * - */ -class SOFA_CORE_API BaseConstraint : public BaseConstraintSet +namespace sofa::core::behavior { -public: - SOFA_ABSTRACT_CLASS(BaseConstraint, BaseConstraintSet); - SOFA_BASE_CAST_IMPLEMENTATION(BaseConstraint) - -protected: - BaseConstraint() {} - ~BaseConstraint() override {} - -private: - BaseConstraint(const BaseConstraint& n) = delete ; - BaseConstraint& operator=(const BaseConstraint& n) = delete ; - -public: - /// Get the ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle. - int getGroup() const; - - /// Set the ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle. - void setGroup(int g); - - typedef long long PersistentID; - typedef type::vector VecPersistentID; - typedef type::Vec<3,int> ConstCoord; - typedef type::vector VecConstCoord; - typedef type::Vec<3,double> ConstDeriv; - typedef type::vector VecConstDeriv; - typedef double ConstArea; - typedef type::vector VecConstArea; - - class ConstraintBlockInfo - { - public: - BaseConstraint* parent; - int const0; ///< index of first constraint - int nbLines; ///< how many dofs (i.e. lines in the matrix) are used by each constraint - int nbGroups; ///< how many groups of constraints are active - bool hasId; ///< true if this constraint has persistent ID information - bool hasPosition; ///< true if this constraint has coordinates information - bool hasDirection; ///< true if this constraint has direction information - bool hasArea; ///< true if this constraint has area information - int offsetId; ///< index of first constraint group info in vector of persistent ids and coordinates - int offsetPosition; ///< index of first constraint group info in vector of coordinates - int offsetDirection; ///< index of first constraint info in vector of directions - int offsetArea; ///< index of first constraint group info in vector of areas - ConstraintBlockInfo() : parent(nullptr), const0(0), nbLines(1), nbGroups(0), hasId(false), hasPosition(false), hasDirection(false), hasArea(false), offsetId(0), offsetPosition(0), offsetDirection(0), offsetArea(0) - {} - }; - typedef type::vector VecConstraintBlockInfo; - - /// Get information for each constraint: pointer to parent BaseConstraint, unique persistent ID, 3D position - /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) and resolution parameters (smoothness, ...) - virtual void getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas); - - /// Add the corresponding ConstraintResolution using the offset parameter - /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) and resolution parameters (smoothness, ...) - /// \param resTab is the result vector that contains the constraint resolution algorithms - virtual void getConstraintResolution(const ConstraintParams* cParams, std::vector &resTab, unsigned int &offset); - - virtual void getConstraintResolution(std::vector &resTab, unsigned int &offset); - - type::vector getIdentifiers() - { - type::vector ids = getBaseConstraintIdentifiers(); - ids.push_back("Base"); - return ids; - } - - virtual type::vector getBaseConstraintIdentifiers() = 0; - - - /// Store the constraint lambda at the constraint dofs at the given VecDerivId location. - /// res = J^t * lambda. - /// J is the sparse matrix containing the constraint jacobian that was used to build the constraint matrix ( see BaseConstraintSet::buildConstraintMatrix ). - /// \param cParams stores the id of the state vectors used during the constraint solving step. Mostly it helps retrieving the MatrixDerivId where - /// the constraint jacobian J is stored. - /// \param res is the state vector Id where to store the result. - /// \param lambda is the vector of scalar constraint impulses. The direction are stored in the MatrixDerivId stored in the cParams. - virtual void storeLambda(const ConstraintParams* cParams, MultiVecDerivId res, const sofa::linearalgebra::BaseVector* lambda) = 0; -}; - -} // namespace sofa::core::behavior +using BaseConstraint SOFA_ATTRIBUTE_DEPRECATED("v25.06", "v26.06", "BaseConstraint has been renamed to BaseLagrangianConstraint") = BaseLagrangianConstraint; +} diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionConstraint.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionConstraint.h index 9243cab1ef8..a437acca2d2 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionConstraint.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseInteractionConstraint.h @@ -21,7 +21,7 @@ ******************************************************************************/ #pragma once -#include +#include #include namespace sofa::core::behavior @@ -34,10 +34,10 @@ namespace sofa::core::behavior * bodies given their current positions and velocities. * */ -class SOFA_CORE_API BaseInteractionConstraint : public BaseConstraint, public virtual StateAccessor +class SOFA_CORE_API BaseInteractionConstraint : public BaseLagrangianConstraint, public virtual StateAccessor { public: - SOFA_ABSTRACT_CLASS2(BaseInteractionConstraint, BaseConstraint, StateAccessor); + SOFA_ABSTRACT_CLASS2(BaseInteractionConstraint, BaseLagrangianConstraint, StateAccessor); SOFA_BASE_CAST_IMPLEMENTATION(BaseInteractionConstraint) /// Get the first MechanicalState diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraint.cpp b/Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.cpp similarity index 82% rename from Sofa/framework/Core/src/sofa/core/behavior/BaseConstraint.cpp rename to Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.cpp index 0d6ccf41939..2e7cebb9401 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseConstraint.cpp +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.cpp @@ -19,21 +19,21 @@ * * * Contact information: contact@sofa-framework.org * ******************************************************************************/ -#include +#include namespace sofa::core::behavior { -int BaseConstraint::getGroup() const +int BaseLagrangianConstraint::getGroup() const { return group.getValue(); } -void BaseConstraint::setGroup(int g) +void BaseLagrangianConstraint::setGroup(int g) { group.setValue(g); } -void BaseConstraint::getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks, +void BaseLagrangianConstraint::getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas) { SOFA_UNUSED(cParams); @@ -45,14 +45,14 @@ void BaseConstraint::getConstraintInfo(const ConstraintParams* cParams, VecConst } -void BaseConstraint::getConstraintResolution(const ConstraintParams* cParams, +void BaseLagrangianConstraint::getConstraintResolution(const ConstraintParams* cParams, std::vector& resTab, unsigned& offset) { getConstraintResolution(resTab, offset); SOFA_UNUSED(cParams); } -void BaseConstraint::getConstraintResolution(std::vector& resTab, unsigned& offset) +void BaseLagrangianConstraint::getConstraintResolution(std::vector& resTab, unsigned& offset) { SOFA_UNUSED(resTab); SOFA_UNUSED(offset); diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.h new file mode 100644 index 00000000000..49eeb0cea1b --- /dev/null +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.h @@ -0,0 +1,123 @@ +/****************************************************************************** +* SOFA, Simulation Open-Framework Architecture * +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Authors: The SOFA Team and external contributors (see Authors.txt) * +* * +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include +#include + +namespace sofa::core::behavior +{ + +/** + * \brief Component computing constraints within a simulated body. + * + * This class defines the abstract API common to all constraints. + * A BaseConstraint computes constraints applied to one or more simulated body + * given its current position and velocity. + * + * Constraints can be internal to a given body (attached to one MechanicalState, + * see the Constraint class), or link several bodies together (such as contacts, + * see the InteractionConstraint class). + * + */ +class SOFA_CORE_API BaseLagrangianConstraint : public BaseConstraintSet +{ +public: + SOFA_ABSTRACT_CLASS(BaseLagrangianConstraint, BaseConstraintSet); + SOFA_BASE_CAST_IMPLEMENTATION(BaseLagrangianConstraint) + +protected: + BaseLagrangianConstraint() {} + ~BaseLagrangianConstraint() override {} + +private: + BaseLagrangianConstraint(const BaseLagrangianConstraint& n) = delete ; + BaseLagrangianConstraint& operator=(const BaseLagrangianConstraint& n) = delete ; + +public: + /// Get the ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle. + int getGroup() const; + + /// Set the ID of the group containing this constraint. This ID is used to specify which constraints are solved by which solver, by specifying in each solver which groups of constraints it should handle. + void setGroup(int g); + + typedef long long PersistentID; + typedef type::vector VecPersistentID; + typedef type::Vec<3,int> ConstCoord; + typedef type::vector VecConstCoord; + typedef type::Vec<3,double> ConstDeriv; + typedef type::vector VecConstDeriv; + typedef double ConstArea; + typedef type::vector VecConstArea; + + class ConstraintBlockInfo + { + public: + BaseLagrangianConstraint* parent; + int const0; ///< index of first constraint + int nbLines; ///< how many dofs (i.e. lines in the matrix) are used by each constraint + int nbGroups; ///< how many groups of constraints are active + bool hasId; ///< true if this constraint has persistent ID information + bool hasPosition; ///< true if this constraint has coordinates information + bool hasDirection; ///< true if this constraint has direction information + bool hasArea; ///< true if this constraint has area information + int offsetId; ///< index of first constraint group info in vector of persistent ids and coordinates + int offsetPosition; ///< index of first constraint group info in vector of coordinates + int offsetDirection; ///< index of first constraint info in vector of directions + int offsetArea; ///< index of first constraint group info in vector of areas + ConstraintBlockInfo() : parent(nullptr), const0(0), nbLines(1), nbGroups(0), hasId(false), hasPosition(false), hasDirection(false), hasArea(false), offsetId(0), offsetPosition(0), offsetDirection(0), offsetArea(0) + {} + }; + typedef type::vector VecConstraintBlockInfo; + + /// Get information for each constraint: pointer to parent BaseConstraint, unique persistent ID, 3D position + /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) and resolution parameters (smoothness, ...) + virtual void getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas); + + /// Add the corresponding ConstraintResolution using the offset parameter + /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) and resolution parameters (smoothness, ...) + /// \param resTab is the result vector that contains the constraint resolution algorithms + virtual void getConstraintResolution(const ConstraintParams* cParams, std::vector &resTab, unsigned int &offset); + + virtual void getConstraintResolution(std::vector &resTab, unsigned int &offset); + + type::vector getIdentifiers() + { + type::vector ids = getBaseConstraintIdentifiers(); + ids.push_back("Base"); + return ids; + } + + virtual type::vector getBaseConstraintIdentifiers() = 0; + + + /// Store the constraint lambda at the constraint dofs at the given VecDerivId location. + /// res = J^t * lambda. + /// J is the sparse matrix containing the constraint jacobian that was used to build the constraint matrix ( see BaseConstraintSet::buildConstraintMatrix ). + /// \param cParams stores the id of the state vectors used during the constraint solving step. Mostly it helps retrieving the MatrixDerivId where + /// the constraint jacobian J is stored. + /// \param res is the state vector Id where to store the result. + /// \param lambda is the vector of scalar constraint impulses. The direction are stored in the MatrixDerivId stored in the cParams. + virtual void storeLambda(const ConstraintParams* cParams, MultiVecDerivId res, const sofa::linearalgebra::BaseVector* lambda) = 0; +}; + +} // namespace sofa::core::behavior diff --git a/Sofa/framework/Core/src/sofa/core/behavior/Constraint.h b/Sofa/framework/Core/src/sofa/core/behavior/Constraint.h index bc3c0a8ab35..8a4e5b8c722 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Constraint.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/Constraint.h @@ -22,10 +22,11 @@ #pragma once #include -#include +#include #include #include +#include namespace sofa::core::behavior { @@ -40,10 +41,10 @@ namespace sofa::core::behavior * */ template -class Constraint : public BaseConstraint, public SingleStateAccessor +class Constraint : public BaseLagrangianConstraint, public SingleStateAccessor { public: - SOFA_CLASS2(SOFA_TEMPLATE(Constraint, DataTypes), BaseConstraint, SOFA_TEMPLATE(SingleStateAccessor, DataTypes)); + SOFA_CLASS2(SOFA_TEMPLATE(Constraint, DataTypes), BaseLagrangianConstraint, SOFA_TEMPLATE(SingleStateAccessor, DataTypes)); typedef typename DataTypes::Real Real; typedef typename DataTypes::VecCoord VecCoord; diff --git a/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl b/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl index caffaa4828e..6bb9dd604f7 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Sofa/framework/Core/src/sofa/core/behavior/fwd.h b/Sofa/framework/Core/src/sofa/core/behavior/fwd.h index 11019c4f5d2..a6c4927f9ac 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/fwd.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/fwd.h @@ -24,7 +24,7 @@ namespace sofa::core::behavior { class BaseAnimationLoop; - class BaseConstraint; + class BaseLagrangianConstraint; class BaseConstraintCorrection; class BaseController; class BaseForceField; diff --git a/Sofa/framework/Core/src/sofa/core/config.h.in b/Sofa/framework/Core/src/sofa/core/config.h.in index a444e394817..e4729fee84d 100644 --- a/Sofa/framework/Core/src/sofa/core/config.h.in +++ b/Sofa/framework/Core/src/sofa/core/config.h.in @@ -125,3 +125,11 @@ #define SOFA_ATTRIBUTE_DISABLED__MAPPING_JACOBIAN() SOFA_ATTRIBUTE_DISABLED("v24.12", "v25.06", "Use the variable sofa::core::vec_id::read_access::mappingJacobian or sofa::core::vec_id::write_access::mappingJacobian instead") #endif + + +#ifdef SOFA_BUILD_SOFA_CORE +#define SOFA_ATTRIBUTE_DEPRECATED__TOBASECONSTRAINT() +#else +#define SOFA_ATTRIBUTE_DEPRECATED__TOBASECONSTRAINT() \ + SOFA_ATTRIBUTE_DEPRECATED("v25.06", "v26.06", "Use toBaseLagrangianConstraint instead.") +#endif diff --git a/Sofa/framework/Core/src/sofa/core/fwd.cpp b/Sofa/framework/Core/src/sofa/core/fwd.cpp index f9f2a857d1a..6a2de45217e 100644 --- a/Sofa/framework/Core/src/sofa/core/fwd.cpp +++ b/Sofa/framework/Core/src/sofa/core/fwd.cpp @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include diff --git a/Sofa/framework/Core/src/sofa/core/fwd.h b/Sofa/framework/Core/src/sofa/core/fwd.h index 83dcd7fec12..622a30e1394 100644 --- a/Sofa/framework/Core/src/sofa/core/fwd.h +++ b/Sofa/framework/Core/src/sofa/core/fwd.h @@ -100,7 +100,7 @@ class BaseForceField; class BaseMass; class BaseMechanicalState; class BaseAnimationLoop; -class BaseConstraint; +class BaseLagrangianConstraint; class BaseConstraintSet; class ConstraintSolver; class ConstraintResolution; diff --git a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.h b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.h index ab1acf57676..4ba0325664b 100644 --- a/Sofa/framework/Core/src/sofa/core/objectmodel/Base.h +++ b/Sofa/framework/Core/src/sofa/core/objectmodel/Base.h @@ -425,7 +425,7 @@ class SOFA_CORE_API Base : public IntrusiveObject SOFA_BASE_CAST_DEFINITION( behavior, BaseProjectiveConstraintSet ) SOFA_BASE_CAST_DEFINITION( behavior, BaseInteractionProjectiveConstraintSet ) SOFA_BASE_CAST_DEFINITION( behavior, BaseConstraintSet ) - SOFA_BASE_CAST_DEFINITION( behavior, BaseConstraint ) + SOFA_BASE_CAST_DEFINITION( behavior, BaseLagrangianConstraint ) SOFA_BASE_CAST_DEFINITION( visual, VisualModel ) SOFA_BASE_CAST_DEFINITION( visual, VisualManager ) SOFA_BASE_CAST_DEFINITION( visual, VisualLoop ) @@ -442,6 +442,9 @@ class SOFA_CORE_API Base : public IntrusiveObject #undef SOFA_BASE_CAST_DEFINITION + SOFA_ATTRIBUTE_DEPRECATED__TOBASECONSTRAINT() virtual const behavior::BaseLagrangianConstraint* toBaseConstraint() const { return toBaseLagrangianConstraint(); } \ + SOFA_ATTRIBUTE_DEPRECATED__TOBASECONSTRAINT() virtual behavior::BaseLagrangianConstraint* toBaseConstraint() { return toBaseLagrangianConstraint(); } + /// @} }; diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetConstraintInfoVisitor.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetConstraintInfoVisitor.cpp index e4b183d8da8..b9070897f84 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetConstraintInfoVisitor.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetConstraintInfoVisitor.cpp @@ -41,7 +41,7 @@ MechanicalGetConstraintInfoVisitor::MechanicalGetConstraintInfoVisitor(const cor Visitor::Result MechanicalGetConstraintInfoVisitor::fwdConstraintSet(simulation::Node* node, core::behavior::BaseConstraintSet* cSet) { - if (core::behavior::BaseConstraint *c=cSet->toBaseConstraint()) + if (core::behavior::BaseLagrangianConstraint *c=cSet->toBaseLagrangianConstraint()) { const ctime_t t0 = begin(node, c); c->getConstraintInfo(_cparams, _blocks, _ids, _positions, _directions, _areas); diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetConstraintInfoVisitor.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetConstraintInfoVisitor.h index 26b64c84fe5..5a5a73e7001 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetConstraintInfoVisitor.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetConstraintInfoVisitor.h @@ -22,18 +22,18 @@ #pragma once #include -#include +#include namespace sofa::simulation::mechanicalvisitor { class SOFA_SIMULATION_CORE_API MechanicalGetConstraintInfoVisitor : public simulation::BaseMechanicalVisitor { public: - typedef core::behavior::BaseConstraint::VecConstraintBlockInfo VecConstraintBlockInfo; - typedef core::behavior::BaseConstraint::VecPersistentID VecPersistentID; - typedef core::behavior::BaseConstraint::VecConstCoord VecConstCoord; - typedef core::behavior::BaseConstraint::VecConstDeriv VecConstDeriv; - typedef core::behavior::BaseConstraint::VecConstArea VecConstArea; + typedef core::behavior::BaseLagrangianConstraint::VecConstraintBlockInfo VecConstraintBlockInfo; + typedef core::behavior::BaseLagrangianConstraint::VecPersistentID VecPersistentID; + typedef core::behavior::BaseLagrangianConstraint::VecConstCoord VecConstCoord; + typedef core::behavior::BaseLagrangianConstraint::VecConstDeriv VecConstDeriv; + typedef core::behavior::BaseLagrangianConstraint::VecConstArea VecConstArea; MechanicalGetConstraintInfoVisitor(const core::ConstraintParams* params, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas); From 799f7c27674aa67326c61bc0c72c0ebf1f710650 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 14 May 2025 11:53:52 +0200 Subject: [PATCH 13/18] 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 0e3854201af26dcb6ebde177dffe32cb72372187 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Wed, 14 May 2025 12:06:37 +0200 Subject: [PATCH 14/18] Fix compilation CUDA --- .../SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/plugins/SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl b/applications/plugins/SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl index 617699b79b5..23b60031211 100644 --- a/applications/plugins/SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl +++ b/applications/plugins/SofaCUDA/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 62e691d6725192748e94d29727e363c548732060 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Thu, 15 May 2025 16:04:08 +0200 Subject: [PATCH 15/18] fix CUDA compilation on doGetElementMass --- .../SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/plugins/SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl b/applications/plugins/SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl index 23b60031211..ac27f18d80c 100644 --- a/applications/plugins/SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl +++ b/applications/plugins/SofaCUDA/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); } From b9da001b499ec703edfde08b67177aae499ba8b8 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 27 May 2025 22:32:34 +0200 Subject: [PATCH 16/18] Apply changes on SofaDistanceGrid --- .../forcefield/DistanceGridForceField.h | 2 +- .../forcefield/DistanceGridForceField.inl | 41 +++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.h b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.h index ab1ceadead0..0296bbca247 100644 --- a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.h +++ b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.h @@ -213,7 +213,7 @@ class DistanceGridForceField : public core::behavior::ForceField void addForce(const sofa::core::MechanicalParams* /*mparams*/, DataVecDeriv & dataF, const DataVecCoord & dataX , const DataVecDeriv & dataV ) override; void addDForce(const sofa::core::MechanicalParams* mparams, DataVecDeriv& datadF , const DataVecDeriv& datadX ) override; - void addKToMatrix(const sofa::core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; + void addKToMatrix(sofa::linearalgebra::BaseMatrix * matrix, SReal kFact, unsigned int &offset) override; SReal getPotentialEnergy(const core::MechanicalParams* /*mparams*/, const DataVecCoord& /* x */) const override { msg_warning() << "Get potentialEnergy not implemented"; diff --git a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.inl b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.inl index 0c544cd8453..d54f9656a4e 100644 --- a/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.inl +++ b/applications/plugins/SofaDistanceGrid/src/SofaDistanceGrid/components/forcefield/DistanceGridForceField.inl @@ -393,31 +393,28 @@ void DistanceGridForceField::addDForce(const sofa::core::MechanicalPa } template -void DistanceGridForceField::addKToMatrix(const sofa::core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) +void DistanceGridForceField::addKToMatrix(sofa::linearalgebra::BaseMatrix * mat, SReal kFactor, unsigned int &offset) { - sofa::core::behavior::MultiMatrixAccessor::MatrixRef r = matrix->getMatrix(this->mstate); - Real kFactor = (Real)sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams, this->rayleighStiffness.getValue()); - unsigned int &offset = r.offset; - sofa::linearalgebra::BaseMatrix* mat = r.matrix; + if (!grid) + return; - if (r) + const sofa::type::vector& contacts = this->contacts.getValue(); + + if (contacts.empty()) + return; + + for (unsigned int i=0; i& contacts = this->contacts.getValue(); - if (contacts.empty()) return; - for (unsigned int i=0; iadd(offset + p*Deriv::total_size + l, offset + p*Deriv::total_size + c, coef); - } - } + const Contact& c = contacts[i]; + const int p = c.index; + const Real fact = (Real)(c.fact * -kFactor); + const Deriv& normal = c.normal; + for (sofa::Size l=0; ladd(offset + p*Deriv::total_size + l, offset + p*Deriv::total_size + c, coef); + } } } From 794fe864b1d819eb9b6249c83e79c527827dd42e Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 6 Jan 2026 10:22:24 +0100 Subject: [PATCH 17/18] update version of change --- .../src/sofa/core/behavior/BaseForceField.h | 14 +++++------ .../Core/src/sofa/core/behavior/BaseMass.h | 24 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h index f40d8adb963..3252bbaf670 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h @@ -73,7 +73,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// @{ /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doAddForce" internally, @@ -105,7 +105,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor virtual void addForce(const MechanicalParams* mparams, MultiVecDerivId fId ) final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doAddDForce" internally, @@ -159,7 +159,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor virtual void addMBKdx(const MechanicalParams* mparams, MultiVecDerivId dfId); /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doGetPotentialEnergy" internally, @@ -180,7 +180,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// @{ /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doAddKToMatrix" internally, @@ -195,7 +195,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor virtual void addKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ) final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doAddBToMatrix" internally, @@ -219,7 +219,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor virtual void addMBKToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix ); /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doBuildStiffnessMatrix" internally, @@ -230,7 +230,7 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor virtual void buildStiffnessMatrix(StiffnessMatrix* matrix) final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doBuildDampingMatrix" internally, diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h index e32e90b70fd..dca10a427d1 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h @@ -71,7 +71,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor /// @{ /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doAddMDx", internally, @@ -83,7 +83,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual void addMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doAccFromF", internally, @@ -95,7 +95,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doAddGravityToV", internally, @@ -109,7 +109,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual void addGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doGetKineticEnergy", internally, @@ -121,7 +121,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual SReal getKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doGetPotentialEnergy", internally, @@ -133,7 +133,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual SReal getPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doGetMomentum", internally, @@ -150,7 +150,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor /// @{ /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doAddMToMatrix", internally, @@ -166,7 +166,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual void addMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doBuildMassMatrix", internally, @@ -179,7 +179,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor /// @} /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doInitGnuplot", internally, @@ -191,7 +191,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual void initGnuplot(const std::string path) final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doExportGnuplot", internally, @@ -203,7 +203,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual void exportGnuplot(const MechanicalParams* mparams, SReal time) final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doGetElementMass", internally, @@ -215,7 +215,7 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual SReal getElementMass(sofa::Index index) const final; /** - * !!! WARNING since v25.12 !!! + * !!! WARNING since v26.06 !!! * * The template method pattern has been applied to this part of the API. * This method calls the newly introduced method "doGetElementMass", internally, From 0adb8ddece6d52d4ca88e3044077a32f6cb020e2 Mon Sep 17 00:00:00 2001 From: hugtalbot Date: Tue, 6 Jan 2026 10:25:23 +0100 Subject: [PATCH 18/18] remove forgotten unresolved conflicts --- .../core/behavior/BaseLagrangianConstraint.h | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.h index 5f6a8015c39..ad0bbaec94f 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseLagrangianConstraint.h @@ -62,15 +62,6 @@ class SOFA_CORE_API BaseLagrangianConstraint : public BaseConstraintSet typedef long long PersistentID; typedef type::vector VecPersistentID; -<<<<<<< HEAD - typedef type::Vec<3,int> ConstCoord; - typedef type::vector VecConstCoord; - typedef type::Vec<3,double> ConstDeriv; - typedef type::vector VecConstDeriv; - typedef double ConstArea; - typedef type::vector VecConstArea; -======= ->>>>>>> master class ConstraintBlockInfo { @@ -80,38 +71,22 @@ class SOFA_CORE_API BaseLagrangianConstraint : public BaseConstraintSet int nbLines; ///< how many dofs (i.e. lines in the matrix) are used by each constraint int nbGroups; ///< how many groups of constraints are active bool hasId; ///< true if this constraint has persistent ID information -<<<<<<< HEAD - bool hasPosition; ///< true if this constraint has coordinates information - bool hasDirection; ///< true if this constraint has direction information - bool hasArea; ///< true if this constraint has area information - int offsetId; ///< index of first constraint group info in vector of persistent ids and coordinates - int offsetPosition; ///< index of first constraint group info in vector of coordinates - int offsetDirection; ///< index of first constraint info in vector of directions - int offsetArea; ///< index of first constraint group info in vector of areas - ConstraintBlockInfo() : parent(nullptr), const0(0), nbLines(1), nbGroups(0), hasId(false), hasPosition(false), hasDirection(false), hasArea(false), offsetId(0), offsetPosition(0), offsetDirection(0), offsetArea(0) -======= int offsetId; ///< index of first constraint group info in vector of persistent ids and coordinates ConstraintBlockInfo() : parent(nullptr), const0(0), nbLines(1), nbGroups(0), hasId(false), offsetId(0) ->>>>>>> master {} }; typedef type::vector VecConstraintBlockInfo; /// Get information for each constraint: pointer to parent BaseConstraint, unique persistent ID, 3D position /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) and resolution parameters (smoothness, ...) -<<<<<<< HEAD - virtual void getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas); -======= virtual void getConstraintInfo(const ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids); - //DEPRECATED(v25.06, v25.12) typedef sofa::type::vector> VecConstCoord; typedef sofa::type::vector> VecConstDeriv; typedef sofa::type::vector VecConstArea; SOFA_ATTRIBUTE_DISABLED__DELETED_ARGUMENTS() virtual void getConstraintInfo(const core::ConstraintParams* cParams, VecConstraintBlockInfo& blocks, VecPersistentID& ids, VecConstCoord& positions, VecConstDeriv& directions, VecConstArea& areas) final = delete; ->>>>>>> master /// Add the corresponding ConstraintResolution using the offset parameter /// \param cParams defines the state vectors to use for positions and velocities. Also defines the order of the constraint (POS, VEL, ACC) and resolution parameters (smoothness, ...)