Skip to content

Commit ec138f6

Browse files
committed
removed: t/k arguments in NonLinModel signature
Can be implemented with a new measured disturbance. Seems like a bloat feature.
1 parent 218b0f1 commit ec138f6

File tree

10 files changed

+85
-88
lines changed

10 files changed

+85
-88
lines changed

src/estimator/execute.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function f̂!(x̂next0, û0, estim::StateEstimator, model::SimModel, x̂0, u0,
4040
@views x̂d_next, x̂s_next = x̂next0[1:model.nx], x̂next0[model.nx+1:end]
4141
mul!(û0, estim.Cs_u, x̂s)
4242
û0 .+= u0
43-
f!(x̂d_next, model, x̂d, û0, d0)
43+
f!(x̂d_next, model, x̂d, û0, d0, model.p)
4444
mul!(x̂s_next, estim.As, x̂s)
4545
return nothing
4646
end
@@ -65,7 +65,7 @@ Mutating output function ``\mathbf{ĥ}`` of the augmented model, see [`f̂!`](@
6565
function ĥ!(ŷ0, estim::StateEstimator, model::SimModel, x̂0, d0)
6666
# `@views` macro avoid copies with matrix slice operator e.g. [a:b]
6767
@views x̂d, x̂s = x̂0[1:model.nx], x̂0[model.nx+1:end]
68-
h!(ŷ0, model, x̂d, d0)
68+
h!(ŷ0, model, x̂d, d0, model.p)
6969
mul!(ŷ0, estim.Cs_y, x̂s, 1, 1)
7070
return nothing
7171
end

src/estimator/internal_model.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ end
171171
172172
State function ``\mathbf{f̂}`` of [`InternalModel`](@ref) for [`NonLinModel`](@ref).
173173
174-
It calls `model.f!(x̂next0, x̂0, u0 ,d0)` since this estimator does not augment the states.
174+
It calls `model.f!(x̂next0, x̂0, u0 ,d0, model.p)` since this estimator does not augment the states.
175175
"""
176-
f̂!(x̂next0, _, ::InternalModel, model::NonLinModel, x̂0, u0, d0) = model.f!(x̂next0, x̂0, u0, d0)
176+
f̂!(x̂next0, _, ::InternalModel, model::NonLinModel, x̂0, u0, d0) = model.f!(x̂next0, x̂0, u0, d0, model.p)
177177

178178
@doc raw"""
179179
ĥ!(ŷ0, estim::InternalModel, model::NonLinModel, x̂0, d0)
180180
181181
Output function ``\mathbf{ĥ}`` of [`InternalModel`](@ref), it calls `model.h!`.
182182
"""
183-
ĥ!(x̂next0, ::InternalModel, model::NonLinModel, x̂0, d0) = model.h!(x̂next0, x̂0, d0)
183+
ĥ!(x̂next0, ::InternalModel, model::NonLinModel, x̂0, d0) = model.h!(x̂next0, x̂0, d0, model.p)
184184

185185

186186
@doc raw"""
@@ -246,7 +246,7 @@ Compute the current stochastic output estimation `ŷs` for [`InternalModel`](@r
246246
"""
247247
function correct_estimate!(estim::InternalModel, y0m, d0)
248248
ŷ0d = estim.buffer.
249-
h!(ŷ0d, estim.model, estim.x̂d, d0)
249+
h!(ŷ0d, estim.model, estim.x̂d, d0, estim.model.p)
250250
ŷs = estim.ŷs
251251
for j in eachindex(ŷs) # broadcasting was allocating unexpectedly, so we use a loop
252252
if j in estim.i_ym
@@ -279,7 +279,7 @@ function update_estimate!(estim::InternalModel, _ , d0, u0)
279279
x̂d, x̂s, ŷs = estim.x̂d, estim.x̂s, estim.ŷs
280280
# -------------- deterministic model ---------------------
281281
x̂dnext = estim.buffer.
282-
f!(x̂dnext, model, x̂d, u0, d0)
282+
f!(x̂dnext, model, x̂d, u0, d0, model.p)
283283
x̂d .= x̂dnext # this also updates estim.x̂0 (they are the same object)
284284
# --------------- stochastic model -----------------------
285285
x̂snext = estim.x̂snext
@@ -317,7 +317,7 @@ function init_estimate!(estim::InternalModel, model::LinModel{NT}, y0m, d0, u0)
317317
# TODO: use estim.buffer.x̂ to reduce the allocation:
318318
x̂d .= (I - model.A)\(model.Bu*u0 + model.Bd*d0 + model.fop - model.xop)
319319
ŷ0d = estim.buffer.
320-
h!(ŷ0d, model, x̂d, d0)
320+
h!(ŷ0d, model, x̂d, d0, model.p)
321321
ŷs = ŷ0d
322322
ŷs[estim.i_ym] .= @views y0m .- ŷ0d[estim.i_ym]
323323
# ŷs=0 for unmeasured outputs :

src/estimator/kalman.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,10 @@ See [`SteadyKalmanFilter`](@ref) for details on ``\mathbf{v}(k), \mathbf{w}(k)``
582582
\text{diag}(Q, Q_{int_u}, Q_{int_{ym}})}`` and ``\mathbf{R̂ = R}``. The functions
583583
``\mathbf{f̂, ĥ}`` are `model` state-space functions augmented with the stochastic model of
584584
the unmeasured disturbances, which is specified by the numbers of integrator `nint_u` and
585-
`nint_ym` (see Extended Help). The ``\mathbf{ĥ^m}`` function represents the measured outputs
586-
of ``\mathbf{ĥ}`` function (and unmeasured ones, for ``\mathbf{ĥ^u}``). The matrix
587-
``\mathbf{P̂}`` is the estimation error covariance of `model` state augmented with the
585+
`nint_ym` (see Extended Help). Model parameters ``\mathbf{p}`` are not an argument of
586+
``\mathbf{f̂, ĥ}`` functions for conciseness. The ``\mathbf{ĥ^m}`` function represents the
587+
measured outputs of ``\mathbf{ĥ}`` function (and unmeasured ones, for ``\mathbf{ĥ^u}``). The
588+
matrix ``\mathbf{P̂}`` is the estimation error covariance of `model` state augmented with the
588589
stochastic ones. Three keyword arguments specify its initial value with ``\mathbf{P̂}_{-1}(0) =
589590
\mathrm{diag}\{ \mathbf{P}(0), \mathbf{P_{int_{u}}}(0), \mathbf{P_{int_{ym}}}(0) \}``. The
590591
initial state estimate ``\mathbf{x̂}_{-1}(0)`` can be manually specified with [`setstate!`](@ref).

src/model/linearization.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,22 @@ function linearize!(
121121
A::Matrix{NT}, Bu::Matrix{NT}, Bd::Matrix{NT} = linmodel.A, linmodel.Bu, linmodel.Bd
122122
C::Matrix{NT}, Dd::Matrix{NT} = linmodel.C, linmodel.Dd
123123
xnext0::Vector{NT}, y0::Vector{NT} = linmodel.buffer.x, linmodel.buffer.y
124-
myf_x0!(xnext0, x0) = f!(xnext0, nonlinmodel, x0, u0, d0)
125-
myf_u0!(xnext0, u0) = f!(xnext0, nonlinmodel, x0, u0, d0)
126-
myf_d0!(xnext0, d0) = f!(xnext0, nonlinmodel, x0, u0, d0)
127-
myh_x0!(y0, x0) = h!(y0, nonlinmodel, x0, d0)
128-
myh_d0!(y0, d0) = h!(y0, nonlinmodel, x0, d0)
124+
myf_x0!(xnext0, x0) = f!(xnext0, nonlinmodel, x0, u0, d0, model.p)
125+
myf_u0!(xnext0, u0) = f!(xnext0, nonlinmodel, x0, u0, d0, model.p)
126+
myf_d0!(xnext0, d0) = f!(xnext0, nonlinmodel, x0, u0, d0, model.p)
127+
myh_x0!(y0, x0) = h!(y0, nonlinmodel, x0, d0, model.p)
128+
myh_d0!(y0, d0) = h!(y0, nonlinmodel, x0, d0, model.p)
129129
ForwardDiff.jacobian!(A, myf_x0!, xnext0, x0)
130130
ForwardDiff.jacobian!(Bu, myf_u0!, xnext0, u0)
131131
ForwardDiff.jacobian!(Bd, myf_d0!, xnext0, d0)
132132
ForwardDiff.jacobian!(C, myh_x0!, y0, x0)
133133
ForwardDiff.jacobian!(Dd, myh_d0!, y0, d0)
134134
# --- compute the nonlinear model output at operating points ---
135-
h!(y0, nonlinmodel, x0, d0)
135+
h!(y0, nonlinmodel, x0, d0, model.p)
136136
y = y0
137137
y .= y0 .+ nonlinmodel.yop
138138
# --- compute the nonlinear model next state at operating points ---
139-
f!(xnext0, nonlinmodel, x0, u0, d0)
139+
f!(xnext0, nonlinmodel, x0, u0, d0, model.p)
140140
xnext = xnext0
141141
xnext .= xnext0 .+ nonlinmodel.fop .- nonlinmodel.xop
142142
# --- modify the linear model operating points ---

src/model/linmodel.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct LinModel{NT<:Real} <: SimModel{NT}
55
Bd ::Matrix{NT}
66
Dd ::Matrix{NT}
77
x0::Vector{NT}
8-
k::Vector{Int}
8+
p ::Nothing
99
Ts::NT
1010
t::Vector{NT}
1111
nu::Int
@@ -36,8 +36,8 @@ struct LinModel{NT<:Real} <: SimModel{NT}
3636
size(C) == (ny,nx) || error("C size must be $((ny,nx))")
3737
size(Bd) == (nx,nd) || error("Bd size must be $((nx,nd))")
3838
size(Dd) == (ny,nd) || error("Dd size must be $((ny,nd))")
39+
p = nothing # the parameter field p is not used for LinModel
3940
Ts > 0 || error("Sampling time Ts must be positive")
40-
k = [0]
4141
uop = zeros(NT, nu)
4242
yop = zeros(NT, ny)
4343
dop = zeros(NT, nd)
@@ -52,8 +52,9 @@ struct LinModel{NT<:Real} <: SimModel{NT}
5252
buffer = SimModelBuffer{NT}(nu, nx, ny, nd)
5353
return new{NT}(
5454
A, Bu, C, Bd, Dd,
55-
x0,
56-
k, Ts, t,
55+
x0,
56+
p,
57+
Ts, t,
5758
nu, nx, ny, nd,
5859
uop, yop, dop, xop, fop,
5960
uname, yname, dname, xname,
@@ -256,11 +257,11 @@ function steadystate!(model::LinModel, u0, d0)
256257
end
257258

258259
"""
259-
f!(xnext0, model::LinModel, x0, u0, d0, _ , _ ) -> nothing
260+
f!(xnext0, model::LinModel, x0, u0, d0, p) -> nothing
260261
261262
Evaluate `xnext0 = A*x0 + Bu*u0 + Bd*d0` in-place when `model` is a [`LinModel`](@ref).
262263
"""
263-
function f!(xnext0, model::LinModel, x0, u0, d0, _ , _ )
264+
function f!(xnext0, model::LinModel, x0, u0, d0, _ )
264265
mul!(xnext0, model.A, x0)
265266
mul!(xnext0, model.Bu, u0, 1, 1)
266267
mul!(xnext0, model.Bd, d0, 1, 1)
@@ -269,11 +270,11 @@ end
269270

270271

271272
"""
272-
h!(y0, model::LinModel, x0, d0, _ , _ ) -> nothing
273+
h!(y0, model::LinModel, x0, d0, p) -> nothing
273274
274275
Evaluate `y0 = C*x0 + Dd*d0` in-place when `model` is a [`LinModel`](@ref).
275276
"""
276-
function h!(y0, model::LinModel, x0, d0, _ , _ )
277+
function h!(y0, model::LinModel, x0, d0, _ )
277278
mul!(y0, model.C, x0)
278279
mul!(y0, model.Dd, d0, 1, 1)
279280
return nothing

src/model/nonlinmodel.jl

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ struct NonLinModel{
66
h!::H
77
p::P
88
solver::DS
9-
k::Vector{Int}
109
Ts::NT
1110
t::Vector{NT}
1211
nu::Int
@@ -27,7 +26,6 @@ struct NonLinModel{
2726
f!::F, h!::H, Ts, nu, nx, ny, nd, p::P, solver::DS
2827
) where {NT<:Real, F<:Function, H<:Function, P<:Any, DS<:DiffSolver}
2928
Ts > 0 || error("Sampling time Ts must be positive")
30-
k = [0]
3129
uop = zeros(NT, nu)
3230
yop = zeros(NT, ny)
3331
dop = zeros(NT, nd)
@@ -45,7 +43,7 @@ struct NonLinModel{
4543
f!, h!,
4644
p,
4745
solver,
48-
k, Ts, t,
46+
Ts, t,
4947
nu, nx, ny, nd,
5048
uop, yop, dop, xop, fop,
5149
uname, yname, dname, xname,
@@ -65,18 +63,18 @@ continuous dynamics. Use `solver=nothing` for the discrete case (see Extended He
6563
functions are defined as:
6664
```math
6765
\begin{aligned}
68-
\mathbf{ẋ}(t) &= \mathbf{f}\Big( \mathbf{x}(t), \mathbf{u}(t), \mathbf{d}(t), \mathbf{p}(t), t \Big) \\
69-
\mathbf{y}(t) &= \mathbf{h}\Big( \mathbf{x}(t), \mathbf{d}(t), \mathbf{p}(t), t \Big)
66+
\mathbf{ẋ}(t) &= \mathbf{f}\Big( \mathbf{x}(t), \mathbf{u}(t), \mathbf{d}(t), \mathbf{p} \Big) \\
67+
\mathbf{y}(t) &= \mathbf{h}\Big( \mathbf{x}(t), \mathbf{d}(t), \mathbf{p} \Big)
7068
\end{aligned}
7169
```
7270
where ``\mathbf{x}``, ``\mathbf{y}, ``\mathbf{u}``, ``\mathbf{d}`` and ``\mathbf{p}`` are
7371
respectively the state, output, manipulated input, measured disturbance and parameter vectors,
7472
and ``t`` the time in second. The functions can be implemented in two possible ways:
7573
76-
1. **Non-mutating functions** (out-of-place): define them as `f(x, u, d, p, t) -> ẋ` and
77-
`h(x, d, p, t) -> y`. This syntax is simple and intuitive but it allocates more memory.
78-
2. **Mutating functions** (in-place): define them as `f!(ẋ, x, u, d, p, t) -> nothing` and
79-
`h!(y, x, d, p, t) -> nothing`. This syntax reduces the allocations and potentially the
74+
1. **Non-mutating functions** (out-of-place): define them as `f(x, u, d, p) -> ẋ` and
75+
`h(x, d, p) -> y`. This syntax is simple and intuitive but it allocates more memory.
76+
2. **Mutating functions** (in-place): define them as `f!(ẋ, x, u, d, p) -> nothing` and
77+
`h!(y, x, d, p) -> nothing`. This syntax reduces the allocations and potentially the
8078
computational burden as well.
8179
8280
`Ts` is the sampling time in second. `nu`, `nx`, `ny` and `nd` are the respective number of
@@ -85,7 +83,7 @@ is the parameters of the model passed to the two functions. It can be of any Jul
8583
but use a mutable type if you want to change them later e.g.: a vector.
8684
8785
!!! tip
88-
Replace the `d`, `p` or `t` argument with `_` if not needed (see Examples below).
86+
Replace the `d` or `p` argument with `_` in your functions if not needed (see Examples below).
8987
9088
A 4th order [`RungeKutta`](@ref) solver discretizes the differential equations by default.
9189
The rest of the documentation assumes discrete dynamics since all models end up in this
@@ -100,9 +98,9 @@ See also [`LinModel`](@ref).
10098
10199
# Examples
102100
```jldoctest
103-
julia> f!(ẋ, x, u, _ ) = (ẋ .= -0.2x .+ u; nothing);
101+
julia> f!(ẋ, x, u, _ , _ ) = (ẋ .= -0.2x .+ u; nothing);
104102
105-
julia> h!(y, x, _ ) = (y .= 0.1x; nothing);
103+
julia> h!(y, x, _ , _ ) = (y .= 0.1x; nothing);
106104
107105
julia> model1 = NonLinModel(f!, h!, 5.0, 1, 1, 1) # continuous dynamics
108106
NonLinModel with a sample time Ts = 5.0 s, RungeKutta solver and:
@@ -111,9 +109,9 @@ NonLinModel with a sample time Ts = 5.0 s, RungeKutta solver and:
111109
1 outputs y
112110
0 measured disturbances d
113111
114-
julia> f(x, u, _ ) = 0.1x + u;
112+
julia> f(x, u, _ , _ ) = 0.1x + u;
115113
116-
julia> h(x, _ ) = 2x;
114+
julia> h(x, _ , _ ) = 2x;
117115
118116
julia> model2 = NonLinModel(f, h, 2.0, 1, 1, 1, solver=nothing) # discrete dynamics
119117
NonLinModel with a sample time Ts = 2.0 s, empty solver and:
@@ -128,16 +126,16 @@ NonLinModel with a sample time Ts = 2.0 s, empty solver and:
128126
State-space functions are similar for discrete dynamics:
129127
```math
130128
\begin{aligned}
131-
\mathbf{x}(k+1) &= \mathbf{f}\Big( \mathbf{x}(k), \mathbf{u}(k), \mathbf{d}(k), \mathbf{p}(k), k \Big) \\
132-
\mathbf{y}(k) &= \mathbf{h}\Big( \mathbf{x}(k), \mathbf{d}(k), \mathbf{p}(k), k \Big)
129+
\mathbf{x}(k+1) &= \mathbf{f}\Big( \mathbf{x}(k), \mathbf{u}(k), \mathbf{d}(k), \mathbf{p}(k) \Big) \\
130+
\mathbf{y}(k) &= \mathbf{h}\Big( \mathbf{x}(k), \mathbf{d}(k), \mathbf{p}(k) \Big)
133131
\end{aligned}
134132
```
135133
with two possible implementations as well:
136134
137-
1. **Non-mutating functions**: define them as `f(x, u, d, p, k) -> xnext` and
138-
`h(x, d, p, k) -> y`.
139-
2. **Mutating functions**: define them as `f!(xnext, x, u, d, p, k) -> nothing` and
140-
`h!(y, x, d, p, k) -> nothing`.
135+
1. **Non-mutating functions**: define them as `f(x, u, d, p) -> xnext` and
136+
`h(x, d, p) -> y`.
137+
2. **Mutating functions**: define them as `f!(xnext, x, u, d, p) -> nothing` and
138+
`h!(y, x, d, p) -> nothing`.
141139
"""
142140
function NonLinModel{NT}(
143141
f::Function, h::Function, Ts::Real, nu::Int, nx::Int, ny::Int, nd::Int=0;
@@ -146,8 +144,8 @@ function NonLinModel{NT}(
146144
isnothing(solver) && (solver=EmptySolver())
147145
ismutating_f = validate_f(NT, f)
148146
ismutating_h = validate_h(NT, h)
149-
f! = ismutating_f ? f : f!(xnext, x, u, d, p, k) = (xnext .= f(x, u, d, p, k); nothing)
150-
h! = ismutating_h ? h : h!(y, x, d, p, k) = (y .= h(x, d, p, k); nothing)
147+
f! = ismutating_f ? f : f!(xnext, x, u, d, p) = (xnext .= f(x, u, d, p); nothing)
148+
h! = ismutating_h ? h : h!(y, x, d, p) = (y .= h(x, d, p); nothing)
151149
f!, h! = get_solver_functions(NT, solver, f!, h!, Ts, nu, nx, ny, nd)
152150
F, H, P, DS = get_types(f!, h!, p, solver)
153151
return NonLinModel{NT, F, H, P, DS}(f!, h!, Ts, nu, nx, ny, nd, p, solver)
@@ -173,13 +171,13 @@ end
173171
Validate `f` function argument signature and return `true` if it is mutating.
174172
"""
175173
function validate_f(NT, f)
176-
ismutating = hasmethod(f, Tuple{Vector{NT}, Vector{NT}, Vector{NT}, Vector{NT}, Any, NT})
177-
if !(ismutating || hasmethod(f, Tuple{Vector{NT}, Vector{NT}, Vector{NT}, Any, NT}))
174+
ismutating = hasmethod(f, Tuple{Vector{NT}, Vector{NT}, Vector{NT}, Vector{NT}, Any})
175+
if !(ismutating || hasmethod(f, Tuple{Vector{NT}, Vector{NT}, Vector{NT}, Any}))
178176
error(
179177
"the state function has no method with type signature "*
180-
"f(x::Vector{$(NT)}, u::Vector{$(NT)}, d::Vector{$(NT)}, p::Any, t::$(NT)) or "*
178+
"f(x::Vector{$(NT)}, u::Vector{$(NT)}, d::Vector{$(NT)}, p::Any) or "*
181179
"mutating form f!(xnext::Vector{$(NT)}, x::Vector{$(NT)}, u::Vector{$(NT)}, "*
182-
"d::Vector{$(NT)}, p::Any, t::$(NT))"
180+
"d::Vector{$(NT)}, p::Any)"
183181
)
184182
end
185183
return ismutating
@@ -191,12 +189,12 @@ end
191189
Validate `h` function argument signature and return `true` if it is mutating.
192190
"""
193191
function validate_h(NT, h)
194-
ismutating = hasmethod(h, Tuple{Vector{NT}, Vector{NT}, Vector{NT}, Any, NT})
195-
if !(ismutating || hasmethod(h, Tuple{Vector{NT}, Vector{NT}, Any, NT}))
192+
ismutating = hasmethod(h, Tuple{Vector{NT}, Vector{NT}, Vector{NT}, Any})
193+
if !(ismutating || hasmethod(h, Tuple{Vector{NT}, Vector{NT}, Any}))
196194
error(
197195
"the output function has no method with type signature "*
198-
"h(x::Vector{$(NT)}, d::Vector{$(NT)}, p::Any, t::$(NT)) or mutating form "*
199-
"h!(y::Vector{$(NT)}, x::Vector{$(NT)}, d::Vector{$(NT)}, p::Any, t::$(NT))"
196+
"h(x::Vector{$(NT)}, d::Vector{$(NT)}, p::Any) or mutating form "*
197+
"h!(y::Vector{$(NT)}, x::Vector{$(NT)}, d::Vector{$(NT)}, p::Any)"
200198
)
201199
end
202200
return ismutating
@@ -205,11 +203,11 @@ end
205203
"Do nothing if `model` is a [`NonLinModel`](@ref)."
206204
steadystate!(::SimModel, _ , _ ) = nothing
207205

208-
"Call `f!(xnext0, x0, u0, d0, p, k)` with `model.f!` method for [`NonLinModel`](@ref)."
209-
f!(xnext0, model::NonLinModel, x0, u0, d0, p, k) = model.f!(xnext0, x0, u0, d0, p, k)
206+
"Call `model.f!(xnext0, x0, u0, d0, p)` for [`NonLinModel`](@ref)."
207+
f!(xnext0, model::NonLinModel, x0, u0, d0, p) = model.f!(xnext0, x0, u0, d0, p)
210208

211-
"Call `h!(y0, x0, d0, p, k)` with `model.h` method for [`NonLinModel`](@ref)."
212-
h!(y0, model::NonLinModel, x0, d0, p, k) = model.h!(y0, x0, d0, p, k)
209+
"Call `model.h!(y0, x0, d0, p)` for [`NonLinModel`](@ref)."
210+
h!(y0, model::NonLinModel, x0, d0, p) = model.h!(y0, x0, d0, p)
213211

214212
detailstr(model::NonLinModel) = ", $(typeof(model.solver).name.name) solver"
215213
detailstr(::NonLinModel{<:Real, <:Function, <:Function, <:Any, <:EmptySolver}) = ", empty solver"

src/model/solver.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function get_solver_functions(NT::DataType, solver::RungeKutta, fc!, hc!, Ts, _
4545
k2_cache::DiffCache{Vector{NT}, Vector{NT}} = DiffCache(zeros(NT, nx), Nc)
4646
k3_cache::DiffCache{Vector{NT}, Vector{NT}} = DiffCache(zeros(NT, nx), Nc)
4747
k4_cache::DiffCache{Vector{NT}, Vector{NT}} = DiffCache(zeros(NT, nx), Nc)
48-
f! = function inner_solver_f!(xnext, x, u, d, p, k)
48+
f! = function inner_solver_f!(xnext, x, u, d, p)
4949
CT = promote_type(eltype(x), eltype(u), eltype(d))
5050
# dummy variable for get_tmp, necessary for PreallocationTools + Julia 1.6 :
5151
var::CT = 0
@@ -55,23 +55,22 @@ function get_solver_functions(NT::DataType, solver::RungeKutta, fc!, hc!, Ts, _
5555
k3 = get_tmp(k3_cache, var)
5656
k4 = get_tmp(k4_cache, var)
5757
@. xcur = x
58-
for k_inner=0:solver.supersample-1
58+
for i=1:solver.supersample
5959
xterm = xnext # TODO: move this out of the loop, just above (to test) ?
60-
t = k*Ts + k_inner*Ts_inner
6160
@. xterm = xcur
62-
fc!(k1, xterm, u, d, p, t)
61+
fc!(k1, xterm, u, d, p)
6362
@. xterm = xcur + k1 * Ts_inner/2
64-
fc!(k2, xterm, u, d, p, t)
63+
fc!(k2, xterm, u, d, p)
6564
@. xterm = xcur + k2 * Ts_inner/2
66-
fc!(k3, xterm, u, d, p, t)
65+
fc!(k3, xterm, u, d, p)
6766
@. xterm = xcur + k3 * Ts_inner
68-
fc!(k4, xterm, u, d, p, t)
67+
fc!(k4, xterm, u, d, p)
6968
@. xcur = xcur + (k1 + 2k2 + 2k3 + k4)*Ts_inner/6
7069
end
7170
@. xnext = xcur
7271
return nothing
7372
end
74-
h!(y, x, d, p, k) = (hc!(y, x, d, p, k*Ts); nothing)
73+
h! = hc!
7574
return f!, h!
7675
end
7776

0 commit comments

Comments
 (0)