Skip to content

Commit dff5a38

Browse files
fix: properly handle SArray and iip propagation for linear SCCs
1 parent 88e5ade commit dff5a38

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/problems/sccnonlinearproblem.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::System, op; eval_expression = f
258258
p = rebuild_with_caches(p, templates...)
259259
end
260260

261+
# yes, `get_p_constructor` since this is only used for `LinearProblem` and
262+
# will retain the shape of `A`
263+
u0_constructor = get_p_constructor(u0_constructor, typeof(u0), u0_eltype)
261264
subprobs = []
262265
for (i, (f, vscc)) in enumerate(zip(nlfuns, var_sccs))
263266
_u0 = SymbolicUtils.Code.create_array(
@@ -271,7 +274,7 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::System, op; eval_expression = f
271274
A,
272275
b = get_A_b_from_LinearFunction(
273276
sys, f, p; eval_expression, eval_module, u0_constructor, u0_eltype)
274-
prob = LinearProblem(A, b, p; f = symbolic_interface, u0 = _u0)
277+
prob = LinearProblem{iip}(A, b, p; f = symbolic_interface, u0 = _u0)
275278
else
276279
isempty(symbolic_idxs) || throw(MissingGuessError(dvs[vscc], _u0))
277280
_u0 = u0_eltype.(_u0)

test/scc_nonlinear_problem.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ using ModelingToolkit: t_nounits as t, D_nounits as D
3636

3737
sccprob = SCCNonlinearProblem{false}(model, SA[(collect(u[1:5]) .=> zeros(5))...])
3838
for prob in sccprob.probs
39-
@test prob.u0 isa SVector
39+
if prob isa LinearProblem
40+
@test prob.A isa SMatrix
41+
@test prob.b isa SVector
42+
else
43+
@test prob.u0 isa SVector
44+
end
4045
@test !SciMLBase.isinplace(prob)
4146
end
4247

0 commit comments

Comments
 (0)