Skip to content
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

Fix pcsaft flash #1913

Merged
merged 5 commits into from Apr 9, 2020
Merged

Fix pcsaft flash #1913

merged 5 commits into from Apr 9, 2020

Conversation

zmeri
Copy link
Contributor

@zmeri zmeri commented Apr 7, 2020

Requirements

  • Fill out this template to the extent possible so that this PR can be reviewed in a timely manner.
  • Replace the bracketed text below with your own.
  • All new code requires tests to ensure against regressions.

Description of the Change

The flash and density solvers for the PC-SAFT backend were update to make them more reliable. Some minor edits to function names were also added to make it clear that PC-SAFT calculates residual H, S, and G.

Benefits

Improved consistency and higher likelihood that PC-SAFT backend will find the correct solution.

Possible Drawbacks

That code elsewhere might break

Verification Process

I added additional unit tests to confirm that the flash and density functions worked over a wider range of conditions, and all these unit tests passed. I also added a python script to make consistency plots for the PC-SAFT backend, and the consistency improved significantly after the changes. I also ran all the unit tests and almost all passed. Of 50497 assertions only 240 failed. Most of those that failed were because I do not have the Refprop or UNIFAC libraries, and the few others I checked also failed before the changes made here, so they appear to be unrelated to the changes here.

Applicable Issues

[ Enter any applicable Issues here. Use Closes #???? if this PR closes an open issue. ]

Copy link
Contributor

@ibell ibell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of small things, nothing too serious.

Comment on lines 1 to 2
// File generated by the script dev/generate_headers.py on 2019-12-12 21:03:32.480501
// File generated by the script dev/generate_headers.py on 2020-04-07 19:35:54.752805

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have noted this before the first PC-SAFT PR, but the autogenerated json files in the include folder should not be under source control

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to the .gitignore file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also remove the generated JSON files from source control? They aren't enormous, but every byte counts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I forgot to do that. Done.

@@ -40,7 +40,9 @@ const parameter_info parameter_info_list[] = {
{iCvmass, "Cvmass", "O", "J/kg/K", "Mass specific constant volume specific heat", false},
{iCp0molar, "Cp0molar", "O", "J/mol/K", "Ideal gas molar specific constant pressure specific heat",false},
{iCp0mass, "Cp0mass", "O", "J/kg/K", "Ideal gas mass specific constant pressure specific heat",false},
{iSmolar_residual, "Smolar_residual", "O", "J/mol/K", "Residual molar entropy (sr/R = tau*dar_dtau-ar)",false},
{iHmolar_residual, "Hmolar_residual", "O", "J/mol/K", "Residual molar enthalpy",false},
{iSmolar_residual, "Smolar_residual", "O", "J/mol/K", "Residual molar entropy (sr/R = s(T,rho) - s^0(T,rho))",false},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This was long overdue anyhow.

Comment on lines +113 to 115
.value("iHmolar_residual", parameters::iHmolar_residual)
.value("iGmolar_residual", parameters::iGmolar_residual)
.value("iDmass", parameters::iDmass)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Can you perhaps also make the same changes to the cython files? The cython interface (for a variety of historical and non-historical reasons) is what is actually used with Python.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the AbstractState pyx and pxd files. Are there any other files I need to update?

Comment on lines 1 to 2
// File generated by the script dev/generate_headers.py on 2019-12-12 21:03:32.480501
// File generated by the script dev/generate_headers.py on 2020-04-07 19:35:54.752805

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also remove the generated JSON files from source control? They aren't enormous, but every byte counts.

Comment on lines +159 to +161
cpdef double gibbsmolar_residual(self) except *
cpdef double hmolar_residual(self) except *
cpdef double smolar_residual(self) except *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they also need to get added to cAbstractState.pxd . This code duplication for C++ classes is one reason that I much prefer pybind11 for wrapping C++. Perhaps you can test compilation for Python?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added them to cAbstractState.pxd as well. I tested compilation and ran a small Python script to check that it worked. The PC-SAFT values matched those from the HEOS backend.

@ibell ibell merged commit feec37f into CoolProp:master Apr 9, 2020
@ibell
Copy link
Contributor

ibell commented Apr 9, 2020

Thanks, merged.

@ibell ibell added this to the v6.4.0 milestone May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants