@@ -292,8 +292,14 @@ function TearingState(sys; quick_cancel = false, check = true)
292
292
end
293
293
if iscall (eq′. lhs) && (op = operation (eq′. lhs)) isa Differential &&
294
294
isequal (op. x, iv) && is_time_dependent_parameter (only (arguments (eq′. lhs)), iv)
295
- param_derivative_map[eq′. lhs] = eq′. rhs
295
+ # parameter derivatives are opted out by specifying `D(p) ~ missing`, but
296
+ # we want to store `nothing` in the map because that means `fast_substitute`
297
+ # will ignore the rule. We will this identify the presence of `eq′.lhs` in
298
+ # the differentiated expression and error.
299
+ param_derivative_map[eq′. lhs] = coalesce (eq′. rhs, nothing )
296
300
eqs_to_retain[i] = false
301
+ # change the equation if the RHS is `missing` so the rest of this loop works
302
+ eq′ = eq′. lhs ~ coalesce (eq′. rhs, 0.0 )
297
303
end
298
304
if _iszero (eq′. lhs)
299
305
rhs = quick_cancel ? quick_cancel_expr (eq′. rhs) : eq′. rhs
@@ -311,9 +317,9 @@ function TearingState(sys; quick_cancel = false, check = true)
311
317
(iscall (_var) && isparameter (operation (_var)) || isconstant (_var))
312
318
if is_time_dependent_parameter (_var, iv) &&
313
319
! haskey (param_derivative_map, Differential (iv)(_var))
314
- # default to `nothing` since it is ignored during substitution,
315
- # so `D(_var)` is retained in the expression.
316
- param_derivative_map[Differential (iv)(_var)] = nothing
320
+ # Parameter derivatives default to zero - they stay constant
321
+ # between callbacks
322
+ param_derivative_map[Differential (iv)(_var)] = 0.0
317
323
end
318
324
continue
319
325
end
0 commit comments