Skip to content

Commit f4931d8

Browse files
committed
cleanup: simpler NonLinModel and NonLinMPC inner constructor
1 parent 09a54a1 commit f4931d8

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/controller/nonlinmpc.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct NonLinMPC{
4545
Yop::Vector{NT}
4646
Dop::Vector{NT}
4747
buffer::PredictiveControllerBuffer{NT}
48-
function NonLinMPC{NT, SE, JM, JEfunc, GCfunc, P}(
48+
function NonLinMPC{NT, SE, JM, P}(
4949
estim::SE,
5050
Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE::JEfunc, gc!::GCfunc, nc, p::P, optim::JM
5151
) where {
@@ -337,8 +337,7 @@ function NonLinMPC(
337337
end
338338
validate_JE(NT, JE)
339339
gc! = get_mutating_gc(NT, gc)
340-
GCfunc = get_type_mutating_gc(gc!)
341-
return NonLinMPC{NT, SE, JM, JEfunc, GCfunc, P}(
340+
return NonLinMPC{NT, SE, JM, P}(
342341
estim, Hp, Hc, M_Hp, N_Hc, L_Hp, Cwt, Ewt, JE, gc!, nc, p, optim
343342
)
344343
end
@@ -396,9 +395,6 @@ function get_mutating_gc(NT, gc)
396395
return gc!
397396
end
398397

399-
"Get the type of the mutating version of the custom constrain function `gc!`."
400-
get_type_mutating_gc(::GCfunc) where {GCfunc<:Function} = GCfunc
401-
402398
"""
403399
test_custom_functions(NT, model::SimModel, JE, gc!, nc, Uop, Yop, Dop, p)
404400

src/model/nonlinmodel.jl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct NonLinModel{
2222
dname::Vector{String}
2323
xname::Vector{String}
2424
buffer::SMB
25-
function NonLinModel{NT, F, H, P, DS}(
25+
function NonLinModel{NT}(
2626
f!::F, h!::H, Ts, nu, nx, ny, nd, p::P, solver::DS, buffer::SMB
2727
) where {NT<:Real, F<:Function, H<:Function, P<:Any, DS<:DiffSolver, SMB<:SimModelBuffer}
2828
Ts > 0 || error("Sampling time Ts must be positive")
@@ -144,10 +144,9 @@ function NonLinModel{NT}(
144144
isnothing(solver) && (solver=EmptySolver())
145145
f!, h! = get_mutating_functions(NT, f, h)
146146
f!, h! = get_solver_functions(NT, solver, f!, h!, Ts, nu, nx, ny, nd)
147-
F, H, P, DS = get_types(f!, h!, p, solver)
148147
jacobian = JacobianBuffer{NT}(f!, h!, nu, nx, ny, nd)
149148
buffer = SimModelBuffer{NT}(nu, nx, ny, nd, jacobian)
150-
return NonLinModel{NT, F, H, P, DS}(f!, h!, Ts, nu, nx, ny, nd, p, solver, buffer)
149+
return NonLinModel{NT}(f!, h!, Ts, nu, nx, ny, nd, p, solver, buffer)
151150
end
152151

153152
function NonLinModel(
@@ -225,13 +224,6 @@ function validate_h(NT, h)
225224
return ismutating
226225
end
227226

228-
"Get the types of `f!`, `h!` and `solver` to construct a `NonLinModel`."
229-
function get_types(
230-
::F, ::H, ::P, ::DS
231-
) where {F<:Function, H<:Function, P<:Any, DS<:DiffSolver}
232-
return F, H, P, DS
233-
end
234-
235227
"Do nothing if `model` is a [`NonLinModel`](@ref)."
236228
steadystate!(::SimModel, _ , _ ) = nothing
237229

0 commit comments

Comments
 (0)