Skip to content

Commit

Permalink
[Simulation.Core] BaseMechanicalVisitor: Deprecate rootData (#4350)
Browse files Browse the repository at this point in the history
* remove ref to nodedata

* add compat

* Update Sofa/framework/Simulation/Core/src/sofa/simulation/config.h.in (typo)

Co-authored-by: Alex Bilger <[email protected]>

---------

Co-authored-by: Alex Bilger <[email protected]>
  • Loading branch information
fredroy and alxbilger authored Dec 20, 2023
1 parent 27878bd commit b1c49a7
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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"; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,27 @@ 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);

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit b1c49a7

Please sign in to comment.