Added more fitting stuff, still some problems with the enumerations in C++

This commit is contained in:
jowr
2014-08-01 15:15:35 +02:00
parent b8badfba2c
commit eddeee54e0
13 changed files with 273 additions and 171 deletions

View File

@@ -101,6 +101,7 @@ void IncompressibleBackend::update(long input_pair, double value1, double value2
if (_T < 0){ throw ValueError("T is less than zero");}
if (!ValidNumber(_T)){ throw ValueError("T is not a valid number");}
if (get_debug_level()>=50) std::cout << format("Incompressible backend: Update finished T=%f, p=%f, x=%s ",this->_T,this->_p,vec_to_string(_fractions).c_str()) << std::endl;
fluid->checkTPX(_T,_p,_fractions[0]);
}
/// Set the mole fractions
@@ -468,6 +469,7 @@ TEST_CASE("Internal consistency checks and example use cases for the incompressi
CAPTURE(res);
CHECK( check_abs(val,res,acc) );
}
CoolProp::set_debug_level(100);
// ... as %
res = CoolProp::PropsSI("D","T",T,"P",p,fluid+format("-%f%s",x*100.0,"%"));
{

View File

@@ -2,9 +2,9 @@
#ifndef INCOMPRESSIBLEBACKEND_H_
#define INCOMPRESSIBLEBACKEND_H_
#include "DataStructures.h"
#include "IncompressibleFluid.h"
#include "AbstractState.h"
#include "DataStructures.h"
#include "Exceptions.h"
#include <vector>
@@ -33,9 +33,9 @@ public:
IncompressibleBackend(const std::vector<std::string> &component_names);
// Incompressible backend uses different compositions
bool using_mole_fractions(){return this->fluid->getxid()==ifrac_mole;};
bool using_mole_fractions(){return this->fluid->getxid()==ifrac_mole;};
bool using_mass_fractions(){return (this->fluid->getxid()==ifrac_mass || this->fluid->getxid()==ifrac_pure);};
bool using_volu_fractions(){return this->fluid->getxid()==ifrac_volume;};
bool using_volu_fractions(){return this->fluid->getxid()==ifrac_volume;};
/// Updating function for incompressible fluid
/**

View File

@@ -1,9 +1,9 @@
#include "DataStructures.h"
#include "IncompressibleFluid.h"
#include "math.h"
#include "MatrixMath.h"
#include "PolyMath.h"
#include "DataStructures.h"
namespace CoolProp {
@@ -39,13 +39,21 @@ bool IncompressibleFluid::is_pure() {
return false;
}
/// Base functions that handle the custom data type, just a place holder to show the structure.
/// Base exponential function
double IncompressibleFluid::baseExponential(IncompressibleData data, double y, double ybase){
Eigen::VectorXd coeffs = makeVector(data.coeffs);
size_t r=coeffs.rows(),c=coeffs.cols();
if (strict && (r!=3 || c!=1) ) throw ValueError(format("%s (%d): You have to provide a 3,1 matrix of coefficients, not (%d,%d).",__FILE__,__LINE__,r,c));
return exp( (double) (coeffs[0] / ( (y-ybase)+coeffs[1] ) - coeffs[2] ) );
}
/// Base exponential function with logarithmic term
double IncompressibleFluid::baseLogexponential(IncompressibleData data, double y, double ybase){
Eigen::VectorXd coeffs = makeVector(data.coeffs);
size_t r=coeffs.rows(),c=coeffs.cols();
if (strict && (r!=3 || c!=1) ) throw ValueError(format("%s (%d): You have to provide a 3,1 matrix of coefficients, not (%d,%d).",__FILE__,__LINE__,r,c));
return exp( (double) ( log( (double) (1.0/((y-ybase)+coeffs[0]) + 1.0/((y-ybase)+coeffs[0])/((y-ybase)+coeffs[0]) ) ) *coeffs[1]+coeffs[2] ) );
}
double IncompressibleFluid::basePolyOffset(IncompressibleData data, double y, double z){
size_t r=data.coeffs.rows(),c=data.coeffs.cols();
double offset = 0.0;
@@ -77,6 +85,9 @@ double IncompressibleFluid::rho (double T, double p, double x){
case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL:
return baseExponential(density, T, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL:
return baseLogexponential(density, T, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL:
return exp(poly.evaluate(density.coeffs, T, x, 0, 0, Tbase, xbase));
break;
@@ -156,6 +167,9 @@ double IncompressibleFluid::visc(double T, double p, double x){
case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL:
return baseExponential(viscosity, T, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL:
return baseLogexponential(viscosity, T, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL:
return exp(poly.evaluate(viscosity.coeffs, T, x, 0, 0, Tbase, xbase));
break;
@@ -180,6 +194,9 @@ double IncompressibleFluid::cond(double T, double p, double x){
case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL:
return baseExponential(conductivity, T, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL:
return baseLogexponential(conductivity, T, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL:
return exp(poly.evaluate(conductivity.coeffs, T, x, 0, 0, Tbase, xbase));
break;
@@ -205,6 +222,9 @@ double IncompressibleFluid::psat(double T, double x){
case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL:
return baseExponential(p_sat, T, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL:
return baseLogexponential(p_sat, T, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL:
return exp(poly.evaluate(p_sat.coeffs, T, x, 0, 0, Tbase, xbase));
break;
@@ -229,6 +249,9 @@ double IncompressibleFluid::Tfreeze( double p, double x){
case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL:
return baseExponential(T_freeze, x, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL:
return baseLogexponential(T_freeze, x, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL:
return exp(poly.evaluate(T_freeze.coeffs, p, x, 0, 0, 0.0, xbase));
break;
@@ -260,7 +283,10 @@ double IncompressibleFluid::inputFromMass (double T, double x){
return poly.evaluate(mass2input.coeffs, T, x, 0, 0, 0.0, 0.0); // TODO: make sure Tbase and xbase is defined in the correct way
break;
case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL:
return baseExponential(mass2input, T, 0.0);
return baseExponential(mass2input, x, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL:
return baseLogexponential(mass2input, x, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL:
return exp(poly.evaluate(mass2input.coeffs, T, x, 0, 0, 0.0, 0.0)); // TODO: make sure Tbase and xbase is defined in the correct way
@@ -294,7 +320,10 @@ double IncompressibleFluid::inputFromVolume (double T, double x){
return poly.evaluate(volume2input.coeffs, T, x, 0, 0, 0.0, 0.0); // TODO: make sure Tbase and xbase is defined in the correct way
break;
case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL:
return baseExponential(volume2input, T, 0.0);
return baseExponential(volume2input, x, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL:
return baseLogexponential(volume2input, x, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL:
return exp(poly.evaluate(volume2input.coeffs, T, x, 0, 0, 0.0, 0.0)); // TODO: make sure Tbase and xbase is defined in the correct way
@@ -328,7 +357,10 @@ double IncompressibleFluid::inputFromMole (double T, double x){
return poly.evaluate(mole2input.coeffs, T, x, 0, 0, 0.0, 0.0); // TODO: make sure Tbase and xbase is defined in the correct way
break;
case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL:
return baseExponential(mole2input, T, 0.0);
return baseExponential(mole2input, x, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL:
return baseLogexponential(mole2input, x, 0.0);
break;
case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL:
return exp(poly.evaluate(mole2input.coeffs, T, x, 0, 0, 0.0, 0.0)); // TODO: make sure Tbase and xbase is defined in the correct way
@@ -441,21 +473,11 @@ double IncompressibleFluid::T_u (double Umass, double p, double x){
bool IncompressibleFluid::checkT(double T, double p, double x) {
if (Tmin <= 0.) throw ValueError("Please specify the minimum temperature.");
if (Tmax <= 0.) throw ValueError("Please specify the maximum temperature.");
if ((Tmin > T) || (T > Tmax)) throw ValueError(
format("Your temperature %f is not between %f and %f.",
T, Tmin, Tmax));
if ((Tmin > T) || (T > Tmax)) throw ValueError(format("Your temperature %f is not between %f and %f.", T, Tmin, Tmax));
double TF = 0.0;
if (T_freeze.type!=IncompressibleData::INCOMPRESSIBLE_NOT_SET) {
TF = Tfreeze(p, x);
}
if ( T<TF) {
throw ValueError(
format("Your temperature %f is below the freezing point of %f.",
T, TF));
} else {
return true;
}
return false;
if (T_freeze.type!=IncompressibleData::INCOMPRESSIBLE_NOT_SET) TF = Tfreeze(p, x);
if ( T<TF) throw ValueError(format("Your temperature %f is below the freezing point of %f.", T, TF));
return true;
}
/// Check validity of pressure input.
@@ -467,21 +489,10 @@ bool IncompressibleFluid::checkT(double T, double p, double x) {
* */
bool IncompressibleFluid::checkP(double T, double p, double x) {
double ps = 0.0;
if (p_sat.type!=IncompressibleData::INCOMPRESSIBLE_NOT_SET) {
ps = psat(T, x);
}
if (p < 0.0) {
throw ValueError(
format("You cannot use negative pressures: %f < %f. ",
p, 0.0));
} else if (p < ps) {
throw ValueError(
format("Equations are valid for liquid phase only: %f < %f. ",
p, ps));
} else {
return true;
}
return false;
if (p_sat.type!=IncompressibleData::INCOMPRESSIBLE_NOT_SET) ps = psat(T, x);
if (p < 0.0) throw ValueError(format("You cannot use negative pressures: %f < %f. ", p, 0.0));
if (ps>0.0 && p < ps) throw ValueError(format("Equations are valid for liquid phase only: %f < %f (psat). ", p, ps));
return true;
}
/// Check validity of composition input.
@@ -489,18 +500,10 @@ bool IncompressibleFluid::checkP(double T, double p, double x) {
* maximum value. Enforces the redefinition of xmin and
* xmax since the default values cause an error. */
bool IncompressibleFluid::checkX(double x){
if (xmin < 0. || xmin > 1.0) {
throw ValueError("Please specify the minimum concentration between 0 and 1.");
} else if (xmax < 0.0 || xmax > 1.0) {
throw ValueError("Please specify the maximum concentration between 0 and 1.");
} else if ((xmin > x) || (x > xmax)) {
throw ValueError(
format("Your composition %f is not between %f and %f.",
x, xmin, xmax));
} else {
return true;
}
return false;
if (xmin < 0.0 || xmin > 1.0) throw ValueError("Please specify the minimum concentration between 0 and 1.");
if (xmax < 0.0 || xmax > 1.0) throw ValueError("Please specify the maximum concentration between 0 and 1.");
if ((xmin > x) || (x > xmax)) throw ValueError(format("Your composition %f is not between %f and %f.", x, xmin, xmax));
return true;
}
} /* namespace CoolProp */

View File

@@ -367,6 +367,11 @@ IncompressibleData JSONIncompressibleLibrary::parse_coefficients(rapidjson::Valu
fluidData.coeffs = vec_to_eigen(cpjson::get_double_array(obj[id.c_str()]["coeffs"]));
return fluidData;
}
else if (!type.compare("logexponential")){
fluidData.type = CoolProp::IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL;
fluidData.coeffs = vec_to_eigen(cpjson::get_double_array(obj[id.c_str()]["coeffs"]));
return fluidData;
}
else if (!type.compare("exppolynomial")){
fluidData.type = CoolProp::IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL;
fluidData.coeffs = vec_to_eigen(cpjson::get_double_array2D(obj[id.c_str()]["coeffs"]));