Skip to content

Commit c46d4b6

Browse files
fix liouville stuff
1 parent 64ee8fa commit c46d4b6

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

src/ModelingToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export SteadyStateProblem, SteadyStateProblemExpr
207207
export JumpProblem, DiscreteProblem
208208
export NonlinearSystem, OptimizationSystem
209209
export ControlSystem
210-
export ode_order_lowering
210+
export ode_order_lowering, liouville_transform
211211
export runge_kutta_discretize
212212
export PDESystem
213213
export Reaction, ReactionSystem, ismassaction, oderatelaw, jumpratelaw

src/systems/diffeqs/basic_transformations.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@ Generates the Liouville transformed set of ODEs, which is the original
55
ODE system with a new variable `trJ` appended, corresponding to the
66
-tr(Jacobian). This variable is used for properties like uncertainty
77
propagation and should be used with a zero initial condition.
8+
9+
10+
11+
Sources:
12+
13+
Probabilistic Robustness Analysis of F-16 Controller Performance: An
14+
Optimal Transport Approach
15+
16+
Abhishek Halder, Kooktae Lee, and Raktim Bhattacharya
17+
https://abhishekhalder.bitbucket.io/F16ACC2013Final.pdf
18+
19+
820
"""
921
function liouville_transform(sys)
1022
t = independent_variable(sys)
1123
@variables trJ
1224
D = ModelingToolkit.Differential(t)
13-
neweq = D(trJ) ~ -tr(calculate_jacobian(sys))
25+
neweq = D(trJ) ~ trJ*-tr(calculate_jacobian(sys))
1426
neweqs = [equations(sys);neweq]
1527
vars = [states(sys);trJ]
1628
ODESystem(neweqs,t,vars,parameters(sys))

test/basic_transformations.jl

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
using ModelingToolkit, OrdinaryDiffEq, Test
22

3-
@parameters t σ ρ β
4-
@variables x(t) y(t) z(t)
3+
@parameters t α β γ δ
4+
@variables x(t) y(t)
55
@derivatives D'~t
66

7-
eqs = [D(D(x)) ~ σ*(y-x),
8-
D(y) ~ x*-z)-y,
9-
D(z) ~ x*y - β*z]
7+
eqs = [D(x) ~ α*x - β*x*y,
8+
D(y) ~ -δ*y + γ*x*y]
109

1110
sys = ODESystem(eqs)
12-
sys = ode_order_lowering(sys)
1311

14-
u0 = [D(x) => 2.0,
15-
x => 1.0,
16-
y => 0.0,
17-
z => 0.0]
12+
u0 = [x => 1.0,
13+
y => 1.0]
1814

19-
p ==> 28.0,
20-
ρ => 10.0,
21-
β => 8/3]
15+
p ==> 1.5,
16+
β => 1.0,
17+
δ => 3.0,
18+
γ => 1.0]
2219

23-
tspan = (0.0,100.0)
24-
prob = ODEProblem(sys,u0,tspan,p,jac=true)
20+
tspan = (0.0,10.0)
21+
prob = ODEProblem(sys,u0,tspan,p)
2522
sol = solve(prob,Tsit5())
2623

27-
sys2 = louiville_transform(sys)
24+
sys2 = liouville_transform(sys)
2825
@variables trJ
2926

30-
u0 = [D(x) => 2.0,
31-
x => 1.0,
32-
y => 0.0,
33-
z => 0.0,
34-
trJ => 0.0]
27+
u0 = [x => 1.0,
28+
y => 1.0,
29+
trJ => 1.0]
3530

3631
prob = ODEProblem(sys2,u0,tspan,p,jac=true)
3732
sol = solve(prob,Tsit5())
38-
@test sol[end,end] 366.66666666
33+
@test sol[end,end] 1.0742818931017244

0 commit comments

Comments
 (0)