@@ -20,73 +20,12 @@ julia> y = model()
2020"""
2121abstract 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
9029end
9130
9231@doc raw """
@@ -96,15 +35,13 @@ Create a buffer for `SimModel` objects for inputs, states, outputs, and disturba
9635
9736The 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)
10845end
10946
11047
0 commit comments