Skip to content

Commit 5ca058d

Browse files
committed
Use default_toterm (with special underscore) for dummies
1 parent 5780d91 commit 5ca058d

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/systems/diffeqs/basic_transformations.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ function change_independent_variable(sys::AbstractODESystem, iv, eqs = []; dummi
149149
# 3) If requested, insert extra dummy equations for e.g. du/dt, d²u/dt², ...
150150
# Otherwise, replace all these derivatives by their explicit expressions
151151
if dummies
152-
div2name = Symbol(iv2name, :_, iv1name) # e.g. :u_t # TODO: customize
153-
ddiv2name = Symbol(div2name, iv1name) # e.g. :u_tt # TODO: customize
154-
div2, ddiv2 = @variables $div2name(iv2) $ddiv2name(iv2) # e.g. u_t(u), u_tt(u)
152+
div2 = substitute(default_toterm(D1(iv2_of_iv1)), iv1 => iv2) # e.g. uˍt(u)
153+
ddiv2 = substitute(default_toterm(D1(D1(iv2_of_iv1))), iv1 => iv2) # e.g. uˍtt(u)
155154
div2, ddiv2 = GlobalScope.([div2, ddiv2]) # do not namespace dummies in new system
156155
eqs = [[div2 ~ div2_of_iv1, ddiv2 ~ ddiv2_of_iv1]; eqs] # add dummy equations
157156
@set! sys.unknowns = [get_unknowns(sys); [div2, ddiv2]] # add dummy variables

test/basic_transformations.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ end
7979

8080
# Apply in two steps, where derivatives are defined at each step: first t -> a, then a -> b
8181
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
82+
a, ȧ, Ω, Ωr, Ωm, ΩΛ, ϕ, aˍt, aˍtt = M2.a, M2.ȧ, M2.Ω, M2.r.Ω, M2.m.Ω, M2.Λ.Ω, M2.ϕ, M2.aˍt, M2.aˍtt
8383
Da = Differential(a)
8484
@test Set(equations(M2)) == Set([
85-
a_t ~# 1st order dummy equation
86-
a_tt ~ Da(ȧ) * a_t # 2nd order dummy equation
85+
aˍt ~# 1st order dummy equation
86+
aˍtt ~ Da(ȧ) * aˍt # 2nd order dummy equation
8787
Ω ~ Ωr + Ωm + ΩΛ
8888
~ (Ω) * a^2
89-
a_tt*Da(ϕ) + a_t^2*(Da^2)(ϕ) ~ -3*a_t^2/a*Da(ϕ)
90-
a_t*Da(Ωr) ~ -4*Ωr*a_t/a
91-
a_t*Da(Ωm) ~ -3*Ωm*a_t/a
92-
a_t*Da(ΩΛ) ~ 0
89+
aˍtt*Da(ϕ) + aˍt^2*(Da^2)(ϕ) ~ -3*aˍt^2/a*Da(ϕ)
90+
aˍt*Da(Ωr) ~ -4*Ωr*aˍt/a
91+
aˍt*Da(Ωm) ~ -3*Ωm*aˍt/a
92+
aˍt*Da(ΩΛ) ~ 0
9393
])
9494

9595
@variables b(M2.a)
@@ -105,7 +105,7 @@ end
105105
@variables x(t)
106106
Mt = ODESystem([D(x) ~ 2*x], t; name = :M) |> complete
107107
Mx = change_independent_variable(Mt, Mt.x; dummies = true)
108-
@test (@variables x x_t(x) x_tt(x); Set(equations(Mx)) == Set([x_t ~ 2*x, x_tt ~ 2*x_t]))
108+
@test (@variables x xˍt(x) xˍtt(x); Set(equations(Mx)) == Set([xˍt ~ 2*x, xˍtt ~ 2*xˍt]))
109109
end
110110

111111
@testset "Change independent variable (free fall)" begin
@@ -133,11 +133,11 @@ end
133133
# Compare to pen-and-paper result
134134
@independent_variables x
135135
Dx = Differential(x)
136-
@variables x_t(x) x_tt(x) y(x) t(x)
136+
@variables xˍt(x) xˍtt(x) y(x) t(x)
137137
@test Set(equations(M2)) == Set([
138-
x_t^2*(Dx^2)(y) + x_tt*Dx(y) ~ x_t^2 + 3*y^2*Dx(y)*x_t # from D(D(y))
139-
x_t ~ x^4 + y^5 + t^6 # 1st order dummy equation
140-
x_tt ~ 4*x^3*x_t + 5*y^4*Dx(y)*x_t + 6*t^5 # 2nd order dummy equation
138+
xˍt^2*(Dx^2)(y) + xˍtt*Dx(y) ~ xˍt^2 + 3*y^2*Dx(y)*xˍt # from D(D(y))
139+
xˍt ~ x^4 + y^5 + t^6 # 1st order dummy equation
140+
xˍtt ~ 4*x^3*xˍt + 5*y^4*Dx(y)*xˍt + 6*t^5 # 2nd order dummy equation
141141
])
142142
end
143143

0 commit comments

Comments
 (0)