@@ -26,34 +26,29 @@ D = Differential(t)
26
26
end
27
27
28
28
@testset " Change independent variable" begin
29
- @independent_variables t
30
29
@variables x (t) y (t) z (t) s (t)
31
30
eqs = [
32
31
D (x) ~ y
33
32
D (D (y)) ~ 2 * x * D (y)
34
33
z ~ x + D (y)
35
34
D (s) ~ 1 / (2 * s)
36
35
]
37
- @named sys1 = ODESystem (eqs, t)
38
- sys1 = complete (sys1 )
36
+ M1 = ODESystem (eqs, t; name = :M ) |> complete
37
+ M2 = ModelingToolkit . change_independent_variable (M1, M1 . s )
39
38
40
- @independent_variables s
41
- sys2 = ModelingToolkit. change_independent_variable (sys1, s)
42
-
43
- sys1 = structural_simplify (sys1; allow_symbolic = true )
44
- sys2 = structural_simplify (sys2; allow_symbolic = true )
45
- prob1 = ODEProblem (sys1, [sys1. x => 1.0 , sys1. y => 1.0 , Differential (t)(sys1. y) => 0.0 , sys1. s => 1.0 ], (1.0 , 4.0 ))
46
- prob2 = ODEProblem (sys2, [sys2. x => 1.0 , sys2. y => 1.0 , Differential (s)(sys2. y) => 0.0 ], (1.0 , 2.0 ))
39
+ M1 = structural_simplify (M1; allow_symbolic = true )
40
+ M2 = structural_simplify (M2; allow_symbolic = true )
41
+ prob1 = ODEProblem (M1, [M1. x => 1.0 , M1. y => 1.0 , Differential (M1. t)(M1. y) => 0.0 , M1. s => 1.0 ], (1.0 , 4.0 ))
42
+ prob2 = ODEProblem (M2, [M2. x => 1.0 , M2. y => 1.0 , Differential (M2. s)(M2. y) => 0.0 ], (1.0 , 2.0 ))
47
43
sol1 = solve (prob1, Tsit5 (); reltol = 1e-10 , abstol = 1e-10 )
48
44
sol2 = solve (prob2, Tsit5 (); reltol = 1e-10 , abstol = 1e-10 )
49
45
ts = range (0.0 , 1.0 , length = 50 )
50
46
ss = .√ (ts)
51
- @test all (isapprox .(sol1 (ts, idxs= sys1 . x), sol2 (ss, idxs= sys2 . x); atol = 1e-7 )) &&
52
- all (isapprox .(sol1 (ts, idxs= sys1 . y), sol2 (ss, idxs= sys2 . y); atol = 1e-7 ))
47
+ @test all (isapprox .(sol1 (ts, idxs= M1 . x), sol2 (ss, idxs= M2 . x); atol = 1e-7 )) &&
48
+ all (isapprox .(sol1 (ts, idxs= M1 . y), sol2 (ss, idxs= M2 . y); atol = 1e-7 ))
53
49
end
54
50
55
51
@testset " Change independent variable (Friedmann equation)" begin
56
- @independent_variables t
57
52
D = Differential (t)
58
53
@variables a (t) ρr (t) ρm (t) ρΛ (t) ρ (t) P (t) ϕ (t)
59
54
@parameters Ωr0 Ωm0 ΩΛ0
68
63
@named M1 = ODESystem (eqs, t)
69
64
M1 = complete (M1)
70
65
71
- @independent_variables a
72
- M2 = ModelingToolkit. change_independent_variable (M1, a)
66
+ M2 = ModelingToolkit. change_independent_variable (M1, M1. a)
73
67
M2 = structural_simplify (M2; allow_symbolic = true )
74
68
@test length (unknowns (M2)) == 2
75
69
end
0 commit comments