Skip to content

Commit d5205d9

Browse files
committed
new h! with 0 allocation
1 parent 48b0e7d commit d5205d9

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/model/nonlinmodel.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ function validate_fcts(NT, f!, h!)
121121
"f!(x::Vector{$(NT)}, u::Vector{$(NT)}, d::Vector{$(NT)}) or "*
122122
"f!(ẋ::Vector{$(NT)}, x::Vector{$(NT)}, u::Vector{$(NT)}, d::Vector{$(NT)})")
123123
end
124-
hargsvalid = hasmethod(h!,Tuple{Vector{NT}, Vector{NT}})
124+
hargsvalid = hasmethod(h!, Tuple{Vector{NT}, Vector{NT}, Vector{NT}})
125125
if !hargsvalid
126126
error("output function has no method with type signature "*
127-
"h(x::Vector{$(NT)}, d::Vector{$(NT)})")
127+
"h!(y::Vector{$(NT)}, x::Vector{$(NT)}, d::Vector{$(NT)})")
128128
end
129129
return iscontinuous
130130
end
@@ -136,7 +136,7 @@ steadystate!(::SimModel, _ , _ ) = nothing
136136
"Call ``\\mathbf{f!(x, u, d)}`` with `model.f!` function for [`NonLinModel`](@ref)."
137137
f!(x, model::NonLinModel, u, d) = model.f!(x, u, d)
138138

139-
"Call ``\\mathbf{h(x, d)}`` with `model.h` function for [`NonLinModel`](@ref)."
140-
h(model::NonLinModel, x, d) = model.h!(x, d)
139+
"Call ``\\mathbf{h!(y, x, d)}`` with `model.h` function for [`NonLinModel`](@ref)."
140+
h!(y, model::NonLinModel, x, d) = model.h!(y, x, d)
141141

142142
typestr(model::NonLinModel) = "nonlinear"

src/sim_model.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ julia> x = updatestate!(model, [1])
144144
"""
145145
function updatestate!(model::SimModel, u, d=empty(model.x))
146146
validate_args(model::SimModel, u, d)
147-
model.x .= f!(model.x, model, u - model.uop, d - model.dop)
147+
f!(model.x, model, u - model.uop, d - model.dop)
148148
return model.x
149149
end
150150

@@ -164,7 +164,11 @@ julia> y = evaloutput(model)
164164
20.0
165165
```
166166
"""
167-
evaloutput(model::SimModel, d=empty(model.x)) = h(model, model.x, d - model.dop) + model.yop
167+
function evaloutput(model::SimModel{NT}, d=empty(model.x)) where NT <: Real
168+
y = Vector{NT}(undef, model.ny)
169+
h!(y, model, model.x, d - model.dop) + model.yop
170+
return y
171+
end
168172

169173
"""
170174
validate_args(model::SimModel, u, d)

0 commit comments

Comments
 (0)