nonlin 1.5.2
A library that provides routines to compute the solutions to systems of nonlinear equations.
Loading...
Searching...
No Matches
nonlin_solve::newton_solver Type Reference

Defines a Newton solver. More...

Inheritance diagram for nonlin_solve::newton_solver:
nonlin_solve::line_search_solver nonlin_core::equation_solver

Public Member Functions

procedure, public solve ns_solve
 Applies Newton's method in conjunction with a backtracking type line search to solve N equations of N unknowns.
 
- Public Member Functions inherited from nonlin_solve::line_search_solver
procedure, public get_line_search lss_get_line_search
 Gets the line search module.
 
procedure, public set_line_search lss_set_line_search
 Sets the line search module.
 
procedure, public set_default_line_search lss_set_default
 Establishes a default line_search object for the line search module.
 
procedure, public is_line_search_defined lss_is_line_search_defined
 Tests to see if a line search module is defined.
 
procedure, public get_use_line_search lss_get_use_search
 Gets a value determining if a line-search should be employed.
 
procedure, public set_use_line_search lss_set_use_search
 Sets a value determining if a line-search should be employed.
 
- Public Member Functions inherited from nonlin_core::equation_solver
procedure, public get_max_fcn_evals es_get_max_eval
 Gets the maximum number of function evaluations allowed during a single solve.
 
procedure, public set_max_fcn_evals es_set_max_eval
 Sets the maximum number of function evaluations allowed during a single solve.
 
procedure, public get_fcn_tolerance es_get_fcn_tol
 Gets the convergence on function value tolerance.
 
procedure, public set_fcn_tolerance es_set_fcn_tol
 Sets the convergence on function value tolerance.
 
procedure, public get_var_tolerance es_get_var_tol
 Gets the convergence on change in variable tolerance.
 
procedure, public set_var_tolerance es_set_var_tol
 Sets the convergence on change in variable tolerance.
 
procedure, public get_gradient_tolerance es_get_grad_tol
 Gets the convergence on slope of the gradient vector tolerance.
 
procedure, public set_gradient_tolerance es_set_grad_tol
 Sets the convergence on slope of the gradient vector tolerance.
 
procedure, public get_print_status es_get_print_status
 Gets a logical value determining if iteration status should be printed.
 
procedure, public set_print_status es_set_print_status
 Sets a logical value determining if iteration status should be printed.
 

Additional Inherited Members

- Public Attributes inherited from nonlin_solve::line_search_solver
logical m_uselinesearch = .true.
 Set to true if a line search should be used regardless of the status of m_lineSearch.
 
- Public Attributes inherited from nonlin_core::equation_solver
real(real64) m_fcntol = 1.0d-8
 The convergence criteria on function values.
 
real(real64) m_xtol = 1.0d-12
 The convergence criteria on change in variable values.
 
real(real64) m_gtol = 1.0d-12
 The convergence criteria for the slope of the gradient vector.
 
logical m_printstatus = .false.
 Set to true to print iteration status; else, false.
 

Detailed Description

Defines a Newton solver.

Definition at line 287 of file nonlin_solve.f90.

Member Function/Subroutine Documentation

◆ solve()

procedure, public nonlin_solve::newton_solver::solve
virtual

Applies Newton's method in conjunction with a backtracking type line search to solve N equations of N unknowns.

Syntax
subroutine solve(class(newton_solver) this, class(vecfcn_helper) fcn, real(real64) x(:), real(real64) fvec(:), optional type(iteration_behavior) ib, optional class(errors) err)
Parameters
[in,out]thisThe equation_solver-based object.
[in]fcnThe vecfcn_helper object containing the equations to solve.
[in,out]xOn input, an N-element array containing an initial estimate to the solution. On output, the updated solution estimate. N is the number of variables.
[out]fvecAn N-element array that, on output, will contain the values of each equation as evaluated at the variable values given in x.
[out]ibAn optional output, that if provided, allows the caller to obtain iteration performance statistics.
[out]errAn optional errors-based object that if provided can be used to retrieve information relating to any errors encountered during execution. If not provided, a default implementation of the errors class is used internally to provide error handling. Possible errors and warning messages that may be encountered are as follows.
  • NL_INVALID_OPERATION_ERROR: Occurs if no equations have been defined.
  • NL_INVALID_INPUT_ERROR: Occurs if the number of equations is different than the number of variables.
  • NL_ARRAY_SIZE_ERROR: Occurs if any of the input arrays are not sized correctly.
  • NL_DIVERGENT_BEHAVIOR_ERROR: Occurs if the direction vector is pointing in an apparent uphill direction.
  • NL_CONVERGENCE_ERROR: Occurs if the line search cannot converge within the allowed number of iterations.
  • NL_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory available.
  • NL_SPURIOUS_CONVERGENCE_ERROR: Occurs as a warning if the slope of the gradient vector becomes sufficiently close to zero.
Example
The following code provides an example of how to solve a system of N equations of N unknonwns using Newton's method.
program main
type(vecfcn_helper) :: obj
procedure(vecfcn), pointer :: fcn
type(newton_solver) :: solver
real(real64) :: x(2), f(2)
! Set the initial conditions to [1, 1]
x = 1.0d0
! Define the function
fcn => fcn1
call obj%set_fcn(fcn, 2, 2)
! Solve the system of equations. The solution overwrites X
call solver%solve(obj, x, f)
! Print the output and the residual:
print '(AF5.3AF5.3A)', "The solution: (", x(1), ", ", x(2), ")"
print '(AE8.3AE8.3A)', "The residual: (", f(1), ", ", f(2), ")"
contains
! System of Equations:
!
! x**2 + y**2 = 34
! x**2 - 2 * y**2 = 7
!
! Solution:
! x = +/-5
! y = +/-3
subroutine fcn1(x, f)
real(real64), intent(in), dimension(:) :: x
real(real64), intent(out), dimension(:) :: f
f(1) = x(1)**2 + x(2)**2 - 34.0d0
f(2) = x(1)**2 - 2.0d0 * x(2)**2 - 7.0d0
end subroutine
end program
Describes an M-element vector-valued function of N-variables.
nonlin_core
nonlin_solve
Defines a type capable of encapsulating a system of nonlinear equations of the form: F(X) = 0....
Defines a Newton solver.
The above program returns the following results.
The solution: (5.000, 3.000)
The residual: (.000E+00, .000E+00)
See Also

Implements nonlin_core::equation_solver.

Definition at line 378 of file nonlin_solve.f90.


The documentation for this type was generated from the following file: