alloc_state Subroutine

public pure subroutine alloc_state(self, n, dima, stat)

Initializes nf_state, i.e., (re)allocates all allocatable arrays and sets them to zero.

Type Bound

nf_state

Arguments

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

State object.

integer, intent(in) :: n

Problem dimension.

integer, intent(in) :: dima

Dimension of the parameter vector a.

integer, intent(out), optional :: stat

Error status of the allocation.


Calls

proc~~alloc_state~~CallsGraph proc~alloc_state nf_state%alloc_state proc~alloc_workspace nf_workspace%alloc_workspace proc~alloc_state->proc~alloc_workspace

Called by

proc~~alloc_state~~CalledByGraph proc~alloc_state nf_state%alloc_state proc~nf_solver_initialize nf_solver%nf_solver_initialize proc~nf_solver_initialize->proc~alloc_state

Variables

Type Visibility Attributes Name Initial
integer, public :: ierr(6)

Source Code

   pure subroutine alloc_state(self, n, dima, stat)
   !! Initializes [[nf_state]], i.e., (re)allocates all allocatable arrays and sets them to
   !! zero.

      class(nf_state), intent(inout) :: self
         !! State object.
      integer, intent(in)  :: n
         !! Problem dimension.
      integer, intent(in)  :: dima
         !! Dimension of the parameter vector `a`.
      integer, intent(out), optional   :: stat
         !! Error status of the allocation.

      integer :: ierr(6)

      if (n <= 0) then
         error stop "Error: 'n' must be positive in hompack_nf_state%alloc()."
      end if

      if (dima <= 0) then
         error stop "Error: 'dima' must be positive in hompack_nf_state%alloc()."
      end if

      if (present(stat)) stat = 0

      ! Deallocate any previously allocated arrays
      self%n = 0
      if (allocated(self%y)) deallocate (self%y)
      if (allocated(self%yold)) deallocate (self%yold)
      if (allocated(self%yp)) deallocate (self%yp)
      if (allocated(self%ypold)) deallocate (self%ypold)
      if (allocated(self%a)) deallocate (self%a)

      ! Allocate/initialize state arrays
      allocate (self%y(n + 1), source=zero, stat=ierr(1))
      allocate (self%yold(n + 1), source=zero, stat=ierr(2))
      allocate (self%yp(n + 1), source=zero, stat=ierr(3))
      allocate (self%ypold(n + 1), source=zero, stat=ierr(4))
      allocate (self%a(dima), source=zero, stat=ierr(5))

      ! Initialize workspace
      call self%workspace%alloc(n, stat=ierr(6))

      if (any(ierr /= 0)) then
         if (present(stat)) then
            stat = ierr(findloc(ierr /= 0, .true., dim=1))
         else
            error stop "Error: Allocation failed in nf_state%alloc()."
         end if
      end if

      ! Set problem dimension now that allocation is successful
      self%n = n

   end subroutine alloc_state