Skip to content

Commit fbf4278

Browse files
alxbilgerhugtalbot
andauthored
[Core] Clarify how the visitor knows if a state is mapped or not (#6086)
clarify how the visitor knows if a state is mapped or not Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
1 parent d7b3d75 commit fbf4278

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ BaseMechanicalVisitor::BaseMechanicalVisitor(const sofa::core::ExecParams *param
5353
canAccessSleepingNode = false;
5454
}
5555

56+
bool BaseMechanicalVisitor::isMechanicalStateMapped(simulation::Node* node) const
57+
{
58+
/**
59+
* WARNING!!!!!
60+
*
61+
* This condition is not valid for all cases, as it only checks for the presence of a mechanical
62+
* mapping in the same Node. This condition does not ensure that the state is not an output of a
63+
* mapping.
64+
*
65+
* Examples of situations where this condition is not appropritate:
66+
* - No mapping in the Node but the mapping is defined in another Node.
67+
* - There is a mapping in the Node, but the state is not an output of this mapping.
68+
*/
69+
return node->mechanicalMapping != nullptr;
70+
}
71+
5672
Visitor::Result BaseMechanicalVisitor::processNodeTopDown(simulation::Node *node, VisitorContext *ctx)
5773
{
5874
for (auto *solver : node->solver)
@@ -76,7 +92,7 @@ Visitor::Result BaseMechanicalVisitor::processNodeTopDown(simulation::Node *node
7692

7793
if (node->mechanicalState != nullptr)
7894
{
79-
if (node->mechanicalMapping != nullptr)
95+
if (isMechanicalStateMapped(node))
8096
{
8197
res = runVisitorTask(this, ctx, &BaseMechanicalVisitor::fwdMappedMechanicalState, &*node->mechanicalState, fwdVisitorType);
8298
}
@@ -134,7 +150,7 @@ void BaseMechanicalVisitor::processNodeBottomUp(simulation::Node *node, VisitorC
134150

135151
if (node->mechanicalState != nullptr)
136152
{
137-
if (node->mechanicalMapping != nullptr)
153+
if (isMechanicalStateMapped(node))
138154
{
139155
runVisitorTask(this, ctx, &BaseMechanicalVisitor::bwdMappedMechanicalState, &*node->mechanicalState, bwdVisitorType);
140156
}

Sofa/framework/Simulation/Core/src/sofa/simulation/BaseMechanicalVisitor.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class SOFA_SIMULATION_CORE_API BaseMechanicalVisitor : public Visitor
4444
{
4545

4646
protected:
47-
simulation::Node* root; ///< root node from which the visitor was executed
47+
simulation::Node* root { nullptr }; ///< root node from which the visitor was executed
4848

4949
virtual Result processNodeTopDown(simulation::Node* node, VisitorContext* ctx);
5050
virtual void processNodeBottomUp(simulation::Node* node, VisitorContext* ctx);
@@ -56,6 +56,12 @@ class SOFA_SIMULATION_CORE_API BaseMechanicalVisitor : public Visitor
5656
/// Only used for debugging / profiling purposes
5757
const char* getClassName() const override;
5858

59+
/**
60+
* Returns true if the node has a mapped mechanical state. It is mapped if the state is not an
61+
* output of a mapping.
62+
*/
63+
virtual bool isMechanicalStateMapped(simulation::Node* node) const;
64+
5965
/**@name Forward processing
6066
Methods called during the forward (top-down) traversal of the data structure.
6167
Method processNodeTopDown(simulation::Node*) calls the fwd* methods in the order given here. When there is a mapping, it is processed first, then method fwdMappedMechanicalState is applied to the BaseMechanicalState.

0 commit comments

Comments
 (0)