Skip to content

Commit 487d304

Browse files
committed
switch to EvalAt in the Rocket launch and explicitely include all parameters in the system
1 parent 219ed56 commit 487d304

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

test/extensions/dynamic_optimization.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -238,49 +238,49 @@ end
238238

239239
@testset "Rocket launch" begin
240240

241-
@parameters h_c m₀ h₀ g₀ D_c c Tₘ m_c
242-
@variables h(..) v(..) m(..) = m₀ [bounds = (m_c, 1)] T(..) [input = true, bounds = (0, Tₘ)]
241+
ps = @parameters h_c m₀ h₀ g₀ D_c c Tₘ m_c
242+
vars = @variables h(t) v(t) m(t) = m₀ [bounds = (m_c, 1)] T(t) [input = true, bounds = (0, Tₘ)]
243243
drag(h, v) = D_c * v^2 * exp(-h_c * (h - h₀) / h₀)
244244
gravity(h) = g₀ * (h₀ / h)
245245

246-
eqs = [D(h(t)) ~ v(t),
247-
D(v(t)) ~ (T(t) - drag(h(t), v(t))) / m(t) - gravity(h(t)),
248-
D(m(t)) ~ -T(t) / c]
246+
eqs = [D(h) ~ v,
247+
D(v) ~ (T - drag(h, v)) / m - gravity(h),
248+
D(m) ~ -T / c]
249249

250250
(ts, te) = (0.0, 0.2)
251-
costs = [-h(te)]
252-
cons = [T(te) ~ 0, m(te) ~ m_c]
253-
@named rocket = System(eqs, t; costs, constraints = cons)
254-
rocket = mtkcompile(rocket; inputs = [T(t)])
251+
costs = [-EvalAt(te)(h)]
252+
cons = [EvalAt(te)(T) ~ 0, EvalAt(te)(m) ~ m_c]
253+
@named rocket = System(eqs, t, vars, ps; costs, constraints = cons)
254+
rocket = mtkcompile(rocket; inputs = [T])
255255

256-
u0map = [h(t) => h₀, m(t) => m₀, v(t) => 0]
256+
u0map = [h => h₀, m => m₀, v => 0]
257257
pmap = [
258258
g₀ => 1, m₀ => 1.0, h_c => 500, c => 0.5 * (g₀ * h₀), D_c => 0.5 * 620 * m₀ / g₀,
259-
Tₘ => 3.5 * g₀ * m₀, T(t) => 0.0, h₀ => 1, m_c => 0.6]
259+
Tₘ => 3.5 * g₀ * m₀, T => 0.0, h₀ => 1, m_c => 0.6]
260260
jprob = JuMPDynamicOptProblem(rocket, [u0map; pmap], (ts, te); dt = 0.001, cse = false)
261261
jsol = solve(jprob, JuMPCollocation(Ipopt.Optimizer, constructRadauIIA5()))
262-
@test jsol.sol[h(t)][end] > 1.012
262+
@test jsol.sol[h][end] > 1.012
263263

264264
if ENABLE_CASADI
265265
cprob = CasADiDynamicOptProblem(
266266
rocket, [u0map; pmap], (ts, te); dt = 0.001, cse = false)
267267
csol = solve(cprob, CasADiCollocation("ipopt"))
268-
@test csol.sol[h(t)][end] > 1.012
268+
@test csol.sol[h][end] > 1.012
269269
end
270270

271271
iprob = InfiniteOptDynamicOptProblem(rocket, [u0map; pmap], (ts, te); dt = 0.001)
272272
isol = solve(iprob, InfiniteOptCollocation(Ipopt.Optimizer))
273-
@test isol.sol[h(t)][end] > 1.012
273+
@test isol.sol[h][end] > 1.012
274274

275275
pprob = PyomoDynamicOptProblem(rocket, [u0map; pmap], (ts, te); dt = 0.001, cse = false)
276276
psol = solve(pprob, PyomoCollocation("ipopt", LagrangeRadau(4)))
277-
@test psol.sol[h(t)][end] > 1.012
277+
@test psol.sol[h][end] > 1.012
278278

279279
# Test solution
280280
@parameters (T_interp::CubicSpline)(..)
281-
eqs = [D(h(t)) ~ v(t),
282-
D(v(t)) ~ (T_interp(t) - drag(h(t), v(t))) / m(t) - gravity(h(t)),
283-
D(m(t)) ~ -T_interp(t) / c]
281+
eqs = [D(h) ~ v,
282+
D(v) ~ (T_interp(t) - drag(h, v)) / m - gravity(h),
283+
D(m) ~ -T_interp(t) / c]
284284
@mtkcompile rocket_ode = System(eqs, t)
285285
interpmap = Dict(T_interp => ctrl_to_spline(jsol.input_sol, CubicSpline))
286286
oprob = ODEProblem(rocket_ode, merge(Dict(u0map), Dict(pmap), interpmap), (ts, te))

0 commit comments

Comments
 (0)