Skip to content

[UPDATE] Unit test for DoAssembly accelerations on coupled mechanisms - #856

Merged
rserban merged 4 commits into
projectchrono:mainfrom
Noah-Parsons:test-assembly-acceleration-coupled
Oct 17, 2026
Merged

rserban merged 4 commits into
projectchrono:mainfrom
Noah-Parsons:test-assembly-acceleration-coupled

Conversation

@Noah-Parsons

@Noah-Parsons Noah-Parsons commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds utest_CH_assembly_acceleration_coupled, a unit test that runs DoAssembly(FULL) on mechanisms whose constraints are coupled and compares the resulting body accelerations with closed-form solutions. It complements the single pendulum in utest_CH_assembly_acceleration. The test was suggested by @rserban following #846 / #852, and includes the two changes he asked for: assertions on the Barzilai-Borwein solver, and a check that default PSOR returns the new ACCELERATION_INACCURATE flag in the dead-centre and light-cart cases.

Related Issue(s)

Follows #846 (fixed in #852) and the ACCELERATION_INACCURATE exit flag added to DoAssembly.

Author(s)

Noah Parsons, independent researcher (GitHub: @Noah-Parsons; email: [email protected]).

Licensing

By submitting this pull request, I agree, that my contribution will be included in Chrono and redistributed under the BSD-3-Clause License.

Backward Compatibility

No changes to library code. The pull request adds one test file and registers it in src/tests/unit_tests/core/CMakeLists.txt.

Implementation Notes

Three test cases, 30 configurations in all, each built from point masses, ChLinkDistance rods and ChLinkLockPrismatic slides. The exact accelerations are derived from each system's Lagrangian, as documented in the file header.

  • Pendulum chains (N = 2, 3 and 5, including aligned and folded configurations), where every rod's quadratic-velocity term enters every body's acceleration.
  • A cart-pole with cart-to-pole mass ratios of 10, 1 and 0.01. The light cart makes the mass matrix nearly singular at th = 0.
  • A slider-crank with l/r = 3 and 1.5 and slider-to-crank mass ratios of 1 and 100, probed at both dead centres (th = 0, pi) and at two regular angles.

Each configuration is run with SPARSE_QR, BARZILAIBORWEIN, default PSOR, and PSOR with 500 iterations.

  • SPARSE_QR and BB are asserted to match the closed form within 1e-3 m/s^2, the tolerance of utest_CH_assembly_acceleration, and must not return NOT_CONVERGED or ACCELERATION_INACCURATE. BB matches SPARSE_QR in all 30 configurations.
  • Default PSOR is asserted to return ACCELERATION_INACCURATE in the five near-degenerate configurations: the light cart at th = 0, and the heavy slider at either dead centre for both crank ratios. Its errors there range from 3.2 to 16.2 m/s^2. With equal crank and slider masses, PSOR remains accurate even at dead centre, so those cases carry no PSOR expectation.
  • PSOR with 500 iterations reduces those five errors to 0.04-0.18 m/s^2, and all five are still flagged. Its results are printed, not asserted.

One observation that may be useful: for the heavy slider at l/r = 3, th = 0.3, default PSOR is off by 8.6e-3 m/s^2 but is not flagged. That is consistent with the default SetAssemblyAccelerationTolerance of 1e-2, and is printed rather than asserted.

Verified on current main with a CMake/Ninja Release build (GCC, Ubuntu under WSL2). utest_CH_assembly_acceleration (8 tests) and utest_CH_assembly_acceleration_coupled (3 tests) both pass.

Post Submission Checklist

  • The feature or features in this pull request is complete
  • Licensing information is complete
  • Corresponding author information is complete
  • The feature has been verified to work with the CMake based build system
  • Suitable tests have been updated or added to the unittest tree.

@rserban rserban left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This review was generated by an AI agent (Claude Code) at the request of @rserban.

