Passive Scalar Conservation#
Passive (mass) scalars in Quokka are stored as partial densities (e.g., rho * X_i where X_i is a species mass fraction), not as fractions. This means any operation that modifies the gas density — density floors, sink particle creation, accretion — must apply the same scaling factor to every passive scalar to keep mass fractions consistent. Failing to do so silently corrupts species composition without triggering any conservation error.
Representation and Indexing#
Passive scalars occupy contiguous slots beginning at scalar0_index in the conserved-variable array. The number of mass scalars (nmscalars_) and total passive scalars (nscalars_) are set by Physics_Traits<problem_t> . Mass scalars are a subset of passive scalars and interact with the EOS; generic passive scalars do not.
EnforceLimits — Density Floor#
HydroSystem::EnforceLimits applies a density floor after each RK stage. When rho < localDensityFloor, the density is raised and all passive scalars are rescaled to preserve mass fractions :
scalar[n] *= rho_old / rho_new
If the new density is exactly zero, scalars are zeroed. After this rescaling, mass scalars are additionally floored at small_x * rho_new and renormalized so their sum equals rho_new .
Sink Particle Creation#
When a sink-like particle is created in SinkCreationHelpers::initializeSinkLikeParticles, the cell gas density is reduced from cell_density to the Jeans density rho_J, and momentum, total energy, and internal energy are all multiplied by scale_factor = rho_J / cell_density. PR #1977 fixed a bug where passive scalars were not being scaled, artificially inflating their mass fractions. The fix adds:
if constexpr (Physics_Traits<problem_t>::numPassiveScalars > 0) {
for (int n = 0; n < Physics_Traits<problem_t>::numPassiveScalars; ++n) {
state_arr(i, j, k, HydroSystem<problem_t>::scalar0_index + n) *= scale_factor;
}
}
This only affects simulations with both numPassiveScalars > 0 and sink particles enabled.
Accretion onto Particles#
During accretion in UpdateHydroState (particle_accretion.hpp), mass is removed from the cell by an accretion_down_factor. Passive scalars are scaled by the same factor :
for (int n = 0; n < Physics_Traits<problem_t>::numPassiveScalars; ++n) {
state_arr[bx](i, j, k, HydroSystem<problem_t>::scalar0_index + n) *= accretion_down_factor;
}
Stochastic Star Particle Creation#
In StochasticStellarPop, when a star particle is created, the remaining cell gas is rescaled by factor = (1 - particle_mass / cell_mass). Passive scalars receive the same factor :
if (nscalars > 0) {
for (int nn = 0; nn < nscalars; ++nn) {
state_arr(i, j, k, HydroSystem<problem_t>::scalar0_index + nn) *= factor;
}
}
Flux-Level Conservation#
At the Riemann solver level, mass scalar fluxes are further corrected to ensure species sum to the density flux. In ComputeFluxes, after computing the raw Riemann flux, mass scalar fluxes are rescaled so that sum(F[scalar_n]) == F[density], following the approach of Plewa & Müller (1999).
Key Source Files#
| File | Relevance |
|---|---|
src/hydro/hydro_system.hpp | EnforceLimits floor scaling; flux-level mass scalar correction |
src/particles/particle_creation.hpp | Sink particle and stochastic star creation scaling |
src/particles/particle_accretion.hpp | Accretion scaling in UpdateHydroState |