-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Implement recreation of SolutionArray objects from stored data #687
Conversation
e18b37d
to
6519516
Compare
6519516
to
8562a94
Compare
Codecov Report
@@ Coverage Diff @@
## master #687 +/- ##
==========================================
- Coverage 70.62% 70.62% -0.01%
==========================================
Files 372 372
Lines 43575 43565 -10
==========================================
- Hits 30777 30768 -9
+ Misses 12798 12797 -1
Continue to review full report at Codecov.
|
0dd6946
to
e84ec2d
Compare
Codecov Report
@@ Coverage Diff @@
## master #687 +/- ##
=======================================
Coverage 70.63% 70.63%
=======================================
Files 372 372
Lines 43567 43567
=======================================
Hits 30773 30773
Misses 12794 12794
Continue to review full report at Codecov.
|
Moving this discussion here so if that commit is deleted, the discussion isn't lost.
I agree this is a legitimate case.
I don't think the setter is correct. If, say, the quality is saved such that it's close to saturated vapor, T and p are not unique compared to the saturated liquid, so using T, p to set the state isn't unique. At least, that's how I'm reading the
I'm not sure what assumptions you mean here. TP is only valid for single-phase states, while TX and PX are only valid for two-phase. I believe TP will raise an exception if T and p are not independent. In any case, shouldn't it be possible to implement the check in the |
Here is the rest of the conversation about the commit adding a TPX setter for PureFluid phases:
(Sorry about the close/reopen, I fat-fingered the buttons on my phone) |
I believe the setter is correct. Edit: re-reading the scenario, we're actually on the same page. Note that this is only possible if P=P_sat(T), which is when the
The current implementation uses a single setter once suitable properties are identified, i.e. implementing a |
Looking over open issues, there are some repercussions for #595, which relocates restoring states to the C++ core. A proper solution would entail defining Edit: #644 is another example where setting of states is not handled consistently with phase definitions. As mentioned, I believe that a list of legitimate setters should be generated within C++. Nevertheless, I do not think that |
e84ec2d
to
265a186
Compare
2e609b8
to
7331100
Compare
7331100
to
2f42415
Compare
To summarize some thoughts on setting states within C++ and the python interface:
|
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.
Overall, this looks very good to me. The set of cases handled is quite comprehensive, and I appreciate the effort put into making any valid combination of properties work for setting the state.
The only one that I question is reintroducing the TPX
setter to PureFluid
. There are better choices easily available -- the default properties include the best one, temperature and density, so I don't think we need to create a fallback option that mostly works but has potential for weirdness for points that fall within the threshold of the isclose
checks.
* setter for `PureFluid.TPX` property is added to allow for automatic restoration of consistent thermodynamic data * alternative to 'TP', 'TX' or 'PX' which may not uniquely describe a valid thermodynamic state * add unit test
This commit implements new methods for SolutionArray: * `restore_data` can restore data previously exported by `collect_data` * `read_csv` restores data previously saved by `write_csv` * unit tests are added for SolutionArray's based on ThermoPhase and PureFluid
2f42415
to
124352f
Compare
👍 @bryanwweber suggested a hidden setter, i.e. |
@speth Yeah, I was mis-remembering what a I still think the |
The hidden setter |
Well, the |
3e4d1b7
to
ee28ae7
Compare
@bryanwweber ...
True. At the same time, any user has to get pretty lucky to 'guess' a valid 3-property state without getting the
Could we resolve this by applying PEP 20 (it is implemented in Python after all?) 😉 |
Here are my thoughts with the "hidden"
I did some experimenting this morning trying to do weird things with the regular
That One other suggestion is to print the T, P, and X values in the |
Both suggestions are reasonable and can be implemented with little effort. Will get to it later today (which also allows @speth to chime in). PS: ad other EOS ... the dual-purpose |
To my understanding, the other EOS types are multi-species capable and |
👍 that would have been my go-to solution also |
All of the choices here are nonideal. I don't really like the idea of adding the I'm also starting to think that option 3 doesn't sound so bad, but I'm still OK with option 1 as implemented.
This would also be consistent with other naming conventions that have been adopted in the Python module, e.g. D for density instead of R for Rho. I think there are additional, larger complexities for the multi-species two-phase phases that are currently unsolved, e.g. how to access the composition of each phase which currently can't be done. |
🤷♂️ ... I can go either way. I have a mild preference for 1 (mostly PEP 20 related), but do not have a problem with 3. On the other hand, since the |
1b9be71
to
8503b12
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 👍 with the properties as they are here (i.e., option 1), and I've suggested a few small changes here.
8503b12
to
2c031d9
Compare
Incorporate reviewer suggestions for error messages (user feedback) in PureFluid.TPX setter and SolutionArray.restore_data
2c031d9
to
4ab78b9
Compare
I'm very new to this forum (and to any development forum for that matter), so my apologies in case my remark is not formulated at the right place or in the right way. I was using the latest cantera version, and trying to recreate a SolutionArray objects from stored data, but got a ValueError. The problems does not seem to be solved in the composite.py source code files which I found here at github. The minimal code to reproduce the problem is:
I believe the problem is situation in de definition of the "join" function in the "composite.py" file. More specifically, within that definition, valid species is declared as:
but should be declared as
or else the ValueError will always be thrown because valid_species represents species_names without prefixes ('X_', or 'Y_') while all_species represents species_names with those prefixes.
Warm regards, Stijn |
...sorry, the large bold sentences in my previous post were meant to be comments in the python code... |
I think your post from earlier today in the Cantera Users' Group is the right place to discuss this. For anyone else finding this, the post can be found at https://groups.google.com/g/cantera-users/c/AFa5u3F6JdQ. |
@stijn76 ... I edited your post so it shows up properly (code blocks should be between triple back ticks). There is a minor bug in your code, as you do not export the full state to csv (only concentrations). But even fixing that, the errors you pointed out persist, and I was able to confirm what you pointed out above. Interestingly, things mostly work for import cantera as ct
gas = ct.Solution('h2o2.yaml') # if changed to gri30.yaml, a ValueError is thrown for read_csv
states2 = ct.SolutionArray(gas)
gas.X = 'H2:0.5, O2:0.4'
gas.TP = 300, 101300
states2.append(T=gas.T, P=gas.P, X=gas.X)
states2.append(T=gas.T, P=gas.P, X=gas.X) # if commented out, this will throw an IndexError for read_csv
states2.write_csv('test3.csv', ('T', 'P', 'X'))
b = ct.SolutionArray(gas)
b.read_csv('test3.csv') PS: Please create a new issue/bug report, rather than attaching this to this old pull request. |
thanks for your help and advise! I've created a new bug report. |
Please fill in the issue number this pull request is fixing:
Fixes #543
Changes proposed in this pull request:
This commit implements two new methods for SolutionArray:
restore_data
can restore data previously exported bycollect_data
read_csv
restores data previously saved bywrite_csv
read_hdf
restores data saved bywrite_hdf
Intended usage is:
and, at a later point
PS: once PR #680 is merged, an equivalent method forDone.read_hdf
will be added to this PR.