diff --git a/include/Ancillaries.h b/include/Ancillaries.h index 3d0d8734..9c04d752 100644 --- a/include/Ancillaries.h +++ b/include/Ancillaries.h @@ -82,15 +82,21 @@ class SaturationAncillaryFunction private: Eigen::MatrixXd num_coeffs, ///< Coefficients for numerator in rational polynomial den_coeffs; ///< Coefficients for denominator in rational polynomial - std::vector n, t, s; - bool using_tau_r; - CoolPropDbl Tmax, Tmin, reducing_value, T_r, max_abs_error; + std::vector n, t, s; // For TYPE_NOT_EXPONENTIAL & TYPE_EXPONENTIAL + union{ + CoolPropDbl max_abs_error; // For TYPE_RATIONAL_POLYNOMIAL + struct{ // For TYPE_NOT_EXPONENTIAL & TYPE_EXPONENTIAL + bool using_tau_r; + CoolPropDbl reducing_value, T_r; + std::size_t N; + }; + }; + CoolPropDbl Tmax, Tmin; enum ancillaryfunctiontypes{TYPE_NOT_SET = 0, TYPE_NOT_EXPONENTIAL, TYPE_EXPONENTIAL, TYPE_RATIONAL_POLYNOMIAL}; ancillaryfunctiontypes type; - std::size_t N; public: SaturationAncillaryFunction(){type = TYPE_NOT_SET;}; diff --git a/src/Backends/Helmholtz/Fluids/Ancillaries.cpp b/src/Backends/Helmholtz/Fluids/Ancillaries.cpp index ccc88af0..a3231d99 100644 --- a/src/Backends/Helmholtz/Fluids/Ancillaries.cpp +++ b/src/Backends/Helmholtz/Fluids/Ancillaries.cpp @@ -16,6 +16,7 @@ SaturationAncillaryFunction::SaturationAncillaryFunction(rapidjson::Value &json_ std::string type = cpjson::get_string(json_code,"type"); if (!type.compare("rational_polynomial")) { + this->type = TYPE_RATIONAL_POLYNOMIAL; num_coeffs = vec_to_eigen(cpjson::get_double_array(json_code["A"])); den_coeffs = vec_to_eigen(cpjson::get_double_array(json_code["B"])); max_abs_error = cpjson::get_double(json_code,"max_abs_error"); @@ -30,7 +31,13 @@ SaturationAncillaryFunction::SaturationAncillaryFunction(rapidjson::Value &json_ } else { + if (!type.compare("rhoLnoexp")) + this->type = TYPE_NOT_EXPONENTIAL; + else + this->type = TYPE_EXPONENTIAL; n = cpjson::get_double_array(json_code["n"]); + N = n.size(); + s = n; t = cpjson::get_double_array(json_code["t"]); Tmin = cpjson::get_double(json_code,"Tmin"); Tmax = cpjson::get_double(json_code,"Tmax"); @@ -39,14 +46,6 @@ SaturationAncillaryFunction::SaturationAncillaryFunction(rapidjson::Value &json_ T_r = cpjson::get_double(json_code,"T_r"); } - if (!type.compare("rational_polynomial")) - this->type = TYPE_RATIONAL_POLYNOMIAL; - else if (!type.compare("rhoLnoexp")) - this->type = TYPE_NOT_EXPONENTIAL; - else - this->type = TYPE_EXPONENTIAL; - this->N = n.size(); - s = n; }; double SaturationAncillaryFunction::evaluate(double T)