@@ -104,59 +104,59 @@ affect_neg = [x ~ 1]
104
104
@test e. rootfind == SciMLBase. LeftRootFind
105
105
106
106
# with only positive edge affect
107
-
108
- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= nothing )
107
+
108
+ e = SymbolicContinuousCallback (eqs[], affect, affect_neg = nothing )
109
109
@test e isa SymbolicContinuousCallback
110
110
@test isequal (e. eqs, eqs)
111
111
@test e. affect == affect
112
112
@test isnothing (e. affect_neg)
113
113
@test e. rootfind == SciMLBase. LeftRootFind
114
114
115
- e = SymbolicContinuousCallback (eqs, affect, affect_neg= nothing )
115
+ e = SymbolicContinuousCallback (eqs, affect, affect_neg = nothing )
116
116
@test e isa SymbolicContinuousCallback
117
117
@test isequal (e. eqs, eqs)
118
118
@test e. affect == affect
119
119
@test isnothing (e. affect_neg)
120
120
@test e. rootfind == SciMLBase. LeftRootFind
121
121
122
- e = SymbolicContinuousCallback (eqs, affect, affect_neg= nothing )
122
+ e = SymbolicContinuousCallback (eqs, affect, affect_neg = nothing )
123
123
@test e isa SymbolicContinuousCallback
124
124
@test isequal (e. eqs, eqs)
125
125
@test e. affect == affect
126
126
@test isnothing (e. affect_neg)
127
127
@test e. rootfind == SciMLBase. LeftRootFind
128
128
129
- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= nothing )
129
+ e = SymbolicContinuousCallback (eqs[], affect, affect_neg = nothing )
130
130
@test e isa SymbolicContinuousCallback
131
131
@test isequal (e. eqs, eqs)
132
132
@test e. affect == affect
133
133
@test isnothing (e. affect_neg)
134
134
@test e. rootfind == SciMLBase. LeftRootFind
135
-
135
+
136
136
# with explicit edge affects
137
-
138
- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= affect_neg)
137
+
138
+ e = SymbolicContinuousCallback (eqs[], affect, affect_neg = affect_neg)
139
139
@test e isa SymbolicContinuousCallback
140
140
@test isequal (e. eqs, eqs)
141
141
@test e. affect == affect
142
142
@test e. affect_neg == affect_neg
143
143
@test e. rootfind == SciMLBase. LeftRootFind
144
144
145
- e = SymbolicContinuousCallback (eqs, affect, affect_neg= affect_neg)
145
+ e = SymbolicContinuousCallback (eqs, affect, affect_neg = affect_neg)
146
146
@test e isa SymbolicContinuousCallback
147
147
@test isequal (e. eqs, eqs)
148
148
@test e. affect == affect
149
149
@test e. affect_neg == affect_neg
150
150
@test e. rootfind == SciMLBase. LeftRootFind
151
151
152
- e = SymbolicContinuousCallback (eqs, affect, affect_neg= affect_neg)
152
+ e = SymbolicContinuousCallback (eqs, affect, affect_neg = affect_neg)
153
153
@test e isa SymbolicContinuousCallback
154
154
@test isequal (e. eqs, eqs)
155
155
@test e. affect == affect
156
156
@test e. affect_neg == affect_neg
157
157
@test e. rootfind == SciMLBase. LeftRootFind
158
158
159
- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= affect_neg)
159
+ e = SymbolicContinuousCallback (eqs[], affect, affect_neg = affect_neg)
160
160
@test e isa SymbolicContinuousCallback
161
161
@test isequal (e. eqs, eqs)
162
162
@test e. affect == affect
@@ -165,21 +165,24 @@ affect_neg = [x ~ 1]
165
165
166
166
# with different root finding ops
167
167
168
- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= affect_neg, rootfind= SciMLBase. LeftRootFind)
168
+ e = SymbolicContinuousCallback (
169
+ eqs[], affect, affect_neg = affect_neg, rootfind = SciMLBase. LeftRootFind)
169
170
@test e isa SymbolicContinuousCallback
170
171
@test isequal (e. eqs, eqs)
171
172
@test e. affect == affect
172
173
@test e. affect_neg == affect_neg
173
174
@test e. rootfind == SciMLBase. LeftRootFind
174
175
175
- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= affect_neg, rootfind= SciMLBase. RightRootFind)
176
+ e = SymbolicContinuousCallback (
177
+ eqs[], affect, affect_neg = affect_neg, rootfind = SciMLBase. RightRootFind)
176
178
@test e isa SymbolicContinuousCallback
177
179
@test isequal (e. eqs, eqs)
178
180
@test e. affect == affect
179
181
@test e. affect_neg == affect_neg
180
182
@test e. rootfind == SciMLBase. RightRootFind
181
183
182
- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= affect_neg, rootfind= SciMLBase. NoRootFind)
184
+ e = SymbolicContinuousCallback (
185
+ eqs[], affect, affect_neg = affect_neg, rootfind = SciMLBase. NoRootFind)
183
186
@test e isa SymbolicContinuousCallback
184
187
@test isequal (e. eqs, eqs)
185
188
@test e. affect == affect
@@ -717,119 +720,147 @@ end
717
720
@testset " Additional SymbolicContinuousCallback options" begin
718
721
# baseline affect (pos + neg + left root find)
719
722
@variables c1 (t)= 1.0 c2 (t)= 1.0 # c1 = cos(t), c2 = cos(3t)
720
- eqs = [D (c1) ~ - sin (t); D (c2) ~ - 3 * sin (3 * t)]
723
+ eqs = [D (c1) ~ - sin (t); D (c2) ~ - 3 * sin (3 * t)]
721
724
record_crossings (i, u, _, c) = push! (c, i. t => i. u[u. v])
722
- cr1 = []; cr2 = []
723
- evt1 = ModelingToolkit. SymbolicContinuousCallback ([c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1))
724
- evt2 = ModelingToolkit. SymbolicContinuousCallback ([c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2))
725
+ cr1 = []
726
+ cr2 = []
727
+ evt1 = ModelingToolkit. SymbolicContinuousCallback (
728
+ [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1))
729
+ evt2 = ModelingToolkit. SymbolicContinuousCallback (
730
+ [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2))
725
731
@named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
726
732
trigsys_ss = structural_simplify (trigsys)
727
733
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
728
734
sol = solve (prob, Tsit5 ())
729
- required_crossings_c1 = [π/ 2 , 3 * π / 2 ]
730
- required_crossings_c2 = [π/ 6 , π/ 2 , 5 * π / 6 , 7 * π / 6 , 3 * π / 2 , 11 * π / 6 ]
735
+ required_crossings_c1 = [π / 2 , 3 * π / 2 ]
736
+ required_crossings_c2 = [π / 6 , π / 2 , 5 * π / 6 , 7 * π / 6 , 3 * π / 2 , 11 * π / 6 ]
731
737
@test maximum (abs .(first .(cr1) .- required_crossings_c1)) < 1e-4
732
738
@test maximum (abs .(first .(cr2) .- required_crossings_c2)) < 1e-4
733
739
@test sign .(cos .(required_crossings_c1 .- 1e-6 )) == sign .(last .(cr1))
734
- @test sign .(cos .(3 * (required_crossings_c2 .- 1e-6 ))) == sign .(last .(cr2))
740
+ @test sign .(cos .(3 * (required_crossings_c2 .- 1e-6 ))) == sign .(last .(cr2))
735
741
736
742
# with neg affect (pos * neg + left root find)
737
- cr1p = []; cr2p = []
738
- cr1n = []; cr2n = []
739
- evt1 = ModelingToolkit. SymbolicContinuousCallback ([c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1p); affect_neg = (record_crossings, [c1 => :v ], [], [], cr1n))
740
- evt2 = ModelingToolkit. SymbolicContinuousCallback ([c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2p); affect_neg = (record_crossings, [c2 => :v ], [], [], cr2n))
743
+ cr1p = []
744
+ cr2p = []
745
+ cr1n = []
746
+ cr2n = []
747
+ evt1 = ModelingToolkit. SymbolicContinuousCallback (
748
+ [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1p);
749
+ affect_neg = (record_crossings, [c1 => :v ], [], [], cr1n))
750
+ evt2 = ModelingToolkit. SymbolicContinuousCallback (
751
+ [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2p);
752
+ affect_neg = (record_crossings, [c2 => :v ], [], [], cr2n))
741
753
@named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
742
754
trigsys_ss = structural_simplify (trigsys)
743
755
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
744
756
sol = solve (prob, Tsit5 (); dtmax = 0.01 )
745
757
c1_pc = filter ((<= )(0 ) ∘ sin, required_crossings_c1)
746
758
c1_nc = filter ((>= )(0 ) ∘ sin, required_crossings_c1)
747
- c2_pc = filter (c -> - sin (3 c) > 0 , required_crossings_c2)
748
- c2_nc = filter (c -> - sin (3 c) < 0 , required_crossings_c2)
759
+ c2_pc = filter (c -> - sin (3 c) > 0 , required_crossings_c2)
760
+ c2_nc = filter (c -> - sin (3 c) < 0 , required_crossings_c2)
749
761
@test maximum (abs .(c1_pc .- first .(cr1p))) < 1e-5
750
762
@test maximum (abs .(c1_nc .- first .(cr1n))) < 1e-5
751
763
@test maximum (abs .(c2_pc .- first .(cr2p))) < 1e-5
752
764
@test maximum (abs .(c2_nc .- first .(cr2n))) < 1e-5
753
765
@test sign .(cos .(c1_pc .- 1e-6 )) == sign .(last .(cr1p))
754
766
@test sign .(cos .(c1_nc .- 1e-6 )) == sign .(last .(cr1n))
755
- @test sign .(cos .(3 * (c2_pc .- 1e-6 ))) == sign .(last .(cr2p))
756
- @test sign .(cos .(3 * (c2_nc .- 1e-6 ))) == sign .(last .(cr2n))
767
+ @test sign .(cos .(3 * (c2_pc .- 1e-6 ))) == sign .(last .(cr2p))
768
+ @test sign .(cos .(3 * (c2_nc .- 1e-6 ))) == sign .(last .(cr2n))
757
769
758
770
# with nothing neg affect (pos * neg + left root find)
759
- cr1p = []; cr2p = []
760
- evt1 = ModelingToolkit. SymbolicContinuousCallback ([c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1p); affect_neg = nothing )
761
- evt2 = ModelingToolkit. SymbolicContinuousCallback ([c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2p); affect_neg = nothing )
771
+ cr1p = []
772
+ cr2p = []
773
+ evt1 = ModelingToolkit. SymbolicContinuousCallback (
774
+ [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1p); affect_neg = nothing )
775
+ evt2 = ModelingToolkit. SymbolicContinuousCallback (
776
+ [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2p); affect_neg = nothing )
762
777
@named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
763
778
trigsys_ss = structural_simplify (trigsys)
764
779
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
765
780
sol = solve (prob, Tsit5 (); dtmax = 0.01 )
766
781
@test maximum (abs .(c1_pc .- first .(cr1p))) < 1e-5
767
782
@test maximum (abs .(c2_pc .- first .(cr2p))) < 1e-5
768
783
@test sign .(cos .(c1_pc .- 1e-6 )) == sign .(last .(cr1p))
769
- @test sign .(cos .(3 * (c2_pc .- 1e-6 ))) == sign .(last .(cr2p))
770
-
784
+ @test sign .(cos .(3 * (c2_pc .- 1e-6 ))) == sign .(last .(cr2p))
771
785
772
786
# mixed
773
- cr1p = []; cr2p = []
774
- cr1n = []; cr2n = []
775
- evt1 = ModelingToolkit. SymbolicContinuousCallback ([c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1p); affect_neg = nothing )
776
- evt2 = ModelingToolkit. SymbolicContinuousCallback ([c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2p); affect_neg = (record_crossings, [c2 => :v ], [], [], cr2n))
787
+ cr1p = []
788
+ cr2p = []
789
+ cr1n = []
790
+ cr2n = []
791
+ evt1 = ModelingToolkit. SymbolicContinuousCallback (
792
+ [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1p); affect_neg = nothing )
793
+ evt2 = ModelingToolkit. SymbolicContinuousCallback (
794
+ [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2p);
795
+ affect_neg = (record_crossings, [c2 => :v ], [], [], cr2n))
777
796
@named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
778
797
trigsys_ss = structural_simplify (trigsys)
779
798
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
780
799
sol = solve (prob, Tsit5 (); dtmax = 0.01 )
781
800
c1_pc = filter ((<= )(0 ) ∘ sin, required_crossings_c1)
782
- c2_pc = filter (c -> - sin (3 c) > 0 , required_crossings_c2)
783
- c2_nc = filter (c -> - sin (3 c) < 0 , required_crossings_c2)
801
+ c2_pc = filter (c -> - sin (3 c) > 0 , required_crossings_c2)
802
+ c2_nc = filter (c -> - sin (3 c) < 0 , required_crossings_c2)
784
803
@test maximum (abs .(c1_pc .- first .(cr1p))) < 1e-5
785
804
@test maximum (abs .(c2_pc .- first .(cr2p))) < 1e-5
786
805
@test maximum (abs .(c2_nc .- first .(cr2n))) < 1e-5
787
806
@test sign .(cos .(c1_pc .- 1e-6 )) == sign .(last .(cr1p))
788
- @test sign .(cos .(3 * (c2_pc .- 1e-6 ))) == sign .(last .(cr2p))
789
- @test sign .(cos .(3 * (c2_nc .- 1e-6 ))) == sign .(last .(cr2n))
790
-
807
+ @test sign .(cos .(3 * (c2_pc .- 1e-6 ))) == sign .(last .(cr2p))
808
+ @test sign .(cos .(3 * (c2_nc .- 1e-6 ))) == sign .(last .(cr2n))
791
809
792
810
# baseline affect w/ right rootfind (pos + neg + right root find)
793
811
@variables c1 (t)= 1.0 c2 (t)= 1.0 # c1 = cos(t), c2 = cos(3t)
794
- cr1 = []; cr2 = []
795
- evt1 = ModelingToolkit. SymbolicContinuousCallback ([c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1); rootfind= SciMLBase. RightRootFind)
796
- evt2 = ModelingToolkit. SymbolicContinuousCallback ([c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2); rootfind= SciMLBase. RightRootFind)
812
+ cr1 = []
813
+ cr2 = []
814
+ evt1 = ModelingToolkit. SymbolicContinuousCallback (
815
+ [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1);
816
+ rootfind = SciMLBase. RightRootFind)
817
+ evt2 = ModelingToolkit. SymbolicContinuousCallback (
818
+ [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2);
819
+ rootfind = SciMLBase. RightRootFind)
797
820
@named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
798
821
trigsys_ss = structural_simplify (trigsys)
799
822
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
800
823
sol = solve (prob, Tsit5 ())
801
- required_crossings_c1 = [π/ 2 , 3 * π / 2 ]
802
- required_crossings_c2 = [π/ 6 , π/ 2 , 5 * π / 6 , 7 * π / 6 , 3 * π / 2 , 11 * π / 6 ]
824
+ required_crossings_c1 = [π / 2 , 3 * π / 2 ]
825
+ required_crossings_c2 = [π / 6 , π / 2 , 5 * π / 6 , 7 * π / 6 , 3 * π / 2 , 11 * π / 6 ]
803
826
@test maximum (abs .(first .(cr1) .- required_crossings_c1)) < 1e-4
804
827
@test maximum (abs .(first .(cr2) .- required_crossings_c2)) < 1e-4
805
828
@test sign .(cos .(required_crossings_c1 .+ 1e-6 )) == sign .(last .(cr1))
806
- @test sign .(cos .(3 * (required_crossings_c2 .+ 1e-6 ))) == sign .(last .(cr2))
807
-
808
-
829
+ @test sign .(cos .(3 * (required_crossings_c2 .+ 1e-6 ))) == sign .(last .(cr2))
809
830
810
831
# baseline affect w/ mixed rootfind (pos + neg + right root find)
811
- cr1 = []; cr2 = []
812
- evt1 = ModelingToolkit. SymbolicContinuousCallback ([c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1); rootfind= SciMLBase. LeftRootFind)
813
- evt2 = ModelingToolkit. SymbolicContinuousCallback ([c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2); rootfind= SciMLBase. RightRootFind)
832
+ cr1 = []
833
+ cr2 = []
834
+ evt1 = ModelingToolkit. SymbolicContinuousCallback (
835
+ [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1);
836
+ rootfind = SciMLBase. LeftRootFind)
837
+ evt2 = ModelingToolkit. SymbolicContinuousCallback (
838
+ [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2);
839
+ rootfind = SciMLBase. RightRootFind)
814
840
@named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
815
841
trigsys_ss = structural_simplify (trigsys)
816
842
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
817
843
sol = solve (prob, Tsit5 ())
818
844
@test maximum (abs .(first .(cr1) .- required_crossings_c1)) < 1e-4
819
845
@test maximum (abs .(first .(cr2) .- required_crossings_c2)) < 1e-4
820
846
@test sign .(cos .(required_crossings_c1 .- 1e-6 )) == sign .(last .(cr1))
821
- @test sign .(cos .(3 * (required_crossings_c2 .+ 1e-6 ))) == sign .(last .(cr2))
847
+ @test sign .(cos .(3 * (required_crossings_c2 .+ 1e-6 ))) == sign .(last .(cr2))
822
848
823
849
# flip order and ensure results are okay
824
- cr1 = []; cr2 = []
825
- evt1 = ModelingToolkit. SymbolicContinuousCallback ([c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1); rootfind= SciMLBase. LeftRootFind)
826
- evt2 = ModelingToolkit. SymbolicContinuousCallback ([c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2); rootfind= SciMLBase. RightRootFind)
850
+ cr1 = []
851
+ cr2 = []
852
+ evt1 = ModelingToolkit. SymbolicContinuousCallback (
853
+ [c1 ~ 0 ], (record_crossings, [c1 => :v ], [], [], cr1);
854
+ rootfind = SciMLBase. LeftRootFind)
855
+ evt2 = ModelingToolkit. SymbolicContinuousCallback (
856
+ [c2 ~ 0 ], (record_crossings, [c2 => :v ], [], [], cr2);
857
+ rootfind = SciMLBase. RightRootFind)
827
858
@named trigsys = ODESystem (eqs, t; continuous_events = [evt2, evt1])
828
859
trigsys_ss = structural_simplify (trigsys)
829
860
prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
830
861
sol = solve (prob, Tsit5 ())
831
862
@test maximum (abs .(first .(cr1) .- required_crossings_c1)) < 1e-4
832
863
@test maximum (abs .(first .(cr2) .- required_crossings_c2)) < 1e-4
833
864
@test sign .(cos .(required_crossings_c1 .- 1e-6 )) == sign .(last .(cr1))
834
- @test sign .(cos .(3 * (required_crossings_c2 .+ 1e-6 ))) == sign .(last .(cr2))
835
- end
865
+ @test sign .(cos .(3 * (required_crossings_c2 .+ 1e-6 ))) == sign .(last .(cr2))
866
+ end
0 commit comments