zmeri / PC-SAFT

Functions implementing the PC-SAFT equation of state, including association, electrolyte and dipole terms
GNU General Public License v3.0
49 stars 18 forks source link

Zmeri patch 7 #69

Closed zmeri closed 4 years ago

SaeedMardani commented 4 years ago

@zmeri, very great work, thanks for sharing! :)

Nram94 commented 4 years ago

@zmeri, great work here! I am currently working with the pure python version and I was wondering if you could please tell me what changes were made to the density exactly so that I can implement them accordingly! Thanks in advance and great job!

zmeri commented 4 years ago

Hi Nicolas,

I changed the logic for the density solver to make it more robust. Here is the key place in the C++ code: https://github.com/zmeri/PC-SAFT/blob/4bd03f8720fa2f29a5240a9800bb5d33ada9094f/pcsaft.cpp#L2201 Essentially, I added an initial scan to find a good first guess to start from. It turns out that PC-SAFT can have more than 3 density roots [ref https://www.researchgate.net/profile/Jean_Noel_Jaubert/publication/229388068_Are_safe_results_obtained_when_the_PC-SAFT_equation_of_state_is_applied_to_ordinary_pure_chemicals/links/598ecc06458515b87b351c74/Are-safe-results-obtained-when-the-PC-SAFT-equation-of-state-is-applied-to-ordinary-pure-chemicals.pdf], and the initial guess values suggested by Gross and Sadowski don't always work. I didn't notice it before, but I started testing at low and high temperatures and then I saw problems. The new logic seems to solve the problem. I also added more robust flash routines for the same reason. You could implement similar logic in the Python code.

Also, I am working on getting the code added as a package to the Python Package Index. I have it working for Windows on TestPyPi: pcsaft https://test.pypi.org/project/pcsaft/. I'll try to send you an email once the package is up on the real PyPi. Then you can just install the code with pip and get the C++ speed without having to build it yourself. Do you use Windows or Linux? I'm not planning on making a wheel for MacOS, so if you're on a Mac then this won't be much help.

And out of curiousity, what are you using PC-SAFT for?

Best regards, Zach

On Sun, Mar 15, 2020 at 10:34 PM Nicolas Ramirez notifications@github.com wrote:

@zmeri https://github.com/zmeri, great work here! I am currently working with the pure python version and I was wondering if you could please tell me what changes were made to the density exactly so that I can implement them accordingly! Thanks in advance and great job!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zmeri/PC-SAFT/pull/69#issuecomment-599261101, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKXTOCAY5ETNPJI2XRLEP3RHU3VDANCNFSM4LG6G7WA .

zmeri commented 4 years ago

Hi,

The pcsaft package is now up on PyPi and can be installed with pip: https://pypi.org/project/pcsaft/

Zach

On Thu, Mar 19, 2020, 21:40 Zach Baird ztbaird@gmail.com wrote:

Hi Nicolas,

I changed the logic for the density solver to make it more robust. Here is the key place in the C++ code: https://github.com/zmeri/PC-SAFT/blob/4bd03f8720fa2f29a5240a9800bb5d33ada9094f/pcsaft.cpp#L2201 Essentially, I added an initial scan to find a good first guess to start from. It turns out that PC-SAFT can have more than 3 density roots [ref https://www.researchgate.net/profile/Jean_Noel_Jaubert/publication/229388068_Are_safe_results_obtained_when_the_PC-SAFT_equation_of_state_is_applied_to_ordinary_pure_chemicals/links/598ecc06458515b87b351c74/Are-safe-results-obtained-when-the-PC-SAFT-equation-of-state-is-applied-to-ordinary-pure-chemicals.pdf], and the initial guess values suggested by Gross and Sadowski don't always work. I didn't notice it before, but I started testing at low and high temperatures and then I saw problems. The new logic seems to solve the problem. I also added more robust flash routines for the same reason. You could implement similar logic in the Python code.

Also, I am working on getting the code added as a package to the Python Package Index. I have it working for Windows on TestPyPi: pcsaft https://test.pypi.org/project/pcsaft/. I'll try to send you an email once the package is up on the real PyPi. Then you can just install the code with pip and get the C++ speed without having to build it yourself. Do you use Windows or Linux? I'm not planning on making a wheel for MacOS, so if you're on a Mac then this won't be much help.

