Skip to content

Commit

Permalink
Merge pull request #2510 from SciML/dd
Browse files Browse the repository at this point in the history
Expose a non dummy derivative index lowering
  • Loading branch information
ChrisRackauckas committed Mar 1, 2024
2 parents 78ec2b2 + e9d5259 commit ef8171a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/structural_transformation/StructuralTransformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export tearing, partial_state_selection, dae_index_lowering, check_consistency
export dummy_derivative
export build_torn_function, build_observed_function, ODAEProblem
export sorted_incidence_matrix,
pantelides!, tearing_reassemble, find_solvables!,
pantelides!, pantelides_reassemble, tearing_reassemble, find_solvables!,
linear_subsys_adjmat!
export tearing_assignments, tearing_substitution
export torn_system_jacobian_sparsity
Expand Down
9 changes: 8 additions & 1 deletion src/systems/systemstructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ end

function _structural_simplify!(state::TearingState, io; simplify = false,
check_consistency = true, fully_determined = true, warn_initialize_determined = false,
dummy_derivative = true,
kwargs...)
check_consistency &= fully_determined
has_io = io !== nothing
Expand All @@ -628,7 +629,13 @@ function _structural_simplify!(state::TearingState, io; simplify = false,
if check_consistency
ModelingToolkit.check_consistency(state, orig_inputs)
end
if fully_determined
if fully_determined && dummy_derivative
sys = ModelingToolkit.dummy_derivative(sys, state; simplify, mm, check_consistency)
elseif fully_determined
var_eq_matching = pantelides!(state; finalize = false, kwargs...)
sys = pantelides_reassemble(state, var_eq_matching)
state = TearingState(sys)
sys, mm = ModelingToolkit.alias_elimination!(state; kwargs...)
sys = ModelingToolkit.dummy_derivative(sys, state; simplify, mm, check_consistency)
else
sys = ModelingToolkit.tearing(sys, state; simplify, mm, check_consistency)
Expand Down
16 changes: 16 additions & 0 deletions test/structural_transformation/index_reduction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,19 @@ let sys = structural_simplify(pendulum2)
@test sol.retcode == ReturnCode.Success
@test norm(sol[x] .^ 2 + sol[y] .^ 2 .- 1) < 1e-2
end

let
@parameters g
@variables x(t) [state_priority = 10] y(t) λ(t)

eqs = [D(D(x)) ~ λ * x
D(D(y)) ~ λ * y - g
x^2 + y^2 ~ 1]
@named pend = ODESystem(eqs, t)
sys = complete(structural_simplify(pend; dummy_derivative = false))
prob = ODEProblem(
sys, [x => 1, y => 0, D(x) => 0.0], (0.0, 10.0), [g => 1], guesses ==> 0.0])
sol = solve(prob, Rodas5P())
@test SciMLBase.successful_retcode(sol)
@test sol[x^2 + y^2][end] < 1.1
end

0 comments on commit ef8171a

Please sign in to comment.