@@ -63,6 +63,16 @@ struct IndexCache
6363 symbol_to_variable:: Dict{Symbol, SymbolicParam}
6464end
6565
66+ function Base. copy (ic:: IndexCache )
67+ IndexCache (copy (ic. unknown_idx), copy (ic. discrete_idx), copy (ic. callback_to_clocks),
68+ copy (ic. tunable_idx), copy (ic. initials_idx), copy (ic. constant_idx),
69+ copy (ic. nonnumeric_idx), copy (ic. observed_syms_to_timeseries),
70+ copy (ic. dependent_pars_to_timeseries), copy (ic. discrete_buffer_sizes),
71+ ic. tunable_buffer_size, ic. initials_buffer_size,
72+ copy (ic. constant_buffer_sizes), copy (ic. nonnumeric_buffer_sizes),
73+ copy (ic. symbol_to_variable))
74+ end
75+
6676function IndexCache (sys:: AbstractSystem )
6777 unks = unknowns (sys)
6878 unk_idxs = UnknownIndexMap ()
@@ -722,3 +732,55 @@ function subset_unknowns_observed(
722732 @set! ic. observed_syms_to_timeseries = observed_syms_to_timeseries
723733 return ic
724734end
735+
736+ function with_additional_constant_parameter (sys:: AbstractSystem , par)
737+ par = unwrap (par)
738+ ps = copy (get_ps (sys))
739+ push! (ps, par)
740+ @set! sys. ps = ps
741+ is_split (sys) || return sys
742+
743+ ic = copy (get_index_cache (sys))
744+ T = symtype (par)
745+ bufidx = findfirst (buft -> buft. type == T, ic. constant_buffer_sizes)
746+ if bufidx === nothing
747+ push! (ic. constant_buffer_sizes, BufferTemplate (T, 1 ))
748+ bufidx = length (ic. constant_buffer_sizes)
749+ idx_in_buf = 1
750+ else
751+ buft = ic. constant_buffer_sizes[bufidx]
752+ ic. constant_buffer_sizes[bufidx] = BufferTemplate (T, buft. length + 1 )
753+ idx_in_buf = buft. length + 1
754+ end
755+
756+ ic. constant_idx[par] = ic. constant_idx[renamespace (sys, par)] = (bufidx, idx_in_buf)
757+ @set! sys. index_cache = ic
758+
759+ return sys
760+ end
761+
762+ function with_additional_nonnumeric_parameter (sys:: AbstractSystem , par)
763+ par = unwrap (par)
764+ ps = copy (get_ps (sys))
765+ push! (ps, par)
766+ @set! sys. ps = ps
767+ is_split (sys) || return sys
768+
769+ ic = copy (get_index_cache (sys))
770+ T = symtype (par)
771+ bufidx = findfirst (buft -> buft. type == T, ic. nonnumeric_buffer_sizes)
772+ if bufidx === nothing
773+ push! (ic. nonnumeric_buffer_sizes, BufferTemplate (T, 1 ))
774+ bufidx = length (ic. nonnumeric_buffer_sizes)
775+ idx_in_buf = 1
776+ else
777+ buft = ic. nonnumeric_buffer_sizes[bufidx]
778+ ic. nonnumeric_buffer_sizes[bufidx] = BufferTemplate (T, buft. length + 1 )
779+ idx_in_buf = buft. length + 1
780+ end
781+
782+ ic. nonnumeric_idx[par] = ic. nonnumeric_idx[renamespace (sys, par)] = (bufidx, idx_in_buf)
783+ @set! sys. index_cache = ic
784+
785+ return sys
786+ end
0 commit comments