Open YouHyin opened 6 months ago
Dear YouHyin,
Thank you very much for your question! The fact you are testing sgtpy
with very challenging mixtures really helps me to keep improving the code. So there are two things that I realized based on your problem:
nan
is not obtained from a 1/x division, but instead, it is obtained because the density solver failed to find a solution. By default, the density solver uses the previous solution to start the iteration; however, this mixture presents two local minima, and the solver jumps between them; hence, at this point, the solution of the previous solution is very off and makes the solver fail. I added a few extra lines that check if there is a nan
either in the density solver solution and if that's the case, the calculation is repeated without relying on any initial guess (I have a routine to automatically generate an initial guess, it is usually more expensive to run than using the previous solution as an initial guess).See some solutions with the above (I'm preventing the ASS step because is jumping between solutions)
Considering AEEA in the vapor phase:
sol=flash(x0, y0, 'LV', z, T, P, eos, minimization_approach='helmholtz',
not_in_x_list=[], not_in_y_list=[], full_output=True, nacc=0) # Set the amount of N2 in the liquid phase to zero
T: 313.15
P: 101000
beta: 0.8175545263742379
error: 0.025054419352129573
iter: 75
X: array([1.47176656e-04, 3.79806416e-02, 6.86335850e-02, 8.93238597e-01])
v1: 2.4101360142835413e-05
Xass1: array([4.47088888e-02, 9.72595681e-03, 1.74872530e-01, 6.97966918e-03,
3.66694469e-01, 2.86091422e-05, 6.01433402e-01, 4.42699813e-02,
8.89444820e-02, 9.45413699e-02])
state1: 'L'
Y: array([8.00558638e-01, 1.38049560e-01, 3.91261490e-10, 6.13918012e-02])
v2: 0.025721154626608105
Xass2: array([0.99952635, 1. , 0.99783144, 0.05341241, 0.99920981,
0.00156895, 0.99981808, 0.99036564, 0.99641074, 0.9958782 ])
state2: 'V'
method: 'Helmholtz_minimization'
Without considering AEEA in the vapor phase:
sol=flash(x0, y0, 'LV', z, T, P, eos, minimization_approach='helmholtz',
not_in_x_list=[], not_in_y_list=[2], full_output=True, nacc=0) # Set the amount of N2 in the liquid phase to zero
T: 313.15
P: 101000
beta: 0.8175545274048039
error: 2.800413437049716e-08
iter: 27
X: array([1.47176607e-04, 3.79806427e-02, 6.86335872e-02, 8.93238594e-01])
v1: 2.4101360329613608e-05
Xass1: array([4.47088873e-02, 9.72595645e-03, 1.74872531e-01, 6.97966927e-03,
3.66694470e-01, 2.86091425e-05, 6.01433400e-01, 4.42699816e-02,
8.89444821e-02, 9.45413704e-02])
state1: 'L'
Y: array([0.80055864, 0.13804956, 0. , 0.0613918 ])
v2: 0.02572115464609747
Xass2: array([0.99952635, 1. , 0.99783144, 0.05341241, 0.99920981,
0.00156895, 0.99981808, 0.99036564, 0.99641074, 0.9958782 ])
state2: 'V'
method: 'Helmholtz_minimization'
I'll update a new version that checks if the density solver converged correctly shortly.
Edit: I just updated a new version to pypi. For now, I only uploaded a precompiled version for OSX; soon, I'll upload a compiled version for Windows.
Regards, Gustavo
First of all, I'm really sorry for the late response. Thank you so much for your response and updating the package so quickly. I'll refer to your answer and proceed with the flash calculation. Thanks to you, it was very helpful. Thank you always.
Best whises! YouHyin
Hello Gustavo!
Your updates to sgtpy have been a great help in my research. Thank you very much. The flash calculations are converging much better than before, but I have a problem.
When I run this code, the liquid and vapor mole fractions come out as nan. I think that during the flash calculation process, there might be an formula in the form of 1/x, and x is becoming 0, leading to nan values. I attempted to debug and change this expression to the form 1/(x+10^-8) to prevent it from diverging to infinity, but I couldn't find the exact expression.
Can you give me any advice on how to change the formula in the flash calculation process so that the nan value does not come out? Thank as always for your help. Best wish!