perturb_x_and_compute_f Subroutine

private subroutine perturb_x_and_compute_f(me, x, dx_factor, dx, df_factor, column, idx, df)

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) :: column

the variable 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


Called by

proc~~perturb_x_and_compute_f~~CalledByGraph proc~perturb_x_and_compute_f numerical_differentiation_module::numdiff_type%perturb_x_and_compute_f proc~compute_jacobian_for_sparsity numerical_differentiation_module::numdiff_type%compute_jacobian_for_sparsity proc~compute_jacobian_for_sparsity->proc~perturb_x_and_compute_f proc~compute_jacobian_standard numerical_differentiation_module::compute_jacobian_standard proc~compute_jacobian_standard->proc~perturb_x_and_compute_f proc~compute_sparsity_random_2 numerical_differentiation_module::compute_sparsity_random_2 proc~compute_sparsity_random_2->proc~compute_jacobian_for_sparsity

Source Code

    subroutine perturb_x_and_compute_f(me,x,dx_factor,dx,&
                                       df_factor,column,idx,df)

    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,intent(in)                :: column    !! the variable 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%n) :: xp  !! the perturbed variable vector
    real(wp),dimension(me%m) :: f   !! function evaluation

    if (me%exception_raised) return ! check for exceptions

    xp = x
    if (dx_factor/=zero) xp(column) = xp(column) + dx_factor * dx(column)
    call me%compute_function(xp,f,idx)
    if (me%exception_raised) return ! check for exceptions
    df(idx) = df(idx) + df_factor * f(idx)

    end subroutine perturb_x_and_compute_f