diff --git a/include/MatrixMath.h b/include/MatrixMath.h index 88868e43..dfc1acdc 100644 --- a/include/MatrixMath.h +++ b/include/MatrixMath.h @@ -20,17 +20,108 @@ template struct VectorNd { typedef std::vector< typename VectorNd::type > type; }; - -//template struct VectorNd<1,T> { -// typedef std::vector< T > type; -//}; - template struct VectorNd<0,T> { typedef T type; }; namespace CoolProp{ +/// Templates for printing numbers, vectors and matrices +static const char* stdFmt = "%7.3f"; + +///Templates for turning vectors (1D-matrices) into strings +template std::string vec_to_string(const std::vector &a, const char *fmt) { + if (a.size()<1) return std::string(""); + std::stringstream out; + out << "[ " << format(fmt,a[0]); + for (size_t j = 1; j < a.size(); j++) { + out << ", " << format(fmt, a[j]); + } + out << " ]"; + return out.str(); +}; +template std::string vec_to_string(const std::vector &a) { + return vec_to_string(a, stdFmt); +}; + +/// Templates for turning numbers (0D-matrices) into strings +template std::string vec_to_string(const T &a, const char *fmt) { + std::vector vec; + vec.push_back(a); + return vec_to_string(vec, fmt); +}; +template std::string vec_to_string(const T &a) { + return vec_to_string(a, stdFmt); +}; + +///Templates for turning 2D-matrices into strings +template std::string vec_to_string(const std::vector > &A, const char *fmt) { + if (A.size()<1) return std::string(""); + std::stringstream out; + out << "[ " << vec_to_string(A[0], fmt); + for (size_t j = 1; j < A.size(); j++) { + out << ", " << std::endl << " " << vec_to_string(A[j], fmt); + } + out << " ]"; + return out.str(); +}; +template std::string vec_to_string(const std::vector > &A) { + return vec_to_string(A, stdFmt); +}; + + +/// Template class for turning numbers (0D-matrices) into strings +//template std::string vec_to_string(const T &a){ +// return vec_to_string(a, stdFmt); +// std::stringstream out; +// out << format("[ %7.3f ]",a); +// return out.str(); +//}; +//template std::string vec_to_string(const VectorNd<0, T> &a){ +// return vec_to_string(a, stdFmt); +//}; +//template std::string vec_to_string(const VectorNd<0, T> &a, const char *fmt) { +// VectorNd<1, T> vec; +// vec.push_back(a); +// return vec_to_string(vec, fmt); +//}; +// +/////Template classes for turning vectors (1D-matrices) into strings +//template std::string vec_to_string(const VectorNd<1, T> &a) { +// return vec_to_string(a, stdFmt); +//}; +//template std::string vec_to_string(const VectorNd<1, T> &a, const char *fmt) { +// if (a.size()<1) { +// return std::string(""); +// } else { +// std::stringstream out; +// out << "[ "; +// out << format(fmt,a[0]); +// for (size_t j = 1; j < a.size(); j++) { +// out << ", "; +// out << format(fmt,a[j]); +// } +// out << " ]"; +// return out.str(); +// } +//}; +// +/////Template classes for turning 2D-matrices into strings +//template std::string vec_to_string(const VectorNd<2, T> &A) { +// return vec_to_string(A, stdFmt); +//} +//template std::string vec_to_string(const VectorNd<2, T> &A, const char *fmt) { +// if (A.size()<1) return std::string(""); +// std::stringstream out; +// out << "[ " << format(fmt,A[0]); +// for (size_t j = 1; j < A.size(); j++) { +// out << ", " << std::endl << " " << vec_to_string(A[j], fmt); +// } +// out << " ]"; +// return out.str(); +//} + + ///// Publish the linear algebra solver //template std::vector linsolve(std::vector > const& A, std::vector const& b); //template std::vector > linsolve(std::vector > const& A, std::vector > const& B); @@ -418,104 +509,6 @@ template std::vector< std::vector > invert(std::vector std::string vec_to_string( T const& a, const char *fmt) { - //std::vector vec; - //vec.push_back(a); - //return vec_to_string(vec, fmt); - std::stringstream out; - out << "[ " << format(fmt,a); - return out.str(); -}; -template std::string vec_to_string( T const& a){ - return vec_to_string(a, stdFmt); -}; - -///Template classes for turning vectors (1D-matrices) into strings -template std::string vec_to_string( std::vector const& a) { - return vec_to_string(a,stdFmt); -}; -template std::string vec_to_string( std::vector const& a, const char *fmt) { - if (a.size()<1) return std::string(""); - std::stringstream out; - out << "[ " << format(fmt,a[0]); - for (size_t j = 1; j < a.size(); j++) { - out << ", " << format(fmt, a[j]); - } - out << " ]"; - return out.str(); -}; - -///Template classes for turning 2D-matrices into strings -template std::string vec_to_string(std::vector > const& A) { - return vec_to_string(A, stdFmt); -}; -template std::string vec_to_string(std::vector > const& A, const char *fmt) { - if (A.size()<1) return std::string(""); - std::stringstream out; - out << "[ " << format(fmt,A[0]); - for (size_t j = 1; j < A.size(); j++) { - out << ", " << std::endl << " " << vec_to_string(A[j], fmt); - } - out << " ]"; - return out.str(); -}; - - -///// Template class for turning numbers (0D-matrices) into strings -////template std::string vec_to_string(const T &a){ -//// return vec_to_string(a, stdFmt); -//// std::stringstream out; -//// out << format("[ %7.3f ]",a); -//// return out.str(); -////}; -////template std::string vec_to_string(const VectorNd<0, T> &a){ -//// return vec_to_string(a, stdFmt); -////}; -////template std::string vec_to_string(const VectorNd<0, T> &a, const char *fmt) { -//// VectorNd<1, T> vec; -//// vec.push_back(a); -//// return vec_to_string(vec, fmt); -////}; -// -/////Template classes for turning vectors (1D-matrices) into strings -//template std::string vec_to_string(const VectorNd<1, T> &a) { -// return vec_to_string(a, stdFmt); -//}; -//template std::string vec_to_string(const VectorNd<1, T> &a, const char *fmt) { -// if (a.size()<1) { -// return std::string(""); -// } else { -// std::stringstream out; -// out << "[ "; -// out << format(fmt,a[0]); -// for (size_t j = 1; j < a.size(); j++) { -// out << ", "; -// out << format(fmt,a[j]); -// } -// out << " ]"; -// return out.str(); -// } -//}; -// -/////Template classes for turning 2D-matrices into strings -//template std::string vec_to_string(const VectorNd<2, T> &A) { -// return vec_to_string(A, stdFmt); -//} -//template std::string vec_to_string(const VectorNd<2, T> &A, const char *fmt) { -// if (A.size()<1) return std::string(""); -// std::stringstream out; -// out << "[ " << format(fmt,A[0]); -// for (size_t j = 1; j < A.size(); j++) { -// out << ", " << std::endl << " " << vec_to_string(A[j], fmt); -// } -// out << " ]"; -// return out.str(); -//} - }; /* namespace CoolProp */ diff --git a/include/PolyMath.h b/include/PolyMath.h index e59c6582..649b587f 100644 --- a/include/PolyMath.h +++ b/include/PolyMath.h @@ -20,6 +20,8 @@ namespace CoolProp{ + + /// The base class for Polynomials class BasePolynomial{ @@ -35,8 +37,6 @@ public: * and checks the vector length against parameter n. */ bool checkCoefficients(const Eigen::VectorXd &coefficients, const unsigned int n); bool checkCoefficients(const Eigen::MatrixXd &coefficients, const unsigned int rows, const unsigned int columns); - bool checkCoefficients(const vectorNd<1, double>::type &coefficients, const unsigned int n); - bool checkCoefficients(const vectorNd<2, double>::type &coefficients, const unsigned int rows, const unsigned int columns); bool checkCoefficients(const std::vector &coefficients, const unsigned int n); bool checkCoefficients(const std::vector< std::vector > &coefficients, const unsigned int rows, const unsigned int columns); diff --git a/src/MatrixMath.cpp b/src/MatrixMath.cpp index 7254865c..4d868ad4 100644 --- a/src/MatrixMath.cpp +++ b/src/MatrixMath.cpp @@ -12,6 +12,21 @@ namespace CoolProp{ + + + + + + + + + + + + + + + ///* //Owe a debt of gratitude to http://sole.ooz.ie/en - very clear treatment of GJ //*/ diff --git a/src/Tests/eigenTest.cpp b/src/Tests/eigenTest.cpp index 77907021..76a3d89c 100644 --- a/src/Tests/eigenTest.cpp +++ b/src/Tests/eigenTest.cpp @@ -4,6 +4,7 @@ //using namespace std; #include +#include #include int main() @@ -30,9 +31,14 @@ double eval = Eigen::poly_eval( coeffs, input); std::cout << "Evaluation of the polynomial at " << input << std::endl; std::cout << eval << std::endl; -//std::vector vec(2,0.2); -//std::cout << CoolProp::vec_to_string(vec) << std::endl; +double vec0 = 0.1; +std::vector vec1(2,0.2); +std::vector< std::vector > vec2; +vec2.push_back(std::vector(2,0.2)); +vec2.push_back(std::vector(2,0.3)); -std::cout << CoolProp::vec_to_string(0.3) << std::endl; +std::cout << CoolProp::vec_to_string(vec0) << std::endl; +std::cout << CoolProp::vec_to_string(vec1) << std::endl; +std::cout << CoolProp::vec_to_string(vec2) << std::endl; }