From 5b032c59a84172a9ae4ec665f3085a1ff4251ea0 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Mon, 5 Oct 2026 11:05:32 +0200 Subject: [PATCH 1/3] Copy local state instead of going through the mappings --- .../VelocityBasedImplicitIntegrationScheme.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/VelocityBasedImplicitIntegrationScheme.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/VelocityBasedImplicitIntegrationScheme.cpp index 18ecc22bb96..b654d44fa93 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/VelocityBasedImplicitIntegrationScheme.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/VelocityBasedImplicitIntegrationScheme.cpp @@ -28,6 +28,7 @@ #include #include using sofa::simulation::mechanicalvisitor::MechanicalGetNonDiagonalMassesCountVisitor; +#include namespace sofa::simulation::integrationscheme { @@ -65,9 +66,12 @@ void VelocityBasedImplicitIntegrationScheme::doSetupIntegrationStep(const core:: // This is only there for lagrangian based simulation, to make sure we start using the real pose // instead of the free pos (same for velocity) - - m_vop->v_eq(m_vResult, core::vec_id::write_access::velocity); - m_vop->v_eq(m_xResult, core::vec_id::write_access::position); + simulation::mechanicalvisitor::MechanicalVOpVisitor copyPoseInFreePose(params, m_vResult, core::vec_id::write_access::velocity); + simulation::mechanicalvisitor::MechanicalVOpVisitor copyVelInFreeVel(params, m_vResult, core::vec_id::write_access::velocity); + copyVelInFreeVel.setMapped(true); + copyPoseInFreePose.setMapped(true); + this->getContext()->executeVisitor(©PoseInFreePose); + this->getContext()->executeVisitor(©VelInFreeVel); // Deal with higher order integration scheme const Size order = getIntegrationSchemeTimeOrder(); From 0546db655dd569d8c52c496aec0124d85ef3948d Mon Sep 17 00:00:00 2001 From: Paul Baksic <30337881+bakpaul@users.noreply.github.com> Date: Mon, 12 Oct 2026 09:30:32 +0200 Subject: [PATCH 2/3] Apply batched suggestions from code review Co-authored-by: Frederick Roy --- .../VelocityBasedImplicitIntegrationScheme.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/VelocityBasedImplicitIntegrationScheme.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/VelocityBasedImplicitIntegrationScheme.cpp index b654d44fa93..070e2025dc3 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/VelocityBasedImplicitIntegrationScheme.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/VelocityBasedImplicitIntegrationScheme.cpp @@ -66,7 +66,7 @@ void VelocityBasedImplicitIntegrationScheme::doSetupIntegrationStep(const core:: // This is only there for lagrangian based simulation, to make sure we start using the real pose // instead of the free pos (same for velocity) - simulation::mechanicalvisitor::MechanicalVOpVisitor copyPoseInFreePose(params, m_vResult, core::vec_id::write_access::velocity); + simulation::mechanicalvisitor::MechanicalVOpVisitor copyPoseInFreePose(params, m_xResult, core::vec_id::write_access::position); simulation::mechanicalvisitor::MechanicalVOpVisitor copyVelInFreeVel(params, m_vResult, core::vec_id::write_access::velocity); copyVelInFreeVel.setMapped(true); copyPoseInFreePose.setMapped(true); From 65911d214fd9edd9c9c59078f05e4662d9c6b430 Mon Sep 17 00:00:00 2001 From: Paul Baksic Date: Mon, 12 Oct 2026 09:39:37 +0200 Subject: [PATCH 3/3] Add state copy for AccelerationBased too --- .../AccelerationBasedImplicitIntegrationScheme.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/AccelerationBasedImplicitIntegrationScheme.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/AccelerationBasedImplicitIntegrationScheme.cpp index a3cb39311ae..9488cb2c10b 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/AccelerationBasedImplicitIntegrationScheme.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/integrationscheme/AccelerationBasedImplicitIntegrationScheme.cpp @@ -27,6 +27,7 @@ #include #include #include +#include using sofa::simulation::mechanicalvisitor::MechanicalGetNonDiagonalMassesCountVisitor; @@ -46,8 +47,13 @@ void AccelerationBasedImplicitIntegrationScheme::doSetupIntegrationStep(const co // This is only there for lagrangian based simulation, to make sure we start using the real pose // instead of the free pos (same for velocity) - m_vop->v_eq(m_vResult, core::vec_id::write_access::velocity); - m_vop->v_eq(m_xResult, core::vec_id::write_access::position); + simulation::mechanicalvisitor::MechanicalVOpVisitor copyPoseInFreePose(params, m_xResult, core::vec_id::write_access::position); + simulation::mechanicalvisitor::MechanicalVOpVisitor copyVelInFreeVel(params, m_vResult, core::vec_id::write_access::velocity); + copyVelInFreeVel.setMapped(true); + copyPoseInFreePose.setMapped(true); + this->getContext()->executeVisitor(©PoseInFreePose); + this->getContext()->executeVisitor(©VelInFreeVel); + // Deal with higher order integration scheme const Size order = getIntegrationSchemeTimeOrder();