diff --git a/include/teqp/models/cubicsuperancillary.hpp b/include/teqp/models/cubicsuperancillary.hpp index 6c6ecbfda0194d4eba133ff4ca0a30e3ac4f1d20..d4c556d57a0e36749050c0afefb3694341f29c45 100644 --- a/include/teqp/models/cubicsuperancillary.hpp +++ b/include/teqp/models/cubicsuperancillary.hpp @@ -50,6 +50,13 @@ public: /// Evaluate the SuperAncillary double y(double x) const{ + // First check whether the input is possible + if (x < exps[0].xmin) { + throw std::invalid_argument("Ttilde (" + std::to_string(x) + ") is below the minimum of " + std::to_string(exps[0].xmin)); + } + if (x > exps.back().xmax) { + throw std::invalid_argument("Ttilde (" + std::to_string(x) + ") is above the maximum of " + std::to_string(exps.back().xmax)); + } // Bisection to find the expansion // we need auto i = get_index(x); diff --git a/src/tests/catch_test_cubics.cxx b/src/tests/catch_test_cubics.cxx index 737f9208dae1b4f3db69cb7cea42a106ad1fd357..6d10711cd9197872a352df6c3fb35a34239b8d24 100644 --- a/src/tests/catch_test_cubics.cxx +++ b/src/tests/catch_test_cubics.cxx @@ -40,6 +40,14 @@ TEST_CASE("Check calling superancillary curves", "[cubic][superanc]") auto [rhoL, rhoV] = model.superanc_rhoLV(130.0); CHECK(rhoL > rhoV); } + SECTION("PR super large temp") { + auto model = canonical_PR(Tc_K, pc_Pa, acentric); + CHECK_THROWS(model.superanc_rhoLV(1.3e6)); + } + SECTION("PR super small temp") { + auto model = canonical_PR(Tc_K, pc_Pa, acentric); + CHECK_THROWS(model.superanc_rhoLV(1.3e-10)); + } SECTION("SRK") { auto model = canonical_SRK(Tc_K, pc_Pa, acentric); auto [rhoL, rhoV] = model.superanc_rhoLV(130.0);