Skip to content

Save the most recently computed velocity instead of zeros - #444

Open
drbergman wants to merge 1 commit into
MathCancer:developmentfrom
drbergman:fix-saved-velocity
Open

drbergman wants to merge 1 commit into
MathCancer:developmentfrom
drbergman:fix-saved-velocity

Conversation

@drbergman

Copy link
Copy Markdown
Collaborator

The velocity field in every output*_cells.mat has always been (0,0,0). Cell::update_position() zeroes velocity at the end of each mechanics step so it can accumulate forces for the next one, and output is written between mechanics steps, so the writer only ever saw the zeroed vector. This PR writes previous_velocity instead, which is the velocity used in the most recent position update. Simulation dynamics are unchanged; only the saved values differ.

recreate_sim_state() (used by resume_from_MultiCellDS()) read the saved value back into velocity. That was harmless while the value was always zero, but with real values it would add the saved velocity on top of the freshly computed forces in the first step after resuming, so cells would overshoot by about 3x on that step. The reader now restores the value into previous_velocity, which also gives the Adams-Bashforth update its history. Before this change, a resumed run's first step overshot by 1.5x because that history was missing.

🤖 Generated with Claude Code

Cell::update_position() zeroes velocity after every position update so it
can accumulate forces for the next mechanics step. Output is written between
mechanics steps, so the saved velocity was always (0,0,0). Write
previous_velocity, which holds the velocity used in the last step.

recreate_sim_state() now restores the saved value into previous_velocity
rather than velocity. Loading it into velocity would add it on top of the
freshly computed forces in the first step after resuming.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the velocity snapshot and restart-handling changes.

No open issues 🎉

What changed in this PR

Corrects PhysiCell velocity output and restart handling without changing simulation dynamics.

Changes:

  • Saves the most recently computed velocity instead of the cleared force accumulator.
  • Restores saved velocity into the integration history, avoiding extra velocity on the first resumed step.
File Description
modules/​PhysiCell_MultiCellDS.cpp Writes and restores previous_velocity in cell snapshots.

Review effort: Balanced

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