To solve a system of nonlinear algebraic equations of the form f(u) = 0. More...
#include <NLASSolver.h>
Public Member Functions | |
NLASSolver () | |
Default constructor. | |
NLASSolver (NonLinearIter nl, int nb_eq=1) | |
Constructor defining the iterative method to solve the equation. More... | |
NLASSolver (real_t &x, NonLinearIter nl=NEWTON) | |
Constructor defining a one-variable problem. More... | |
NLASSolver (Vect< real_t > &x, NonLinearIter nl=NEWTON) | |
Constructor defining a multi-variable problem. More... | |
NLASSolver (MyNLAS &my_nlas, NonLinearIter nl=NEWTON) | |
Constructor using a user defined class. More... | |
~NLASSolver () | |
Destructor. | |
void | setMaxIter (int max_it) |
Set Maximal number of iterations. More... | |
void | setTolerance (real_t toler) |
Set tolerance value for convergence. More... | |
void | set (NonLinearIter nl) |
Define an iterative procedure To be chosen among the enumerated values: BISECTION , REGULA_FALSI or NEWTON . | |
void | setNbEq (size_t nb_eq) |
Define number of equations. | |
void | setFunction (function< real_t(real_t)> f) |
Define the function associated to the equation to solve. More... | |
void | setFunction (function< Vect< real_t >(Vect< real_t >)> f) |
Define the function associated to the equation to solve. More... | |
void | setGradient (function< real_t(real_t)> g) |
Define the function associated to the derivative of the equation to solve. More... | |
void | setGradient (function< Vect< real_t >(Vect< real_t >)> g) |
Define the function associated to the gradient of the equation to solve. More... | |
void | setf (string exp) |
Set function for which zero is sought (case of one equation) More... | |
void | setDf (string exp, int i=1, int j=1) |
Set pzrtial derivative of function for which zero is sought (case of many equations) More... | |
void | setPDE (Equa &eq) |
Define a PDE. More... | |
void | setInitial (Vect< real_t > &u) |
Set initial guess for the iterations. More... | |
void | setInitial (real_t &x) |
Set initial guess for a unique unknown. More... | |
void | setInitial (real_t a, real_t b) |
Set initial guesses bisection or Regula falsi algorithms. More... | |
void | run () |
Run the solution procedure. | |
real_t | get () const |
Return solution (Case of a scalar equation) | |
void | get (Vect< real_t > &u) const |
Return solution (case of a nonlinear system of equations) More... | |
int | getNbIter () const |
Return number of iterations. | |
Detailed Description
To solve a system of nonlinear algebraic equations of the form f(u) = 0.
Features:
- The nonlinear problem is solved by the Newton's method in the general case, and in the one variable case, either by the bisection or the Regula Falsi method
-
The function and its gradient are given:
- Either by regular expressions
- Or by user defined functions
- Or by a user defined class. This feature enables defining the function and its gradient through a PDE class for instance
Constructor & Destructor Documentation
◆ NLASSolver() [1/4]
NLASSolver | ( | NonLinearIter | nl, |
int | nb_eq = 1 |
||
) |
Constructor defining the iterative method to solve the equation.
- Parameters
-
[in] nl Choose an iterative procedure to solve the nonlinear system of equations: To be chosen among the enumerated values: BISECTION
,REGULA_FALSI
orNEWTON
.[in] nb_eq Number of equations [Default: 1
]
◆ NLASSolver() [2/4]
NLASSolver | ( | real_t & | x, |
NonLinearIter | nl = NEWTON |
||
) |
Constructor defining a one-variable problem.
- Parameters
-
[in] x Variable containing on input initial guess and on output solution, if convergence is achieved [in] nl Iterative procedure to solve the nonlinear system of equations: To be chosen among the enumerated values: BISECTION
,REGULA_FALSI
orNEWTON
.
◆ NLASSolver() [3/4]
NLASSolver | ( | Vect< real_t > & | x, |
NonLinearIter | nl = NEWTON |
||
) |
Constructor defining a multi-variable problem.
- Parameters
-
[in] x Variable containing on input initial guess and on output solution, if convergence is achieved [in] nl Iterative procedure to solve the nonlinear system of equations: The only possible value (default one) in the current version is NEWTON
.
◆ NLASSolver() [4/4]
NLASSolver | ( | MyNLAS & | my_nlas, |
NonLinearIter | nl = NEWTON |
||
) |
Constructor using a user defined class.
- Parameters
-
[in] my_nlas Reference to instance of user defined class. This class inherits from abstract class MyNLAS. It must contain the member function Vect<double>
Function(const Vect<double>& x) which returns the value of the nonlinear function, as a vector, for a given solution vectorx
. The user defined class must contain, if the iterative scheme requires it the member functionVect<double>
Gradient(const Vect<real_t>& x) which returns the gradient as an*n
vector, each index(i,j) containing the j-th partial derivative of the i-th function.
[in] nl Iterative procedure to solve the nonlinear system of equations: To be chosen among the enumerated values: BISECTION
,REGULA_FALSI
orNEWTON
.
Member Function Documentation
◆ get()
Return solution (case of a nonlinear system of equations)
- Parameters
-
[out] u Vector that contains on output the solution
◆ setDf()
void setDf | ( | string | exp, |
int | i = 1 , |
||
int | j = 1 |
||
) |
Set pzrtial derivative of function for which zero is sought (case of many equations)
- Parameters
-
[in] exp Regular expression defining the partial derivative. In this expression, the variables are x1
,x2
, ...x10
(up to 10 variables)[in] i Component of function [Default: =1
][in] j Index of the partial derivative [Default: =1
]
◆ setf()
void setf | ( | string | exp | ) |
Set function for which zero is sought (case of one equation)
- Parameters
-
[in] exp Regular expression defining the function using the symbol x
as a variable
◆ setFunction() [1/2]
Define the function associated to the equation to solve.
This function can be used in the case where a user defined function is to be given. To be used in the one-variable case.
- Parameters
-
[in] f Function given as a function of one real variable and returning a real number. This function can be defined by the calling program as a C-function and then cast to an instance of class function
◆ setFunction() [2/2]
Define the function associated to the equation to solve.
This function can be used in the case where a user defined function is to be given.
- Parameters
-
[in] f Function given as a function of many variables, stored in an input vector, and returns a vector. This function can be defined by the calling program as a C-function and then cast to an instance of class function
◆ setGradient() [1/2]
Define the function associated to the derivative of the equation to solve.
- Parameters
-
[in] g Function given as a function of one real variable and returning a real number. This function can be defined by the calling program as a C-function and then cast to an instance of class function
◆ setGradient() [2/2]
Define the function associated to the gradient of the equation to solve.
- Parameters
-
[in] g Function given as a function of many variables, stored in an input vector. and returns a n*n
vector (
n is the number of variables). This function can be defined by the calling program as a C-function and then cast to an instance of class function
◆ setInitial() [1/3]
void setInitial | ( | real_t & | x | ) |
Set initial guess for a unique unknown.
- Parameters
-
[in] x Rference to value of initial guess
◆ setInitial() [2/3]
Set initial guesses bisection or Regula falsi algorithms.
- Parameters
-
[in] a Value of first initial guess [in] b Value of second initial guess
- Note
- The function has to have opposite signs at these values
i.e.
f(a)f(b)<0.
- Warning
- This function makes sense only in the case of a unique function of one variable
◆ setInitial() [3/3]
Set initial guess for the iterations.
- Parameters
-
[in] u Vector containing initial guess for the unknown
◆ setMaxIter()
void setMaxIter | ( | int | max_it | ) |
Set Maximal number of iterations.
Default value of this parameter is 100
◆ setPDE()
void setPDE | ( | Equa & | eq | ) |
Define a PDE.
The solver can be used to solve a nonlinear PDE. In this case, the PDE is defined as an instance of a class inheriting of Equa.
- Parameters
-
[in] eq Pointer to equation instance
◆ setTolerance()
void setTolerance | ( | real_t | toler | ) |
Set tolerance value for convergence.
Default value of this parameter is 1.e-8