Functions: SimModel Internals
Abstract Types
ModelPredictiveControl.SimModelODE — Type
abstract type SimModelODE <: SimModelAbstract subtype of SimModel for ordinary differential equations.
ModelPredictiveControl.SimModelDAE — Type
abstract type SimModelDAE <: SimModelAbstract subtype of SimModel for differential and algebraic equations.
Model Construction
ModelPredictiveControl.init_defectmat_dae — Function
init_defectmat_dae(NT, ::OrthogonalCollocation, nx, na, Co, λo) -> Es, Ks, AeqInit 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.
init_defectmat_dae(NT, ::CollocationMethod, nx, na, _ , _ ) -> Es, Ks, AeqNo linear equality constraint for other CollocationMethods, return empty matrices.
State-Space Functions
ModelPredictiveControl.f! — Function
f!(x0next, _ , model::LinModel, x0, u0, d0, _ ) -> nothingEvaluate x0next = A*x0 + Bu*u0 + Bd*d0 in-place when model is a LinModel.
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 k̄ arguments in-place. The latter is used to store the intermediate stage values of the solver.
f!(x0next, _ , model::NonLinModelDAE, x0, u0, d0, _ ) -> nothingSolve 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.
ModelPredictiveControl.h! — Function
h!(y0, model::LinModel, x0, d0, _ ) -> nothingEvaluate y0 = C*x0 + Dd*d0 in-place when model is a LinModel.
h!(y0, model::NonLinModel, x0, d0, p)Compute y0 by calling model.h! directly for NonLinModel.
h!(y0, model::NonLinModelDAE, x0, d0, p) -> nothingSolve 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.
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).
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.
initstate_core!(::SimModel, u0, d0)Do nothing at all by default.