Skip to content

Commit b863d5d

Browse files
committed
rebase
1 parent 1d52236 commit b863d5d

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
7777

7878
[extensions]
7979
MTKBifurcationKitExt = "BifurcationKit"
80-
MTKCasADiDynamicOptExt = ["CasADi", "DataInterpolations", "DiffEqDevTools"]
80+
MTKCasADiDynamicOptExt = ["CasADi", "DataInterpolations"]
8181
MTKChainRulesCoreExt = "ChainRulesCore"
8282
MTKDeepDiffsExt = "DeepDiffs"
8383
MTKFMIExt = "FMI"

ext/MTKCasADiDynamicOptExt.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module MTKCasADiDynamicOptExt
22
using ModelingToolkit
33
using CasADi
4-
using DiffEqDevTools, DiffEqBase
4+
using DiffEqBase
55
using DataInterpolations
66
using UnPack
7-
const MTK = MOdelingToolkit
7+
const MTK = ModelingToolkit
88

99
struct CasADiDynamicOptProblem{uType, tType, isinplace, P, F, K} <:
1010
AbstractDynamicOptProblem{uType, tType, isinplace}
@@ -221,17 +221,22 @@ function add_solve_constraints!(prob, tableau; is_free_t)
221221
end
222222
end
223223

224-
is_explicit(tableau) = tableau isa DiffEqDevTools.ExplicitRKTableau
225224

226225
"""
227226
solve(prob::CasADiDynamicOptProblem, casadi_solver, ode_solver; plugin_options, solver_options)
228227
229228
`plugin_options` and `solver_options` get propagated to the Opti object in CasADi.
230229
"""
231-
function DiffEqBase.solve(prob::CasADiDynamicOptProblem, solver::Union{String, Symbol}, ode_solver::Union{String, Symbol}; plugin_options::Dict = Dict(), solver_options::Dict = Dict(), silent = false)
230+
function DiffEqBase.solve(prob::CasADiDynamicOptProblem, solver::Union{String, Symbol}, ode_solver::Symbol = :Default; plugin_options::Dict = Dict(), solver_options::Dict = Dict(), silent = false)
232231
model = prob.model
233232
opti = model.opti
234233

234+
if ode_solver == :Default
235+
tableau = MTK.constructDefault()
236+
else
237+
tableau_getter = Symbol(:construct, ode_solver)
238+
tableau = @eval Main.tableau_getter()
239+
end
235240
solver!(opti, solver, plugin_options, solver_options)
236241
add_casadi_solve_constraints!(prob, tableau)
237242
solver!(cmodel, "$solver", plugin_options, solver_options)

src/systems/optimal_control_interface.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ end
1818

1919
function JuMPDynamicOptProblem end
2020
function InfiniteOptDynamicOptProblem end
21+
function CasADiDynamicOptProblem end
2122

2223
function warn_overdetermined(sys, u0map)
2324
constraintsys = get_constraintsystem(sys)
@@ -27,6 +28,25 @@ function warn_overdetermined(sys, u0map)
2728
end
2829
end
2930

31+
"""
32+
Default ODE Tableau: RadauIIA5
33+
"""
34+
function constructDefault(T::Type = Float64)
35+
sq6 = sqrt(6)
36+
A = [11 // 45-7sq6 / 360 37 // 225-169sq6 / 1800 -2 // 225+sq6 / 75
37+
37 // 225+169sq6 / 1800 11 // 45+7sq6 / 360 -2 // 225-sq6 / 75
38+
4 // 9-sq6 / 36 4 // 9+sq6 / 36 1//9]
39+
c = [2 // 5 - sq6 / 10; 2 / 5 + sq6 / 10; 1]
40+
α = [4 // 9 - sq6 / 36; 4 // 9 + sq6 / 36; 1 // 9]
41+
A = map(T, A)
42+
α = map(T, α)
43+
c = map(T, c)
44+
45+
DiffEqBase.ImplicitRKTableau(A, c, α, 5)
46+
end
47+
48+
is_explicit(tableau) = tableau isa DiffEqBase.ExplicitRKTableau
49+
3050
"""
3151
Generate the control function f(x, u, p, t) from the ODESystem.
3252
Input variables are automatically inferred but can be manually specified.

0 commit comments

Comments
 (0)