Cantera
2.3.0
|
Classes | |
struct | RootFind::rfTable |
Structure containing the iteration history. More... | |
class | RootFind |
Root finder for 1D problems. More... | |
Functions | |
RootFind (ResidEval *resid) | |
Constructor for the object. More... | |
RootFind (const RootFind &r) | |
RootFind & | operator= (const RootFind &right) |
doublereal | delXNonzero (doublereal x1) const |
Calculate a deltaX from an input value of x. More... | |
doublereal | delXMeaningful (doublereal x1) const |
Calculate a deltaX from an input value of x. More... | |
doublereal | deltaXControlled (doublereal x2, doublereal x1) const |
Calculate a controlled, nonzero delta between two numbers. More... | |
bool | theSame (doublereal x2, doublereal x1, doublereal factor=1.0) const |
Function to decide whether two real numbers are the same or not. More... | |
int | solve (doublereal xmin, doublereal xmax, int itmax, doublereal &funcTargetValue, doublereal *xbest) |
Using a line search method, find the root of a 1D function. More... | |
doublereal | func (doublereal x) |
Return the function value. More... | |
void | setTol (doublereal rtolf, doublereal atolf, doublereal rtolx=0.0, doublereal atolx=0.0) |
Set the tolerance parameters for the rootfinder. More... | |
void | setPrintLvl (int printLvl) |
Set the print level from the rootfinder. More... | |
void | setFuncIsGenerallyIncreasing (bool value) |
Set the function behavior flag. More... | |
void | setFuncIsGenerallyDecreasing (bool value) |
Set the function behavior flag. More... | |
void | setDeltaX (doublereal deltaXNorm) |
Set the minimum value of deltaX. More... | |
void | setDeltaXMax (doublereal deltaX) |
Set the maximum value of deltaX. More... | |
void | printTable () |
Print the iteration history table. More... | |
Variables | |
ResidEval * | m_residFunc |
Pointer to the residual function evaluator. More... | |
doublereal | m_funcTargetValue |
Target value for the function. More... | |
doublereal | m_atolf |
Absolute tolerance for the value of f. More... | |
doublereal | m_atolx |
Absolute tolerance for the value of x. More... | |
doublereal | m_rtolf |
Relative tolerance for the value of f and x. More... | |
doublereal | m_rtolx |
Relative tolerance for the value of x. More... | |
doublereal | m_maxstep |
Maximum number of step sizes. More... | |
int | printLvl |
Print level. More... | |
bool | writeLogAllowed_ |
Boolean to turn on the possibility of writing a log file. More... | |
doublereal | DeltaXnorm_ |
Delta X norm. More... | |
int | specifiedDeltaXnorm_ |
Boolean indicating whether DeltaXnorm_ has been specified by the user or not. More... | |
doublereal | DeltaXMax_ |
Delta X Max. More... | |
int | specifiedDeltaXMax_ |
Boolean indicating whether DeltaXMax_ has been specified by the user or not. More... | |
bool | FuncIsGenerallyIncreasing_ |
Boolean indicating whether the function is an increasing with x. More... | |
bool | FuncIsGenerallyDecreasing_ |
Boolean indicating whether the function is decreasing with x. More... | |
doublereal | deltaXConverged_ |
Value of delta X that is needed for convergence. More... | |
doublereal | x_maxTried_ |
Internal variable tracking largest x tried. More... | |
doublereal | fx_maxTried_ |
Internal variable tracking f(x) of largest x tried. More... | |
doublereal | x_minTried_ |
Internal variable tracking smallest x tried. More... | |
doublereal | fx_minTried_ |
Internal variable tracking f(x) of smallest x tried. More... | |
std::vector< struct rfTable > | rfHistory_ |
Vector of iteration histories. More... | |
Constant which determines the return integer from the routine | |
#define | ROOTFIND_SUCCESS 0 |
This means that the root solver was a success. More... | |
#define | ROOTFIND_SUCCESS_XCONVERGENCEONLY 1 |
This return value means that the root finder resolved a solution in the x coordinate, however, convergence in F was not achieved. More... | |
#define | ROOTFIND_FAILEDCONVERGENCE -1 |
This means that the root solver failed to achieve convergence. More... | |
#define | ROOTFIND_BADINPUT -2 |
This means that the input to the root solver was defective. More... | |
#define | ROOTFIND_SOLNLOWERTHANXMIN -3 |
This means that the rootfinder believes the solution is lower than xmin. More... | |
#define | ROOTFIND_SOLNHIGHERTHANXMAX -4 |
This means that the rootfinder believes the solution is higher than xmax. More... | |
int | its |
int | TP_its |
double | slope |
double | xval |
double | fval |
int | foundPos |
int | foundNeg |
double | deltaXConverged |
double | deltaFConverged |
double | delX |
std::string | reasoning |
void | clear () |
#define ROOTFIND_SUCCESS 0 |
This means that the root solver was a success.
Definition at line 25 of file RootFind.h.
Referenced by RootFind::solve().
#define ROOTFIND_SUCCESS_XCONVERGENCEONLY 1 |
This return value means that the root finder resolved a solution in the x coordinate, however, convergence in F was not achieved.
A common situation for this to happen is that f(x) is discontinuous about f(x) = f_0, where we seek the x where the function is equal to f_0. f(x) spans the f_0 while not being equal to f_0 anywhere.
Definition at line 33 of file RootFind.h.
#define ROOTFIND_FAILEDCONVERGENCE -1 |
This means that the root solver failed to achieve convergence.
Definition at line 35 of file RootFind.h.
Referenced by RootFind::solve().
#define ROOTFIND_BADINPUT -2 |
This means that the input to the root solver was defective.
Definition at line 37 of file RootFind.h.
Referenced by RootFind::solve().
#define ROOTFIND_SOLNLOWERTHANXMIN -3 |
This means that the rootfinder believes the solution is lower than xmin.
Definition at line 39 of file RootFind.h.
#define ROOTFIND_SOLNHIGHERTHANXMAX -4 |
This means that the rootfinder believes the solution is higher than xmax.
Definition at line 41 of file RootFind.h.
Constructor for the object.
resid | Pointer to the residual function to be used to calculate f(x) |
Definition at line 33 of file RootFind.cpp.
Definition at line 59 of file RootFind.cpp.
Definition at line 86 of file RootFind.cpp.
References RootFind::deltaXConverged_, RootFind::DeltaXMax_, RootFind::DeltaXnorm_, RootFind::FuncIsGenerallyDecreasing_, RootFind::FuncIsGenerallyIncreasing_, RootFind::fx_maxTried_, RootFind::fx_minTried_, RootFind::m_atolf, RootFind::m_atolx, RootFind::m_funcTargetValue, RootFind::m_maxstep, RootFind::m_residFunc, RootFind::m_rtolf, RootFind::m_rtolx, RootFind::printLvl, RootFind::specifiedDeltaXMax_, RootFind::specifiedDeltaXnorm_, Cantera::warn_deprecated(), RootFind::writeLogAllowed_, RootFind::x_maxTried_, and RootFind::x_minTried_.
|
private |
Calculate a deltaX from an input value of x.
This routine ensure that the deltaX will be greater or equal to DeltaXNorm_ or 1.0E-14 x
x1 | input value of x |
Definition at line 117 of file RootFind.cpp.
References RootFind::DeltaXnorm_.
Referenced by RootFind::deltaXControlled(), and RootFind::delXMeaningful().
|
private |
Calculate a deltaX from an input value of x.
This routine ensure that the deltaX will be greater or equal to DeltaXNorm_ or 1.0E-14 x or deltaXConverged_.
x1 | input value of x |
Definition at line 127 of file RootFind.cpp.
References RootFind::deltaXConverged_, and RootFind::delXNonzero().
Referenced by RootFind::theSame().
|
private |
Calculate a controlled, nonzero delta between two numbers.
The delta is designed to be greater than or equal to delXMeaningful(x) defined above with the same sign as the original delta. Therefore if you subtract it from either of the two original numbers, you get a different number.
x2 | first number |
x1 | second number |
Definition at line 136 of file RootFind.cpp.
References RootFind::delXNonzero().
Referenced by RootFind::solve().
|
private |
Function to decide whether two real numbers are the same or not.
A comparison is made between the two numbers to decide whether they are close to one another. This is defined as being within factor * delXMeaningful() of each other.
The basic premise here is that if the two numbers are too close, the noise will prevent an accurate calculation of the function and its slope.
x1 | First number |
x2 | second number |
factor | Multiplicative factor to multiple deltaX with |
Definition at line 151 of file RootFind.cpp.
References RootFind::delXMeaningful().
int solve | ( | doublereal | xmin, |
doublereal | xmax, | ||
int | itmax, | ||
doublereal & | funcTargetValue, | ||
doublereal * | xbest | ||
) |
Using a line search method, find the root of a 1D function.
This routine solves the following equation.
\[ R(x) = f(x) - f_o = 0 \]
xmin | Minimum value of x to be used. |
xmax | Maximum value of x to be used |
itmax | maximum number of iterations. Usually, it can be less than 50. |
funcTargetValue | Value of \( f_o \) in the equation. On return, it contains the value of the function actually obtained. |
xbest | Returns the x that satisfies the function On input, xbest should contain the best estimate of the solution. An attempt to find the solution near xbest is made. |
Definition at line 163 of file RootFind.cpp.
References RootFind::deltaXControlled(), RootFind::deltaXConverged_, RootFind::DeltaXMax_, RootFind::DeltaXnorm_, RootFind::func(), RootFind::m_atolf, RootFind::m_atolx, RootFind::m_funcTargetValue, RootFind::m_rtolf, RootFind::m_rtolx, Cantera::print_funcEval(), RootFind::printLvl, RootFind::rfHistory_, ROOTFIND_BADINPUT, ROOTFIND_FAILEDCONVERGENCE, ROOTFIND_SUCCESS, RootFind::specifiedDeltaXMax_, RootFind::specifiedDeltaXnorm_, Cantera::writelog(), RootFind::writeLogAllowed_, Cantera::writelogf(), RootFind::x_maxTried_, and RootFind::x_minTried_.
doublereal func | ( | doublereal | x | ) |
Return the function value.
This routine evaluates the following equation.
\[ R(x) = f(x) - f_o = 0 \]
x | Value of the independent variable |
Definition at line 990 of file RootFind.cpp.
References Cantera::checkFinite(), RootFind::fx_maxTried_, RootFind::fx_minTried_, RootFind::m_funcTargetValue, RootFind::m_residFunc, RootFind::x_maxTried_, and RootFind::x_minTried_.
Referenced by RootFind::solve().
void setTol | ( | doublereal | rtolf, |
doublereal | atolf, | ||
doublereal | rtolx = 0.0 , |
||
doublereal | atolx = 0.0 |
||
) |
Set the tolerance parameters for the rootfinder.
These tolerance parameters are used on the function value and the independent value to determine convergence
rtolf | Relative tolerance. The default is 10^-5 |
atolf | absolute tolerance. The default is 10^-11 |
rtolx | Relative tolerance. The default is 10^-5. Default parameter is 0.0, in which case rtolx is set equal to rtolf |
atolx | absolute tolerance. The default is 10^-11. Default parameter is 0.0, in which case atolx is set equal to atolf |
Definition at line 1008 of file RootFind.cpp.
References RootFind::m_atolf, RootFind::m_atolx, RootFind::m_rtolf, and RootFind::m_rtolx.
void setPrintLvl | ( | int | printLvl | ) |
Set the print level from the rootfinder.
printLvl | integer value |
Definition at line 1024 of file RootFind.cpp.
References RootFind::printLvl.
void setFuncIsGenerallyIncreasing | ( | bool | value | ) |
Set the function behavior flag.
If this is true, the function is generally an increasing function of x. In particular, if the algorithm is seeking a higher value of f, it will look in the positive x direction.
This type of function is needed because this algorithm must deal with regions of f(x) where f is not changing with x.
value | boolean value |
Definition at line 1029 of file RootFind.cpp.
References RootFind::FuncIsGenerallyDecreasing_, and RootFind::FuncIsGenerallyIncreasing_.
void setFuncIsGenerallyDecreasing | ( | bool | value | ) |
Set the function behavior flag.
If this is true, the function is generally a decreasing function of x. In particular, if the algorithm is seeking a higher value of f, it will look in the negative x direction.
This type of function is needed because this algorithm must deal with regions of f(x) where f is not changing with x.
value | boolean value |
Definition at line 1037 of file RootFind.cpp.
References RootFind::FuncIsGenerallyDecreasing_, and RootFind::FuncIsGenerallyIncreasing_.
void setDeltaX | ( | doublereal | deltaXNorm | ) |
Set the minimum value of deltaX.
deltaXNorm |
Definition at line 1045 of file RootFind.cpp.
References RootFind::DeltaXnorm_, and RootFind::specifiedDeltaXnorm_.
void setDeltaXMax | ( | doublereal | deltaX | ) |
Set the maximum value of deltaX.
deltaX |
Definition at line 1051 of file RootFind.cpp.
References RootFind::DeltaXMax_, and RootFind::specifiedDeltaXMax_.
void printTable | ( | ) |
Print the iteration history table.
Definition at line 1057 of file RootFind.cpp.
References RootFind::m_funcTargetValue, RootFind::rfHistory_, and Cantera::writelogf().
ResidEval* m_residFunc |
Pointer to the residual function evaluator.
Definition at line 305 of file RootFind.h.
Referenced by RootFind::func(), and RootFind::operator=().
doublereal m_funcTargetValue |
Target value for the function.
We seek the value of f that is equal to this value
Definition at line 309 of file RootFind.h.
Referenced by RootFind::func(), RootFind::operator=(), RootFind::printTable(), and RootFind::solve().
doublereal m_atolf |
Absolute tolerance for the value of f.
Definition at line 312 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setTol(), and RootFind::solve().
doublereal m_atolx |
Absolute tolerance for the value of x.
Definition at line 315 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setTol(), and RootFind::solve().
doublereal m_rtolf |
Relative tolerance for the value of f and x.
Definition at line 318 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setTol(), and RootFind::solve().
doublereal m_rtolx |
Relative tolerance for the value of x.
Definition at line 321 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setTol(), and RootFind::solve().
doublereal m_maxstep |
Maximum number of step sizes.
Definition at line 324 of file RootFind.h.
Referenced by RootFind::operator=().
|
protected |
Print level.
Definition at line 328 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setPrintLvl(), and RootFind::solve().
bool writeLogAllowed_ |
Boolean to turn on the possibility of writing a log file.
Definition at line 332 of file RootFind.h.
Referenced by RootFind::operator=(), and RootFind::solve().
|
protected |
Delta X norm.
This is the nominal value of deltaX that will be used by the program
Definition at line 337 of file RootFind.h.
Referenced by RootFind::delXNonzero(), RootFind::operator=(), RootFind::setDeltaX(), and RootFind::solve().
|
protected |
Boolean indicating whether DeltaXnorm_ has been specified by the user or not.
Definition at line 341 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setDeltaX(), and RootFind::solve().
|
protected |
Delta X Max.
This is the maximum value of deltaX that will be used by the program. Sometimes a large change in x causes problems.
Definition at line 348 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setDeltaXMax(), and RootFind::solve().
|
protected |
Boolean indicating whether DeltaXMax_ has been specified by the user or not.
Definition at line 352 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setDeltaXMax(), and RootFind::solve().
|
protected |
Boolean indicating whether the function is an increasing with x.
Definition at line 355 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setFuncIsGenerallyDecreasing(), and RootFind::setFuncIsGenerallyIncreasing().
|
protected |
Boolean indicating whether the function is decreasing with x.
Definition at line 358 of file RootFind.h.
Referenced by RootFind::operator=(), RootFind::setFuncIsGenerallyDecreasing(), and RootFind::setFuncIsGenerallyIncreasing().
|
protected |
Value of delta X that is needed for convergence.
X will be considered as converged if we are within deltaXConverged_ of the solution The default is zero.
Definition at line 365 of file RootFind.h.
Referenced by RootFind::delXMeaningful(), RootFind::operator=(), and RootFind::solve().
|
protected |
Internal variable tracking largest x tried.
Definition at line 368 of file RootFind.h.
Referenced by RootFind::func(), RootFind::operator=(), and RootFind::solve().
|
protected |
Internal variable tracking f(x) of largest x tried.
Definition at line 371 of file RootFind.h.
Referenced by RootFind::func(), and RootFind::operator=().
|
protected |
Internal variable tracking smallest x tried.
Definition at line 374 of file RootFind.h.
Referenced by RootFind::func(), RootFind::operator=(), and RootFind::solve().
|
protected |
Internal variable tracking f(x) of smallest x tried.
Definition at line 377 of file RootFind.h.
Referenced by RootFind::func(), and RootFind::operator=().
|
protected |
Vector of iteration histories.
Definition at line 420 of file RootFind.h.
Referenced by RootFind::printTable(), and RootFind::solve().