Thanks, @Noah-Parsons, this is a useful addition. The chains, the cart-pole and the slider-crank cover coupled constraints, prismatic slides and near-singular configurations, which the single-pendulum test does not, and the closed-form references make the results easy to trust.

I rebuilt the test against current main, which now includes the UNSUPPORTED_CONTACTS exit flag from #850. All three tests pass, and the numbers match your description: SPARSE_QR and BB are within 6.5e-4 in all 30 configurations, and default PSOR is flagged in exactly the five near-degenerate cases (errors of 3.2–16.2 m/s²).

Two changes before we merge:

1. The PSOR ACCELERATION_INACCURATE assertion is missing. The last commit ("Assert … PSOR ACCELERATION_INACCURATE …") and the PR description both say default PSOR is asserted to return ACCELERATION_INACCURATE in the five near-degenerate cases. In the code, though, Check() asserts only for SPARSE_QR and BB (k <= 1), and the PSOR results are only printed. As it stands, the test would not notice if the flag stopped firing on these mechanisms, and that is the regression check I'd most like it to provide.

Please pass the expectation in from each case and assert it for default PSOR only. For example:

template <typename Case>
void Check(const Case& c, const std::string& label, bool psor_inaccurate = false) {
    ...
        if (k == 2 && psor_inaccurate)
            EXPECT_EQ(r.flag, AssemblyAnalysis::ExitFlag::ACCELERATION_INACCURATE) << label << " " << names[k];

with psor_inaccurate = true for these cases:

  • cart-pole, M/m = 0.01, th = 0
  • slider-crank, ms/mc = 100, th = 0 and th = pi, for both l/r = 3 and l/r = 1.5

Please don't assert anything for the other PSOR runs or for PSOR x500, as you planned. Some of them are close to the tolerance; for example, the heavy slider at l/r = 3, th = 0.3 has an error of 8.6e-3 against the 1e-2 default.

2. FlagName() needs the new exit flag. main now has AssemblyAnalysis::ExitFlag::UNSUPPORTED_CONTACTS. Please rebase on main and add the matching case to FlagName(), so the switch is complete and doesn't trigger -Wswitch.

Once both are in, this is good to merge from my side.

Noah-Parsons and others added 4 commits October 11, 2026 20:39
Pendulum chains, a cart-pole and a slider-crank through dead centre, each checked against its closed-form constrained acceleration. Complements the single-link pendulum in utest_CH_assembly_acceleration.
…e cases

The previous commit described this assertion but did not add it; the PSOR results were only printed. Check() now takes the expectation from each case and asserts ACCELERATION_INACCURATE for default PSOR in the five near-degenerate configurations (light cart at th = 0; heavy slider at both dead centres for l/r = 3 and 1.5). Nothing is asserted for the other PSOR runs or for PSOR x500.

Also add UNSUPPORTED_CONTACTS to FlagName() so the switch covers every exit flag on main.
@Noah-Parsons
Noah-Parsons force-pushed the test-assembly-acceleration-coupled branch from 226420a to 671ae93 Compare October 11, 2026 20:47
@Noah-Parsons

Copy link
Copy Markdown
Contributor Author

Thanks, Radu. Both changes are now in, on a branch rebased onto current main (3ad85ce):

Check() takes psor_inaccurate from each case and asserts ACCELERATION_INACCURATE for default PSOR only, in the five cases you listed: cart-pole M/m = 0.01 at th = 0, and slider-crank ms/mc = 100 at th = 0 and th = pi for both l/r = 3 and l/r = 1.5. Nothing is asserted for the other PSOR runs or for PSOR x500.

FlagName() now has a case for UNSUPPORTED_CONTACTS.

I wasn’t able to rebuild Chrono locally today, so please let me know if anything fails on your side.

@Noah-Parsons
Noah-Parsons requested a review from rserban October 16, 2026 17:18
@rserban
rserban merged commit fc08808 into projectchrono:main Oct 17, 2026
@Noah-Parsons
Noah-Parsons deleted the test-assembly-acceleration-coupled branch October 18, 2026 15:46
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.

2 participants