@@ -104,59 +104,59 @@ affect_neg = [x ~ 1]
104104 @test e. rootfind == SciMLBase. LeftRootFind
105105
106106 # with only positive edge affect
107-
108- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= nothing )
107+
108+ e = SymbolicContinuousCallback (eqs[], affect, affect_neg = nothing )
109109 @test e isa SymbolicContinuousCallback
110110 @test isequal (e. eqs, eqs)
111111 @test e. affect == affect
112112 @test isnothing (e. affect_neg)
113113 @test e. rootfind == SciMLBase. LeftRootFind
114114
115- e = SymbolicContinuousCallback (eqs, affect, affect_neg= nothing )
115+ e = SymbolicContinuousCallback (eqs, affect, affect_neg = nothing )
116116 @test e isa SymbolicContinuousCallback
117117 @test isequal (e. eqs, eqs)
118118 @test e. affect == affect
119119 @test isnothing (e. affect_neg)
120120 @test e. rootfind == SciMLBase. LeftRootFind
121121
122- e = SymbolicContinuousCallback (eqs, affect, affect_neg= nothing )
122+ e = SymbolicContinuousCallback (eqs, affect, affect_neg = nothing )
123123 @test e isa SymbolicContinuousCallback
124124 @test isequal (e. eqs, eqs)
125125 @test e. affect == affect
126126 @test isnothing (e. affect_neg)
127127 @test e. rootfind == SciMLBase. LeftRootFind
128128
129- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= nothing )
129+ e = SymbolicContinuousCallback (eqs[], affect, affect_neg = nothing )
130130 @test e isa SymbolicContinuousCallback
131131 @test isequal (e. eqs, eqs)
132132 @test e. affect == affect
133133 @test isnothing (e. affect_neg)
134134 @test e. rootfind == SciMLBase. LeftRootFind
135-
135+
136136 # with explicit edge affects
137-
138- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= affect_neg)
137+
138+ e = SymbolicContinuousCallback (eqs[], affect, affect_neg = affect_neg)
139139 @test e isa SymbolicContinuousCallback
140140 @test isequal (e. eqs, eqs)
141141 @test e. affect == affect
142142 @test e. affect_neg == affect_neg
143143 @test e. rootfind == SciMLBase. LeftRootFind
144144
145- e = SymbolicContinuousCallback (eqs, affect, affect_neg= affect_neg)
145+ e = SymbolicContinuousCallback (eqs, affect, affect_neg = affect_neg)
146146 @test e isa SymbolicContinuousCallback
147147 @test isequal (e. eqs, eqs)
148148 @test e. affect == affect
149149 @test e. affect_neg == affect_neg
150150 @test e. rootfind == SciMLBase. LeftRootFind
151151
152- e = SymbolicContinuousCallback (eqs, affect, affect_neg= affect_neg)
152+ e = SymbolicContinuousCallback (eqs, affect, affect_neg = affect_neg)
153153 @test e isa SymbolicContinuousCallback
154154 @test isequal (e. eqs, eqs)
155155 @test e. affect == affect
156156 @test e. affect_neg == affect_neg
157157 @test e. rootfind == SciMLBase. LeftRootFind
158158
159- e = SymbolicContinuousCallback (eqs[], affect, affect_neg= affect_neg)
159+ e = SymbolicContinuousCallback (eqs[], affect, affect_neg = affect_neg)
160160 @test e isa SymbolicContinuousCallback
161161 @test isequal (e. eqs, eqs)
162162 @test e. affect == affect
@@ -165,21 +165,24 @@ affect_neg = [x ~ 1]
165165
166166 # with different root finding ops
167167
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)
169170 @test e isa SymbolicContinuousCallback
170171 @test isequal (e. eqs, eqs)
171172 @test e. affect == affect
172173 @test e. affect_neg == affect_neg
173174 @test e. rootfind == SciMLBase. LeftRootFind
174175
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)
176178 @test e isa SymbolicContinuousCallback
177179 @test isequal (e. eqs, eqs)
178180 @test e. affect == affect
179181 @test e. affect_neg == affect_neg
180182 @test e. rootfind == SciMLBase. RightRootFind
181183
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)
183186 @test e isa SymbolicContinuousCallback
184187 @test isequal (e. eqs, eqs)
185188 @test e. affect == affect
@@ -717,119 +720,147 @@ end
717720@testset " Additional SymbolicContinuousCallback options" begin
718721 # baseline affect (pos + neg + left root find)
719722 @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)]
721724 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))
725731 @named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
726732 trigsys_ss = structural_simplify (trigsys)
727733 prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
728734 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 ]
731737 @test maximum (abs .(first .(cr1) .- required_crossings_c1)) < 1e-4
732738 @test maximum (abs .(first .(cr2) .- required_crossings_c2)) < 1e-4
733739 @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))
735741
736742 # 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))
741753 @named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
742754 trigsys_ss = structural_simplify (trigsys)
743755 prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
744756 sol = solve (prob, Tsit5 (); dtmax = 0.01 )
745757 c1_pc = filter ((<= )(0 ) ∘ sin, required_crossings_c1)
746758 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)
749761 @test maximum (abs .(c1_pc .- first .(cr1p))) < 1e-5
750762 @test maximum (abs .(c1_nc .- first .(cr1n))) < 1e-5
751763 @test maximum (abs .(c2_pc .- first .(cr2p))) < 1e-5
752764 @test maximum (abs .(c2_nc .- first .(cr2n))) < 1e-5
753765 @test sign .(cos .(c1_pc .- 1e-6 )) == sign .(last .(cr1p))
754766 @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))
757769
758770 # 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 )
762777 @named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
763778 trigsys_ss = structural_simplify (trigsys)
764779 prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
765780 sol = solve (prob, Tsit5 (); dtmax = 0.01 )
766781 @test maximum (abs .(c1_pc .- first .(cr1p))) < 1e-5
767782 @test maximum (abs .(c2_pc .- first .(cr2p))) < 1e-5
768783 @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))
771785
772786 # 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))
777796 @named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
778797 trigsys_ss = structural_simplify (trigsys)
779798 prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
780799 sol = solve (prob, Tsit5 (); dtmax = 0.01 )
781800 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)
784803 @test maximum (abs .(c1_pc .- first .(cr1p))) < 1e-5
785804 @test maximum (abs .(c2_pc .- first .(cr2p))) < 1e-5
786805 @test maximum (abs .(c2_nc .- first .(cr2n))) < 1e-5
787806 @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))
791809
792810 # baseline affect w/ right rootfind (pos + neg + right root find)
793811 @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)
797820 @named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
798821 trigsys_ss = structural_simplify (trigsys)
799822 prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
800823 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 ]
803826 @test maximum (abs .(first .(cr1) .- required_crossings_c1)) < 1e-4
804827 @test maximum (abs .(first .(cr2) .- required_crossings_c2)) < 1e-4
805828 @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))
809830
810831 # 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)
814840 @named trigsys = ODESystem (eqs, t; continuous_events = [evt1, evt2])
815841 trigsys_ss = structural_simplify (trigsys)
816842 prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
817843 sol = solve (prob, Tsit5 ())
818844 @test maximum (abs .(first .(cr1) .- required_crossings_c1)) < 1e-4
819845 @test maximum (abs .(first .(cr2) .- required_crossings_c2)) < 1e-4
820846 @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))
822848
823849 # 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)
827858 @named trigsys = ODESystem (eqs, t; continuous_events = [evt2, evt1])
828859 trigsys_ss = structural_simplify (trigsys)
829860 prob = ODEProblem (trigsys_ss, [], (0.0 , 2 π))
830861 sol = solve (prob, Tsit5 ())
831862 @test maximum (abs .(first .(cr1) .- required_crossings_c1)) < 1e-4
832863 @test maximum (abs .(first .(cr2) .- required_crossings_c2)) < 1e-4
833864 @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