Skip to content

Commit

Permalink
Merge pull request #3119 from ctessum/units_init
Browse files Browse the repository at this point in the history
Don't check units during initialization
  • Loading branch information
AayushSabharwal authored Oct 28, 2024
2 parents 213246e + 616e5d1 commit 024e66c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/systems/problem_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ Keyword arguments:
- `eval_module`: If `eval_expression == true`, the module to `eval` into. Otherwise, the module
in which to generate the `RuntimeGeneratedFunction`.
- `fully_determined`: Override whether the initialization system is fully determined.
- `check_units`: Enable or disable unit checks.
- `check_initialization_units`: Enable or disable unit checks when constructing the
initialization problem.
- `tofloat`, `use_union`: Passed to [`better_varmap_to_vars`](@ref) for building `u0` (and
possibly `p`).
- `u0_constructor`: A function to apply to the `u0` value returned from `better_varmap_to_vars`
Expand All @@ -414,7 +415,7 @@ function process_SciMLProblem(
implicit_dae = false, t = nothing, guesses = AnyDict(),
warn_initialize_determined = true, initialization_eqs = [],
eval_expression = false, eval_module = @__MODULE__, fully_determined = false,
check_units = true, tofloat = true, use_union = false,
check_initialization_units = false, tofloat = true, use_union = false,
u0_constructor = identity, du0map = nothing, check_length = true, symbolic_u0 = false, kwargs...)
dvs = unknowns(sys)
ps = parameters(sys)
Expand Down Expand Up @@ -464,7 +465,8 @@ function process_SciMLProblem(
!isempty(initialization_equations(sys))) && t !== nothing
initializeprob = ModelingToolkit.InitializationProblem(
sys, t, u0map, pmap; guesses, warn_initialize_determined,
initialization_eqs, eval_expression, eval_module, fully_determined, check_units)
initialization_eqs, eval_expression, eval_module, fully_determined,
check_units = check_initialization_units)
initializeprobmap = getu(initializeprob, unknowns(sys))

punknowns = [p
Expand Down
17 changes: 17 additions & 0 deletions test/initializationsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using ForwardDiff
using SymbolicIndexingInterface, SciMLStructures
using SciMLStructures: Tunable
using ModelingToolkit: t_nounits as t, D_nounits as D
using DynamicQuantities

@parameters g
@variables x(t) y(t) [state_priority = 10] λ(t)
Expand Down Expand Up @@ -860,3 +861,19 @@ end
integ = init(prob)
@test integ[x] [1.0, 3.0]
end

@testset "units" begin
t = ModelingToolkit.t
D = ModelingToolkit.D
@parameters g [unit = u"m/s^2"] L=1 [unit = u"m^2"]
@variables x(t) [unit = u"m"] y(t) [unit = u"m" state_priority = 10] λ(t) [unit = u"s^-2"]
eqs = [D(D(x)) ~ λ * x
D(D(y)) ~ λ * y - g
x^2 + y^2 ~ L]
@mtkbuild pend = ODESystem(eqs, t)

prob = ODEProblem(pend, [x => 1, y => 0], (0.0, 1.5), [g => 1],
guesses = ModelingToolkit.missing_variable_defaults(pend))
sol = solve(prob, Rodas5P())
@test SciMLBase.successful_retcode(sol)
end

0 comments on commit 024e66c

Please sign in to comment.