Skip to content

Commit b25870c

Browse files
committed
Revert variable mapping change - original was correct
The ordering from mmprob.f matches unknowns(mtk_simplified) ordering, so the simple index-based mapping was correct after all. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 091984a commit b25870c

File tree

1 file changed

+3
-33
lines changed

1 file changed

+3
-33
lines changed

benchmarks/DAE/NANDGateProblem.jmd

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -211,42 +211,12 @@ mmprob = ODEProblem(mmf, y0, tspan)
211211
# ModelingToolkit version via modelingtoolkitize
212212
mtk_sys = modelingtoolkitize(mmprob)
213213
mtk_simplified = structural_simplify(mtk_sys)
214-
215-
# Properly map initial conditions by matching variable names
216-
original_vars = unknowns(mtk_sys)
217-
simplified_vars = unknowns(mtk_simplified)
218-
219-
# Create mapping from original to simplified system
220-
u0_mtk = []
221-
for var in simplified_vars
222-
# Find the corresponding variable in the original system
223-
orig_idx = findfirst(v -> isequal(v, var), original_vars)
224-
if orig_idx !== nothing
225-
push!(u0_mtk, var => mmprob.u0[orig_idx])
226-
else
227-
# If variable not found, it might be a new auxiliary variable - use zero
228-
push!(u0_mtk, var => 0.0)
229-
end
230-
end
231-
214+
u0_mtk = [mtk_simplified.states[i] => mmprob.u0[i] for i in 1:length(mmprob.u0)]
232215
mtkprob = ODEProblem(mtk_simplified, u0_mtk, mmprob.tspan)
233216

234217
# DAEProblem version
235-
du_orig = mmprob.f(mmprob.u0, mmprob.p, 0.0)
236-
237-
# Map derivatives to simplified system
238-
du0 = []
239-
for var in simplified_vars
240-
# Find the corresponding variable in the original system
241-
orig_idx = findfirst(v -> isequal(v, var), original_vars)
242-
if orig_idx !== nothing
243-
push!(du0, D(var) => du_orig[orig_idx])
244-
else
245-
# If variable not found, use zero derivative
246-
push!(du0, D(var) => 0.0)
247-
end
248-
end
249-
218+
du = mmprob.f(mmprob.u0, mmprob.p, 0.0)
219+
du0 = D.(unknowns(mtk_simplified)) .=> du
250220
daeprob = DAEProblem(mtk_simplified, du0, [], tspan)
251221

252222
# Generate reference solutions

0 commit comments

Comments
 (0)