diff --git a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h index 47c53f8f8b8..68eb629de8d 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h @@ -311,12 +311,12 @@ 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 {} - 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 390b5cb70fe..4de50b04985 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; @@ -642,7 +642,7 @@ void DiagonalMass::buildMassMatrix(sofa::core::beha 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 e67680dbcb4..12cb7445807 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h @@ -220,12 +220,12 @@ 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 {} - 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 c21e3b62d45..61511eaca5e 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(); @@ -2312,7 +2312,7 @@ void MeshMatrixMass::buildMassMatrix(sofa::core::be 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 258eb345e10..031c50b7c25 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h @@ -148,12 +148,12 @@ 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 {} - 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 13668956420..b7aa028d331 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()) { @@ -594,14 +594,14 @@ void UniformMass::buildMassMatrix(sofa::core::behavior::MassMatrixAcc 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 d6e8b1531a1..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 @@ -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) @@ -337,7 +337,7 @@ void HexahedronFEMForceFieldAndMass::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"<addMass(this); @@ -49,7 +121,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..e32e90b70fd 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h @@ -47,9 +47,21 @@ 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) 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; + virtual void doExportGnuplot(const MechanicalParams* mparams, SReal time) = 0; + virtual SReal doGetElementMass(sofa::Index index) const = 0; + virtual void doGetElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const = 0; + private: BaseMass(const BaseMass& n) = delete; BaseMass& operator=(const BaseMass& n) = delete; @@ -58,51 +70,161 @@ 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; + + /** + * !!! 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) = 0; + virtual void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) 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 "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. - virtual void addGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) = 0; + virtual void addGravityToV(const MechanicalParams* mparams, MultiVecDerivId vid) 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 "doGetKineticEnergy", internally, + * which is the method to override from now on. + * + **/ /// vMv/2 - virtual SReal getKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; + virtual SReal getKineticEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const 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 "doGetPotentialEnergy", internally, + * which is the method to override from now on. + * + **/ + /// Mgx - virtual SReal getPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const = 0; + virtual SReal getPotentialEnergy(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const 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 "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 = 0; + virtual type::Vec6 getMomentum(const MechanicalParams* mparams = mechanicalparams::defaultInstance()) const final; /// @} /// @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. /// \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 addMToMatrix(const MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) final; - virtual void buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices); + /** + * !!! 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; /// @} + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doInitGnuplot", internally, + * which is the method to override from now on. + * + **/ + /// initialization to export kinetic and potential energy to gnuplot files format - virtual void initGnuplot(const std::string path)=0; + virtual void initGnuplot(const std::string path) 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 "doExportGnuplot", internally, + * which is the method to override from now on. + * + **/ /// export kinetic and potential energy state at "time" to a gnuplot file - virtual void exportGnuplot(const MechanicalParams* mparams, SReal time)=0; + virtual void exportGnuplot(const MechanicalParams* mparams, SReal time) 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 "doGetElementMass", internally, + * which is the method to override from now on. + * + **/ /// Get the mass relative to the DOF at \a index. - virtual SReal getElementMass(sofa::Index index) const =0; + virtual SReal getElementMass(sofa::Index index) const 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 "doGetElementMass", internally, + * which is the method to override from now on. + * + **/ + /// Get the matrix relative to the DOF at \a index. - virtual void getElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const = 0; + virtual void getElementMass(sofa::Index index, linearalgebra::BaseMatrix *m) const final; virtual bool isDiagonal() const = 0; diff --git a/Sofa/framework/Core/src/sofa/core/behavior/Mass.h b/Sofa/framework/Core/src/sofa/core/behavior/Mass.h index 1dec7f93119..a2d6f03bdf2 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Mass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/Mass.h @@ -54,17 +54,26 @@ class Mass : virtual public ForceField, public BaseMass protected: Mass(MechanicalState *mm = nullptr); - ~Mass() override; + 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 $ /// /// 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 +81,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 +105,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 +121,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 +134,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); @@ -140,19 +149,19 @@ 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 addGravityToV(const MechanicalParams* mparams, MultiVecDerivId /*vid*/) override; + void doAddGravityToV(const MechanicalParams* mparams, MultiVecDerivId /*vid*/) override; virtual void addGravityToV(const MechanicalParams* /* mparams */, DataVecDeriv& /* d_v */); /// 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 88f94b7bea5..6bb9dd604f7 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,16 +182,12 @@ 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"; } template -void Mass::initGnuplot(const std::string path) +void Mass::doInitGnuplot(const std::string path) { if (!this->getName().empty()) { @@ -207,26 +199,26 @@ 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) { - (*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; } } 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); diff --git a/applications/plugins/SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl b/applications/plugins/SofaCUDA/src/SofaCUDA/component/mass/CudaUniformMass.inl index 617699b79b5..ac27f18d80c 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); } @@ -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); }