And out of curiousity, what are you using PC-SAFT for?

Best regards, Zach

On Sun, Mar 15, 2020 at 10:34 PM Nicolas Ramirez notifications@github.com wrote:

@zmeri https://github.com/zmeri, great work here! I am currently working with the pure python version and I was wondering if you could please tell me what changes were made to the density exactly so that I can implement them accordingly! Thanks in advance and great job!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zmeri/PC-SAFT/pull/69#issuecomment-599261101, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKXTOCAY5ETNPJI2XRLEP3RHU3VDANCNFSM4LG6G7WA .

Nram94 commented 4 years ago

Hello, Zach,

Thanks for your response!

I am currently using Windows and it is great to have it available on PyPi I will try this version as soon as I can. I am currently working on my PhD thesis using PcSaft and I am not very fond of Fortran so I began trying to do all calcultions that I have in Fortran in Python as a personal project. I was planning adding a parametrization method proposed by Jaubert and Privat called I-PcSaft https://pubs.acs.org/doi/10.1021/acs.iecr.9b04660 And as anotherpersonal project I am working on different thermodynamics applications using PcSaft as the go to model.

Thanks again for this amazing work!

Kind regards, Nicolas

El El vie, 20 de mar. de 2020 a la(s) 7:26 p. m., Zach Baird < notifications@github.com> escribió:

Hi,

The pcsaft package is now up on PyPi and can be installed with pip: https://pypi.org/project/pcsaft/

Zach

On Thu, Mar 19, 2020, 21:40 Zach Baird ztbaird@gmail.com wrote:

Hi Nicolas,

I changed the logic for the density solver to make it more robust. Here is the key place in the C++ code:

https://github.com/zmeri/PC-SAFT/blob/4bd03f8720fa2f29a5240a9800bb5d33ada9094f/pcsaft.cpp#L2201 Essentially, I added an initial scan to find a good first guess to start from. It turns out that PC-SAFT can have more than 3 density roots [ref < https://www.researchgate.net/profile/Jean_Noel_Jaubert/publication/229388068_Are_safe_results_obtained_when_the_PC-SAFT_equation_of_state_is_applied_to_ordinary_pure_chemicals/links/598ecc06458515b87b351c74/Are-safe-results-obtained-when-the-PC-SAFT-equation-of-state-is-applied-to-ordinary-pure-chemicals.pdf ], and the initial guess values suggested by Gross and Sadowski don't always work. I didn't notice it before, but I started testing at low and high temperatures and then I saw problems. The new logic seems to solve the problem. I also added more robust flash routines for the same reason. You could implement similar logic in the Python code.

Also, I am working on getting the code added as a package to the Python Package Index. I have it working for Windows on TestPyPi: pcsaft https://test.pypi.org/project/pcsaft/. I'll try to send you an email once the package is up on the real PyPi. Then you can just install the code with pip and get the C++ speed without having to build it yourself. Do you use Windows or Linux? I'm not planning on making a wheel for MacOS, so if you're on a Mac then this won't be much help.

And out of curiousity, what are you using PC-SAFT for?

Best regards, Zach

On Sun, Mar 15, 2020 at 10:34 PM Nicolas Ramirez < notifications@github.com> wrote:

@zmeri https://github.com/zmeri, great work here! I am currently working with the pure python version and I was wondering if you could please tell me what changes were made to the density exactly so that I can implement them accordingly! Thanks in advance and great job!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zmeri/PC-SAFT/pull/69#issuecomment-599261101, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AFKXTOCAY5ETNPJI2XRLEP3RHU3VDANCNFSM4LG6G7WA

.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/zmeri/PC-SAFT/pull/69#issuecomment-601848636, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN2HLBDYONZJZR5ID2OTKO3RIOYNNANCNFSM4LG6G7WA .

-- Nicolás Ramírez V.

Nram94 commented 3 years ago

Hi, Zach!

