Skip to content

Commit

Permalink
[Simulation.Core] Remove usage of ill-used nodeData in MechanicalGetN…
Browse files Browse the repository at this point in the history
…onDiagonalMassesCountVisitor and MechanicalVDotVisitor (#4328)

* remove ill-used nodedata for nondiagmass visitor

* remove ill-used nodedata for vdot visitor

* set to const ptr

* replace result type by an integer

* add keyword for lifecycle
  • Loading branch information
fredroy authored Dec 13, 2023
1 parent 4a40054 commit 9792d3d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void EulerExplicitSolver::solve(const core::ExecParams* params,
addSeparateGravity(&mop, dt, vResult);
computeForce(&mop, f);

SReal nbNonDiagonalMasses = 0;
sofa::Size nbNonDiagonalMasses = 0;
MechanicalGetNonDiagonalMassesCountVisitor(&mop.mparams, &nbNonDiagonalMasses).execute(this->getContext());

// Mass matrix is diagonal, solution can thus be found by computing acc = f/m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ namespace sofa::simulation::mechanicalvisitor

Visitor::Result MechanicalGetNonDiagonalMassesCountVisitor::fwdMass(VisitorContext* ctx, core::behavior::BaseMass* mass)
{
*ctx->nodeData += !mass->isDiagonal();
SOFA_UNUSED(ctx);

if(this->m_nbNonDiagonalMassesPtr && !mass->isDiagonal())
(*m_nbNonDiagonalMassesPtr)++;

return RESULT_CONTINUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ namespace sofa::simulation::mechanicalvisitor
class SOFA_SIMULATION_CORE_API MechanicalGetNonDiagonalMassesCountVisitor : public MechanicalVisitor
{
public:
MechanicalGetNonDiagonalMassesCountVisitor(const sofa::core::MechanicalParams* mparams, SReal* result)
: MechanicalVisitor(mparams)
sofa::Size* const m_nbNonDiagonalMassesPtr { nullptr };

// SOFA_ATTRIBUTE_DISABLED("v24.06", "v24.12", "given result is not a Real anymore since https://github.com/sofa-framework/sofa/pull/4328")
MechanicalGetNonDiagonalMassesCountVisitor(const sofa::core::MechanicalParams* mparams, SReal* result) = delete;

MechanicalGetNonDiagonalMassesCountVisitor(const sofa::core::MechanicalParams* mparams, sofa::Size* result)
: MechanicalVisitor(mparams), m_nbNonDiagonalMassesPtr(result)
{
rootData = result;
}

Result fwdMass(VisitorContext* ctx, sofa::core::behavior::BaseMass* mass) override;
Expand All @@ -46,7 +50,6 @@ class SOFA_SIMULATION_CORE_API MechanicalGetNonDiagonalMassesCountVisitor : publ
{
return true;
}

};

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ namespace sofa::simulation::mechanicalvisitor

Visitor::Result MechanicalVDotVisitor::fwdMechanicalState(VisitorContext* ctx, core::behavior::BaseMechanicalState* mm)
{
*ctx->nodeData += mm->vDot(this->params, a.getId(mm),b.getId(mm) );
if(m_total)
*m_total += mm->vDot(this->params, a.getId(mm),b.getId(mm) );

return RESULT_CONTINUE;
}

Expand All @@ -40,4 +42,4 @@ std::string MechanicalVDotVisitor::getInfos() const
return name;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ class SOFA_SIMULATION_CORE_API MechanicalVDotVisitor : public BaseMechanicalVisi
public:
sofa::core::ConstMultiVecId a;
sofa::core::ConstMultiVecId b;
SReal* const m_total { nullptr };

MechanicalVDotVisitor(const sofa::core::ExecParams* params, sofa::core::ConstMultiVecId a, sofa::core::ConstMultiVecId b, SReal* t)
: BaseMechanicalVisitor(params) , a(a), b(b) //, total(t)
: BaseMechanicalVisitor(params) , a(a), b(b), m_total(t)
{
#ifdef SOFA_DUMP_VISITOR_INFO
setReadWriteVectors();
#endif
rootData = t;
}

Result fwdMechanicalState(VisitorContext* ctx,sofa::core::behavior::BaseMechanicalState* mm) override;
Expand All @@ -65,4 +66,4 @@ class SOFA_SIMULATION_CORE_API MechanicalVDotVisitor : public BaseMechanicalVisi
}
#endif
};
}
}

0 comments on commit 9792d3d

Please sign in to comment.