diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp index 2d7a2781d1c..2fdddfd1e8a 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.cpp @@ -35,6 +35,12 @@ BaseForceField::BaseForceField() { } +void BaseForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId) +{ + assert(mparams); + this->addDForce(mparams, dfId, mparams->dx(), mparams->x(), mparams->v()); +} + void BaseForceField::addMBKdx(const MechanicalParams* mparams, MultiVecDerivId dfId) { const auto kFactor = sofa::core::mechanicalparams::kFactorIncludingRayleighDamping(mparams,rayleighStiffness.getValue()); @@ -42,7 +48,8 @@ void BaseForceField::addMBKdx(const MechanicalParams* mparams, MultiVecDerivId d if (kFactor != 0.0 || bFactor != 0.0) { - addDForce(mparams, dfId); + assert(mparams); + addDForce(mparams, dfId, mparams->dx(), mparams->x(), mparams->v()); } } diff --git a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h index 76c2fc2361b..2db133df726 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/BaseForceField.h @@ -96,17 +96,26 @@ class SOFA_CORE_API BaseForceField : public virtual StateAccessor /// /// If the ForceField can be represented as a matrix, this method computes /// \f[ - /// df += kFactor K dx + bFactor B dx + /// df += kFactor K(x) dx + bFactor B(v) dx /// \f] /// where K is the stiffness matrix (associated with forces which derive from a potential), /// and B is the damping matrix (associated with viscous forces). /// /// \param mparams - /// - \a mparams->mFactor() is the coefficient for mass contributions (i.e. second-order derivatives term in the ODE) - /// - \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; + /// - \a mparams->mFactor() is the coefficient for mass contributions (i.e. second-order + /// derivatives term in the ODE) + /// - \a mparams->kFactor() is the coefficient for stiffness contributions (i.e. DOFs term in + /// the ODE) + /// \param dfId the cotangent output vector + /// \param dxId the tangent input vector + /// \param xId the position input vector + /// \param vId the velocity input vector + virtual void addDForce(const MechanicalParams* mparams, + MultiVecDerivId dfId, ConstMultiVecDerivId dxId, + ConstMultiVecCoordId xId, ConstMultiVecDerivId vId) = 0; + + SOFA_ATTRIBUTE_DEPRECATED__ADDDFORCE_OVERLOAD() + 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. diff --git a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h index 91e87c4abeb..b672093d26a 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/ForceField.h @@ -99,7 +99,8 @@ class ForceField : public BaseForceField, public virtual SingleStateAccessor::addForce(const MechanicalParams* mparams, MultiVecDe } template -void ForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) +void ForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId, + ConstMultiVecDerivId dxId, ConstMultiVecCoordId xId, ConstMultiVecDerivId vId) { if (mparams && this->mstate) { @@ -60,7 +61,19 @@ void ForceField::addDForce(const MechanicalParams* mparams, MultiVecD mparams->setKFactorUsed(false); #endif - addDForce(mparams, *dfId[this->mstate.get()].write(), *mparams->readDx(this->mstate.get())); + Data* df = dfId[this->mstate.get()].write(); assert(df); + const Data* dx = dxId[this->mstate.get()].read(); assert(dx); + const Data* x = xId[this->mstate.get()].read(); assert(x); + const Data* v = vId[this->mstate.get()].read(); assert(v); + + const AddDForceVectors vectors { + .df = *df, + .dx = *dx, + .x = *x, + .v = *v + }; + + doAddDForce(mparams, vectors); #ifndef NDEBUG if (!mparams->getKFactorUsed()) @@ -76,7 +89,14 @@ void ForceField::addDForce(const MechanicalParams* mparams, MultiVecD } } -template +template +void ForceField::doAddDForce(const MechanicalParams* mparams, const AddDForceVectors& vectors) +{ + // compatibility with legacy `addDForce`. + addDForce(mparams, vectors.df, vectors.dx); +} + +template SReal ForceField::getPotentialEnergy(const MechanicalParams* mparams) const { if (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 4dc05954b5f..4f6fadbc163 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.h @@ -90,12 +90,9 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair /// explicitly (i.e. using its value at the beginning of the timestep). /// /// If the ForceField can be represented as a matrix, this method computes - /// $ df += kFactor K dx + bFactor B dx $ - /// - /// 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; + /// $ df += kFactor K(x) dx + bFactor B(v) dx $ + void addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId, ConstMultiVecDerivId dxId, + ConstMultiVecCoordId xId, ConstMultiVecDerivId vId) override; /// Get the potential energy associated to this ForceField. @@ -132,7 +129,12 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair /// /// This method must be implemented by the component, and is usually called /// by the generic MixedInteractionForceField::addDForce() method. - + /// + /// + /// ******************** WARNING ******************** + /// This overload is deprecated!!! Use `doAddDForce` instead. + /// + SOFA_ATTRIBUTE_DEPRECATED__ADDDFORCE_DERIVED() 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. @@ -155,6 +157,27 @@ class MixedInteractionForceField : public BaseInteractionForceField, public Pair BaseMechanicalState* getMechModel1() override { return Inherit2::getMechModel1(); } BaseMechanicalState* getMechModel2() override { return Inherit2::getMechModel2(); } + +protected: + + // all vectors involved in the addDForce operation + template + struct AddDForceVectors + { + sofa::DataVecDeriv_t& df; + const sofa::DataVecDeriv_t& dx; + const sofa::DataVecCoord_t& x; + const sofa::DataVecDeriv_t& v; + }; + + // Computes df += kFactor K(x) dx + bFactor B(v) dx + // with: + // K the derivative of the forces wrt the position + // B the derivative of the forces wrt the velocity + virtual void doAddDForce(const MechanicalParams* mparams, + const AddDForceVectors& vectors1, + const AddDForceVectors& vectors2); + }; #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..95a5b65002a 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/MixedInteractionForceField.inl @@ -58,19 +58,50 @@ void MixedInteractionForceField::addForce(const Mechanic } template -void MixedInteractionForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) +void MixedInteractionForceField::addDForce(const MechanicalParams* mparams, + MultiVecDerivId dfId, ConstMultiVecDerivId dxId, ConstMultiVecCoordId xId, ConstMultiVecDerivId vId) { if (this->mstate1 && this->mstate2) { auto state1 = this->mstate1.get(); auto state2 = this->mstate2.get(); - addDForce( mparams, - *dfId[state1].write() , *dfId[state2].write() , - *mparams->readDx(state1) , *mparams->readDx(state2) ); + + Data* df1 = dfId[state1].write(); assert(df1); + Data* df2 = dfId[state2].write(); assert(df2); + + const Data* dx1 = dxId[state1].read(); assert(dx1); + const Data* dx2 = dxId[state2].read(); assert(dx2); + + const Data* x1 = xId[state1].read(); assert(x1); + const Data* x2 = xId[state2].read(); assert(x2); + + const Data* v1 = vId[state1].read(); assert(v1); + const Data* v2 = vId[state2].read(); assert(v2); + + const AddDForceVectors vectors1 { + .df = *df1, + .dx = *dx1, + .x = *x1, + .v = *v1 + }; + + const AddDForceVectors vectors2 { + .df = *df2, + .dx = *dx2, + .x = *x2, + .v = *v2 + }; + + doAddDForce(mparams, vectors1, vectors2); } } - +template +void MixedInteractionForceField::doAddDForce( + const MechanicalParams* mparams, const AddDForceVectors& vectors1, + const AddDForceVectors& vectors2) +{ +} template SReal MixedInteractionForceField::getPotentialEnergy(const MechanicalParams* mparams) const diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h index 20db861a697..b3ca0b4feb1 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.h @@ -103,12 +103,13 @@ class PairInteractionForceField : public BaseInteractionForceField, public PairS /// explicitly (i.e. using its value at the beginning of the timestep). /// /// If the ForceField can be represented as a matrix, this method computes - /// $ df += kFactor K dx + bFactor B dx $ + /// $ df += kFactor K(x) dx + bFactor B(v) dx $ /// /// 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 addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId, ConstMultiVecDerivId dxId, + ConstMultiVecCoordId xId, ConstMultiVecDerivId vId) override; /// Compute the force derivative given a small displacement from the /// position and velocity used in the previous call to addForce(). @@ -123,10 +124,12 @@ class PairInteractionForceField : public BaseInteractionForceField, public PairS /// This method must be implemented by the component, and is usually called /// by the generic PairInteractionForceField::addDForce() method. /// - /// To support old components that implement the deprecated addForce method - /// without scalar coefficients, it defaults to using a temporaty vector to - /// compute $ K dx $ and then manually scaling all values by kFactor. - + /// + /// + /// ******************** WARNING ******************** + /// This overload is deprecated!!! Use `doAddDForce` instead. + /// + SOFA_ATTRIBUTE_DEPRECATED__ADDDFORCE_DERIVED() virtual void addDForce(const MechanicalParams* mparams, DataVecDeriv& df1, DataVecDeriv& df2, const DataVecDeriv& dx1, const DataVecDeriv& dx2)=0; @@ -218,6 +221,24 @@ class PairInteractionForceField : public BaseInteractionForceField, public PairS return name; } +protected: + + // all vectors involved in the addDForce operation + struct AddDForceVectors + { + DataVecDeriv& df; + const DataVecDeriv& dx; + const DataVecCoord& x; + const DataVecDeriv& v; + }; + + // Computes df += kFactor K(x) dx + bFactor B(v) dx + // with: + // K the derivative of the forces wrt the position + // B the derivative of the forces wrt the velocity + virtual void doAddDForce(const MechanicalParams* mparams, + const AddDForceVectors& vectors1, const AddDForceVectors& vectors2); + }; #if !defined(SOFA_CORE_BEHAVIOR_PAIRINTERACTIONFORCEFIELD_CPP) diff --git a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl index 61e666c2e87..c028745c4ad 100644 --- a/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl +++ b/Sofa/framework/Core/src/sofa/core/behavior/PairInteractionForceField.inl @@ -61,20 +61,54 @@ void PairInteractionForceField::addForce(const MechanicalParams* mpar } template -void PairInteractionForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId ) +void PairInteractionForceField::addDForce(const MechanicalParams* mparams, MultiVecDerivId dfId, + ConstMultiVecDerivId dxId, ConstMultiVecCoordId xId, ConstMultiVecDerivId vId) { auto state1 = this->mstate1.get(); - auto state2 = this->mstate2.get(); + auto state2 = this->mstate2.get(); if (state1 && state2) { - addDForce( - mparams, *dfId[state1].write(), *dfId[state2].write(), - *mparams->readDx(state1), *mparams->readDx(state2)); + Data* df1 = dfId[state1].write(); assert(df1); + Data* df2 = dfId[state2].write(); assert(df2); + + const Data* dx1 = dxId[state1].read(); assert(dx1); + const Data* dx2 = dxId[state2].read(); assert(dx2); + + const Data* x1 = xId[state1].read(); assert(x1); + const Data* x2 = xId[state2].read(); assert(x2); + + const Data* v1 = vId[state1].read(); assert(v1); + const Data* v2 = vId[state2].read(); assert(v2); + + const AddDForceVectors vectors1 { + .df = *df1, + .dx = *dx1, + .x = *x1, + .v = *v1 + }; + + const AddDForceVectors vectors2 { + .df = *df2, + .dx = *dx2, + .x = *x2, + .v = *v2 + }; + + doAddDForce(mparams, vectors1, vectors2); } else msg_error() << "PairInteractionForceField::addDForce(const MechanicalParams* /*mparams*/, MultiVecDerivId /*fId*/ ), mstate missing"; } +template +void PairInteractionForceField::doAddDForce(const MechanicalParams* mparams, + const AddDForceVectors& vectors1, + const AddDForceVectors& vectors2) +{ + // compatibility with legacy `addDForce`. + addDForce(mparams, vectors1.df, vectors2.df, vectors1.dx, vectors2.dx); +} + template SReal PairInteractionForceField::getPotentialEnergy(const MechanicalParams* mparams) const { diff --git a/Sofa/framework/Core/src/sofa/core/config.h.in b/Sofa/framework/Core/src/sofa/core/config.h.in index 2215e894724..e7ab007943d 100644 --- a/Sofa/framework/Core/src/sofa/core/config.h.in +++ b/Sofa/framework/Core/src/sofa/core/config.h.in @@ -127,3 +127,17 @@ SOFA_ATTRIBUTE_DEPRECATED("v26.06", "v29.06", "Use toBaseComponent instead.") #define SOFA_CORE_DEPRECATED_RENAME_CREATORMAP_OBJECTTEMPLATECREATORMAP() \ SOFA_ATTRIBUTE_DISABLED("v25.12", "v26.06", "Type CreatorMap has been renamed to ObjectTemplateCreatorMap.") #endif + +#ifdef SOFA_BUILD_SOFA_CORE +#define SOFA_ATTRIBUTE_DEPRECATED__ADDDFORCE_OVERLOAD() +#else +#define SOFA_ATTRIBUTE_DEPRECATED__ADDDFORCE_OVERLOAD() \ + SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.06", "addDForce must be used by providing the dx, x and v vectors.") +#endif + +#ifdef SOFA_BUILD_SOFA_CORE +#define SOFA_ATTRIBUTE_DEPRECATED__ADDDFORCE_DERIVED() +#else +#define SOFA_ATTRIBUTE_DEPRECATED__ADDDFORCE_DERIVED() \ + SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.06", "Use doAddDForce instead.") +#endif diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.cpp index d6c0e0b020d..5030a28e0ae 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.cpp @@ -259,9 +259,15 @@ void MechanicalOperations::computeForce(core::MultiVecDerivId result, bool clear executeVisitor( MechanicalComputeForceVisitor(&mparams, result, accumulate) ); } - -/// Compute the current force delta (given the latest propagated displacement) void MechanicalOperations::computeDf(core::MultiVecDerivId df, bool clear, bool accumulate) +{ + computeDf(df, sofa::core::vec_id::read_access::dx, + sofa::core::vec_id::read_access::position, + sofa::core::vec_id::read_access::velocity, + clear, accumulate); +} + +void MechanicalOperations::computeDf(core::MultiVecDerivId df, core::ConstMultiVecDerivId dx, core::ConstMultiVecCoordId x, core::ConstMultiVecDerivId v, bool clear, bool accumulate) { setDf(df); if (clear) @@ -269,22 +275,14 @@ void MechanicalOperations::computeDf(core::MultiVecDerivId df, bool clear, bool executeVisitor( MechanicalResetForceVisitor(&mparams, df, false) ); // finish(); } - executeVisitor( MechanicalComputeDfVisitor( &mparams, df, accumulate) ); + executeVisitor( MechanicalComputeDfVisitor( &mparams, df, dx, x, v, accumulate) ); } /// Compute the current force delta (given the latest propagated velocity) void MechanicalOperations::computeDfV(core::MultiVecDerivId df, bool clear, bool accumulate) { - const core::ConstMultiVecDerivId dx = mparams.dx(); - mparams.setDx(mparams.v()); - setDf(df); - if (clear) - { - executeVisitor( MechanicalResetForceVisitor(&mparams, df, false) ); - //finish(); - } - executeVisitor( MechanicalComputeDfVisitor(&mparams, df, accumulate) ); - mparams.setDx(dx); + computeDf(df, mparams.v(), sofa::core::vec_id::read_access::position, + sofa::core::vec_id::read_access::velocity, clear, accumulate); } /// accumulate $ df += (m M + b B + k K) dx $ (given the latest propagated displacement) diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.h index be3e21be8ef..dd38e4d25e9 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/MechanicalOperations.h @@ -80,9 +80,11 @@ class SOFA_SIMULATION_CORE_API MechanicalOperations void computeEnergy(SReal &kineticEnergy, SReal &potentialEnergy); /// Compute the current force (given the latest propagated position and velocity) void computeForce(core::MultiVecDerivId result, bool clear = true, bool accumulate = true); - /// Compute the current force delta (given the latest propagated displacement) + /// Compute the current force delta, (given the latest propagated displacement) SOFA_ATTRIBUTE_DEPRECATED__MECHANICALOPERATIONS_COMPUTEDF() void computeDf(core::MultiVecDerivId df, bool clear = true, bool accumulate = true); + /// Compute the current force delta, given the provided propagated displacement + void computeDf(core::MultiVecDerivId df, core::ConstMultiVecDerivId dx, core::ConstMultiVecCoordId x, core::ConstMultiVecDerivId v, bool clear = true, bool accumulate = true); /// Compute the current force delta (given the latest propagated velocity) SOFA_ATTRIBUTE_DEPRECATED__MECHANICALOPERATIONS_COMPUTEDFV() void computeDfV(core::MultiVecDerivId df, bool clear = true, bool accumulate = true); 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 2210ab92bdc..500a83fda98 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in @@ -213,3 +213,17 @@ #define SOFA_ATTRIBUTE_DEPRECATED__MECHANICALOPERATIONS_PRINTWITHELAPSEDTIME() \ SOFA_ATTRIBUTE_DISABLED("v26.12", "v27.06", "This method is unused.") #endif + +#ifdef SOFA_BUILD_SOFA_SIMULATION_CORE +#define SOFA_ATTRIBUTE_DEPRECATED__COMPUTEDF_OVERLOAD() +#else +#define SOFA_ATTRIBUTE_DEPRECATED__COMPUTEDF_OVERLOAD() \ + SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.06", "computeDf must be used by providing the dx vector.") +#endif + +#ifdef SOFA_BUILD_SOFA_SIMULATION_CORE +#define SOFA_ATTRIBUTE_DEPRECATED__COMPUTEDFVISITOR_CONSTRUCTOR_OVERLOAD() +#else +#define SOFA_ATTRIBUTE_DEPRECATED__COMPUTEDFVISITOR_CONSTRUCTOR_OVERLOAD() \ + SOFA_ATTRIBUTE_DEPRECATED("v26.12", "v27.06", "Constructor must be used by providing the dx vector.") +#endif diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.cpp index 8f8200fb06d..4304ca04852 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.cpp @@ -29,7 +29,7 @@ namespace sofa::simulation::mechanicalvisitor Visitor::Result MechanicalComputeDfVisitor::fwdForceField(simulation::Node* /*node*/, core::behavior::BaseForceField* ff) { - ff->addDForce(this->mparams, res); + ff->addDForce(this->mparams, res, dx, x, v); return RESULT_CONTINUE; } diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.h index 0c0d9c588cb..b88b913a3d3 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalComputeDfVisitor.h @@ -33,21 +33,39 @@ class SOFA_SIMULATION_CORE_API MechanicalComputeDfVisitor : public MechanicalVis { public: sofa::core::MultiVecDerivId res; + sofa::core::ConstMultiVecDerivId dx; + sofa::core::ConstMultiVecCoordId x; + sofa::core::ConstMultiVecDerivId v; bool accumulate; ///< Accumulate everything back to the DOFs through the mappings - MechanicalComputeDfVisitor(const sofa::core::MechanicalParams* mechaparams, sofa::core::MultiVecDerivId resvecid) - : MechanicalVisitor(mechaparams) , res(resvecid), accumulate(true) + + MechanicalComputeDfVisitor(const sofa::core::MechanicalParams* mechaparams, + sofa::core::MultiVecDerivId resvecid, + sofa::core::ConstMultiVecDerivId dxvecid, + sofa::core::ConstMultiVecCoordId xvecid, + sofa::core::ConstMultiVecDerivId vvecid, + bool bAccumulate = true + ) + : MechanicalVisitor(mechaparams) , res(resvecid), dx(dxvecid), x(xvecid), v(vvecid), accumulate(bAccumulate) { #ifdef SOFA_DUMP_VISITOR_INFO setReadWriteVectors(); #endif } - MechanicalComputeDfVisitor(const sofa::core::MechanicalParams* mechaparams, sofa::core::MultiVecDerivId resvecid, bool bAccumulate) - : MechanicalVisitor(mechaparams) , res(resvecid), accumulate(bAccumulate) + + SOFA_ATTRIBUTE_DEPRECATED__COMPUTEDFVISITOR_CONSTRUCTOR_OVERLOAD() + MechanicalComputeDfVisitor(const sofa::core::MechanicalParams* mechaparams, + sofa::core::MultiVecDerivId resvecid, + bool bAccumulate = true + ) + : MechanicalVisitor(mechaparams) , + res(resvecid), + dx(mechaparams ? mechaparams->dx() : core::vec_id::read_access::dx), accumulate(bAccumulate) { #ifdef SOFA_DUMP_VISITOR_INFO setReadWriteVectors(); #endif } + Result fwdForceField(simulation::Node* /*node*/,sofa::core::behavior::BaseForceField* ff) override; void bwdMechanicalMapping(simulation::Node* /*node*/, sofa::core::BaseMapping* map) override; diff --git a/Sofa/framework/Simulation/Core/test/Visitor_test.cpp b/Sofa/framework/Simulation/Core/test/Visitor_test.cpp index e3a2d2f703d..f14576a74a6 100644 --- a/Sofa/framework/Simulation/Core/test/Visitor_test.cpp +++ b/Sofa/framework/Simulation/Core/test/Visitor_test.cpp @@ -89,7 +89,7 @@ class TestForceField : public core::behavior::BaseForceField { public: void addForce(const core::MechanicalParams* mparams, core::MultiVecDerivId fId) override {} - void addDForce(const core::MechanicalParams* mparams, core::MultiVecDerivId dfId) override {} + void addDForce(const core::MechanicalParams*, core::MultiVecDerivId, core::ConstMultiVecDerivId, core::ConstMultiVecCoordId, core::ConstMultiVecDerivId) override {} SReal getPotentialEnergy(const core::MechanicalParams* mparams) const override { return {}; } void addKToMatrix(const core::MechanicalParams* mparams, const sofa::core::behavior::MultiMatrixAccessor* matrix) override {} }; @@ -115,7 +115,7 @@ class TestInteractionForceField : public core::behavior::BaseInteractionForceFie { public: void addForce(const core::MechanicalParams* mparams, core::MultiVecDerivId fId) override {} - void addDForce(const core::MechanicalParams* mparams, core::MultiVecDerivId dfId) override {} + void addDForce(const core::MechanicalParams*, core::MultiVecDerivId, core::ConstMultiVecDerivId, core::ConstMultiVecCoordId, core::ConstMultiVecDerivId) override {} SReal getPotentialEnergy(const core::MechanicalParams* mparams) const override { return {}; } };