pockit.base.variablebase

def V_interpolation( x_old: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], x_new: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]) -> numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]:

Value matrix with interpolation nodes x_old and evaluation nodes x_new.

def D_interpolation( x_old: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], x_new: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]) -> numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]:

Derivative matrix with interpolation nodes x_old and evaluation nodes x_new.

class BatchIndexArray:

Provide indexed access to a sequence of array slices.

BatchIndexArray( data: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], l_index: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]], r_index: numpy.ndarray[typing.Any, numpy.dtype[numpy.int32]])
Arguments:
  • data: The underlying data array.
  • l_index: The left indices of each batch.
  • r_index: The right indices of each batch (exclusive).
class VariableBase(abc.ABC):

Optimization variable for a discretized phase.

A Variable exposes its data both as a flat array for solvers and through convenient accessors for individual state and control variables. It also provides interpolation matrices for plotting and mesh adaptation.

Users normally create instances with constant_guess or linear_guess and then adjust the initial guess as needed.

VariableBase( phase: pockit.base.phasebase.PhaseBase, data: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]])
Arguments:
  • phase: The Phase object to create the Variable for.
  • data: The underlying data array.
def V_x( self, t: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]) -> scipy.sparse._csr.csr_array:

Return the value interpolation matrix for the state variables at the output time nodes t.

Arguments:
  • t: Time points for output.
Returns:

The interpolation matrix in the compressed sparse row format.

Examples:

Plot the first state variable at the output time nodes t_out:

>>> t_out = np.linspace(v.t_0, v.t_f, 100)
>>> V_x = v.V_x(t_out)
>>> x_out_0 = V_x @ v.x[0]
>>> plt.plot(t_out, x_out_0)
def V_u( self, t: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]) -> scipy.sparse._csr.csr_array:

Return the value interpolation matrix for the control variables at the output time nodes t.

Arguments:
  • t: Time points for output.
Returns:

The interpolation matrix in the compressed sparse row format.

Examples:

Plot the first control variable at the output time nodes t_out:

>>> t_out = np.linspace(v.t_0, v.t_f, 100)
>>> V_u = v.V_u(t_out)
>>> u_out_0 = V_u @ v.u[0]
>>> plt.plot(t_out, u_out_0)
def D_x( self, t: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]) -> scipy.sparse._csr.csr_array:

Return the physical-time derivative matrix for the state variables.

Arguments:
  • t: Time points for output.
Returns:

The derivative matrix in the compressed sparse row format.

Examples:

Plot the derivative of the first state variable at the output time nodes t_out:

>>> t_out = np.linspace(v.t_0, v.t_f, 100)
>>> D_x = v.D_x(t_out)
>>> dx_out_0 = D_x @ v.x[0]
>>> plt.plot(t_out, dx_out_0)
def D_u( self, t: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]) -> scipy.sparse._csr.csr_array:

Return the physical-time derivative matrix for the control variables.

Arguments:
  • t: Time points for output.
Returns:

The derivative matrix in the compressed sparse row format.

Examples:

Plot the derivative of the first control variable at the output time nodes t_out:

>>> t_out = np.linspace(v.t_0, v.t_f, 100)
>>> D_u = v.D_u(t_out)
>>> du_out_0 = D_u @ v.u[0]
>>> plt.plot(t_out, du_out_0)

State values, indexed by state variable.

Control values, indexed by control variable.

t_0: float

The initial time of the variable.

t_f: float

The terminal time of the variable.

data: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

The underlying data array.

Typically used to pass to the solver.

t_x: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

The time interpolation nodes of the state variables.

t_u: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

The time interpolation nodes of the control variables.

def adapt(self, phase: pockit.base.phasebase.PhaseBase) -> Self:

Adapt the Variable to a Phase with a different mesh and interpolation degree.

Return a new Variable object without changing the current one.

Arguments:
  • phase: The Phase with a different mesh and interpolation degree to adapt to.
Returns:

A new Variable object adapted with values interpolated from the current one and compatible with the discretization scheme of the new Phase.

def constant_guess_base( Variable: Type[VariableBase], phase: pockit.base.phasebase.PhaseBase, value: float = 1.0) -> VariableBase:

Return a Variable with constant guesses for a Phase.

Fixed boundary values are preserved, and all other variables are set to value. The returned object can be adjusted before it is passed to a solver.

Arguments:
  • Variable: Concrete Variable class to instantiate.
  • phase: The Phase to guess for.
  • value: The constant value to guess.
Returns:

A Variable with constant guesses for the given Phase.

def linear_guess_base( Variable: Type[VariableBase], phase: pockit.base.phasebase.PhaseBase, default: float = 1.0) -> VariableBase:

Return a Variable with linear guesses for a Phase.

Fixed boundary values are preserved. Missing boundary values are replaced by default, and state values between the boundaries are interpolated linearly. The returned object can be adjusted before it is passed to a solver.

Arguments:
  • Variable: Concrete Variable class to instantiate.
  • phase: The Phase to guess for.
  • default: The default value to guess.
Returns:

A Variable with linear guesses for the given Phase.