@@ -514,11 +514,10 @@ end
514
514
testsol (ssys3, SDEProblem, RI5, u0, p, tspan; tstops = [1.0 ], paramtotest = k)
515
515
516
516
# mixing with a func affect
517
- function affect! (integrator, u, p, ctx)
518
- integrator. ps[p. k] = 1.0
519
- nothing
517
+ function affect! (mod, obs, ctx, integ)
518
+ return (; k = 1.0 )
520
519
end
521
- cb2‵‵ = [2.0 ] => (affect!, [], [k], [k], nothing )
520
+ cb2‵‵ = [2.0 ] => (f = affect!, modified = (; k) )
522
521
@named osys4 = System (eqs, t, [A], [k, t1], discrete_events = [cb1, cb2‵‵])
523
522
@named ssys4 = SDESystem (eqs, [0.0 ], t, [A], [k, t1],
524
523
discrete_events = [cb1, cb2‵‵])
527
526
testsol (ssys4, SDEProblem, RI5, u0, p, tspan; tstops = [1.0 ], paramtotest = k)
528
527
529
528
# mixing with symbolic condition in the func affect
530
- cb2‵‵‵ = (t == t2) => (affect!, [], [k], [k], nothing )
529
+ cb2‵‵‵ = (t == t2) => (f = affect!, modified = (; k) )
531
530
@named osys5 = System (eqs, t, [A], [k, t1, t2], discrete_events = [cb1, cb2‵‵‵])
532
531
@named ssys5 = SDESystem (eqs, [0.0 ], t, [A], [k, t1, t2],
533
532
discrete_events = [cb1, cb2‵‵‵])
@@ -605,17 +604,15 @@ end
605
604
testsol (jsys3, u0, p, tspan; tstops = [1.0 ], rng, paramtotest = k)
606
605
607
606
# mixing with a func affect
608
- function affect! (integrator, u, p, ctx)
609
- integrator. ps[p. k] = 1.0
610
- reset_aggregated_jumps! (integrator)
611
- nothing
607
+ function affect! (mod, obs, ctx, integrator)
608
+ return (; k = 1.0 )
612
609
end
613
- cb2‵‵ = [2.0 ] => (affect!, [], [k], [k], nothing )
610
+ cb2‵‵ = [2.0 ] => (f = affect!, modified = (; k) )
614
611
@named jsys4 = JumpSystem (eqs, t, [A], [k, t1], discrete_events = [cb1, cb2‵‵])
615
612
testsol (jsys4, u0, p, tspan; tstops = [1.0 ], rng, paramtotest = k)
616
613
617
614
# mixing with symbolic condition in the func affect
618
- cb2‵‵‵ = (t == t2) => (affect!, [], [k], [k], nothing )
615
+ cb2‵‵‵ = (t == t2) => (f = affect!, modified = (; k) )
619
616
@named jsys5 = JumpSystem (eqs, t, [A], [k, t1, t2], discrete_events = [cb1, cb2‵‵‵])
620
617
testsol (jsys5, u0, p, tspan; tstops = [1.0 , 2.0 ], rng, paramtotest = k)
621
618
@named jsys6 = JumpSystem (eqs, t, [A], [k, t1, t2], discrete_events = [cb2‵‵‵, cb1])
@@ -649,13 +646,16 @@ end
649
646
# baseline affect (pos + neg + left root find)
650
647
@variables c1 (t)= 1.0 c2 (t)= 1.0 # c1 = cos(t), c2 = cos(3t)
651
648
eqs = [D (c1) ~ - sin (t); D (c2) ~ - 3 * sin (3 * t)]
652
- record_crossings (i, u, _, c) = push! (c, i. t => i. u[u. v])
649
+ function record_crossings (mod, obs, ctx, integ)
650
+ push! (ctx, integ. t => obs. v)
651
+ return (;)
652
+ end
653
653
cr1 = []
654
654
cr2 = []
655
655
evt1 = ModelingToolkit. SymbolicContinuousCallback (
656
- [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1))
656
+ [c1 ~ 0 ], (f = record_crossings, observed = (; v = c1), ctx = cr1))
657
657
evt2 = ModelingToolkit. SymbolicContinuousCallback (
658
- [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2))
658
+ [c2 ~ 0 ], (f = record_crossings, observed = (; v = c2), ctx = cr2))
659
659
@named trigsys = System (eqs, t; continuous_events = [evt1, evt2])
660
660
trigsys_ss = structural_simplify (trigsys)
661
661
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
@@ -673,11 +673,11 @@ end
673
673
cr1n = []
674
674
cr2n = []
675
675
evt1 = ModelingToolkit. SymbolicContinuousCallback (
676
- [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1p);
677
- affect_neg = (record_crossings, [c1 => :v ], [], [], cr1n))
676
+ [c1 ~ 0 ], (f = record_crossings, observed = (; v = c1), ctx = cr1p);
677
+ affect_neg = (f = record_crossings, observed = (; v = c1), ctx = cr1n))
678
678
evt2 = ModelingToolkit. SymbolicContinuousCallback (
679
- [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2p);
680
- affect_neg = (record_crossings, [c2 => :v ], [], [], cr2n))
679
+ [c2 ~ 0 ], (f = record_crossings, observed = (; v = c2), ctx = cr2p);
680
+ affect_neg = (f = record_crossings, observed = (; v = c2), ctx = cr2n))
681
681
@named trigsys = System (eqs, t; continuous_events = [evt1, evt2])
682
682
trigsys_ss = structural_simplify (trigsys)
683
683
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
699
699
cr1p = []
700
700
cr2p = []
701
701
evt1 = ModelingToolkit. SymbolicContinuousCallback (
702
- [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1p); affect_neg = nothing )
702
+ [c1 ~ 0 ], (f = record_crossings, observed = (; v = c1), ctx = cr1p); affect_neg = nothing )
703
703
evt2 = ModelingToolkit. SymbolicContinuousCallback (
704
- [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2p); affect_neg = nothing )
704
+ [c2 ~ 0 ], (f = record_crossings, observed = (; v = c2), ctx = cr2p); affect_neg = nothing )
705
705
@named trigsys = System (eqs, t; continuous_events = [evt1, evt2])
706
706
trigsys_ss = structural_simplify (trigsys)
707
707
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
@@ -717,10 +717,10 @@ end
717
717
cr1n = []
718
718
cr2n = []
719
719
evt1 = ModelingToolkit. SymbolicContinuousCallback (
720
- [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1p); affect_neg = nothing )
720
+ [c1 ~ 0 ], (f = record_crossings, observed = (; v = c1), ctx = cr1p); affect_neg = nothing )
721
721
evt2 = ModelingToolkit. SymbolicContinuousCallback (
722
- [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2p);
723
- affect_neg = (record_crossings, [c2 => :v ], [], [], cr2n))
722
+ [c2 ~ 0 ], (f = record_crossings, observed = (; v = c2), ctx = cr2p);
723
+ affect_neg = (f = record_crossings, observed = (; v = c2), ctx = cr2n))
724
724
@named trigsys = System (eqs, t; continuous_events = [evt1, evt2])
725
725
trigsys_ss = structural_simplify (trigsys)
726
726
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
@@ -740,10 +740,10 @@ end
740
740
cr1 = []
741
741
cr2 = []
742
742
evt1 = ModelingToolkit. SymbolicContinuousCallback (
743
- [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1);
743
+ [c1 ~ 0 ], (f = record_crossings, observed = (; v = c1), ctx = cr1);
744
744
rootfind = SciMLBase. RightRootFind)
745
745
evt2 = ModelingToolkit. SymbolicContinuousCallback (
746
- [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2);
746
+ [c2 ~ 0 ], (f = record_crossings, observed = (; v = c2), ctx = cr2);
747
747
rootfind = SciMLBase. RightRootFind)
748
748
@named trigsys = System (eqs, t; continuous_events = [evt1, evt2])
749
749
trigsys_ss = structural_simplify (trigsys)
@@ -760,10 +760,10 @@ end
760
760
cr1 = []
761
761
cr2 = []
762
762
evt1 = ModelingToolkit. SymbolicContinuousCallback (
763
- [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1);
763
+ [c1 ~ 0 ], (f = record_crossings, observed = (; v = c1), ctx = cr1);
764
764
rootfind = SciMLBase. LeftRootFind)
765
765
evt2 = ModelingToolkit. SymbolicContinuousCallback (
766
- [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2);
766
+ [c2 ~ 0 ], (f = record_crossings, observed = (; v = c2), ctx = cr2);
767
767
rootfind = SciMLBase. RightRootFind)
768
768
@named trigsys = System (eqs, t; continuous_events = [evt1, evt2])
769
769
trigsys_ss = structural_simplify (trigsys)
@@ -778,10 +778,10 @@ end
778
778
cr1 = []
779
779
cr2 = []
780
780
evt1 = ModelingToolkit. SymbolicContinuousCallback (
781
- [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1);
781
+ [c1 ~ 0 ], (f = record_crossings, observed = (; v = c1), ctx = cr1);
782
782
rootfind = SciMLBase. LeftRootFind)
783
783
evt2 = ModelingToolkit. SymbolicContinuousCallback (
784
- [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2);
784
+ [c2 ~ 0 ], (f = record_crossings, observed = (; v = c2), ctx = cr2);
785
785
rootfind = SciMLBase. RightRootFind)
786
786
@named trigsys = System (eqs, t; continuous_events = [evt2, evt1])
787
787
trigsys_ss = structural_simplify (trigsys)
@@ -879,10 +879,10 @@ end
879
879
@variables x (t)
880
880
@parameters a (t) b (t) c (t)
881
881
cb1 = SymbolicContinuousCallback ([x ~ 1.0 ] => [a ~ - Pre (a)], discrete_parameters = [a])
882
- function save_affect! (integ, u, p, ctx )
883
- integ . ps[p . b] = 5.0
882
+ function save_affect! (mod, obs, ctx, integ )
883
+ return (; b = 5.0 )
884
884
end
885
- cb2 = [x ~ 0.5 ] => (save_affect!, [], [b], [b], nothing )
885
+ cb2 = [x ~ 0.5 ] => (f = save_affect!, modified = (; b) )
886
886
cb3 = SymbolicDiscreteCallback (1.0 => [c ~ t], discrete_parameters = [c])
887
887
888
888
@mtkbuild sys = System (D (x) ~ cos (t), t, [x], [a, b, c];
@@ -1067,8 +1067,7 @@ end
1067
1067
@testset " Initialization" begin
1068
1068
@variables x (t)
1069
1069
seen = false
1070
- f = ModelingToolkit. FunctionalAffect (
1071
- f = (i, u, p, c) -> seen = true , sts = [], pars = [], discretes = [])
1070
+ f = ModelingToolkit. ImperativeAffect (f = (m, o, ctx, int) -> (seen = true ; return (;)))
1072
1071
cb1 = ModelingToolkit. SymbolicContinuousCallback (
1073
1072
[x ~ 0 ], nothing , initialize = [x ~ 1.5 ], finalize = f)
1074
1073
@mtkbuild sys = System (D (x) ~ - 1 , t, [x], []; continuous_events = [cb1])
@@ -1080,16 +1079,13 @@ end
1080
1079
1081
1080
@variables x (t)
1082
1081
seen = false
1083
- f = ModelingToolkit. FunctionalAffect (
1084
- f = (i, u, p, c) -> seen = true , sts = [], pars = [], discretes = [])
1082
+ f = ModelingToolkit. ImperativeAffect (f = (m, o, ctx, int) -> (seen = true ; return (;)))
1085
1083
cb1 = ModelingToolkit. SymbolicContinuousCallback (
1086
1084
[x ~ 0 ], nothing , initialize = [x ~ 1.5 ], finalize = f)
1087
1085
inited = false
1088
1086
finaled = false
1089
- a = ModelingToolkit. FunctionalAffect (
1090
- f = (i, u, p, c) -> inited = true , sts = [], pars = [], discretes = [])
1091
- b = ModelingToolkit. FunctionalAffect (
1092
- f = (i, u, p, c) -> finaled = true , sts = [], pars = [], discretes = [])
1087
+ a = ModelingToolkit. ImperativeAffect (f = (m, o, ctx, int) -> (inited = true ; return (;)))
1088
+ b = ModelingToolkit. ImperativeAffect (f = (m, o, ctx, int) -> (finaled = true ; return (;)))
1093
1089
cb2 = ModelingToolkit. SymbolicContinuousCallback (
1094
1090
[x ~ 0.1 ], nothing , initialize = a, finalize = b)
1095
1091
@mtkbuild sys = System (D (x) ~ - 1 , t, [x], []; continuous_events = [cb1, cb2])
0 commit comments