From 52650406afd48336ec6ce98d5a983b5b1be81ecb Mon Sep 17 00:00:00 2001 From: Ian Bell <ian.bell@nist.gov> Date: Thu, 8 Apr 2021 10:44:37 -0400 Subject: [PATCH] Allow iteration limit to be set, rename method See #2 --- include/teqp/algorithms/VLE.hpp | 7 ++++--- src/tests/catch_tests.cxx | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/teqp/algorithms/VLE.hpp b/include/teqp/algorithms/VLE.hpp index 2514d7d..9035824 100644 --- a/include/teqp/algorithms/VLE.hpp +++ b/include/teqp/algorithms/VLE.hpp @@ -63,11 +63,11 @@ public: }; template<typename Residual, typename Scalar> -auto do_pure_VLE(Residual &resid, Scalar T, Scalar rhoL, Scalar rhoV) { +auto do_pure_VLE_T(Residual &resid, Scalar T, Scalar rhoL, Scalar rhoV, int maxiter) { auto rhovec = (Eigen::ArrayXd(2) << rhoL, rhoV).finished(); auto r0 = resid.call(rhovec); auto J = resid.Jacobian(rhovec); - for (int iter = 0; iter < 100; ++iter){ + for (int iter = 0; iter < maxiter; ++iter){ if (iter > 0) { r0 = resid.call(rhovec); J = resid.Jacobian(rhovec); @@ -76,11 +76,12 @@ auto do_pure_VLE(Residual &resid, Scalar T, Scalar rhoL, Scalar rhoV) { auto rhovecnew = (rhovec + v).eval(); // If the solution has stopped improving, stop. The change in rhovec is equal to v in infinite precision, but - // not when finite precision is involved, so use the minimum non-denormal float as the determination of whether + // not when finite precision is involved, use the minimum non-denormal float as the determination of whether // the values are done changing if (((rhovecnew - rhovec).cwiseAbs() < std::numeric_limits<Scalar>::min()).all()) { break; } rhovec += v; } + return std::make_tuple(rhovec[0], rhovec[1]); } \ No newline at end of file diff --git a/src/tests/catch_tests.cxx b/src/tests/catch_tests.cxx index e6999ab..ee9b009 100644 --- a/src/tests/catch_tests.cxx +++ b/src/tests/catch_tests.cxx @@ -243,5 +243,5 @@ TEST_CASE("Test pure VLE", "") { auto r1 = resid.call(rhovec1); CHECK((r0.cwiseAbs() > r1.cwiseAbs()).eval().all()); - do_pure_VLE(resid, T, 22834.056386882046, 1025.106554560764); + do_pure_VLE_T(resid, T, 22834.056386882046, 1025.106554560764, 20); } \ No newline at end of file -- GitLab