Skip to content

[BUGFIX] DoAssembly: solve the acceleration-level problem instead of reporting a velocity increment - #852

Merged
rserban merged 1 commit into
mainfrom
fix/assembly-acceleration-level
Oct 5, 2026
Merged

rserban merged 1 commit into
mainfrom
fix/assembly-acceleration-level

Conversation

@DanNegrut

Copy link
Copy Markdown
Contributor

Summary

ChSystem::DoAssembly() at AssemblyAnalysis::Level::ACCELERATION reported the velocity increment of a 1e-6 linearized Euler step as the acceleration. That increment satisfies Cq a = 0 and omits the quadratic-velocity term -(dCq/dt) v, so for any constrained system in motion the scattered accelerations and reactions were wrong (for a pendulum, the entire centripetal part). The acceleration level now takes a second step in the same velocity-level (DVI) form, with the mass matrix only and with the quadratic-velocity term on the constraint right-hand side, so bilateral and rheonomic constraints get the acceleration-level solution while unilateral constraints and frictional contacts keep their velocity-level treatment. Also fixed on the way: DoAssembly() left its internal 1e-6 step in the system, so DoFrameKinematics() advanced time by 1e-6 per frame instead of the requested step. Seven new unit tests cover a pendulum on a ChLinkDistance against its closed form (two lengths, two solvers, reaction compared as a vector), a motor-driven body with a time-dependent angle, a velocity-dependent force, the ACCELERATION-only action, a free body, a two-frame DoFrameKinematics(), and a failing acceleration-level solve.

Related Issue(s)

fixes #846

Author(s)

Dan Negrut, University of Wisconsin-Madison, [email protected] (corresponding)

Licensing

I agree that my contribution is made available under the BSD-3-Clause license of Project Chrono and may be redistributed under those terms.

Backward Compatibility

No API change. Behavior changes:

  • Accelerations and reactions reported after DoAssembly() (and therefore DoFrameKinematics()) now include the quadratic-velocity term. In motion they change by omega^2 L-sized amounts, which were the missing physics. At rest they change by the central-differencing floor of the added term, about 1e-4 times the constraint's length scale in SI units for the accelerations (1e-4 for a 1 m distance constraint, 1e-2 for 100 m) and that times the mass involved for the reactions, where they were previously exact to roundoff.
  • DoAssembly() no longer leaves GetStep() == 1e-6 behind; DoFrameKinematics(frame_time, step_size) now advances by step_size per frame as documented.
  • Systems with active contacts at assembly time: a resting and a separating box-on-ground case give the same results as before (resting: free fall is reported, a pre-existing limitation, see below; separating: correct). A sliding frictional contact gives a different acceleration than before, and neither value is meaningful: the relaxed cone complementarity of the velocity-level step gives a sliding contact an artificial separation velocity of order mu times the sliding speed (and the matching friction impulse), so the "consistent" velocity it produces is already off; the old code then published that velocity jump divided by 1e-6, the new code publishes the second step's increment. No non-regression is claimed for that case.
  • DoStepDynamics() trajectories are unaffected.

Detailed Description

ChAssemblyAnalysis::AssemblyAnalysis() handled Level::VELOCITY and Level::ACCELERATION together: one linearized semi-implicit Euler step with dt = 1e-6 produced a velocity V satisfying Cq(q) V = -C/dt - Ct, and (V - Vold)/dt was scattered as the acceleration with the step's multipliers, scaled by 1/dt, as reactions. Because the Jacobian is frozen at q, that increment has no component along the constraint normals: it satisfies Cq a = 0, not Cq a = -(dCq/dt) v.

The fix keeps the velocity-level step unchanged and, for the acceleration level, takes a second step from the now consistent (X, V):

