NLASSolver Class Reference

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, size_t nb_eq=1)
 Constructor defining the iterative method to solve the equation.
 
 NLASSolver (real_t &x, NonLinearIter nl=NEWTON)
 Constructor defining a one-variable problem.
 
 NLASSolver (Vect< real_t > &x, NonLinearIter nl=NEWTON)
 Constructor defining a multi-variable problem.
 
 NLASSolver (MyNLAS &my_nlas, NonLinearIter nl=NEWTON)
 Constructor using a user defined class.
 
 ~NLASSolver ()
 Destructor.
 
void setMaxIter (int max_it)
 Set Maximal number of iterations.
 
void setTolerance (real_t toler)
 Set tolerance value for convergence.
 
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.
 
void setFunction (function< Vect< real_t >(Vect< real_t >)> f)
 Define the function associated to the equation to solve.
 
void setGradient (function< real_t(real_t)> g)
 Define the function associated to the derivative of the equation to solve.
 
void setGradient (function< Vect< real_t >(Vect< real_t >)> g)
 Define the function associated to the gradient of the equation to solve.
 
void setf (string exp)
 Set function for which zero is sought (case of one equation)
 
void setDf (string exp, size_t i=1, size_t j=1)
 Set pzrtial derivative of function for which zero is sought (case of many equations)
 
void setPDE (Equa &eq)
 Define a PDE.
 
void setInitial (Vect< real_t > &u)
 Set initial guess for the iterations.
 
void setInitial (real_t &x)
 Set initial guess for a unique unknown.
 
void setInitial (real_t a, real_t b)
 Set initial guesses bisection or Regula falsi algorithms.
 
int 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)
 
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,
size_t  nb_eq = 1 
)

Constructor defining the iterative method to solve the equation.

Parameters
[in]nlChoose an iterative procedure to solve the nonlinear system of equations: To be chosen among the enumerated values: BISECTION, REGULA_FALSI or NEWTON.
[in]nb_eqNumber of equations [Default: 1]

◆ NLASSolver() [2/4]

NLASSolver ( real_t &  x,
NonLinearIter  nl = NEWTON 
)

Constructor defining a one-variable problem.

Parameters
[in]xVariable containing on input initial guess and on output solution, if convergence is achieved
[in]nlIterative procedure to solve the nonlinear system of equations: To be chosen among the enumerated values: BISECTION, REGULA_FALSI or NEWTON.

◆ NLASSolver() [3/4]

NLASSolver ( Vect< real_t > &  x,
NonLinearIter  nl = NEWTON 
)

Constructor defining a multi-variable problem.

Parameters
[in]xVariable containing on input initial guess and on output solution, if convergence is achieved
[in]nlIterative 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_nlasReference 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 vector x. The user defined class must contain, if the iterative scheme requires it the member function Vect<double> Gradient(const Vect<real_t>& x) which returns the gradient as a n*n vector, each index (i,j) containing the j-th partial derivative of the i-th function.
[in]nlIterative procedure to solve the nonlinear system of equations: To be chosen among the enumerated values: BISECTION, REGULA_FALSI or NEWTON.

Member Function Documentation

◆ get()

void get ( Vect< real_t > &  u) const

Return solution (case of a nonlinear system of equations)

Parameters
[out]uVector that contains on output the solution

◆ setDf()

void setDf ( string  exp,
size_t  i = 1,
size_t  j = 1 
)

Set pzrtial derivative of function for which zero is sought (case of many equations)

Parameters
[in]expRegular expression defining the partial derivative. In this expression, the variables are x1, x2, ... x10 (up to 10 variables)
[in]iComponent of function [Default: =1]
[in]jIndex of the partial derivative [Default: =1]

◆ setf()

void setf ( string  exp)

Set function for which zero is sought (case of one equation)

Parameters
[in]expRegular expression defining the function using the symbol x as a variable

◆ setFunction() [1/2]

void setFunction ( function< real_t(real_t)>  f)

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]fFunction 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]

void setFunction ( function< Vect< real_t >(Vect< real_t >)>  f)

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]fFunction 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]

void setGradient ( function< real_t(real_t)>  g)

Define the function associated to the derivative of the equation to solve.

Parameters
[in]gFunction 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]

void setGradient ( function< Vect< real_t >(Vect< real_t >)>  g)

Define the function associated to the gradient of the equation to solve.

Parameters
[in]gFunction 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]xRference to value of initial guess

◆ setInitial() [2/3]

void setInitial ( real_t  a,
real_t  b 
)

Set initial guesses bisection or Regula falsi algorithms.

Parameters
[in]aValue of first initial guess
[in]bValue 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]

void setInitial ( Vect< real_t > &  u)

Set initial guess for the iterations.

Parameters
[in]uVector 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]eqPointer to equation instance

◆ setTolerance()

void setTolerance ( real_t  toler)

Set tolerance value for convergence.

Default value of this parameter is 1.e-8