Skip to content
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
3 changes: 2 additions & 1 deletion src/systems/nonlinear/nonlinearsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,8 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::NonlinearSystem, u0map,
new_eqs = eqs[reduce(vcat, eq_sccs)]
@set! sys.unknowns = new_dvs
@set! sys.eqs = new_eqs
sys = complete(sys)
@set! sys.index_cache = subset_unknowns_observed(
get_index_cache(sys), sys, new_dvs, getproperty.(obs, (:lhs,)))
return SCCNonlinearProblem(subprobs, explicitfuns, p, true; sys)
end

Expand Down
19 changes: 19 additions & 0 deletions test/scc_nonlinear_problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@
β = 1e-6
R0 = 1000
R = 9000
Ue(t) = 0.1 * sin(200 * π * t)

Check warning on line 96 in test/scc_nonlinear_problem.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"Ue" should be "Use" or "Due".

function transamp(out, du, u, p, t)
g(x) = 1e-6 * (exp(x / 0.026) - 1)
y1, y2, y3, y4, y5, y6, y7, y8 = u
out[1] = -Ue(t) / R0 + y1 / R0 + C[1] * du[1] - C[1] * du[2]

Check warning on line 101 in test/scc_nonlinear_problem.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"Ue" should be "Use" or "Due".
out[2] = -Ub / R + y2 * 2 / R - (α - 1) * g(y2 - y3) - C[1] * du[1] + C[1] * du[2]
out[3] = -g(y2 - y3) + y3 / R + C[2] * du[3]
out[4] = -Ub / R + y4 / R + α * g(y2 - y3) + C[3] * du[4] - C[3] * du[5]
Expand Down Expand Up @@ -263,3 +263,22 @@
sol = solve(prob, NewtonRaphson())
@test SciMLBase.successful_retcode(sol)
end

@testset "SCCNonlinearProblem retains parameter order" begin
@variables x y z
@parameters σ β ρ
@mtkbuild fullsys = NonlinearSystem(
[0 ~ x^3 * β + y^3 * ρ - σ, 0 ~ x^2 + 2x * y + y^2, 0 ~ z^2 - 4z + 4],
[x, y, z], [σ, β, ρ])

u0 = [x => 1.0,
y => 0.0,
z => 0.0]

p = [σ => 28.0,
ρ => 10.0,
β => 8 / 3]

sccprob = SCCNonlinearProblem(fullsys, u0, p)
@test isequal(parameters(fullsys), parameters(sccprob.f.sys))
end
Loading