Skip to content

Commit

Permalink
add dispatch to symbolic array for units
Browse files Browse the repository at this point in the history
  • Loading branch information
aml5600 committed Sep 4, 2024
1 parent f1b8e72 commit 8f2d885
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/systems/unit_check.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ get_unit(x::Real) = unitless
get_unit(x::DQ.AbstractQuantity) = screen_unit(x)
get_unit(x::AbstractArray) = map(get_unit, x)
get_unit(x::Num) = get_unit(unwrap(x))
get_unit(x::Symbolics.Arr) = get_unit(unwrap(x))
get_unit(op::Differential, args) = get_unit(args[1]) / get_unit(op.x)
get_unit(op::Difference, args) = get_unit(args[1]) / get_unit(op.t)
get_unit(op::typeof(getindex), args) = get_unit(args[1])
Expand Down
7 changes: 7 additions & 0 deletions test/dq_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,10 @@ let
@test mm2units == MT.oneunit(mm2units)
@test mmunits == mm2units
end

# test for array variable units https://github.com/SciML/ModelingToolkit.jl/issues/3009
let
@variables x_vec(t)[1:3] [unit = u"1"] x_mat(t)[1:3, 1:3] [unit = u"1"]
@test MT.get_unit(x_vec) == u"1"
@test MT.get_unit(x_mat) == u"1"
end

0 comments on commit 8f2d885

Please sign in to comment.