Skip to content

Commit b0f8f78

Browse files
Merge pull request #2349 from SciML/myb/unit
[BREAKING Don't merge] Support DynamicQuantities
2 parents df4b7e5 + e763b63 commit b0f8f78

19 files changed

+566
-66
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1717
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1818
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1919
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
20+
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
2021
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
2122
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
2223
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
@@ -72,6 +73,7 @@ Distributed = "1"
7273
Distributions = "0.23, 0.24, 0.25"
7374
DocStringExtensions = "0.7, 0.8, 0.9"
7475
DomainSets = "0.6"
76+
DynamicQuantities = "0.8, 0.9, 0.10"
7577
ForwardDiff = "0.10.3"
7678
FunctionWrappersWrappers = "0.1"
7779
Graphs = "1.5.2"

src/ModelingToolkit.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ include("systems/pde/pdesystem.jl")
152152

153153
include("systems/sparsematrixclil.jl")
154154
include("systems/discrete_system/discrete_system.jl")
155+
include("systems/unit_check.jl")
155156
include("systems/validation.jl")
156157
include("systems/dependency_graphs.jl")
157158
include("clock.jl")

src/systems/diffeqs/odesystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ struct ODESystem <: AbstractODESystem
163163
check_equations(equations(cevents), iv)
164164
end
165165
if checks == true || (checks & CheckUnits) > 0
166-
all_dimensionless([dvs; ps; iv]) || check_units(deqs)
166+
u = __get_unit_type(dvs, ps, iv)
167+
check_units(u, deqs)
167168
end
168169
new(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
169170
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, torn_matching,

src/systems/diffeqs/sdesystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ struct SDESystem <: AbstractODESystem
134134
check_equations(equations(cevents), iv)
135135
end
136136
if checks == true || (checks & CheckUnits) > 0
137-
all_dimensionless([dvs; ps; iv]) || check_units(deqs, neqs)
137+
u = __get_unit_type(dvs, ps, iv)
138+
check_units(u, deqs, neqs)
138139
end
139140
new(tag, deqs, neqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
140141
ctrl_jac,

src/systems/discrete_system/discrete_system.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
103103
check_parameters(ps, iv)
104104
end
105105
if checks == true || (checks & CheckUnits) > 0
106-
all_dimensionless([dvs; ps; iv; ctrls]) || check_units(discreteEqs)
106+
u = __get_unit_type(dvs, ps, iv, ctrls)
107+
check_units(u, discreteEqs)
107108
end
108109
new(tag, discreteEqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, name,
109110
systems,

src/systems/jumps/jumpsystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
112112
check_parameters(ps, iv)
113113
end
114114
if checks == true || (checks & CheckUnits) > 0
115-
all_dimensionless([states; ps; iv]) || check_units(ap, iv)
115+
u = __get_unit_type(states, ps, iv)
116+
check_units(u, ap, iv)
116117
end
117118
new{U}(tag, ap, iv, states, ps, var_to_name, observed, name, systems, defaults,
118119
connector_type, devents, metadata, gui_metadata, complete)

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
8888
tearing_state = nothing, substitutions = nothing,
8989
complete = false, parent = nothing; checks::Union{Bool, Int} = true)
9090
if checks == true || (checks & CheckUnits) > 0
91-
all_dimensionless([states; ps]) || check_units(eqs)
91+
u = __get_unit_type(states, ps)
92+
check_units(u, eqs)
9293
end
9394
new(tag, eqs, states, ps, var_to_name, observed, jac, name, systems, defaults,
9495
connector_type, metadata, gui_metadata, tearing_state, substitutions, complete,

src/systems/optimization/constraints_system.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ struct ConstraintsSystem <: AbstractTimeIndependentSystem
7777
tearing_state = nothing, substitutions = nothing;
7878
checks::Union{Bool, Int} = true)
7979
if checks == true || (checks & CheckUnits) > 0
80-
all_dimensionless([states; ps]) || check_units(constraints)
80+
u = __get_unit_type(states, ps)
81+
check_units(u, constraints)
8182
end
8283
new(tag, constraints, states, ps, var_to_name, observed, jac, name, systems,
8384
defaults,

src/systems/optimization/optimizationsystem.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ struct OptimizationSystem <: AbstractOptimizationSystem
6666
gui_metadata = nothing, complete = false, parent = nothing;
6767
checks::Union{Bool, Int} = true)
6868
if checks == true || (checks & CheckUnits) > 0
69-
unwrap(op) isa Symbolic && check_units(op)
70-
check_units(observed)
71-
all_dimensionless([states; ps]) || check_units(constraints)
69+
u = __get_unit_type(states, ps)
70+
unwrap(op) isa Symbolic && check_units(u, op)
71+
check_units(u, observed)
72+
check_units(u, constraints)
7273
end
7374
new(tag, op, states, ps, var_to_name, observed,
7475
constraints, name, systems, defaults, metadata, gui_metadata, complete,

src/systems/pde/pdesystem.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
9898
checks::Union{Bool, Int} = true,
9999
name)
100100
if checks == true || (checks & CheckUnits) > 0
101-
all_dimensionless([dvs; ivs; ps]) || check_units(eqs)
101+
u = __get_unit_type(dvs, ivs, ps)
102+
check_units(u, eqs)
102103
end
103104

104105
eqs = eqs isa Vector ? eqs : [eqs]

0 commit comments

Comments
 (0)