diff --git a/src/AbstractState.cpp b/src/AbstractState.cpp index 93febc6e..60714a1f 100644 --- a/src/AbstractState.cpp +++ b/src/AbstractState.cpp @@ -187,6 +187,14 @@ double AbstractState::trivial_keyed_output(int key) return this->rhomolar_critical(); case irhomass_critical: return this->rhomolar_critical()*molar_mass(); + case iODP: + return this->calc_ODP(); + case iGWP100: + return this->calc_GWP100(); + case iGWP20: + return this->calc_GWP20(); + case iGWP500: + return this->calc_GWP500(); default: throw ValueError(format("This input [%d: \"%s\"] is not valid for trivial_keyed_output",key,get_parameter_information(key,"short").c_str())); diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index 9126fa20..0ac44580 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -526,6 +526,51 @@ std::string HelmholtzEOSMixtureBackend::calc_name(void) return components[0]->name; } } +long double HelmholtzEOSMixtureBackend::calc_ODP(void) +{ + if (components.size() != 1){ + throw ValueError(format("For now, calc_ODP is only valid for pure and pseudo-pure fluids, %d components", components.size())); + } + else{ + long double v = components[0]->environment.ODP; + if (!ValidNumber(v) || v < 0){ throw ValueError(format("ODP value is not specified or invalid")); } + return v; + } +} +long double HelmholtzEOSMixtureBackend::calc_GWP20(void) +{ + if (components.size() != 1){ + throw ValueError(format("For now, calc_GWP20 is only valid for pure and pseudo-pure fluids, %d components", components.size())); + } + else{ + long double v = components[0]->environment.GWP20; + if (!ValidNumber(v) || v < 0){ throw ValueError(format("GWP20 value is not specified or invalid"));} + return v; + } +} +long double HelmholtzEOSMixtureBackend::calc_GWP100(void) +{ + if (components.size() != 1){ + throw ValueError(format("For now, calc_GWP100 is only valid for pure and pseudo-pure fluids, %d components", components.size())); + } + else{ + long double v = components[0]->environment.GWP100; + if (!ValidNumber(v) || v < 0){ throw ValueError(format("GWP100 value is not specified or invalid")); } + return v; + } +} +long double HelmholtzEOSMixtureBackend::calc_GWP500(void) +{ + if (components.size() != 1){ + throw ValueError(format("For now, calc_GWP500 is only valid for pure and pseudo-pure fluids, %d components", components.size())); + } + else{ + long double v = components[0]->environment.GWP500; + if (!ValidNumber(v) || v < 0){ throw ValueError(format("GWP500 value is not specified or invalid")); } + return v; + } +} + long double HelmholtzEOSMixtureBackend::calc_T_critical(void) { if (components.size() != 1){ diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h index d3f0bdf9..1655b413 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h @@ -63,6 +63,10 @@ public: long double calc_saturation_ancillary(parameters param, int Q, parameters given, double value); void calc_ssat_max(void); void calc_hsat_max(void); + long double calc_GWP20(); + long double calc_GWP500(); + long double calc_GWP100(); + long double calc_ODP(); const CoolProp::SimpleState &calc_state(const std::string &state); diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index 95957872..29c82b66 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -378,10 +378,15 @@ double _PropsSI(const std::string &Output, const std::string &Name1, double Prop State.reset(AbstractState::factory(backend, fluid_string)); // First check if it is a trivial input (critical/max parameters for instance) - if (is_valid_parameter(Output, iOutput) && is_trivial_parameter(iOutput)) + if (is_valid_parameter(Output, iOutput)) { - double val = State->trivial_keyed_output(iOutput); - return val; + if (is_trivial_parameter(iOutput)){ + double val = State->trivial_keyed_output(iOutput); + return val; + } + } + else{ + throw ValueError(format("Invalid output parameter [%s]",Output.c_str())); } parameters iName1 = get_parameter_index(Name1); @@ -442,19 +447,31 @@ double PropsSI(const char *Output, const char *Name1, double Prop1, const char * } double Props1SI(const std::string &FluidName, const std::string &Output) { - std::string _FluidName = FluidName, empty_string = "", _Output = Output; - double val1 = PropsSI(_FluidName, empty_string, 0, empty_string, 0, _Output); - if (!ValidNumber(val1)){ - // flush the error - set_error_string(""); - // Try with them flipped - val1 = PropsSI(_Output, empty_string, 0, empty_string, 0, _FluidName); - } - if (!ValidNumber(val1)){ - set_error_string(format("Unable to use inputs %s,%s in Props1SI (order doesn't matter)")); + std::string _FluidName = FluidName, empty_string = "", _Output = Output; + bool valid_fluid1 = is_valid_fluid_string(_FluidName); + bool valid_fluid2 = is_valid_fluid_string(_Output); + if (valid_fluid1 && valid_fluid2){ + set_error_string(format("Both inputs to Props1SI [%s,%s] are valid fluids", Output.c_str(), FluidName.c_str())); return _HUGE; } - return val1; + if (!valid_fluid1 && !valid_fluid2){ + set_error_string(format("Neither input to Props1SI [%s,%s] is a valid fluid", Output.c_str(), FluidName.c_str())); + return _HUGE; + } + if (!valid_fluid1 && valid_fluid2){ + // They are backwards, swap + std::swap(_Output, _FluidName); + } + + // First input is the fluid, second input is the input parameter + double val1 = PropsSI(_Output, "", 0, "", 0, _FluidName); + if (!ValidNumber(val1)){ + set_error_string(format("Unable to use input parameter [%s] in Props1SI for fluid %s; error was %s", _Output.c_str(), _FluidName.c_str(), get_global_param_string("errstring").c_str())); + return _HUGE; + } + else{ + return val1; + } } double PropsSI(const std::string &Output, const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &Ref) { diff --git a/src/DataStructures.cpp b/src/DataStructures.cpp index a85e81d0..d0974ab0 100644 --- a/src/DataStructures.cpp +++ b/src/DataStructures.cpp @@ -40,13 +40,13 @@ parameter_info parameter_info_list[] = { parameter_info(iCvmass, "Cvmass","O","J/kg/K","Mass specific constant volume specific heat",false), parameter_info(iCp0molar, "Cp0molar","O","J/mol/K","Ideal gas molar specific constant presssure specific heat",false), parameter_info(iCp0mass, "Cp0mass","O","J/kg/K","Ideal gas mass specific constant presssure specific heat",false), - parameter_info(iGWP20, "GWP20","O","-","20-year gobal warming potential",false), - parameter_info(iGWP100, "GWP100","O","-","100-year gobal warming potential",false), - parameter_info(iGWP500, "GWP500","O","-","500-year gobal warming potential",false), - parameter_info(iFH, "FH","O","-","Flammability hazard",false), - parameter_info(iHH, "HH","O","-","Health hazard",false), - parameter_info(iPH, "PH","O","-","Physical hazard",false), - parameter_info(iODP, "ODP","O","-","Ozone depletion potential",false), + parameter_info(iGWP20, "GWP20","O","-","20-year gobal warming potential",true), + parameter_info(iGWP100, "GWP100","O","-","100-year gobal warming potential",true), + parameter_info(iGWP500, "GWP500","O","-","500-year gobal warming potential",true), + parameter_info(iFH, "FH","O","-","Flammability hazard",true), + parameter_info(iHH, "HH","O","-","Health hazard",true), + parameter_info(iPH, "PH","O","-","Physical hazard",true), + parameter_info(iODP, "ODP","O","-","Ozone depletion potential",true), parameter_info(iBvirial, "Bvirial","O","-","Second virial coefficient",false), parameter_info(iCvirial, "Cvirial","O","-","Third virial coefficient",false), parameter_info(idBvirial_dT, "dBvirial_dT","O","-","Derivative of second virial coefficient with respect to T",false), @@ -119,6 +119,7 @@ public: index_map.insert(std::pair("V", iviscosity)); index_map.insert(std::pair("L", iconductivity)); index_map.insert(std::pair("pcrit", iP_critical)); + index_map.insert(std::pair("Pcrit", iP_critical)); index_map.insert(std::pair("Tcrit", iT_critical)); index_map.insert(std::pair("Ttriple", iT_triple)); index_map.insert(std::pair("ptriple", iP_triple));