Functions: SimModel Internals

Abstract Types

Model Construction

ModelPredictiveControl.init_defectmat_daeFunction
init_defectmat_dae(NT, ::OrthogonalCollocation, nx, na, Co, λo) -> Es, Ks, Aeq

Init the matrices for computing the defect of the next state.

Knowing that the decision vector $\mathbf{Z}$ contain $\mathbf{x̂_0}(k+1)$, $\mathbf{a_0}(k+0)$, $\mathbf{k̄}(k+0)$ and $\mathbf{ā}(k+0)$ vectors with an OrthogonalCollocation, this linear equation compute the defect of the states at time $k+1$:

\[\begin{aligned} \mathbf{s}(k+1) &= \mathbf{E_s Z + K_s x_0}(k) \\ &= \mathbf{E_s Z + F_s} \end{aligned}\]

It is forced to be $\mathbf{s}(k+1) = \mathbf{0}$ using the optimization equality constraints.

source
init_defectmat_dae(NT, ::CollocationMethod, nx, na, _ , _ ) -> Es, Ks, Aeq

No linear equality constraint for other CollocationMethods, return empty matrices.

source

State-Space Functions

ModelPredictiveControl.f!Function
f!(x0next, _ , model::LinModel, x0, u0, d0, _ ) -> nothing

Evaluate x0next = A*x0 + Bu*u0 + Bd*d0 in-place when model is a LinModel.

source
f!(x0next, k̄, model::NonLinModel, x0, u0, d0, p)

Compute x0next using the DiffSolver in model.solver and model.f!.

The method mutates x0next and arguments in-place. The latter is used to store the intermediate stage values of the solver.

source
f!(x0next, _ , model::NonLinModelDAE, x0, u0, d0, _ ) -> nothing

Solve the optimization model.optim problem for NonLinModelDAE.

After solving, the next state $\mathbf{x_0}(k+1)$ will be stored in-place in the x0next argument. The next algebraic variable $\mathbf{a_0}(k+1)$ will be also stored at model.a0.

source
ModelPredictiveControl.h!Function
h!(y0, model::LinModel, x0, d0, _ ) -> nothing

Evaluate y0 = C*x0 + Dd*d0 in-place when model is a LinModel.

source
h!(y0, model::NonLinModel, x0, d0, p)

Compute y0 by calling model.h! directly for NonLinModel.

source
h!(y0, model::NonLinModelDAE, x0, d0, p) -> nothing

Solve the algebraic equation to get a0 and call model.h! for NonLinModelDAE.

If model.iszero_Ha is true, the algebraic variable is not used in model.h! according to SparseConnectivityTracer.jl, the algebraic equation solving is thus skipped and model.h! is called directly.

source

Init State

ModelPredictiveControl.initstate_core!Function
initstate_core!(model::LinModel, u0, d0)

Set model.x0 to u0 and d0 steady-state if model is a LinModel.

Following setop! notation, the method evaluates the equilibrium from:

\[ \mathbf{x_0} = \mathbf{(I - A)^{-1}(B_u u_0 + B_d d_0 + f_{op} - x_{op})}\]

with constant manipulated inputs $\mathbf{u_0 = u - u_{op}}$ and measured disturbances $\mathbf{d_0 = d - d_{op}}$. The Moore-Penrose pseudo-inverse computes $\mathbf{(I - A)^{-1}}$ to support integrating model (integrator states will be 0).

source
initstate_core!(model::NonLinModelDAE, u0, d0)

Reset warm-starting for model.Z and model.a0 if model is a NonLinModelDAE.

The field model.a0 and model.Z respectively warm-start evaloutput and updatestate! solving. The method also set model.optim_u0 and model.optim_d0 at u0 and d0 values. The model.u0 field is used to solve the algebraic equation $\mathbf{q}$ in evaloutput method, but it should not impact the result in theory since model is strictly proper w.r.t. u0.

source
initstate_core!(::SimModel, u0, d0)

Do nothing at all by default.

source