diff --git a/Sofa/Component/Mass/Testing/src/sofa/component/mass/testing/MassTestCreation.h b/Sofa/Component/Mass/Testing/src/sofa/component/mass/testing/MassTestCreation.h index e706e7999f7..180d74764c8 100644 --- a/Sofa/Component/Mass/Testing/src/sofa/component/mass/testing/MassTestCreation.h +++ b/Sofa/Component/Mass/Testing/src/sofa/component/mass/testing/MassTestCreation.h @@ -77,7 +77,7 @@ struct Mass_test : public sofa::testing::BaseSimulationTest, public sofa::testin bool m_debug; ///< Print debug messages. Default is false. /// } - bool m_testAccFromF { true }; + bool m_testSolveLinearSystem { true }; bool m_testAddMToMatrix { true }; bool m_testBuildMassMatrix { true }; bool m_testKineticEnergy { true }; @@ -238,11 +238,11 @@ struct Mass_test : public sofa::testing::BaseSimulationTest, public sofa::testin checkKineticEnergy(v, n, mparams, Mv); } - // 2. Test accFromF: a = M^-1 * f + // 2. Test solveLinearSystem: a = M^-1 * f // a = M^-1 * (M * v) should be v - if (m_testAccFromF) + if (m_testSolveLinearSystem) { - m_mass->accFromF(&mparams, sofa::core::vec_id::write_access::force); + m_mass->solveLinearSystem(&mparams, sofa::core::vec_id::write_access::force, sofa::core::vec_id::read_access::force); VecDeriv a; sofa::testing::copyFromData(a, m_dof->readForces()); @@ -251,7 +251,7 @@ struct Mass_test : public sofa::testing::BaseSimulationTest, public sofa::testin * std::max((SReal)1, (SReal)this->vectorMaxAbs(v)); EXPECT_LT((SReal)this->vectorMaxDiff(a, v), tolerance) - << "accFromF inconsistent with addMDx (M^-1 * M * v != v)"; + << "solveLinearSystem inconsistent with addMDx (M^-1 * M * v != v)"; } sofa::SignedIndex matrixSize = (sofa::SignedIndex)(n * DataTypes::deriv_total_size); diff --git a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h index e54db5c837c..618b769286f 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.h @@ -293,7 +293,7 @@ class DiagonalMass : public core::behavior::Mass, public virtual sofa // -- Mass interface void addMDx(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecDeriv& dx, SReal factor) override; - void accFromF(const core::MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f) override; + void doSolveLinearSystem(const core::MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f) override; void addForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl index 3ec1e820647..c92deda2879 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/DiagonalMass.inl @@ -561,7 +561,7 @@ void DiagonalMass::addMDx(const core::MechanicalPar template -void DiagonalMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& a, const DataVecDeriv& f) +void DiagonalMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& a, const DataVecDeriv& f) { const MassVector &masses= d_vertexMass.getValue(); diff --git a/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.h b/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.h index 25523754ace..b5d4eb50194 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.h @@ -148,7 +148,6 @@ class FEMMass : */ void addMDx(const core::MechanicalParams* mparams, DataVecDeriv_t& f, const DataVecDeriv_t& dx, SReal factor) override; - using Inherit1::accFromF; /** * @brief Compute $ a = M^{-1} f $ if the mass matrix is lumped. Triggers an error otherwise. * @@ -156,7 +155,7 @@ class FEMMass : * @param a The result vector of $M^{-1} f$. * @param f The vector to be multiplied by the inverse mass matrix. */ - void accFromF(const core::MechanicalParams* mparams, DataVecDeriv_t& a, const DataVecDeriv_t& f) override; + void doSolveLinearSystem(const core::MechanicalParams* mparams, DataVecDeriv_t& a, const DataVecDeriv_t& f) override; using Inherit1::getKineticEnergy; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl index 8655dcedf50..91ebbf3e9b4 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/FEMMass.inl @@ -299,7 +299,7 @@ void FEMMass::addMDx(const core::MechanicalParams* mpa } template -void FEMMass::accFromF(const core::MechanicalParams* mparams, +void FEMMass::doSolveLinearSystem(const core::MechanicalParams* mparams, DataVecDeriv_t& a, const DataVecDeriv_t& f) { @@ -310,7 +310,7 @@ void FEMMass::accFromF(const core::MechanicalParams* m if (!d_lumping.getValue()) { - msg_error() << "the method 'accFromF' can't be used with this component as this " + msg_error() << "the method 'solveLinearSystem' can't be used with this component as this " "SPARSE mass matrix can't be inversed easily. Enable 'lumping' instead."; return; } diff --git a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h index eac01a2eedf..86dc2a10c58 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.h @@ -200,8 +200,7 @@ class MeshMatrixMass : public core::behavior::Mass, public virtual co using Inherited::addMDx; void addMDx(const core::MechanicalParams*, DataVecDeriv& f, const DataVecDeriv& dx, SReal factor) override; - using Inherited::accFromF; - void accFromF(const core::MechanicalParams*, DataVecDeriv& a, const DataVecDeriv& f) override; // This function can't be used as it use M^-1 + void doSolveLinearSystem(const core::MechanicalParams*, DataVecDeriv& a, const DataVecDeriv& f) override; // This function can't be used as it use M^-1 void addForce(const core::MechanicalParams*, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl index 4ff3efb67e3..eeb7a34a52a 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/MeshMatrixMass.inl @@ -2048,12 +2048,12 @@ void MeshMatrixMass::addMDx(const core::MechanicalP template -void MeshMatrixMass::accFromF(const core::MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f) +void MeshMatrixMass::doSolveLinearSystem(const core::MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f) { SOFA_UNUSED(mparams); if( !isLumped() ) { - msg_error() << "the method 'accFromF' can't be used with MeshMatrixMass as this SPARSE mass matrix can't be inversed easily. " + msg_error() << "the method 'solveLinearSystem' can't be used with MeshMatrixMass as this SPARSE mass matrix can't be inversed easily. " << "Please proceed to mass lumping or use a DiagonalMass (both are equivalent)."; return; } diff --git a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h index e5ce1c12bf3..78f8edecf92 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.h @@ -131,8 +131,7 @@ class UniformMass : public core::behavior::Mass, public virtual core: using Inherited::addMDx; void addMDx(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecDeriv& dx, SReal factor) override; - using Inherited::accFromF; - void accFromF(const core::MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f) override; + void doSolveLinearSystem(const core::MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f) override; void addForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override; using Inherited::getKineticEnergy; diff --git a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl index 97296af7047..5650f6d0e1f 100644 --- a/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl +++ b/Sofa/Component/Mass/src/sofa/component/mass/UniformMass.inl @@ -420,7 +420,7 @@ void UniformMass::addMDx ( const core::MechanicalParams*, DataVecDeri template -void UniformMass::accFromF ( const core::MechanicalParams*, DataVecDeriv& va, const DataVecDeriv& vf ) +void UniformMass::doSolveLinearSystem ( const core::MechanicalParams*, DataVecDeriv& va, const DataVecDeriv& vf ) { if (!this->isComponentStateValid()) return; diff --git a/Sofa/Component/Mass/tests/MassTestCreation[FEMMass].cpp b/Sofa/Component/Mass/tests/MassTestCreation[FEMMass].cpp index caa8d9bee0e..9fb842fa1e4 100644 --- a/Sofa/Component/Mass/tests/MassTestCreation[FEMMass].cpp +++ b/Sofa/Component/Mass/tests/MassTestCreation[FEMMass].cpp @@ -46,7 +46,7 @@ struct ElementMass_template_test : public Mass_testm_testAccFromF = false; + this->m_testSolveLinearSystem = false; this->m_testAddMToMatrix = false; this->m_errorMax = 1e2_sreal; diff --git a/Sofa/Component/Mass/tests/MassTestCreation[MeshMatrixMass].cpp b/Sofa/Component/Mass/tests/MassTestCreation[MeshMatrixMass].cpp index 55d51ae57a4..15119adeaed 100644 --- a/Sofa/Component/Mass/tests/MassTestCreation[MeshMatrixMass].cpp +++ b/Sofa/Component/Mass/tests/MassTestCreation[MeshMatrixMass].cpp @@ -64,7 +64,7 @@ struct MeshMatrixMass_template_test : public Mass_test m_topology->computeCrossElementBuffers(); - this->m_testAccFromF = lumped; + this->m_testSolveLinearSystem = lumped; this->m_mass->d_lumping.setValue(lumped); this->run_test(x, v); 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..5027c28acee 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 @@ -82,7 +82,7 @@ class HexahedralFEMForceFieldAndMass : virtual public sofa::core::behavior::Mass ///// WARNING this method only add diagonal elements in the given matrix ! void addMBKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override; - void accFromF(const core::MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f) override; + void doSolveLinearSystem(const core::MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f) override; void addForce(const core::MechanicalParams* mparams, DataVecDeriv& f, const DataVecCoord& x, const DataVecDeriv& v) override; diff --git a/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl b/Sofa/Component/SolidMechanics/FEM/Elastic/src/sofa/component/solidmechanics/fem/elastic/HexahedralFEMForceFieldAndMass.inl index eccde4589d2..4081771f99b 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 @@ -385,9 +385,9 @@ void HexahedralFEMForceFieldAndMass::addMBKToMatrix (const core::Mech template -void HexahedralFEMForceFieldAndMass::accFromF(const core::MechanicalParams*, DataVecDeriv& /*a*/, const DataVecDeriv& /*f*/) +void HexahedralFEMForceFieldAndMass::doSolveLinearSystem(const core::MechanicalParams*, DataVecDeriv& /*a*/, const DataVecDeriv& /*f*/) { - msg_error() << "HexahedralFEMForceFieldAndMass::accFromF not yet implemented"; + msg_error() << "HexahedralFEMForceFieldAndMass::solveLinearSystem not yet implemented"; // need to built the big global mass matrix and to inverse it... } 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 ae9160a0161..3c403973206 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 @@ -87,7 +87,7 @@ class HexahedronFEMForceFieldAndMass : virtual public core::behavior::Mass::buildMassMatrix(sofa::core::beha } template -void HexahedronFEMForceFieldAndMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& /*a*/, const DataVecDeriv& /*f*/) +void HexahedronFEMForceFieldAndMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& /*a*/, const DataVecDeriv& /*f*/) { - msg_warning()<<"HexahedronFEMForceFieldAndMass::accFromF not yet implemented"<::solveLinearSystem not yet implemented"<getPotentialEnergy(mparams, mparams->x()); } +void BaseMass::accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) +{ + solveLinearSystem(mparams, aid, mparams->f()); +} + void BaseMass::buildMassMatrix(sofa::core::behavior::MassMatrixAccumulator* matrices) { static std::set hasEmittedWarning; diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h index 258622f10d5..ae60269f8a2 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseMass.h @@ -62,7 +62,15 @@ class SOFA_CORE_API BaseMass : public virtual StateAccessor virtual void addMDx(const MechanicalParams* mparams, MultiVecDerivId fid, SReal factor) =0; /// dx = M^-1 f - virtual void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) = 0; + SOFA_CORE_DEPRECATED_ACCFROMF() + virtual void accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) final; + + /// Solve M x = b, or x = M^-1 b, where M is the mass matrix + /// + /// Warning: this method is only implemented in derived classes when the mass matrix is trivial + /// (for example, diagonal mass matrices), allowing for efficient linear system solving. In the + /// other cases, it may be necessary to use a more general linear solver. + virtual void solveLinearSystem(const MechanicalParams* mparams, MultiVecDerivId xId, ConstMultiVecDerivId bId) = 0; /// \brief Perform v += dt*g operation. Used if mass wants to added G separately from the other forces to v. /// diff --git a/Sofa/framework/Core/src/sofa/core/behavior/Mass.h b/Sofa/framework/Core/src/sofa/core/behavior/Mass.h index 54cbdcc9730..d97329fa710 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Mass.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/Mass.h @@ -68,14 +68,11 @@ class Mass : virtual public ForceField, public BaseMass virtual void addMDx(const MechanicalParams* mparams, DataVecDeriv& f, const DataVecDeriv& dx, SReal factor); - /// $ dx = M^-1 f $ - /// - /// 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; - + SOFA_CORE_DEPRECATED_ACCFROMF() virtual void accFromF(const MechanicalParams* mparams, DataVecDeriv& a, const DataVecDeriv& f); + void solveLinearSystem(const MechanicalParams* mparams, MultiVecDerivId xId, ConstMultiVecDerivId bId) override; + virtual void doSolveLinearSystem(const MechanicalParams* mparams, DataVecDeriv& x, const DataVecDeriv& b); /// Mass forces (gravity) often have null derivative void addDForce(const MechanicalParams* /*mparams*/, DataVecDeriv & /*df*/, const DataVecDeriv & /*dx*/ ) override; diff --git a/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl b/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl index af7659392ba..59cf2be1de0 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/Mass.inl @@ -64,26 +64,40 @@ void Mass::addMDx(const MechanicalParams* /*mparams*/, DataVecDeriv& msg_warning() << "Method addMDx(const MechanicalParams* , DataVecDeriv& , const DataVecDeriv& , SReal ) not implemented."; } - template -void Mass::accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) +void Mass::accFromF(const MechanicalParams* /*mparams*/, DataVecDeriv& /*a*/, const DataVecDeriv& /*f*/) +{ + msg_warning() << "Method accFromF(const MechanicalParams* , DataVecDeriv& , const DataVecDeriv& ) not implemented."; +} + +template +void Mass::solveLinearSystem(const MechanicalParams* mparams, + MultiVecDerivId xId, ConstMultiVecDerivId bId) { if(mparams) { auto mstate = this->mstate.get(); - accFromF(mparams, *aid[mstate].write(), *mparams->readF(mstate)); + + DataVecDeriv* x = xId[mstate].write(); assert(x); + const DataVecDeriv* b = bId[mstate].read(); assert(b); + + doSolveLinearSystem(mparams, *x, *b); } - else msg_error() <<"Mass::accFromF(const MechanicalParams* mparams, MultiVecDerivId aid) receives no mparam"; } -template -void Mass::accFromF(const MechanicalParams* /*mparams*/, DataVecDeriv& /*a*/, const DataVecDeriv& /*f*/) +template +void Mass::doSolveLinearSystem(const MechanicalParams* mparams, + DataVecDeriv& x, const DataVecDeriv& b) { - msg_warning() << "Method accFromF(const MechanicalParams* , DataVecDeriv& , const DataVecDeriv& ) not implemented."; -} + SOFA_UNUSED(mparams); + SOFA_UNUSED(x); + SOFA_UNUSED(b); + msg_warning() << "Method 'solveLinearSystem' was called but it is not implemented for '" << + this->getClassName() << "'. Behavior is undefined. Try using a linear solver."; +} -template +template void Mass::addDForce(const MechanicalParams* mparams, DataVecDeriv & /*df*/, const DataVecDeriv & /*dx*/) { diff --git a/Sofa/framework/Core/src/sofa/core/config.h.in b/Sofa/framework/Core/src/sofa/core/config.h.in index d022d8f9e02..afd55c8aa26 100644 --- a/Sofa/framework/Core/src/sofa/core/config.h.in +++ b/Sofa/framework/Core/src/sofa/core/config.h.in @@ -153,3 +153,10 @@ SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.12", "Use BaseContext instead of Contex #define SOFA_CORE_DEPRECATED_RESETVEC() \ SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.12", "Use resetVec instead.") #endif + +#ifdef SOFA_BUILD_SOFA_CORE +#define SOFA_CORE_DEPRECATED_ACCFROMF() +#else +#define SOFA_CORE_DEPRECATED_ACCFROMF() \ +SOFA_ATTRIBUTE_DISABLED("v26.12", "v27.06", "Use solveLinearSystem instead of accFromF.") +#endif diff --git a/Sofa/framework/Simulation/Core/CMakeLists.txt b/Sofa/framework/Simulation/Core/CMakeLists.txt index b6b136c30f2..0d8e20a8f04 100644 --- a/Sofa/framework/Simulation/Core/CMakeLists.txt +++ b/Sofa/framework/Simulation/Core/CMakeLists.txt @@ -92,7 +92,6 @@ set(HEADER_FILES ${SRC_ROOT}/mappinggraph/VisitorApplication.h ${SRC_ROOT}/mappinggraph/MappingGraphUser.h - ${SRC_ROOT}/mechanicalvisitor/MechanicalAccFromFVisitor.h ${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateJacobian.h ${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateJacobian.h ${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateMatrixDeriv.h @@ -118,6 +117,7 @@ set(HEADER_FILES ${SRC_ROOT}/mechanicalvisitor/MechanicalIdentityBlocksInJacobianVisitor.h ${SRC_ROOT}/mechanicalvisitor/MechanicalIntegrateConstraintVisitor.h ${SRC_ROOT}/mechanicalvisitor/MechanicalIntegrationVisitor.h + ${SRC_ROOT}/mechanicalvisitor/MechanicalMassLinearSolveVisitor.h ${SRC_ROOT}/mechanicalvisitor/MechanicalMultiVectorFromBaseVectorVisitor.h ${SRC_ROOT}/mechanicalvisitor/MechanicalMultiVectorPeqBaseVectorVisitor.h ${SRC_ROOT}/mechanicalvisitor/MechanicalMultiVectorToBaseVectorVisitor.h @@ -246,7 +246,6 @@ set(SOURCE_FILES ${SRC_ROOT}/mappinggraph/MappingGraphVisitor.cpp ${SRC_ROOT}/mappinggraph/MappingGraphUser.cpp - ${SRC_ROOT}/mechanicalvisitor/MechanicalAccFromFVisitor.cpp ${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateJacobian.cpp ${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateJacobian.cpp ${SRC_ROOT}/mechanicalvisitor/MechanicalAccumulateMatrixDeriv.cpp @@ -272,6 +271,7 @@ set(SOURCE_FILES ${SRC_ROOT}/mechanicalvisitor/MechanicalIdentityBlocksInJacobianVisitor.cpp ${SRC_ROOT}/mechanicalvisitor/MechanicalIntegrateConstraintVisitor.cpp ${SRC_ROOT}/mechanicalvisitor/MechanicalIntegrationVisitor.cpp + ${SRC_ROOT}/mechanicalvisitor/MechanicalMassLinearSolveVisitor.cpp ${SRC_ROOT}/mechanicalvisitor/MechanicalMultiVectorFromBaseVectorVisitor.cpp ${SRC_ROOT}/mechanicalvisitor/MechanicalMultiVectorPeqBaseVectorVisitor.cpp ${SRC_ROOT}/mechanicalvisitor/MechanicalMultiVectorToBaseVectorVisitor.cpp @@ -345,6 +345,8 @@ set(DEPRECATED_HEADER_FILES ${DEPRECATED_DIR}/TaskSchedulerRegistry.h ${DEPRECATED_DIR}/UpdateMappingEndEvent.h ${DEPRECATED_DIR}/WorkerThread.h + + ${DEPRECATED_DIR}/mechanicalvisitor/MechanicalAccFromFVisitor.h ) sofa_find_package(Sofa.Core REQUIRED) diff --git a/Sofa/framework/Simulation/Core/compat/sofa/simulation/mechanicalvisitor/MechanicalAccFromFVisitor.h b/Sofa/framework/Simulation/Core/compat/sofa/simulation/mechanicalvisitor/MechanicalAccFromFVisitor.h new file mode 100644 index 00000000000..947cf9a2ed3 --- /dev/null +++ b/Sofa/framework/Simulation/Core/compat/sofa/simulation/mechanicalvisitor/MechanicalAccFromFVisitor.h @@ -0,0 +1,24 @@ +/****************************************************************************** +* 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 +SOFA_HEADER_DEPRECATED("v26.12", "v27.06", "sofa/simulation/mechanicalvisitor/MechanicalMassLinearSolveVisitor.h") diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.cpp index 79d700ab702..8f1755fc9e7 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -250,7 +250,7 @@ void MechanicalOperations::accFromF(core::MultiVecDerivId a, core::ConstMultiVec setDx(a); setF(f); - executeVisitor( MechanicalAccFromFVisitor(&mparams, a) ); + executeVisitor( MechanicalMassLinearSolveVisitor(&mparams, a, f) ); } /// Compute the current force (given the latest propagated position and velocity) diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in b/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in index 726be46e134..41ee2907c0d 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in @@ -297,7 +297,7 @@ #else #define SOFA_ATTRIBUTE_DEPRECATED__MECHANICALPROPAGATEDXANDRESETFORCEVISITOR() \ SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.06", "`MechanicalPropagateDxAndResetForceVisitor` was not used. If you need it, use DifferentialOperations::pushforwardTangent.") -#endif +#endif #ifdef SOFA_BUILD_SOFA_SIMULATION_CORE #define SOFA_ATTRIBUTE_DEPRECATED__MECHANICALIDENTITYBLOCKSINJACOBIANVISITOR() @@ -312,3 +312,10 @@ #define SOFA_ATTRIBUTE_DEPRECATED__MECHANICALGETMOMENTUMVISITOR() \ SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.06", "`MechanicalGetMomentumVisitor` was not used.") #endif + +#ifdef SOFA_BUILD_SOFA_SIMULATION_CORE +#define SOFA_ATTRIBUTE_DEPRECATED__MECHANICALACCFROMFVISITOR() +#else +#define SOFA_ATTRIBUTE_DEPRECATED__MECHANICALACCFROMFVISITOR() \ + SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.06", "MechanicalAccFromFVisitor is renamed to MechanicalMassLinearSolveVisitor.") +#endif diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAccFromFVisitor.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalMassLinearSolveVisitor.cpp similarity index 86% rename from Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAccFromFVisitor.cpp rename to Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalMassLinearSolveVisitor.cpp index 5ce8ff4548e..defa3c8388a 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAccFromFVisitor.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalMassLinearSolveVisitor.cpp @@ -27,15 +27,15 @@ namespace sofa::simulation::mechanicalvisitor { -Visitor::Result MechanicalAccFromFVisitor::fwdMass(simulation::Node* /*node*/, core::behavior::BaseMass* mass) +Visitor::Result MechanicalMassLinearSolveVisitor::fwdMass(simulation::Node* /*node*/, core::behavior::BaseMass* mass) { - mass->accFromF(mparams, a); + mass->solveLinearSystem(mparams, x, b); return RESULT_CONTINUE; } -std::string MechanicalAccFromFVisitor::getInfos() const +std::string MechanicalMassLinearSolveVisitor::getInfos() const { - std::string name="a["+a.getName()+"] f["+mparams->f().getName()+"]"; return name; + std::string name="x["+x.getName()+"] b["+b.getName()+"]"; return name; } } diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAccFromFVisitor.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalMassLinearSolveVisitor.h similarity index 79% rename from Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAccFromFVisitor.h rename to Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalMassLinearSolveVisitor.h index 230bb3bf971..5ac099a91a0 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalAccFromFVisitor.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalMassLinearSolveVisitor.h @@ -26,15 +26,17 @@ namespace sofa::simulation::mechanicalvisitor { -/** Compute accelerations generated by given forces +/** Solves a linear system where the matrix is the mass matrix */ -class SOFA_SIMULATION_CORE_API MechanicalAccFromFVisitor : public MechanicalVisitor +class SOFA_SIMULATION_CORE_API MechanicalMassLinearSolveVisitor : public MechanicalVisitor { public: - sofa::core::MultiVecDerivId a; - //ConstMultiVecDerivId f; // in MechanicalParams - MechanicalAccFromFVisitor(const sofa::core::MechanicalParams* mechaparams, sofa::core::MultiVecDerivId avecid) - : MechanicalVisitor(mechaparams), a(avecid) //, f(f) + sofa::core::MultiVecDerivId x; + sofa::core::ConstMultiVecDerivId b; + + MechanicalMassLinearSolveVisitor(const sofa::core::MechanicalParams* mechaparams, + sofa::core::MultiVecDerivId xVecId, sofa::core::ConstMultiVecDerivId bVecId) + : MechanicalVisitor(mechaparams), x(xVecId), b(bVecId) { #ifdef SOFA_DUMP_VISITOR_INFO setReadWriteVectors(); @@ -44,7 +46,7 @@ class SOFA_SIMULATION_CORE_API MechanicalAccFromFVisitor : public MechanicalVisi /// Return a class name for this visitor /// Only used for debugging / profiling purposes - const char* getClassName() const override { return "MechanicalAccFromFVisitor"; } + const char* getClassName() const override { return "MechanicalMassLinearSolveVisitor"; } virtual std::string getInfos() const override; /// Specify whether this action can be parallelized. @@ -55,10 +57,13 @@ class SOFA_SIMULATION_CORE_API MechanicalAccFromFVisitor : public MechanicalVisi #ifdef SOFA_DUMP_VISITOR_INFO void setReadWriteVectors() override { - addWriteVector(a); + addWriteVector(x); addReadVector(mparams->f()); } #endif }; +SOFA_ATTRIBUTE_DEPRECATED__MECHANICALACCFROMFVISITOR() +using MechanicalAccFromFVisitor = MechanicalMassLinearSolveVisitor; + } diff --git a/Sofa/framework/Simulation/Core/test/Visitor_test.cpp b/Sofa/framework/Simulation/Core/test/Visitor_test.cpp index 751625162b1..4df6237055e 100644 --- a/Sofa/framework/Simulation/Core/test/Visitor_test.cpp +++ b/Sofa/framework/Simulation/Core/test/Visitor_test.cpp @@ -121,10 +121,11 @@ class TestMass : public core::behavior::BaseMass SOFA_UNUSED(fid); SOFA_UNUSED(factor); } - void accFromF(const core::MechanicalParams* mparams, core::MultiVecDerivId aid) override + void solveLinearSystem(const core::MechanicalParams* mparams, core::MultiVecDerivId xId, core::ConstMultiVecDerivId bId) override { SOFA_UNUSED(mparams); - SOFA_UNUSED(aid); + SOFA_UNUSED(xId); + SOFA_UNUSED(bId); } void addGravityToV(const core::MechanicalParams* mparams, core::MultiVecDerivId vid) override { diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaDiagonalMass.h b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaDiagonalMass.h index 7b3e2dbec93..bf37a4b4df5 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaDiagonalMass.h +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaDiagonalMass.h @@ -56,7 +56,7 @@ template <> void DiagonalMass::addMDx(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecDeriv& d_dx, SReal d_factor); template <> -void DiagonalMass::accFromF(const core::MechanicalParams* mparams, DataVecDeriv& d_a, const DataVecDeriv& d_f); +void DiagonalMass::doSolveLinearSystem(const core::MechanicalParams* mparams, DataVecDeriv& d_a, const DataVecDeriv& d_f); template<> void DiagonalMass::addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v); @@ -69,7 +69,7 @@ template <> void DiagonalMass::addMDx(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecDeriv& d_dx, SReal d_factor); template <> -void DiagonalMass::accFromF(const core::MechanicalParams* mparams, DataVecDeriv& d_a, const DataVecDeriv& d_f); +void DiagonalMass::doSolveLinearSystem(const core::MechanicalParams* mparams, DataVecDeriv& d_a, const DataVecDeriv& d_f); template<> void DiagonalMass::addForce(const core::MechanicalParams* mparams, DataVecDeriv& d_f, const DataVecCoord& d_x, const DataVecDeriv& d_v); diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaDiagonalMass.inl b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaDiagonalMass.inl index 15de95a0252..38f1e95a258 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaDiagonalMass.inl +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaDiagonalMass.inl @@ -67,7 +67,7 @@ void DiagonalMass::addMDx(const core::MechanicalParams* /*mparam } template<> -void DiagonalMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) +void DiagonalMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) { VecDeriv& a = *d_a.beginEdit(); const VecDeriv& f = d_f.getValue(); @@ -120,7 +120,7 @@ void DiagonalMass::addMDx(const core::MechanicalParams* /*mparam } template<> -void DiagonalMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) +void DiagonalMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) { VecDeriv& a = *d_a.beginEdit(); const VecDeriv& f = d_f.getValue(); diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaMeshMatrixMass.h b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaMeshMatrixMass.h index d328b0b025e..f0542ccf04d 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaMeshMatrixMass.h +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaMeshMatrixMass.h @@ -50,7 +50,7 @@ template<> void MeshMatrixMass::addForce(const core::MechanicalParams*, DataVecDeriv& /*vf*/, const DataVecCoord& /* */, const DataVecDeriv& /* */); template<> -void MeshMatrixMass::accFromF(const core::MechanicalParams*, DataVecDeriv& a, const DataVecDeriv& f); +void MeshMatrixMass::doSolveLinearSystem(const core::MechanicalParams*, DataVecDeriv& a, const DataVecDeriv& f); @@ -73,7 +73,7 @@ template<> void MeshMatrixMass::addForce(const core::MechanicalParams*, DataVecDeriv& /*vf*/, const DataVecCoord& /* */, const DataVecDeriv& /* */); template<> -void MeshMatrixMass::accFromF(const core::MechanicalParams*, DataVecDeriv& a, const DataVecDeriv& f); +void MeshMatrixMass::doSolveLinearSystem(const core::MechanicalParams*, DataVecDeriv& a, const DataVecDeriv& f); @@ -96,7 +96,7 @@ template<> void MeshMatrixMass::addForce(const core::MechanicalParams*, DataVecDeriv& /*vf*/, const DataVecCoord& /* */, const DataVecDeriv& /* */); template<> -void MeshMatrixMass::accFromF(const core::MechanicalParams*, DataVecDeriv& a, const DataVecDeriv& f); +void MeshMatrixMass::doSolveLinearSystem(const core::MechanicalParams*, DataVecDeriv& a, const DataVecDeriv& f); #ifndef SOFA_GPU_CUDA_CUDAMESHMATRIXMASS_CPP diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaMeshMatrixMass.inl b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaMeshMatrixMass.inl index cf448043971..297d33dc1b7 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaMeshMatrixMass.inl +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaMeshMatrixMass.inl @@ -92,7 +92,7 @@ void MeshMatrixMass::addForce(const core::MechanicalParams* /*mp } template<> -void MeshMatrixMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& a, const DataVecDeriv& f) +void MeshMatrixMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& a, const DataVecDeriv& f) { VecDeriv& _acc = *a.beginEdit(); const VecDeriv& _f = f.getValue(); @@ -141,7 +141,7 @@ void MeshMatrixMass::addForce(const core::MechanicalParams* /*mp } template<> -void MeshMatrixMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& a, const DataVecDeriv& f) +void MeshMatrixMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& a, const DataVecDeriv& f) { VecDeriv& _acc = *a.beginEdit(); const VecDeriv& _f = f.getValue(); @@ -190,7 +190,7 @@ void MeshMatrixMass::addForce(const core::MechanicalParams* /*mp } template<> -void MeshMatrixMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& a, const DataVecDeriv& f) +void MeshMatrixMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& a, const DataVecDeriv& f) { VecDeriv& _acc = *a.beginEdit(); const VecDeriv& _f = f.getValue(); diff --git a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl index 617699b79b5..6018cee4221 100644 --- a/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl +++ b/applications/plugins/SofaCUDA/Component/src/SofaCUDA/component/mass/CudaUniformMass.inl @@ -81,7 +81,7 @@ void UniformMass::addMDx(const core::MechanicalParams* /*mparams } template <> -void UniformMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) +void UniformMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) { VecDeriv& a = *d_a.beginEdit(); const VecDeriv& f = d_f.getValue(); @@ -120,7 +120,7 @@ void UniformMass::addMDx(const core::MechanicalParams* /*mparam } template <> -void UniformMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) +void UniformMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) { VecDeriv& a = *d_a.beginEdit(); const VecDeriv& f = d_f.getValue(); @@ -163,7 +163,7 @@ void UniformMass::addMDx(const core::MechanicalPara } template<> -void UniformMass::accFromF(const core::MechanicalParams * /*mparams*/, DataVecDeriv &a, const DataVecDeriv &f) +void UniformMass::doSolveLinearSystem(const core::MechanicalParams * /*mparams*/, DataVecDeriv &a, const DataVecDeriv &f) { VecDeriv& _a = *a.beginEdit(); const VecDeriv _f = f.getValue(); @@ -256,7 +256,7 @@ void UniformMass::addMDx(const core::MechanicalParams* /*mparams } template <> -void UniformMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) +void UniformMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) { VecDeriv& a = *d_a.beginEdit(); const VecDeriv& f = d_f.getValue(); @@ -313,7 +313,7 @@ void UniformMass::addMDx(const core::MechanicalParams* /*mparam } template <> -void UniformMass::accFromF(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) +void UniformMass::doSolveLinearSystem(const core::MechanicalParams* /*mparams*/, DataVecDeriv& d_a, const DataVecDeriv& d_f) { VecDeriv& a = *d_a.beginEdit(); const VecDeriv& f = d_f.getValue();