feat(cfd): RMS divergence (L2 continuity residual)#428
Merged
Conversation
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
FlowSolution::rms_divergence()— the root-mean-square divergence over allnx*nycells:// rms = sqrt( <(div u)^2> ) (1/s)Why
The divergence family has
divergence_at_cell,max_divergence, andmean_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 constraintdiv u = 0is satisfied. The square-summing companion to the signed mean and the peakmax_divergence, mirroringrms_vorticity(#406).Test
rms_divergence_is_the_l2_continuity_residual(5x5 unit grid):rms = 0;div u = ceverywhere) ->rms = c, and for the constant fieldrms == mean == max(threads both, non-tautological);div u = [c,c,c,-c,-c]per row) ->rms = cwhile the signed mean cancels toc/5, sorms > |mean|(the RMS catches the local violations the mean misses);0.Pure method on
FlowSolution, nolib.rschange.valenx-cfd-native126 lib tests (was 125);cargo clippy -p valenx-cfd-native --all-targets -- -D warningsclean. Research-grade convergence diagnostic.