2828@testset " Change independent variable (trivial)" begin
2929 @variables x (t) y (t)
3030 eqs1 = [D (D (x)) ~ D (x) + x, D (y) ~ 1 ]
31- M1 = ODESystem (eqs1, t; name = :M ) |> complete
32- M2 = change_independent_variable (M1, M1 . y)
31+ M1 = ODESystem (eqs1, t; name = :M )
32+ M2 = change_independent_variable (M1, y)
3333 eqs2 = substitute (equations (M2), M2. y => M1. t) # system should be equivalent when parametrized with y (since D(y) ~ 1), so substitute back ...
3434 @test eqs1[1 ] == only (eqs2) # ... and check that the equations are unmodified
3535end
4343 D (s) ~ 1 / (2 * s)
4444 ]
4545 initialization_eqs = [x ~ 1.0 , y ~ 1.0 , D (y) ~ 0.0 ]
46- M1 = ODESystem (eqs, t; initialization_eqs, name = :M ) |> complete
47- M2 = change_independent_variable (M1, M1 . s; dummies = true )
46+ M1 = ODESystem (eqs, t; initialization_eqs, name = :M )
47+ M2 = change_independent_variable (M1, s; dummies = true )
4848
4949 M1 = structural_simplify (M1; allow_symbolic = true )
5050 M2 = structural_simplify (M2; allow_symbolic = true )
7575 ]
7676 M1 = ODESystem (eqs, t, [Ω, a, ȧ, ϕ], []; name = :M )
7777 M1 = compose (M1, r, m, Λ)
78- M1 = complete (M1; flatten = false )
7978
8079 # Apply in two steps, where derivatives are defined at each step: first t -> a, then a -> b
8180 M2 = change_independent_variable (M1, M1. a; dummies = true )
82- a, ȧ, Ω, Ωr, Ωm, ΩΛ, ϕ, aˍt, aˍtt = M2. a, M2. ȧ, M2. Ω, M2. r. Ω, M2. m. Ω, M2. Λ. Ω, M2. ϕ, M2. aˍt, M2. aˍtt
81+ M2c = complete (M2) # just for the following equation comparison (without namespacing)
82+ a, ȧ, Ω, Ωr, Ωm, ΩΛ, ϕ, aˍt, aˍtt = M2c. a, M2c. ȧ, M2c. Ω, M2c. r. Ω, M2c. m. Ω, M2c. Λ. Ω, M2c. ϕ, M2c. aˍt, M2c. aˍtt
8383 Da = Differential (a)
8484 @test Set (equations (M2)) == Set ([
8585 aˍt ~ ȧ # 1st order dummy equation
@@ -103,16 +103,16 @@ end
103103
104104@testset " Change independent variable (simple)" begin
105105 @variables x (t)
106- Mt = ODESystem ([D (x) ~ 2 * x], t; name = :M ) |> complete
107- Mx = change_independent_variable (Mt, Mt . x; dummies = true )
106+ Mt = ODESystem ([D (x) ~ 2 * x], t; name = :M )
107+ Mx = change_independent_variable (Mt, x; dummies = true )
108108 @test (@variables x xˍt (x) xˍtt (x); Set (equations (Mx)) == Set ([xˍt ~ 2 * x, xˍtt ~ 2 * xˍt]))
109109end
110110
111111@testset " Change independent variable (free fall)" begin
112112 @variables x (t) y (t)
113113 @parameters g v # gravitational acceleration and constant horizontal velocity
114- Mt = ODESystem ([D (D (y)) ~ - g, D (x) ~ v], t; name = :M ) |> complete # gives (x, y) as function of t, ...
115- Mx = change_independent_variable (Mt, Mt . x; dummies = false ) # ... but we want y as a function of x
114+ Mt = ODESystem ([D (D (y)) ~ - g, D (x) ~ v], t; name = :M ) # gives (x, y) as function of t, ...
115+ Mx = change_independent_variable (Mt, x; dummies = false ) # ... but we want y as a function of x
116116 Mx = structural_simplify (Mx; allow_symbolic = true )
117117 Dx = Differential (Mx. x)
118118 prob = ODEProblem (Mx, [Mx. y => 0.0 , Dx (Mx. y) => 1.0 ], (0.0 , 20.0 ), [g => 9.81 , v => 10.0 ]) # 1 = dy/dx = (dy/dt)/(dx/dt) means equal initial horizontal and vertical velocities
127127 M1 = ODESystem ([ # crazy non-autonomous non-linear 2nd order ODE
128128 D (D (y)) ~ D (x)^ 2 + D (y^ 3 ) |> expand_derivatives # expand D(y^3) # TODO : make this test 3rd order
129129 D (x) ~ x^ 4 + y^ 5 + t^ 6
130- ], t; name = :M ) |> complete
131- M2 = change_independent_variable (M1, M1 . x; dummies = true )
130+ ], t; name = :M )
131+ M2 = change_independent_variable (M1, x; dummies = true )
132132
133133 # Compare to pen-and-paper result
134134 @independent_variables x
@@ -144,18 +144,16 @@ end
144144@testset " Change independent variable (errors)" begin
145145 @variables x (t) y z (y) w (t) v (t)
146146 M = ODESystem ([D (x) ~ 0 , v ~ x], t; name = :M )
147- @test_throws " incomplete" change_independent_variable (M, M. x)
148- M = complete (M)
149- @test_throws " singular" change_independent_variable (M, M. x)
147+ @test_throws " singular" change_independent_variable (M, x)
150148 @test_throws " structurally simplified" change_independent_variable (structural_simplify (M), y)
151149 @test_throws " Got 0 equations:" change_independent_variable (M, w)
152150 @test_throws " Got 0 equations:" change_independent_variable (M, v)
153- M = ODESystem ([D (x) ~ 1 , v ~ 1 ], t; name = :M ) |> complete
154- @test_throws " Got 2 equations:" change_independent_variable (M, M . x, [D (x) ~ 2 ])
151+ M = ODESystem ([D (x) ~ 1 , v ~ 1 ], t; name = :M )
152+ @test_throws " Got 2 equations:" change_independent_variable (M, x, [D (x) ~ 2 ])
155153 @test_throws " not a function of the independent variable" change_independent_variable (M, y)
156154 @test_throws " not a function of the independent variable" change_independent_variable (M, z)
157155 M = ODESystem ([D (x) ~ 0 , v ~ x], t; name = :M )
158156 @variables x (.. ) # require explicit argument
159- M = ODESystem ([D (x (t)) ~ x (t- 1 )], t; name = :M ) |> complete
160- @test_throws " DDE" change_independent_variable (M, M . x )
157+ M = ODESystem ([D (x (t)) ~ x (t- 1 )], t; name = :M )
158+ @test_throws " DDE" change_independent_variable (M, x (t) )
161159end
0 commit comments