Skip to content
Open
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 @@ -40,15 +40,19 @@ StopperLagrangianConstraint<DataTypes>::StopperLagrangianConstraint(MechanicalSt
template<class DataTypes>
void StopperLagrangianConstraint<DataTypes>::init()
{
this->mstate = dynamic_cast<MechanicalState*>(this->getContext()->getMechanicalState());
assert(this->mstate);
core::behavior::SingleStateAccessor<DataTypes>::init();

helper::WriteAccessor<Data<VecCoord> > xData = *this->mstate->write(core::vec_id::write_access::position);
VecCoord& x = xData.wref();
if (x[d_index.getValue()].x() < d_min.getValue())
x[d_index.getValue()].x() = (Real) d_min.getValue();
if (x[d_index.getValue()].x() > d_max.getValue())
x[d_index.getValue()].x() = (Real) d_max.getValue();
if (!this->isComponentStateInvalid())
{
helper::WriteAccessor<Data<VecCoord> > xData = *this->mstate->write(core::vec_id::write_access::position);
VecCoord& x = xData.wref();
if (x[d_index.getValue()].x() < d_min.getValue())
x[d_index.getValue()].x() = (Real) d_min.getValue();
if (x[d_index.getValue()].x() > d_max.getValue())
x[d_index.getValue()].x() = (Real) d_max.getValue();

Comment on lines +47 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that this is just the old code refactored. But I find it intriguing that a lagrangian constraint is performing a pure projection at init. Nobody asked for this. I would remove this because it might create very bad internal stress in some cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This projection is here since the introduction of the component (9be66af)

If we remove the projection, we can remove the entire init method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would advocate for it. Let the constraint solver do the work instead of doing something unrelated before the solving...

this->d_componentState.setValue(core::objectmodel::ComponentState::Valid);
}
}

template<class DataTypes>
Expand Down
Loading