Compute dx
, the perturbation vector for x
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
vector of variables (size |
|
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 |
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