mutationpp / Mutationpp

The MUlticomponent Thermodynamic And Transport library for IONized gases in C++
GNU Lesser General Public License v3.0
106 stars 58 forks source link

Clip species compositions to improve robustness #13

Open jbscoggi opened 5 years ago

jbscoggi commented 5 years ago

General description

Species compositions such as mole/mass fractions, densities, or number densities are required throughout M++ in order to compute many different properties of a mixture. There is a growing consensus that the compositions should be clipped in order to improve the robustness of some algorithms. This should be done at a low level to ensure consistency throughout.

Detailed description

I propose to clip the species mole fractions to a lower bound, which can be changed as input from the user in the mixture file. Whenever a species composition is either given by the user, or computed from an equilibrium calculation, the species mole fractions would be clipped, and any other form of the composition should be set consistent with those mole fractions. For example, if the following mole fractions are given:

Species Mole Fraction
N 0.0
O 0.0
NO 0.0
N2 0.8
O2 0.2

then the mole fractions saved internally would be set to

Species Mole Fraction
N tol
O tol
NO tol
N2 0.8
O2 0.2

where tol is the tolerance set by the user (default of 1.0e-16). The corresponding mass fractions or species densities would then be evaluated according to the updated mole fractions to ensure consistency throughout.

Modifications to current behavior

Examples to use for testing

jbscoggi commented 5 years ago

After some offline discussion, we don't feel this is a must-have for v1.0.0, so I'm removing the milestone.

mgoodson-cvd commented 2 years ago

Just as a warning to others, I've encountered two places where a mass fraction of zero will produce a division by zero:

My solution is to clip the mass fractions before passing to Mutation++, which seems preferable to clipping inside Mutation++. I would be very confused as a user if I passed in mass fractions of zero and got back non-zero mole fractions, for example.