Skip to content

Expose a non dummy derivative index lowering #2510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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