Skip to content

Restore contact history on restart: fix island label for loaded contacts, add SA/SM existing contacts - #89

Merged
Ruochun merged 2 commits into
projectchrono:mainfrom
Cosmodude:restart-contact-history
Nov 23, 2026
Merged

Ruochun merged 2 commits into
projectchrono:mainfrom
Cosmodude:restart-contact-history

Conversation

@Cosmodude

Copy link
Copy Markdown
Contributor

Fixes #88.

What

  • DEMDynamicThread::populateEntityArrays: set contactPatchIsland = 0 for loaded contacts (the label the simple patch-combination route gives every contact). Before this, loaded contacts kept the default NULL_BODYID island, so kT never matched their history on (A, B, island) and every loaded contact wildcard was silently zeroed. Loading contacts with the non-simple patch-combination route now raises a DEME_ERROR instead of silently losing history.
  • New DEMClumpBatch::SetExistingContactTypes(types) (C++ and Python): "SS", "SA" or "SM" per existing pair, validated with DEME_ERROR. SetExistingContacts clears it, so existing callers keep the all-SS behaviour.
  • For SA/SM, A is offset as a batch sphere and B is kept as the global analytical component / mesh patch ID (as reported by GetContactDetailedInfo), range-checked against the number of analytical components / mesh patches.
  • Loaded contacts are stable-sorted by (type, A, B) and duplicates are rejected, since kT run-length-encodes the previous contacts by type and binary-searches (A, B) within each type.
  • Typed contacts are accepted only from the first clump batch of a fresh solver (otherwise the type segments would be split).
  • Python reference docs updated for SetExistingContactTypes.

Tests

  • New ModularTest DEMTest_RestartContactHistory: settles a small bed on an analytical floor and a mesh plate, saves contacts, builds a new solver, reloads them (typed and untyped) and checks that delta_time keeps growing for SS/SA/SM pairs that stay in contact; it also checks that invalid input (wrong type count, unsupported type) raises errors. It uses the new API, so it does not compile on main; the SS part of the bug (0 % of loaded SS history continued) was measured on 3.0.19, whose load path is the same as main's.
  • Run on an RTX 4090 (3.1.0 + this patch): PASS. Typed reload continued SS 100 % of 756, SA 100 % of 120, SM 100 % of 37 established contacts; untyped reload continued SS 100 % of 756; both invalid-input checks raised the expected errors.
  • Downstream check with a 42k-grain bed on the same setup: history continued for SS 99.982 %, SA 100 %, SM 100 %; kinetic energy over the first 50 ms after reload was 1.07× that of the uninterrupted run. On 3.0.19, an SS-only restart (no surface contacts) gave a post-restart KE spike of 337× on the first sample, versus 1.76× with SS+SA+SM reloaded.
  • Branch rebased on current main (7b051a7); DEMTest_RestartContactHistory builds (CUDA 12.8, sm_89), git clang-format clean.

Compatibility
No behaviour change unless SetExistingContactTypes is called, apart from the island fix (which makes existing SS restarts keep their history as documented) and the new error for loading contacts with non-simple patch combination.

Not covered
Mesh–mesh and mesh–analytical contacts; loading typed contacts into a solver that already has clumps.

…ts, add SA/SM existing contacts

- populateEntityArrays: label loaded contacts with island 0, as kT's simple patch route does, so their
  history is matched on the first contact detection instead of being silently zeroed. Loading contacts
  with the flooded-island patch route now errors out instead of silently losing history.
- DEMClumpBatch::SetExistingContactTypes (C++ and Python): per-pair SS/SA/SM types, so sphere-analytical
  and sphere-mesh histories can be restored. Loaded contacts are sorted by (type, A, B), duplicates and
  out-of-range geometry IDs are rejected.
- New modular test DEMTest_RestartContactHistory.
@Ruochun

Ruochun commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks. We will merge your pull request. Restarting with history has not been working very well, missing various support and as you noted, especially with MM and MA flavors. So we thank you for the effort in improving that, and we may further modernize this utility later.

A few side notes that may be useful for you: 1. We've been putting the history-aware restarting utility at low priority because it seems to us that in typical frictional contact usages, the history at restart plays a minor role, as it will be re-established anyway in a few steps. But this might not be true for you given your use cases. 2. You said you need restarting because of long simulations. But if it is also related to rare, unexpected stalling, the newest version (3.1.0+) should have this problem resolved. Feel free to try. 3. In the upcoming versions (3.2.0+), we plan to improve the rolling resistance and spinning friction implementation, which should slightly change the physics and the format of the detailed contact info class and its output files (forces now differentiate between object A and B, but in typical usages they are the same). It's just a heads-up, since you seem to be using detailed contact info. If you do not use those force model components, then it should be safe to ignore.

Thank you!

@Ruochun
Ruochun merged commit f494133 into projectchrono:main Nov 23, 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.

Restarting from saved contacts silently zeroes contact history (island label), and sphere–analytical / sphere–mesh contacts cannot be reloaded

2 participants