@@ -420,6 +420,54 @@ function SymbolicIndexingInterface.remake_buffer(sys, oldbuf::MTKParameters, val
420
420
return newbuf
421
421
end
422
422
423
+ struct NestedGetIndex{T}
424
+ x:: T
425
+ end
426
+
427
+ function Base. getindex (ngi:: NestedGetIndex , idx:: Tuple )
428
+ i, j, k... = idx
429
+ return ngi. x[i][j][k... ]
430
+ end
431
+
432
+ # Required for DiffEqArray constructor to work during interpolation
433
+ Base. size (:: NestedGetIndex ) = ()
434
+
435
+ function SymbolicIndexingInterface. with_updated_parameter_timeseries_values (
436
+ ps:: MTKParameters , args:: Pair{A, B} ...) where {A, B <: NestedGetIndex }
437
+ for (i, val) in args
438
+ ps. discrete[i] = val. x
439
+ end
440
+ return ps
441
+ end
442
+
443
+ function SciMLBase. create_parameter_timeseries_collection (
444
+ sys:: AbstractSystem , ps:: MTKParameters , tspan)
445
+ ic = get_index_cache (sys) # this exists because the parameters are `MTKParameters`
446
+ has_discrete_subsystems (sys) || return nothing
447
+ (dss = get_discrete_subsystems (sys)) === nothing && return nothing
448
+ _, _, _, id_to_clock = dss
449
+ buffers = []
450
+
451
+ for (i, partition) in enumerate (ps. discrete)
452
+ clock = id_to_clock[i + 1 ]
453
+ if clock isa Clock
454
+ ts = tspan[1 ]: (clock. dt): tspan[2 ]
455
+ push! (buffers, DiffEqArray (NestedGetIndex{typeof (partition)}[], ts, (1 , 1 )))
456
+ elseif clock isa SolverStepClock
457
+ push! (buffers,
458
+ DiffEqArray (NestedGetIndex{typeof (partition)}[], eltype (tspan)[], (1 , 1 )))
459
+ else
460
+ error (" Unhandled clock $clock " )
461
+ end
462
+ end
463
+
464
+ return ParameterTimeseriesCollection (Tuple (buffers), copy (ps))
465
+ end
466
+
467
+ function SciMLBase. get_saveable_values (ps:: MTKParameters , timeseries_idx)
468
+ return NestedGetIndex (deepcopy (ps. discrete[timeseries_idx]))
469
+ end
470
+
423
471
function DiffEqBase. anyeltypedual (
424
472
p:: MTKParameters , :: Type{Val{counter}} = Val{0 }) where {counter}
425
473
DiffEqBase. anyeltypedual (p. tunable)
0 commit comments