Renamed the enumeration and still no luck

This commit is contained in:
jowr
2014-08-01 15:44:02 +02:00
parent eddeee54e0
commit 165298d41e
9 changed files with 34 additions and 32 deletions

View File

@@ -576,7 +576,7 @@ class IncompressibleFitter(object):
#print("Fit did not succeed with {0}, reducing tolerance to {1}.".format(algorithm,tol))
success = False
counter += 1
elif tolerance<1e-10:
elif tolerance<1e-3:
tolerance *= 1e2
if DEBUG: print("Fit did not succeed, reducing tolerance to {0}.".format(tolerance))
success = False

View File

@@ -74,10 +74,10 @@ int get_parameter_index(const std::string &param_name);
std::string get_csv_parameter_list();
/// These are constants for the compositions
enum compositions{ifrac_mass, ifrac_mole, ifrac_volume, ifrac_undefined, ifrac_pure};
enum composition_types{IFRAC_MASS, IFRAC_MOLE, IFRAC_VOLUME, IFRAC_UNDEFINED, IFRAC_PURE};
/// These are constants for the phases of the fluid
enum phases{ iphase_liquid, iphase_supercritical, iphase_gas, iphase_twophase, iphase_unknown };
enum phases{iphase_liquid, iphase_supercritical, iphase_gas, iphase_twophase, iphase_unknown};
/// These are unit types for the fluid
enum fluid_types{FLUID_TYPE_PURE, FLUID_TYPE_PSEUDOPURE, FLUID_TYPE_REFPROP, FLUID_TYPE_INCOMPRESSIBLE_LIQUID, FLUID_TYPE_INCOMPRESSIBLE_SOLUTION, FLUID_TYPE_UNDEFINED};

View File

