Repository navigation
[UPDATE] Unit test for DoAssembly accelerations on coupled mechanisms - #856
Conversation
rserban
left a comment
There was a problem hiding this comment.
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.
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.
…the coupled assembly test
…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.
226420a to
671ae93
Compare
|
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. |
Summary
Adds
utest_CH_assembly_acceleration_coupled, a unit test that runsDoAssembly(FULL)on mechanisms whose constraints are coupled and compares the resulting body accelerations with closed-form solutions. It complements the single pendulum inutest_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 newACCELERATION_INACCURATEflag in the dead-centre and light-cart cases.Related Issue(s)
Follows #846 (fixed in #852) and the
ACCELERATION_INACCURATEexit flag added toDoAssembly.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,
ChLinkDistancerods andChLinkLockPrismaticslides. The exact accelerations are derived from each system's Lagrangian, as documented in the file header.Each configuration is run with SPARSE_QR, BARZILAIBORWEIN, default PSOR, and PSOR with 500 iterations.
utest_CH_assembly_acceleration, and must not returnNOT_CONVERGEDorACCELERATION_INACCURATE. BB matches SPARSE_QR in all 30 configurations.ACCELERATION_INACCURATEin 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.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
SetAssemblyAccelerationToleranceof 1e-2, and is printed rather than asserted.Verified on current
mainwith a CMake/Ninja Release build (GCC, Ubuntu under WSL2).utest_CH_assembly_acceleration(8 tests) andutest_CH_assembly_acceleration_coupled(3 tests) both pass.Post Submission Checklist