vecfcn_helper Derived Type

type, public :: vecfcn_helper

Defines a type capable of encapsulating a system of nonlinear equations of the form: F(X) = 0. This type is used to establish the system of equations to solve, and provides a means for computing the Jacobian matrix for the system of equations, and any other ancillary operations that may be needed by the solver.


Contents


Components

Type Visibility Attributes Name Initial
integer(kind=int32), public :: m_nvar = 0

The number of variables in m_fcn.


Type-Bound Procedures

procedure, public :: fcn => vfh_fcn

  • private subroutine vfh_fcn(this, x, f)

    Executes the routine containing the system of equations to solve. No action is taken if the pointer to the subroutine has not been defined.

    Arguments

    Type IntentOptional Attributes Name
    class(vecfcn_helper), intent(in) :: this

    The vecfcn_helper object.

    real(kind=real64), intent(in), dimension(:) :: x

    An N-element array containing the independent variables.

    real(kind=real64), intent(out), dimension(:) :: f

    An M-element array that, on output, contains the values of the M functions.

procedure, public :: get_equation_count => vfh_get_nfcn

  • private function vfh_get_nfcn(this) result(n)

    Gets the number of equations in this system.

    Arguments

    Type IntentOptional Attributes Name
    class(vecfcn_helper), intent(in) :: this

    The vecfcn_helper object.

    Return Value integer(kind=int32)

    The function count.

procedure, public :: get_variable_count => vfh_get_nvar

  • private function vfh_get_nvar(this) result(n)

    Gets the number of variables in this system.

    Arguments

    Type IntentOptional Attributes Name
    class(vecfcn_helper), intent(in) :: this

    The vecfcn_helper object.

    Return Value integer(kind=int32)

    The number of variables.

procedure, public :: is_fcn_defined => vfh_is_fcn_defined

  • private function vfh_is_fcn_defined(this) result(x)

    Tests if the pointer to the subroutine containing the system of equations to solve has been assigned.

    Arguments

    Type IntentOptional Attributes Name
    class(vecfcn_helper), intent(in) :: this

    The vecfcn_helper object.

    Return Value logical

    Returns true if the pointer has been assigned; else, false.

procedure, public :: is_jacobian_defined => vfh_is_jac_defined

  • private function vfh_is_jac_defined(this) result(x)

    Tests if the pointer to the Jacobian calculation routine has been defined.

    Arguments

    Type IntentOptional Attributes Name
    class(vecfcn_helper), intent(in) :: this

    The vecfcn_helper object.

    Return Value logical

    Returns true if the pointer has been assigned; else, false.

procedure, public :: jacobian => vfh_jac_fcn

  • private subroutine vfh_jac_fcn(this, x, jac, fv, work, olwork, err)

    Executes the routine containing the Jacobian matrix if supplied. If not supplied, the Jacobian is computed via finite differences.

    Arguments

    Type IntentOptional Attributes Name
    class(vecfcn_helper), intent(in) :: this

    The vecfcn_helper object.

    real(kind=real64), intent(inout), dimension(:) :: x

    An N-element array containing the independent variables defining the point about which the derivatives will be calculated.

    real(kind=real64), intent(out), dimension(:,:) :: jac

    An M-by-N matrix where, on output, the Jacobian will be written.

    real(kind=real64), intent(in), optional, dimension(:), target :: fv

    An optional M-element array containing the function values at x. If not supplied, the function values are computed at x.

    real(kind=real64), intent(out), optional, dimension(:), target :: work

    An optional input, that if provided, prevents any local memory allocation. If not provided, the memory required is allocated within. If provided, the length of the array must be at least olwork. Notice, a workspace array is only utilized if the user does not provide a routine for computing the Jacobian.

    integer(kind=int32), intent(out), optional :: olwork

    An optional output used to determine workspace size. If supplied, the routine determines the optimal size for work, and returns without performing any actual calculations.

    integer(kind=int32), intent(out), optional :: err

    An optional integer output that can be used to determine error status. If not used, and an error is encountered, the routine simply returns silently. If used, the following error codes identify error status:

    • 0: No error has occurred.

    • n: A positive integer denoting the index of an invalid input.

    • -1: Indicates internal memory allocation failed.

procedure, public :: set_fcn => vfh_set_fcn

  • private subroutine vfh_set_fcn(this, fcn, nfcn, nvar)

    Establishes a pointer to the routine containing the system of equations to solve.

    Arguments

    Type IntentOptional Attributes Name
    class(vecfcn_helper), intent(inout) :: this

    The vecfcn_helper object.

    procedure(vecfcn), intent(in), pointer :: fcn

    The function pointer.

    integer(kind=int32), intent(in) :: nfcn

    The number of functions.

    integer(kind=int32), intent(in) :: nvar

    The number of variables.

procedure, public :: set_jacobian => vfh_set_jac

  • private subroutine vfh_set_jac(this, jac)

    Establishes a pointer to the routine for computing the Jacobian matrix of the system of equations. If no routine is defined, the Jacobian matrix will be computed numerically (this is the default state).

    Arguments

    Type IntentOptional Attributes Name
    class(vecfcn_helper), intent(inout) :: this

    The vecfcn_helper object.

    procedure(jacobianfcn), intent(in), pointer :: jac

    The function pointer.