From ce5d8a919fabd538c5ecc118eacdb5472b0dd127 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Sun, 10 Aug 2014 21:39:09 +0200 Subject: [PATCH] D(T,P) falls back to Brent if can't get good solution with other solvers A guaranteed solution if the solution domain made wide enough Signed-off-by: Ian Bell --- src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index 807814c7..9ac6bfdb 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -1497,7 +1497,7 @@ long double HelmholtzEOSMixtureBackend::solver_rho_Tp(long double T, long double catch(std::exception &) { try{ - // Next we try with Secant method + // Next we try with Secant method shooting off from the guess value double rhomolar = Secant(resid, rhomolar_guess, 0.0001*rhomolar_guess, 1e-8, 100, errstring); if (!ValidNumber(rhomolar)){throw ValueError();} return rhomolar; @@ -1505,7 +1505,10 @@ long double HelmholtzEOSMixtureBackend::solver_rho_Tp(long double T, long double catch(std::exception &) { try{ - Secant(resid, rhomolar_guess, 0.0001*rhomolar_guess, 1e-8, 100, errstring); + // Next we try with a Brent method bounded solver since the function is 1-1 + double rhomolar = Brent(resid, 0.1*rhomolar_guess, 2*rhomolar_guess,DBL_EPSILON,1e-8,100,errstring); + if (!ValidNumber(rhomolar)){throw ValueError();} + return rhomolar; } catch(...){