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

t and p as params instead of floats #76

Closed samiit closed 4 years ago

samiit commented 4 years ago

Hi,

I see that in the current implementation it is necessary to give the inputs - temperature, pressure and mole fractions as floats. Is it possible to give them as symbolic variables? Sorry if I am asking a silly question.

Sam

zmeri commented 4 years ago

I'm not exactly sure what you mean by symbolic variables. Do you mean something like Sympy? If you use symbolic variables, I think the best thing to do would be to try inputting them and see what happens. Since internally the code does not use symbolic variables, I imagine that any added precision from using them would be lost though.

samiit commented 4 years ago

Thanks for answering. I did try inputting a symbolic variable (something like Sympy), but then the check method rejects it. It requires it to be a float. Where can deactivate it? I asked another question, but I ask it here again, can you direct me to the code that I can make changes in?

samiit commented 4 years ago

Thanks I got your response. As of now I see that it is not possible, but if required, we would need to modify the Cpp code to skip the check. The whole reason for me was to get the pure implementations of the PC-SAFT and have it all in Python. As I read in your Readme file that an earlier git repo has only Python. If you don't mind, could you direct me to that commit?

Thanks.

zmeri commented 4 years ago

You can find the pure Python code in this earlier version. As a warning, the pure PC-SAFT code is quite slow. Also, I haven't kept the Python code up to date, so if you want to bring it up to date you would need to check what commits have happened since that version. I think the biggest thing is that I changed the functions that solve for density and vapor-liquid equilibrium (I changed the bubbleT and bubbleP functions to flashTQ and flashPQ). Solving for roots with PC-SAFT can be quite a challenge, as shown in this article.

samiit commented 4 years ago

Thanks. Just another question still. Does you existing API also offer access to first and second derivatives? In that case I don't have to bother with the Python implementation.

zmeri commented 4 years ago

Only the first derivative with respect to temperature is currently implemented: https://pcsaft.readthedocs.io/en/latest/functions/pcsaft.pcsaft_dadt.html. The first derivative with respect to density is also calculated as part of calculating the compressibility or pressure (so pcsaft_Z), but there is not a separate function for it. The second derivatives are not implemented.

samiit commented 4 years ago

Would it be possible to include second derivatives; and for more than just temperature? If you can direct me to the place where it should be implemented in the C++ code, I can also try to contribute. Thanks for your great work.

zmeri commented 4 years ago

I currently am not able to add the derivatives myself. I found it takes a significant amount of time to add a new derivative, and other projects are demanding my time. If you would like to, you can add it yourself. The main thing is to create a new function for the derivative. You can use the existing temperature derivative function as an example. You would also need to add a function to solve for the appropriate derivative of Xa (a parameter in the association term). You can use an existing Xa derivative function as an example.

zmeri commented 4 years ago

@samiit I'm going to go ahead and close this issue now because I think we resolved your original question.

samiit commented 4 years ago

Thanks Zach!