# finite_difference.py¶

Finite difference derivative approximations.

class openmdao.approximation_schemes.finite_difference.FDForm(deltas, coeffs, current_coeff)

Bases: tuple

__contains__(key, /)

Return key in self.

__getitem__(key, /)

Return self[key].

__iter__(/)

Implement iter(self).

coeffs

Alias for field number 1

count(value, /)

Return number of occurrences of value.

current_coeff

Alias for field number 2

deltas

Alias for field number 0

index(value, start=0, stop=sys.maxsize, /)

Return first index of value.

Raises ValueError if the value is not present.

class openmdao.approximation_schemes.finite_difference.FiniteDifference[source]

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).$
DEFAULT_OPTIONS = {'directional': False, 'form': 'forward', '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.

systemSystem

Containing System.

kwargsdict

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

vectorndarray or None

Direction for difference when using directional derivatives.

apply_directional(data, direction)[source]

Apply stepsize to direction and embed into approximation data.

Parameters
datatuple

Tuple contains step size, and other info.

directionndarray

Vector containing derivative direction.

Returns
ndarray

New tuple with new step direction.

compute_approx_col_iter(system, total=False, under_cs=False)[source]

Execute the system to compute the approximate sub-Jacobians.

Parameters
systemSystem

System on which the execution is run.

totalbool

If True total derivatives are being approximated, else partials.

under_csbool

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

compute_approximations(system, jac=None, total=False)

Execute the system to compute the approximate sub-Jacobians.

Parameters
systemSystem

System on which the execution is run.

jacNone or dict-like

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

totalbool

If True total derivatives are being approximated, else partials.