mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-01 03:00:13 -04:00
A little bit on polynomials
This commit is contained in:
@@ -276,10 +276,19 @@ template<class T> std::string vec_to_string(const std::vector<std::vector<T> > &
|
||||
//template<class T> std::string vec_to_string(std::vector<std::vector<T> > const& A, const char *fmt);
|
||||
|
||||
|
||||
// Forward definitions
|
||||
template<class T> std::size_t num_rows (std::vector<std::vector<T> > const& in);
|
||||
template<class T> std::size_t max_cols (std::vector<std::vector<T> > const& in);
|
||||
/// Some shortcuts and regularly needed operations
|
||||
template<class T> std::size_t num_rows ( std::vector<T> const& in){ return in.size(); }
|
||||
template<class T> std::size_t num_rows (std::vector<std::vector<T> > const& in){ return in.size(); }
|
||||
|
||||
template<class T> std::size_t max_cols (std::vector<std::vector<T> > const& in){
|
||||
std::size_t cols = 0;
|
||||
std::size_t col = 0;
|
||||
for (std::size_t i = 0; i < in.size(); i++) {
|
||||
col = in[i].size();
|
||||
if (cols<col) {cols = col;}
|
||||
}
|
||||
return cols;
|
||||
};
|
||||
template<class T> bool is_squared(std::vector<std::vector<T> > const& in){
|
||||
std::size_t cols = max_cols(in);
|
||||
if (cols!=num_rows(in)) { return false;}
|
||||
@@ -290,20 +299,8 @@ template<class T> bool is_squared(std::vector<std::vector<T> > co
|
||||
}
|
||||
return true;
|
||||
};
|
||||
template<class T> std::size_t max_cols (std::vector<std::vector<T> > const& in){
|
||||
std::size_t cols = 0;
|
||||
std::size_t col = 0;
|
||||
for (std::size_t i = 0; i < in.size(); i++) {
|
||||
col = in[i].size();
|
||||
if (cols<col) {cols = col;}
|
||||
}
|
||||
return cols;
|
||||
};
|
||||
|
||||
/// Some shortcuts and regularly needed operations
|
||||
template<class T> std::size_t num_rows ( std::vector<T> const& in){ return in.size(); }
|
||||
template<class T> std::size_t num_cols ( std::vector<T> const& in){ return 1; }
|
||||
template<class T> std::size_t num_rows (std::vector<std::vector<T> > const& in){ return in.size(); }
|
||||
template<class T> std::size_t num_cols (std::vector<std::vector<T> > const& in){
|
||||
if (num_rows(in)>0) {
|
||||
if (is_squared(in)) {
|
||||
|
||||
@@ -120,9 +120,17 @@ public:
|
||||
/// Basic checks for coefficient vectors.
|
||||
/** Starts with only the first coefficient dimension
|
||||
* and checks the matrix size against the parameters rows and columns. */
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial
|
||||
bool checkCoefficients(const unsigned int rows);
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial in the 1st dimension
|
||||
/// @param columns unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension
|
||||
bool checkCoefficients(const unsigned int rows, const unsigned int columns);
|
||||
/// @param coefficients vector containing the ordered coefficients
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial
|
||||
bool checkCoefficients(const Eigen::VectorXd &coefficients, const unsigned int rows);
|
||||
/// @param coefficients vector containing the ordered coefficients
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial
|
||||
bool checkCoefficients(const std::vector<double> &coefficients, const unsigned int rows);
|
||||
/// @param coefficients matrix containing the ordered coefficients
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial in the 1st dimension
|
||||
/// @param columns unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension
|
||||
@@ -147,7 +155,7 @@ protected:
|
||||
Eigen::MatrixXd integrateCoeffs(const Eigen::MatrixXd &coefficients, unsigned int axis = 1);
|
||||
/// @param coefficients matrix containing the ordered coefficients
|
||||
/// @param axis unsigned integer value that represents the desired direction of integration
|
||||
std::vector<std::vector<double> > integrateCoeffs(const std::vector<std::vector<double> > &coefficients, unsigned int axis = 1);
|
||||
//std::vector<std::vector<double> > integrateCoeffs(const std::vector<std::vector<double> > &coefficients, unsigned int axis = 1);
|
||||
|
||||
/// Derivative coefficients calculation
|
||||
/** Deriving coefficients for polynomials is done by multiplying the
|
||||
@@ -161,7 +169,7 @@ protected:
|
||||
Eigen::MatrixXd deriveCoeffs(const Eigen::MatrixXd &coefficients, unsigned int axis = 1);
|
||||
/// @param coefficients matrix containing the ordered coefficients
|
||||
/// @param axis unsigned integer value that represents the desired direction of derivation
|
||||
std::vector<std::vector<double> > deriveCoeffs(const std::vector<std::vector<double> > &coefficients, unsigned int axis = 1);
|
||||
//std::vector<std::vector<double> > deriveCoeffs(const std::vector<std::vector<double> > &coefficients, unsigned int axis = 1);
|
||||
|
||||
public:
|
||||
/// The core functions to evaluate the polynomial
|
||||
|
||||
@@ -24,30 +24,74 @@ void Polynomial2D::setCoefficients(const Eigen::MatrixXd &coefficients){
|
||||
this->coefficients = coefficients;
|
||||
}
|
||||
void Polynomial2D::setCoefficients(const std::vector<std::vector<double> > &coefficients){
|
||||
int c = num_cols(coefficients);
|
||||
int r = num_rows(coefficients);
|
||||
std::size_t c = num_cols(coefficients), r = num_rows(coefficients);
|
||||
Eigen::MatrixXd tmp = Eigen::MatrixXd::Constant(r,c,0.0);
|
||||
std::cout << "Rows: " << r << " Columns: " << c << std::endl;
|
||||
std::cout << "Rows: " << tmp.rows() << " Columns: " << tmp.cols() << std::endl;
|
||||
convert(coefficients,tmp);
|
||||
this->setCoefficients(tmp);
|
||||
}
|
||||
|
||||
/// Basic checks for coefficient vectors.
|
||||
/** Starts with only the first coefficient dimension
|
||||
* and checks the matrix size against the parameters rows and columns. */
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial
|
||||
bool Polynomial2D::checkCoefficients(const unsigned int rows);
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial in the 1st dimension
|
||||
/// @param columns unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension
|
||||
bool Polynomial2D::checkCoefficients(const unsigned int rows, const unsigned int columns);
|
||||
/// @param coefficients vector containing the ordered coefficients
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial
|
||||
bool Polynomial2D::checkCoefficients(const Eigen::VectorXd &coefficients, const unsigned int rows){
|
||||
if (coefficients.rows() == rows){
|
||||
return true;
|
||||
} else {
|
||||
throw ValueError(format("The number of coefficients %d does not match with %d. ",coefficients.rows(),rows));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// @param coefficients vector containing the ordered coefficients
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial
|
||||
bool Polynomial2D::checkCoefficients(const std::vector<double> &coefficients, const unsigned int rows){
|
||||
if (coefficients.size() == rows){
|
||||
return true;
|
||||
} else {
|
||||
throw ValueError(format("The number of coefficients %d does not match with %d. ",coefficients.size(),rows));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// @param coefficients matrix containing the ordered coefficients
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial in the 1st dimension
|
||||
/// @param columns unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension
|
||||
bool Polynomial2D::checkCoefficients(const Eigen::MatrixXd &coefficients, const unsigned int rows, const unsigned int columns);
|
||||
/// @param coefficients matrix containing the ordered coefficients
|
||||
/// @param rows unsigned integer value that represents the desired degree of the polynomial in the 1st dimension
|
||||
/// @param columns unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension
|
||||
bool Polynomial2D::checkCoefficients(const std::vector<std::vector<double> > &coefficients, const unsigned int rows, const unsigned int columns);
|
||||
|
||||
|
||||
|
||||
///// Basic checks for coefficient vectors.
|
||||
///** Starts with only the first coefficient dimension
|
||||
// * and checks the matrix size against the parameters rows and columns. */
|
||||
///// @param rows unsigned integer value that represents the desired degree of the polynomial in the 1st dimension
|
||||
///// @param columns unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension
|
||||
//bool Polynomial2D::checkCoefficients(const unsigned int rows, const unsigned int columns);
|
||||
///// @param coefficients matrix containing the ordered coefficients
|
||||
///// @param rows unsigned integer value that represents the desired degree of the polynomial in the 1st dimension
|
||||
///// @param columns unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension
|
||||
//bool Polynomial2D::checkCoefficients(const Eigen::MatrixXd &coefficients, const unsigned int rows, const unsigned int columns);
|
||||
///// @param coefficients matrix containing the ordered coefficients
|
||||
///// @param rows unsigned integer value that represents the desired degree of the polynomial in the 1st dimension
|
||||
///// @param columns unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension
|
||||
//bool Polynomial2D::checkCoefficients(const std::vector<std::vector<double> > &coefficients, const unsigned int rows, const unsigned int columns);
|
||||
//
|
||||
// * and checks the vector length against parameter n. */
|
||||
//bool BasePolynomial::checkCoefficients(const std::vector<double> &coefficients, unsigned int n){
|
||||
|
||||
//bool BasePolynomial::checkCoefficients(std::vector< std::vector<double> > const& coefficients, unsigned int rows, unsigned int columns){
|
||||
// if (coefficients.size() == rows){
|
||||
// bool result = true;
|
||||
// for(unsigned int i=0; i<rows; i++) {
|
||||
// result = result && checkCoefficients(coefficients[i],columns);
|
||||
// }
|
||||
// return result;
|
||||
// } else {
|
||||
// throw ValueError(format("The number of rows %d does not match with %d. ",coefficients.size(),rows));
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///// Integration functions
|
||||
///** Integrating coefficients for polynomials is done by dividing the
|
||||
// * original coefficients by (i+1) and elevating the order by 1
|
||||
|
||||
Reference in New Issue
Block a user