Skip to content

fix species flux summing so final Dnp1 isnt double counted#609

Merged
baperry2 merged 2 commits intoAMReX-Combustion:developmentfrom
baperry2:species-flux-fix
Jan 2, 2026
Merged

fix species flux summing so final Dnp1 isnt double counted#609
baperry2 merged 2 commits intoAMReX-Combustion:developmentfrom
baperry2:species-flux-fix

Conversation

@baperry2
Copy link
Copy Markdown
Collaborator

In PeleLM::computeDifferentialDiffusionTerms we do a check on whether we are at the 0th or final SDC iteration to determine whether the species fluxes computed should be added for flux tracking purposes ($D^n$ and $D^{n+1,k}$) in the species diffusion update below).

Screenshot 2025-12-30 at 4 59 57 PM

However, PeleLM::computeDifferentialDiffusionTerms also gets called after the SDC iteration loop while computing the final divu for the velocity update. Currently, this trips the check on being at the final SDC iteration, and the flux is spuriously added into the flux trackers for a second time. This PR fixes the issue by changing the SDC iteration loop to directly update m_sdcIter, so once the SDC iteration loop completes this value exceeds m_nSDCmax and the check does not trip.

Hat tip to @wengzf20 for catching this in #608. @wengzf20 please confirm this change addresses the issue you are seeing.

Copy link
Copy Markdown
Contributor

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 fixes a bug where species fluxes were being double-counted during the final SDC (Spectral Deferred Correction) iteration. The issue occurred because computeDifferentialDiffusionTerms was being called both during the final SDC iteration and again after the SDC loop completed, with the member variable m_sdcIter still equal to m_nSDCmax, causing the flux tracking condition to trigger twice.

Key Changes:

  • Modified the SDC iteration loop to use the member variable m_sdcIter directly as the loop counter instead of a local variable
  • Removed the assignment m_sdcIter = sdcIter from within the oneSDC() function
  • This ensures that after the loop completes, m_sdcIter equals m_nSDCmax + 1, preventing the spurious flux addition in the post-SDC calcDivU() call

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

Copy link
Copy Markdown

@drummerdoc drummerdoc left a comment

Choose a reason for hiding this comment

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

This seems to avoid the observed issue, but I'm concerned about the level of "corporate knowledge" needed to understand what's happening here. Would it be easier to understand if there was a variable a_sdc_diffTerm_weight that was passed in by caller so that the intention is stated clearly?

@wengzf20
Copy link
Copy Markdown

Using m_sdcIter and disabling m_sdcIter = sdcIter do avoid revising rhoYFluxes during the calcDivU() call. The results look much more satisfactory in my case. Thank you @baperry2

@baperry2
Copy link
Copy Markdown
Collaborator Author

baperry2 commented Jan 1, 2026

@drummerdoc I implemented your suggestion.

@drummerdoc
Copy link
Copy Markdown

Nice. Thanks!

@baperry2
Copy link
Copy Markdown
Collaborator Author

baperry2 commented Jan 2, 2026

@d-montgomery and @SreejithNREL: this may slightly impact the mass flow rate calculations for the SATF cases.

@baperry2 baperry2 merged commit 66b151b into AMReX-Combustion:development Jan 2, 2026
24 checks passed
@baperry2 baperry2 deleted the species-flux-fix branch January 2, 2026 18:31
@d-montgomery
Copy link
Copy Markdown
Contributor

d-montgomery commented Jan 5, 2026

@d-montgomery and @SreejithNREL: this may slightly impact the mass flow rate calculations for the SATF cases.

Thanks for the heads up @baperry2 !

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.

5 participants