Repository navigation
[BUGFIX] DoAssembly: solve the acceleration-level problem instead of reporting a velocity increment - #852
Merged
Conversation
…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]>
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChSystem::DoAssembly()atAssemblyAnalysis::Level::ACCELERATIONreported the velocity increment of a 1e-6 linearized Euler step as the acceleration. That increment satisfiesCq a = 0and 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, soDoFrameKinematics()advanced time by 1e-6 per frame instead of the requested step. Seven new unit tests cover a pendulum on aChLinkDistanceagainst 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, theACCELERATION-only action, a free body, a two-frameDoFrameKinematics(), 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:
DoAssembly()(and thereforeDoFrameKinematics()) now include the quadratic-velocity term. In motion they change byomega^2 L-sized amounts, which were the missing physics. At rest they change by the central-differencing floor of the added term, about1e-4times 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 leavesGetStep() == 1e-6behind;DoFrameKinematics(frame_time, step_size)now advances bystep_sizeper frame as documented.mutimes 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()handledLevel::VELOCITYandLevel::ACCELERATIONtogether: one linearized semi-implicit Euler step withdt = 1e-6produced a velocityVsatisfyingCq(q) V = -C/dt - Ct, and(V - Vold)/dtwas scattered as the acceleration with the step's multipliers, scaled by1/dt, as reactions. Because the Jacobian is frozen atq, that increment has no component along the constraint normals: it satisfiesCq a = 0, notCq 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):with
Qc = d^2C/dt^2alongVobtained by central differencing ofC(step 1e-6, the same differencingChIntegrableIIorder::StateSolveAuses), and reportsa = (v2 - V)/dtandlas the reactions, so thatM a + Cq' l = fandCq a = -Qc. Only the mass matrix enters this solve: it evaluates the acceleration at the current state and is not an integration step, so thedF/dvanddF/dxfactors of the velocity step are not used (with them,dF/dv Vleaks 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 fromv2, as every dynamics step does. The return value of the solve is honored: on failure nothing is scattered andNOT_CONVERGEDis returned.Measured on a point mass on a
ChLinkDistance(hanging at 35 deg, m = 1 kg), error of the reported acceleration againsta = g - (g.phat + omega^2 L) phat, identical to six digits with the PSOR and the SPARSE_QR solvers:Before the fix the error was exactly
omega^2 Lalong the rod and the reported reaction wasm g cos(35 deg) = 8.036 Nat 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 phatto the same floor. A body driven by aChLinkMotorRotationAnglewith nonzero angular velocity and acceleration at the assembly time matchesalpha x r - omega^2 rto 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 callDoAssembly(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-6the-C/dtterm deactivates a resting contact with any positive gap, soDoAssembly()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 matchingmutimes 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 toframe_time - step_size.The related PyChrono limitation, that
ChStateandChStateDeltacannot be sized from Python, is #847 and is not addressed here.🤖 Generated with Claude Code