zmeri / PC-SAFT

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

Additional function for the natural log of the fugacity #100

Closed DiegoTMelfi closed 1 year ago

DiegoTMelfi commented 2 years ago

Dear,

This is not an actual issue with the codes, but would it be possible to create another function that evaluates the natural log of the fugacity of the component in the phase (essentially identical to pcsaft_fugcoef, but without the last exponential operation)? I ask this because I am doing polymer phase equilibria and for polymers, the natural log of the fugacity in a liquid phase is of the order of negative 1000. And when we do exp(-1000) we get zero because double precision cannot compute such a small number, which is what the program is returning. I could try to do it myself, but my cython background is null, and this might be something that other people can benefit from.

Thank you in advance, Diego

zmeri commented 2 years ago

Hi, I am busy with other tasks right now and cannot implement this at the moment. However, it wouldn't be hard for you to do it yourself, even without a cython background. You could copy the pcsaft_fugcoef function, rename it, and remove the exponential operation at the end. Then you would just need to copy the line for the pcsaft_fugcoef function in the remaining files (pcsaft_electrolyte.h, pcsaft.pyx, pcsaft.pxd, init.py) and change it to the name of your new function. Doing so will make the function available to the Python module via Cython. Compile using Cython (see the Cython docs) and the new function should be ready to go.

I know that working with a new language/technology can be daunting, but this really is a good task to get started with and learn from. I've had to learn myself the same way, and the skills you learn can be quite useful later.

On Wed, Jun 1, 2022 at 2:13 AM DiegoTMelfi @.***> wrote:

Dear,

This is not an actual issue with the codes, but would it be possible to create another function that evaluates the natural log of the fugacity of the component in the phase (essentially identical to pcsaft_fugcoef, but without the last exponential operation)? I ask this because I am doing polymer phase equilibria and for polymers, the natural log of the fugacity in a liquid phase is of the order of negative 1000. And when we do exp(-1000) we get zero because double precision cannot compute such a small number, which is what the program is returning. I could try to do it myself, but my cython background is null, and this might be something that other people can benefit from.

Thank you in advance, Diego

— Reply to this email directly, view it on GitHub https://github.com/zmeri/PC-SAFT/issues/100, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKXTOBDZ7GMCJ554H36EXLVM2MI3ANCNFSM5XPDBLGQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

DiegoTMelfi commented 2 years ago

Hi,

Thank you for your response and your directions! After a little struggle, I created the new function, which is working just fine. Diego

zmeri commented 1 year ago

I'm glad to hear that you got it working. Would you be willing to submit a pull request and contribute your improvements?

On Sat, Jun 25, 2022 at 12:22 AM DiegoTMelfi @.***> wrote:

Hi,

Thank you for your response and your directions! After a little struggle, I created the new function, which is working just fine. Diego

— Reply to this email directly, view it on GitHub https://github.com/zmeri/PC-SAFT/issues/100#issuecomment-1165950200, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKXTOFAJWL6YIHTO2PLU2TVQYRHNANCNFSM5XPDBLGQ . You are receiving this because you commented.Message ID: @.***>