mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-23 03:00:17 -04:00
Added isentropic expansion coefficient (#1791)
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
namespace CoolProp {
|
||||
|
||||
/// This tiny class holds pointers to generators for the backends and can be used to look up
|
||||
/// generators at runtime. This class should be populated through the use of static initialized
|
||||
/// generators at runtime. This class should be populated through the use of static initialized
|
||||
|
||||
class BackendLibrary{
|
||||
private:
|
||||
@@ -47,7 +47,7 @@ inline BackendLibrary & get_backend_library(){
|
||||
static BackendLibrary the_library;
|
||||
return the_library;
|
||||
}
|
||||
|
||||
|
||||
void register_backend(const backend_families &bf, shared_ptr<AbstractStateGenerator> gen){
|
||||
get_backend_library().add_backend(bf, gen);
|
||||
};
|
||||
@@ -114,14 +114,14 @@ AbstractState * AbstractState::factory(const std::string &backend, const std::ve
|
||||
backend_families f1;
|
||||
std::string f2;
|
||||
extract_backend_families_string(backend, f1, f2);
|
||||
|
||||
|
||||
std::map<backend_families,shared_ptr<AbstractStateGenerator> >::const_iterator gen, end;
|
||||
get_backend_library().get_generator_iterators(f1, gen, end);
|
||||
|
||||
if (get_debug_level() > 0){
|
||||
std::cout << "AbstractState::factory backend_library size: " << get_backend_library().size() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (gen != end){
|
||||
// One of the registered backends was able to match the given backend family
|
||||
return gen->second->get_AbstractState(fluid_names);
|
||||
@@ -429,7 +429,7 @@ double AbstractState::keyed_output(parameters key)
|
||||
case ispeed_sound:
|
||||
return speed_sound();
|
||||
case ialphar:
|
||||
return alphar();
|
||||
return alphar();
|
||||
case ialpha0:
|
||||
return alpha0();
|
||||
case idalpha0_ddelta_consttau:
|
||||
@@ -452,6 +452,8 @@ double AbstractState::keyed_output(parameters key)
|
||||
return isothermal_compressibility();
|
||||
case iisobaric_expansion_coefficient:
|
||||
return isobaric_expansion_coefficient();
|
||||
case iisentropic_expansion_coefficient:
|
||||
return isentropic_expansion_coefficient();
|
||||
case iviscosity:
|
||||
return viscosity();
|
||||
case iconductivity:
|
||||
@@ -633,12 +635,15 @@ double AbstractState::isothermal_compressibility(void){
|
||||
double AbstractState::isobaric_expansion_coefficient(void){
|
||||
return -1.0/_rhomolar*first_partial_deriv(iDmolar, iT, iP);
|
||||
}
|
||||
double AbstractState::isentropic_expansion_coefficient(void) {
|
||||
return _rhomolar/_p*first_partial_deriv(iP, iDmolar, iSmolar);
|
||||
}
|
||||
double AbstractState::Bvirial(void){ return calc_Bvirial(); }
|
||||
double AbstractState::Cvirial(void){ return calc_Cvirial(); }
|
||||
double AbstractState::dBvirial_dT(void){ return calc_dBvirial_dT(); }
|
||||
double AbstractState::dCvirial_dT(void){ return calc_dCvirial_dT(); }
|
||||
double AbstractState::compressibility_factor(void){ return calc_compressibility_factor(); }
|
||||
|
||||
|
||||
double AbstractState::fundamental_derivative_of_gas_dynamics()
|
||||
{
|
||||
// See Colonna, FPE, 2010, Eq. 1
|
||||
@@ -984,7 +989,7 @@ TEST_CASE("Check derivatives in first_partial_deriv","[derivs_in_first_partial_d
|
||||
// Numerical derivatives
|
||||
CoolPropDbl dP_dT_num = (WaterplusT->p() - WaterminusT->p())/(2*dT);
|
||||
CoolPropDbl dP_drho_num = (Waterplusrho->p() - Waterminusrho->p())/(2*drho);
|
||||
|
||||
|
||||
CoolPropDbl dHmolar_dT_num = (WaterplusT->hmolar() - WaterminusT->hmolar())/(2*dT);
|
||||
CoolPropDbl dHmolar_drho_num = (Waterplusrho->hmolar() - Waterminusrho->hmolar())/(2*drho);
|
||||
CoolPropDbl dHmass_dT_num = (WaterplusT->hmass() - WaterminusT->hmass())/(2*dT);
|
||||
@@ -1059,7 +1064,7 @@ TEST_CASE("Check derivatives in first_partial_deriv","[derivs_in_first_partial_d
|
||||
|
||||
CHECK( std::abs(dP_dT_analyt/dP_dT_num-1) < eps);
|
||||
CHECK( std::abs(dP_drho_analyt/dP_drho_num-1) < eps);
|
||||
|
||||
|
||||
CHECK( std::abs(dHmolar_dT_analyt/dHmolar_dT_num-1) < eps);
|
||||
CHECK( std::abs(dHmolar_drho_analyt/dHmolar_drho_num-1) < eps);
|
||||
CHECK( std::abs(dHmass_dT_analyt/dHmass_dT_num-1) < eps);
|
||||
@@ -1094,4 +1099,4 @@ TEST_CASE("Check derivatives in first_partial_deriv","[derivs_in_first_partial_d
|
||||
CHECK( std::abs(dspeed_sound_drho_analyt/dspeed_sound_drho_num-1) < eps);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace CoolProp{
|
||||
|
||||
struct parameter_info
|
||||
{
|
||||
{
|
||||
int key;
|
||||
const char *short_desc, *IO, *units, *description;
|
||||
bool trivial; ///< True if the input is trivial, and can be directly calculated (constants like critical properties, etc.)
|
||||
@@ -73,29 +73,30 @@ const parameter_info parameter_info_list[] = {
|
||||
{ifraction_min, "fraction_min", "O", "-", "Fraction (mole, mass, volume) minimum value for incompressible solutions",true},
|
||||
{ifraction_max, "fraction_max", "O", "-", "Fraction (mole, mass, volume) maximum value for incompressible solutions",true},
|
||||
{iT_freeze, "T_freeze", "O", "K", "Freezing temperature for incompressible solutions",true},
|
||||
|
||||
|
||||
{ispeed_sound, "speed_of_sound", "O", "m/s", "Speed of sound", false},
|
||||
{iviscosity, "viscosity", "O", "Pa-s", "Viscosity", false},
|
||||
{iconductivity, "conductivity", "O", "W/m/K", "Thermal conductivity", false},
|
||||
{isurface_tension, "surface_tension", "O", "N/m", "Surface tension", false},
|
||||
{iPrandtl, "Prandtl", "O", "-", "Prandtl number", false},
|
||||
|
||||
|
||||
{iisothermal_compressibility, "isothermal_compressibility", "O", "1/Pa", "Isothermal compressibility",false},
|
||||
{iisobaric_expansion_coefficient, "isobaric_expansion_coefficient", "O", "1/K", "Isobaric expansion coefficient",false},
|
||||
{iisentropic_expansion_coefficient, "isentropic_expansion_coefficient", "O", "-", "Isentropic expansion coefficient",false},
|
||||
{iZ, "Z", "O", "-", "Compressibility factor",false},
|
||||
{ifundamental_derivative_of_gas_dynamics, "fundamental_derivative_of_gas_dynamics", "O", "-", "Fundamental derivative of gas dynamics",false},
|
||||
{iPIP, "PIP", "O", "-", "Phase identification parameter", false},
|
||||
|
||||
|
||||
{ialphar, "alphar", "O", "-", "Residual Helmholtz energy", false},
|
||||
{idalphar_dtau_constdelta, "dalphar_dtau_constdelta", "O", "-", "Derivative of residual Helmholtz energy with tau",false},
|
||||
{idalphar_ddelta_consttau, "dalphar_ddelta_consttau", "O", "-", "Derivative of residual Helmholtz energy with delta",false},
|
||||
|
||||
|
||||
{ialpha0, "alpha0", "O", "-", "Ideal Helmholtz energy", false},
|
||||
{idalpha0_dtau_constdelta, "dalpha0_dtau_constdelta", "O", "-", "Derivative of ideal Helmholtz energy with tau",false},
|
||||
{idalpha0_ddelta_consttau, "dalpha0_ddelta_consttau", "O", "-", "Derivative of ideal Helmholtz energy with delta",false},
|
||||
|
||||
|
||||
{iPhase, "Phase", "O", "-", "Phase index as a float", false},
|
||||
|
||||
|
||||
};
|
||||
|
||||
class ParameterInformation
|
||||
@@ -231,24 +232,24 @@ bool is_valid_first_derivative(const std::string &name, parameters &iOf, paramet
|
||||
if (get_debug_level() > 5){std::cout << format("is_valid_first_derivative(%s)",name.c_str());}
|
||||
// There should be exactly one /
|
||||
// There should be exactly one |
|
||||
|
||||
|
||||
// Suppose we start with "d(P)/d(T)|Dmolar"
|
||||
std::vector<std::string> split_at_bar = strsplit(name, '|'); // "d(P)/d(T)" and "Dmolar"
|
||||
if (split_at_bar.size() != 2){return false;}
|
||||
|
||||
|
||||
std::vector<std::string> split_at_slash = strsplit(split_at_bar[0], '/'); // "d(P)" and "d(T)"
|
||||
if (split_at_slash.size() != 2){return false;}
|
||||
|
||||
|
||||
std::size_t i0 = split_at_slash[0].find("(");
|
||||
std::size_t i1 = split_at_slash[0].find(")", i0);
|
||||
if (!((i0 > 0) && (i0 != std::string::npos) && (i1 > (i0+1)) && (i1 != std::string::npos))){return false;}
|
||||
std::string num = split_at_slash[0].substr(i0+1, i1-i0-1);
|
||||
|
||||
|
||||
i0 = split_at_slash[1].find("(");
|
||||
i1 = split_at_slash[1].find(")", i0);
|
||||
if (!((i0 > 0) && (i0 != std::string::npos) && (i1 > (i0+1)) && (i1 != std::string::npos))){return false;}
|
||||
std::string den = split_at_slash[1].substr(i0+1, i1-i0-1);
|
||||
|
||||
|
||||
parameters Of, Wrt, Constant;
|
||||
if (is_valid_parameter(num, Of) && is_valid_parameter(den, Wrt) && is_valid_parameter(split_at_bar[1], Constant)){
|
||||
iOf = Of; iWrt = Wrt; iConstant = Constant; return true;
|
||||
@@ -293,14 +294,14 @@ bool is_valid_first_saturation_derivative(const std::string &name, parameters &i
|
||||
bool is_valid_second_derivative(const std::string &name, parameters &iOf1, parameters &iWrt1, parameters &iConstant1, parameters &iWrt2, parameters &iConstant2)
|
||||
{
|
||||
if (get_debug_level() > 5){std::cout << format("is_valid_second_derivative(%s)",name.c_str());}
|
||||
|
||||
|
||||
// Suppose we start with "d(d(P)/d(Dmolar)|T)/d(Dmolar)|T"
|
||||
std::size_t i = name.rfind('|');
|
||||
if ((i == 0) || (i == std::string::npos)){return false;}
|
||||
std::string constant2 = name.substr(i+1); // "T"
|
||||
if (!is_valid_parameter(constant2, iConstant2)){return false;};
|
||||
std::string left_of_bar = name.substr(0, i); // "d(d(P)/d(Dmolar)|T)/d(Dmolar)"
|
||||
|
||||
|
||||
i = left_of_bar.rfind('/');
|
||||
if ((i == 0) || (i == std::string::npos)){return false;}
|
||||
std::string left_of_slash = left_of_bar.substr(0, i); // "d(d(P)/d(Dmolar)|T)"
|
||||
@@ -311,23 +312,23 @@ bool is_valid_second_derivative(const std::string &name, parameters &iOf1, param
|
||||
if (!((i > 0) && (i != std::string::npos) && (i1 > (i+1)) && (i1 != std::string::npos))){return false;}
|
||||
std::string num = left_of_slash.substr(i+1, i1-i-1); // "d(P)/d(Dmolar)|T"
|
||||
if (!is_valid_first_derivative(num, iOf1, iWrt1, iConstant1)){return false;}
|
||||
|
||||
|
||||
i = right_of_slash.find("(");
|
||||
i1 = right_of_slash.rfind(")");
|
||||
if (!((i > 0) && (i != std::string::npos) && (i1 > (i+1)) && (i1 != std::string::npos))){return false;}
|
||||
std::string den = right_of_slash.substr(i+1, i1-i-1); // "Dmolar"
|
||||
if (!is_valid_parameter(den, iWrt2)){return false;}
|
||||
|
||||
|
||||
// If we haven't quit yet, all is well
|
||||
return true;
|
||||
}
|
||||
|
||||
struct phase_info
|
||||
{
|
||||
{
|
||||
phases key;
|
||||
const char *short_desc, *long_desc;
|
||||
};
|
||||
|
||||
|
||||
const phase_info phase_info_list[] = {
|
||||
{ iphase_liquid, "phase_liquid", "" },
|
||||
{ iphase_gas, "phase_gas", "" },
|
||||
@@ -414,9 +415,9 @@ const input_pair_info input_pair_list[] = {
|
||||
{ DmolarQ_INPUTS, "DmolarQ_INPUTS", "Molar density in mol/m^3, Molar quality" },
|
||||
|
||||
{ PQ_INPUTS, "PQ_INPUTS", "Pressure in Pa, Molar quality" },
|
||||
|
||||
|
||||
{ PT_INPUTS, "PT_INPUTS", "Pressure in Pa, Temperature in K" },
|
||||
|
||||
|
||||
|
||||
{ DmassT_INPUTS, "DmassT_INPUTS", "Mass density in kg/m^3, Temperature in K" },
|
||||
{ DmolarT_INPUTS, "DmolarT_INPUTS", "Molar density in mol/m^3, Temperature in K" },
|
||||
@@ -643,7 +644,7 @@ TEST_CASE("Check that all parameters are described","")
|
||||
std::ostringstream ss;
|
||||
ss << "Parameter index," << i << "last index:" << CoolProp::iundefined_parameter;
|
||||
SECTION(ss.str(), "")
|
||||
{
|
||||
{
|
||||
std::string prior;
|
||||
if (i > 1){
|
||||
CHECK_NOTHROW(prior = CoolProp::get_parameter_information(i-1,"short"));
|
||||
@@ -660,7 +661,7 @@ TEST_CASE("Check that all phases are described","[phase_index]")
|
||||
std::ostringstream ss;
|
||||
ss << "Parameter index," << i << "last index:" << CoolProp::iundefined_parameter;
|
||||
SECTION(ss.str(), "")
|
||||
{
|
||||
{
|
||||
std::string stringrepr;
|
||||
int key;
|
||||
CHECK_NOTHROW(stringrepr = CoolProp::get_phase_short_desc(static_cast<CoolProp::phases>(i)));
|
||||
|
||||
Reference in New Issue
Block a user