Skip to content

adaptive sstp: fix for the case when first step wwas not done in …#486

Open
pdziekan wants to merge 2 commits intoigfuw:masterfrom
pdziekan:adaptive_sstp
Open

adaptive sstp: fix for the case when first step wwas not done in …#486
pdziekan wants to merge 2 commits intoigfuw:masterfrom
pdziekan:adaptive_sstp

Conversation

@pdziekan
Copy link
Copy Markdown
Contributor

@pdziekan pdziekan commented Apr 2, 2026

…adapt and we only make one step

Copilot AI review requested due to automatic review settings April 2, 2026 13:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts the adaptive SSTP (substepping) condensation logic to correctly roll back the non-condensation state when the adaptation phase does not complete an initial condensation step and only a single trial step was applied.

Changes:

  • Update the rollback multiplier used after the adaptation loop to handle the sstp_cond_max == 1 case.
  • Extend the inline comment describing the rollback behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 176 to +190
// override number of substeps for SDs that de/activate in this timestep;
if(sstp_cond_act > 1)
{
const real_t rc2 = thrust::get<2>(thrust::get<2>(tpl));

if ( ( rw2 < rc2 && (rw2 + sstp_cond * drw2) > rc2 ) ||
( rw2 > rc2 && (rw2 + sstp_cond * drw2) < rc2 ) )
{
sstp_cond = sstp_cond_act;
first_cond_step_done_in_adaptation = false;
}
}
if(!first_cond_step_done_in_adaptation)
{
_apply_noncond_perparticle_sstp_delta(delta_fraction_applied); // revert to state before adaptation loop (beacause sstp_cond == sstp_cond_max and sstp_cond_max may not be a power of 2)
_apply_noncond_perparticle_sstp_delta(sstp_cond_max == 1 ? -delta_fraction_applied : delta_fraction_applied); // revert to state before adaptation loop (beacause sstp_cond == sstp_cond_max and sstp_cond_max may not be a power of 2); If only one step was tried, whole change was applied; If more steps were tried, we are moving back from the entire step
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The revert logic here can leave sstp_tmp_* in a partially-advanced state when first_cond_step_done_in_adaptation was set to true in the convergence loop and then later flipped back to false by the activation override (sstp_cond_act block). In that path the code exits the loop with non-cond deltas net-applied for one substep (e.g., +1/sstp_cond), but delta_fraction_applied still reflects the last trial (e.g., -1/sstp_cond_try), so applying it once does not restore the pre-adaptation state and will bias subsequent substepping. Consider tracking the net fraction currently applied to sstp_tmp_* (or saving the pre-loop sstp_tmp_* values and restoring them) and reverting based on that net fraction instead of delta_fraction_applied/sstp_cond_max heuristics.

Copilot uses AI. Check for mistakes.
if(!first_cond_step_done_in_adaptation)
{
_apply_noncond_perparticle_sstp_delta(delta_fraction_applied); // revert to state before adaptation loop (beacause sstp_cond == sstp_cond_max and sstp_cond_max may not be a power of 2)
_apply_noncond_perparticle_sstp_delta(sstp_cond_max == 1 ? -delta_fraction_applied : delta_fraction_applied); // revert to state before adaptation loop (beacause sstp_cond == sstp_cond_max and sstp_cond_max may not be a power of 2); If only one step was tried, whole change was applied; If more steps were tried, we are moving back from the entire step
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

Typo in the inline comment: "beacause" should be "because" (and the comment is quite long; consider splitting into two lines for readability).

Suggested change
_apply_noncond_perparticle_sstp_delta(sstp_cond_max == 1 ? -delta_fraction_applied : delta_fraction_applied); // revert to state before adaptation loop (beacause sstp_cond == sstp_cond_max and sstp_cond_max may not be a power of 2); If only one step was tried, whole change was applied; If more steps were tried, we are moving back from the entire step
_apply_noncond_perparticle_sstp_delta(sstp_cond_max == 1 ? -delta_fraction_applied : delta_fraction_applied); // revert to state before adaptation loop (because sstp_cond == sstp_cond_max
// and sstp_cond_max may not be a power of 2); If only one step was tried, whole change was applied; If more steps were tried, we are moving back from the entire step

Copilot uses AI. Check for mistakes.
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