nonlin 1.5.2
A library that provides routines to compute the solutions to systems of nonlinear equations.
Loading...
Searching...
No Matches
nonlin_core::equation_solver Type Referenceabstract

A base class for various solvers of nonlinear systems of equations. More...

Inheritance diagram for nonlin_core::equation_solver:
nonlin_least_squares::least_squares_solver nonlin_solve::line_search_solver nonlin_solve::newton_solver nonlin_solve::quasi_newton_solver

Public Member Functions

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.
 
procedure(nonlin_solver), deferred, pass, public solve nonlin_solver
 Solves the system of equations.
 

Public Attributes

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.
 

Private Attributes

integer(int32) m_maxeval = 100
 The maximum number of function evaluations allowed per solve.
 

Detailed Description

A base class for various solvers of nonlinear systems of equations.

Example
The following example illustrates the use of the newton_solver type, which includes this type in its inheritance chain, to solve a system of equations. Several options are utilized in the example to illustrate much of the solver functionallity. Notice, many of these options are not necessary to compute the solution; however, they do provide means of control over the solver. For a more minimalistic example see the vecfcn_helper type.
program example
use iso_fortran_env
implicit none
! Local Variables
type(vecfcn_helper) :: obj
procedure(vecfcn), pointer :: fcn
type(newton_solver) :: solver
real(real64) :: x(2), f(2)
type(iteration_behavior) :: tracking
! Assign a pointer to the subroutine containing the equations to solve
fcn => fcns
call obj%set_fcn(fcn, 2, 2) ! There are 2 equations with 2 unknowns
! Set up solver parameters
call solver%set_max_fcn_evals(1000) ! Specify the maximum number of function evaluations before iteration termination
call solver%set_fcn_tolerance(1.0d-10)
call solver%set_var_tolerance(1.0d-10)
call solver%set_gradient_tolerance(1.0d-10)
! Tell the solver to print out a status update at each iteration - the default behavior does not print updates
call solver%set_print_status(.true.)
! Define an initial guess
x = 1.0d0 ! Equivalent to x = [1.0d0, 1.0d0]
! Solve the system of equations, but include solver statistics tracking
call solver%solve(obj, x, f, tracking)
! Display the output
print *, ""
print '(AF7.5AF7.5A)', "Solution: (", x(1), ", ", x(2), ")"
print '(AE9.3AE9.3A)', "Residual: (", f(1), ", ", f(2), ")"
print '(AI0)', "Iteration Count: ", tracking%iter_count
print '(AI0)', "Function Evaluations: ", tracking%fcn_count
print '(AI0)', "Jacobian Evaluations: ", tracking%jacobian_count
print '(AL1)', "Converge on Function Value: ", tracking%converge_on_fcn
print '(AL1)', "Converge on Change in Variable: ", tracking%converge_on_chng
print '(AL1)', "Converge on Zero Slope Gradient Vector: ", tracking%converge_on_zero_diff
contains
! Define the routine containing the equations to solve. The equations are:
! x**2 + y**2 = 34
! x**2 - 2 * y**2 = 7
subroutine fcns(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
nonlin_core
nonlin_solve
The above program produces the following output.
Iteration: 1
Function Evaluations: 3
Jacobian Evaluations: 1
Change in Variable: 0.545E+00
Residual: 0.272E+02
Iteration: 2
Function Evaluations: 5
Jacobian Evaluations: 2
Change in Variable: 0.504E+00
Residual: 0.743E+01
Iteration: 3
Function Evaluations: 6
Jacobian Evaluations: 3
Change in Variable: 0.132E+00
Residual: 0.522E+00
Iteration: 4
Function Evaluations: 7
Jacobian Evaluations: 4
Change in Variable: 0.882E-02
Residual: 0.199E-02
Iteration: 5
Function Evaluations: 8
Jacobian Evaluations: 5
Change in Variable: 0.389E-04
Residual: 0.302E-07
Solution: (5.00000, 3.00000)
Residual: (0.000E+00, 0.000E+00)
Iteration Count: 6
Function Evaluations: 9
Jacobian Evaluations: 6
Converge on Function Value: T
Converge on Change in Variable: F
Converge on Zero Slope Gradient Vector: F

Definition at line 1260 of file nonlin_core.f90.

Member Function/Subroutine Documentation

◆ get_fcn_tolerance()

procedure, public nonlin_core::equation_solver::get_fcn_tolerance

Gets the convergence on function value tolerance.

Syntax
pure real(real64) get_fcn_tolerance(class(equation_solver) this)
Parameters
[in]thisThe equation_solver object.
Returns
The tolerance value.

Definition at line 1308 of file nonlin_core.f90.

◆ get_gradient_tolerance()

procedure, public nonlin_core::equation_solver::get_gradient_tolerance

Gets the convergence on slope of the gradient vector tolerance.

Syntax
pure real(real64) function get_gradient_tolerance(class(equation_solver))
Parameters
[in]thisThe equation_solver object.
Returns
The tolerance value.

Definition at line 1357 of file nonlin_core.f90.

◆ get_max_fcn_evals()

procedure, public nonlin_core::equation_solver::get_max_fcn_evals

Gets the maximum number of function evaluations allowed during a single solve.

Syntax
pure integer(int32) function get_max_fcn_evals(class(equation_solver) this)
Parameters
[in]thisThe equation_solver object.
Returns
The maximum number of function evaluations.

Definition at line 1283 of file nonlin_core.f90.

◆ get_print_status()

procedure, public nonlin_core::equation_solver::get_print_status

Gets a logical value determining if iteration status should be printed.

Syntax
pure logical get_print_status(class(equation_solver) this)
Parameters
[in]thisThe equation_solver object.
Returns
True if the iteration status should be printed; else, false.

Definition at line 1383 of file nonlin_core.f90.

◆ get_var_tolerance()

procedure, public nonlin_core::equation_solver::get_var_tolerance

Gets the convergence on change in variable tolerance.

Syntax
pure real(real64) function get_var_tolerance(class(equation_solver) this)
Parameters
[in]thisThe equation_solver object.
Returns
The tolerance value.

Definition at line 1332 of file nonlin_core.f90.

◆ set_fcn_tolerance()

procedure, public nonlin_core::equation_solver::set_fcn_tolerance

Sets the convergence on function value tolerance.

Syntax
subroutine set_fcn_tolerance(class(equation_solver) this, real(real64) x)
Parameters
[in,out]thisThe equation_solver object.
[in]xThe tolerance value.
Example
See the equation_solver type for an example on how to establish the function value tolerance.

Definition at line 1322 of file nonlin_core.f90.

◆ set_gradient_tolerance()

procedure, public nonlin_core::equation_solver::set_gradient_tolerance

Sets the convergence on slope of the gradient vector tolerance.

Syntax
subroutine set_gradient_tolerance(class(equation_solver) this, real(real64) x)
Parameters
[in,out]thisThe equation_solver object.
[in]xThe tolerance value.
Example
See the equation_solver type for an example on how to establish the gradient vector slope tolerance.

Definition at line 1372 of file nonlin_core.f90.

◆ set_max_fcn_evals()

procedure, public nonlin_core::equation_solver::set_max_fcn_evals

Sets the maximum number of function evaluations allowed during a single solve.

Syntax
subroutine set_max_fcn_evals(class(equation_solver) this, integer(int32) n)
Parameters
[in,out]thisThe equation_solver object.
[in]nThe maximum number of function evaluations.
Example
See the equation_solver type for an example on how to establish the limit on number of function evaluations.

Definition at line 1298 of file nonlin_core.f90.

◆ set_print_status()

procedure, public nonlin_core::equation_solver::set_print_status

Sets a logical value determining if iteration status should be printed.

Syntax
subroutine set_print_status(class(equation_solver) this, logical x)
Parameters
[in,out]thisThe equation_solver object.
[in]xTrue if the iteration status should be printed; else, false.
Example
See the equation_solver type for an example on how to enable iteration update printing.

Definition at line 1398 of file nonlin_core.f90.

◆ set_var_tolerance()

procedure, public nonlin_core::equation_solver::set_var_tolerance

Sets the convergence on change in variable tolerance.

Syntax
subroutine set_var_tolerance(class(equation_solver) this, real(real64) x)
Parameters
[in,out]thisThe equation_solver object.
[in]xThe tolerance value.
Example
See the equation_solver type for an example on how to establish the change in variable tolerance.

Definition at line 1346 of file nonlin_core.f90.

◆ solve()

procedure(nonlin_solver), deferred, pass, public nonlin_core::equation_solver::solve
pure virtual

Solves the system of equations.

Example
See the equation_solver type for an example on how to solve a system of equations.

Implemented in nonlin_solve::newton_solver, and nonlin_solve::quasi_newton_solver.

Definition at line 1404 of file nonlin_core.f90.

Member Data Documentation

◆ m_fcntol

real(real64) nonlin_core::equation_solver::m_fcntol = 1.0d-8

The convergence criteria on function values.

Definition at line 1265 of file nonlin_core.f90.

◆ m_gtol

real(real64) nonlin_core::equation_solver::m_gtol = 1.0d-12

The convergence criteria for the slope of the gradient vector.

Definition at line 1269 of file nonlin_core.f90.

◆ m_maxeval

integer(int32) nonlin_core::equation_solver::m_maxeval = 100
private

The maximum number of function evaluations allowed per solve.

Definition at line 1263 of file nonlin_core.f90.

◆ m_printstatus

logical nonlin_core::equation_solver::m_printstatus = .false.

Set to true to print iteration status; else, false.

Definition at line 1271 of file nonlin_core.f90.

◆ m_xtol

real(real64) nonlin_core::equation_solver::m_xtol = 1.0d-12

The convergence criteria on change in variable values.

Definition at line 1267 of file nonlin_core.f90.


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