perturb_x_and_compute_f_partitioned Subroutine

private subroutine perturb_x_and_compute_f_partitioned(me, x, dx_factor, dx, df_factor, columns, idx, df, f0, f0_computed)

Perturb the specified optimization variable, and compute the function. This routine is designed so that df is accumulated as each function evaluation is done, to avoid having to allocate more temporary storage.

Type Bound

numdiff_type

Arguments

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

nominal variable vector

real(kind=wp), intent(in) :: dx_factor

factor to multiply dx

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

the perturbation value for this column

real(kind=wp), intent(in) :: df_factor

factor to multiply function value

integer, intent(in), dimension(:) :: columns

the variables to perturb

integer, intent(in), dimension(:) :: idx

the elements in this column of the Jacobian to compute (passed to function)

real(kind=wp), intent(inout), dimension(me%m) :: df

the accumulated function value note: for the first call, this should be set to zero

real(kind=wp), intent(inout), optional, dimension(me%m) :: f0

function value at the nominal x, reused when dx_factor=0 (see compute_nominal_function)

logical, intent(inout), optional :: f0_computed

if f0 has already been computed. must be set to false before the first call.


Calls

proc~~perturb_x_and_compute_f_partitioned~~CallsGraph proc~perturb_x_and_compute_f_partitioned numdiff_type%perturb_x_and_compute_f_partitioned proc~compute_nominal_function numdiff_type%compute_nominal_function proc~perturb_x_and_compute_f_partitioned->proc~compute_nominal_function interface~unique unique proc~compute_nominal_function->interface~unique proc~unique_int unique_int interface~unique->proc~unique_int proc~unique_real unique_real interface~unique->proc~unique_real interface~expand_vector expand_vector proc~unique_int->interface~expand_vector interface~sort_ascending sort_ascending proc~unique_int->interface~sort_ascending proc~unique_real->interface~expand_vector proc~unique_real->interface~sort_ascending proc~expand_vector_int expand_vector_int interface~expand_vector->proc~expand_vector_int proc~expand_vector_real expand_vector_real interface~expand_vector->proc~expand_vector_real proc~sort_ascending_int sort_ascending_int interface~sort_ascending->proc~sort_ascending_int proc~sort_ascending_real sort_ascending_real interface~sort_ascending->proc~sort_ascending_real interface~swap swap proc~sort_ascending_int->interface~swap proc~sort_ascending_real->interface~swap proc~swap_int swap_int interface~swap->proc~swap_int proc~swap_real swap_real interface~swap->proc~swap_real

Called by

proc~~perturb_x_and_compute_f_partitioned~~CalledByGraph proc~perturb_x_and_compute_f_partitioned numdiff_type%perturb_x_and_compute_f_partitioned proc~compute_jacobian_partitioned compute_jacobian_partitioned proc~compute_jacobian_partitioned->proc~perturb_x_and_compute_f_partitioned

Source Code

    subroutine perturb_x_and_compute_f_partitioned(me,x,dx_factor,dx,&
                                       df_factor,columns,idx,df,f0,f0_computed)

    implicit none

    class(numdiff_type),intent(inout) :: me
    real(wp),dimension(:),intent(in)  :: x         !! nominal variable vector
    real(wp),intent(in)               :: dx_factor !! factor to multiply `dx`
    real(wp),dimension(:),intent(in)  :: dx        !! the perturbation value for this column
    real(wp),intent(in)               :: df_factor !! factor to multiply function value
    integer,dimension(:),intent(in)   :: columns   !! the variables to perturb
    integer,dimension(:),intent(in)   :: idx       !! the elements in this
                                                   !! column of the Jacobian
                                                   !! to compute (passed to function)
    real(wp),dimension(me%m),intent(inout) :: df   !! the accumulated function value
                                                   !! note: for the first call, this
                                                   !! should be set to zero
    real(wp),dimension(me%m),intent(inout),optional :: f0 !! function value at the nominal `x`,
                                                          !! reused when `dx_factor=0`
                                                          !! (see [[compute_nominal_function]])
    logical,intent(inout),optional :: f0_computed  !! if `f0` has already been computed.
                                                   !! must be set to false before the first call.

    real(wp),dimension(me%m) :: f   !! function evaluation

    if (me%exception_raised) return ! check for exceptions

    if (dx_factor==zero .and. present(f0) .and. present(f0_computed)) then
        ! reuse the nominal function value:
        if (.not. f0_computed) then
            call me%compute_nominal_function(x,f0)
            if (me%exception_raised) return ! check for exceptions
            f0_computed = .true.
        end if
        df(idx) = df(idx) + df_factor * f0(idx)
        return
    end if

    ! note: me%xwork must equal x on entry (see [[init_xwork]]).
    ! only the perturbed elements are changed, and they are restored after the call.
    if (dx_factor/=zero) me%xwork(columns) = x(columns) + dx_factor * dx(columns)
    call me%compute_function(me%xwork,f,idx)
    me%xwork(columns) = x(columns)
    if (me%exception_raised) return ! check for exceptions
    df(idx) = df(idx) + df_factor * f(idx)

    end subroutine perturb_x_and_compute_f_partitioned