[ M    Cq' ] [ v2    ]   [ M V + dt f          ]
[ Cq   0   ] [ -dt l ] = [ -C/dt - Ct - dt Qc  ]

with Qc = d^2C/dt^2 along V obtained by central differencing of C (step 1e-6, the same differencing ChIntegrableIIorder::StateSolveA uses), and reports a = (v2 - V)/dt and l as the reactions, so that M a + Cq' l = f and Cq a = -Qc. Only the mass matrix enters this solve: it evaluates the acceleration at the current state and is not an integration step, so the dF/dv and dF/dx factors of the velocity step are not used (with them, dF/dv V leaks into the reported acceleration, doubling the deceleration of a damped body; a unit test with a velocity-dependent force guards this). Solving the smooth acceleration-level problem directly (StateSolveA) was tried first and rejected: for unilateral constraints a smooth acceleration-level complementarity keeps a separating contact active and cannot represent sliding friction, whereas the DVI-form step decides the active set and friction direction from v2, as every dynamics step does. The return value of the solve is honored: on failure nothing is scattered and NOT_CONVERGED is returned.

Measured on a point mass on a ChLinkDistance (hanging at 35 deg, m = 1 kg), error of the reported acceleration against a = g - (g.phat + omega^2 L) phat, identical to six digits with the PSOR and the SPARSE_QR solvers:

omega [rad/s] L = 1 m, before L = 1 m, after L = 100 m, after
0.0 3e-11 2.2e-4 1.4e-2
1.0 1.00 8.9e-5 1.6e-2
2.0 4.00 1.3e-4 3.6e-2
3.0 9.00 1.3e-4 3.0e-2

Before the fix the error was exactly omega^2 L along the rod and the reported reaction was m g cos(35 deg) = 8.036 N at every speed (exact at omega = 3: 17.04 N). After the fix the residual is the differencing floor, ~eps L / Delta^2, one-sided along the rod; the reaction vector in the absolute frame matches -m lam phat to the same floor. A body driven by a ChLinkMotorRotationAngle with nonzero angular velocity and acceleration at the assembly time matches alpha x r - omega^2 r to 1.2e-4 with the direct solver. Lowering the floor (a larger difference step) is left for a separate change.

Two numerical notes, both properties of the velocity-increment definition the assembly has always used: the accelerations and reactions carry an iterative solver's residual amplified by 1/dt (the motor case with six coupled constraints and the default PSOR settings gives a 1e-2 velocity residual and hence an O(1e4) acceleration error; the direct sparse solvers do not), and the differencing floor above. Both are documented in the header.

Checks: utest_CH_assembly_acceleration (new, 7 tests) passes; the 14 existing unit tests that call DoAssembly(FULL) (utest_JOINT_distance, _revolute, _linactuator, _cylindrical, _prismatic, _spherical, _universal, _revsph, _rackpinion, _rotspring, _transpring, _tsda, _distance_unilateral, utest_CH_assembly) still pass. Built and run with MSVC 19.44 on Windows, core module, clean configure and build.

Observations from testing assembly with active contacts, pre-existing and not addressed here (filed as #850 and #851): with dt = 1e-6 the -C/dt term deactivates a resting contact with any positive gap, so DoAssembly() reports free fall for a box sitting on the ground; and for a sliding frictional contact the relaxed cone complementarity of the velocity-level step alters the sliding velocity (the known artificial separation velocity of the relaxation, here 0.35 m/s upward and the matching mu times that loss of sliding speed, from a 1e-6 s step). Also pre-existing: DoFrameKinematics() assembles at the start of each frame and then advances the clock, so the final state corresponds to frame_time - step_size.

The related PyChrono limitation, that ChState and ChStateDelta cannot be sized from Python, is #847 and is not addressed here.

🤖 Generated with Claude Code

…rying the quadratic-velocity term

The acceleration level of ChAssemblyAnalysis reported the velocity increment of
a 1e-6 linearized Euler step as the acceleration. With the Jacobian frozen at q
that increment satisfies Cq a = 0 and omits the quadratic-velocity term
-(dCq/dt) v, so accelerations and reactions after DoAssembly() were wrong for
any constrained system in motion (a pendulum lost its entire centripetal part),
and correct only at rest, which is why the joint tests never saw it (#846).

The acceleration level now takes a second step in the same DVI form from the
consistent (X, V), with the mass matrix only (no dF/dv or dF/dx factors: this
evaluates the acceleration at the current state, it is not an integration
step) and with the quadratic-velocity term, obtained by central differencing
of C along V (step 1e-6, as in StateSolveA), added to the constraint
right-hand side as dt*Qc; it reports a = (v2 - V)/dt and l = L/dt.
Keeping the DVI form matters for unilateral constraints and frictional
contacts: their active set and friction direction are decided from v2, as in a
dynamics step, which a smooth acceleration-level solve cannot do (a separating
contact would stay active, sliding friction would vanish). With active
contacts, resting and separating cases give the same results as before; a
sliding frictional contact gives a different acceleration than before, and
neither value is physical (the velocity-level step itself alters the sliding
velocity, a pre-existing limitation left for a separate issue). The
differencing puts a floor of about 1e-4 times the constraint's length scale
(SI units) on the reported values, also at rest, where they were previously
exact, and an iterative solver's residual is amplified by 1/dt in them; both
are stated in the header, the CHANGELOG and the tests.

Also: the return value of the acceleration-level solve is honored (nothing is
scattered and NOT_CONVERGED is returned on failure), and ChSystem::DoAssembly()
now restores the system step it overwrote, so DoFrameKinematics() advances by
the requested step size instead of 1e-6 per frame.

New unit test utest_CH_assembly_acceleration (7 tests): pendulum on a
ChLinkDistance against its closed form at four speeds, L = 1 and L = 100, PSOR
and SPARSE_QR, reaction compared as a vector; a body driven by a
ChLinkMotorRotationAngle with a time-dependent angle; a one-DOF integrable
with a velocity-dependent force (guards the mass-only solve); ACCELERATION-only
action with a velocity-drift bound; free body; two-frame DoFrameKinematics;
failing acceleration-level solve on a mock integrable. The 14 existing unit
tests that call DoAssembly(FULL) still pass.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@rserban
rserban requested review from tasora and removed request for tasora October 2, 2026 19:08
@rserban
rserban merged commit 23c6790 into main Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DoAssembly at the ACCELERATION level drops the quadratic-velocity constraint term (Cq a = 0 instead of Cq a = -(dCq/dt) v)

2 participants