Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
618 stars 348 forks source link

IdealGasPhase getStandardChemPotentials #841

Open decaluwe opened 4 years ago

decaluwe commented 4 years ago

System information

Expected behavior The standard state definition for an ideal gas, typically, is pressure-independent. All pressure dependence in thermodynamic definitions is generally handled in the activity term, where the activity of a species k is equal to pressure*molefraction[k]/standardPressure.

More directly, this should always result in reverse reaction rate coefficients, calculated via k_rev = k_fwdexp(-deltaG^o/RT)prod(standardConcentrations^nu_k` being pressure independent (so long as f_fwd is pressure-independent).

Actual behavior (EDITED FROM ORIGINAL POST)

Additional context See discussions below.

decaluwe commented 4 years ago

A few additional thoughts:

bryanwweber commented 4 years ago

I don't have enough knowledge to say if what you've got here is thermodynamically correct. We should get @cfgoldsmith and @rwest to weigh in, and maybe the SAB as well if you want.

That said, it would be interesting to see if you made these changes whether there would be any changes in the IdealGasPhase calculations. We expect not, but you never know... So I'd be interested in seeing an implementation 😁

decaluwe commented 4 years ago

There wouldn’t be any changes AFAIK— the bulk properties are all correct, it’s just how those are split between the “standard” and “non-standard” portions that causes problems for a heterogeneous reaction. Curious to see if it is a problem Generally, or if there is something specific about electrochemistry. For the Kc calculations, the changes to delta G^0 and logStandardConc would offset each other.

Okay, this has clarified that I’m pretty sure I’m right 😁, and I’ll at least work up an implementation to test it out.

Sent from my iPhone

On Apr 4, 2020, at 7:58 AM, Bryan W. Weber notifications@github.com wrote:

 I don't have enough knowledge to say if what you've got here is thermodynamically correct. We should get @cfgoldsmith and @rwest to weigh in, and maybe the SAB as well if you want.

That said, it would be interesting to see if you made these changes whether there would be any changes in the IdealGasPhase calculations. We expect not, but you never know... So I'd be interested in seeing an implementation 😁

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

speth commented 4 years ago

I think it might be worth discussing the more general issue here, as we seem to keep bumping into this confusion about the differences between the standard / reference and unqualified thermodynamic properties. See, for instance https://github.com/Cantera/cantera/issues/522, where @decaluwe posed the question:

Do we need both (or either) "standard state" and "reference species property" calculations featured in the codebase? You can't really avoid having the reference data loaded and stored as such, but I'm somewhat skeptical that we need the standard state data explicitly calculated or stored.

I would go a step further, and question whether either "standard state" or "reference state" thermodynamic properties should be part of the public interface to the ThermoPhase class. These methods are used in a handful of places, such as the kinetics calculations mentioned above, as well as in the equilibrium solvers. However, it might be the case that these could be replaced with use of the full thermodynamic properties without losing anything.

decaluwe commented 4 years ago
  1. @speth -- While I agree that this is a conversation/decision we keep putting off, and one that needs to occur, it is only partially relevant to the issue raised here (if I am understanding your suggestion correctly. I may not be - see below).

    Whether or not they are publicly accessible (I can think of 1 or 2 use cases where they are not necessary, but maybe a user would like them -- see below for this, too), the standard-state Gibbs energy of reaction is required internally for calculating the reverse reaction rate coefficient for reversible reactions. The issue here is that something seems to be awry with how this is done for certain reactions, such that Cantera calculates reverse rate coefficients that are pressure-dependent but ought not to be.

  2. I appear to have misinterpreted @wbessler's original observation. The exchangecurrentdensity gives the incorrect (pressure-dependent k_rev) result, whereas the standard approach does not. I have amended the original issue message to reflect this. This makes sense (a bug of the nature I described above would have been caught by now, I would think), and makes the problem much less widespread (it does not impact all interface reactions, just this one rate coefficient type). It also suggests two possible paths to fixing it.

This actually breaks the issue into two separate issues:

  1. Fixing the current issue: The conversion and calculation of k_rev is likely not coded in a generalized manner when rate_coeff_type = exchangecurrentdensity is used. I will inspect. Clearly, the code should just implement the full theory, without making any assumptions about the standard state, and let the terms be whatever they are.

    1a. On a related note, I did notice that something similar is done in IdealGasPhase::getChemPotentials - the routine hard-codes the species activities as X_k, rather than calling sub-routines to calculate them. It's done correctly, but if, for example, we do change the standard state, this is less robust in that it would not automatically adjust.

  2. A broader question about the standard state for the IdealGasPhase, and whether it should be pressure-dependent. Pressure-independent would be more consistent with how the field conceives of the Ideal Gas phase, likely helping prevent similar confusion and or errors on two fronts:

decaluwe commented 4 years ago

So... I think this discussion on standard states is valuable, but is unrelated to the error in the charge transfer rate coefficients.

I went and re-derived the conversion, yesterday. The error observed by @wbessler turns out to be either a typo or simply an error in the derivation of InterfaceKinetics::convertExchangeCurrentDensityFormulation. There is a missing m_beta[i] exponent in the standard concentration term in the denominator.

I have a fix implemented and will submit a PR shortly. What to do with this discussion, though? I think it is worth figuring out what to do with the standard/reference/etc. states, even though it might not be at the very top of anyone's list.

speth commented 4 years ago

I think the enhancements repo is the place to start this discussion, and the fix for the issue you noted with convertExchangeCurrentDensityFormulation should close this issue. I can take care of creating the new issue in the enhancements repo. We can copy any relevant comments here or on other issues to that thread.