Skip to content

Compare NEMO freestream mass fractions against a roundoff tolerance - #2880

Open
bellonarts wants to merge 3 commits into
su2code:developfrom
babybluechips:fix_massfrac_tolerance
Open

Compare NEMO freestream mass fractions against a roundoff tolerance#2880
bellonarts wants to merge 3 commits into
su2code:developfrom
babybluechips:fix_massfrac_tolerance

Conversation

@bellonarts

@bellonarts bellonarts commented Sep 5, 2026

Copy link
Copy Markdown

Proposed Changes

CSU2TCLib validates the user-supplied freestream composition with if (mf != 1.0), an exact floating-point equality on an accumulated sum, at four gas-model sites (ARGON, N2, AIR-5, AIR-7). A physically exact composition need not sum to bit-exact unity in double precision. For example

GAS_COMPOSITION= ( 0.999, 0.00025, 0.00025, 0.00025, 0.00025 )

sums to 1 - 1.1e-16 and is rejected with "Intial gas mass fractions do not sum to 1!", which reads to the user as a typo in a composition that visibly sums to one. Any case seeding trace species can hit this.

This PR compares against a 1e-10 roundoff tolerance and reports the offending sum in the message. The tolerance sits about six orders above the roundoff in the example (1.1e-16) and four orders below the 1.e-6 already used for the same "is this roundoff?" question in Common/src/fem/fem_geometry_structure.cpp, so genuine input errors are still rejected. The constant is constexpr passivedouble per the convention in option_structure.hpp, and the message uses SU2_TYPE::GetValue so the change is safe under AD builds. The sum is printed with 16 significant digits through a small static helper shared by the four sites, because to_string would print 1.000000 for any sum that fails the tolerance by less than 5e-7; a composition off by 3e-7 now reports sum = 0.9999997 and a real typo reports sum = 0.99. The pre-existing "Intial" typo is corrected in the same lines.

Verification with actual solver launches on the public viscous-cone mesh (ITER= 0, exit code as the verdict): the roundoff-unity AIR-5 and AIR-7 compositions are now accepted; exact compositions for ARGON, N2, AIR-5 and AIR-7 remain accepted; real typos such as ( 0.75, 0.24, 0, 0, 0 ) remain rejected for every gas model. The regression baselines are unchanged, serial and MPI, so no regression vectors are modified.

The contributor entry is added to AUTHORS.md. A dedicated constructor unit test was removed in response to maintainer review; the acceptance/rejection matrix above exercises the behavior through actual solver launches.

Related Work

The confusing failure mode may account for some reports of NEMO setup difficulty; it surfaces whenever trace species are seeded rather than left at exact zero. No open issue or PR is known to cover it.

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These a guide for you to know what the reviewers will be looking for in your contribution.

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • A dedicated unit test is not included at maintainer request; actual solver launches cover accepted roundoff and rejected invalid compositions.
  • Documentation is not applicable; this corrects input validation and its diagnostic without changing a configuration keyword or public API.

CSU2TCLib rejected the freestream composition with an exact
floating-point equality on an accumulated sum at four gas-model sites,
so a physically exact input such as ( 0.999, 0.00025, 0.00025, 0.00025,
0.00025 ), which sums to 1 - 1.1e-16 in double precision, was refused
as a typo. Compare against a 1e-10 roundoff tolerance instead, report
the offending sum with 16 significant digits (to_string would print
1.000000 for a sum that fails the tolerance by less than 5e-7), and fix
the "Intial" typo. Add a Catch2 unit test that constructs the model for
the AIR-5 roundoff composition and for N2 ( 0.999, 0.001 ); on stock
develop the driver aborts in the AIR-5 constructor. No flow numbers
change.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Comment thread UnitTests/SU2_CFD/fluid/CNEMOGas_composition_tests.cpp Outdated
Remove the broad CNEMOGas constructor test at maintainer request and add Jared Bellon to AUTHORS.md. The solver-launch acceptance/rejection matrix remains the behavioral coverage.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

2 participants