diff --git a/include/IncompressibleFluid.h b/include/IncompressibleFluid.h index 243d2869..6993572a 100644 --- a/include/IncompressibleFluid.h +++ b/include/IncompressibleFluid.h @@ -31,7 +31,9 @@ struct IncompressibleData { INCOMPRESSIBLE_NOT_SET, INCOMPRESSIBLE_POLYNOMIAL, INCOMPRESSIBLE_EXPONENTIAL, - INCOMPRESSIBLE_EXPPOLYNOMIAL + INCOMPRESSIBLE_EXPPOLYNOMIAL, + INCOMPRESSIBLE_POLYOFFSET, + INCOMPRESSIBLE_EXPOFFSET }; Eigen::MatrixXd coeffs; //TODO: Can we store the Eigen::Matrix objects more efficiently? //std::vector > coeffs; @@ -76,7 +78,7 @@ protected: //double u_h(double T, double p, double x); public: - IncompressibleFluid(){}; + IncompressibleFluid(){name = "";}; virtual ~IncompressibleFluid(){}; std::string getName() const {return name;} @@ -97,7 +99,9 @@ public: double getTbase() const {return Tbase;} double getxbase() const {return xbase;} - void setName(std::string name) {this->name = name;} + void setName(std::string name) { + std::cout << name << "::" << this->name << std::endl; + this->name = name;} void setDescription(std::string description) {this->description = description;} void setReference(std::string reference) {this->reference = reference;} void setTmax(double Tmax) {this->Tmax = Tmax;} @@ -125,6 +129,8 @@ public: /// A function to check coefficients and equation types. void validate(); + /// + protected: /// Base function that handles the custom data type, just a place holder to show the structure. diff --git a/src/Backends/Incompressible/IncompressibleBackend.cpp b/src/Backends/Incompressible/IncompressibleBackend.cpp index 84e5aa87..e44c57c4 100644 --- a/src/Backends/Incompressible/IncompressibleBackend.cpp +++ b/src/Backends/Incompressible/IncompressibleBackend.cpp @@ -57,8 +57,9 @@ void IncompressibleBackend::update(long input_pair, double value1, double value2 if (!ValidNumber(_T)){ throw ValueError("T is not a valid number");} } +/// Get the viscosity [Pa-s] long double IncompressibleBackend::calc_viscosity(void){ - return visc(_T,_p); + return fluid->visc(_T, _p); } /// Set the mole fractions @@ -82,10 +83,6 @@ void IncompressibleBackend::check_status() { throw CoolProp::NotImplementedError("Cannot check status for incompressible fluid"); } -/// Get the viscosity [Pa-s] -long double IncompressibleBackend::calc_viscosity(void){ - throw NotImplementedError(); -} /// Get the thermal conductivity [W/m/K] (based on the temperature and density in the state class) long double IncompressibleBackend::calc_conductivity(void){ throw NotImplementedError(); diff --git a/src/Backends/Incompressible/IncompressibleLibrary.cpp b/src/Backends/Incompressible/IncompressibleLibrary.cpp index 528e9f79..4812b200 100644 --- a/src/Backends/Incompressible/IncompressibleLibrary.cpp +++ b/src/Backends/Incompressible/IncompressibleLibrary.cpp @@ -1,7 +1,7 @@ #include "IncompressibleLibrary.h" #include "MatrixMath.h" #include "rapidjson/rapidjson_include.h" -#include "all_incompressibles_JSON.h" // Makes a std::string variable called all_fluids_JSON +#include "all_incompressibles_JSON.h" // Makes a std::string variable called all_incompressibles_JSON namespace CoolProp{ @@ -28,9 +28,22 @@ IncompressibleData JSONIncompressibleLibrary::parse_coefficients(rapidjson::Valu fluidData.coeffs = vec_to_eigen(cpjson::get_double_array2D(obj[id.c_str()]["coeffs"])); return fluidData; } - else{ + else if (!type.compare("expoffset")){ + fluidData.type = CoolProp::IncompressibleData::INCOMPRESSIBLE_EXPOFFSET; + fluidData.coeffs = vec_to_eigen(cpjson::get_double_array(obj[id.c_str()]["coeffs"])); + return fluidData; + } + else if (!type.compare("polyoffset")){ + fluidData.type = CoolProp::IncompressibleData::INCOMPRESSIBLE_POLYOFFSET; + fluidData.coeffs = vec_to_eigen(cpjson::get_double_array2D(obj[id.c_str()]["coeffs"])); + return fluidData; + } + else if (vital){ throw ValueError(format("The type [%s] is not understood for [%s] of incompressible fluids. Please check your JSON file.", type.c_str(), id.c_str())); } + else{ + std::cout << format("The type [%s] is not understood for [%s] of incompressible fluids. Please check your JSON file.\n", type.c_str(), id.c_str()); + } } else{ throw ValueError(format("Your file does not have an entry for \"coeffs\" in [%s], which is vital for this function.", id.c_str())); @@ -50,7 +63,9 @@ IncompressibleData JSONIncompressibleLibrary::parse_coefficients(rapidjson::Valu /// Get a double from the JSON storage if it is defined, otherwise return def double JSONIncompressibleLibrary::parse_value(rapidjson::Value &obj, std::string id, bool vital, double def=0.0){ - if (obj.HasMember(id.c_str())) {return cpjson::get_double(obj, id);} + if (obj.HasMember(id.c_str())) { + return cpjson::get_double(obj, id); + } else{ if (vital) { throw ValueError(format("Your file does not have information for [%s], which is vital for an incompressible fluid.", id.c_str())); @@ -81,7 +96,6 @@ void JSONIncompressibleLibrary::add_one(rapidjson::Value &fluid_json) { // Create an instance of the fluid IncompressibleFluid &fluid = fluid_map[index]; - fluid.setName(cpjson::get_string(fluid_json, "name")); fluid.setDescription(cpjson::get_string(fluid_json, "description")); fluid.setReference(cpjson::get_string(fluid_json, "reference")); @@ -113,7 +127,8 @@ void JSONIncompressibleLibrary::add_one(rapidjson::Value &fluid_json) { ); /// A function to check coefficients and equation types. - fluid.validate(); + /// \todo Implement the validation function + //fluid.validate(); // Add name->index mapping string_to_index_map[fluid.getName()] = index; @@ -141,7 +156,7 @@ IncompressibleFluid& JSONIncompressibleLibrary::get(std::string key) { } }; -/// Get a CoolPropFluid instance stored in this library +/// Get a IncompressibleFluid instance stored in this library /** @param key The index of the fluid in the map */ @@ -187,10 +202,10 @@ static JSONIncompressibleLibrary library; void load_incompressible_library() { rapidjson::Document dd; - // This json formatted string comes from the all_fluids_JSON.h header which is a C++-escaped version of the JSON file + // This json formatted string comes from the all_incompressibles_JSON.h header which is a C++-escaped version of the JSON file dd.Parse<0>(all_incompressibles_JSON.c_str()); if (dd.HasParseError()){ - throw ValueError("Unable to load all_fluids.json"); + throw ValueError("Unable to load all_incompressibles_JSON.json"); } else{ try{library.add_many(dd);}catch(std::exception &e){std::cout << e.what() << std::endl;} }