CoolProp
PolyMath.h
1 #ifndef POLYMATH_H
2 #define POLYMATH_H
3
4 #include "CoolProp.h"
5 #include "CoolPropTools.h"
6 #include "Exceptions.h"
7
8 #include <vector>
9 #include <string>
10 #include "Solvers.h"
11 #include "MatrixMath.h"
12 #include "unsupported/Eigen/Polynomials"
13
14 namespace CoolProp{
15
16 // Just a forward declaration
17 class Poly2DResidual;
18 class Poly2DFracResidual;
19
21
24 class Polynomial2D {
25
26 public:
29
31  virtual ~Polynomial2D(){};
32
33 public:
36  Eigen::MatrixXd convertCoefficients(const std::vector<double> &coefficients){return vec_to_eigen(coefficients);}
39  Eigen::MatrixXd convertCoefficients(const std::vector<std::vector<double> > &coefficients){return vec_to_eigen(coefficients);}
40
42
44  bool checkCoefficients(const Eigen::MatrixXd &coefficients, const unsigned int rows, const unsigned int columns);
48
49 public:
51
59  Eigen::MatrixXd integrateCoeffs(const Eigen::MatrixXd &coefficients, const int &axis, const int &times);
63
65
68  Eigen::MatrixXd deriveCoeffs(const Eigen::MatrixXd &coefficients, const int &axis=-1, const int &times=1);
72
73 public:
75
85  double evaluate(const Eigen::MatrixXd &coefficients, const double &x_in);
88
92  double evaluate(const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in);
93
98  double derivative(const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis);
99
104  double integral(const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis);
105
106 protected:
107  // TODO: Why doe these base definitions not work with derived classes?
112  double solve_limits(Poly2DResidual* res, const double &min, const double &max);
113
114  // TODO: Why doe these base definitions not work with derived classes?
118  double solve_guess(Poly2DResidual* res, const double &guess);
119
120 public:
126  Eigen::VectorXd solve(const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const int &axis);
127
135  double solve_limits(const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &min, const double &max, const int &axis);
136
143  double solve_guess(const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &guess, const int &axis);
144
145
146 protected:
148
151  double simplePolynomial(const std::vector<double> &coefficients, double x);
152  DEPRECATED(double simplePolynomial(const std::vector<std::vector<double> > &coefficients, double x, double y));
154
159  double baseHorner(const std::vector<double> &coefficients, double x);
160  DEPRECATED(double baseHorner(const std::vector<std::vector<double> > &coefficients, double x, double y));
161
162  bool do_debug(void){return get_debug_level()>=500;}
163
164 };
165
166
168 protected:
169  enum dims {iX, iY};
170  Eigen::MatrixXd coefficients;
171  bool derIsSet;
172  Eigen::MatrixXd coefficientsDer;
173  int axis;
175  double in;
179  double z_in;
180
181 protected:
182  Poly2DResidual();
183
184 public:
191  Poly2DResidual(Polynomial2D &poly, const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const int &axis);
192  virtual ~Poly2DResidual(){};
193
194  double call(double target);
195  double deriv(double target);
196 };
197
198
200
207
208 public:
211
213  virtual ~Polynomial2DFrac(){};
214
215 public:
216 // /// Integration functions
217 // /** Integrating coefficients for polynomials is done by dividing the
218 // * original coefficients by (i+1) and elevating the order by 1
219 // * through adding a zero as first coefficient.
220 // * Some reslicing needs to be applied to integrate along the x-axis.
221 // * In the brine/solution equations, reordering of the parameters
222 // * avoids this expensive operation. However, it is included for the
223 // * sake of completeness.
224 // */
225 // /// @param coefficients matrix containing the ordered coefficients
226 // /// @param axis unsigned integer value that represents the desired direction of integration
227 // /// @param times integer value that represents the desired order of integration
228 // /// @param firstExponent integer value that represents the first exponent of the polynomial in axis direction
229 // Eigen::MatrixXd integrateCoeffs(const Eigen::MatrixXd &coefficients, const int &axis, const int &times, const int &firstExponent);
230 //
232
240  Eigen::MatrixXd deriveCoeffs(const Eigen::MatrixXd &coefficients, const int &axis, const int &times, const int &firstExponent);
245
246 public:
248
258  double evaluate(const Eigen::MatrixXd &coefficients, const double &x_in, const int &firstExponent=0, const double &x_base=0.0);
263
271  double evaluate(const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0);
272
281  double derivative(const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0);
282
292  double integral(const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0, const double &ax_val=0.0);
293
294 public:
304  Eigen::VectorXd solve(const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0);
305
317  double solve_limits(const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &min, const double &max, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0);
318
329  double solve_guess(const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &guess, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0);
330
343  double solve_limitsInt(const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &min, const double &max, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0, const int &int_axis=0);
344
356  double solve_guessInt(const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &guess, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0, const int &int_axis=0);
357
358 protected:
360  double factorial(const int &nValue);
361
364  double binom(const int &nValue, const int &nValue2);
365
370  Eigen::MatrixXd fracIntCentralDvector(const int &m, const double &x_in, const double &x_base);
371
376  double fracIntCentral(const Eigen::MatrixXd &coefficients, const double &x_in, const double &x_base);
377
378 };
379
381 protected:
382  int x_exp, y_exp;
383  double x_base, y_base;
386
387 protected:
389
390 public:
401  Poly2DFracResidual(Polynomial2DFrac &poly, const Eigen::MatrixXd &coefficients,
402  const double &in, const double &z_in, const int &axis,
403  const int &x_exp, const int &y_exp, const double &x_base, const double &y_base);
404  virtual ~Poly2DFracResidual(){};
405  double call(double target);
406  double deriv(double target);
407 };
408
410
411 protected:
412  int int_axis;
414
415 public:
427  Poly2DFracIntResidual(Polynomial2DFrac &poly, const Eigen::MatrixXd &coefficients,
428  const double &in, const double &z_in, const int &axis,
429  const int &x_exp, const int &y_exp, const double &x_base, const double &y_base,
430  const int &int_axis);
431  virtual ~Poly2DFracIntResidual(){};
432  double call(double target);
433  double deriv(double target);
434 };
435
436
437
438 //
439 //
440 //
441 //
442 //
443 //
444 //
445 //
446 //
448 //class BasePolynomial{
449 //
450 //public:
451 // // Constructor
452 // BasePolynomial();
453 // // Destructor. No implementation
454 // virtual ~BasePolynomial(){};
455 //
456 //public:
457 // /// Basic checks for coefficient vectors.
458 // /** Starts with only the first coefficient dimension
459 // * and checks the vector length against parameter n. */
460 // bool checkCoefficients(const Eigen::VectorXd &coefficients, const unsigned int n);
461 // bool checkCoefficients(const Eigen::MatrixXd &coefficients, const unsigned int rows, const unsigned int columns);
462 // bool checkCoefficients(const std::vector<double> &coefficients, const unsigned int n);
463 // bool checkCoefficients(const std::vector< std::vector<double> > &coefficients, const unsigned int rows, const unsigned int columns);
464 //
465 // /** Integrating coefficients for polynomials is done by dividing the
466 // * original coefficients by (i+1) and elevating the order by 1
467 // * through adding a zero as first coefficient.
468 // * Some reslicing needs to be applied to integrate along the x-axis.
469 // * In the brine/solution equations, reordering of the parameters
470 // * avoids this expensive operation. However, it is included for the
471 // * sake of completeness.
472 // */
473 // std::vector<double> integrateCoeffs(const std::vector<double> &coefficients);
474 // std::vector< std::vector<double> > integrateCoeffs(const std::vector< std::vector<double> > &coefficients, bool axis);
475 //
476 // /** Deriving coefficients for polynomials is done by multiplying the
477 // * original coefficients with i and lowering the order by 1.
478 // *
479 // * It is not really deprecated, but untested and therefore a warning
480 // * is issued. Please check this method before you use it.
481 // */
482 // std::vector<double> deriveCoeffs(const std::vector<double> &coefficients);
483 // std::vector< std::vector<double> > deriveCoeffs(const std::vector< std::vector<double> > &coefficients, unsigned int axis);
484 //
485 //private:
486 // /** The core of the polynomial wrappers are the different
487 // * implementations that follow below. In case there are
488 // * new calculation schemes available, please do not delete
489 // * the implementations, but mark them as deprecated.
490 // * The old functions are good for debugging since the
491 // * structure is easier to read than the backward Horner-scheme
492 // * or the recursive Horner-scheme.
493 // */
494 //
495 // /// Simple polynomial function generator. <- Deprecated due to poor performance, use Horner-scheme instead
496 // /** Base function to produce n-th order polynomials
497 // * based on the length of the coefficient vector.
498 // * Starts with only the first coefficient at x^0. */
499 // DEPRECATED(double simplePolynomial(const std::vector<double> &coefficients, double x));
500 // DEPRECATED(double simplePolynomial(const std::vector<std::vector<double> > &coefficients, double x, double y));
501 //
502 // /// Simple integrated polynomial function generator.
503 // /** Base function to produce integrals of n-th order polynomials based on
504 // * the length of the coefficient vector.
505 // * Starts with only the first coefficient at x^0 */
506 // ///Indefinite integral in x-direction
507 // double simplePolynomialInt(const std::vector<double> &coefficients, double x);
508 // ///Indefinite integral in y-direction only
509 // double simplePolynomialInt(const std::vector<std::vector<double> > &coefficients, double x, double y);
510 //
511 // /// Simple integrated polynomial function generator divided by independent variable.
512 // /** Base function to produce integrals of n-th order
513 // * polynomials based on the length of the coefficient
514 // * vector. Starts with only the first coefficient at x^0 */
515 // ///Indefinite integral of a polynomial divided by its independent variable
516 // double simpleFracInt(const std::vector<double> &coefficients, double x);
517 // ///Indefinite integral of a polynomial divided by its 2nd independent variable
518 // double simpleFracInt(const std::vector<std::vector<double> > &coefficients, double x, double y);
519 //
520 // /** Simple integrated centred(!) polynomial function generator divided by independent variable.
521 // * We need to rewrite some of the functions in order to
522 // * use central fit. Having a central temperature xbase
523 // * allows for a better fit, but requires a different
524 // * formulation of the fracInt function group. Other
525 // * functions are not affected.
526 // * Starts with only the first coefficient at x^0 */
527 // ///Helper function to calculate the D vector:
528 // double factorial(double nValue);
529 // double binom(double nValue, double nValue2);
530 // std::vector<double> fracIntCentralDvector(int m, double x, double xbase);
531 // ///Indefinite integral of a centred polynomial divided by its independent variable
532 // double fracIntCentral(const std::vector<double> &coefficients, double x, double xbase);
533 //
534 // /// Horner function generator implementations
535 // /** Represent polynomials according to Horner's scheme.
536 // * This avoids unnecessary multiplication and thus
537 // * speeds up calculation.
538 // */
539 // double baseHorner(const std::vector<double> &coefficients, double x);
540 // double baseHorner(const std::vector< std::vector<double> > &coefficients, double x, double y);
541 // ///Indefinite integral in x-direction
542 // double baseHornerInt(const std::vector<double> &coefficients, double x);
543 // ///Indefinite integral in y-direction only
544 // double baseHornerInt(const std::vector<std::vector<double> > &coefficients, double x, double y);
545 // ///Indefinite integral of a polynomial divided by its independent variable
546 // double baseHornerFracInt(const std::vector<double> &coefficients, double x);
547 // ///Indefinite integral of a polynomial divided by its 2nd independent variable
548 // double baseHornerFracInt(const std::vector<std::vector<double> > &coefficients, double x, double y);
549 //
550 // /** Alternatives
551 // * Simple functions that heavily rely on other parts of this file.
552 // * We still need to check which combinations yield the best
553 // * performance.
554 // */
555 // ///Derivative in x-direction
556 // double deriveIn2Steps(const std::vector<double> &coefficients, double x); // TODO: Check results!
557 // ///Derivative in terms of x(axis=true) or y(axis=false).
558 // double deriveIn2Steps(const std::vector< std::vector<double> > &coefficients, double x, double y, bool axis); // TODO: Check results!
559 // ///Indefinite integral in x-direction
560 // double integrateIn2Steps(const std::vector<double> &coefficients, double x);
561 // ///Indefinite integral in terms of x(axis=true) or y(axis=false).
562 // double integrateIn2Steps(const std::vector< std::vector<double> > &coefficients, double x, double y, bool axis);
563 // ///Indefinite integral in x-direction of a polynomial divided by its independent variable
564 // double fracIntIn2Steps(const std::vector<double> &coefficients, double x);
565 // ///Indefinite integral in y-direction of a polynomial divided by its 2nd independent variable
566 // double fracIntIn2Steps(const std::vector<std::vector<double> > &coefficients, double x, double y);
567 // ///Indefinite integral of a centred polynomial divided by its 2nd independent variable
568 // double fracIntCentral2Steps(const std::vector<std::vector<double> > &coefficients, double x, double y, double ybase);
569 //
570 //public:
571 // /** Here we define the functions that should be used by the
572 // * respective implementations. Please do no use any other
573 // * method since this would break the purpose of this interface.
574 // * Note that the functions below are supposed to be aliases
575 // * to implementations declared elsewhere in this file.
576 // */
577 //
578 // /** Everything related to the normal polynomials goes in this
579 // * section, holds all the functions for evaluating polynomials.
580 // */
581 // /// Evaluates a one-dimensional polynomial for the given coefficients
582 // /// @param coefficients vector containing the ordered coefficients
583 // /// @param x double value that represents the current input
584 // virtual inline double polyval(const std::vector<double> &coefficients, double x){
585 // return baseHorner(coefficients,x);
586 // }
587 //
588 // /// Evaluates a two-dimensional polynomial for the given coefficients
589 // /// @param coefficients vector containing the ordered coefficients
590 // /// @param x double value that represents the current input in the 1st dimension
591 // /// @param y double value that represents the current input in the 2nd dimension
592 // virtual inline double polyval(const std::vector< std::vector<double> > &coefficients, double x, double y){
593 // return baseHorner(coefficients,x,y);
594 // }
595 //
596 //
597 // /** Everything related to the integrated polynomials goes in this
598 // * section, holds all the functions for evaluating polynomials.
599 // */
600 // /// Evaluates the indefinite integral of a one-dimensional polynomial
601 // /// @param coefficients vector containing the ordered coefficients
602 // /// @param x double value that represents the current input
603 // virtual inline double polyint(const std::vector<double> &coefficients, double x){
604 // return baseHornerInt(coefficients,x);
605 // }
606 //
607 // /// Evaluates the indefinite integral of a two-dimensional polynomial along the 2nd axis (y)
608 // /// @param coefficients vector containing the ordered coefficients
609 // /// @param x double value that represents the current input in the 1st dimension
610 // /// @param y double value that represents the current input in the 2nd dimension
611 // virtual inline double polyint(const std::vector< std::vector<double> > &coefficients, double x, double y){
612 // return baseHornerInt(coefficients,x,y);
613 // }
614 //
615 //
616 // /** Everything related to the derived polynomials goes in this
617 // * section, holds all the functions for evaluating polynomials.
618 // */
619 // /// Evaluates the derivative of a one-dimensional polynomial
620 // /// @param coefficients vector containing the ordered coefficients
621 // /// @param x double value that represents the current input
622 // virtual inline double polyder(const std::vector<double> &coefficients, double x){
623 // return deriveIn2Steps(coefficients,x);
624 // }
625 //
626 // /// Evaluates the derivative of a two-dimensional polynomial along the 2nd axis (y)
627 // /// @param coefficients vector containing the ordered coefficients
628 // /// @param x double value that represents the current input in the 1st dimension
629 // /// @param y double value that represents the current input in the 2nd dimension
630 // virtual inline double polyder(const std::vector< std::vector<double> > &coefficients, double x, double y){
631 // return deriveIn2Steps(coefficients,x,y,false);
632 // }
633 //
634 //
635 // /** Everything related to the polynomials divided by one variable goes in this
636 // * section, holds all the functions for evaluating polynomials.
637 // */
638 // /// Evaluates the indefinite integral of a one-dimensional polynomial divided by its independent variable
639 // /// @param coefficients vector containing the ordered coefficients
640 // /// @param x double value that represents the current position
641 // virtual inline double polyfracval(const std::vector<double> &coefficients, double x){
642 // return baseHorner(coefficients,x)/x;
643 // }
644 //
645 // /// Evaluates the indefinite integral of a two-dimensional polynomial divided by its 2nd independent variable
646 // /// @param coefficients vector containing the ordered coefficients
647 // /// @param x double value that represents the current input in the 1st dimension
648 // /// @param y double value that represents the current input in the 2nd dimension
649 // virtual inline double polyfracval(const std::vector< std::vector<double> > &coefficients, double x, double y){
650 // return baseHorner(coefficients,x,y)/y;
651 // }
652 //
653 //
654 // /** Everything related to the integrated polynomials divided by one variable goes in this
655 // * section, holds all the functions for solving polynomials.
656 // */
657 // /// Evaluates the indefinite integral of a one-dimensional polynomial divided by its independent variable
658 // /// @param coefficients vector containing the ordered coefficients
659 // /// @param x double value that represents the current position
660 // virtual inline double polyfracint(const std::vector<double> &coefficients, double x){
661 // return baseHornerFracInt(coefficients,x);
662 // }
663 //
664 // /// Evaluates the indefinite integral of a two-dimensional polynomial divided by its 2nd independent variable
665 // /// @param coefficients vector containing the ordered coefficients
666 // /// @param x double value that represents the current input in the 1st dimension
667 // /// @param y double value that represents the current input in the 2nd dimension
668 // virtual inline double polyfracint(const std::vector< std::vector<double> > &coefficients, double x, double y){
669 // return baseHornerFracInt(coefficients,x,y);
670 // }
671 //
672 // /// Evaluates the indefinite integral of a centred one-dimensional polynomial divided by its independent variable
673 // /// @param coefficients vector containing the ordered coefficients
674 // /// @param x double value that represents the current position
675 // /// @param xbase central temperature for fitted function
676 // virtual inline double polyfracintcentral(const std::vector<double> &coefficients, double x, double xbase){
677 // return fracIntCentral(coefficients,x,xbase);
678 // }
679 //
680 // /// Evaluates the indefinite integral of a centred two-dimensional polynomial divided by its 2nd independent variable
681 // /// @param coefficients vector containing the ordered coefficients
682 // /// @param x double value that represents the current input in the 1st dimension
683 // /// @param y double value that represents the current input in the 2nd dimension
684 // /// @param ybase central temperature for fitted function
685 // virtual inline double polyfracintcentral(const std::vector< std::vector<double> > &coefficients, double x, double y, double ybase){
686 // return fracIntCentral2Steps(coefficients,x,y,ybase);
687 // }
688 //
689 //
690 // /** Everything related to the derived polynomials divided by one variable goes in this
691 // * section, holds all the functions for solving polynomials.
692 // */
693 // /// Evaluates the derivative of a one-dimensional polynomial divided by its independent variable
694 // /// @param coefficients vector containing the ordered coefficients
695 // /// @param x double value that represents the current position
696 // virtual inline double polyfracder(const std::vector<double> &coefficients, double x){
697 // throw CoolProp::NotImplementedError("Derivatives of polynomials divided by their independent variable have not been implemented."); // TODO: Implement polyfracder1D
698 // }
699 //
700 // /// Evaluates the derivative of a two-dimensional polynomial divided by its 2nd independent variable
701 // /// @param coefficients vector containing the ordered coefficients
702 // /// @param x double value that represents the current input in the 1st dimension
703 // /// @param y double value that represents the current input in the 2nd dimension
704 // virtual inline double polyfracder(const std::vector< std::vector<double> > &coefficients, double x, double y){
705 // throw CoolProp::NotImplementedError("Derivatives of polynomials divided by their independent variable have not been implemented."); // TODO: Implement polyfracder2D
706 // }
707 //
708 // /// Evaluates the derivative of a centred one-dimensional polynomial divided by its independent variable
709 // /// @param coefficients vector containing the ordered coefficients
710 // /// @param x double value that represents the current position
711 // /// @param xbase central temperature for fitted function
712 // virtual inline double polyfracdercentral(const std::vector<double> &coefficients, double x, double xbase){
713 // throw CoolProp::NotImplementedError("Derivatives of polynomials divided by their independent variable have not been implemented."); // TODO: Implement polyfracdercentral1D
714 // }
715 //
716 // /// Evaluates the derivative of a centred two-dimensional polynomial divided by its 2nd independent variable
717 // /// @param coefficients vector containing the ordered coefficients
718 // /// @param x double value that represents the current input in the 1st dimension
719 // /// @param y double value that represents the current input in the 2nd dimension
720 // /// @param ybase central temperature for fitted function
721 // virtual inline double polyfracdercentral(const std::vector< std::vector<double> > &coefficients, double x, double y, double ybase){
722 // throw CoolProp::NotImplementedError("Derivatives of polynomials divided by their independent variable have not been implemented."); // TODO: Implement polyfracdercentral2D
723 // }
724 //};
725 //
726 //
727 //
728 //
730 // * used by the solvers.
731 // * TODO: Make multidimensional
732 // */
733 //class PolyResidual : public FuncWrapper1D {
734 //protected:
735 // enum dims {i1D, i2D};
736 // /// Object that evaluates the equation
737 // BasePolynomial poly;
738 // /// Current output value
739 // double output, firstDim;
740 // int dim;
741 // std::vector< std::vector<double> > coefficients;
742 //private:
743 // PolyResidual();
744 //public:
745 // PolyResidual(const std::vector<double> &coefficients, double y);
746 // PolyResidual(const std::vector< std::vector<double> > &coefficients, double x, double z);
747 // virtual ~PolyResidual(){};
748 // bool is2D(){return (this->dim==i2D);};
749 // virtual double call(double x);
750 // virtual double deriv(double x);
751 //};
752 //class PolyIntResidual : public PolyResidual {
753 //public:
754 // PolyIntResidual(const std::vector<double> &coefficients, double y):PolyResidual(coefficients, y){};
755 // PolyIntResidual(const std::vector< std::vector<double> > &coefficients, double x, double z):PolyResidual(coefficients, x, z){};
756 // virtual double call(double x);
757 // virtual double deriv(double x);
758 //};
759 //class PolyFracIntResidual : public PolyResidual {
760 //public:
761 // PolyFracIntResidual(const std::vector<double> &coefficients, double y):PolyResidual(coefficients, y){};
762 // PolyFracIntResidual(const std::vector< std::vector<double> > &coefficients, double x, double z):PolyResidual(coefficients, x, z){};
763 // virtual double call(double x);
764 // virtual double deriv(double x);
765 //};
766 //class PolyFracIntCentralResidual : public PolyResidual {
767 //protected:
768 // double baseVal;
769 //public:
770 // PolyFracIntCentralResidual(const std::vector<double> &coefficients, double y, double xBase):PolyResidual(coefficients, y){this->baseVal = xBase;};
771 // PolyFracIntCentralResidual(const std::vector< std::vector<double> > &coefficients, double x, double z, double yBase): PolyResidual(coefficients, x, z){this->baseVal = yBase;};
772 // virtual double call(double x);
773 // virtual double deriv(double x);
774 //};
775 //class PolyDerResidual : public PolyResidual {
776 //public:
777 // PolyDerResidual(const std::vector<double> &coefficients, double y):PolyResidual(coefficients, y){};
778 // PolyDerResidual(const std::vector< std::vector<double> > &coefficients, double x, double z):PolyResidual(coefficients, x, z){};
779 // virtual double call(double x);
780 // virtual double deriv(double x);
781 //};
782 //
783 //
784 //
785 //
787 // * but solves the polynomial for the given value
788 // * instead of evaluating it.
789 // * TODO: This class does not check for bijective
790 // * polynomials and is therefore a little
791 // * fragile.
792 // */
793 //class PolynomialSolver : public BasePolynomial{
794 //private:
795 // enum solvers {iNewton, iBrent};
796 // int uses;
797 // double guess, min, max;
798 // double macheps, tol;
799 // int maxiter;
800 //
801 //public:
802 // // Constructor
803 // PolynomialSolver();
804 // // Destructor. No implementation
805 // virtual ~PolynomialSolver(){};
806 //
807 //public:
808 // /** Here we redefine the functions that solve the polynomials.
809 // * These implementations all use the base class to evaluate
810 // * the polynomial during the solution process.
811 // */
812 //
813 // /** Everything related to the normal polynomials goes in this
814 // * section, holds all the functions for solving polynomials.
815 // */
816 // /// Solves a one-dimensional polynomial for the given coefficients
817 // /// @param coefficients vector containing the ordered coefficients
818 // /// @param y double value that represents the current input
819 // virtual double polyval(const std::vector<double> &coefficients, double y);
820 //
821 // /// Solves a two-dimensional polynomial for the given coefficients
822 // /// @param coefficients vector containing the ordered coefficients
823 // /// @param x double value that represents the current input in the 1st dimension
824 // /// @param z double value that represents the current output
825 // virtual double polyval(const std::vector< std::vector<double> > &coefficients, double x, double z);
826 //
827 //
828 // /** Everything related to the integrated polynomials goes in this
829 // * section, holds all the functions for solving polynomials.
830 // */
831 // /// Solves the indefinite integral of a one-dimensional polynomial
832 // /// @param coefficients vector containing the ordered coefficients
833 // /// @param y double value that represents the current output
834 // virtual double polyint(const std::vector<double> &coefficients, double y);
835 //
836 // /// Solves the indefinite integral of a two-dimensional polynomial along the 2nd axis (y)
837 // /// @param coefficients vector containing the ordered coefficients
838 // /// @param x double value that represents the current input in the 1st dimension
839 // /// @param z double value that represents the current output
840 // virtual double polyint(const std::vector< std::vector<double> > &coefficients, double x, double z);
841 //
842 //
843 // /** Everything related to the derived polynomials goes in this
844 // * section, holds all the functions for solving polynomials.
845 // */
846 // /// Solves the derivative of a one-dimensional polynomial
847 // /// @param coefficients vector containing the ordered coefficients
848 // /// @param y double value that represents the current output
849 // virtual double polyder(const std::vector<double> &coefficients, double y);
850 //
851 // /// Solves the derivative of a two-dimensional polynomial along the 2nd axis (y)
852 // /// @param coefficients vector containing the ordered coefficients
853 // /// @param x double value that represents the current input in the 1st dimension
854 // /// @param z double value that represents the current output
855 // virtual double polyder(const std::vector< std::vector<double> > &coefficients, double x, double z);
856 //
857 //
858 // /** Everything related to the polynomials divided by one variable goes in this
859 // * section, holds all the functions for solving polynomials.
860 // */
861 // /// Solves the indefinite integral of a one-dimensional polynomial divided by its independent variable
862 // /// @param coefficients vector containing the ordered coefficients
863 // /// @param y double value that represents the current output
864 // virtual double polyfracval(const std::vector<double> &coefficients, double y);
865 //
866 // /// Solves the indefinite integral of a two-dimensional polynomial divided by its 2nd independent variable
867 // /// @param coefficients vector containing the ordered coefficients
868 // /// @param x double value that represents the current input in the 1st dimension
869 // /// @param z double value that represents the current output
870 // virtual double polyfracval(const std::vector< std::vector<double> > &coefficients, double x, double z);
871 //
872 //
873 // /** Everything related to the integrated polynomials divided by one variable goes in this
874 // * section, holds all the functions for solving polynomials.
875 // */
876 // /// Solves the indefinite integral of a one-dimensional polynomial divided by its independent variable
877 // /// @param coefficients vector containing the ordered coefficients
878 // /// @param y double value that represents the current output
879 // virtual double polyfracint(const std::vector<double> &coefficients, double y);
880 //
881 // /// Solves the indefinite integral of a two-dimensional polynomial divided by its 2nd independent variable
882 // /// @param coefficients vector containing the ordered coefficients
883 // /// @param x double value that represents the current input in the 1st dimension
884 // /// @param z double value that represents the current output
885 // virtual double polyfracint(const std::vector< std::vector<double> > &coefficients, double x, double z);
886 //
887 // /// Solves the indefinite integral of a centred one-dimensional polynomial divided by its independent variable
888 // /// @param coefficients vector containing the ordered coefficients
889 // /// @param y double value that represents the current output
890 // /// @param xbase central x-value for fitted function
891 // virtual double polyfracintcentral(const std::vector<double> &coefficients, double y, double xbase);
892 //
893 // /// Solves the indefinite integral of a centred two-dimensional polynomial divided by its 2nd independent variable
894 // /// @param coefficients vector containing the ordered coefficients
895 // /// @param x double value that represents the current input in the 1st dimension
896 // /// @param z double value that represents the current output
897 // /// @param ybase central y-value for fitted function
898 // virtual double polyfracintcentral(const std::vector< std::vector<double> > &coefficients, double x, double z, double ybase);
899 //
900 //
901 // /** Everything related to the derived polynomials divided by one variable goes in this
902 // * section, holds all the functions for solving polynomials.
903 // */
904 // /// Solves the derivative of a one-dimensional polynomial divided by its independent variable
905 // /// @param coefficients vector containing the ordered coefficients
906 // /// @param y double value that represents the current output
907 // virtual double polyfracder(const std::vector<double> &coefficients, double y);
908 //
909 // /// Solves the derivative of a two-dimensional polynomial divided by its 2nd independent variable
910 // /// @param coefficients vector containing the ordered coefficients
911 // /// @param x double value that represents the current input in the 1st dimension
912 // /// @param z double value that represents the current output
913 // virtual double polyfracder(const std::vector< std::vector<double> > &coefficients, double x, double z);
914 //
915 // /// Solves the derivative of a centred one-dimensional polynomial divided by its independent variable
916 // /// @param coefficients vector containing the ordered coefficients
917 // /// @param y double value that represents the current output
918 // /// @param xbase central x-value for fitted function
919 // virtual double polyfracdercentral(const std::vector<double> &coefficients, double y, double xbase);
920 //
921 // /// Solves the derivative of a centred two-dimensional polynomial divided by its 2nd independent variable
922 // /// @param coefficients vector containing the ordered coefficients
923 // /// @param x double value that represents the current input in the 1st dimension
924 // /// @param z double value that represents the current output
925 // /// @param ybase central y-value for fitted function
926 // virtual double polyfracdercentral(const std::vector< std::vector<double> > &coefficients, double x, double z, double ybase);
927 //
928 //
929 // /** Set the solvers and updates either the guess values or the
930 // * boundaries for the variable to solve for.
931 // */
932 // /// Sets the guess value for the Newton solver and enables it.
933 // /// @param guess double value that represents the guess value
934 // virtual void setGuess(double guess);
935 // /// Sets the limits for the Brent solver and enables it.
936 // /// @param min double value that represents the lower boundary
937 // /// @param max double value that represents the upper boundary
938 // virtual void setLimits(double min, double max);
939 // /// Solves the equations based on previously defined parameters.
940 // /// @param min double value that represents the lower boundary
941 // /// @param max double value that represents the upper boundary
942 // virtual double solve(PolyResidual &res);
943 //};
944 //
945 //
947 //class BaseExponential{
948 //
949 //protected:
950 // BasePolynomial poly;
951 // bool POLYMATH_DEBUG;
952 //
953 //public:
954 // BaseExponential();
955 // virtual ~BaseExponential(){};
956 //
957 //public:
958 // /// Evaluates an exponential function for the given coefficients
959 // /// @param coefficients vector containing the ordered coefficients
960 // /// @param x double value that represents the current input
961 // /// @param n int value that determines the kind of exponential function
962 // double expval(const std::vector<double> &coefficients, double x, int n);
963 //
964 // /// Evaluates an exponential function for the given coefficients
965 // /// @param coefficients vector containing the ordered coefficients
966 // /// @param x double value that represents the current input in the 1st dimension
967 // /// @param y double value that represents the current input in the 2nd dimension
968 // /// @param n int value that determines the kind of exponential function
969 // double expval(const std::vector< std::vector<double> > &coefficients, double x, double y, int n);
970 //};
971
972
973 }; /* namespace CoolProp */
974 #endif
double evaluate(const Eigen::MatrixXd &coefficients, const double &x_in)
The core functions to evaluate the polynomial.
Definition: PolyMath.cpp:158
Definition: Solvers.h:37
The base class for all Polynomials.
Definition: PolyMath.h:24
Polynomial2D()
Constructors.
Definition: PolyMath.h:28
Definition: PolyMath.h:380
int get_debug_level()
Get the debug level.
Definition: CoolProp.cpp:63
virtual ~Polynomial2D()
Destructor. No implementation.
Definition: PolyMath.h:31
A class for polynomials starting at an arbitrary degree.
Definition: PolyMath.h:206
virtual ~Polynomial2DFrac()
Destructor. No implementation.
Definition: PolyMath.h:213
Eigen::MatrixXd deriveCoeffs(const Eigen::MatrixXd &coefficients, const int &axis=-1, const int &times=1)
Derivative coefficients calculation.
Definition: PolyMath.cpp:104
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > vec_to_eigen(const std::vector< std::vector< T > > &coefficients)
Definition: MatrixMath.h:114
double derivative(const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis)
Definition: PolyMath.cpp:182
Polynomial2D poly
Object that evaluates the equation.
Definition: PolyMath.h:177
Polynomial2DFrac()
Constructors.
Definition: PolyMath.h:210
double baseHorner(const std::vector< double > &coefficients, double x)
Horner function generator implementations.
Definition: PolyMath.cpp:302
double integral(const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis)
Definition: PolyMath.cpp:191
Eigen::VectorXd solve(const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const int &axis)
Returns a vector with ALL the real roots of p(x_in,y_in)-z_in.
Definition: PolyMath.cpp:227
Eigen::MatrixXd integrateCoeffs(const Eigen::MatrixXd &coefficients, const int &axis, const int &times)
Integration functions.
Definition: PolyMath.cpp:53
Definition: PolyMath.h:409
double in
the fixed input != targetDim
Definition: PolyMath.h:175
double solve_limits(Poly2DResidual *res, const double &min, const double &max)
Uses the Brent solver to find the roots of p(x_in,y_in)-z_in.
Definition: PolyMath.cpp:199
double z_in
Current output value.
Definition: PolyMath.h:179
Eigen::MatrixXd convertCoefficients(const std::vector< std::vector< double > > &coefficients)
Convert the coefficient matrix.
Definition: PolyMath.h:39
Definition: PolyMath.h:167
bool checkCoefficients(const Eigen::MatrixXd &coefficients, const unsigned int rows, const unsigned int columns)
Basic checks for coefficient vectors.
Definition: PolyMath.cpp:27
Eigen::MatrixXd convertCoefficients(const std::vector< double > &coefficients)
Convert the coefficient vector.
Definition: PolyMath.h:36
Polynomial2DFrac poly
Object that evaluates the equation.
Definition: PolyMath.h:385
double simplePolynomial(const std::vector< double > &coefficients, double x)
Simple polynomial function generator. <- Deprecated due to poor performance, use Horner-scheme instea...
Definition: PolyMath.cpp:279
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
double solve_guess(Poly2DResidual *res, const double &guess)
Uses the Newton solver to find the roots of p(x_in,y_in)-z_in.
Definition: PolyMath.cpp:212