Skip to content

Commit

Permalink
Merge branch 'master' into 24_11_add_warning_when_using_disabled_mech…
Browse files Browse the repository at this point in the history
…anism
  • Loading branch information
hugtalbot authored Dec 6, 2024
2 parents f989e41 + bece924 commit 3746ff8
Show file tree
Hide file tree
Showing 239 changed files with 1,290 additions and 1,046 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void ConstraintAnimationLoop::freeMotion(const core::ExecParams* params, simulat
if(d_schemeCorrection.getValue())
{
sofa::core::ConstraintParams cparams(*params);
sofa::core::MultiVecDerivId f = core::VecDerivId::externalForce();
sofa::core::MultiVecDerivId f = core::vec_id::write_access::externalForce;

for (auto cc : constraintCorrections)
{
Expand All @@ -319,7 +319,7 @@ void ConstraintAnimationLoop::freeMotion(const core::ExecParams* params, simulat

{
sofa::core::MechanicalParams mparams(*params);
sofa::core::MultiVecCoordId xfree = sofa::core::VecCoordId::freePosition();
sofa::core::MultiVecCoordId xfree = sofa::core::vec_id::write_access::freePosition;
mparams.x() = xfree;
MechanicalProjectPositionVisitor(&mparams, 0, xfree ).execute(context);
MechanicalPropagateOnlyPositionVisitor(&mparams, 0, xfree ).execute(context);
Expand All @@ -331,7 +331,7 @@ void ConstraintAnimationLoop::freeMotion(const core::ExecParams* params, simulat
////////propagate acceleration ? //////

//this is done to set dx to zero in subgraph
core::MultiVecDerivId dx_id = core::VecDerivId::dx();
core::MultiVecDerivId dx_id = core::vec_id::write_access::dx;
MechanicalVOpVisitor(params, dx_id, core::ConstVecId::null(), core::ConstVecId::null(), 1.0 ).setMapped(true).execute(context);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -393,28 +393,28 @@ void ConstraintAnimationLoop::setConstraintEquations(const core::ExecParams* par
void ConstraintAnimationLoop::writeAndAccumulateAndCountConstraintDirections(const core::ExecParams* params, simulation::Node *context, unsigned int &numConstraints)
{
core::ConstraintParams cparams = core::ConstraintParams(*params);
cparams.setX(core::ConstVecCoordId::freePosition());
cparams.setV(core::ConstVecDerivId::freeVelocity());
cparams.setX(core::vec_id::read_access::freePosition);
cparams.setV(core::vec_id::read_access::freeVelocity);

// calling resetConstraint on LMConstraints and MechanicalStates
MechanicalResetConstraintVisitor(&cparams).execute(context);

// calling applyConstraint on each constraint
MechanicalSetConstraint(&cparams, core::MatrixDerivId::constraintJacobian(), numConstraints).execute(context);
MechanicalSetConstraint(&cparams, core::vec_id::write_access::constraintJacobian, numConstraints).execute(context);

sofa::helper::AdvancedTimer::valSet("numConstraints", numConstraints);

// calling accumulateConstraint on the mappings
MechanicalAccumulateConstraint2(&cparams, core::MatrixDerivId::constraintJacobian()).execute(context);
MechanicalAccumulateConstraint2(&cparams, core::vec_id::write_access::constraintJacobian).execute(context);

getCP()->clear(numConstraints,this->d_tol.getValue());
}

void ConstraintAnimationLoop::getIndividualConstraintViolations(const core::ExecParams* params, simulation::Node *context)
{
core::ConstraintParams cparams = core::ConstraintParams(*params);
cparams.setX(core::ConstVecCoordId::freePosition());
cparams.setV(core::ConstVecDerivId::freeVelocity());
cparams.setX(core::vec_id::read_access::freePosition);
cparams.setV(core::vec_id::read_access::freeVelocity);

constraint::lagrangian::solver::MechanicalGetConstraintViolationVisitor(&cparams, getCP()->getDfree()).execute(context);
}
Expand All @@ -423,8 +423,8 @@ void ConstraintAnimationLoop::getIndividualConstraintSolvingProcess(const core::
{
/// calling getConstraintResolution: each constraint provides a method that is used to solve it during GS iterations
core::ConstraintParams cparams = core::ConstraintParams(*params);
cparams.setX(core::ConstVecCoordId::freePosition());
cparams.setV(core::ConstVecDerivId::freeVelocity());
cparams.setX(core::vec_id::read_access::freePosition);
cparams.setV(core::vec_id::read_access::freeVelocity);

MechanicalGetConstraintResolutionVisitor(&cparams, getCP()->getConstraintResolutions(), 0).execute(context);
}
Expand Down Expand Up @@ -467,12 +467,12 @@ void ConstraintAnimationLoop::correctiveMotion(const core::ExecParams* params, s

simulation::common::MechanicalOperations mop(params, node);

mop.propagateV(core::VecDerivId::velocity());
mop.propagateV(core::vec_id::write_access::velocity);

mop.propagateDx(core::VecDerivId::dx(), true);
mop.propagateDx(core::vec_id::write_access::dx, true);

// "mapped" x = xfree + dx
MechanicalVOpVisitor(params, core::VecCoordId::position(), core::ConstVecCoordId::freePosition(), core::ConstVecDerivId::dx(), 1.0 ).setOnlyMapped(true).execute(node);
MechanicalVOpVisitor(params, core::vec_id::write_access::position, core::vec_id::read_access::freePosition, core::vec_id::read_access::dx, 1.0 ).setOnlyMapped(true).execute(node);

if(!d_schemeCorrection.getValue())
{
Expand Down Expand Up @@ -564,8 +564,8 @@ void ConstraintAnimationLoop::step ( const core::ExecParams* params, SReal dt )

// This solver will work in freePosition and freeVelocity vectors.
// We need to initialize them if it's not already done.
MechanicalVInitVisitor<core::V_COORD>(params, core::VecCoordId::freePosition(), core::ConstVecCoordId::position(), true).execute(node);
MechanicalVInitVisitor<core::V_DERIV>(params, core::VecDerivId::freeVelocity(), core::ConstVecDerivId::velocity()).execute(node);
MechanicalVInitVisitor<core::V_COORD>(params, core::vec_id::write_access::freePosition, core::vec_id::read_access::position, true).execute(node);
MechanicalVInitVisitor<core::V_DERIV>(params, core::vec_id::write_access::freeVelocity, core::vec_id::read_access::velocity).execute(node);

if (d_doCollisionsFirst.getValue())
{
Expand Down Expand Up @@ -622,8 +622,8 @@ void ConstraintAnimationLoop::step ( const core::ExecParams* params, SReal dt )

//////////////// BEFORE APPLYING CONSTRAINT : propagate position through mapping
core::MechanicalParams mparams(*params);
MechanicalProjectPositionVisitor(&mparams, 0, core::VecCoordId::position()).execute(node);
MechanicalPropagateOnlyPositionVisitor(&mparams, 0, core::VecCoordId::position()).execute(node);
MechanicalProjectPositionVisitor(&mparams, 0, core::vec_id::write_access::position).execute(node);
MechanicalPropagateOnlyPositionVisitor(&mparams, 0, core::vec_id::write_access::position).execute(node);


/// CONSTRAINT SPACE & COMPLIANCE COMPUTATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ void FreeMotionAnimationLoop::init()

simulation::common::VectorOperations vop(core::execparams::defaultInstance(), getContext());

MultiVecDeriv dx(&vop, core::VecDerivId::dx());
MultiVecDeriv dx(&vop, core::vec_id::write_access::dx);
dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true);

MultiVecDeriv df(&vop, core::VecDerivId::dforce());
MultiVecDeriv df(&vop, core::vec_id::write_access::dforce);
df.realloc(&vop, !d_threadSafeVisitor.getValue(), true);

if (!l_constraintSolver)
Expand Down Expand Up @@ -163,10 +163,10 @@ void FreeMotionAnimationLoop::step(const sofa::core::ExecParams* params, SReal d
simulation::common::VectorOperations vop(params, node);
simulation::common::MechanicalOperations mop(params, getContext());

MultiVecCoord pos(&vop, core::VecCoordId::position() );
MultiVecDeriv vel(&vop, core::VecDerivId::velocity() );
MultiVecCoord freePos(&vop, core::VecCoordId::freePosition() );
MultiVecDeriv freeVel(&vop, core::VecDerivId::freeVelocity() );
MultiVecCoord pos(&vop, core::vec_id::write_access::position );
MultiVecDeriv vel(&vop, core::vec_id::write_access::velocity );
MultiVecCoord freePos(&vop, core::vec_id::write_access::freePosition );
MultiVecDeriv freeVel(&vop, core::vec_id::write_access::freeVelocity );

core::ConstraintParams cparams(*params);
cparams.setX(freePos);
Expand All @@ -175,18 +175,18 @@ void FreeMotionAnimationLoop::step(const sofa::core::ExecParams* params, SReal d
cparams.setLambda(l_constraintSolver->getLambda());
cparams.setOrder(m_solveVelocityConstraintFirst.getValue() ? core::ConstraintOrder::VEL : core::ConstraintOrder::POS_AND_VEL);

MultiVecDeriv dx(&vop, core::VecDerivId::dx());
MultiVecDeriv dx(&vop, core::vec_id::write_access::dx);
dx.realloc(&vop, !d_threadSafeVisitor.getValue(), true);

MultiVecDeriv df(&vop, core::VecDerivId::dforce());
MultiVecDeriv df(&vop, core::vec_id::write_access::dforce);
df.realloc(&vop, !d_threadSafeVisitor.getValue(), true);

// This solver will work in freePosition and freeVelocity vectors.
// We need to initialize them if it's not already done.
{
SCOPED_TIMER("MechanicalVInitVisitor");
MechanicalVInitVisitor< core::V_COORD >(params, core::VecCoordId::freePosition(), core::ConstVecCoordId::position(), true).execute(node);
MechanicalVInitVisitor< core::V_DERIV >(params, core::VecDerivId::freeVelocity(), core::ConstVecDerivId::velocity(), true).execute(node);
MechanicalVInitVisitor< core::V_COORD >(params, core::vec_id::write_access::freePosition, core::vec_id::read_access::position, true).execute(node);
MechanicalVInitVisitor< core::V_DERIV >(params, core::vec_id::write_access::freeVelocity, core::vec_id::read_access::velocity, true).execute(node);
}

// This animation loop works with lagrangian constraints. Forces derive from the constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ bool LocalMinDistance::testValidity(Point &p, const Vec3 &PQ) const
return true;

BaseMeshTopology* topology = p.getCollisionModel()->getCollisionTopology();
const auto& x =(p.getCollisionModel()->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue());
const auto& x =(p.getCollisionModel()->getMechanicalState()->read(core::vec_id::read_access::position)->getValue());

const auto& trianglesAroundVertex = topology->getTrianglesAroundVertex(p.getIndex());
const auto& edgesAroundVertex = topology->getEdgesAroundVertex(p.getIndex());
Expand Down Expand Up @@ -1278,7 +1278,7 @@ bool LocalMinDistance::testValidity(Line &l, const Vec3 &PQ) const
AB.normalize();

BaseMeshTopology* topology = l.getCollisionModel()->getCollisionTopology();
const auto& x =(l.getCollisionModel()->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue());
const auto& x =(l.getCollisionModel()->getMechanicalState()->read(core::vec_id::read_access::position)->getValue());
const auto& trianglesAroundEdge = topology->getTrianglesAroundEdge(l.getIndex());

if ( trianglesAroundEdge.size() == 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ bool MeshMinProximityIntersection::testIntersection(Line& e1, Line& e2, const co
const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity();
using Real = Line::Coord::value_type;

const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();

const auto& e1p1 = positions_e1[e1.i1()];
const auto& e1p2 = positions_e1[e1.i2()];
Expand Down Expand Up @@ -129,8 +129,8 @@ int MeshMinProximityIntersection::computeIntersection(Line& e1, Line& e2, Output
const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity();
using Real = Line::Coord::value_type;

const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();

const auto& e1p1 = positions_e1[e1.i1()];
const auto& e1p2 = positions_e1[e1.i2()];
Expand Down Expand Up @@ -216,8 +216,8 @@ bool MeshMinProximityIntersection::testIntersection(Triangle& e2, Point& e1, con

const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity();

const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();

const auto& e1p1 = positions_e1[e1.getIndex()];
const auto& e2p1 = positions_e2[e2.p1Index()];
Expand Down Expand Up @@ -272,8 +272,8 @@ int MeshMinProximityIntersection::computeIntersection(Triangle& e2, Point& e1, O

const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity();

const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();

const auto& e1p1 = positions_e1[e1.getIndex()];
const auto& e2p1 = positions_e2[e2.p1Index()];
Expand Down Expand Up @@ -361,8 +361,8 @@ bool MeshMinProximityIntersection::testIntersection(Line& e2, Point& e1, const c
const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity();
using Real = Line::Coord::value_type;

const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();

const auto& e1p1 = positions_e1[e1.getIndex()];
const auto& e2p1 = positions_e2[e2.i1()];
Expand Down Expand Up @@ -391,8 +391,8 @@ int MeshMinProximityIntersection::computeIntersection(Line& e2, Point& e1, Outpu

const SReal alarmDist = currentIntersection->getAlarmDistance() + e1.getProximity() + e2.getProximity();

const auto& positions_e1 = e1.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::ConstVecCoordId::position())->getValue();
const auto& positions_e1 = e1.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();
const auto& positions_e2 = e2.model->getMechanicalState()->read(core::vec_id::read_access::position)->getValue();

const auto& e1p1 = positions_e1[e1.getIndex()];
const auto& e2p1 = positions_e2[e2.i1()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ typename CylinderCollisionModel<DataTypes>::Real CylinderCollisionModel< DataTyp

template<class DataTypes>
const typename CylinderCollisionModel<DataTypes>::Coord & CylinderCollisionModel< DataTypes >::center(sofa::Index i)const{
return DataTypes::getCPos((m_mstate->read(core::ConstVecCoordId::position())->getValue())[i]);
return DataTypes::getCPos((m_mstate->read(core::vec_id::read_access::position)->getValue())[i]);
}

template<class DataTypes>
Expand Down Expand Up @@ -255,7 +255,7 @@ typename TCylinder<DataTypes>::Real TCylinder<DataTypes >::radius() const

template<class DataTypes>
const typename CylinderCollisionModel<DataTypes>::Coord & CylinderCollisionModel<DataTypes >::velocity(sofa::Index index) const {
return DataTypes::getDPos(((m_mstate->read(core::ConstVecDerivId::velocity())->getValue()))[index]);
return DataTypes::getDPos(((m_mstate->read(core::vec_id::read_access::velocity)->getValue()))[index]);
}


Expand All @@ -264,7 +264,7 @@ const typename TCylinder<DataTypes>::Coord & TCylinder<DataTypes >::v() const {r

template<class DataTypes>
const sofa::type::Quat<SReal> CylinderCollisionModel<DataTypes >::orientation(sofa::Index index)const{
return m_mstate->read(core::ConstVecCoordId::position())->getValue()[index].getOrientation();
return m_mstate->read(core::vec_id::read_access::position)->getValue()[index].getOrientation();
}

template<class DataTypes>
Expand Down
Loading

0 comments on commit 3746ff8

Please sign in to comment.