diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.h index 236ab760b61..b18fff86608 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.h @@ -75,8 +75,6 @@ class BarycentricMapping : public LinearMapping void applyJT(const core::MechanicalParams *mparams, Data< typename In::VecDeriv >& out, const Data< typename Out::VecDeriv >& in) override; void applyJT(const core::ConstraintParams *cparams, Data< typename In::MatrixDeriv >& out, const Data< typename Out::MatrixDeriv >& in) override; - const sofa::linearalgebra::BaseMatrix* getJ() override; - virtual const type::vector* getJs() override; void draw(const core::visual::VisualParams* vparams) override; void handleTopologyChange(core::topology::Topology* t) override; @@ -94,6 +92,10 @@ class BarycentricMapping : public LinearMapping ~BarycentricMapping() override; + + const sofa::linearalgebra::BaseMatrix* doGetJ() override; + virtual const type::vector* doGetJs() override; + linearalgebra::BaseMatrix *internalMatrix; ///< internally store a matrix for getJ/Compliant type::vector< linearalgebra::BaseMatrix* > js; private: diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.inl index ef6ae436d07..0b68d56c0f6 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BarycentricMapping.inl @@ -329,7 +329,7 @@ void BarycentricMapping::applyJT (const core::MechanicalParams * mpar template -const sofa::linearalgebra::BaseMatrix* BarycentricMapping::getJ() +const sofa::linearalgebra::BaseMatrix* BarycentricMapping::doGetJ() { if (d_mapper!=nullptr ) { @@ -473,10 +473,10 @@ void BarycentricMapperTriangleSetTopology::handleTopologyChange(core::to #endif // BARYCENTRIC_MAPPER_TOPOCHANGE_REINIT template -const type::vector< linearalgebra::BaseMatrix*>* BarycentricMapping::getJs() +const type::vector< linearalgebra::BaseMatrix*>* BarycentricMapping::doGetJs() { typedef typename Mapper::MatrixType mat_type; - const sofa::linearalgebra::BaseMatrix* matJ = getJ(); + const sofa::linearalgebra::BaseMatrix* matJ = core::BaseMapping::getJ(); const auto * mat = dynamic_cast(matJ); if(mat==nullptr) diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.h index 95abbb15dc1..af863b30b8d 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.h @@ -105,9 +105,11 @@ class BeamLinearMapping : public LinearMapping void applyJT(const core::ConstraintParams *cparams, Data< typename In::MatrixDeriv >& out, const Data< typename Out::MatrixDeriv >& in) override; - const sofa::linearalgebra::BaseMatrix* getJ() override; - void draw(const core::visual::VisualParams* vparams) override; + +protected: + const sofa::linearalgebra::BaseMatrix* doGetJ() override; + }; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.inl index 99eba171599..45364012c14 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/BeamLinearMapping.inl @@ -278,7 +278,7 @@ void BeamLinearMapping::draw(const core::visual::VisualParams* vparam template -const sofa::linearalgebra::BaseMatrix* BeamLinearMapping::getJ() +const sofa::linearalgebra::BaseMatrix* BeamLinearMapping::doGetJ() { const unsigned int inStateSize = this->fromModel->getSize(); diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMulti2Mapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMulti2Mapping.h index e4ecbfc49d3..6c66686837f 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMulti2Mapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMulti2Mapping.h @@ -100,7 +100,6 @@ class CenterOfMassMulti2Mapping : public LinearMulti2Mapping msg_warning() << "This object only support Direct Solving but an Indirect Solver in the scene is calling method applyJT(constraint) which is not implemented. This will produce un-expected behavior."; } - void applyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {} void init() override; void draw(const core::visual::VisualParams* vparams) override; @@ -114,6 +113,9 @@ class CenterOfMassMulti2Mapping : public LinearMulti2Mapping virtual ~CenterOfMassMulti2Mapping() {} + void doApplyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {} + + type::vector inputBaseMass1; type::vector inputWeightedCOM1; type::vector inputWeightedForce1; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMultiMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMultiMapping.h index e6143072db6..9df98bf3acc 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMultiMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/CenterOfMassMultiMapping.h @@ -84,7 +84,6 @@ class CenterOfMassMultiMapping : public LinearMultiMapping //virtual void applyJ(const type::vector< OutVecDeriv*>& outDeriv, const type::vector& inDeriv); //virtual void applyJT( const type::vector& outDeriv , const type::vector& inDeriv ); - void applyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {} void init() override; void draw(const core::visual::VisualParams* vparams) override; @@ -98,6 +97,9 @@ class CenterOfMassMultiMapping : public LinearMultiMapping virtual ~CenterOfMassMultiMapping() {} + void doApplyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {} + + type::vector inputBaseMass; InVecCoord inputWeightedCOM; InVecDeriv inputWeightedForce; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.h index 2daa51fb3ea..7ccd8447359 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.h @@ -139,7 +139,7 @@ class DeformableOnRigidFrameMapping : public LinearMulti2Mapping& dataVecOutRootForce, const type::vector& dataVecInForce) override; - void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId inForce, core::ConstMultiVecDerivId outForce) override; + void doApplyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId inForce, core::ConstMultiVecDerivId outForce) override; //ApplyJT Constraint diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.inl index 195104551be..fc1178e6255 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DeformableOnRigidFrameMapping.inl @@ -385,7 +385,7 @@ void DeformableOnRigidFrameMapping::applyJT( } template -void DeformableOnRigidFrameMapping::applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId inForce, core::ConstMultiVecDerivId outForce) +void DeformableOnRigidFrameMapping::doApplyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId inForce, core::ConstMultiVecDerivId outForce) { SOFA_UNUSED(mparams); SOFA_UNUSED(inForce); @@ -486,9 +486,9 @@ void DeformableOnRigidFrameMapping::handleTopologyChange(cor { case core::topology::TRIANGLESADDED: ///< To notify the end for the current sequence of topological change events { - core::Multi2Mapping::apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::restPosition, core::vec_id::read_access::restPosition); + core::BaseMapping::apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::restPosition, core::vec_id::read_access::restPosition); if(this->f_applyRestPosition.getValue() ) - core::Multi2Mapping::apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::position, core::vec_id::read_access::position); + core::BaseMapping::apply(core::mechanicalparams::defaultInstance(), core::vec_id::write_access::position, core::vec_id::read_access::position); break; } default: diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DistanceToPlaneMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DistanceToPlaneMapping.h index df3382fe926..d17aaf4973e 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DistanceToPlaneMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DistanceToPlaneMapping.h @@ -52,7 +52,6 @@ class DistanceToPlaneMapping : public LinearMapping>& out, const Data>& in) override; - const linearalgebra::BaseMatrix* getJ() override; void handleTopologyChange() override; @@ -64,6 +63,7 @@ class DistanceToPlaneMapping : public LinearMapping J; }; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DistanceToPlaneMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DistanceToPlaneMapping.inl index 2e1cabe3043..031b3523392 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DistanceToPlaneMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/DistanceToPlaneMapping.inl @@ -172,7 +172,7 @@ void DistanceToPlaneMapping::applyJT(const core::ConstraintParams *cparams, } template -const linearalgebra::BaseMatrix* DistanceToPlaneMapping::getJ() +const linearalgebra::BaseMatrix* DistanceToPlaneMapping::doGetJ() { return &J; } diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMapping.h index 5b926849ced..33c467a809a 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMapping.h @@ -110,7 +110,6 @@ class IdentityMapping : public LinearMapping void applyJT(const core::ConstraintParams *cparams, Data& out, const Data& in) override; - const sofa::linearalgebra::BaseMatrix* getJ() override; void handleTopologyChange() override; @@ -123,9 +122,9 @@ class IdentityMapping : public LinearMapping typedef type::vector< linearalgebra::BaseMatrix* > js_type; js_type Js; -public: + const sofa::linearalgebra::BaseMatrix* doGetJ() override; - const js_type* getJs() override; + const js_type* doGetJs() override; }; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMapping.inl index ecfeb57aff8..b180effa9b0 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMapping.inl @@ -136,13 +136,13 @@ void IdentityMapping::handleTopologyChange() } template -const sofa::linearalgebra::BaseMatrix* IdentityMapping::getJ() +const sofa::linearalgebra::BaseMatrix* IdentityMapping::doGetJ() { return &J; } template -const typename IdentityMapping::js_type* IdentityMapping::getJs() +const typename IdentityMapping::js_type* IdentityMapping::doGetJs() { return &Js; } diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.h index 2ebb82cf83b..171020d17db 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.h @@ -70,15 +70,15 @@ class IdentityMultiMapping : public LinearMultiMapping void apply(const core::MechanicalParams* mparams, const type::vector& dataVecOutPos, const type::vector& dataVecInPos) override; void applyJ(const core::MechanicalParams* mparams, const type::vector& dataVecOutVel, const type::vector& dataVecInVel) override; void applyJT(const core::MechanicalParams* mparams, const type::vector& dataVecOutForce, const type::vector& dataVecInForce) override; - void applyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*enforce*/, core::ConstMultiVecDerivId /*outForce*/) override {} void applyJT( const core::ConstraintParams* cparams, const type::vector< InDataMatrixDeriv* >& dataMatOutConst, const type::vector< const OutDataMatrixDeriv* >& dataMatInConst ) override; - virtual const type::vector* getJs() override; protected : IdentityMultiMapping(); virtual ~IdentityMultiMapping(); + void doApplyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*enforce*/, core::ConstMultiVecDerivId /*outForce*/) override {} + virtual const type::vector* doGetJs() override; type::vector baseMatrices; ///< Jacobian of the mapping, in a vector diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.inl index 15e2fbbd233..4e4109b1b2d 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/IdentityMultiMapping.inl @@ -169,7 +169,7 @@ void IdentityMultiMapping::applyJT( const core::ConstraintParams* /*c template -const type::vector* IdentityMultiMapping::getJs() +const type::vector* IdentityMultiMapping::doGetJs() { return &baseMatrices; } diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.h index 9316c0eca42..2d2c58b80ac 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.h @@ -97,7 +97,11 @@ class SkinningMapping : public LinearMapping protected: SkinningMapping (); virtual ~SkinningMapping(); - + + // additional Compliant methods + const type::vector* doGetJs() override; + const sofa::linearalgebra::BaseMatrix* doGetJ() override; + public: void init() override; void reinit() override; @@ -114,9 +118,6 @@ class SkinningMapping : public LinearMapping void applyJT( const sofa::core::ConstraintParams* cparams, InDataMatrixDeriv& out, const OutDataMatrixDeriv& in) override; //void applyJT( typename In::MatrixDeriv& out, const typename Out::MatrixDeriv& in ); - // additional Compliant methods - const type::vector* getJs() override; - const sofa::linearalgebra::BaseMatrix* getJ() override; SeqTriangles triangles; // Topology of toModel (used for weight display) void draw(const core::visual::VisualParams* vparams) override; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl index cd664d6f130..124d8c44ab3 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl @@ -328,13 +328,13 @@ void SkinningMapping::applyJT ( const sofa::core::ConstraintParams* c } template -const sofa::type::vector* SkinningMapping::getJs() +const sofa::type::vector* SkinningMapping::doGetJs() { return new sofa::type::vector(1, (sofa::linearalgebra::BaseMatrix*)&_J); } template -const sofa::linearalgebra::BaseMatrix* SkinningMapping::getJ() +const sofa::linearalgebra::BaseMatrix* SkinningMapping::doGetJ() { return (sofa::linearalgebra::BaseMatrix*)&_J; } diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.h index 21858156950..8e55ad81c17 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.h @@ -116,13 +116,12 @@ class SubsetMapping : public LinearMapping void applyJT ( const core::ConstraintParams* /*cparams*/, InDataMatrixDeriv& dOut, const OutDataMatrixDeriv& dIn) override; - const sofa::linearalgebra::BaseMatrix* getJ() override; - -public: typedef type::vector< linearalgebra::BaseMatrix* > js_type; - const js_type* getJs() override; protected: + + const sofa::linearalgebra::BaseMatrix* doGetJ() override; + const js_type* doGetJs() override; typedef linearalgebra::EigenSparseMatrix eigen_type; eigen_type eigen; js_type js; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.inl index 3560a4cbe35..744fe751e55 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMapping.inl @@ -286,7 +286,7 @@ void SubsetMapping::applyJT ( const core::ConstraintParams * /*cparam } template -const sofa::linearalgebra::BaseMatrix* SubsetMapping::getJ() +const sofa::linearalgebra::BaseMatrix* SubsetMapping::doGetJ() { if (matrixJ.get() == 0 || updateJ) { @@ -322,7 +322,7 @@ const sofa::linearalgebra::BaseMatrix* SubsetMapping::getJ() template -const typename SubsetMapping::js_type* SubsetMapping::getJs() +const typename SubsetMapping::js_type* SubsetMapping::doGetJs() { using MatrixIndex = typename MatrixType::Index; if( !eigen.compressedMatrix.nonZeros() || updateJ ) { diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.h index 8fc5781b9a3..1c282cfa1fe 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.h @@ -56,13 +56,8 @@ class SubsetMultiMapping : public LinearMultiMapping void apply(const core::MechanicalParams* mparams, const type::vector*>& dataVecOutPos, const type::vector*>& dataVecInPos) override; void applyJ(const core::MechanicalParams* mparams, const type::vector*>& dataVecOutVel, const type::vector*>& dataVecInVel) override; void applyJT(const core::MechanicalParams* mparams, const type::vector*>& dataVecOutForce, const type::vector*>& dataVecInForce) override; - void applyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {} - void applyJT( const core::ConstraintParams* cparams, const type::vector< DataMatrixDeriv_t* >& dataMatOutConst, const type::vector< const DataMatrixDeriv_t* >& dataMatInConst ) override; - /// Experimental API used to handle multimappings in matrix assembly. Returns pointers to matrices associated with parent states, consistently with getFrom(). - virtual const type::vector* getJs() override; - Data< type::vector > d_indexPairs; ///< list of couples (parent index + index in the parent) protected : @@ -70,6 +65,10 @@ protected : SubsetMultiMapping(); virtual ~SubsetMultiMapping() override; + void doApplyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {} + /// Experimental API used to handle multimappings in matrix assembly. Returns pointers to matrices associated with parent states, consistently with getFrom(). + virtual const type::vector* doGetJs() override; + type::vector baseMatrices; ///< Jacobian of the mapping, in a vector }; diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.inl b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.inl index b788abdd744..3a3d6fc7920 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.inl +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SubsetMultiMapping.inl @@ -97,7 +97,7 @@ SubsetMultiMapping::~SubsetMultiMapping() } template -const type::vector* SubsetMultiMapping::getJs() +const type::vector* SubsetMultiMapping::doGetJs() { return &baseMatrices; } diff --git a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/VoidMapping.h b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/VoidMapping.h index 8a52296593b..d0f270636c3 100644 --- a/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/VoidMapping.h +++ b/Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/VoidMapping.h @@ -60,10 +60,6 @@ class VoidMapping : public LinearBaseMapping return vec; } - /// Disable the mapping to get the original coordinates of the mapped model. - void disable() override - { - } /// Get the source (upper) model. virtual type::vector getMechFrom() override @@ -79,43 +75,48 @@ class VoidMapping : public LinearBaseMapping return vec; } - void apply (const core::MechanicalParams* /* mparams */, core::MultiVecCoordId /* outPos */, core::ConstMultiVecCoordId /* inPos */) override + + +protected: + In* fromModel; + Out* toModel; + + VoidMapping():Inherit(),fromModel(nullptr),toModel(nullptr) { + this->f_mapForces.setValue(false); + this->f_mapConstraints.setValue(false); + this->f_mapMasses.setValue(false); } - void applyJ(const core::MechanicalParams* /* mparams */, core::MultiVecDerivId /* outVel */, core::ConstMultiVecDerivId /* inVel */) override + ~VoidMapping() override { } - - void applyJT(const core::MechanicalParams* /* mparams */, core::MultiVecDerivId /* inForce */, core::ConstMultiVecDerivId /* outForce */) override + void doApply (const core::MechanicalParams* /* mparams */, core::MultiVecCoordId /* outPos */, core::ConstMultiVecCoordId /* inPos */) override { } - void applyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {} + /// Disable the mapping to get the original coordinates of the mapped model. + void doDisable() override + { + } - void applyJT(const core::ConstraintParams * /*cparams*/, core::MultiMatrixDerivId /* inConst */, core::ConstMultiMatrixDerivId /* outConst */) override + void doApplyJ(const core::MechanicalParams* /* mparams */, core::MultiVecDerivId /* outVel */, core::ConstMultiVecDerivId /* inVel */) override { } - void computeAccFromMapping(const core::MechanicalParams* /*mparams */, core::MultiVecDerivId /* outAcc */, core::ConstMultiVecDerivId /* inVel */, core::ConstMultiVecDerivId /* inAcc */) override + void doApplyJT(const core::MechanicalParams* /* mparams */, core::MultiVecDerivId /* inForce */, core::ConstMultiVecDerivId /* outForce */) override { } -protected: - In* fromModel; - Out* toModel; + void doApplyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override {} - VoidMapping():Inherit(),fromModel(nullptr),toModel(nullptr) + void doApplyJT(const core::ConstraintParams * /*cparams*/, core::MultiMatrixDerivId /* inConst */, core::ConstMultiMatrixDerivId /* outConst */) override { - this->f_mapForces.setValue(false); - this->f_mapConstraints.setValue(false); - this->f_mapMasses.setValue(false); } - ~VoidMapping() override + void doComputeAccFromMapping(const core::MechanicalParams* /*mparams */, core::MultiVecDerivId /* outAcc */, core::ConstMultiVecDerivId /* inVel */, core::ConstMultiVecDerivId /* inAcc */) override { } - }; } // namespace sofa::component::mapping::linear diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.h index 3554709407c..f98850d3c75 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.h @@ -51,7 +51,6 @@ class AreaMapping : public BaseNonLinearMapping void init() override; void apply(const core::MechanicalParams* mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; - void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; protected: AreaMapping(); @@ -62,6 +61,7 @@ class AreaMapping : public BaseNonLinearMapping const Data >& childForce) override; using typename Inherit1::SparseKMatrixEigen; + void doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void doUpdateK( const core::MechanicalParams* mparams, const Data >& childForce, diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.inl index 636143b57b7..754435da195 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/AreaMapping.inl @@ -275,7 +275,7 @@ void AreaMapping::doUpdateK(const core::MechanicalParams* mparams, } template -void AreaMapping::buildGeometricStiffnessMatrix( +void AreaMapping::doBuildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { const unsigned& geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.h index 847c8628cdf..b8420f9c5ae 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.h @@ -50,14 +50,14 @@ class BaseNonLinearMapping : public core::Mapping, public NonLinearMa void applyJ(const core::MechanicalParams* mparams, DataVecDeriv_t& out, const DataVecDeriv_t& in) final; void applyJT(const core::MechanicalParams* mparams, DataVecDeriv_t& out, const DataVecDeriv_t& in) final; void applyJT(const core::ConstraintParams *cparams, DataMatrixDeriv_t& out, const DataMatrixDeriv_t& in) final; - void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForceId, core::ConstMultiVecDerivId childForceId) final; - const linearalgebra::BaseMatrix* getK() final; - const type::vector* getJs() override; +protected: - void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId) final; -protected: + void doApplyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForceId, core::ConstMultiVecDerivId childForceId) final; + const linearalgebra::BaseMatrix* doGetK() final; + const type::vector* doGetJs() override; + void doUpdateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId) final; using SparseKMatrixEigen = linearalgebra::EigenSparseMatrix; diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.inl index 742d3303e87..8870e952d3f 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/BaseNonLinearMapping.inl @@ -77,7 +77,7 @@ void BaseNonLinearMapping::applyJT( } template -void BaseNonLinearMapping::applyDJT( +void BaseNonLinearMapping::doApplyDJT( const core::MechanicalParams* mparams, core::MultiVecDerivId parentForceId, core::ConstMultiVecDerivId childForceId) { @@ -110,20 +110,20 @@ void BaseNonLinearMapping::applyDJT( } template -const linearalgebra::BaseMatrix* BaseNonLinearMapping::getK() +const linearalgebra::BaseMatrix* BaseNonLinearMapping::doGetK() { return &m_geometricStiffnessMatrix; } template -const type::vector* BaseNonLinearMapping::getJs() +const type::vector* BaseNonLinearMapping::doGetJs() { return &m_baseMatrices; } template void BaseNonLinearMapping:: -updateK(const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId) +doUpdateK(const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId) { const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); if( !geometricStiffness ) { this->m_geometricStiffnessMatrix.resize(0,0); return; } diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.h index b6a83b8d346..fc8bb3cad1a 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.h @@ -91,7 +91,6 @@ class DistanceFromTargetMapping : public BaseNonLinearMapping, void init() override; void apply(const core::MechanicalParams *mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; - void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void draw(const core::visual::VisualParams* vparams) override; Data d_showObjectScale; ///< Scale for object display @@ -105,6 +104,7 @@ class DistanceFromTargetMapping : public BaseNonLinearMapping, Data >& parentForce, const Data >& parentDisplacement, const Data >& childForce) override; + void doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; using typename Inherit1::SparseKMatrixEigen; diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.inl index 660ad6ed5ce..74949ee8b20 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceFromTargetMapping.inl @@ -233,7 +233,7 @@ void DistanceFromTargetMapping::matrixFreeApplyDJT( } template -void DistanceFromTargetMapping::buildGeometricStiffnessMatrix( +void DistanceFromTargetMapping::doBuildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.h index 2eaa44eb362..231007c7143 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.h @@ -70,7 +70,6 @@ class DistanceMapping : public BaseNonLinearMapping void init() override; void apply(const core::MechanicalParams *mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; - void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void computeBBox(const core::ExecParams* params, bool onlyVisible) override; void draw(const core::visual::VisualParams* vparams) override; @@ -82,6 +81,7 @@ class DistanceMapping : public BaseNonLinearMapping Data >& parentForce, const Data >& parentDisplacement, const Data >& childForce) override; + void doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; using typename Inherit1::SparseKMatrixEigen; diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.inl index 7a7cdef0967..df62de5e04d 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMapping.inl @@ -253,7 +253,7 @@ void DistanceMapping::doUpdateK( } template -void DistanceMapping::buildGeometricStiffnessMatrix( +void DistanceMapping::doBuildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { const unsigned& geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMultiMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMultiMapping.h index 763b6a752b7..4c1d65fd5aa 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMultiMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMultiMapping.h @@ -164,13 +164,6 @@ class DistanceMultiMapping : public core::MultiMapping, public Stabil virtual void applyJ(const type::vector& outDeriv, const type::vector& inDeriv); virtual void applyJT(const type::vector< InVecDeriv*>& outDeriv, const type::vector& inDeriv); void applyJT( const core::ConstraintParams* /* cparams */, const type::vector< InDataMatrixDeriv* >& /* dataMatOutConst */, const type::vector< const OutDataMatrixDeriv* >& /* dataMatInConst */ ) override {} - void applyDJT(const core::MechanicalParams*, core::MultiVecDerivId inForce, core::ConstMultiVecDerivId outForce) override; - - virtual const type::vector* getJs() override; - - void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForce ) override; - const linearalgebra::BaseMatrix* getK() override; - void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void draw(const core::visual::VisualParams* vparams) override; @@ -178,6 +171,13 @@ class DistanceMultiMapping : public core::MultiMapping, public Stabil DistanceMultiMapping(); ~DistanceMultiMapping() override; + void doApplyDJT(const core::MechanicalParams*, core::MultiVecDerivId inForce, core::ConstMultiVecDerivId outForce) override; + virtual const type::vector* doGetJs() override; + + void doUpdateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForce ) override; + const linearalgebra::BaseMatrix* doGetK() override; + void doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; + type::vector baseMatrices; ///< Jacobian of the mapping, in a vector type::vector directions; ///< Unit vectors in the directions of the lines type::vector< Real > invlengths; ///< inverse of current distances. Null represents the infinity (null distance) diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMultiMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMultiMapping.inl index 63ac9b51664..1bc798609cb 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMultiMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/DistanceMultiMapping.inl @@ -263,7 +263,7 @@ void DistanceMultiMapping::applyJT(const type::vector< InVecDeriv*>& } template -void DistanceMultiMapping::applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId inForce, core::ConstMultiVecDerivId outForce) +void DistanceMultiMapping::doApplyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId inForce, core::ConstMultiVecDerivId outForce) { SOFA_UNUSED(outForce); // NOT OPTIMIZED AT ALL, but will do the job for now @@ -344,13 +344,13 @@ void DistanceMultiMapping::applyDJT(const core::MechanicalParams* mpa template -const type::vector* DistanceMultiMapping::getJs() +const type::vector* DistanceMultiMapping::doGetJs() { return &baseMatrices; } template -void DistanceMultiMapping::updateK(const core::MechanicalParams* /*mparams*/, core::ConstMultiVecDerivId childForceId ) +void DistanceMultiMapping::doUpdateK(const core::MechanicalParams* /*mparams*/, core::ConstMultiVecDerivId childForceId ) { const unsigned& geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); if( !geometricStiffness ) { K.resize(0,0); return; } @@ -409,13 +409,13 @@ void DistanceMultiMapping::updateK(const core::MechanicalParams* /*mp template -const linearalgebra::BaseMatrix* DistanceMultiMapping::getK() +const linearalgebra::BaseMatrix* DistanceMultiMapping::doGetK() { return &K; } template -void DistanceMultiMapping::buildGeometricStiffnessMatrix( +void DistanceMultiMapping::doBuildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { const unsigned& geometricStiffness = d_geometricStiffness.getValue().getSelectedId(); diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.cpp b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.cpp index b06218c9c0e..500f65e1b98 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.cpp +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.cpp @@ -55,10 +55,10 @@ template class SOFA_COMPONENT_MAPPING_NONLINEAR_API RigidMapping< Rigid2Types, V template<> -void RigidMapping< sofa::defaulttype::Rigid2Types, sofa::defaulttype::Vec2Types >::updateK( const core::MechanicalParams* /*mparams*/, core::ConstMultiVecDerivId /*childForceId*/ ) +void RigidMapping< sofa::defaulttype::Rigid2Types, sofa::defaulttype::Vec2Types >::doUpdateK( const core::MechanicalParams* /*mparams*/, core::ConstMultiVecDerivId /*childForceId*/ ) {} template<> -const linearalgebra::BaseMatrix* RigidMapping< sofa::defaulttype::Rigid2Types, sofa::defaulttype::Vec2Types >::getK() +const linearalgebra::BaseMatrix* RigidMapping< sofa::defaulttype::Rigid2Types, sofa::defaulttype::Vec2Types >::doGetK() { msg_error() << "TODO: assembled geometric stiffness not implemented"; return nullptr; diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.h index d85fd31e496..d2fdfac8ef6 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.h @@ -122,16 +122,6 @@ class RigidMapping : public core::Mapping, public NonLinearMappingDat void applyJT(const core::ConstraintParams *cparams, Data& out, const Data& in) override; - void applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForce, core::ConstMultiVecDerivId childForce ) override; - - const sofa::linearalgebra::BaseMatrix* getJ() override; - - virtual const type::vector* getJs() override; - - void updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId ) override; - const linearalgebra::BaseMatrix* getK() override; - void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; - void draw(const core::visual::VisualParams* vparams) override; @@ -149,6 +139,15 @@ class RigidMapping : public core::Mapping, public NonLinearMappingDat void updateOmega(typename InDeriv::Rot& omega, const OutDeriv& out, const OutCoord& rotatedpoint); protected: + + void doApplyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForce, core::ConstMultiVecDerivId childForce ) override; + const sofa::linearalgebra::BaseMatrix* doGetJ() override; + virtual const type::vector* doGetJs() override; + void doUpdateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId ) override; + const linearalgebra::BaseMatrix* doGetK() override; + void doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; + + class Loader; void load(const char* filename); @@ -170,9 +169,9 @@ template struct RigidMappingMatrixHelper; template<> SOFA_COMPONENT_MAPPING_NONLINEAR_API -void RigidMapping< sofa::defaulttype::Rigid2Types, sofa::defaulttype::Vec2Types >::updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId ); +void RigidMapping< sofa::defaulttype::Rigid2Types, sofa::defaulttype::Vec2Types >::doUpdateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId ); template<> SOFA_COMPONENT_MAPPING_NONLINEAR_API -const linearalgebra::BaseMatrix* RigidMapping< sofa::defaulttype::Rigid2Types, sofa::defaulttype::Vec2Types >::getK(); +const linearalgebra::BaseMatrix* RigidMapping< sofa::defaulttype::Rigid2Types, sofa::defaulttype::Vec2Types >::doGetK(); #if !defined(SOFA_COMPONENT_MAPPING_RIGIDMAPPING_CPP) extern template class SOFA_COMPONENT_MAPPING_NONLINEAR_API RigidMapping< sofa::defaulttype::Rigid3Types, sofa::defaulttype::Vec3Types >; diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.inl index 5ecfca122ca..670a5f030e8 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/RigidMapping.inl @@ -357,7 +357,7 @@ void RigidMapping::applyJT(const core::MechanicalParams * /*mparams*/ } template -void RigidMapping::applyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForceChangeId, core::ConstMultiVecDerivId childForceId) +void RigidMapping::doApplyDJT(const core::MechanicalParams* mparams, core::MultiVecDerivId parentForceChangeId, core::ConstMultiVecDerivId childForceId) { if( !d_geometricStiffness.getValue().getSelectedId() ) return; @@ -373,7 +373,7 @@ void RigidMapping::applyDJT(const core::MechanicalParams* mparams, co // if symmetrized version, force local assembly if( d_geometricStiffness.getValue().getSelectedId() == 2 ) { - updateK( mparams, childForceId ); + core::BaseMapping::updateK( mparams, childForceId ); auto InF = sofa::helper::getWriteOnlyAccessor(*parentForceChangeId[this->fromModel.get()].write()); auto inDx = sofa::helper::getReadAccessor(*mparams->readDx(this->fromModel.get())); @@ -509,7 +509,7 @@ void fill_block(Eigen::Matrix& block, const Coord& v) { } template -const type::vector* RigidMapping::getJs() +const type::vector* RigidMapping::doGetJs() { const OutVecCoord& out =this->toModel->read(core::vec_id::read_access::position)->getValue(); const InVecCoord& in =this->fromModel->read(core::vec_id::read_access::position)->getValue(); @@ -569,7 +569,7 @@ const type::vector* RigidMapping::g template -void RigidMapping::updateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId ) +void RigidMapping::doUpdateK( const core::MechanicalParams* mparams, core::ConstMultiVecDerivId childForceId ) { SOFA_UNUSED(mparams); const unsigned geomStiff = d_geometricStiffness.getValue().getSelectedId(); @@ -629,14 +629,14 @@ void RigidMapping::updateK( const core::MechanicalParams* mparams, co template -const sofa::linearalgebra::BaseMatrix* RigidMapping::getK() +const sofa::linearalgebra::BaseMatrix* RigidMapping::doGetK() { if( m_geometricStiffnessMatrix.compressedMatrix.nonZeros() ) return &m_geometricStiffnessMatrix; else return nullptr; } template -void RigidMapping::buildGeometricStiffnessMatrix( +void RigidMapping::doBuildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { const unsigned int geomStiff = d_geometricStiffness.getValue().getSelectedId(); @@ -698,7 +698,7 @@ void RigidMapping::buildGeometricStiffnessMatrix( template -const sofa::linearalgebra::BaseMatrix* RigidMapping::getJ() +const sofa::linearalgebra::BaseMatrix* RigidMapping::doGetJ() { const OutVecCoord& out =this->toModel->read(core::vec_id::read_access::position)->getValue(); const InVecCoord& in =this->fromModel->read(core::vec_id::read_access::position)->getValue(); diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.h index 138c075f2ea..717a04f6709 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.h @@ -76,13 +76,13 @@ class SquareDistanceMapping : public BaseNonLinearMapping void init() override; void apply(const core::MechanicalParams *mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; - void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void draw(const core::visual::VisualParams* vparams) override; protected: SquareDistanceMapping(); ~SquareDistanceMapping() override; + void doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void matrixFreeApplyDJT(const core::MechanicalParams* mparams, Real kFactor, Data >& parentForce, diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.inl index 54d11d5cb55..3e3a7fc0b44 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareDistanceMapping.inl @@ -206,7 +206,7 @@ void SquareDistanceMapping::doUpdateK( } template -void SquareDistanceMapping::buildGeometricStiffnessMatrix( +void SquareDistanceMapping::doBuildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.h index a8131b726bc..df477353676 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.h @@ -51,7 +51,6 @@ class SquareMapping : public BaseNonLinearMapping static constexpr auto Nin = In::deriv_total_size; void apply(const core::MechanicalParams *mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; - void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; protected: @@ -61,6 +60,7 @@ class SquareMapping : public BaseNonLinearMapping const Data >& childForce) override; using typename Inherit1::SparseKMatrixEigen; + void doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; void doUpdateK( const core::MechanicalParams* mparams, const Data >& childForce, diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.inl index f5183295f67..3f2f1253b8a 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/SquareMapping.inl @@ -97,7 +97,7 @@ void SquareMapping::doUpdateK(const core::MechanicalParams* mparams, } template -void SquareMapping::buildGeometricStiffnessMatrix( +void SquareMapping::doBuildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { const unsigned geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.h b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.h index c8bc2df7b2f..ed6005f8d8b 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.h +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.h @@ -51,7 +51,6 @@ class VolumeMapping : public BaseNonLinearMapping void init() override; void apply(const core::MechanicalParams* mparams, DataVecCoord_t& out, const DataVecCoord_t& in) override; - void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; protected: VolumeMapping(); @@ -60,6 +59,7 @@ class VolumeMapping : public BaseNonLinearMapping Data >& parentForce, const Data >& parentDisplacement, const Data >& childForce) override; + void doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) override; using typename Inherit1::SparseKMatrixEigen; diff --git a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.inl b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.inl index 06d97729f97..9fc94d78270 100644 --- a/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.inl +++ b/Sofa/Component/Mapping/NonLinear/src/sofa/component/mapping/nonlinear/VolumeMapping.inl @@ -280,7 +280,7 @@ void VolumeMapping::doUpdateK(const core::MechanicalParams* mparams, } template -void VolumeMapping::buildGeometricStiffnessMatrix( +void VolumeMapping::doBuildGeometricStiffnessMatrix( sofa::core::GeometricStiffnessMatrix* matrices) { const unsigned& geometricStiffness = this->d_geometricStiffness.getValue().getSelectedId(); diff --git a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MappingTestCreation.h b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MappingTestCreation.h index 63657b8542e..22acb7904a2 100644 --- a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MappingTestCreation.h +++ b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MappingTestCreation.h @@ -400,8 +400,8 @@ struct Mapping_test: public BaseSimulationTest, NumericTestapply(&mparams, core::vec_id::write_access::position, core::vec_id::write_access::position); - mapping->applyJ(&mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity); + static_cast(mapping)->apply(&mparams, core::vec_id::write_access::position, core::vec_id::write_access::position); + static_cast(mapping)->applyJ(&mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity); bool succeed = true; @@ -441,14 +441,14 @@ struct Mapping_test: public BaseSimulationTest, NumericTestwriteForces()->fill(Deriv_t()); // reset parent forces before accumulating child forces outDofs->writeForces().wref() = forceOut; - mapping->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); + static_cast(mapping)->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); forceIn = inDofs->readForces().ref(); } void computeVelocityOutFromVelocityIn(core::MechanicalParams mparams, VecDeriv_t& velocityOut, const VecDeriv_t& velocityIn) { inDofs->writeVelocities().wref() = velocityIn; - mapping->applyJ( &mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity ); + static_cast(mapping)->applyJ( &mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity ); velocityOut = outDofs->readVelocities().ref(); } @@ -575,7 +575,7 @@ struct Mapping_test: public BaseSimulationTest, NumericTest errorThreshold ) { - mapping->apply ( &mparams, core::vec_id::write_access::position, core::vec_id::write_access::position ); + static_cast(mapping)->apply ( &mparams, core::vec_id::write_access::position, core::vec_id::write_access::position ); const VecCoord_t& positionOut1 = outDofs->readPositions(); const auto sizeOut = positionOut.size(); diff --git a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MultiMappingTestCreation.h b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MultiMappingTestCreation.h index 3c0e5868a0a..613202b37b0 100644 --- a/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MultiMappingTestCreation.h +++ b/Sofa/Component/Mapping/Testing/src/sofa/component/mapping/testing/MultiMappingTestCreation.h @@ -177,8 +177,8 @@ struct MultiMapping_test : public BaseSimulationTest, NumericTestapply(&mparams, core::vec_id::write_access::position, core::vec_id::write_access::position); - mapping->applyJ(&mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity); + static_cast(mapping)->apply(&mparams, core::vec_id::write_access::position, core::vec_id::write_access::position); + static_cast(mapping)->applyJ(&mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity); /// test apply: check if the child positions are the expected ones bool succeed=true; @@ -228,7 +228,7 @@ struct MultiMapping_test : public BaseSimulationTest, NumericTestwriteForces(); sofa::testing::copyToData( fout, fc ); - mapping->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); + static_cast(mapping)->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); for(Index i=0; ireadForces() ); // cout<<"parent forces fp = "<applyJ( &mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity ); + static_cast(mapping)->applyJ( &mparams, core::vec_id::write_access::velocity, core::vec_id::write_access::velocity ); ReadOutVecDeriv vout = outDofs->readVelocities(); sofa::testing::copyFromData( vc, vout); // cout<<"child velocity vc = " << vc << endl; @@ -319,7 +319,7 @@ struct MultiMapping_test : public BaseSimulationTest, NumericTestapplyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); + static_cast(mapping)->applyJT( &mparams, core::vec_id::write_access::force, core::vec_id::write_access::force ); for( Index p=0; preadForces() ); @@ -334,7 +334,7 @@ struct MultiMapping_test : public BaseSimulationTest, NumericTest* BaseMapping::getJs() +{ + //TODO (SPRINT SED 2025): Component state mechamism + return doGetJs(); +} + +void BaseMapping::updateK( const MechanicalParams* mparams, ConstMultiVecDerivId outForce ) +{ + //TODO (SPRINT SED 2025): Component state mechamism + doUpdateK(mparams,outForce); +} + +const linearalgebra::BaseMatrix* BaseMapping::getK() +{ + //TODO (SPRINT SED 2025): Component state mechamism + return doGetK(); +} + void BaseMapping::buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) +{ + //TODO (SPRINT SED 2025): Component state mechamism + doBuildGeometricStiffnessMatrix(matrices); +} +void BaseMapping::doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) { SOFA_UNUSED(matrices); } diff --git a/Sofa/framework/Core/src/sofa/core/BaseMapping.h b/Sofa/framework/Core/src/sofa/core/BaseMapping.h index 4e71d332ef6..17fba14df25 100644 --- a/Sofa/framework/Core/src/sofa/core/BaseMapping.h +++ b/Sofa/framework/Core/src/sofa/core/BaseMapping.h @@ -63,10 +63,27 @@ class SOFA_CORE_API BaseMapping : public virtual objectmodel::BaseObject /// function is constant. virtual bool isLinear() const { return false; } + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doApply" internally, + * which is the method to override from now on. + * + **/ /// Apply the transformation from the input model to the output model (like apply displacement from BehaviorModel to VisualModel) - virtual void apply (const MechanicalParams* mparams = mechanicalparams::defaultInstance(), MultiVecCoordId outPos = vec_id::write_access::position, ConstMultiVecCoordId inPos = vec_id::read_access::position ) = 0; + virtual void apply (const MechanicalParams* mparams = mechanicalparams::defaultInstance(), MultiVecCoordId outPos = vec_id::write_access::position, ConstMultiVecCoordId inPos = vec_id::read_access::position ) 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 "doApplyJ" internally, + * which is the method to override from now on. + * + **/ /// Compute output velocity based on input velocity, using the linearized transformation (tangent operator). Also used to propagate small displacements. - virtual void applyJ(const MechanicalParams* mparams = mechanicalparams::defaultInstance(), MultiVecDerivId outVel = vec_id::write_access::velocity, ConstMultiVecDerivId inVel = vec_id::read_access::velocity ) = 0; + virtual void applyJ(const MechanicalParams* mparams = mechanicalparams::defaultInstance(), MultiVecDerivId outVel = vec_id::write_access::velocity, ConstMultiVecDerivId inVel = vec_id::read_access::velocity ) final; /// Accessor to the input model of this mapping virtual type::vector getFrom() = 0; @@ -82,13 +99,49 @@ class SOFA_CORE_API BaseMapping : public virtual objectmodel::BaseObject * Methods related to the transmission of forces */ ///@{ + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doApplyJT" internally, + * which is the method to override from now on. + * + **/ /// Accumulate child force in the parent force. In implicit methods, this is also used to accumulate a change of child force to a change of parent force. - virtual void applyJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) = 0; + virtual void applyJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) 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 "doApplyDJT" internally, + * which is the method to override from now on. + * + **/ /// Accumulate a change of parent force due to the change of the mapping, for a constant child force. Null for linear mappings. - virtual void applyDJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) = 0; + virtual void applyDJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) 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 "doApplyJT" internally, + * which is the method to override from now on. + * + **/ /// Propagate constraint Jacobians upward - virtual void applyJT(const ConstraintParams* mparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst) = 0; - virtual void computeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc) = 0; + virtual void applyJT(const ConstraintParams* mparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst) 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 "doComputeAccFromMapping" internally, + * which is the method to override from now on. + * + **/ + virtual void computeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc) final; virtual bool areForcesMapped() const; virtual bool areConstraintsMapped() const; @@ -112,6 +165,15 @@ class SOFA_CORE_API BaseMapping : public virtual objectmodel::BaseObject /// input and output DOFs (mostly identity or data-conversion mappings). virtual bool sameTopology() const { return false; } + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetJ" internally, + * which is the method to override from now on. + * + **/ /// Get the (sparse) jacobian matrix of this mapping, as used in applyJ/applyJT. /// This matrix should have as many columns as DOFs in the input mechanical states /// (one after the other in case of multi-mappings), and as many lines as DOFs in @@ -123,44 +185,106 @@ class SOFA_CORE_API BaseMapping : public virtual objectmodel::BaseObject /// @todo Note that if the mapping provides this matrix, then a default implementation /// of all other related methods could be provided, or optionally used to verify the /// provided implementations for debugging. - virtual const sofa::linearalgebra::BaseMatrix* getJ(const MechanicalParams* /*mparams*/); + virtual const sofa::linearalgebra::BaseMatrix* getJ(const MechanicalParams* /*mparams*/) 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 "doGetJ" internally, + * which is the method to override from now on. + * + **/ /// @deprecated - virtual const sofa::linearalgebra::BaseMatrix* getJ(); + virtual const sofa::linearalgebra::BaseMatrix* getJ() final; typedef sofa::linearalgebra::BaseMatrix* (*func_createMappedMatrix)(const behavior::BaseMechanicalState* , const behavior::BaseMechanicalState* ); + + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doCreateMappedMatrix" internally, + * which is the method to override from now on. + * + **/ /// Create a matrix for mapped mechanical objects /// If the two mechanical objects is identical, create a new stiffness matrix for this mapped objects /// If the two mechanical objects is different, create a new interaction matrix - virtual sofa::linearalgebra::BaseMatrix* createMappedMatrix(const behavior::BaseMechanicalState* state1, const behavior::BaseMechanicalState* state2, func_createMappedMatrix); + virtual sofa::linearalgebra::BaseMatrix* createMappedMatrix(const behavior::BaseMechanicalState* state1, const behavior::BaseMechanicalState* state2, func_createMappedMatrix) final; /// Get the source (upper) mechanical state. virtual type::vector getMechFrom() = 0; /// Get the destination (lower, mapped) mechanical state. virtual type::vector getMechTo() = 0; + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doDisable" internally, + * which is the method to override from now on. + * + **/ /// Disable the mapping to get the original coordinates of the mapped model. - virtual void disable()=0; + virtual void disable() final; + /// @name API for global matrix assembly (used in the Compliant plugin) /// @{ + /** + * !!! WARNING since v25.12 !!! + * + * The template method pattern has been applied to this part of the API. + * This method calls the newly introduced method "doGetJs" internally, + * which is the method to override from now on. + * + **/ /// Returns pointers to Jacobian matrices associated with parent states, consistently with getFrom(). Most mappings have only one parent, however Multimappings have several parents. /// For efficiency concerns, please return pointers to defaulttype::EigenBaseSparseMatrix - virtual const type::vector* getJs() { dmsg_error() << "Calling a virtual method not implemented."; return nullptr; } + virtual const type::vector* getJs() 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 "doUpdateK" internally, + * which is the method to override from now on. + * + **/ /// Compute the geometric stiffness matrix based on given child forces /// K = dJ^T * outForce /// Default implementation does nothing, corresponding to a linear mapping. - virtual void updateK( const MechanicalParams* /*mparams*/, ConstMultiVecDerivId /*outForce*/ ) {} + virtual void updateK( const MechanicalParams* /*mparams*/, ConstMultiVecDerivId /*outForce*/ ) 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 "doGetK" internally, + * which is the method to override from now on. + * + **/ /// Returns a pointer to the geometric stiffness matrix. /// This is the equivalent of applyDJT, for matrix assembly instead of matrix-vector product. /// This matrix is associated with the parent DOFs. It is a square matrix with a size of the total number of parent DOFs. /// For efficiency concerns, please return a pointer to a defaulttype::EigenBaseSparseMatrix - virtual const linearalgebra::BaseMatrix* getK() { return nullptr; } + virtual const linearalgebra::BaseMatrix* getK() 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 "doBuildGeometricStiffnessMatrix" internally, + * which is the method to override from now on. + * + **/ /** * \brief Assembles the geometric stiffness matrix of the mapping in the * provided matrix object. @@ -180,13 +304,29 @@ class SOFA_CORE_API BaseMapping : public virtual objectmodel::BaseObject * * \param matrices The matrix to fill in with the geometric stiffness of the mapping */ - virtual void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices); + virtual void buildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices) final; /// @} protected: bool testMechanicalState(BaseState* state); + //Method for template method pattern + virtual void doBuildGeometricStiffnessMatrix(sofa::core::GeometricStiffnessMatrix* matrices); + virtual const linearalgebra::BaseMatrix* doGetK() { return nullptr; } + virtual void doUpdateK( const MechanicalParams* /*mparams*/, ConstMultiVecDerivId /*outForce*/ ) {} + virtual const type::vector* doGetJs() { dmsg_error() << "Calling a virtual method not implemented."; return nullptr; } + virtual void doDisable() = 0; + virtual sofa::linearalgebra::BaseMatrix* doCreateMappedMatrix(const behavior::BaseMechanicalState* state1, const behavior::BaseMechanicalState* state2, func_createMappedMatrix); + virtual const sofa::linearalgebra::BaseMatrix* doGetJ(); + virtual const sofa::linearalgebra::BaseMatrix* doGetJ(const MechanicalParams* /*mparams*/); + virtual void doComputeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc) = 0; + virtual void doApplyJT(const ConstraintParams* mparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst) = 0; + virtual void doApplyDJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) = 0; + virtual void doApplyJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) = 0; + virtual void doApplyJ(const MechanicalParams* mparams = mechanicalparams::defaultInstance(), MultiVecDerivId outVel = vec_id::write_access::velocity, ConstMultiVecDerivId inVel = vec_id::read_access::velocity ) = 0; + virtual void doApply (const MechanicalParams* mparams = mechanicalparams::defaultInstance(), MultiVecCoordId outPos = vec_id::write_access::position, ConstMultiVecCoordId inPos = vec_id::read_access::position ) = 0; + public: bool insertInNode( objectmodel::BaseNode* node ) override; bool removeInNode( objectmodel::BaseNode* node ) override; diff --git a/Sofa/framework/Core/src/sofa/core/Mapping.h b/Sofa/framework/Core/src/sofa/core/Mapping.h index daf5a0b3606..2469cd6dcf5 100644 --- a/Sofa/framework/Core/src/sofa/core/Mapping.h +++ b/Sofa/framework/Core/src/sofa/core/Mapping.h @@ -100,62 +100,22 @@ class Mapping : public BaseMapping /// Return the pointer to the output model. type::vector getTo() override; - /// Apply /// - /// Apply the mapping to position vectors. - /// - /// If the Mapping can be represented as a matrix J, this method computes - /// $ out = J in $ - void apply (const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos ) override; /// This method must be reimplemented by all mappings. virtual void apply( const MechanicalParams* mparams, OutDataVecCoord& out, const InDataVecCoord& in)= 0; - /// ApplyJ /// - /// Apply the mapping to derived (velocity, displacement) vectors. - /// $ out = J in $ - /// where J is the tangent operator (the linear approximation) of the mapping - void applyJ(const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel ) override; - /// This method must be reimplemented by all mappings. virtual void applyJ( const MechanicalParams* mparams, OutDataVecDeriv& out, const InDataVecDeriv& in) = 0; - /// ApplyJT (Force)/// - /// Apply the reverse mapping to force vectors. - /// $ out += J^t in $ - /// where J is the tangent operator (the linear approximation) of the mapping - void applyJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce ) override; - /// This method must be reimplemented by all mappings. virtual void applyJT( const MechanicalParams* mparams, InDataVecDeriv& out, const OutDataVecDeriv& in) = 0; - /// ApplyDJT (Force)/// - /// Apply the change of force due to the nonlinearity of the mapping and the last propagated displacement. Also called geometric stiffness. - /// The default implementation does nothing, assuming a linear mapping. - /// - /// This method computes - /// \f$ f_p += dJ^t f_c \f$, where \f$ f_p \f$ is the parent force and \f$ f_c \f$ is the child force. - /// where J is the tangent operator (the linear approximation) of the mapping - /// The child force is accessed in the child state using mparams->readF() . This requires that the child force vector is used by the solver to compute the force \f$ f(x,v)\f$ corresponding to the current positions and velocities, and not to store auxiliary values. - /// The displacement is accessed in the parent state using mparams->readDx() . - /// This method generally corresponds to a symmetric stiffness matrix, but with rotations (which are not a commutative group) it is not the case. - /// Since some solvers (including the Conjugate Gradient) require symmetric matrices, a flag is set in the MechanicalParams to say if symmetric matrices are required. If so, non-symmetric geometric stiffness should not be applied. - void applyDJT(const MechanicalParams* /*mparams = */ , MultiVecDerivId /*parentForce*/, ConstMultiVecDerivId /*childForce*/ ) override; - - /// ApplyJT (Constraint)/// - void applyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) override; - /// This method must be reimplemented by all mappings if they need to support constraints. virtual void applyJT( const ConstraintParams* /* mparams */, InDataMatrixDeriv& /* out */, const OutDataMatrixDeriv& /* in */) { msg_error() << "This mapping does not support certain constraints because Mapping::applyJT( const ConstraintParams* , InDataMatrixDeriv&, const OutDataMatrixDeriv&) is not overloaded."; } - /// computeAccFromMapping - /// Compute the acceleration of the child, based on the acceleration and the velocity of the parent. - /// Let \f$ v_c = J v_p \f$ be the velocity of the child given the velocity of the parent, then the acceleration is \f$ a_c = J a_p + dJ v_p \f$. - /// The second term is null in linear mappings, otherwise it encodes the acceleration due to the change of mapping at constant parent velocity. - /// For instance, in a rigid mapping with angular velocity\f$ w \f$, the second term is $ w^(w^rel_pos) $ - void computeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc ) override; /// This method must be reimplemented by all mappings if they need to support composite accelerations virtual void computeAccFromMapping(const MechanicalParams* /* mparams */, OutDataVecDeriv& /* accOut */, const InDataVecDeriv& /* vIn */, const InDataVecDeriv& /* accIn */) @@ -173,15 +133,6 @@ class Mapping : public BaseMapping /// Get the destination (lower, mapped) model. virtual type::vector getMechTo() override; - //Create a matrix for mapped mechanical objects - //If the two mechanical objects is identical, create a new stiffness matrix for this mapped objects - //If the two mechanical objects is different, create a new interaction matrix - sofa::linearalgebra::BaseMatrix* createMappedMatrix(const behavior::BaseMechanicalState* state1, const behavior::BaseMechanicalState* state2, func_createMappedMatrix) override; - - /// Disable the mapping to get the original coordinates of the mapped model. - /// - /// It is for instance used in RigidMapping to get the local coordinates of the object. - void disable() override; /// Pre-construction check method called by ObjectFactory. /// @@ -274,6 +225,61 @@ class Mapping : public BaseMapping return name; } + +protected: + /// Apply /// + /// Apply the mapping to position vectors. + /// + /// If the Mapping can be represented as a matrix J, this method computes + /// $ out = J in $ + void doApply (const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos ) override; + + /// ApplyJ /// + /// Apply the mapping to derived (velocity, displacement) vectors. + /// $ out = J in $ + /// where J is the tangent operator (the linear approximation) of the mapping + void doApplyJ(const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel ) override; + + /// ApplyJT (Force)/// + /// Apply the reverse mapping to force vectors. + /// $ out += J^t in $ + /// where J is the tangent operator (the linear approximation) of the mapping + void doApplyJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce ) override; + + /// ApplyDJT (Force)/// + /// Apply the change of force due to the nonlinearity of the mapping and the last propagated displacement. Also called geometric stiffness. + /// The default implementation does nothing, assuming a linear mapping. + /// + /// This method computes + /// \f$ f_p += dJ^t f_c \f$, where \f$ f_p \f$ is the parent force and \f$ f_c \f$ is the child force. + /// where J is the tangent operator (the linear approximation) of the mapping + /// The child force is accessed in the child state using mparams->readF() . This requires that the child force vector is used by the solver to compute the force \f$ f(x,v)\f$ corresponding to the current positions and velocities, and not to store auxiliary values. + /// The displacement is accessed in the parent state using mparams->readDx() . + /// This method generally corresponds to a symmetric stiffness matrix, but with rotations (which are not a commutative group) it is not the case. + /// Since some solvers (including the Conjugate Gradient) require symmetric matrices, a flag is set in the MechanicalParams to say if symmetric matrices are required. If so, non-symmetric geometric stiffness should not be applied. + void doApplyDJT(const MechanicalParams* /*mparams = */ , MultiVecDerivId /*parentForce*/, ConstMultiVecDerivId /*childForce*/ ) override; + + /// ApplyJT (Constraint)/// + void doApplyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) override; + + /// computeAccFromMapping + /// Compute the acceleration of the child, based on the acceleration and the velocity of the parent. + /// Let \f$ v_c = J v_p \f$ be the velocity of the child given the velocity of the parent, then the acceleration is \f$ a_c = J a_p + dJ v_p \f$. + /// The second term is null in linear mappings, otherwise it encodes the acceleration due to the change of mapping at constant parent velocity. + /// For instance, in a rigid mapping with angular velocity\f$ w \f$, the second term is $ w^(w^rel_pos) $ + void doComputeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc ) override; + + + //Create a matrix for mapped mechanical objects + //If the two mechanical objects is identical, create a new stiffness matrix for this mapped objects + //If the two mechanical objects is different, create a new interaction matrix + sofa::linearalgebra::BaseMatrix* doCreateMappedMatrix(const behavior::BaseMechanicalState* state1, const behavior::BaseMechanicalState* state2, func_createMappedMatrix) override; + + /// Disable the mapping to get the original coordinates of the mapped model. + /// + /// It is for instance used in RigidMapping to get the local coordinates of the object. + void doDisable() override; + }; diff --git a/Sofa/framework/Core/src/sofa/core/Mapping.inl b/Sofa/framework/Core/src/sofa/core/Mapping.inl index 48624dc065b..9111bfc4a3b 100644 --- a/Sofa/framework/Core/src/sofa/core/Mapping.inl +++ b/Sofa/framework/Core/src/sofa/core/Mapping.inl @@ -105,14 +105,14 @@ void Mapping::init() setNonMechanical(); } - apply(mechanicalparams::defaultInstance(), vec_id::write_access::position, vec_id::read_access::position); - applyJ(mechanicalparams::defaultInstance(), vec_id::write_access::velocity, vec_id::read_access::velocity); + BaseMapping::apply(mechanicalparams::defaultInstance(), vec_id::write_access::position, vec_id::read_access::position); + BaseMapping::applyJ(mechanicalparams::defaultInstance(), vec_id::write_access::velocity, vec_id::read_access::velocity); if (f_applyRestPosition.getValue()) - apply(mechanicalparams::defaultInstance(), vec_id::write_access::restPosition, vec_id::read_access::restPosition); + BaseMapping::apply(mechanicalparams::defaultInstance(), vec_id::write_access::restPosition, vec_id::read_access::restPosition); } template -sofa::linearalgebra::BaseMatrix* Mapping::createMappedMatrix(const behavior::BaseMechanicalState* state1, const behavior::BaseMechanicalState* state2, func_createMappedMatrix m_createMappedMatrix) +sofa::linearalgebra::BaseMatrix* Mapping::doCreateMappedMatrix(const behavior::BaseMechanicalState* state1, const behavior::BaseMechanicalState* state2, func_createMappedMatrix m_createMappedMatrix) { sofa::linearalgebra::BaseMatrix* result; if( !this->areMatricesMapped() ) @@ -133,7 +133,7 @@ sofa::linearalgebra::BaseMatrix* Mapping::createMappedMatrix(const behav template -void Mapping::apply(const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos) +void Mapping::doApply(const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos) { State* fromModel = this->fromModel.get(); State* toModel = this->toModel.get(); @@ -149,7 +149,7 @@ void Mapping::apply(const MechanicalParams* mparams, MultiVecCoordId out }// Mapping::apply template -void Mapping::applyJ(const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel) +void Mapping::doApplyJ(const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel) { State* fromModel = this->fromModel.get(); State* toModel = this->toModel.get(); @@ -165,7 +165,7 @@ void Mapping::applyJ(const MechanicalParams* mparams, MultiVecDerivId ou }// Mapping::applyJ template -void Mapping::applyJT(const MechanicalParams *mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) +void Mapping::doApplyJT(const MechanicalParams *mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) { State* fromModel = this->fromModel.get(); State* toModel = this->toModel.get(); @@ -182,7 +182,7 @@ void Mapping::applyJT(const MechanicalParams *mparams, MultiVecDerivId i /// ApplyJT (Constraint)/// template -void Mapping::applyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) +void Mapping::doApplyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) { State* fromModel = this->fromModel.get(); State* toModel = this->toModel.get(); @@ -199,14 +199,14 @@ void Mapping::applyJT(const ConstraintParams* cparams, MultiMatrixDerivI template -void Mapping::applyDJT(const MechanicalParams* /*mparams */ , MultiVecDerivId /*parentForce*/, ConstMultiVecDerivId /*childForce*/ ) +void Mapping::doApplyDJT(const MechanicalParams* /*mparams */ , MultiVecDerivId /*parentForce*/, ConstMultiVecDerivId /*childForce*/ ) { //applyDJT } template -void Mapping::computeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc ) +void Mapping::doComputeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc ) { State* fromModel = this->fromModel.get(); State* toModel = this->toModel.get(); @@ -221,7 +221,7 @@ void Mapping::computeAccFromMapping(const MechanicalParams* mparams, Mul }// Mapping::computeAccFromMapping template -void Mapping::disable() +void Mapping::doDisable() { } diff --git a/Sofa/framework/Core/src/sofa/core/Multi2Mapping.h b/Sofa/framework/Core/src/sofa/core/Multi2Mapping.h index c0ead569710..4a5dcb3892d 100644 --- a/Sofa/framework/Core/src/sofa/core/Multi2Mapping.h +++ b/Sofa/framework/Core/src/sofa/core/Multi2Mapping.h @@ -91,13 +91,6 @@ class Multi2Mapping : public BaseMapping /// Get the destination (lower, mapped) model. virtual type::vector getMechTo() override; - /// Apply /// - /// Apply the mapping to position vectors. - /// - /// If the Mapping can be represented as a matrix J, this method computes - /// $ out = J in $ - void apply (const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos ) override; - /// This method must be reimplemented by all mappings. /// InPos and OutPos by default contains VecIds of type V_COORD. /// The size of InPos vector is the same as the number of fromModels. @@ -108,12 +101,6 @@ class Multi2Mapping : public BaseMapping const type::vector*>& dataVecIn1Pos , const type::vector*>& dataVecIn2Pos) = 0; - /// ApplyJ /// - /// This method computes - /// $ out = J in $ - /// where J is the tangent operator (the linear approximation) of the mapping - void applyJ (const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel ) override; - /// This method must be reimplemented by all mappings. /// InDeriv and OutDeriv by default contains VecIds of type V_DERIV. /// The size of InDeriv vector is the same as the number of fromModels. @@ -147,10 +134,6 @@ class Multi2Mapping : public BaseMapping const type::vector*>& /* inDeriv1 */, const type::vector*>& /* inDeriv2 */) {} - /// ApplyJT (Force)/// - /// Apply the mapping to Force vectors. - void applyJT (const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce ) override; - /// This method must be reimplemented by all mappings. /// InDeriv and OutDeriv by default contains VecIds of type V_DERIV. /// The size of InDeriv vector is the same as the number of fromModels. @@ -161,9 +144,6 @@ class Multi2Mapping : public BaseMapping const type::vector< DataVecDeriv_t*>& dataVecOut2Force, const type::vector*>& dataVecInForce) = 0; - /// ApplyJT (Constraint)/// - void applyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) override; - /// This method must be reimplemented by all mappings if they need to support constraints. virtual void applyJT( const ConstraintParams* /* cparams */, const type::vector< DataMatrixDeriv_t*>& /* dataMatOut1Const */ , @@ -173,9 +153,6 @@ class Multi2Mapping : public BaseMapping msg_error() << "This mapping does not support constraint because Multi2Mapping::applyJT(const ConstraintParams*, const type::vector< DataMatrixDeriv_t*>&, const type::vector< DataMatrixDeriv_t*>&, const type::vector*>&) is not overloaded."; } - /// computeAccFromMapping - void computeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc ) override; - /// This method must be reimplemented by all mappings if they need to support composite accelerations virtual void computeAccFromMapping( const MechanicalParams* /* mparams */, const type::vector< DataVecDeriv_t*>& /* dataVecOutAcc */, @@ -188,11 +165,6 @@ class Multi2Mapping : public BaseMapping void init() override; - /// Disable the mapping to get the original coordinates of the mapped model. - /// - /// It is for instance used in RigidMapping to get the local coordinates of the object. - void disable() override; - /// Pre-construction check method called by ObjectFactory. /// /// This implementation read the object1 and object2 attributes and check @@ -231,6 +203,36 @@ class Multi2Mapping : public BaseMapping } protected: + + /// computeAccFromMapping + void doComputeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc ) override; + + /// ApplyJT (Constraint)/// + void doApplyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) override; + + /// ApplyJT (Force)/// + /// Apply the mapping to Force vectors. + void doApplyJT (const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce ) override; + + /// Apply /// + /// Apply the mapping to position vectors. + /// + /// If the Mapping can be represented as a matrix J, this method computes + /// $ out = J in $ + void doApply (const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos ) override; + + /// ApplyJ /// + /// This method computes + /// $ out = J in $ + /// where J is the tangent operator (the linear approximation) of the mapping + void doApplyJ (const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel ) override; + + /// Disable the mapping to get the original coordinates of the mapped model. + /// + /// It is for instance used in RigidMapping to get the local coordinates of the object. + void doDisable() override; + + void getVecIn1Coord (const MultiVecCoordId id, type::vector< DataVecCoord_t*> &v) const { for (unsigned int i=0; i*> &v) const diff --git a/Sofa/framework/Core/src/sofa/core/Multi2Mapping.inl b/Sofa/framework/Core/src/sofa/core/Multi2Mapping.inl index e95a1b2f195..40adbf13228 100644 --- a/Sofa/framework/Core/src/sofa/core/Multi2Mapping.inl +++ b/Sofa/framework/Core/src/sofa/core/Multi2Mapping.inl @@ -139,7 +139,7 @@ type::vector Multi2Mapping::getMech } template < class In1, class In2,class Out> -void Multi2Mapping::apply (const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos ) +void Multi2Mapping::doApply (const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos ) { type::vector*> vecOutPos; getVecOutCoord(outPos, vecOutPos); @@ -152,7 +152,7 @@ void Multi2Mapping::apply (const MechanicalParams* mparams, MultiVe } template < class In1, class In2,class Out> -void Multi2Mapping::applyJ (const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel ) +void Multi2Mapping::doApplyJ (const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel ) { type::vector*> vecOutVel; getVecOutDeriv(outVel, vecOutVel); @@ -164,7 +164,7 @@ void Multi2Mapping::applyJ (const MechanicalParams* mparams, MultiV } template < class In1, class In2,class Out> -void Multi2Mapping::applyJT (const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce ) +void Multi2Mapping::doApplyJT (const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce ) { type::vector*> vecOut1Force; getVecIn1Deriv(inForce, vecOut1Force); @@ -177,7 +177,7 @@ void Multi2Mapping::applyJT (const MechanicalParams* mparams, Multi } template < class In1, class In2,class Out> -void Multi2Mapping::applyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) +void Multi2Mapping::doApplyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) { type::vector*> matOut1Const; getMatIn1Deriv(inConst, matOut1Const); @@ -190,7 +190,7 @@ void Multi2Mapping::applyJT(const ConstraintParams* cparams, MultiM } template < class In1, class In2,class Out> -void Multi2Mapping::computeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc ) +void Multi2Mapping::doComputeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc ) { type::vector*> vecOutAcc; getVecOutDeriv(outAcc, vecOutAcc); @@ -221,14 +221,14 @@ void Multi2Mapping::init() } } - apply(mechanicalparams::defaultInstance() , vec_id::write_access::position, vec_id::read_access::position); - applyJ(mechanicalparams::defaultInstance() , vec_id::write_access::velocity, vec_id::read_access::velocity); + BaseMapping::apply(mechanicalparams::defaultInstance() , vec_id::write_access::position, vec_id::read_access::position); + BaseMapping::applyJ(mechanicalparams::defaultInstance() , vec_id::write_access::velocity, vec_id::read_access::velocity); if (f_applyRestPosition.getValue()) - apply(mechanicalparams::defaultInstance(), vec_id::write_access::restPosition, vec_id::read_access::restPosition); + BaseMapping::apply(mechanicalparams::defaultInstance(), vec_id::write_access::restPosition, vec_id::read_access::restPosition); } template < class In1, class In2, class Out > -void Multi2Mapping::disable() +void Multi2Mapping::doDisable() { } } // namespace sofa diff --git a/Sofa/framework/Core/src/sofa/core/MultiMapping.h b/Sofa/framework/Core/src/sofa/core/MultiMapping.h index bc65f24d32f..7418c91dc96 100644 --- a/Sofa/framework/Core/src/sofa/core/MultiMapping.h +++ b/Sofa/framework/Core/src/sofa/core/MultiMapping.h @@ -100,71 +100,30 @@ class MultiMapping : public BaseMapping /// Get the destination (lower, mapped) model. virtual type::vector getMechTo() override; - /// Apply /// - /// Apply the mapping to position vectors. - /// - /// If the Mapping can be represented as a matrix \f$ J \f$, this method computes - /// \f$ out = J in \f$ - void apply (const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos ) override; - /// This method must be reimplemented by all mappings. /// InPos and OutPos by default contains VecIds of type V_COORD. /// The size of InPos vector is the same as the number of fromModels. /// The size of OutPos vector is the same as the number of OutModels. virtual void apply(const MechanicalParams* mparams, const type::vector& dataVecOutPos, const type::vector& dataVecInPos) = 0; - /// ApplyJ /// - /// Apply the mapping to derived (velocity, displacement) vectors. - /// \f$ out = J in \f$ - /// where \f$ J \f$ is the tangent operator (the linear approximation) of the mapping - void applyJ (const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel ) override; - /// This method must be reimplemented by all mappings. /// InDeriv and OutDeriv by default contains VecIds of type V_DERIV. /// The size of InDeriv vector is the same as the number of fromModels. /// The size of OutDeriv vector is the same as the number of OutModels. virtual void applyJ(const MechanicalParams* mparams, const type::vector& dataVecOutVel, const type::vector& dataVecInVel) = 0; - /// ApplyJT (Force)/// - /// Apply the reverse mapping to force vectors. - /// \f$ out += J^t in \f$ - /// where \f$ J \f$ is the tangent operator (the linear approximation) of the mapping - void applyJT (const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce ) override; - /// This method must be reimplemented by all mappings. /// InDeriv and OutDeriv by default contains VecIds of type V_DERIV. /// The size of InDeriv vector is the same as the number of fromModels. /// The size of OutDeriv vector is the same as the number of OutModels. virtual void applyJT(const MechanicalParams* mparams, const type::vector& dataVecOutForce, const type::vector& dataVecInForce) = 0; - /// ApplyJT (Constraint)/// - void applyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) override - { - type::vector matOutConst; - getMatInDeriv(inConst, matOutConst); - type::vector matInConst; - getConstMatOutDeriv(outConst, matInConst); - - this->applyJT(cparams, matOutConst, matInConst); - } /// This method must be reimplemented by all mappings if they need to support constraints. virtual void applyJT( const ConstraintParams* /* cparams */, const type::vector< InDataMatrixDeriv* >& /* dataMatOutConst */, const type::vector< const OutDataMatrixDeriv* >& /* dataMatInConst */ ) { msg_error() << "This mapping does not support certain constraints since MultiMapping::applyJT( const ConstraintParams*, const type::vector< InDataMatrixDeriv* >& , const type::vector< const OutDataMatrixDeriv* >& ) is not overloaded"; } - /// computeAccFromMapping - void computeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc) override - { - type::vector vecOutAcc; - getVecOutDeriv(outAcc, vecOutAcc); - type::vector vecInVel; - getConstVecInDeriv(inVel, vecInVel); - type::vector vecInAcc; - getConstVecInDeriv(inAcc, vecInAcc); - - this->computeAccFromMapping(mparams, vecOutAcc, vecInVel, vecInAcc); - } /// This method must be reimplemented by all mappings if they need to support composite accelerations virtual void computeAccFromMapping( const MechanicalParams* /* mparams */, const type::vector< OutDataVecDeriv*>& /* dataVecOutAcc */, @@ -183,11 +142,6 @@ class MultiMapping : public BaseMapping /// and applyJ(type::vector& InDeriv, type::vector& OutDeriv) methods. //virtual void updateMapping(); - /// Disable the mapping to get the original coordinates of the mapped model. - /// - /// It is for instance used in RigidMapping to get the local coordinates of the object. - void disable() override; - template static std::string shortName(const T* ptr = nullptr, objectmodel::BaseObjectDescription* arg = nullptr) @@ -233,6 +187,55 @@ class MultiMapping : public BaseMapping protected: + + /// Apply /// + /// Apply the mapping to position vectors. + /// + /// If the Mapping can be represented as a matrix \f$ J \f$, this method computes + /// \f$ out = J in \f$ + void doApply (const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos ) override; + + /// ApplyJ /// + /// Apply the mapping to derived (velocity, displacement) vectors. + /// \f$ out = J in \f$ + /// where \f$ J \f$ is the tangent operator (the linear approximation) of the mapping + void doApplyJ (const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel ) override; + + /// ApplyJT (Force)/// + /// Apply the reverse mapping to force vectors. + /// \f$ out += J^t in \f$ + /// where \f$ J \f$ is the tangent operator (the linear approximation) of the mapping + void doApplyJT (const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce ) override; + + /// ApplyJT (Constraint)/// + void doApplyJT(const ConstraintParams* cparams, MultiMatrixDerivId inConst, ConstMultiMatrixDerivId outConst ) override + { + type::vector matOutConst; + getMatInDeriv(inConst, matOutConst); + type::vector matInConst; + getConstMatOutDeriv(outConst, matInConst); + + this->applyJT(cparams, matOutConst, matInConst); + } + + /// computeAccFromMapping + void doComputeAccFromMapping(const MechanicalParams* mparams, MultiVecDerivId outAcc, ConstMultiVecDerivId inVel, ConstMultiVecDerivId inAcc) override + { + type::vector vecOutAcc; + getVecOutDeriv(outAcc, vecOutAcc); + type::vector vecInVel; + getConstVecInDeriv(inVel, vecInVel); + type::vector vecInAcc; + getConstVecInDeriv(inAcc, vecInAcc); + + this->computeAccFromMapping(mparams, vecOutAcc, vecInVel, vecInAcc); + } + /// Disable the mapping to get the original coordinates of the mapped model. + /// + /// It is for instance used in RigidMapping to get the local coordinates of the object. + void doDisable() override; + + void getVecInCoord (const MultiVecCoordId id, type::vector< InDataVecCoord* > &v) const { for (unsigned int i=0; i &v) const diff --git a/Sofa/framework/Core/src/sofa/core/MultiMapping.inl b/Sofa/framework/Core/src/sofa/core/MultiMapping.inl index b0c460635ba..54999e195da 100644 --- a/Sofa/framework/Core/src/sofa/core/MultiMapping.inl +++ b/Sofa/framework/Core/src/sofa/core/MultiMapping.inl @@ -128,14 +128,14 @@ void MultiMapping::init() } } - apply(mechanicalparams::defaultInstance() , vec_id::write_access::position, vec_id::read_access::position); - applyJ(mechanicalparams::defaultInstance() , vec_id::write_access::velocity, vec_id::read_access::velocity); + BaseMapping::apply(mechanicalparams::defaultInstance() , vec_id::write_access::position, vec_id::read_access::position); + BaseMapping::applyJ(mechanicalparams::defaultInstance() , vec_id::write_access::velocity, vec_id::read_access::velocity); if (f_applyRestPosition.getValue()) - apply(mechanicalparams::defaultInstance(), vec_id::write_access::restPosition, vec_id::read_access::restPosition); + BaseMapping::apply(mechanicalparams::defaultInstance(), vec_id::write_access::restPosition, vec_id::read_access::restPosition); } template -void MultiMapping::apply(const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos) +void MultiMapping::doApply(const MechanicalParams* mparams, MultiVecCoordId outPos, ConstMultiVecCoordId inPos) { type::vector vecOutPos; getVecOutCoord(outPos, vecOutPos); @@ -145,7 +145,7 @@ void MultiMapping::apply(const MechanicalParams* mparams, MultiVecCoordI }// MultiMapping::apply template -void MultiMapping::applyJ(const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel) +void MultiMapping::doApplyJ(const MechanicalParams* mparams, MultiVecDerivId outVel, ConstMultiVecDerivId inVel) { type::vector vecOutVel; getVecOutDeriv(outVel, vecOutVel); @@ -155,7 +155,7 @@ void MultiMapping::applyJ(const MechanicalParams* mparams, MultiVecDeriv }// MultiMapping::applyJ template -void MultiMapping::applyJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) +void MultiMapping::doApplyJT(const MechanicalParams* mparams, MultiVecDerivId inForce, ConstMultiVecDerivId outForce) { type::vector vecOutForce; getVecInDeriv(inForce, vecOutForce); @@ -166,7 +166,7 @@ void MultiMapping::applyJT(const MechanicalParams* mparams, MultiVecDeri }// MultiMapping::applyJT template -void MultiMapping::disable() +void MultiMapping::doDisable() { } } // namespace sofa::core diff --git a/applications/plugins/ArticulatedSystemPlugin/src/ArticulatedSystemPlugin/ArticulatedSystemMapping.h b/applications/plugins/ArticulatedSystemPlugin/src/ArticulatedSystemPlugin/ArticulatedSystemMapping.h index b69581c80f2..d6d60692d54 100644 --- a/applications/plugins/ArticulatedSystemPlugin/src/ArticulatedSystemPlugin/ArticulatedSystemMapping.h +++ b/applications/plugins/ArticulatedSystemPlugin/src/ArticulatedSystemPlugin/ArticulatedSystemMapping.h @@ -174,7 +174,7 @@ class ArticulatedSystemMapping : public core::Multi2Mapping dataVecOutRootForce[0]->endEdit(); } - void applyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override + void doApplyDJT(const core::MechanicalParams* /*mparams*/, core::MultiVecDerivId /*inForce*/, core::ConstMultiVecDerivId /*outForce*/) override { } @@ -210,7 +210,7 @@ class ArticulatedSystemMapping : public core::Multi2Mapping dataMatOutRootConst[0]->endEdit(); } - const sofa::linearalgebra::BaseMatrix* getJ() override { return nullptr; } + const sofa::linearalgebra::BaseMatrix* doGetJ() override { return nullptr; } void draw(const core::visual::VisualParams* vparams) override;