@@ -23,12 +23,11 @@ function FunctionalAffect(f, sts, pars, ctx = nothing)
23
23
# sts & pars contain either pairs: resistor.R => R, or Syms: R
24
24
vs = [x isa Pair ? x. first : x for x in sts]
25
25
vs_syms = [x isa Pair ? Symbol (x. second) : getname (x) for x in sts]
26
- length (vs_syms) == length (unique (vs_syms)) || error (" Variables are not unique." )
27
26
28
27
ps = [x isa Pair ? x. first : x for x in pars]
29
28
ps_syms = [x isa Pair ? Symbol (x. second) : getname (x) for x in pars]
30
- length (ps_syms) == length (unique (ps_syms)) || error (" Parameters are not unique." )
31
-
29
+ length (vs_syms) + length ( ps_syms) == length (unique (vcat (vs_syms, ps_syms))) || error (" All symbols for variables & parameters must be unique." )
30
+
32
31
FunctionalAffect (f, vs, vs_syms, ps, ps_syms, ctx)
33
32
end
34
33
@@ -405,20 +404,16 @@ function compile_user_affect(affect::FunctionalAffect, sys, dvs, ps; kwargs...)
405
404
# (MTK should keep these symbols)
406
405
v = filter (x -> ! isnothing (x[1 ]), collect (zip (v_inds, states_syms (affect))))
407
406
v_inds = [x[1 ] for x in v]
408
- v_syms = Tuple ( [x[2 ] for x in v])
407
+ v_syms = [x[2 ] for x in v]
409
408
p = filter (x -> ! isnothing (x[1 ]), collect (zip (p_inds, parameters_syms (affect))))
410
409
p_inds = [x[1 ] for x in p]
411
- p_syms = Tuple ([x[2 ] for x in p])
412
-
413
- let v_inds= v_inds, p_inds= p_inds, v_syms= v_syms, p_syms= p_syms, user_affect= func (affect), ctx = context (affect)
414
- function (integ)
415
- uv = @views integ. u[v_inds]
416
- pv = @views integ. p[p_inds]
410
+ p_syms = [x[2 ] for x in p]
417
411
418
- u = LArray {v_syms} (uv)
419
- p = LArray {p_syms} (pv)
412
+ kwargs = zip (vcat (v_syms, p_syms), vcat (v_inds, p_inds))
420
413
421
- user_affect (integ. t, u, p, ctx)
414
+ let kwargs= kwargs, user_affect= func (affect), ctx = context (affect)
415
+ function (integ)
416
+ user_affect (integ, ctx; kwargs... )
422
417
end
423
418
end
424
419
end
0 commit comments