Skip to content

[AI-Assisted] fix(thermo): keep Mod2004 Born chemical potentials intensive - #3865

Merged
EvenSol merged 5 commits into
masterfrom
fix/3862-born-intensive
Sep 21, 2026
Merged

EvenSol merged 5 commits into
masterfrom
fix/3862-born-intensive

Conversation

@EvenSol

@EvenSol EvenSol commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

Problem

ComponentModifiedFurstElectrolyteEosMod2004.dFBorndN added the phase-level dielectric derivative FBornD() directly to a mole derivative. Because that term is extensive, identical intensive states produced different chemical potentials, fugacity coefficients and flash results when only the amount basis changed.

Closes #3862.

Changes

  • Remove the unweighted FBornD() term, preserving the 2004 model's existing zero solvent-permittivity derivative convention and its Born mixed derivatives.
  • Add 11 regression cases covering nine model/mixing-rule configurations, amount multipliers from 1e-6 to 1e6, Born energy extensivity, intensive Born derivatives and full log fugacity coefficients, the Born Euler identity, a single-solvent energy finite difference, and the reported two-phase methane/water/NaCl flash.
  • Document the full dielectric chain rule, the distinction between scaling and complete thermodynamic consistency, and the literature-based development recommendations.
  • Correct the Born equation in the electrolyte CPA guide to match the implementation's molar and diameter conventions.

Dividing FBornD() by total moles is not a valid substitute for the missing chain-rule factor.

Other EOS audit

Base Furst, electrolyte CPA, Statoil, Advanced and MM already include the dielectric chain-rule factor. Their scaling regressions pass; MM is checked with MOLAR_AVERAGE, VOLUME_AVERAGE, LOOYENGA and LICHTENECKER. CPA Old inherits the base derivative (source inspection). Ordinary SRK/PR/CPA/non-electrolyte SAFT and Pitzer do not use the faulty Mod2004 implementation. This is a focused audit of this failure mode, not certification of every derivative in those models.

Literature and remaining scope

The documentation discusses Maribo-Mogensen et al. (2015, doi:10.1002/aic.14829), Simonin (2019, doi:10.1063/1.5096598), Novak et al. (2023, doi:10.1021/acs.iecr.3c00717), and Novak et al. (2025, doi:10.1016/j.fluid.2025.114339). Source claims were verified from publisher/institutional abstracts; the chain rule is independently derived from NeqSim's implemented energy.

The legacy 2004 model still recomputes permittivity with temperature/composition while suppressing those derivatives. This PR fixes phase-size dependence. Full mixed-solvent/caloric consistency requires coordinated Born and long-range derivative work and property validation; it is explicitly not claimed here. No fitted parameters or public signatures change.

Validation

Base: a7f0e929559b27e70c841b763a77b6bf04c964ff; NeqSim 3.21.0 source; OpenJDK 17.0.20.
Before the correction, the new amount-scaling and TP-flash assertions reproduce the failure. On the final implementation: 69 tests passed, zero failures/errors/skips, including all 11 new regressions.

Maven was bootstrapped with the work-with-neqsim prepare_maven.py helper.

Command Result
./mvnw -B -ntp -DskipTests -Dmaven.javadoc.skip=true -Djacoco.skip=true compile Exit 0
./mvnw -B -ntp -Dtest=ElectrolyteBornExtensivityTest -Djacoco.skip=true test Exit 0; 11 passed
./mvnw -B -ntp -Dtest='ElectrolyteBornExtensivityTest,SystemFurstElectrolyteEosTest,SystemElectrolyteCPATest,SystemElectrolyteCPAMMTest,SystemElectrolyteCPAAdvancedTest,PhaseModifiedFurstElectrolyteEosTest,PhaseModifiedFurstElectrolyteEosMod2004Test,PhaseElectrolyteCPATest,PhaseElectrolyteCPAstatoilTest,PhaseElectrolyteCPAOldTest' -Djacoco.skip=true test Exit 0; 69 passed
python3 devtools/run_spotless.py apply (including clean repeat) Exit 0
python3 devtools/run_spotless.py check Exit 0
python3 devtools/check_documentation_search.py Exit 0; 717 Markdown pages, one standalone HTML page
pre-commit run --all-files --hook-stage pre-commit Exit 0
pre-commit run --all-files --hook-stage pre-push Exit 0
./mvnw -B -ntp -DskipTests -DjavadocExecutable=<local-javadoc-launcher> javadoc:javadoc Exit 0; existing documentation warnings
git diff --check Exit 0

The runtime includes the JDK javadoc module but no launcher, so the local launcher invokes that module and forwards JVM options. The first attempt without it was blocked by the missing executable. A task-local pre-commit installation was used because an existing launcher had missing dependencies. No environment workaround was added to the repository.

VALIDATION PENDING CI: GitHub's full Java/platform matrix was not run locally.

Documentation impact

Updated docs/thermo/ElectrolyteCPAModel.md, added docs/thermo/ElectrolyteBornDerivatives.md, and documented the derivative convention in Javadoc. The new guide is linked from the existing electrolyte CPA documentation.

Requested CI repair — latest validation

Remove the duplicate Born-guide heading caught by documentation tests. Preserve and freshly evaluate the lower endpoint in binary feasibility search so it remains available when interior candidates fail replay. Apply the compatible repair from #3801 and add a synthetic regression for the non-repeatable boundary. The regression was reproduced failing before the repair. Feasibility and utilization tolerances remain strict.

Current repair head: 47bd8d3125a14a4233d9814c8b68ab216d8861da, parent 10adc61695abd5b42f7db4739a5d250b8d59b933. Earlier head and repair-budget notes above describe previous checkpoints; the user explicitly requested repair of all failing PRs.

Local OpenJDK 17 validation: 6 focused tests passed, zero failures/errors/skips using ./mvnw -q -Dtest=ProductionOptimizerSelectedPointTest,BottleneckAnalysisOptimizerTest#testTwoStageOptimizationRecommendedApproach -DexcludedTestGroups= -Djacoco.skip=true test (exit 0).

After Maven bootstrap with the NeqSim skill helper, the final tree passed all of the following (exit 0):

  • python3 devtools/run_spotless.py apply twice, with an unchanged repeated diff;
  • python3 -m pre_commit run --all-files --hook-stage pre-commit;
  • python3 devtools/run_spotless.py check;
  • python3 devtools/check_documentation_search.py;
  • python3 -m pre_commit run --all-files --hook-stage pre-push;
  • git diff --check and git diff --cached --check;
  • python3 -m unittest discover -s docs -p 'test_*.py' (386 passed).

The selected primary Python runtime used task-local pre-commit dependencies. Documentation impact: document verified endpoint recovery before Debottlenecking Studies while preserving master's non-monotonic-envelope guidance. A three-way document merge against the actual shared base and exact master document exits 0. The previous documentation follow-up had a trailing blank line at EOF: its claim that every final gate passed was incorrect because the whitespace check exited 2. This commit removes that blank line; the complete gate sequence was rerun successfully before publication.

VALIDATION PENDING CI for the new head's hosted Java/platform checks. No merge or readiness change.

Remove the unweighted dielectric derivative from dFBorndN, add electrolyte-family scaling and flash regressions, and document the chain rule, literature and remaining legacy limitations.

Closes #3862
@EvenSol
EvenSol merged commit fa2b79f into master Sep 21, 2026
30 checks passed
@EvenSol
EvenSol deleted the fix/3862-born-intensive branch September 21, 2026 03:50
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.

PhaseModifiedFurstElectrolyteEosMod2004.dFBorndN adds an extensive term, so ln phi depends on the phase size

1 participant