From a3f0a7f83a9b572dd4f3664c8eb3f214afae9bfb Mon Sep 17 00:00:00 2001
From: Ian Bell <ian.bell@nist.gov>
Date: Wed, 24 Aug 2022 11:16:17 -0400
Subject: [PATCH] Restructure the flag management for mix TP VLE

---
 include/teqp/algorithms/VLE.hpp | 9 +++++----
 interface/pybind11_wrapper.cpp  | 2 ++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/teqp/algorithms/VLE.hpp b/include/teqp/algorithms/VLE.hpp
index bb81454..983e1bb 100644
--- a/include/teqp/algorithms/VLE.hpp
+++ b/include/teqp/algorithms/VLE.hpp
@@ -167,7 +167,7 @@ auto pure_VLE_T(const Model& model, Scalar T, Scalar rhoL, Scalar rhoV, int maxi
     return do_pure_VLE_T(res, rhoL, rhoV, maxiter);
 }
 
-enum class VLE_return_code { unset, xtol_satisfied, functol_satisfied, maxiter_met, notfinite_step };
+enum class VLE_return_code { unset, xtol_satisfied, functol_satisfied, maxfev_met, maxiter_met, notfinite_step };
 
 /***
 * \brief Do a vapor-liquid phase equilibrium problem for a mixture (binary only for now) with mole fractions specified in the liquid phase
@@ -310,7 +310,7 @@ struct MixVLEReturn {
     std::string message;
     Eigen::ArrayXd rhovecL, rhovecV;
     VLE_return_code return_code;
-    int num_iter;
+    int num_iter, num_fev;
     double T;
     Eigen::ArrayXd r;
 };
@@ -439,9 +439,9 @@ auto mix_VLE_Tp(const Model& model, Scalar T, Scalar pgiven, const Vector& rhove
         case e::RelativeErrorTooSmall:
             return_code = VLE_return_code::functol_satisfied;
         case e::TooManyFunctionEvaluation:
-            return_code = VLE_return_code::maxiter_met;
+            return_code = VLE_return_code::maxfev_met;
         case e::TolTooSmall:
-            return_code = VLE_return_code::xtol_satisfied
+            return_code = VLE_return_code::xtol_satisfied;
             //NotMakingProgressJacobian = 4,
             //NotMakingProgressIterations = 5,
         default:
@@ -454,6 +454,7 @@ auto mix_VLE_Tp(const Model& model, Scalar T, Scalar pgiven, const Vector& rhove
     MixVLEReturn r;
     r.return_code = return_code;
     r.num_iter = solver.iter;
+    r.num_fev = solver.nfev;
     r.r = final_r;
     r.success = (info == e::RelativeErrorTooSmall || info == e::TolTooSmall);
     r.rhovecL = rhovecL;
diff --git a/interface/pybind11_wrapper.cpp b/interface/pybind11_wrapper.cpp
index fef51a7..6cd0449 100644
--- a/interface/pybind11_wrapper.cpp
+++ b/interface/pybind11_wrapper.cpp
@@ -141,6 +141,7 @@ void init_teqp(py::module& m) {
         .value("xtol_satisfied", VLE_return_code::xtol_satisfied)
         .value("functol_satisfied", VLE_return_code::functol_satisfied)
         .value("maxiter_met", VLE_return_code::maxiter_met)
+        .value("maxfev_met", VLE_return_code::maxfev_met)
         .value("notfinite_step", VLE_return_code::notfinite_step)
         ;
 
@@ -153,6 +154,7 @@ void init_teqp(py::module& m) {
         .def_readonly("return_code", &MixVLEReturn::return_code)
         .def_readonly("num_iter", &MixVLEReturn::num_iter)
         .def_readonly("T", &MixVLEReturn::T)
+        .def_readonly("num_fev", &MixVLEReturn::num_fev)
         .def_readonly("r", &MixVLEReturn::r)
         ;
 
-- 
GitLab