I have been using your repository to perform calculations for some pure compounds. However, I am running into troubles with the Hvap function, in particular with the flashTQ portion of it calculating Pvap, as it seemingly cannot find a solution at temperatures above 500 K (for some compounds I tested, like propinoic acid, the issue showed up a T = 413.68 K, for 1,1-Dibromoethane at T = 590.69 K. For Nitrobenzene the issue rises around T = 520 K). Is there a way to go around this issue? Can you ellaborate a bit on how the flashTQ function operates (I can imagine the bulk of it is in the C++ part of the code which unfortunately I cannot comprehend very well as I know very little about this language), and if maybe it is an issue of number of iterations or the method used to find the solution. Is there a way to input this to the function?

I tried setting p_guess to the actual vapor pressure from experimental data but the solution could not be found.

Thanks in advance and thank you for this amazing work once again!

zmeri commented 3 years ago

Hi Nicolas!

Yes, performing phase equilibrium calculations can be quite difficult, especially for PC-SAFT. As you probably already know, when solving in the two phase region there are generally three density solutions/roots to an equation of state. For PC-SAFT, there are often more than 3 because PC-SAFT exhibits a second spurious phase equilibrium line that seems to be an artifact of how the equation of state is constructed (see Privat et al. 2010 https://www.researchgate.net/profile/Jean-Noel-Jaubert/publication/229388068_Are_safe_results_obtained_when_the_PC-SAFT_equation_of_state_is_applied_to_ordinary_pure_chemicals/links/598ecc06458515b87b351c74/Are-safe-results-obtained-when-the-PC-SAFT-equation-of-state-is-applied-to-ordinary-pure-chemicals.pdf). In addition, I haven't had the time to develop a rigorous flash algorithm for a wide range of problems. The algorithm I used is fairly simple and probably should be made more robust. Although, it has worked for my use cases so far.

Unfortunately, I don't think a simple tweak could fix the problems with the flash algorithm. I think some time would need to be invested to completely redo the algorithm in the code. I know there is some literature out there about better flash algorithms to use. I don't have time at the moment to do this though. In the meantime, it might also be possible to code your own flash function in Python. The fugacity coefficients can be calculated, so it should be possible to define your equilibrium criteria and create a cost function that can be minimized using an existing Python optimization algorithm, such as those in Scipy.

Sorry I can't be of more help, but it's not an easy problem to solve.

Zach

On Wed, Mar 17, 2021 at 11:34 AM Nicolas Ramirez @.***> wrote:

Hi, Zach!

I have been using your repository to perform calculations for some pure compounds. However, I am running into troubles with the Hvap function, in particular with the flashTQ portion of it calculating Pvap, as it seemingly cannot find a solution at temperatures above 500 K (for some compound I tested, like propinioc acid, the issue showed up a T = 590.69 K, similarly for 1,1-Dibromoethane. For Nitrobenzene the issue rises around T = 520 K. Is there a way to go around this issue? Can you ellaborate a bit on how the flashTQ function operates (I can imagine the bulk of it is in the C++ part of the code which unfortunately I cannot comprehend very well as I know very little about this language), and if maybe it is an issue of number of iterations or the method used to find the solution. Is there a way to input this to the function?

I tried setting p_guess to the actual vapor pressure from experimental data but the solution could not be found.

Thanks in advance and thank you for this amazing work once again!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/zmeri/PC-SAFT/pull/69#issuecomment-800936787, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKXTOF2M2JP3ZKDRBTPYGLTEBZSLANCNFSM4LG6G7WA .

Nram94 commented 3 years ago

Hi Zach!

Thank you for your response! I understand better the problem now and yes, it is not as simple as I first thought it could be. I will try implementing a self-made one in order to see if I can perform these calculations. If I find something useful I will let you know!

Thank you once again and once again kudos on this amazing work!

Nicolas

Nram94 commented 3 years ago

Hi Zach!

Thank you for your response! I understand better the problem now and yes, it is not as simple as I first thought it could be. I will try implementing a self-made one in order to see if I can perform these calculations. If I find something useful I will let you know!

Thank you once again and once again kudos on this amazing work!

Nicolas

May I also ask, exacly which flash algoruthm are you implementing here? This would be of great help in order to better understand how to approach the issue.