-
-
Notifications
You must be signed in to change notification settings - Fork 228
Fix unit validation for dimensionally compatible quantities (fixes #3787) #3838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -283,3 +283,25 @@ end | |||||
@test ModelingToolkit.get_unit.(filter(x -> occursin("ˍt", string(x)), unknowns(pend))) == | ||||||
[u"m/s", u"m/s"] | ||||||
end | ||||||
|
||||||
# Test for issue #3787: Validation of units with non-SI units should work | ||||||
@testset "Issue #3787: Non-SI unit validation" begin | ||||||
@parameters τ_ms [unit = u"ms"] | ||||||
@variables t_ms [unit = u"ms"] E_kJ(t_ms) [unit = u"kJ"] P_MW(t_ms) [unit = u"MW"] | ||||||
D_ms = Differential(t_ms) | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
# This should pass: kJ/ms = kW, and MW and kW are dimensionally compatible (both power) | ||||||
eqs_3787 = [D_ms(E_kJ) ~ P_MW - E_kJ / τ_ms, | ||||||
0 ~ P_MW] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
@test MT.validate(eqs_3787) == true | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
# Additional test: compatible units of different scales | ||||||
@variables x_m [unit = u"m"] y_km [unit = u"km"] | ||||||
eq_scales = [x_m ~ y_km] | ||||||
@test MT.validate(eq_scales) == true | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
# Test that incompatible dimensions still fail | ||||||
@variables a_length [unit = u"m"] b_time [unit = u"s"] | ||||||
eq_incompatible = [a_length ~ b_time] | ||||||
@test MT.validate(eq_incompatible) == false | ||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