@@ -7,7 +7,7 @@ using NaNMath
7
7
using Setfield
8
8
const MTK = ModelingToolkit
9
9
10
- SPECIAL_FUNCTIONS_DICT = Dict ([acos => Pyomo. py_acos,
10
+ const SPECIAL_FUNCTIONS_DICT = Dict ([acos => Pyomo. py_acos,
11
11
acosh => Pyomo. py_acosh,
12
12
asin => Pyomo. py_asin,
13
13
tan => Pyomo. py_tan,
@@ -33,22 +33,11 @@ struct PyomoDynamicOptModel
33
33
function PyomoDynamicOptModel (model, U, V, tₛ, is_free_final)
34
34
@variables MODEL_SYM:: Symbolics.symstruct (ConcreteModel) T_SYM DUMMY_SYM
35
35
model. dU = dae. DerivativeVar (U, wrt = model. t, initialize = 0 )
36
- # add_time_equation!(model, MODEL_SYM, T_SYM)
37
36
new (model, U, V, tₛ, is_free_final, nothing ,
38
37
PyomoVar (model. dU), MODEL_SYM, T_SYM, DUMMY_SYM)
39
38
end
40
39
end
41
40
42
- function add_time_equation! (model:: ConcreteModel , model_sym, t_sym)
43
- model. dtime = dae. DerivativeVar (model. time)
44
-
45
- mdt = Symbolics. value (pysym_getproperty (model_sym, :dtime ))
46
- mts = Symbolics. value (pysym_getproperty (model_sym, :tₛ ))
47
- expr = mdt[t_sym] - mts == 0
48
- f = Pyomo. pyfunc (eval (Symbolics. build_function (expr, model_sym, t_sym)))
49
- model. time_eq = pyomo. Constraint (model. t, rule = f)
50
- end
51
-
52
41
struct PyomoDynamicOptProblem{uType, tType, isinplace, P, F, K} < :
53
42
AbstractDynamicOptProblem{uType, tType, isinplace}
54
43
f:: F
@@ -119,7 +108,7 @@ function MTK.add_constraint!(pmodel::PyomoDynamicOptModel, cons; n_idxs = 1)
119
108
else
120
109
cons. lhs - cons. rhs ≤ 0
121
110
end
122
- expr = Symbolics. substitute (Symbolics. unwrap (expr), SPECIAL_FUNCTIONS_DICT)
111
+ expr = Symbolics. substitute (Symbolics. unwrap (expr), SPECIAL_FUNCTIONS_DICT, fold = false )
123
112
124
113
cons_sym = Symbol (" cons" , hash (cons))
125
114
if occursin (Symbolics. unwrap (t_sym), expr)
133
122
134
123
function MTK. set_objective! (pmodel:: PyomoDynamicOptModel , expr)
135
124
@unpack model, model_sym, t_sym, dummy_sym = pmodel
136
- expr = Symbolics. substitute (expr, SPECIAL_FUNCTIONS_DICT)
125
+ expr = Symbolics. substitute (expr, SPECIAL_FUNCTIONS_DICT, fold = false )
137
126
if occursin (Symbolics. unwrap (t_sym), expr)
138
127
f = eval (Symbolics. build_function (expr, model_sym, t_sym))
139
128
model. obj = pyomo. Objective (model. t, rule = Pyomo. pyfunc (f))
0 commit comments