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̄, ui, di, model::NonLinModel, x0, u0, d0, u0next, d0next)Compute x0next using the DiffSolver in model.solver and model.f!.
The method mutates x0next, k̄, ui and di arguments in-place. The k̄ argument is used to store the intermediate stage values of the solver. The ui and di arguments are used to stored the interpolated inputs and measured disturbances, respectively (needed for FOH discretization). The model parameter model.p is not included in the function signature for conciseness.
f!(x0next, _ , _ , _ , model::NonLinModelDAE, x0, u0, d0, u0next, d0next) -> 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 right limit of the current algebraic variable $\mathbf{a^+}(k+0)$ 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)Compute y0 by calling model.h! directly for NonLinModel.
h!(y0, model::NonLinModelDAE, x0, d0) -> 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.
ModelPredictiveControl.fq_dae! — Function
fq_dae!(ẋ0, q0, model, x0, a0, u0, d0)Call model.fq! for NonLinModelDAE or model.f! for NonLinModel.
Both the algebraic variable a0 and the residual q0 arguments are ignored if model is a NonLinModel.
ModelPredictiveControl.h_dae! — Function
h_dae!(y0, model, x0, a0, d0)Call model.h! with the a0 argument if NonLinModelDAE, else without.
The a0 argument is ignored for SimModelODEs. See also fq_dae!.
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.