Skip to content
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

Root finding failed #161

Open
zplizzi opened this issue Aug 16, 2019 · 4 comments
Open

Root finding failed #161

zplizzi opened this issue Aug 16, 2019 · 4 comments

Comments

@zplizzi
Copy link

zplizzi commented Aug 16, 2019

When trying to find the equilibria of the following system, I get "root finding failed" and "too much of at least one component" warnings.

eqsys = EqSystem.from_string("""

CO2 + H2O = H2CO3; 1.7e-3
H2CO3 = H+ + HCO3-; 10**-6.3
HCO3- = H+ + CO3-2; 10**-10.3

HPO4-2 + H2O = H2PO4- + OH-; 10**-6.79
Na2HPO4 = 2 Na+ + HPO4-2; 10**5
KH2PO4 = K+ + H2PO4-; 10**5

HCl = H+ + Cl-; 10**5.9
CH3CO2H = CH3CO2- + H+; 10**-4.756

H2O = H+ + OH-; 10**-14
""")


arr, info, sane = eqsys.root(defaultdict(float, \
    {'H2O': 55.4,
     'CO2': 3, 
     "KH2PO4": 0.0422 * 1,
     "Na2HPO4": 0.0578 * 1,
     "HCl": 0,
     "CH3CO2H": 0.0,
     "CH3CO2-": 0
    }))
conc = dict(zip(eqsys.substances, arr))
print(conc)

Even with somewhat simplified versions of this system, I still get the errors at times.

@bjodah
Copy link
Owner

bjodah commented Aug 16, 2019

Hi, it was a while since I was solving equilibria, but I remember that the solvers provided by scipy had trouble with convergence quite often. I tried applying various transformations with some success, but I think using another solver is probably a better solution long term, I started looking into using IPOPT (cyipopt provides Python bindings), but I got busy with other work.

For trying variable transformations, I have an example notebook (ammonical cupric solution), if you want to try IPOPT there will be some development that needs to be done, I won't have time to do this myself in the foreseeable future, but if you're interested in trying that avenue, let me know and I'll try to help out.

Either way, you'll probably want to indicate that some of these species belong to another phase (it's solubility products for the potassium and sodium salts I presume?). I seem to remember that the default parser respected the (s) suffix?

@zplizzi
Copy link
Author

zplizzi commented Aug 17, 2019

No worries, I probably don't have the time/skill to dig into improving the solver. I'll just work with what you have here - this library is awesome overall!

@bjodah
Copy link
Owner

bjodah commented Aug 17, 2019

I'm happy to hear that you are finding the library useful! And I appreciate that you're opening issues as well, it will make it easier to prioritize what to improve when I find some spare time.

@bjodah
Copy link
Owner

bjodah commented Apr 29, 2021

Just saw that openturns wraps Ipopt in their python wrapper, leaving a link here for future reference:
http://openturns.github.io/openturns/latest/user_manual/_generated/openturns.Ipopt.html#ipopt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants