Expose Peng-Robinson EoS parameters to Python interface#1664
Expose Peng-Robinson EoS parameters to Python interface#1664speth merged 5 commits intoCantera:mainfrom
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1664 +/- ##
==========================================
+ Coverage 72.77% 72.78% +0.01%
==========================================
Files 375 375
Lines 56632 56679 +47
Branches 20590 20607 +17
==========================================
+ Hits 41212 41255 +43
- Misses 12398 12400 +2
- Partials 3022 3024 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
I am not sure whether I am fully behind hard-coded names as parameters, as users need to know what those are (an alternative would be to return an AnyMap populated with all applicable entries, which can then be mapped to a Python dict). I am also unsure whether the name compute_extra_method is intuitive.
PS: for the failing examples, there's a pending fix in 62300d3
| * @return Computed value wrapped in AnyValue type for Peng-Robinson phase | ||
| * quantities | ||
| */ | ||
| AnyValue compute_extra_method(const std::string& name) override; |
There was a problem hiding this comment.
| AnyValue compute_extra_method(const std::string& name) override; | |
| AnyValue computeExtraMethod(const std::string& name) override; |
In C++, Cantera uses mostly camelCase methods rather than snake_case.
src/thermo/PengRobinson.cpp
Outdated
|
|
||
| AnyValue PengRobinson::compute_extra_method(const std::string& name) | ||
| { | ||
| if(name == "aAlpha_mix") { |
There was a problem hiding this comment.
| if(name == "aAlpha_mix") { | |
| if (name == "aAlpha_mix") { |
Missing whitespace after if
|
I recall us having discussed this idea at some point before. Can you please update the initial post to describe the use case for making these parameters accessible? |
I have updated with a reference to a paper showing the compressible flamelet methodology that utilizes tabulations of real-gas parameters to create better flamelet tables. |
|
Now that I've worked on the implementation, essentially all of the additional methods are just calling already defined functions in the PREOS implementation, so those could be exposed instead of adding this new virtual method. I don't know if that is better or worse. |
From the perspective of the Python API implementation (or any other language interface), it is easier (preferable?) to have a single function signature that is common to all |
So for an AnyMap return type, you're saying that the function should just collect all parameters and return them all to user instead of letting them choose? |
Correct. |
|
Ok, I switched to the AnyMap, and that is a more user-friendly option for sure. |
|
I have an example here: This just uses the Cantera co2_PR_example.yaml and the data in critical-properties.yaml The CO2 file is at: /test/data/ and the critical file is at /build/data |
speth
left a comment
There was a problem hiding this comment.
Thanks for implementing this, @wandadars. I think it will be a useful feature, especially in some debugging applications. Besides the specific comments below, this also needs a test, ideally for the Python interface.
9a2fe2a to
a2b1615
Compare
a2b1615 to
2f751d3
Compare
|
Ok. I made some final changes that I had missed when we renamed the method. I added a Python test to the ThermoPhase Python testing file. I'm not well versed in handling of YAML files that have multiple definitions in them (like the co2_PR one), but I think it does the right thing. One thing I'm not 100% sure on with the Peng Robinson specifications is how we can set the Peng Robinson equation of state to be used, but to give it a species that is ideal-like. That way we could potentially test the values of the parameters that are returned, as I believe for a single species, those values would all be zero. I just haven't quite figured out how to formalize such a configuration using Cantera yet. |
speth
left a comment
There was a problem hiding this comment.
Thanks for the updates, @wandadars. I only have a couple of minor formatting/style requests.
For the test, I think you should check that the keys returned are what you expect, rather than just the number of keys is correct. I don't think you necessarily need to worry about whether the numerical values are correct in this test. But if you want to check something, you could use the returned values of aAlpha_mix and b_mix along with the current temperature and molar volume to compute the pressure of the mixture using the PR equation of state and see if it matches.
|
I have made those formatting updates and added that much better pressure testing unit test. |
speth
left a comment
There was a problem hiding this comment.
Thanks, @wandadars. This looks good to me!
This pull request seeks to expose the Peng-Robinson equation of state parameters, such as aAlpha, b, and the first and second derivatives of aAlpha with respect to temperature so that these values are available through the Python interface of the ThermoPhase object. These parameters are often used in the context of compressible flamelet table tabulations.
See: https://arxiv.org/abs/1704.02639
I'm attempting to use the AnyValue object for the return type to generalize a bit. The overall idea I had was to have a catch-all function that can dispatch to method that return values from the eos objects.
Checklist
scons build&scons test) and unit tests address code coverage