# finite_difference.py

# finite_difference.py¶

Finite difference derivative approximations.

classopenmdao.approximation_schemes.finite_difference.FiniteDifference[source]Bases:

`openmdao.approximation_schemes.approximation_scheme.ApproximationScheme`

Approximation scheme using finite differences to estimate derivatives.

For example, using the ‘forward’ form with a step size of ‘h’ will approximate the derivative in the following way:

\[f'(x) = \frac{f(x+h) - f(x)}{h} + O(h).\]

- Attributes

_starting_outsndarrayA copy of the starting outputs array used to restore the outputs to original values.

_starting_insndarrayA copy of the starting inputs array used to restore the inputs to original values.

_results_tmpndarrayAn array the same size as the system outputs. Used to store the results temporarily.

- DEFAULT_OPTIONS
= {'directional': False, 'form': 'forward', 'minimum_step': 1e-12, 'order': None, 'step': 1e-06, 'step_calc': 'abs'}

- __init__()[source]
Initialize the ApproximationScheme.

- add_approximation(
abs_key,system,kwargs,vector=None)[source]Use this approximation scheme to approximate the derivative d(of)/d(wrt).

- Parameters

abs_keytuple(str,str)Absolute name pairing of (of, wrt) for the derivative.

systemSystemContaining System.

kwargsdictAdditional keyword arguments, to be interpreted by sub-classes.

vectorndarray or NoneDirection for difference when using directional derivatives.

- apply_directional(
data,direction)[source]Apply stepsize to direction and embed into approximation data.

- Parameters

datatupleTuple contains step size, and other info.

directionndarrayVector containing derivative direction.

- Returns

- ndarray
New tuple with new step direction.

- compute_approx_col_iter(
system,under_cs=False)[source]Execute the system to compute the approximate sub-Jacobians.

- Parameters

systemSystemSystem on which the execution is run.

under_csboolTrue if we’re currently under complex step at a higher level.

- Yields

- int
column index

- ndarray
solution array corresponding to the jacobian column at the given column index

- compute_approximations(
system,jac=None)Execute the system to compute the approximate sub-Jacobians.

- Parameters

systemSystemSystem on which the execution is run.

jacNone or dict-likeIf None, update system with the approximated sub-Jacobians. Otherwise, store the approximations in the given dict-like object.