Skip to content

feat(cfd): RMS divergence (L2 continuity residual)#428

Merged
nochallenge merged 1 commit into
masterfrom
feat/cfd-rms-divergence
Jun 8, 2026
Merged

feat(cfd): RMS divergence (L2 continuity residual)#428
nochallenge merged 1 commit into
masterfrom
feat/cfd-rms-divergence

Conversation

@nochallenge

Copy link
Copy Markdown
Owner

What

Adds FlowSolution::rms_divergence() — the root-mean-square divergence over all nx*ny cells:

// rms = sqrt( <(div u)^2> )   (1/s)

Why

The divergence family has divergence_at_cell, max_divergence, and mean_divergence (#417), but no RMS. The L2 continuity residual is the standard convergence metric — unlike the signed mean (whose +/- cells cancel), the RMS sums squares so it never cancels and reflects how well the discrete continuity constraint div u = 0 is satisfied. The square-summing companion to the signed mean and the peak max_divergence, mirroring rms_vorticity (#406).

Test

rms_divergence_is_the_l2_continuity_residual (5x5 unit grid):

  • (a) solenoidal shear -> rms = 0;
  • (b) uniform expansion (div u = c everywhere) -> rms = c, and for the constant field rms == mean == max (threads both, non-tautological);
  • (c) sign-varying "tent" (div u = [c,c,c,-c,-c] per row) -> rms = c while the signed mean cancels to c/5, so rms > |mean| (the RMS catches the local violations the mean misses);
  • (d) zero-flow -> 0.

Pure method on FlowSolution, no lib.rs change. valenx-cfd-native 126 lib tests (was 125); cargo clippy -p valenx-cfd-native --all-targets -- -D warnings clean. Research-grade convergence diagnostic.

Add FlowSolution::rms_divergence(), the root-mean-square divergence over
all nx*ny cells:

  rms = sqrt( <(div u)^2> )   (1/s)

the L2 continuity residual. Unlike the signed mean_divergence (whose +/-
cells cancel), the RMS sums squares so it never cancels -- the standard
convergence metric for how well the discrete continuity constraint
div u = 0 is satisfied. The square-summing companion to the signed mean
(#417) and the peak max_divergence, mirroring rms_vorticity (#406).

Analytic test rms_divergence_is_the_l2_continuity_residual:
(a) solenoidal shear -> rms = 0;
(b) uniform expansion (div u = c everywhere) -> rms = c, and for the
    constant field rms == mean == max (threads both, non-tautological);
(c) sign-varying "tent" (div u = [c,c,c,-c,-c] per row) -> rms = c while
    the signed mean cancels to c/5, so rms > |mean| (the RMS catches the
    local violations the mean misses);
(d) zero-flow -> 0.

Pure method on FlowSolution, no lib.rs change. cfd-native 126 lib tests
(was 125), cargo clippy --all-targets -D warnings clean.
@nochallenge nochallenge merged commit cdf8ac3 into master Jun 8, 2026
@nochallenge nochallenge deleted the feat/cfd-rms-divergence branch June 8, 2026 22:25
nochallenge added a commit that referenced this pull request Jun 8, 2026
Add FlowSolution::mean_dissipation_rate(kinematic_viscosity), the rate at
which the flow irreversibly converts kinetic energy to heat by viscosity:

  eps = nu * <|S|^2> = nu * (rms_strain_rate)^2   (m^2/s^3, per unit mass)

the quantity that closes the turbulent energy budget (the Kolmogorov
cascade rate). Since |S|^2 = 2 S_ij S_ij, eps = 2*nu*<S_ij S_ij>. It is
the strain-squared companion to rms_strain_rate (#428), threading it
directly. A pure rotation strains nothing and dissipates nothing; only
deformation dissipates.

Analytic test mean_dissipation_rate_is_viscosity_times_strain_squared:
(a) worked: pure shear u(y)=gamma*y, |S|=gamma, nu=0.1 -> eps=nu*gamma^2=0.4;
(b) threads rms_vorticity (#406) (non-tautological): for a pure shear
    |S|=|omega|, so eps = nu*rms_vorticity^2;
(c) solid-body rotation -> no strain -> no dissipation (even though it spins);
(d) proportional to nu, and zero at nu=0.

Pure method on FlowSolution, no lib.rs change. cfd-native 129 lib tests
(was 128), cargo clippy --all-targets -D warnings clean.
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.

1 participant