@@ -26,7 +26,6 @@
namespace CoolProp {
struct IncompressibleData {
int type;
enum IncompressibleTypeEnum {
INCOMPRESSIBLE_NOT_SET,
INCOMPRESSIBLE_POLYNOMIAL,
@@ -35,6 +34,7 @@ struct IncompressibleData {
INCOMPRESSIBLE_LOGEXPONENTIAL,
INCOMPRESSIBLE_POLYOFFSET
};
IncompressibleTypeEnum type;
Eigen::MatrixXd coeffs; //TODO: Can we store the Eigen::Matrix objects more efficiently?
//std::vector<std::vector<double> > coeffs;
IncompressibleData() {
@@ -57,7 +57,7 @@ protected:
double Tmin, Tmax;
double xmin, xmax;
int xid;
composition_types xid;
double TminPsat;
double xref, Tref, pref;
@@ -132,7 +132,7 @@ protected:
//double u_h(double T, double p, double x);
public:
IncompressibleFluid(){strict = true; xid = ifrac_undefined;};
IncompressibleFluid(){strict = true; xid = IFRAC_UNDEFINED;};
virtual ~IncompressibleFluid(){};
std::string getName() const {return name;}
@@ -144,7 +144,7 @@ public:
double getTmin() const {return Tmin;}
double getxmax() const {return xmax;}
double getxmin() const {return xmin;}
int getxid() const {return xid;}
composition_types getxid() const {return xid;}
double getTminPsat() const {return TminPsat;}
double getTref() const {return Tref;}
double getpref() const {return pref;}
@@ -161,7 +161,7 @@ public:
void setTmin(double Tmin) {this->Tmin = Tmin;}
void setxmax(double xmax) {this->xmax = xmax;}
void setxmin(double xmin) {this->xmin = xmin;}
void setxid(int xid) {this->xid = xid;}
void setxid(composition_types xid) {this->xid = xid;}
void setTminPsat(double TminPsat) {this->TminPsat = TminPsat;}
//void setTref(double Tref) {this->Tref = Tref;}
//void setpref(double pref) {this->pref = pref;}

View File

@@ -111,10 +111,10 @@ void IncompressibleBackend::update(long input_pair, double value1, double value2
void IncompressibleBackend::set_mole_fractions(const std::vector<long double> &mole_fractions){
if (get_debug_level()>=10) std::cout << format("Incompressible backend: Called set_mole_fractions with %s ",vec_to_string(mole_fractions).c_str()) << std::endl;
if (mole_fractions.size()!=1) throw ValueError(format("The incompressible backend only supports one entry in the mole fraction vector and not %d.",mole_fractions.size()));
if (fluid->getxid()==ifrac_pure) {
if (fluid->getxid()==IFRAC_PURE) {
this->_fractions = std::vector<long double>(1,0);
if (get_debug_level()>=20) std::cout << format("Incompressible backend: Overwriting fractions for pure fluid with %s -> %s",vec_to_string(mole_fractions).c_str(),vec_to_string(this->_fractions).c_str()) << std::endl;
} else if (fluid->getxid()==ifrac_mole) {
} else if (fluid->getxid()==IFRAC_MOLE) {
this->_fractions = mole_fractions;
} else {
this->_fractions.clear();
@@ -131,10 +131,10 @@ void IncompressibleBackend::set_mole_fractions(const std::vector<long double> &m
void IncompressibleBackend::set_mass_fractions(const std::vector<long double> &mass_fractions){
if (get_debug_level()>=10) std::cout << format("Incompressible backend: Called set_mass_fractions with %s ",vec_to_string(mass_fractions).c_str()) << std::endl;
if (mass_fractions.size()!=1) throw ValueError(format("The incompressible backend only supports one entry in the mass fraction vector and not %d.",mass_fractions.size()));
if (fluid->getxid()==ifrac_pure) {
if (fluid->getxid()==IFRAC_PURE) {
this->_fractions = std::vector<long double>(1,0);
if (get_debug_level()>=20) std::cout << format("Incompressible backend: Overwriting fractions for pure fluid with %s -> %s",vec_to_string(mass_fractions).c_str(),vec_to_string(this->_fractions).c_str()) << std::endl;
} else if (fluid->getxid()==ifrac_mass) {
} else if (fluid->getxid()==IFRAC_MASS) {
this->_fractions = mass_fractions;
} else {
this->_fractions.clear();
@@ -151,10 +151,10 @@ void IncompressibleBackend::set_mass_fractions(const std::vector<long double> &m
void IncompressibleBackend::set_volu_fractions(const std::vector<long double> &volu_fractions){
if (get_debug_level()>=10) std::cout << format("Incompressible backend: Called set_volu_fractions with %s ",vec_to_string(volu_fractions).c_str()) << std::endl;
if (volu_fractions.size()!=1) throw ValueError(format("The incompressible backend only supports one entry in the volume fraction vector and not %d.",volu_fractions.size()));
if (fluid->getxid()==ifrac_pure) {
if (fluid->getxid()==IFRAC_PURE) {
this->_fractions = std::vector<long double>(1,0);
if (get_debug_level()>=20) std::cout << format("Incompressible backend: Overwriting fractions for pure fluid with %s -> %s",vec_to_string(volu_fractions).c_str(),vec_to_string(this->_fractions).c_str()) << std::endl;
} else if (fluid->getxid()==ifrac_volume) {
} else if (fluid->getxid()==IFRAC_VOLUME) {
this->_fractions = volu_fractions;
} else {
this->_fractions.clear();

View File

@@ -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_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_mole_fractions(void){return this->fluid->getxid()==IFRAC_MOLE;};
bool using_mass_fractions(void){return (this->fluid->getxid()==IFRAC_MASS || this->fluid->getxid()==IFRAC_PURE);};
bool using_volu_fractions(void){return this->fluid->getxid()==IFRAC_VOLUME;};
/// Updating function for incompressible fluid
/**

View File

@@ -272,9 +272,9 @@ double IncompressibleFluid::Tfreeze( double p, double x){
/** If the fluid type is mass-based, it does not do anything. Otherwise,
* it converts the mass fraction to the required input. */
double IncompressibleFluid::inputFromMass (double T, double x){
if (this->xid==ifrac_pure) {
if (this->xid==IFRAC_PURE) {
return _HUGE;
} else if (this->xid==ifrac_mass) {
} else if (this->xid==IFRAC_MASS) {
return x;
} else {
throw NotImplementedError("Mass composition conversion has not been implemented.");
@@ -309,9 +309,9 @@ double IncompressibleFluid::inputFromMass (double T, double x){
/** If the fluid type is volume-based, it does not do anything. Otherwise,
* it converts the volume fraction to the required input. */
double IncompressibleFluid::inputFromVolume (double T, double x){
if (this->xid==ifrac_pure) {
if (this->xid==IFRAC_PURE) {
return _HUGE;
} else if (this->xid==ifrac_volume) {
} else if (this->xid==IFRAC_VOLUME) {
return x;
} else {
throw NotImplementedError("Volume composition conversion has not been implemented.");
@@ -346,9 +346,9 @@ double IncompressibleFluid::inputFromVolume (double T, double x){
/** If the fluid type is mole-based, it does not do anything. Otherwise,
* it converts the mole fraction to the required input. */
double IncompressibleFluid::inputFromMole (double T, double x){
if (this->xid==ifrac_pure) {
if (this->xid==IFRAC_PURE) {
return _HUGE;
} else if (this->xid==ifrac_mole) {
} else if (this->xid==IFRAC_MOLE) {
return x;
} else {
throw NotImplementedError("Mole composition conversion has not been implemented.");

View File

@@ -1,5 +1,6 @@
#include "IncompressibleLibrary.h"
#include "MatrixMath.h"
#include "DataStructures.h"
//#include "crossplatform_shared_ptr.h"
#include "rapidjson/rapidjson_include.h"
#include "all_incompressibles_JSON.h" // Makes a std::string variable called all_incompressibles_JSON
@@ -421,16 +422,16 @@ double JSONIncompressibleLibrary::parse_value(rapidjson::Value &obj, std::string
}
/// Get an integer from the JSON storage to identify the composition
int JSONIncompressibleLibrary::parse_ifrac(rapidjson::Value &obj, std::string id){
composition_types JSONIncompressibleLibrary::parse_ifrac(rapidjson::Value &obj, std::string id){
std::string res = cpjson::get_string(obj, id);
if (!res.compare("mass")) return CoolProp::ifrac_undefined;
if (!res.compare("mole")) return CoolProp::ifrac_mole;
if (!res.compare("volume")) return CoolProp::ifrac_volume;
if (!res.compare("not defined")) return CoolProp::ifrac_undefined;
if (!res.compare("pure")) return CoolProp::ifrac_pure;
if (!res.compare("mass")) return IFRAC_UNDEFINED;
if (!res.compare("mole")) return IFRAC_MOLE;
if (!res.compare("volume")) return IFRAC_VOLUME;
if (!res.compare("not defined")) return IFRAC_UNDEFINED;
if (!res.compare("pure")) return IFRAC_PURE;
throw ValueError(format("Cannot recognise the entry for [%s], [%s] is unknown for incompressible fluids.", id.c_str(), res.c_str()));
return CoolProp::ifrac_undefined;
return IFRAC_UNDEFINED;
}
/// Add all the fluid entries in the rapidjson::Value instance passed in

View File

@@ -2,6 +2,7 @@
#ifndef INCOMPRESSIBLELIBRARY_H
#define INCOMPRESSIBLELIBRARY_H
#include "DataStructures.h"
#include "IncompressibleFluid.h"
//#include "crossplatform_shared_ptr.h"
@@ -154,7 +155,7 @@ protected:
/// A general function to parse the json files that hold the coefficient matrices
IncompressibleData parse_coefficients(rapidjson::Value &obj, std::string id, bool vital);
double parse_value(rapidjson::Value &obj, std::string id, bool vital, double def);
int parse_ifrac(rapidjson::Value &obj, std::string id);
composition_types parse_ifrac(rapidjson::Value &obj, std::string id);
public:
// Default constructor;

View File

@@ -182,7 +182,7 @@ CoolProp::IncompressibleFluid CoolPropTesting::incompressibleFluidObject(){
CH3OH.setTmin(-50 + 273.15);
CH3OH.setxmax(0.5);
CH3OH.setxmin(0.0);
CH3OH.setxid(CoolProp::ifrac_mass);
CH3OH.setxid(CoolProp::IFRAC_MASS);
CH3OH.setTminPsat( 20 + 273.15);
CH3OH.setTbase(-4.48 + 273.15);