CoolProp
Solvers.h
1 #ifndef SOLVERS_H
2 #define SOLVERS_H
3 
4 #include <vector>
5 #include <string>
6 #include "Exceptions.h"
7 #include "CoolPropTools.h"
8 
9 namespace CoolProp
10 {
11 
12 // *****************************************************************************
13 // *****************************************************************************
14 // SOLVER WRAPPER CLASSES
15 // *****************************************************************************
16 // *****************************************************************************
17 
18 
20 {
21 public:
22  int errcode;
23  std::string errstring;
24  Dictionary options;
25  int iter;
26  FuncWrapper1D() : errcode(0), errstring("") {};
27  virtual ~FuncWrapper1D(){};
28  virtual double call(double) = 0;
34  virtual bool input_not_in_range(double x){ return false; };
35 };
36 
38 {
39 public:
40  virtual double deriv(double) = 0;
41 };
42 
44 {
45 public:
46  virtual double second_deriv(double) = 0;
47 };
48 
50 {
51 public:
52  virtual double third_deriv(double) = 0;
53 };
54 
56 {
57 public:
58  int errcode;
59  std::string errstring;
60  FuncWrapperND() : errcode(0), errstring("") {};
61  virtual ~FuncWrapperND(){};
62  virtual std::vector<double> call(const std::vector<double>&) = 0;// must be provided
63  virtual std::vector<std::vector<double> > Jacobian(const std::vector<double>&);
64 };
65 
66 // *****************************************************************************
67 // *****************************************************************************
68 // SOLVER ROUTINES
69 // *****************************************************************************
70 // *****************************************************************************
71 
72 // Single-Dimensional solvers, pointer versions
73 double Brent(FuncWrapper1D* f, double a, double b, double macheps, double t, int maxiter);
74 double Secant(FuncWrapper1D* f, double x0, double dx, double ftol, int maxiter);
75 double BoundedSecant(FuncWrapper1D* f, double x0, double xmin, double xmax, double dx, double ftol, int maxiter);
76 double Newton(FuncWrapper1DWithDeriv* f, double x0, double ftol, int maxiter);
77 double Halley(FuncWrapper1DWithTwoDerivs* f, double x0, double ftol, int maxiter, double xtol_rel = 1e-12);
78 double Householder4(FuncWrapper1DWithThreeDerivs* f, double x0, double ftol, int maxiter, double xtol_rel = 1e-12);
79 
80 // Single-Dimensional solvers, refere
81 inline double Brent(FuncWrapper1D &f, double a, double b, double macheps, double t, int maxiter){
82  return Brent(&f, a, b, macheps, t, maxiter);
83 }
84 inline double Secant(FuncWrapper1D &f, double x0, double dx, double ftol, int maxiter){
85  return Secant(&f, x0, dx, ftol, maxiter);
86 }
87 inline double BoundedSecant(FuncWrapper1D &f, double x0, double xmin, double xmax, double dx, double ftol, int maxiter){
88  return BoundedSecant(&f, x0, xmin, xmax, dx, ftol, maxiter);
89 }
90 inline double Newton(FuncWrapper1DWithDeriv &f, double x0, double ftol, int maxiter){
91  return Newton(&f, x0, ftol, maxiter);
92 }
93 inline double Halley(FuncWrapper1DWithTwoDerivs &f, double x0, double ftol, int maxiter, double xtol_rel = 1e-12){
94  return Halley(&f, x0, ftol, maxiter, xtol_rel);
95 }
96 inline double Householder4(FuncWrapper1DWithThreeDerivs &f, double x0, double ftol, int maxiter, double xtol_rel = 1e-12){
97  return Householder4(&f, x0, ftol, maxiter, xtol_rel);
98 }
99 
100 
101 // Multi-Dimensional solvers
102 std::vector<double> NDNewtonRaphson_Jacobian(FuncWrapperND *f, const std::vector<double> &x0, double tol, int maxiter, double w = 1.0);
103 
104 }; /*namespace CoolProp*/
105 #endif
Definition: Solvers.h:37
Definition: Solvers.h:43
std::vector< double > NDNewtonRaphson_Jacobian(FuncWrapperND *f, const std::vector< double > &x0, double tol, int maxiter, double w=1.0)
In this formulation of the Multi-Dimensional Newton-Raphson solver the Jacobian matrix is known...
Definition: Solvers.cpp:53
double Halley(FuncWrapper1DWithTwoDerivs *f, double x0, double ftol, int maxiter, double xtol_rel=1e-12)
In the Halley&#39;s method solver, two derivatives of the input variable are needed, it yields the follow...
Definition: Solvers.cpp:161
Definition: CoolPropTools.h:63
Definition: Solvers.h:55
double Brent(FuncWrapper1D *f, double a, double b, double macheps, double t, int maxiter)
This function implements a 1-D bounded solver using the algorithm from Brent, R.
Definition: Solvers.cpp:414
double Householder4(FuncWrapper1DWithThreeDerivs *f, double x0, double ftol, int maxiter, double xtol_rel=1e-12)
In the 4-th order Householder method, three derivatives of the input variable are needed...
Definition: Solvers.cpp:223
double Newton(FuncWrapper1DWithDeriv *f, double x0, double ftol, int maxiter)
In the newton function, a 1-D Newton-Raphson solver is implemented using exact solutions.
Definition: Solvers.cpp:115
Definition: Solvers.h:19
double BoundedSecant(FuncWrapper1D *f, double x0, double xmin, double xmax, double dx, double ftol, int maxiter)
In the secant function, a 1-D Newton-Raphson solver is implemented.
Definition: Solvers.cpp:360
virtual bool input_not_in_range(double x)
/brief A function for checking whether the input is in range;
Definition: Solvers.h:34
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 Secant(FuncWrapper1D *f, double x0, double dx, double ftol, int maxiter)
In the secant function, a 1-D Newton-Raphson solver is implemented.
Definition: Solvers.cpp:286