From de465e1cf6755d23231f289c6f7c24fd58eca465 Mon Sep 17 00:00:00 2001 From: Jeff Henning Date: Wed, 19 Dec 2018 22:55:42 -0500 Subject: [PATCH] Disambiguate IF97 Fluid Names - Water only (#1770) --- src/AbstractState.cpp | 16 ++++++++++++++-- wrappers/MathCAD/CoolPropMathcad.cpp | 26 +++++++++++++++++++------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/AbstractState.cpp b/src/AbstractState.cpp index f7926aa2..122b5828 100644 --- a/src/AbstractState.cpp +++ b/src/AbstractState.cpp @@ -54,8 +54,20 @@ void register_backend(const backend_families &bf, shared_ptr &fluid_names){ - return new IF97Backend(); + AbstractState * get_AbstractState(const std::vector &fluid_names) { + if (fluid_names.size() == 1) { // Check that fluid_names[0] has only one component + std::string str = fluid_names[0]; // Check that the fluid name is an alias for "Water" + if ((upper(str) == "WATER") || + (upper(str) == "H2O")) { + return new IF97Backend(); + } + else { + throw ValueError(format("The IF97 backend returns Water props only; fluid name [%s] not allowed", fluid_names[0].c_str())); + } + } + else { + throw ValueError(format("The IF97 backend does not support mixtures, only Water")); + }; }; } ; // This static initialization will cause the generator to register diff --git a/wrappers/MathCAD/CoolPropMathcad.cpp b/wrappers/MathCAD/CoolPropMathcad.cpp index d31f18b5..837929bb 100644 --- a/wrappers/MathCAD/CoolPropMathcad.cpp +++ b/wrappers/MathCAD/CoolPropMathcad.cpp @@ -22,7 +22,7 @@ namespace CoolProp { } enum EC { MUST_BE_REAL = 1, INSUFFICIENT_MEMORY, INTERRUPTED, // Mathcad Error Codes - BAD_FLUID, BAD_PARAMETER, BAD_PHASE, // CoolProp Error Codes + BAD_FLUID, BAD_IF97_FLUID, BAD_PARAMETER, BAD_PHASE, // CoolProp Error Codes ONLY_ONE_PHASE_SPEC, BAD_REF, NON_TRIVIAL, NO_REFPROP, NOT_AVAIL, BAD_INPUT_PAIR, BAD_QUAL, TWO_PHASE, NON_TWO_PHASE, T_OUT_OF_RANGE, P_OUT_OF_RANGE, @@ -40,6 +40,7 @@ enum EC { MUST_BE_REAL = 1, INSUFFICIENT_MEMORY, INTERRUPTED, // Mathcad E "Insufficient Memory", "Argument must be real", "Invalid Fluid String", + "IF97 Backend supports pure water only", "Invalid Parameter String", "Invalid Phase String", "Only one input key phase specification allowed", @@ -191,17 +192,26 @@ enum EC { MUST_BE_REAL = 1, INSUFFICIENT_MEMORY, INTERRUPTED, // Mathcad E std::string emsg = CoolProp::get_global_param_string("errstring"); CoolProp::set_error_string(emsg); // reset error string so Mathcad can retrieve it if (emsg.find("valid fluid")!=std::string::npos) { - if (emsg.find("Neither input")!=std::string::npos) - if (emsg.find("REFPROP")!=std::string::npos) { + if (emsg.find("Neither input") != std::string::npos) { + if (emsg.find("REFPROP") != std::string::npos) { // Fluid can be in either parameter location, find out which. // It will be in brackets in the error message. - if (FluidString.find("REFPROP")!=std::string::npos) + if (FluidString.find("REFPROP") != std::string::npos) errPos = 1; // [REFPROP::???] is in Fluid->str, i.e. position 1 else errPos = 2; // [REFPROP::???] is in PropName->str, i.e. position 2 - return MAKELRESULT(NO_REFPROP,errPos); - } else - return MAKELRESULT(BAD_FLUID,1); + return MAKELRESULT(BAD_FLUID, errPos); + } + else if (emsg.find("IF97") != std::string::npos) { + if (FluidString.find("IF97") != std::string::npos) + errPos = 1; // [IF97::???] is in Fluid->str, i.e. position 1 + else + errPos = 2; // [IF97::???] is in PropName-str, i.e. position 2 + return MAKELRESULT(BAD_IF97_FLUID, errPos); + } + else + return MAKELRESULT(BAD_FLUID, 1); + } else // "Both inputs" return MAKELRESULT(BAD_PARAMETER,2); } else if (emsg.find("Unable to use")!=std::string::npos) { @@ -306,6 +316,8 @@ enum EC { MUST_BE_REAL = 1, INSUFFICIENT_MEMORY, INTERRUPTED, // Mathcad E return MAKELRESULT(NO_REFPROP,6); else return MAKELRESULT(BAD_FLUID,6); + } else if (emsg.find("IF97") != std::string::npos) { + return MAKELRESULT(BAD_IF97_FLUID, 6); } else return MAKELRESULT(BAD_FLUID,6); } else if (emsg.find("Temperature")!=std::string::npos) {