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:

Utility class for firstly indexing a batch of elements and then further indexing the value.

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.

Variable objects provide two kinds of interfaces:

  • Plain 1D array for passing to the solver;
  • Methods for quickly accessing specific variables for users to set and extract corresponding values.

Besides, Variable provides methods to generate interpolation matrices for mesh adaption and plotting.

Generally, users need not create Variable objects directly. A better way is to use the func:constant_guess and func:linear_guess functions to generate a starting point and possibly adjust it manually.

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(t_0, 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(t_0, 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 derivative interpolation matrix for the state variables at the output time nodes t.

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(t_0, 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 derivative interpolation matrix for the control variables at the output time nodes t.

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(t_0, 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)

The state variables of the variable that could be further indexed.

The control variables of the variable that could be further indexed.

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 conditions are set to the corresponding values, while the other variables are set to value. The function could be used as a starting point to obtain the desired dimensions and interpolation nodes, and then the guesses could be manually adjusted further.

Arguments:
  • 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 conditions are set to the corresponding values; all other boundary conditions are assumed to be default. Then, linear interpolation is used to set variables in the middle. The function could be used as a starting point to obtain the desired dimensions and interpolation nodes, and then the guesses could be manually adjusted further.

Arguments:
  • phase: The Phase to guess for.
  • default: The default value to guess.
Returns:

A Variable with linear guesses for the given Phase.