Skip to content

ComputeAofs: non-EB flux-register path ignores do_crse_add/do_fine_add, so the mac_sync adds coarse fluxes the EB twin skips #226

Closed

Description

@WeiqunZhang

Location: Source/NavierStokesBase.cpp:5267, Source/NavierStokesBase.cpp:5273
Severity: Low — currently masked by advance_setup resetting the register before its next use; a twin divergence and an unhonoured parameter
Category: AMR-sync
Based on commit bb697bf5 (line numbers refer to that tree).

Problem

The EB branch of the second MFIter loop only updates the fine level's register when the caller
allows it, which is how MacProj::mac_sync_compute (do_crse_add=false) keeps the sync from
touching the level/level+1 register:

// Source/NavierStokesBase.cpp:5227, 5243 (EB twin)
            if ( do_reflux && do_crse_add && (level < parent->finestLevel()) ) {
...
            if ( do_reflux && do_fine_add && (level > 0)) {

The non-EB branch tests neither flag; do_fine_add is explicitly ignore_unused (line 4724) and
do_crse_add only flips the sign:

// Source/NavierStokesBase.cpp:5264-5277
        Real sync_factor = do_crse_add ? 1.0 : -1.0;
        if ( do_reflux && (level < parent->finestLevel()) ) {
               getAdvFluxReg(level+1).CrseAdd(mfi, ..., dxDp, sync_factor*dt, ...);
        }
        if ( do_reflux && (level > 0) ) {
              advflux_reg->FineAdd(mfi, ..., dxDp, sync_factor*dt, ...);
        }

So during the mac_sync at a level below the finest, the non-EB build adds -dt times the sync
fluxes into getAdvFluxReg(level+1), and a caller passing update_fluxreg=false to
mac_sync_compute would still get a FineAdd.

Impact

Today this is harmless only because NavierStokesBase::post_timestep calls reflux() before
mac_sync() and advance_setup calls getAdvFluxReg(level+1).reset() at the start of the next
step, so the spurious coarse contribution is discarded before it is refluxed. It is wasted work on
every sync step of every multilevel non-EB run (Exec/run2d/regtest.2d.* with amr.max_level>0),
and any reordering of reflux/mac_sync, or a future caller with update_fluxreg=false, turns it
into a wrong sync. The EB and non-EB twins should agree.

Suggested fix

Honour the two flags in the non-EB branch exactly as the EB branch does.

--- a/Source/NavierStokesBase.cpp
+++ b/Source/NavierStokesBase.cpp
@@ -5264,13 +5264,13 @@
         Real sync_factor = do_crse_add ? 1.0 : -1.0;
 
         // Update the flux registers when no EB
-        if ( do_reflux && (level < parent->finestLevel()) ) {
+        if ( do_reflux && do_crse_add && (level < parent->finestLevel()) ) {
                getAdvFluxReg(level+1).CrseAdd(mfi,
                               {AMREX_D_DECL(&fx_fab,&fy_fab,&fz_fab)},
                               dxDp, sync_factor*dt, flux_comp, state_indx, ncomp, amrex::RunOn::Device);
         } // do_reflux && level < finest_level
 
-        if ( do_reflux && (level > 0) ) {
+        if ( do_reflux && do_fine_add && (level > 0) ) {
               advflux_reg->FineAdd(mfi,
                               {AMREX_D_DECL(&fx_fab,&fy_fab,&fz_fab)},
                                dxDp, sync_factor*dt, flux_comp, state_indx, ncomp, amrex::RunOn::Device);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions