compute_perturb_vector Subroutine

private subroutine compute_perturb_vector(me, x, dpert, perturb_mode, dx)

Compute dx, the perturbation vector for x

Type Bound

numdiff_type

Arguments

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

vector of variables (size n)

real(kind=wp), intent(in), dimension(me%n) :: dpert
integer, intent(in) :: perturb_mode
real(kind=wp), intent(out), dimension(me%n) :: dx

absolute perturbation (>0) for each variable


Calls

proc~~compute_perturb_vector~~CallsGraph proc~compute_perturb_vector numerical_differentiation_module::numdiff_type%compute_perturb_vector proc~raise_exception numerical_differentiation_module::numdiff_type%raise_exception proc~compute_perturb_vector->proc~raise_exception

Called by

proc~~compute_perturb_vector~~CalledByGraph proc~compute_perturb_vector numerical_differentiation_module::numdiff_type%compute_perturb_vector proc~compute_perturbation_vector numerical_differentiation_module::numdiff_type%compute_perturbation_vector proc~compute_perturbation_vector->proc~compute_perturb_vector proc~compute_sparsity_perturbation_vector numerical_differentiation_module::numdiff_type%compute_sparsity_perturbation_vector proc~compute_sparsity_perturbation_vector->proc~compute_perturb_vector proc~compute_jacobian numerical_differentiation_module::numdiff_type%compute_jacobian proc~compute_jacobian->proc~compute_perturbation_vector proc~compute_jacobian_for_sparsity numerical_differentiation_module::numdiff_type%compute_jacobian_for_sparsity proc~compute_jacobian_for_sparsity->proc~compute_sparsity_perturbation_vector proc~compute_jacobian_dense numerical_differentiation_module::numdiff_type%compute_jacobian_dense proc~compute_jacobian_dense->proc~compute_jacobian proc~compute_jacobian_times_vector numerical_differentiation_module::numdiff_type%compute_jacobian_times_vector proc~compute_jacobian_times_vector->proc~compute_jacobian 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 compute_perturb_vector(me,x,dpert,perturb_mode,dx)

    implicit none

    class(numdiff_type),intent(inout)    :: me
    real(wp),dimension(me%n),intent(in)  :: x     !! vector of variables (size `n`)
    real(wp),dimension(me%n),intent(in)  :: dpert
    integer,intent(in)                   :: perturb_mode
    real(wp),dimension(me%n),intent(out) :: dx  !! absolute perturbation (>0)
                                                !! for each variable

    real(wp),parameter :: eps = epsilon(1.0_wp) !! the smallest allowed absolute step

    if (me%exception_raised) return ! check for exceptions

    select case (perturb_mode)
    case(1)
        dx = abs(dpert)
    case(2)
        dx = abs(dpert * x)
    case(3)
        dx = abs(dpert) * (1.0_wp + abs(x))
    case default
        call me%raise_exception(27,'compute_perturb_vector',&
                                   'invalid value for perturb_mode (must be 1, 2, or 3)')
        return
    end select

    ! make sure none are too small:
    where (dx<eps)
        dx = eps
    end where

    end subroutine compute_perturb_vector