Skip to content

Commit 2e7ab0e

Browse files
authored
Merge pull request #161 from JuliaControl/debug_ti_nonlinmodel
debug: `NonLinModel` fields are now all concrete types
2 parents 2b1abf0 + 06c65e0 commit 2e7ab0e

File tree

3 files changed

+5
-68
lines changed

3 files changed

+5
-68
lines changed

Diff for: Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelPredictiveControl"
22
uuid = "61f9bdb8-6ae4-484a-811f-bbf86720c31c"
33
authors = ["Francis Gagnon"]
4-
version = "1.3.3"
4+
version = "1.3.4"
55

66
[deps]
77
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"

Diff for: src/model/linmodel.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct LinModel{NT<:Real} <: SimModel{NT}
2121
yname::Vector{String}
2222
dname::Vector{String}
2323
xname::Vector{String}
24-
buffer::SimModelBuffer{NT, Nothing}
24+
buffer::SimModelBuffer{NT}
2525
function LinModel{NT}(A, Bu, C, Bd, Dd, Ts) where {NT<:Real}
2626
A, Bu = to_mat(A, 1, 1), to_mat(Bu, 1, 1)
2727
nu, nx = size(Bu, 2), size(A, 2)

Diff for: src/sim_model.jl

+3-66
Original file line numberDiff line numberDiff line change
@@ -20,73 +20,12 @@ julia> y = model()
2020
"""
2121
abstract type SimModel{NT<:Real} end
2222

23-
struct JacobianBuffer{
24-
NT<:Real,
25-
FX<:Function,
26-
FU<:Function,
27-
FD<:Function,
28-
HX<:Function,
29-
HU<:Function,
30-
CFX<:ForwardDiff.JacobianConfig,
31-
CFU<:ForwardDiff.JacobianConfig,
32-
CFD<:ForwardDiff.JacobianConfig,
33-
CHU<:ForwardDiff.JacobianConfig,
34-
CHX<:ForwardDiff.JacobianConfig
35-
}
36-
xnext::Vector{NT}
37-
x::Vector{NT}
38-
y::Vector{NT}
39-
u::Vector{NT}
40-
d::Vector{NT}
41-
f_x!::FX
42-
f_u!::FU
43-
f_d!::FD
44-
h_x!::HX
45-
h_d!::HU
46-
f_x_cfg::CFX
47-
f_u_cfg::CFU
48-
f_d_cfg::CFD
49-
h_x_cfg::CHX
50-
h_d_cfg::CHU
51-
end
52-
53-
"""
54-
JacobianBuffer(NT::DataType, f!::Function, h!::Function, nx, nu, ny, nd)
55-
56-
Buffer object for calling `ForwardDiff.jacobian!` on `SimModel` without any allocation.
57-
"""
58-
function JacobianBuffer{NT}(
59-
f!::Function, h!::Function, nx::Int, nu::Int, ny::Int, nd::Int
60-
) where NT <: Real
61-
xnext = Vector{NT}(undef, nx)
62-
x = Vector{NT}(undef, nx)
63-
y = Vector{NT}(undef, ny)
64-
u = Vector{NT}(undef, nu)
65-
d = Vector{NT}(undef, nd)
66-
f_x!(y, x) = f!(y, x, u, d)
67-
f_u!(y, u) = f!(y, x, u, d)
68-
f_d!(y, d) = f!(y, x, u, d)
69-
h_x!(y, x) = h!(y, x, d)
70-
h_d!(y, d) = h!(y, x, d)
71-
f_x_cfg = ForwardDiff.JacobianConfig(f_x!, xnext, x)
72-
f_u_cfg = ForwardDiff.JacobianConfig(f_u!, xnext, u)
73-
f_d_cfg = ForwardDiff.JacobianConfig(f_d!, xnext, d)
74-
h_x_cfg = ForwardDiff.JacobianConfig(h_x!, y, x)
75-
h_d_cfg = ForwardDiff.JacobianConfig(h_d!, y, d)
76-
return JacobianBuffer(
77-
xnext, x, y, u, d,
78-
f_x!, f_u!, f_d!, h_x!, h_d!,
79-
f_x_cfg, f_u_cfg, f_d_cfg, h_x_cfg, h_d_cfg
80-
)
81-
end
82-
83-
struct SimModelBuffer{NT<:Real, JB<:Union{JacobianBuffer, Nothing}}
23+
struct SimModelBuffer{NT<:Real}
8424
u::Vector{NT}
8525
x::Vector{NT}
8626
y::Vector{NT}
8727
d::Vector{NT}
8828
empty::Vector{NT}
89-
jacobian::JB
9029
end
9130

9231
@doc raw"""
@@ -96,15 +35,13 @@ Create a buffer for `SimModel` objects for inputs, states, outputs, and disturba
9635
9736
The buffer is used to store intermediate results during simulation without allocating.
9837
"""
99-
function SimModelBuffer{NT}(
100-
nu::Int, nx::Int, ny::Int, nd::Int, jacobian::JB=nothing
101-
) where {NT <: Real, JB <: Union{JacobianBuffer, Nothing}}
38+
function SimModelBuffer{NT}(nu::Int, nx::Int, ny::Int, nd::Int) where {NT <: Real}
10239
u = Vector{NT}(undef, nu)
10340
x = Vector{NT}(undef, nx)
10441
y = Vector{NT}(undef, ny)
10542
d = Vector{NT}(undef, nd)
10643
empty = Vector{NT}(undef, 0)
107-
return SimModelBuffer{NT, JB}(u, x, y, d, empty, jacobian)
44+
return SimModelBuffer{NT}(u, x, y, d, empty)
10845
end
10946

11047

0 commit comments

Comments
 (0)