Skip to content

Commit

Permalink
fix: pass VariableUnit of diff var while converting it to a Term
Browse files Browse the repository at this point in the history
Units are defined only in MTK, so pass this piece of info to `Symbolics.diff2term` to add this to the returning term-var.
  • Loading branch information
ven-k committed Apr 11, 2024
1 parent dde5b83 commit 56f4e35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function default_toterm(x)
end
x = normalize_to_differential(op)(arguments(x)...)
end
Symbolics.diff2term(x)
Symbolics.diff2term(x, Dict(VariableUnit => get_unit(x)))
else
x
end
Expand Down
8 changes: 7 additions & 1 deletion test/variable_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ new = (((1 / β - 1) + δ) / γ)^(1 / (γ - 1))
using ModelingToolkit: isdifferential, vars, collect_differential_variables,
collect_ivs
@variables t u(t) y(t)
D = Differential(t)
using ModelingToolkit: D
eq = D(y) ~ u
v = vars(eq)
@test v == Set([D(y), u])
Expand All @@ -32,3 +32,9 @@ aov = ModelingToolkit.collect_applied_operators(eq, Differential)

ts = collect_ivs([eq])
@test ts == Set([t])

# Test units of diff vars of `Term` type.
using ModelingToolkit: t, get_unit, default_toterm
@variables k(t)
k2 = D(D(k))
get_unit(default_toterm(k2)) == get_unit(k2)

0 comments on commit 56f4e35

Please sign in to comment.