Fixed mass-based saturation derivatives; closes #673

This commit is contained in:
Ian Bell
2015-05-14 18:24:44 -06:00
parent f6109785c7
commit 4010e59e48
2 changed files with 36 additions and 1 deletions

View File

@@ -304,12 +304,14 @@ void CoolProp::TabularBackend::load_tables(){
std::string path_to_tables = this->path_to_tables();
single_phase_logph.AS = this->AS;
single_phase_logpT.AS = this->AS;
pure_saturation.AS = this->AS;
single_phase_logph.set_limits();
single_phase_logpT.set_limits();
load_table(single_phase_logph, path_to_tables, "single_phase_logph.bin.z");
load_table(single_phase_logpT, path_to_tables, "single_phase_logpT.bin.z");
load_table(pure_saturation, path_to_tables, "pure_saturation.bin.z");
load_table(phase_envelope, path_to_tables, "phase_envelope.bin.z");
}
#if defined(ENABLE_CATCH)
@@ -367,6 +369,34 @@ TEST_CASE_METHOD(TabularFixture, "Tests for tabular backends with water", "[Tabu
CHECK(std::abs((expected-actual_TTSE)/expected) < 1e-6);
CHECK(std::abs((expected-actual_BICUBIC)/expected) < 1e-6);
}
SECTION("first_saturation_deriv dDmass/dP"){
setup();
ASHEOS->update(CoolProp::PQ_INPUTS, 101325, 1);
CoolPropDbl expected = ASHEOS->first_saturation_deriv(CoolProp::iDmass, CoolProp::iP);
ASTTSE->update(CoolProp::PQ_INPUTS, 101325, 1);
CoolPropDbl actual_TTSE = ASTTSE->first_saturation_deriv(CoolProp::iDmass, CoolProp::iP);
ASBICUBIC->update(CoolProp::PQ_INPUTS, 101325, 1);
CoolPropDbl actual_BICUBIC = ASBICUBIC->first_saturation_deriv(CoolProp::iDmass, CoolProp::iP);
CAPTURE(expected);
CAPTURE(actual_TTSE);
CAPTURE(actual_BICUBIC);
CHECK(std::abs((expected-actual_TTSE)/expected) < 1e-6);
CHECK(std::abs((expected-actual_BICUBIC)/expected) < 1e-6);
}
SECTION("first_saturation_deriv dHmass/dP"){
setup();
ASHEOS->update(CoolProp::PQ_INPUTS, 101325, 1);
CoolPropDbl expected = ASHEOS->first_saturation_deriv(CoolProp::iHmass, CoolProp::iP);
ASTTSE->update(CoolProp::PQ_INPUTS, 101325, 1);
CoolPropDbl actual_TTSE = ASTTSE->first_saturation_deriv(CoolProp::iHmass, CoolProp::iP);
ASBICUBIC->update(CoolProp::PQ_INPUTS, 101325, 1);
CoolPropDbl actual_BICUBIC = ASBICUBIC->first_saturation_deriv(CoolProp::iHmass, CoolProp::iP);
CAPTURE(expected);
CAPTURE(actual_TTSE);
CAPTURE(actual_BICUBIC);
CHECK(std::abs((expected-actual_TTSE)/expected) < 1e-6);
CHECK(std::abs((expected-actual_BICUBIC)/expected) < 1e-6);
}
SECTION("first_two_phase_deriv dDmolar/dP|Hmolar"){
setup();
ASHEOS->update(CoolProp::PQ_INPUTS, 101325, 0.1);

View File

@@ -256,6 +256,7 @@ class PureFluidSaturationTableData{
case iP: x = (Q == 0) ? &pL : &pV; break;
default: throw ValueError(format("Key for Wrt1 is invalid in calc_first_saturation_deriv"));
}
CoolPropDbl factor = 1.0;
switch(Of1){
case iT: y = (Q == 0) ? &TL : &TV; break;
case iP: y = (Q == 0) ? &pL : &pV; break;
@@ -263,11 +264,15 @@ class PureFluidSaturationTableData{
case iHmolar: y = (Q == 0) ? &hmolarL : &hmolarV; break;
case iSmolar: y = (Q == 0) ? &smolarL : &smolarV; break;
case iUmolar: y = (Q == 0) ? &umolarL : &umolarV; break;
case iDmass: y = (Q == 0) ? &rhomolarL : &rhomolarV; factor = AS->molar_mass(); break;
case iHmass: y = (Q == 0) ? &hmolarL : &hmolarV; factor = 1/AS->molar_mass(); break;
case iSmass: y = (Q == 0) ? &smolarL : &smolarV; factor = 1/AS->molar_mass(); break;
case iUmass: y = (Q == 0) ? &umolarL : &umolarV; factor = 1/AS->molar_mass(); break;
default: throw ValueError(format("Key for Of1 is invalid in calc_first_saturation_deriv"));
}
return CubicInterpFirstDeriv((*x)[i-2], (*x)[i-1], (*x)[i], (*x)[i+1],
(*y)[i-2], (*y)[i-1], (*y)[i], (*y)[i+1],
val);
val)*factor;
};
//calc_first_two_phase_deriv(parameters Of, parameters Wrt, parameters Constant);
};