Merge branch 'master' into tabular

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2015-03-02 20:20:51 -07:00
36 changed files with 954 additions and 761 deletions

View File

@@ -72,31 +72,30 @@ bool has_backend_in_string(const std::string &fluid_string, std::size_t &i)
return i != std::string::npos;
}
void extract_backend(const std::string &fluid_string, std::string &backend, std::string &fluid)
void extract_backend(std::string fluid_string, std::string &backend, std::string &fluid)
{
std::size_t i;
std::string _fluid_string = fluid_string;
// For backwards compatibility reasons, if "REFPROP-" or "REFPROP-MIX:" start
// the fluid_string, replace them with "REFPROP::"
if (_fluid_string.find("REFPROP-MIX:") == 0)
if (fluid_string.find("REFPROP-MIX:") == 0)
{
_fluid_string.replace(0, 12, "REFPROP::");
fluid_string.replace(0, 12, "REFPROP::");
}
if (_fluid_string.find("REFPROP-") == 0)
if (fluid_string.find("REFPROP-") == 0)
{
_fluid_string.replace(0, 8, "REFPROP::");
fluid_string.replace(0, 8, "REFPROP::");
}
if (has_backend_in_string(_fluid_string, i))
if (has_backend_in_string(fluid_string, i))
{
// Part without the ::
backend = _fluid_string.substr(0, i);
backend = fluid_string.substr(0, i);
// Fluid name after the ::
fluid = _fluid_string.substr(i+2);
fluid = fluid_string.substr(i+2);
}
else
{
backend = "?";
fluid = _fluid_string;
fluid = fluid_string;
}
if (get_debug_level()>10) std::cout << format("%s:%d: backend extracted. backend: %s. fluid: %s\n",__FILE__,__LINE__, backend.c_str(), fluid.c_str());
}
@@ -124,7 +123,7 @@ std::string extract_fractions(const std::string &fluid_string, std::vector<doubl
for (std::size_t i = 0; i < pairs.size(); ++i)
{
std::string fluid = pairs[i];
const std::string &fluid = pairs[i];
// Must end with ']'
if (fluid[fluid.size()-1] != ']')
@@ -137,7 +136,7 @@ std::string extract_fractions(const std::string &fluid_string, std::vector<doubl
// Convert fraction to a double
char *pEnd;
std::string &name = name_fraction[0], &fraction = name_fraction[1];
const std::string &name = name_fraction[0], &fraction = name_fraction[1];
double f = strtod(fraction.c_str(), &pEnd);
// If pEnd points to the last character in the string, it wasn't able to do the conversion
@@ -333,7 +332,7 @@ void _PropsSI_outputs(shared_ptr<AbstractState> &State,
State->update(input_pair, in1[i], in2[i]);
}
}
catch(std::exception &){
catch(...){
if (one_input_one_output){IO.clear(); throw;} // Re-raise the exception since we want to bubble the error
// All the outputs are filled with _HUGE; go to next input
for (std::size_t j = 0; j < IO[i].size(); ++j){ IO[i][j] = _HUGE; }
@@ -369,7 +368,7 @@ void _PropsSI_outputs(shared_ptr<AbstractState> &State,
// At least one has succeeded
success = true;
}
catch(std::exception &){
catch(...){
if (one_input_one_output){IO.clear(); throw;} // Re-raise the exception since we want to bubble the error
IO[i][j] = _HUGE;
}
@@ -463,7 +462,6 @@ std::vector<std::vector<double> > PropsSImulti(const std::vector<std::string> &O
}
double PropsSI(const std::string &Output, const std::string &Name1, double Prop1, const std::string &Name2, double Prop2, const std::string &Ref)
{
std::string backend, fluid; std::vector<double> fractions(1,1.0);
#if !defined(NO_ERROR_CATCHING)
try{
#endif
@@ -472,11 +470,11 @@ double PropsSI(const std::string &Output, const std::string &Name1, double Prop1
// Here is the real code that is inside the try block
std::string backend, fluid;
extract_backend(Ref, backend, fluid);
std::string fluid_string = fluid;
if (has_fractions_in_string(fluid) || has_solution_concentration(fluid)){
fluid_string = extract_fractions(fluid, fractions);
}
std::vector<double> fractions(1, 1.0);
// extract_fractions checks for has_fractions_in_string / has_solution_concentration; no need to double check
std::string fluid_string = extract_fractions(fluid, fractions);
std::vector<std::vector<double> > IO;
_PropsSImulti(strsplit(Output,'&'), Name1, std::vector<double>(1, Prop1), Name2, std::vector<double>(1, Prop2), backend, strsplit(fluid_string, '&'), fractions, IO);
if (IO.empty()){ throw ValueError(get_global_param_string("errstring").c_str()); }
@@ -628,11 +626,10 @@ TEST_CASE("Check inputs to PropsSI","[PropsSI]")
* Props1SI *
****************************************************/
double Props1SI(const std::string &FluidName, const std::string &Output)
double Props1SI(std::string FluidName, std::string Output)
{
std::string _FluidName = FluidName, empty_string = "", _Output = Output;
bool valid_fluid1 = is_valid_fluid_string(_FluidName);
bool valid_fluid2 = is_valid_fluid_string(_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;
@@ -643,13 +640,13 @@ double Props1SI(const std::string &FluidName, const std::string &Output)
}
if (!valid_fluid1 && valid_fluid2){
// They are backwards, swap
std::swap(_Output, _FluidName);
std::swap(Output, FluidName);
}
// First input is the fluid, second input is the input parameter
double val1 = PropsSI(_Output, "", 0, "", 0, _FluidName);
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()));
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{
@@ -690,7 +687,7 @@ bool is_valid_fluid_string(const std::string &input_fluid_string)
shared_ptr<AbstractState> State(AbstractState::factory(backend, fluid_string));
return true;
}
catch (std::exception &){
catch (...){
return false;
}
}
@@ -698,64 +695,63 @@ double saturation_ancillary(const std::string &fluid_name, const std::string &ou
// Generate the state instance
std::vector<std::string> names(1, fluid_name);
shared_ptr<CoolProp::HelmholtzEOSMixtureBackend> HEOS(new CoolProp::HelmholtzEOSMixtureBackend(names));
CoolProp::HelmholtzEOSMixtureBackend HEOS(names);
parameters iInput = get_parameter_index(input);
parameters iOutput = get_parameter_index(output);
return HEOS->saturation_ancillary(iOutput, Q, iInput, value);
return HEOS.saturation_ancillary(iOutput, Q, iInput, value);
}
void set_reference_stateS(const std::string &Ref, const std::string &reference_state)
{
shared_ptr<CoolProp::HelmholtzEOSMixtureBackend> HEOS;
std::vector<std::string> _comps(1, Ref);
HEOS.reset(new CoolProp::HelmholtzEOSMixtureBackend(_comps));
CoolProp::HelmholtzEOSMixtureBackend HEOS(_comps);
if (!reference_state.compare("IIR"))
{
HEOS->update(QT_INPUTS, 0, 273.15);
HEOS.update(QT_INPUTS, 0, 273.15);
// Get current values for the enthalpy and entropy
double deltah = HEOS->hmass() - 200000; // offset from 200000 J/kg enthalpy
double deltas = HEOS->smass() - 1000; // offset from 1000 J/kg/K entropy
double delta_a1 = deltas/(HEOS->gas_constant()/HEOS->molar_mass());
double delta_a2 = -deltah/(HEOS->gas_constant()/HEOS->molar_mass()*HEOS->get_reducing_state().T);
HEOS->get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, "IIR");
HEOS->update_states();
double deltah = HEOS.hmass() - 200000; // offset from 200000 J/kg enthalpy
double deltas = HEOS.smass() - 1000; // offset from 1000 J/kg/K entropy
double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass());
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
HEOS.get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, "IIR");
HEOS.update_states();
}
else if (!reference_state.compare("ASHRAE"))
{
HEOS->update(QT_INPUTS, 0, 243.15);
HEOS.update(QT_INPUTS, 0, 243.15);
// Get current values for the enthalpy and entropy
double deltah = HEOS->hmass() - 0; // offset from 0 J/kg enthalpy
double deltas = HEOS->smass() - 0; // offset from 0 J/kg/K entropy
double delta_a1 = deltas/(HEOS->gas_constant()/HEOS->molar_mass());
double delta_a2 = -deltah/(HEOS->gas_constant()/HEOS->molar_mass()*HEOS->get_reducing_state().T);
HEOS->get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, "ASHRAE");
HEOS->update_states();
double deltah = HEOS.hmass() - 0; // offset from 0 J/kg enthalpy
double deltas = HEOS.smass() - 0; // offset from 0 J/kg/K entropy
double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass());
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
HEOS.get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, "ASHRAE");
HEOS.update_states();
}
else if (!reference_state.compare("NBP"))
{
// Saturated liquid boiling point at 1 atmosphere
HEOS->update(PQ_INPUTS, 101325, 0);
HEOS.update(PQ_INPUTS, 101325, 0);
double deltah = HEOS->hmass() - 0; // offset from 0 kJ/kg enthalpy
double deltas = HEOS->smass() - 0; // offset from 0 kJ/kg/K entropy
double delta_a1 = deltas/(HEOS->gas_constant()/HEOS->molar_mass());
double delta_a2 = -deltah/(HEOS->gas_constant()/HEOS->molar_mass()*HEOS->get_reducing_state().T);
double deltah = HEOS.hmass() - 0; // offset from 0 kJ/kg enthalpy
double deltas = HEOS.smass() - 0; // offset from 0 kJ/kg/K entropy
double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass());
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
if (get_debug_level() > 5){std::cout << format("[set_reference_stateD] delta_a1 %g delta_a2 %g\n",delta_a1, delta_a2);}
HEOS->get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, "NBP");
HEOS->update_states();
HEOS.get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, "NBP");
HEOS.update_states();
}
else if (!reference_state.compare("DEF"))
{
HEOS->get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(0,0,"");
HEOS.get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(0,0,"");
}
else if (!reference_state.compare("RESET"))
{
HEOS->get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(0, 0, "");
HEOS->get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffsetCore.set(0, 0, "");
HEOS.get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(0, 0, "");
HEOS.get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffsetCore.set(0, 0, "");
}
else
{
@@ -764,19 +760,18 @@ void set_reference_stateS(const std::string &Ref, const std::string &reference_s
}
void set_reference_stateD(const std::string &Ref, double T, double rhomolar, double h0, double s0)
{
shared_ptr<CoolProp::HelmholtzEOSMixtureBackend> HEOS;
std::vector<std::string> _comps(1, Ref);
HEOS.reset(new CoolProp::HelmholtzEOSMixtureBackend(_comps));
CoolProp::HelmholtzEOSMixtureBackend HEOS(_comps);
HEOS->update(DmolarT_INPUTS, rhomolar, T);
HEOS.update(DmolarT_INPUTS, rhomolar, T);
// Get current values for the enthalpy and entropy
double deltah = HEOS->hmass() - h0; // offset from specified enthalpy in J/mol
double deltas = HEOS->smass() - s0; // offset from specified entropy in J/mol/K
double delta_a1 = deltas/(8.314472/HEOS->molar_mass());
double delta_a2 = -deltah/(8.314472/HEOS->molar_mass()*HEOS->get_reducing_state().T);
HEOS->get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, "custom");
HEOS->update_states();
double deltah = HEOS.hmass() - h0; // offset from specified enthalpy in J/mol
double deltas = HEOS.smass() - s0; // offset from specified entropy in J/mol/K
double delta_a1 = deltas/(8.314472/HEOS.molar_mass());
double delta_a2 = -deltah/(8.314472/HEOS.molar_mass()*HEOS.get_reducing_state().T);
HEOS.get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, "custom");
HEOS.update_states();
}
std::string get_BibTeXKey(const std::string &Ref, const std::string &key)
@@ -854,10 +849,10 @@ std::string get_fluid_param_string(const std::string &FluidName, const std::stri
std::string backend, fluid;
extract_backend(FluidName, backend, fluid);
if (backend == "INCOMP"){
shared_ptr<CoolProp::IncompressibleBackend> INCOMP(new CoolProp::IncompressibleBackend(fluid));
CoolProp::IncompressibleBackend INCOMP(fluid);
if (!ParamName.compare("long_name")){
return INCOMP->calc_name();
return INCOMP.calc_name();
}
else{
throw ValueError(format("Input value [%s] is invalid for Fluid [%s]",ParamName.c_str(),FluidName.c_str()));
@@ -865,8 +860,8 @@ std::string get_fluid_param_string(const std::string &FluidName, const std::stri
}
std::vector<std::string> comps(1, FluidName);
shared_ptr<CoolProp::HelmholtzEOSMixtureBackend> HEOS(new CoolProp::HelmholtzEOSMixtureBackend(comps));
CoolProp::CoolPropFluid *cpfluid = HEOS->get_components()[0];
CoolProp::HelmholtzEOSMixtureBackend HEOS(comps);
CoolProp::CoolPropFluid *cpfluid = HEOS.get_components()[0];
if (!ParamName.compare("aliases")){
return strjoin(cpfluid->aliases, ", ");