Skip to content

Commit

Permalink
Merge pull request SciML#2349 from SciML/myb/unit
Browse files Browse the repository at this point in the history
[BREAKING Don't merge] Support DynamicQuantities
  • Loading branch information
ChrisRackauckas authored Jan 4, 2024
2 parents df4b7e5 + e763b63 commit b0f8f78
Show file tree
Hide file tree
Showing 19 changed files with 566 additions and 66 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Expand Down Expand Up @@ -72,6 +73,7 @@ Distributed = "1"
Distributions = "0.23, 0.24, 0.25"
DocStringExtensions = "0.7, 0.8, 0.9"
DomainSets = "0.6"
DynamicQuantities = "0.8, 0.9, 0.10"
ForwardDiff = "0.10.3"
FunctionWrappersWrappers = "0.1"
Graphs = "1.5.2"
Expand Down
1 change: 1 addition & 0 deletions src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ include("systems/pde/pdesystem.jl")

include("systems/sparsematrixclil.jl")
include("systems/discrete_system/discrete_system.jl")
include("systems/unit_check.jl")
include("systems/validation.jl")
include("systems/dependency_graphs.jl")
include("clock.jl")
Expand Down
3 changes: 2 additions & 1 deletion src/systems/diffeqs/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ struct ODESystem <: AbstractODESystem
check_equations(equations(cevents), iv)
end
if checks == true || (checks & CheckUnits) > 0
all_dimensionless([dvs; ps; iv]) || check_units(deqs)
u = __get_unit_type(dvs, ps, iv)
check_units(u, deqs)
end
new(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, torn_matching,
Expand Down
3 changes: 2 additions & 1 deletion src/systems/diffeqs/sdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ struct SDESystem <: AbstractODESystem
check_equations(equations(cevents), iv)
end
if checks == true || (checks & CheckUnits) > 0
all_dimensionless([dvs; ps; iv]) || check_units(deqs, neqs)
u = __get_unit_type(dvs, ps, iv)
check_units(u, deqs, neqs)
end
new(tag, deqs, neqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
ctrl_jac,
Expand Down
3 changes: 2 additions & 1 deletion src/systems/discrete_system/discrete_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
check_parameters(ps, iv)
end
if checks == true || (checks & CheckUnits) > 0
all_dimensionless([dvs; ps; iv; ctrls]) || check_units(discreteEqs)
u = __get_unit_type(dvs, ps, iv, ctrls)
check_units(u, discreteEqs)
end
new(tag, discreteEqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, name,
systems,
Expand Down
3 changes: 2 additions & 1 deletion src/systems/jumps/jumpsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
check_parameters(ps, iv)
end
if checks == true || (checks & CheckUnits) > 0
all_dimensionless([states; ps; iv]) || check_units(ap, iv)
u = __get_unit_type(states, ps, iv)
check_units(u, ap, iv)
end
new{U}(tag, ap, iv, states, ps, var_to_name, observed, name, systems, defaults,
connector_type, devents, metadata, gui_metadata, complete)
Expand Down
3 changes: 2 additions & 1 deletion src/systems/nonlinear/nonlinearsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
tearing_state = nothing, substitutions = nothing,
complete = false, parent = nothing; checks::Union{Bool, Int} = true)
if checks == true || (checks & CheckUnits) > 0
all_dimensionless([states; ps]) || check_units(eqs)
u = __get_unit_type(states, ps)
check_units(u, eqs)
end
new(tag, eqs, states, ps, var_to_name, observed, jac, name, systems, defaults,
connector_type, metadata, gui_metadata, tearing_state, substitutions, complete,
Expand Down
3 changes: 2 additions & 1 deletion src/systems/optimization/constraints_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ struct ConstraintsSystem <: AbstractTimeIndependentSystem
tearing_state = nothing, substitutions = nothing;
checks::Union{Bool, Int} = true)
if checks == true || (checks & CheckUnits) > 0
all_dimensionless([states; ps]) || check_units(constraints)
u = __get_unit_type(states, ps)
check_units(u, constraints)
end
new(tag, constraints, states, ps, var_to_name, observed, jac, name, systems,
defaults,
Expand Down
7 changes: 4 additions & 3 deletions src/systems/optimization/optimizationsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ struct OptimizationSystem <: AbstractOptimizationSystem
gui_metadata = nothing, complete = false, parent = nothing;
checks::Union{Bool, Int} = true)
if checks == true || (checks & CheckUnits) > 0
unwrap(op) isa Symbolic && check_units(op)
check_units(observed)
all_dimensionless([states; ps]) || check_units(constraints)
u = __get_unit_type(states, ps)
unwrap(op) isa Symbolic && check_units(u, op)
check_units(u, observed)
check_units(u, constraints)
end
new(tag, op, states, ps, var_to_name, observed,
constraints, name, systems, defaults, metadata, gui_metadata, complete,
Expand Down
3 changes: 2 additions & 1 deletion src/systems/pde/pdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
checks::Union{Bool, Int} = true,
name)
if checks == true || (checks & CheckUnits) > 0
all_dimensionless([dvs; ivs; ps]) || check_units(eqs)
u = __get_unit_type(dvs, ivs, ps)
check_units(u, eqs)
end

eqs = eqs isa Vector ? eqs : [eqs]
Expand Down
Loading

0 comments on commit b0f8f78

Please sign in to comment.