-
Notifications
You must be signed in to change notification settings - Fork 47
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
bubble_pressure with SAFTgammaMie #52
Comments
Hi! |
i think i fixed it. i'm waiting for the tests to pass and then release a new version as soon as possible |
Thanks for this! I have run into similar issues with, e.g., gibbs_free_energy, but I will wait to see if the update fixes these too. I just want to re-iterate how wonderful Clapeyron.jl is! Even just for using Cubic EOS's, it's a wonderfully simple & efficient interface. I plan to use it for a long time to come. Regarding multicomponent flash algorithms: to understand the interface, and to answer some of my own research questions, I have now implemented a simple multicomponent, multiphase, isothermal-isobaric flash algorithm, which uses differential evolution (DE) algorithms from BlackBoxOptim.jl to find the global minima of the Gibbs Free Energy, calculated using Clapeyron.jl (c.f. 10.1142/9789813207523_0007). I have tested it on several 2- and 3-species cases, and am yet to see it fail. DE flash calculations will never be as fast as specialized codes, but I have found them to be extremely robust, and also very simple conceptually. The algorithm takes around 10000 function evaluations to converge, which takes about 0.1-5 seconds depending on the underlying EOS. The one downside is the user must specify the number of phases - this is not worked out automatically at present. If you specify too many phases, the code predicts multiple phases with equal composition, and if you specify too few, the predictions are unphysical. You can iteratively solve the code, increasing the number of phases by 1 each time, until the Gibbs Free Energy stops decreasing; this process could probably be automated if desired. Would there be interest in incorporating a DE flash algorithm into Clapeyron.jl? I'd be happy to formulate it as a pull request if so. |
Hi there! Great to hear that you plan to use Clapeyron in your future work! I hope these fixes will help you with these issues! With regards to the multi-component flash algorithms, we would absolutely be interested in incorporating a DE flash algorithm into Clapeyron.jl! A flash algorithm is really the only missing component to our package (aside from perhaps parameter estimation modules); we've been trying to find ways to implement either the RAND and HELD algorithms; the issue is finding the time to do these things... if you are willing and able, we would be extremely grateful if you shared your implement with us! The speeds you mention are consistent with the values for a (very) basic RR implementation I've developed which is in no way robust... any improvement is more than welcome! |
Great. I don't have a lot of experience with pull requests, but I will try to educate myself. :) If I can't find the time in the next week, I could also send a Jupyter notebook with the code/tests. |
And yes, I can see HELD being a pain to implement (though in the long run, it is probably better than a DE implementation...) |
If you need any help navigating around GitHub / PR, feel free to dm us on Zulip! |
Sorry to bother about this again, but I'm still having some issues with SAFTgammaMie. In particular, mixtures of water and various species (e.g. methanol, CO2, ethanol) give NaN errors for most functions, especially at higher pressures (e.g. 100 bar) and when the water fraction is >85%. For example:
This prints various NaN's. If we replace SAFTgammaMie with other state functions (PR, PCSAFT) everything works well. |
This is just an example of how much tuning we have left to do... in short, the reason this is happening is because our initial guess for the volume is too small. The one we provide is generally ok for lower pressures. But, at higher pressures, we need to make the initial guess bigger. You can do this from the outside by just adding:
I've tried this for your case and it works. N.B. This is also an example of a feature we hope to take more-advantage of: extensible methods. We hope, if users run into similar issues in the future, it will be easy enough for them to modify the underlying methods to suit their needs. |
Weird, it seems that the volume solver is failing for the liquid phase, can you try using |
As a stopgap, you can do: v = volume... #obtaining the volume from the specified pressure, by modifying the function or using the underlying solver
prop =VT_entropy(v, T, x) #calling the property with a VTn specification
|
Thanks for the responses. For your information, there are a few edge-cases where no initial guess seems to work with the solver. I've given an example below for water-methanol at 25C and 50 bar. I'm not sure why the solver fails for this case. I'm hesitant to guess a volume in any other way, as I suspect in condensed phases most properties are strongly dependent on the volume. However, for my own application the work-around of trying a few initial guesses until you get convergence seems to work most of the time. Thanks!
|
After a bit of troubleshooting, I think I found the culprit. This is a general problem for most systems with a lot of association going on. Problems tend to occur when we exceed the maximum number of iterations required for the association fractions in SAFT-gamma Mie to converge (500). For my personal uses, I've raised that to 10000 (way over kill, but I'm dealing with systems which have a lot of association). @longemen3000 , should we raise this limit in the default code? I've found increasing it to 1000 iterations is sufficient to deal with the above problem. @denbigh For a quick fix, just paste this code at the beginning of your script (it increases the max iterations to 1000)::
Sorry if it makes your code look ugly... this will hopefully only be a temporary fix. |
Fantastic, thanks! I just want to confirm that with both changes (change initial volume guess to 2*lb_volume, and increase iterations to 1000) everything works, and I get no NaN results for a broad sweep of conditions. |
ok, i'm gonna bump the iteration limit, increase the x0_volume_liquid on SAFTgammaMie, and release a new version |
First things first - thank you so much for your wonderful work on this package! I am currently doing research on transport phenomena in high pressure ternary mixtures of CO2/water/cosolvent[methanol/acetonitrile/etc.] and the existence of a simple to use group contribution SAFT implementation in Julia, for prediction of fugacity coefficients, and hopefully for analysis of LLE, is a godsend. I have some interest/background/time to work on multicomponent flash calculations; if there are any algorithms which you are looking to implement, I'd be open to lending a hand.
I also have a brief technical question. I have been playing around with Clapeyron, and I have noticed a potential issue with bubble_pressure calculations when using SAFTgammaMie.
The following code for calculating the bubble pressure works well using PCSAFT:
It also works well with SAFTVRMie. However, with SAFTgammaMie:
I get an error:
I believe this may be traced back to lines 12 and 13 of bubble_pressure.jl, which require splitting the mixture model into pure models:
I noticed that split_model appears to split SAFTgammaMie mixtures into some kind of composite object with type:
whereas if you use split_model on, say, SAFTVRMie, you get objects of a simpler type:
Do you know if this is a bug in either split_model or in the SAFTgammaMie implementation? It would be useful to do bubble_pressure calculations using SAFTgammaMie.
The text was updated successfully, but these errors were encountered: