Skip to content

Diffusion::diffuse_scalar: with rho_flag==1 and delta_rhs, the old-time diffusion term is also multiplied by rho_half #240

Closed

Description

@WeiqunZhang

Location: Source/Diffusion.cpp:478, Source/Diffusion.cpp:481
Severity: Low — latent: no current caller passes both delta_rhs and add_old_time_divFlux=true
Category: Physics-numerics
Based on commit bb697bf5 (line numbers refer to that tree).

Problem

For rho_flag==1 (RhoInverse_Laplacian_S) the implicit system is
rho_half*S^{n+1} - theta*dt*L(S^{n+1}) = rho_half*S* + (1-theta)*dt*L(S^n) + rho_half*dt*delta_rhs.
When add_old_time_divFlux is set, Rhs already holds (1-theta)*dt*L(S^n) from mgn.apply
(:443). The source loop then does this:

// Source/Diffusion.cpp:477-483
            // Add body sources
            if ( has_delta_rhs ) {
                rhs(i,j,k,n) += deltarhs(i,j,k,n) * dt;
                if ( rho_flag == 1 ) {
                    rhs(i,j,k,n) *= rhoHalf(i,j,k);
                }
            }

This multiplies the old-time diffusion term by rho_half as well. Without delta_rhs the same term
is left unscaled, so the result depends on whether a source is present. Only the source should be scaled.

Impact

Today nothing reaches it. scalar_diffusion_update passes delta_rhs = nullptr
(NavierStokes.cpp:901). mac_sync passes delta_rhs = &Ssync with add_old_time_divFlux = false
(NavierStokes.cpp:1586,1622), so Rhs starts at zero and the multiplication is harmless there. A
caller that adds an explicit source to a non-conservative diffusing scalar with Crank-Nicolson
(be_cn_theta != 1) would get its old-time diffusion scaled by rho_half, which is wrong whenever
the density is not 1.

Suggested fix

Scale only the source term.

--- a/Source/Diffusion.cpp
+++ b/Source/Diffusion.cpp
@@ -477,10 +477,10 @@ Diffusion::diffuse_scalar (const Vector<MultiFab*>&  S_old,
         {
             // Add body sources
             if ( has_delta_rhs ) {
-                rhs(i,j,k,n) += deltarhs(i,j,k,n) * dt;
-                if ( rho_flag == 1 ) {
-                    rhs(i,j,k,n) *= rhoHalf(i,j,k);
-                }
+                // Scale only the source by rho_half, not the old-time diffusion term.
+                Real src = deltarhs(i,j,k,n) * dt;
+                if ( rho_flag == 1 ) { src *= rhoHalf(i,j,k); }
+                rhs(i,j,k,n) += src;
             }
             // Always do : copy S_new into Soln
             //             add Soln to Rhs

Activity

  1. added a commit that references this issue on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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