From b1c49a761faec4ea63a5bffd32e8bfda67e552f2 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Wed, 20 Dec 2023 10:06:33 +0100 Subject: [PATCH] [Simulation.Core] BaseMechanicalVisitor: Deprecate rootData (#4350) * remove ref to nodedata * add compat * Update Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in (typo) Co-authored-by: Alex Bilger --------- Co-authored-by: Alex Bilger --- .../sofa/simulation/BaseMechanicalVisitor.cpp | 69 ++----------------- .../sofa/simulation/BaseMechanicalVisitor.h | 19 +++-- .../Core/src/sofa/simulation/config.h.in | 7 ++ ...chanicalGetNonDiagonalMassesCountVisitor.h | 5 -- .../mechanicalvisitor/MechanicalVDotVisitor.h | 4 -- .../MechanicalVMultiOpVisitor.h | 4 -- .../MechanicalVNormVisitor.h | 4 -- .../mechanicalvisitor/MechanicalVOpVisitor.h | 4 -- 8 files changed, 23 insertions(+), 93 deletions(-) diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.cpp index be36afdee57..46925012b52 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.cpp @@ -200,57 +200,15 @@ Visitor::Result BaseMechanicalVisitor::fwdInteractionConstraint(VisitorContext* Visitor::Result BaseMechanicalVisitor::processNodeTopDown(simulation::Node* node, LocalStorage* stack) { - if (root == nullptr) - { - root = node; - } - - VisitorContext ctx; - ctx.root = root; - ctx.node = node; - ctx.nodeData = rootData; - - const bool writeData = writeNodeData(); - if (writeData) - { - // create temporary accumulation buffer for parallel reductions (dot products) - if (node != root) - { - const SReal* parentData = stack->empty() ? rootData : (SReal*)stack->top(); - ctx.nodeData = new SReal(0.0); - setNodeData(node, ctx.nodeData, parentData); - stack->push(ctx.nodeData); - } - } - - return processNodeTopDown(node, &ctx); + SOFA_UNUSED(stack); + return processNodeTopDown(node); } void BaseMechanicalVisitor::processNodeBottomUp(simulation::Node* node, LocalStorage* stack) { - VisitorContext ctx; - ctx.root = root; - ctx.node = node; - ctx.nodeData = rootData; - SReal* parentData = rootData; - - const bool writeData = writeNodeData(); - - if (writeData) - { - // use temporary accumulation buffer for parallel reductions (dot products) - if (node != root) - { - ctx.nodeData = (SReal*)stack->pop(); - parentData = stack->empty() ? rootData : (SReal*)stack->top(); - } - } - - processNodeBottomUp(node, &ctx); - - if (writeData && parentData != ctx.nodeData) - addNodeData(node, parentData, ctx.nodeData); + SOFA_UNUSED(stack); + return processNodeBottomUp(node); } @@ -408,25 +366,6 @@ void BaseMechanicalVisitor::end(simulation::Node* node, core::objectmodel::BaseO //} -/// Return true if this visitor need to read the node-specific data if given -bool BaseMechanicalVisitor::readNodeData() const -{ return false; } - -/// Return true if this visitor need to write to the node-specific data if given -bool BaseMechanicalVisitor::writeNodeData() const -{ return false; } - -void BaseMechanicalVisitor::setNodeData(simulation::Node* /*node*/, SReal* nodeData, const SReal* parentData) -{ - *nodeData = (parentData == nullptr) ? 0.0 : *parentData; -} - -void BaseMechanicalVisitor::addNodeData(simulation::Node* /*node*/, SReal* parentData, const SReal* nodeData) -{ - if (parentData) - *parentData += *nodeData; -} - /// Return a class name for this visitor /// Only used for debugging / profiling purposes const char* BaseMechanicalVisitor::getClassName() const { return "MechanicalVisitor"; } diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.h index bd25f9e25b7..0120f5f0c12 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.h @@ -45,7 +45,9 @@ class SOFA_SIMULATION_CORE_API BaseMechanicalVisitor : public Visitor protected: simulation::Node* root; ///< root node from which the visitor was executed - SReal* rootData; ///< data for root node + + SOFA_ATTRIBUTE_DEPRECATED_NODEDATA() + SReal* rootData { nullptr }; ///< data for root node virtual Result processNodeTopDown(simulation::Node* node, VisitorContext* ctx); virtual void processNodeBottomUp(simulation::Node* node, VisitorContext* ctx); @@ -53,14 +55,17 @@ class SOFA_SIMULATION_CORE_API BaseMechanicalVisitor : public Visitor public: BaseMechanicalVisitor(const sofa::core::ExecParams* params); - /// Return true if this visitor need to read the node-specific data if given - virtual bool readNodeData() const; + SOFA_ATTRIBUTE_DEPRECATED_NODEDATA() + virtual bool readNodeData() const { return false; }; + + SOFA_ATTRIBUTE_DEPRECATED_NODEDATA() + virtual bool writeNodeData() const { return false; }; - /// Return true if this visitor need to write to the node-specific data if given - virtual bool writeNodeData() const; + SOFA_ATTRIBUTE_DEPRECATED_NODEDATA() + virtual void setNodeData(simulation::Node* /*node*/, SReal* /*nodeData*/, const SReal* /*parentData*/) {}; - virtual void setNodeData(simulation::Node* /*node*/, SReal* nodeData, const SReal* parentData); - virtual void addNodeData(simulation::Node* /*node*/, SReal* parentData, const SReal* nodeData); + SOFA_ATTRIBUTE_DEPRECATED_NODEDATA() + virtual void addNodeData(simulation::Node* /*node*/, SReal* /*parentData*/, const SReal* /*nodeData*/) {}; /// Return a class name for this visitor /// Only used for debugging / profiling purposes diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in b/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in index a949327fc2c..9c80cf1bd83 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in @@ -248,3 +248,10 @@ SOFA_ATTRIBUTE_DEPRECATED( \ #define SOFA_ATTRIBUTE_DEPRECATED_LOCALSTORAGE() \ SOFA_ATTRIBUTE_DEPRECATED("v23.12", "v24.06", "LocalStorage feature was seemingly not used so it has been deprecated.") #endif // SOFA_BUILD_SOFA_SIMULATION_CORE + +#ifdef SOFA_BUILD_SOFA_SIMULATION_CORE +#define SOFA_ATTRIBUTE_DEPRECATED_NODEDATA() +#else +#define SOFA_ATTRIBUTE_DEPRECATED_NODEDATA() \ +SOFA_ATTRIBUTE_DEPRECATED("v23.12", "v24.06", "rootdata/nodedata feature was never really used so it has been deprecated. All the related functions/members/variables won't do anything.") +#endif // SOFA_BUILD_SOFA_SIMULATION_CORE diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetNonDiagonalMassesCountVisitor.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetNonDiagonalMassesCountVisitor.h index 6053eb36900..6b173d74223 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetNonDiagonalMassesCountVisitor.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalGetNonDiagonalMassesCountVisitor.h @@ -45,11 +45,6 @@ class SOFA_SIMULATION_CORE_API MechanicalGetNonDiagonalMassesCountVisitor : publ /// Return a class name for this visitor /// Only used for debugging / profiling purposes const char* getClassName() const override { return "MechanicalGetNonDiagonalMassesCountVisitor";} - - bool writeNodeData() const override - { - return true; - } }; } diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVDotVisitor.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVDotVisitor.h index 837ee617d86..87ccad2fbe8 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVDotVisitor.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVDotVisitor.h @@ -53,10 +53,6 @@ class SOFA_SIMULATION_CORE_API MechanicalVDotVisitor : public BaseMechanicalVisi { return true; } - bool writeNodeData() const override - { - return true; - } #ifdef SOFA_DUMP_VISITOR_INFO void setReadWriteVectors() override diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVMultiOpVisitor.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVMultiOpVisitor.h index 4e148074844..162d6c7fe13 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVMultiOpVisitor.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVMultiOpVisitor.h @@ -59,10 +59,6 @@ class SOFA_SIMULATION_CORE_API MechanicalVMultiOpVisitor : public BaseMechanical { return true; } - bool readNodeData() const override - { - return true; - } #ifdef SOFA_DUMP_VISITOR_INFO void setReadWriteVectors() override { diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVNormVisitor.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVNormVisitor.h index 45d53382d1d..8f161ec7172 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVNormVisitor.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVNormVisitor.h @@ -58,10 +58,6 @@ class SOFA_SIMULATION_CORE_API MechanicalVNormVisitor : public BaseMechanicalVis { return true; } - bool writeNodeData() const override - { - return true; - } #ifdef SOFA_DUMP_VISITOR_INFO void setReadWriteVectors() override diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVOpVisitor.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVOpVisitor.h index b4f512fc693..3bf1f0fd93d 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVOpVisitor.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/mechanicalvisitor/MechanicalVOpVisitor.h @@ -64,10 +64,6 @@ class SOFA_SIMULATION_CORE_API MechanicalVOpVisitor : public BaseMechanicalVisit { return true; } - bool readNodeData() const override - { - return true; - } #ifdef SOFA_DUMP_VISITOR_INFO void setReadWriteVectors() override {