Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Simulation.Core] Remove usage of ill-used nodeData in MechanicalGetNonDiagonalMassesCountVisitor and MechanicalVDotVisitor #4328

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
}
}
Loading