set_numdiff_bounds Subroutine

private subroutine set_numdiff_bounds(me, xlow, xhigh)

Change the variable bounds in a numdiff_type.

See also

Note

The bounds must be set when the class is initialized, but this routine can be used to change them later if required.

Type Bound

numdiff_type

Arguments

Type IntentOptional Attributes Name
class(numdiff_type), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: xlow

lower bounds on x

real(kind=wp), intent(in), dimension(:) :: xhigh

upper bounds on x


Calls

proc~~set_numdiff_bounds~~CallsGraph proc~set_numdiff_bounds numerical_differentiation_module::numdiff_type%set_numdiff_bounds proc~integer_to_string numerical_differentiation_module::integer_to_string proc~set_numdiff_bounds->proc~integer_to_string proc~raise_exception numerical_differentiation_module::numdiff_type%raise_exception proc~set_numdiff_bounds->proc~raise_exception

Called by

proc~~set_numdiff_bounds~~CalledByGraph proc~set_numdiff_bounds numerical_differentiation_module::numdiff_type%set_numdiff_bounds proc~initialize_numdiff numerical_differentiation_module::numdiff_type%initialize_numdiff proc~initialize_numdiff->proc~set_numdiff_bounds proc~initialize_numdiff_for_diff numerical_differentiation_module::numdiff_type%initialize_numdiff_for_diff proc~initialize_numdiff_for_diff->proc~set_numdiff_bounds

Source Code

    subroutine set_numdiff_bounds(me,xlow,xhigh)

    implicit none

    class(numdiff_type),intent(inout) :: me
    real(wp),dimension(:),intent(in)  :: xlow    !! lower bounds on `x`
    real(wp),dimension(:),intent(in)  :: xhigh   !! upper bounds on `x`

    integer :: i  !! counter for error print
    character(len=:),allocatable :: error_info !! error message info
    character(len=:),allocatable :: istr   !! for integer to string
    character(len=30) :: xlow_str, xhigh_str !! for real to string

    if (me%exception_raised) return ! check for exceptions

    if (allocated(me%xlow))  deallocate(me%xlow)
    if (allocated(me%xhigh)) deallocate(me%xhigh)

    if (size(xlow)/=me%n .or. size(xhigh)/=me%n) then
        call me%raise_exception(3,'set_numdiff_bounds',&
                                  'invalid size of xlow or xhigh')
        return
    else if (any(xlow>=xhigh)) then
        error_info = 'all xlow must be < xhigh'
        do i = 1, size(xlow)
            if (xlow(i)>=xhigh(i)) then
                istr = integer_to_string(i)
                write(xlow_str,'(F30.16)') xlow(i)
                write(xhigh_str,'(F30.16)') xhigh(i)
                error_info = error_info//new_line('')//'  Error for optimization variable '//trim(adjustl(istr))//&
                                ': xlow='//trim(adjustl(xlow_str))//&
                                ' >= xhigh='//trim(adjustl(xhigh_str))
            end if
        end do
        call me%raise_exception(4,'set_numdiff_bounds',error_info)
        return
    else
        allocate(me%xlow(me%n))
        allocate(me%xhigh(me%n))
        me%xlow  = xlow
        me%xhigh = xhigh
    end if

    end subroutine set_numdiff_bounds