abstract class for the root solver methods
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
procedure(func), | private, | pointer | :: | f | => | null() |
user function to find the root of |
real(kind=wp), | private | :: | ftol | = | 0.0_wp |
absolute tolerance for |
|
real(kind=wp), | private | :: | rtol | = | 1.0e-6_wp |
relative tol for x |
|
real(kind=wp), | private | :: | atol | = | 1.0e-12_wp |
absolute tol for x [not used by all methods] |
|
integer, | private | :: | maxiter | = | 2000 |
maximum number of iterations [not used by all methods] |
initialize the class [must be called first]
Initialize the root_solver class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(root_solver), | intent(out) | :: | me | |||
procedure(func) | :: | f |
user function |
|||
real(kind=wp), | intent(in), | optional | :: | ftol |
absolute tolerance for |
|
real(kind=wp), | intent(in), | optional | :: | rtol |
relative tol for x |
|
real(kind=wp), | intent(in), | optional | :: | atol |
absolute tol for x |
|
integer, | intent(in), | optional | :: | maxiter |
maximum number of iterations |
main routine for finding the root
Main wrapper routine for all the methods.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(root_solver), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in) | :: | ax |
left endpoint of initial interval |
||
real(kind=wp), | intent(in) | :: | bx |
right endpoint of initial interval |
||
real(kind=wp), | intent(out) | :: | xzero |
abscissa approximating a zero of |
||
real(kind=wp), | intent(out) | :: | fzero |
value of |
||
integer, | intent(out) | :: | iflag |
status flag ( |
||
real(kind=wp), | intent(in), | optional | :: | fax |
if |
|
real(kind=wp), | intent(in), | optional | :: | fbx |
if |
|
logical, | intent(in), | optional | :: | bisect_on_failure |
if true, then if the specified method fails,
it will be retried using the bisection method.
(default is False). Note that this can use up
to |
root solver function. Meant to be called from solve, which handles some common startup tasks. All these routines assume that and have opposite signs.
Root solver function interface
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(root_solver), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in) | :: | ax |
left endpoint of initial interval |
||
real(kind=wp), | intent(in) | :: | bx |
right endpoint of initial interval |
||
real(kind=wp), | intent(in) | :: | fax |
|
||
real(kind=wp), | intent(in) | :: | fbx |
|
||
real(kind=wp), | intent(out) | :: | xzero |
abscissa approximating a zero of |
||
real(kind=wp), | intent(out) | :: | fzero |
value of |
||
integer, | intent(out) | :: | iflag |
status flag |
Returns the function values at ax
and bx
to start the root finding algorithm.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(root_solver), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in) | :: | ax |
left endpoint of initial interval |
||
real(kind=wp), | intent(in) | :: | bx |
right endpoint of initial interval |
||
real(kind=wp), | intent(in), | optional | :: | fax |
if |
|
real(kind=wp), | intent(in), | optional | :: | fbx |
if |
|
real(kind=wp), | intent(out) | :: | fa |
|
||
real(kind=wp), | intent(out) | :: | fb |
|
Determines convergence in x based on if the reltol or abstol is satisfied.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(root_solver), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in) | :: | a |
old value |
||
real(kind=wp), | intent(in) | :: | b |
new value |
to check f
value against ftol
Returns true if this is a solution and sets xzero
and fzero
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(root_solver), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in) | :: | x | |||
real(kind=wp), | intent(in) | :: | f | |||
real(kind=wp), | intent(inout) | :: | xzero | |||
real(kind=wp), | intent(inout) | :: | fzero |
type,abstract,public :: root_solver !! abstract class for the root solver methods private procedure(func),pointer :: f => null() !! user function to find the root of real(wp) :: ftol = 0.0_wp !! absolute tolerance for `f=0` real(wp) :: rtol = 1.0e-6_wp !! relative tol for x real(wp) :: atol = 1.0e-12_wp !! absolute tol for x [not used by all methods] integer :: maxiter = 2000 !! maximum number of iterations [not used by all methods] contains private procedure,public :: initialize => initialize_root_solver !! initialize the class [must be called first] procedure,public :: solve !! main routine for finding the root procedure(root_f),deferred :: find_root !! root solver function. Meant to be !! called from [[solve]], which handles some common !! startup tasks. All these routines assume that !! \( f(a_x) \) and \( f(b_x) \) have opposite signs. procedure :: get_fa_fb procedure :: converged procedure :: solution !! to check `f` value against `ftol` end type root_solver