@@ -5,7 +5,7 @@ Abstract supertype of [`LinModel`](@ref) and [`NonLinModel`](@ref) types.
55
66---
77
8- (model::SimModel)(d=model.dop ) -> y
8+ (model::SimModel)(d=[] ) -> y
99
1010Functor allowing callable `SimModel` object as an alias for [`evaloutput`](@ref).
1111
@@ -20,6 +20,29 @@ julia> y = model()
2020"""
2121abstract type SimModel{NT<: Real } end
2222
23+ struct SimModelBuffer{NT<: Real }
24+ u:: Vector{NT}
25+ x:: Vector{NT}
26+ y:: Vector{NT}
27+ d:: Vector{NT}
28+ empty:: Vector{NT}
29+ end
30+
31+ @doc raw """
32+ SimModelBuffer(nu, nx, ny, nd) -> SimModelBuffer{NT}
33+
34+ Create a buffer for `SimModel` objects for inputs, states, outputs, and disturbances.
35+ """
36+ function SimModelBuffer {NT} (nu, nx, ny, nd) where NT <: Real
37+ u = Vector {NT} (undef, nu)
38+ x = Vector {NT} (undef, nx)
39+ y = Vector {NT} (undef, ny)
40+ d = Vector {NT} (undef, nd)
41+ empty = Vector {NT} (undef, 0 )
42+ return SimModelBuffer {NT} (u, x, y, d, empty)
43+ end
44+
45+
2346@doc raw """
2447 setop!(model; uop=nothing, yop=nothing, dop=nothing, xop=nothing, fop=nothing) -> model
2548
160183detailstr (model:: SimModel ) = " "
161184
162185@doc raw """
163- initstate!(model::SimModel, u, d=model.dop ) -> x
186+ initstate!(model::SimModel, u, d=[] ) -> x
164187
165188Init `model.x0` with manipulated inputs `u` and measured disturbances `d` steady-state.
166189
@@ -182,7 +205,7 @@ julia> x ≈ updatestate!(model, u)
182205true
183206```
184207"""
185- function initstate! (model:: SimModel , u, d= model. dop )
208+ function initstate! (model:: SimModel , u, d= model. buffer . empty )
186209 validate_args (model:: SimModel , d, u)
187210 u0, d0 = u - model. uop, d - model. dop
188211 steadystate! (model, u0, d0)
@@ -191,7 +214,7 @@ function initstate!(model::SimModel, u, d=model.dop)
191214end
192215
193216"""
194- updatestate!(model::SimModel, u, d=model.dop ) -> x
217+ updatestate!(model::SimModel, u, d=[] ) -> x
195218
196219Update `model.x0` states with current inputs `u` and measured disturbances `d`.
197220
@@ -204,7 +227,7 @@ julia> x = updatestate!(model, [1])
204227 1.0
205228```
206229"""
207- function updatestate! (model:: SimModel{NT} , u, d= model. dop ) where NT <: Real
230+ function updatestate! (model:: SimModel{NT} , u, d= model. buffer . empty ) where NT <: Real
208231 validate_args (model:: SimModel , d, u)
209232 xnext0 = Vector {NT} (undef, model. nx)
210233 u0, d0 = u - model. uop, d - model. dop
@@ -217,7 +240,7 @@ function updatestate!(model::SimModel{NT}, u, d=model.dop) where NT <: Real
217240end
218241
219242"""
220- evaloutput(model::SimModel, d=model.dop ) -> y
243+ evaloutput(model::SimModel, d=[] ) -> y
221244
222245Evaluate `SimModel` outputs `y` from `model.x0` states and measured disturbances `d`.
223246
@@ -232,7 +255,7 @@ julia> y = evaloutput(model)
232255 20.0
233256```
234257"""
235- function evaloutput (model:: SimModel{NT} , d= model. dop ) where NT <: Real
258+ function evaloutput (model:: SimModel{NT} , d= model. buffer . empty ) where NT <: Real
236259 validate_args (model, d)
237260 y0 = Vector {NT} (undef, model. ny)
238261 d0 = d - model. dop
@@ -262,7 +285,7 @@ to_mat(A::Real, dims...) = fill(A, dims)
262285
263286
264287" Functor allowing callable `SimModel` object as an alias for `evaloutput`."
265- (model:: SimModel )(d= model. dop ) = evaloutput (model:: SimModel , d)
288+ (model:: SimModel )(d= model. buffer . empty ) = evaloutput (model:: SimModel , d)
266289
267290include (" model/linmodel.jl" )
268291include (" model/solver.jl" )
0 commit comments