Reformulation of Helmholtz energy expressions - #1799
Conversation
…into HelmHoltz-Rework
|
@snarasi2 Take a look |
|
I'm somewhat unsure about the compatibility test - It seems like everything is fine except for the number of iterations for a few of the samples. If the absolute tolerance is adjusted to 2, this test passes. Arguably, this might somewhat defeat the spirit of a compatibility test, but given that the other assertions remain valid and the iteration changes are small and in both directions (4 decrease by 1, 5 increase by 1) it seems fairly acceptable? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1799 +/- ##
==========================================
- Coverage 73.82% 73.70% -0.12%
==========================================
Files 419 425 +6
Lines 66392 67674 +1282
Branches 11170 11424 +254
==========================================
+ Hits 49013 49881 +868
- Misses 14839 15175 +336
- Partials 2540 2618 +78 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I can also increase the code coverage by including some additional fluids which use other energy terms. I was intending to wait until the next pull request and merge them all, but can quite easily add them to the commit here and extend the coolprop comparison tests to include a call to the WriteParameters class to check enthalpy and density values, similarly to what is currently done in the test_parameter_util tests. |
|
@StephenBurroughs this is a pretty large PR. Might you be available to talk through this over zoom? Our regular dev call is 11am Pacific Time (which is pretty early for you). We might be able to schedule another time. |
Sure thing, I'll shoot you an email |
|
Thank you so much for contributing this, @StephenBurroughs . However, I don't have a good enough grasp on the core Helmholtz code to feel comfortable replacing it wholesale. Unless @eslickj reappears from the aether to review this PR, I think the best path forward is to take this version of the Helmholtz properties and put it Let me know what you think. |
|
I can see where you're coming from @dallan-keylogic. This could be an option - although I feel like possibly including it in modular properties instead could be appropriate - I have some other reasons for this as well, as Peng-Robinson is on my radar... |
…uora-smart-energy-systems/idaes-pse into HelmHoltzReformulated
|
@dallan-keylogic If you have time, have a look at the newer implementation here. It maintains compatibility with legacy fluids, but also brings in a whole heap of additional fluids through the new formulation. |
|
I've updated the CoolProp test in a similar manner to the other pull request I opened for #1815 - This means that they pass with CoolPropv8 (and compatibility tests will pass if the relevant PR is merged in the compatibility repo). If you want to hold off on the CoolProp upgrade, I'll just roll back that test change. |
Overview of Reformulation
This pull request is the first of 3 refactors to reformulate the way in which General Helmholtz property packages are built. The full set of changes are as follows:
I have already made some progress with regard to Tcx expressions and have actually integrated all of Coolprop (without surface tension, thermal conductivity, and viscosity), but thought that it might be a bit easier to deal with these changes in stages rather than submitting a single, giant PR.
Fixes
Provides a modular set of terms for building Helmholtz property packages.
Adds a set of tests to compare fluid properties against CoolProp
Summary/Motivation:
The existing implementation for general Helmholtz property packages is functional, but also rather painful to use when extending to support new fluids. This is primarily down to two reasons:
This is problematic, as it means that to add support for a new fluid, a user is required to essentially write out a whole new expression for ideal and residual terms, as well as evaluate, transcribe, and check the derivatives thereof.
A solution to this can be found in the modular approach that is used by CoolProp - energy formulations are essentially made up of a combination of terms. Under the status quo implementation within IDAES, any additional fluid for which an expression has not already been created must be explicitly defined, even if there is only one term that is altered from an existing expression. By switching to a modular approach that just relies on the terms being defined, fluids can be added quite rapidly by identifying the terms that are present and building the full expression in an on-demand fashion. It's also much easier to add new terms that aren't already supported, as they can be defined as standalone terms and automatically pulled into the expression builder with minimal effort.
This process is also much faster if we remove the need to explicitly define derivative terms. These are necessary because of the formulation of the backend c++ code within IDAES-extensions, which provides external functions to the property package. Thankfully, Pyomo actually provides a way to do symbolic differentiation, which means that we can generate these derivatives during the process of writing the property package files rather than having to define them explicitly. This is great, because it reduces the amount of effort required to add additional forms for energy terms, as well as reduces the number of possible sources of error within the calculations.
Finally,
I've added a test that compares enthalpy/entropy differences and density against coolprop. This is in part due to the next stage of this broader rework which brings in all coolprop fluids, as frankly it seemed far less painful than explicitly defining a set of properties to verify against for everything.
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my contribution: