complex_step.py

complex_step.py#

Complex Step derivative approximations.

class openmdao.approximation_schemes.complex_step.ComplexStep[source]

Bases: ApproximationScheme

Approximation scheme using complex step to calculate derivatives.

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

\[f'(x) = \Im{\frac{f(x+ih)}{h}}.\]
Attributes:
_fd<FiniteDifference>

When nested complex step is detected, we switch to Finite Difference.

DEFAULT_OPTIONS = {'directional': False, 'step': 1e-40}
__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:
datafloat

Step size for complex step.

directionndarray

Vector containing derivative direction.

Returns:
ndarray

New step direction.

compute_approx_col_iter(system, under_cs=False)[source]

Execute the system to compute the approximate sub-Jacobians.

Parameters:
systemSystem

System on which the execution is run.

under_csbool

True 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:
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.