nf_solver_solve Function

public function nf_solver_solve(self, x0, a) result(result)

Type Bound

nf_solver

Arguments

Type IntentOptional Attributes Name
class(nf_solver), intent(inout) :: self

Solver object.

real(kind=dp), intent(in) :: x0(:)

Initial point for the solver. For fixed-point and zero-finding problems, this is the initial guess . For curve-tracking problems, this is the initial solution at .

real(kind=dp), intent(in), optional :: a(:)

Parameter vector for curve-tracking problems. Required if the solver was initialized with problem_type = curve_track.

Return Value type(nf_result)


Calls

proc~~nf_solver_solve~~CallsGraph proc~nf_solver_solve nf_solver%nf_solver_solve proc~fixpnf fixpnf proc~nf_solver_solve->proc~fixpnf proc~rootnf rootnf proc~fixpnf->proc~rootnf proc~stepnf stepnf proc~fixpnf->proc~stepnf proc~qofs qofs proc~rootnf->proc~qofs proc~root root proc~rootnf->proc~root proc~tangnf tangnf proc~rootnf->proc~tangnf proc~stepnf->proc~qofs proc~stepnf->proc~tangnf interface~dgeqpf dgeqpf proc~tangnf->interface~dgeqpf interface~dormqr dormqr proc~tangnf->interface~dormqr

Variables

Type Visibility Attributes Name Initial
integer, public :: iflag
integer, public :: n
real(kind=dp), public, allocatable :: a_(:)

Source Code

   type(nf_result) function nf_solver_solve(self, x0, a) result(result)

      class(nf_solver), intent(inout) :: self
         !! Solver object.
      real(dp), intent(in) :: x0(:)
         !! Initial point for the solver. For fixed-point and zero-finding problems, this is
         !! the initial guess \(a\). For curve-tracking problems, this is the initial solution
         !! \(x_0\) at \(\lambda=0\).
      real(dp), intent(in), optional :: a(:)
         !! Parameter vector \(a\) for curve-tracking problems. Required if the solver was
         !! initialized with `problem_type = curve_track`.

      integer :: iflag, n
      real(dp), allocatable :: a_(:)

      n = self%state%n

      associate (message => result%status%message, code => result%status%code)

         ! Validate that the solver has been initialized
         if (.not. self%initialized) then
            message = "Solver has not been initialized. Call `initialize` before `solve`."
            code = fixpnf_input_error
            return
         end if

         ! Validate the initial point 'x0'
         if (size(x0) /= n) then
            message = "Illegal input: length of `x0` must be equal to `n` specified during initialization."
            code = fixpnf_input_error
            return
         end if

         ! Validate the parameter vector 'a' for curve-tracking problems
         if (self%problem_type == problem_curve_track) then
            if (.not. present(a)) then
               message = "Illegal input: parameter vector `a` must be provided for curve-tracking problems."
               code = fixpnf_input_error
               return
            end if
            if (size(a) /= size(self%state%a)) then
               message = "Illegal input: length of parameter vector `a` must match the dimension specified during initialization."
               code = fixpnf_input_error
               return
            end if
            a_ = a
         else
            a_ = [zero]
         end if

      end associate

      ! Determine 'iflag'
      if (self%problem_type == problem_fix_point) then
         iflag = 0
      else if (self%problem_type == problem_zero_find) then
         iflag = -1
      else if (self%problem_type == problem_curve_track) then
         iflag = -2
      end if

      ! Call the solver
      call fixpnf(self%state, self%callbacks, self%state%n, x0, iflag, self%config, a_)

      ! Populate the result object
      result%arc_length = self%state%s
      result%lambda = self%state%y(1)
      result%x = self%state%y(2:n + 1)
      result%nfe = self%state%nfe
      result%status%code = iflag

   end function nf_solver_solve