Skip to content

Commit 64ee8fa

Browse files
add the liouville transformation
1 parent 6cbc8ea commit 64ee8fa

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

docs/src/systems/ODESystem.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ODESystem
1717

1818
```@docs
1919
ode_order_lowering
20+
liouville_transform
2021
```
2122

2223
## Applicable Calculation and Generation Functions

src/ModelingToolkit.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ include("systems/diffeqs/abstractodesystem.jl")
176176
include("systems/diffeqs/first_order_transform.jl")
177177
include("systems/diffeqs/modelingtoolkitize.jl")
178178
include("systems/diffeqs/validation.jl")
179+
include("systems/diffeqs/basic_transformations.jl")
179180

180181
include("systems/jumps/jumpsystem.jl")
181182

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
$(TYPEDSIGNATURES)
3+
4+
Generates the Liouville transformed set of ODEs, which is the original
5+
ODE system with a new variable `trJ` appended, corresponding to the
6+
-tr(Jacobian). This variable is used for properties like uncertainty
7+
propagation and should be used with a zero initial condition.
8+
"""
9+
function liouville_transform(sys)
10+
t = independent_variable(sys)
11+
@variables trJ
12+
D = ModelingToolkit.Differential(t)
13+
neweq = D(trJ) ~ -tr(calculate_jacobian(sys))
14+
neweqs = [equations(sys);neweq]
15+
vars = [states(sys);trJ]
16+
ODESystem(neweqs,t,vars,parameters(sys))
17+
end

test/basic_transformations.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using ModelingToolkit, OrdinaryDiffEq, Test
2+
3+
@parameters t σ ρ β
4+
@variables x(t) y(t) z(t)
5+
@derivatives D'~t
6+
7+
eqs = [D(D(x)) ~ σ*(y-x),
8+
D(y) ~ x*-z)-y,
9+
D(z) ~ x*y - β*z]
10+
11+
sys = ODESystem(eqs)
12+
sys = ode_order_lowering(sys)
13+
14+
u0 = [D(x) => 2.0,
15+
x => 1.0,
16+
y => 0.0,
17+
z => 0.0]
18+
19+
p ==> 28.0,
20+
ρ => 10.0,
21+
β => 8/3]
22+
23+
tspan = (0.0,100.0)
24+
prob = ODEProblem(sys,u0,tspan,p,jac=true)
25+
sol = solve(prob,Tsit5())
26+
27+
sys2 = louiville_transform(sys)
28+
@variables trJ
29+
30+
u0 = [D(x) => 2.0,
31+
x => 1.0,
32+
y => 0.0,
33+
z => 0.0,
34+
trJ => 0.0]
35+
36+
prob = ODEProblem(sys2,u0,tspan,p,jac=true)
37+
sol = solve(prob,Tsit5())
38+
@test sol[end,end] 366.66666666

0 commit comments

Comments
 (0)