Skip to content

Commit 99aae6f

Browse files
authored
Merge pull request #145 from JuliaControl/new_ode_solver
added: new `ForwardEuler` solver with 0 allocation
2 parents 40ee33d + 0fde9bd commit 99aae6f

File tree

13 files changed

+85
-38
lines changed

13 files changed

+85
-38
lines changed

docs/src/public/sim_model.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,9 @@ ModelPredictiveControl.DiffSolver
6767
```@docs
6868
RungeKutta
6969
```
70+
71+
### ForwardEuler
72+
73+
```@docs
74+
ForwardEuler
75+
```

src/ModelPredictiveControl.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import PreallocationTools: DiffCache, get_tmp
2323
import OSQP, Ipopt
2424

2525
export SimModel, LinModel, NonLinModel
26-
export DiffSolver, RungeKutta
26+
export DiffSolver, RungeKutta, ForwardEuler
2727
export setop!, setname!
2828
export setstate!, setmodel!, preparestate!, updatestate!, evaloutput, linearize, linearize!
2929
export savetime!, periodsleep

src/controller/explicitmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ suitable for applications that require small sample times. The keyword arguments
100100
identical to [`LinMPC`](@ref), except for `Cwt` and `optim` which are not supported.
101101
102102
This method uses the default state estimator, a [`SteadyKalmanFilter`](@ref) with default
103-
arguments.
103+
arguments. This controller is allocation-free.
104104
105105
# Examples
106106
```jldoctest

src/controller/linmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ from ``j=0`` to ``H_p-1``. The slack variable ``ϵ`` relaxes the constraints, as
117117
in [`setconstraint!`](@ref) documentation. See Extended Help for a detailed nomenclature.
118118
119119
This method uses the default state estimator, a [`SteadyKalmanFilter`](@ref) with default
120-
arguments.
120+
arguments. This controller allocates memory at each time step for the optimization.
121121
122122
# Arguments
123123
- `model::LinModel` : model used for controller predictions and state estimations.

src/controller/nonlinmpc.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ This method uses the default state estimator:
144144
- if `model` is a [`LinModel`](@ref), a [`SteadyKalmanFilter`](@ref) with default arguments;
145145
- else, an [`UnscentedKalmanFilter`](@ref) with default arguments.
146146
147+
This controller allocates memory at each time step for the optimization.
148+
147149
!!! warning
148150
See Extended Help if you get an error like:
149151
`MethodError: no method matching Float64(::ForwardDiff.Dual)`.

src/estimator/internal_model.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ Construct an internal model estimator based on `model` ([`LinModel`](@ref) or [`
7171
unmeasured ``\mathbf{y^u}``. `model` evaluates the deterministic predictions
7272
``\mathbf{ŷ_d}``, and `stoch_ym`, the stochastic predictions of the measured outputs
7373
``\mathbf{ŷ_s^m}`` (the unmeasured ones being ``\mathbf{ŷ_s^u=0}``). The predicted outputs
74-
sum both values : ``\mathbf{ŷ = ŷ_d + ŷ_s}``. See the Extended Help for more details.
74+
sum both values : ``\mathbf{ŷ = ŷ_d + ŷ_s}``. See the Extended Help for more details. This
75+
estimator is allocation-free is `model` simulations do not allocate.
7576
7677
!!! warning
7778
`InternalModel` estimator does not work if `model` is integrating or unstable. The

src/estimator/kalman.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ on the covariance tuning. The matrices ``\mathbf{Ĉ^m, D̂_d^m}`` are the rows
101101
``\mathbf{Ĉ, D̂_d}`` that correspond to measured outputs ``\mathbf{y^m}`` (and unmeasured
102102
ones, for ``\mathbf{Ĉ^u, D̂_d^u}``). The Kalman filter will estimate the current state with
103103
the newest measurements ``\mathbf{x̂}_k(k)`` if `direct` is `true`, else it will predict the
104-
state of the next time step ``\mathbf{x̂}_k(k+1)``.
104+
state of the next time step ``\mathbf{x̂}_k(k+1)``. This estimator is allocation-free.
105105
106106
# Arguments
107107
!!! info
@@ -352,6 +352,7 @@ the estimation error covariance of `model` states augmented with the stochastic
352352
``\mathbf{P̂}_{-1}(0) = \mathrm{diag}\{ \mathbf{P}(0), \mathbf{P_{int_{u}}}(0),
353353
\mathbf{P_{int_{ym}}}(0) \}``. The initial state estimate ``\mathbf{x̂}_{-1}(0)`` can be
354354
manually specified with [`setstate!`](@ref), or automatically with [`initstate!`](@ref).
355+
This estimator is allocation-free.
355356
356357
# Arguments
357358
!!! info
@@ -596,6 +597,7 @@ matrix ``\mathbf{P̂}`` is the estimation error covariance of `model` state augm
596597
stochastic ones. Three keyword arguments specify its initial value with ``\mathbf{P̂}_{-1}(0) =
597598
\mathrm{diag}\{ \mathbf{P}(0), \mathbf{P_{int_{u}}}(0), \mathbf{P_{int_{ym}}}(0) \}``. The
598599
initial state estimate ``\mathbf{x̂}_{-1}(0)`` can be manually specified with [`setstate!`](@ref).
600+
This estimator is allocation-free if `model` simulations do not allocate.
599601
600602
# Arguments
601603
!!! info
@@ -950,7 +952,7 @@ Both [`LinModel`](@ref) and [`NonLinModel`](@ref) are supported. The process mod
950952
keyword arguments are identical to [`UnscentedKalmanFilter`](@ref), except for `α`, `β` and
951953
`κ` which do not apply to the extended Kalman Filter. The Jacobians of the augmented model
952954
``\mathbf{f̂, ĥ}`` are computed with [`ForwardDiff.jl`](https://github.com/JuliaDiff/ForwardDiff.jl)
953-
automatic differentiation.
955+
automatic differentiation. This estimator allocates memory for the Jacobians.
954956
955957
!!! warning
956958
See the Extended Help of [`linearize`](@ref) function if you get an error like:

src/estimator/luenberger.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ elements specifying the observer poles/eigenvalues (near ``z=0.5`` by default).
7878
is constructed with a direct transmission from ``\mathbf{y^m}`` if `direct=true` (a.k.a.
7979
current observers, in opposition to the delayed/prediction form). The method computes the
8080
observer gain `K̂` with [`place`](https://juliacontrol.github.io/ControlSystems.jl/stable/lib/synthesis/#ControlSystemsBase.place).
81+
This estimator is allocation-free.
8182
8283
# Examples
8384
```jldoctest

src/estimator/mhe/construct.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ the keyword argument `direct=true` (default value), the constant ``p=0`` in the
215215
above, and the MHE is in the current form. Else ``p=1``, leading to the prediction form.
216216
217217
See [`UnscentedKalmanFilter`](@ref) for details on the augmented process model and
218-
``\mathbf{R̂}, \mathbf{Q̂}`` covariances.
218+
``\mathbf{R̂}, \mathbf{Q̂}`` covariances. This estimator allocates a fair amount of memory
219+
at each time step.
219220
220221
!!! warning
221222
See the Extended Help if you get an error like:

src/model/linearization.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ end
120120
121121
Linearize `model` and store the result in `linmodel` (in-place).
122122
123-
The keyword arguments are identical to [`linearize`](@ref).
123+
The keyword arguments are identical to [`linearize`](@ref). The code is allocation-free if
124+
`model` simulations does not allocate.
124125
125126
# Examples
126127
```jldoctest

0 commit comments

Comments
 (0)