Skip to content

Commit 024e66c

Browse files
Merge pull request #3119 from ctessum/units_init
Don't check units during initialization
2 parents 213246e + 616e5d1 commit 024e66c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/systems/problem_utils.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ 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_initialization_units`: Enable or disable unit checks when constructing the
400+
initialization problem.
400401
- `tofloat`, `use_union`: Passed to [`better_varmap_to_vars`](@ref) for building `u0` (and
401402
possibly `p`).
402403
- `u0_constructor`: A function to apply to the `u0` value returned from `better_varmap_to_vars`
@@ -414,7 +415,7 @@ function process_SciMLProblem(
414415
implicit_dae = false, t = nothing, guesses = AnyDict(),
415416
warn_initialize_determined = true, initialization_eqs = [],
416417
eval_expression = false, eval_module = @__MODULE__, fully_determined = false,
417-
check_units = true, tofloat = true, use_union = false,
418+
check_initialization_units = false, tofloat = true, use_union = false,
418419
u0_constructor = identity, du0map = nothing, check_length = true, symbolic_u0 = false, kwargs...)
419420
dvs = unknowns(sys)
420421
ps = parameters(sys)
@@ -464,7 +465,8 @@ function process_SciMLProblem(
464465
!isempty(initialization_equations(sys))) && t !== nothing
465466
initializeprob = ModelingToolkit.InitializationProblem(
466467
sys, t, u0map, pmap; guesses, warn_initialize_determined,
467-
initialization_eqs, eval_expression, eval_module, fully_determined, check_units)
468+
initialization_eqs, eval_expression, eval_module, fully_determined,
469+
check_units = check_initialization_units)
468470
initializeprobmap = getu(initializeprob, unknowns(sys))
469471

470472
punknowns = [p

test/initializationsystem.jl

+17
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)