From ed1d7a41a64cb92ef945b506313c2b571e4e4a61 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Thu, 11 Sep 2014 13:00:53 +0200 Subject: [PATCH] Fixes to Mixture Parameters If F_ij is zero, put in a dummy departure function If pair is invalid, throw error rather than crash Signed-off-by: Ian Bell --- src/Backends/Helmholtz/MixtureParameters.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Backends/Helmholtz/MixtureParameters.cpp b/src/Backends/Helmholtz/MixtureParameters.cpp index 33f31ae6..5bc70736 100644 --- a/src/Backends/Helmholtz/MixtureParameters.cpp +++ b/src/Backends/Helmholtz/MixtureParameters.cpp @@ -217,6 +217,11 @@ void MixtureParameters::set_mixture_parameters(HelmholtzEOSMixtureBackend &HEOS) // *************************************************** // Reducing parameters for binary pair // *************************************************** + + if (mixturebinarypairlibrary.binary_pair_map.find(CAS) == mixturebinarypairlibrary.binary_pair_map.end()) + { + throw ValueError(format("Could not match the binary pair [%s,%s] - for now this is an error.", CAS[0].c_str(), CAS[1].c_str())); + } // Get a reference to the first matching binary pair in the dictionary Dictionary &dict_red = mixturebinarypairlibrary.binary_pair_map[CAS][0]; @@ -249,6 +254,16 @@ void MixtureParameters::set_mixture_parameters(HelmholtzEOSMixtureBackend &HEOS) // Departure functions used in excess term // *************************************************** + // Set the scaling factor F for the excess term + HEOS.Excess.F[i][j] = dict_red.get_number("F"); + + if (std::abs(HEOS.Excess.F[i][j]) < DBL_EPSILON){ + // Empty departure function that will just return 0 + std::vector n(1,0), d(1,1), t(1,1), l(1,0); + HEOS.Excess.DepartureFunctionMatrix[i][j].reset(new ExponentialDepartureFunction(n,d,t,l)); + continue; + } + // Get the name of the departure function to be used for this binary pair std::string Name = CoolProp::get_reducing_function_name(components[i]->CAS, components[j]->CAS); @@ -260,9 +275,6 @@ void MixtureParameters::set_mixture_parameters(HelmholtzEOSMixtureBackend &HEOS) std::vector d = dict_dep.get_double_vector("d"); std::vector t = dict_dep.get_double_vector("t"); - // Set the scaling factor F for the excess term - HEOS.Excess.F[i][j] = dict_red.get_number("F"); - std::string type_dep = dict_dep.get_string("type"); if (!type_dep.compare("GERG-2008")){