-
-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Differentiate quality from mole fraction in Python #719
Differentiate quality from mole fraction in Python #719
Conversation
2ee2146
to
8565d0d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fully on board with this renaming. I think it will be worth it to avoid the confusion caused by the overloading of X as both mole fraction and vapor fraction depending on the phase type.
8565d0d
to
57eba8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While trying to experiment with getting Q
to work as the column name for SolutionArray
output, I ran into a problem, and haven't quite been able to figure out why it's failing:
>>> import cantera as ct
>>> p = ct.Water()
>>> s = ct.SolutionArray(p, 5)
>>> data, cols = s.collect_data()
>>> s.restore_data(data, cols)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-02284ff2df78> in <module>()
----> 1 s.restore_data(data, cols)
~/src/cantera/build/python/cantera/composite.py in restore_data(self, data, labels)
704 raise ValueError(
705 "invalid/incomplete state information (detected "
--> 706 "partial information as mode='{}')".format(mode)
707 )
708
ValueError: invalid/incomplete state information (detected partial information as mode='Y')
Hm, I can reproduce this. I will have to look at this, as it looks like the standard In [1]: import cantera as ct
...: p = ct.Water()
...: s = ct.SolutionArray(p, 5)
...: data, cols = s.collect_data()
In[2]: cols
Out[2]: ['T', 'density', 'Y_H2O'] Will add some additional unit tests to make sure that there aren't any surprises. |
@speth ... on second look, the fix is already included in #720, which allows for different standard states (up until now, the standard state is defined as So, would you mind tabling this until #720 is discussed & merged? (I recall you mentioning that there may be several issues that may need to be converged). |
Ah, I didn't realize that it was a pre-existing issue, but that makes sense, and I'm happy to see that it's already fixed by #720. |
@speth ... I confirmed that the bug you found was indeed pre-existing, but also found a second issue that prevented #720 from fixing it directly (the additional fix is now added in ce424c9). This is added to #720, as a fix of #644 (and associated issues) is required regardless. I also added a unit test to confirm that things are working as expected. |
Adding an observation from #720 here (per @speth's findings) gas = ct.Solution('gri30.yaml')
w = ct.Water()
a = ct.SolutionArray(gas, 10)
'TX' in dir(a) # False, as expected
b = ct.SolutionArray(w)
'TX' in dir(b) # True, as expected
'TX' in dir(a) # True, as expected, but not desired
a.TX # unexpectedly (but as desired) raises AttributeError Once |
57eba8e
to
aabf45f
Compare
Codecov Report
@@ Coverage Diff @@
## master #719 +/- ##
=========================================
+ Coverage 71.4% 71.4% +<.01%
=========================================
Files 372 372
Lines 43859 43863 +4
=========================================
+ Hits 31317 31320 +3
- Misses 12542 12543 +1
Continue to review full report at Codecov.
|
Remaining steps:
|
@speth after rebasing to #720,
I.e. I believe this is ready for a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, this eliminates the the TX
and PX
attributes of SolutionArray
without a (runtime) deprecation warning. I also noticed that the X
and TPX
properties of SolutionArray
don't seem to emit any warnings for pure fluids.
I'm not really sold on making nativeState
work with char
instead of std::string
. The efficiency benefit shouldn't ever matter, and I don't want to assume that there will always be a clear one-character name for any state variable. For example, what letter would you use for the electron temperature in a non-thermal plasma?
The idea of having Q
be dimensioned as nSpecies
to support more general multi-phase fluids is an interesting one, but it's a bit inconsistent here -- the value returned by PureFluid.Q
is a scalar, while SolutionArray.Q
returns an array with nSpecies
in the last dimension, and the second value returned by SolutionArray.TQ
is not. I realize that this is an inconsistency inherited from the previous mis-use of X
, but that's not a great reason to keep it. I'd like to avoid making the interface to the simple case that we already have (i.e. single-component fluids) less convenient in support of a capability that is mostly theoretical at present (would Q even be a useful state setter in such a case?).
Regarding isFluid
, I'm not really sure I see what the use case is, but if we really want such a flag, then the name is going to need some work. isMultiphase
would be one option, but I'd worry about distinguishing between "this model includes phase changes" and "the current state involves multiple phases".
78d8688
to
1affcad
Compare
@speth ... thanks for the review. I'm responding to your points before addressing major issue.
Yes, I just confirmed this. I hadn't anticipating this as I thought that the unit tests would catch - turns out that I was only testing deprecation of
I dropped the commit.
I want to believe that Cantera should be able to handle realistic multi-fuel vaporization applications eventually. My thought here was to exactly replicate the behavior of mass/mole fractions. I don't see much of an inconvenience as the only instance where
I had |
I don't think I don't think the vapor fraction of each species in a multiphase mixture can be used as part of a state setter in the same way as it can for a single-species phase, since it would over-specify the system per the Gibbs' Phase Rule, so I see this as more of a calculated property than part of the state. It could make sense to have two separate properties, one for the total vapor fraction across all species and one for the fraction of each species in the vapor phase. This would be analogous to what we do for many other properties, e.g.
OK, I can see that being useful for cases like |
This is a valid point: a scalar it is.
Exactly - it's often not immediately clear what's implemented. I hope we'll be able to set |
1affcad
to
c2f486b
Compare
@speth ... per discussion, I switched
|
c2f486b
to
174c9b7
Compare
@speth ... I believe 174c9b7 addresses setters/getters not being defined correctly, i.e. almost all points previously raised are now addressed. The lack of warnings is curious: I verified that the functions that should raise the warnings are indeed called. I found another context where warnings (and even errors!) are not raised, which may be related: see #746 |
@ischoegl For warnings at least, the warning is only shown the first time a |
Correct. The warnings here are, however, raised in |
@bryanwweber and @speth ... documenting the lack of warning (which I believe to be a bug that goes beyond this PR)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. This is looking pretty good to me.
I think there are some examples that need to be updated to use these new properties. rankine.py
comes to mind immediately, but there may be others.
01d8455
to
5a0174b
Compare
@speth ... made all requested changes and updated |
5a0174b
to
211cb09
Compare
Please fill in the issue number this pull request is fixing:
Fixes: N/A; but follows discussion in review of #687:
Changes proposed in this pull request:
Q
instead ofX
for quality (vapor fraction)X
inPureFluid
InSolutionArray.collect
, the species name is appended in labels, i.e.Q_H2O
I.e.