derivatives.py

openconcept.utilities.math.derivatives.first_deriv(dts, q, n_segments=1, n_simpson_intervals_per_segment=2, order=4)

This method differentiates a quantity over time using fourth order finite differencing

A “segment” is defined as a portion of the quantity vector q with a constant delta t (or delta x, etc). This routine is designed to be used in the context of Simpson’s rule integration where segment endpoints are coincident in time and n_points_per_seg = 2*n + 1

Inputs:
  • dts (float) – “Time” step between points for each segment. Length of dts must equal n_segments (vector) Note that this is half the corresponding Simpson integration timestep

  • q (float) – Quantity to be differentiated (vector) Total length of q = n_segments * n_points_per_seg

  • n_segments (int) – Number of segments to differentiate. Each segment has constant dt (scalar)

  • n_simpson_intervals_per_segment (int) – Number of Simpson’s rule intervals per segment. Minimum is 2. (scalar) The number of points per segment = 2*n + 1

  • order (int) – Order of accuracy (choose 2 or 4)

Returns:

dqdt – Derivative of q with respect to time (vector)

Return type:

float

openconcept.utilities.math.derivatives.first_deriv_partials(dts, q, n_segments=1, n_simpson_intervals_per_segment=2, order=4)

This method provides the Jacobian of a temporal first derivative

A “segment” is defined as a portion of the quantity vector q with a constant delta t (or delta x, etc). This routine is designed to be used in the context of Simpson’s rule integration where segment endpoints are coincident in time and n_points_per_seg = 2*n + 1

Inputs:
  • dts (float) – “Time” step between points for each segment. Length of dts must equal n_segments (vector) Note that this is half the corresponding Simpson integration timestep

  • q (float) – Quantity to be differentiated (vector) Total length of q = n_segments * n_points_per_seg

  • n_segments (int) – Number of segments to differentiate. Each segment has constant dt (scalar)

  • n_simpson_intervals_per_segment (int) – Number of Simpson’s rule intervals per segment. Minimum is 2. (scalar) The number of points per segment = 2*n + 1

Returns:

  • d_dqdt_dq (list of floats) – Jacobian of the temporal derivative vector dqdt with respect its quantity vector q (NxN sparse array) returned in CSR format as rowidx, colidx, data

  • d_dqdt_ddt (list of list of floats) – Jacobians of the temporal derivative vector dqdt with respect to segment timestep dt[i] (Nx1 sparse arrays) returned in CSR format as rowidxs[i], colidxs[i], data[i]

class openconcept.utilities.math.derivatives.FirstDerivative(**kwargs)

Bases: ExplicitComponent

This component differentiates a vector using a second or fourth order finite difference approximation

Inputs:

q (float) – The vector quantity to differentiate. q is defined consistent with the Simpson’s Rule formulation used in the rest of this package q is comprised of multiple “segments” or phases with equal temporal spacing. The endpoints of each segment correspond to exacty the same timepoint as the endpoint of the next section q is of length nn_tot where nn_tot = n_segments x(2 x num_intervals + 1) Each segment of q is of length nn_seg = (2 x num_intervals + 1)