add initial constitutive relations api - #17
Conversation
| constexpr IonicStrength::Params testParams | ||
| { | ||
| // Species charge | ||
| { 1.0, -1.0, 2.0 } |
There was a problem hiding this comment.
The sum of charges needs to be 0. Suggesting to change 1.0 to -1.0
|
Bdot tests are expected to fail now. Need to update the expected solution. |
There was a problem hiding this comment.
I've heavily modified and refactored this file to account for the activity model during mass action solve. The root cause is secondary concentrations and activity coefficients are coupled (i.e., ionic strength depends on the secondary concentrations). So we should solve them together, and therefore, concentrations, activity coefficients and activities are mutually consistent.
The specific changes include:
-
Refactored
calculateLogSecondarySpeciesConcentrationandcalculateLogSecondarySpeciesConcentrationWrtLogC: an inner Newton solve onlog(C_sec)returning concentrations, activity coefficients, activities, a convergence flag, and the exactd log(C_sec)/d log(C_prim). -
Renamed the old fixed-activity-coefficient versions to
...NoActivityUpdateand...WrtLogCNoActivityUpdate. -
Removed the two
calculateAggregatePrimaryConcentrationsWrtLogCoverloads and thecalculateTotalAndMobileAggregatePrimaryConcentrationsWrtLogC, which reconstructed secondary concentrations internally undergamma == 1. The two remaining aggregate functions are a pure mole balance,T_i = C_prim,i + sum_j nu_ji C_sec,j, taking the solved secondary arrays as input.
There was a problem hiding this comment.
New tests added:
Self-consistent solve, checking mass action holds and a = C * gamma for all species:
test_calculateLogSecondarySpeciesConcentration_allEquilibrium_identitytest_calculateLogSecondarySpeciesConcentration_allEquilibrium_bdottest_calculateLogSecondarySpeciesConcentration_mixedSystem_identitytest_calculateLogSecondarySpeciesConcentration_mixedSystem_bdottest_calculateLogSecondarySpeciesConcentration_identityActivityModel— reproduces the reference
concentrations and confirms unit activity coefficients.
Derivative d log(C_sec)/d log(C_prim) against a central difference of the solve itself:
test_calculateLogSecondarySpeciesConcentrationWrtLogC_allEquilibrium_identitytest_calculateLogSecondarySpeciesConcentrationWrtLogC_allEquilibrium_bdottest_calculateLogSecondarySpeciesConcentrationWrtLogC_mixedSystem_bdot
This PR adds constitutive relations for activity and ionic strength.