Skip to content

Commit f7bf33a

Browse files
ctessumAayushSabharwal
authored andcommitted
Don't check units during initialization
...because initialization problems don't correctly handle units and units have already been checked during system initialization.
1 parent fa14fdd commit f7bf33a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/systems/problem_utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ Keyword arguments:
396396
- `eval_module`: If `eval_expression == true`, the module to `eval` into. Otherwise, the module
397397
in which to generate the `RuntimeGeneratedFunction`.
398398
- `fully_determined`: Override whether the initialization system is fully determined.
399-
- `check_units`: Enable or disable unit checks.
399+
- `check_units`: Enable or disable unit checks when constructing the initialization problem.
400400
- `tofloat`, `use_union`: Passed to [`better_varmap_to_vars`](@ref) for building `u0` (and
401401
possibly `p`).
402402
- `u0_constructor`: A function to apply to the `u0` value returned from `better_varmap_to_vars`
@@ -414,7 +414,7 @@ function process_SciMLProblem(
414414
implicit_dae = false, t = nothing, guesses = AnyDict(),
415415
warn_initialize_determined = true, initialization_eqs = [],
416416
eval_expression = false, eval_module = @__MODULE__, fully_determined = false,
417-
check_units = true, tofloat = true, use_union = false,
417+
check_units = false, tofloat = true, use_union = false,
418418
u0_constructor = identity, du0map = nothing, check_length = true, symbolic_u0 = false, kwargs...)
419419
dvs = unknowns(sys)
420420
ps = parameters(sys)

test/initializationsystem.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using ForwardDiff
33
using SymbolicIndexingInterface, SciMLStructures
44
using SciMLStructures: Tunable
55
using ModelingToolkit: t_nounits as t, D_nounits as D
6+
using DynamicQuantities
67

78
@parameters g
89
@variables x(t) y(t) [state_priority = 10] λ(t)
@@ -860,3 +861,19 @@ end
860861
integ = init(prob)
861862
@test integ[x] [1.0, 3.0]
862863
end
864+
865+
@testset "units" begin
866+
t = ModelingToolkit.t
867+
D = ModelingToolkit.D
868+
@parameters g [unit = u"m/s^2"] L=1 [unit = u"m^2"]
869+
@variables x(t) [unit = u"m"] y(t) [unit = u"m" state_priority = 10] λ(t) [unit = u"s^-2"]
870+
eqs = [D(D(x)) ~ λ * x
871+
D(D(y)) ~ λ * y - g
872+
x^2 + y^2 ~ L]
873+
@mtkbuild pend = ODESystem(eqs, t)
874+
875+
prob = ODEProblem(pend, [x => 1, y => 0], (0.0, 1.5), [g => 1],
876+
guesses = ModelingToolkit.missing_variable_defaults(pend))
877+
sol = solve(prob, Rodas5P())
878+
@test SciMLBase.successful_retcode(sol)
879+
end

0 commit comments

Comments
 (0)