pockit.base.variablebase
Value matrix with interpolation nodes x_old
and evaluation nodes
x_new
.
Derivative matrix with interpolation nodes x_old
and evaluation
nodes x_new
.
Utility class for firstly indexing a batch of elements and then further indexing the value.
Arguments:
- data: The underlying data array.
- l_index: The left indices of each batch.
- r_index: The right indices of each batch (exclusive).
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.
Arguments:
- phase: The
Phase
object to create theVariable
for. - data: The underlying data 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)
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)
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)
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 underlying data array.
Typically used to pass to the solver.
The time interpolation nodes of the state variables.
The time interpolation nodes of the control variables.
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 newPhase
.
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 givenPhase
.
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 givenPhase
.