Implemented new gas constant normalization method - seems to work well and doesn't touch pure fluid properties

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
Ian Bell
2014-09-10 15:44:01 +02:00
parent 86f52bdf4e
commit 883b7a3f09
4 changed files with 30 additions and 15 deletions

View File

@@ -16,6 +16,8 @@ bool get_config_bool(configuration_keys key)
switch(key)
{
case NORMALIZE_GAS_CONSTANTS:
return false;
case NORMALIZE_GAS_CONSTANTS2:
return true;
default:
throw ValueError(format("%d is invalid key to get_config_bool",key));

View File

@@ -4,7 +4,7 @@
#include "Exceptions.h"
#include "CoolPropTools.h"
enum configuration_keys {NORMALIZE_GAS_CONSTANTS};
enum configuration_keys {NORMALIZE_GAS_CONSTANTS, NORMALIZE_GAS_CONSTANTS2};
namespace CoolProp
{

View File

@@ -171,11 +171,11 @@ long double HelmholtzEOSMixtureBackend::calc_gas_constant(void)
return components[0]->gas_constant();
}
else{
if (get_config_bool(NORMALIZE_GAS_CONSTANTS)){
if (get_config_bool(NORMALIZE_GAS_CONSTANTS) || get_config_bool(NORMALIZE_GAS_CONSTANTS2)){
return R_u_CODATA;
}
else{
// mass fraction weighet average of the components
// mass fraction weighted average of the components
double summer = 0;
for (unsigned int i = 0; i < components.size(); ++i)
{
@@ -1954,7 +1954,7 @@ long double HelmholtzEOSMixtureBackend::calc_cvmolar(void)
// Calculate derivatives if needed, or just use cached values
long double d2ar_dTau2 = d2alphar_dTau2();
long double d2a0_dTau2 = d2alpha0_dTau2();
long double R_u = static_cast<double>(_gas_constant);
long double R_u = gas_constant();
// Get cv
_cvmolar = -R_u*pow(_tau.pt(),2)*(d2ar_dTau2 + d2a0_dTau2);
@@ -1973,7 +1973,7 @@ long double HelmholtzEOSMixtureBackend::calc_cpmolar(void)
long double d2ar_dDelta2 = d2alphar_dDelta2();
long double d2ar_dDelta_dTau = d2alphar_dDelta_dTau();
long double d2ar_dTau2 = d2alphar_dTau2();
long double R_u = static_cast<double>(_gas_constant);
long double R_u = gas_constant();
// Get cp
_cpmolar = R_u*(-pow(_tau.pt(),2)*(d2ar_dTau2 + d2a0_dTau2)+pow(1+_delta.pt()*dar_dDelta-_delta.pt()*_tau.pt()*d2ar_dDelta_dTau,2)/(1+2*_delta.pt()*dar_dDelta+pow(_delta.pt(),2)*d2ar_dDelta2));
@@ -1988,7 +1988,7 @@ long double HelmholtzEOSMixtureBackend::calc_cpmolar_idealgas(void)
// Calculate derivatives if needed, or just use cached values
long double d2a0_dTau2 = d2alpha0_dTau2();
long double R_u = static_cast<double>(_gas_constant);
long double R_u = gas_constant();
// Get cp of the ideal gas
return R_u*(1+(-pow(_tau.pt(),2))*d2a0_dTau2);
@@ -2090,6 +2090,10 @@ void HelmholtzEOSMixtureBackend::calc_all_alphar_deriv_cache(const std::vector<l
for (std::size_t i = 0; i < N; ++i){
HelmholtzDerivatives derivs = components[i]->pEOS->alphar.all(tau, delta);
long double xi = mole_fractions[i];
long double R_u_ratio = 1;
if (get_config_bool(NORMALIZE_GAS_CONSTANTS2)){
R_u_ratio = components[0]->pEOS->R_u/R_u_CODATA;
}
summer_base += xi*derivs.alphar;
summer_dDelta += xi*derivs.dalphar_ddelta;
summer_dTau += xi*derivs.dalphar_dtau;

View File

@@ -414,15 +414,24 @@ int main()
#endif
#if 0
{
//::set_debug_level(10);
double h = HumidAir::HAPropsSI("H","T",303.15,"R",1.0000000000000000e+00,"P",1.0132500000000000e+05 );
double T = HumidAir::HAPropsSI("T","H",h,"R",1.0000000000000000e+00,"P",1.0132500000000000e+05 );
double hh = HumidAir::HAPropsSI("H","T",T,"R",1.0000000000000000e+00,"P",1.0132500000000000e+05 );
double s = HumidAir::HAPropsSI("S","T",2.1814999999999998e+02,"R",1.0000000000000000e+00,"P",1.0132500000000000e+05);
int r = 3;
}
#endif
#if 0
{
::set_debug_level(11);
std::vector<std::string> tags;
tags.push_back("[mixture_derivs]");
tags.push_back("[REFPROP_backwards_compatibility]");
run_user_defined_tests(tags);
char c;
std::cin >> c;
}
#endif
#if 0
#if 1
{
run_tests();
char c;
@@ -436,7 +445,7 @@ int main()
int rr =0;
}
#endif
#if 1
#if 0
{
// std::vector<std::string> names(1, "n-Propane");
// shared_ptr<HelmholtzEOSMixtureBackend> HEOS(new HelmholtzEOSMixtureBackend(names));
@@ -452,10 +461,10 @@ int main()
// HEOS->update(PT_INPUTS, p, Tmelt);};
// std::cout << get_global_param_string("errstring") << std::endl;
// }
double TTTA = PropsSI("T","P",1e5,"Q",0,"Methane[0.25]&Ethane[0.2]&Propane[0.1]");
double TTT = PropsSI("Dmolar","P",1e5,"T",300,"Methane[0.25]&Ethane[0.2]&Propane[0.1]");
double TTTB = PropsSI("T","P",3e6,"Q",0,"R32[0.5]&R125[0.5]");
double TTTB2 = PropsSI("T","P",3e6,"Q",0,"REFPROP::R32[0.5]&R125[0.5]");
// double TTTA = PropsSI("T","P",1e5,"Q",0,"Methane[0.25]&Ethane[0.2]&Propane[0.1]");
// double TTT = PropsSI("Dmolar","P",1e5,"T",300,"Methane[0.25]&Ethane[0.2]&Propane[0.1]");
// double TTTB = PropsSI("T","P",3e6,"Q",0,"R32[0.5]&R125[0.5]");
// double TTTB2 = PropsSI("T","P",3e6,"Q",0,"REFPROP::R32[0.5]&R125[0.5]");
::set_debug_level(0);
@@ -474,7 +483,7 @@ int main()
std::cout << get_global_param_string("errstring") << std::endl;
}
t2 = clock();
std::cout << format("value(all): %g s/call\n", ((double)(t2-t1))/CLOCKS_PER_SEC);
std::cout << format("time: %g s/call\n", ((double)(t2-t1))/CLOCKS_PER_SEC);
exit(EXIT_SUCCESS);
std::cout << get_global_param_string("errstring") << std::endl;