@@ -71,7 +71,7 @@ Contains a single callback whose `condition` is a continuous function. The callb
71
71
if the starting condition is less than the tolerance from zero, then no root will be detected.
72
72
This is to stop repeat events happening just after a previously rootfound event.
73
73
"""
74
- struct ContinuousCallback{F1,F2,F3,F4,T,T2,I} <: AbstractContinuousCallback
74
+ struct ContinuousCallback{F1,F2,F3,F4,T,T2,I,R } <: AbstractContinuousCallback
75
75
condition:: F1
76
76
affect!:: F2
77
77
affect_neg!:: F3
@@ -80,16 +80,17 @@ struct ContinuousCallback{F1,F2,F3,F4,T,T2,I} <: AbstractContinuousCallback
80
80
rootfind:: Bool
81
81
interp_points:: Int
82
82
save_positions:: BitArray{1}
83
+ dtrelax:: R
83
84
abstol:: T
84
85
reltol:: T2
85
86
ContinuousCallback (condition:: F1 ,affect!:: F2 ,affect_neg!:: F3 ,
86
87
initialize:: F4 ,idxs:: I ,rootfind,
87
- interp_points,save_positions,abstol:: T ,reltol:: T2 ) where {F1,F2,F3,F4,T,T2,I} =
88
- new {F1,F2,F3,F4,T,T2,I} (condition,
88
+ interp_points,save_positions,dtrelax :: R , abstol:: T ,reltol:: T2 ) where {F1,F2,F3,F4,T,T2,I,R } =
89
+ new {F1,F2,F3,F4,T,T2,I,R } (condition,
89
90
affect!,affect_neg!,
90
91
initialize,idxs,rootfind,interp_points,
91
92
BitArray (collect (save_positions)),
92
- abstol,reltol)
93
+ dtrelax, abstol,reltol)
93
94
end
94
95
95
96
ContinuousCallback (condition,affect!,affect_neg!;
@@ -98,11 +99,13 @@ ContinuousCallback(condition,affect!,affect_neg!;
98
99
rootfind= true ,
99
100
save_positions= (true ,true ),
100
101
interp_points= 10 ,
102
+ dtrelax= 1 ,
101
103
abstol= 10 eps (),reltol= 0 ) = ContinuousCallback (
102
104
condition,affect!,affect_neg!,initialize,
103
105
idxs,
104
106
rootfind,interp_points,
105
- save_positions,abstol,reltol)
107
+ save_positions,
108
+ dtrelax,abstol,reltol)
106
109
107
110
function ContinuousCallback (condition,affect!;
108
111
initialize = INITIALIZE_DEFAULT,
@@ -111,12 +114,14 @@ function ContinuousCallback(condition,affect!;
111
114
save_positions= (true ,true ),
112
115
affect_neg! = affect!,
113
116
interp_points= 10 ,
117
+ dtrelax= 1 ,
114
118
abstol= 10 eps (),reltol= 0 )
115
119
116
120
ContinuousCallback (
117
121
condition,affect!,affect_neg!,initialize,idxs,
118
122
rootfind,interp_points,
119
- collect (save_positions),abstol,reltol)
123
+ collect (save_positions),
124
+ dtrelax,abstol,reltol)
120
125
121
126
end
122
127
@@ -157,7 +162,7 @@ multiple events.
157
162
158
163
Rest of the arguments have the same meaning as in [`ContinuousCallback`](@ref).
159
164
"""
160
- struct VectorContinuousCallback{F1,F2,F3,F4,T,T2,I} <: AbstractContinuousCallback
165
+ struct VectorContinuousCallback{F1,F2,F3,F4,T,T2,I,R } <: AbstractContinuousCallback
161
166
condition:: F1
162
167
affect!:: F2
163
168
affect_neg!:: F3
@@ -167,17 +172,18 @@ struct VectorContinuousCallback{F1,F2,F3,F4,T,T2,I} <: AbstractContinuousCallbac
167
172
rootfind:: Bool
168
173
interp_points:: Int
169
174
save_positions:: BitArray{1}
175
+ dtrelax:: R
170
176
abstol:: T
171
177
reltol:: T2
172
178
VectorContinuousCallback (condition:: F1 ,affect!:: F2 ,affect_neg!:: F3 ,len:: Int ,
173
179
initialize:: F4 ,idxs:: I ,rootfind,
174
- interp_points,save_positions,
175
- abstol:: T ,reltol:: T2 ) where {F1,F2,F3,F4,T,T2,I} =
176
- new {F1,F2,F3,F4,T,T2,I} (condition,
180
+ interp_points,save_positions,dtrelax :: R ,
181
+ abstol:: T ,reltol:: T2 ) where {F1,F2,F3,F4,T,T2,I,R } =
182
+ new {F1,F2,F3,F4,T,T2,I,R } (condition,
177
183
affect!,affect_neg!,len,
178
184
initialize,idxs,rootfind,interp_points,
179
185
BitArray (collect (save_positions)),
180
- abstol,reltol)
186
+ dtrelax, abstol,reltol)
181
187
end
182
188
183
189
VectorContinuousCallback (condition,affect!,affect_neg!,len;
@@ -186,12 +192,14 @@ VectorContinuousCallback(condition,affect!,affect_neg!,len;
186
192
rootfind= true ,
187
193
save_positions= (true ,true ),
188
194
interp_points= 10 ,
195
+ dtrelax= 1 ,
189
196
abstol= 10 eps (),reltol= 0 ) = VectorContinuousCallback (
190
197
condition,affect!,affect_neg!,len,
191
198
initialize,
192
199
idxs,
193
200
rootfind,interp_points,
194
- save_positions,abstol,reltol)
201
+ save_positions,dtrelax,
202
+ abstol,reltol)
195
203
196
204
function VectorContinuousCallback (condition,affect!,len;
197
205
initialize = INITIALIZE_DEFAULT,
@@ -200,12 +208,14 @@ function VectorContinuousCallback(condition,affect!,len;
200
208
save_positions= (true ,true ),
201
209
affect_neg! = affect!,
202
210
interp_points= 10 ,
211
+ dtrelax= 1 ,
203
212
abstol= 10 eps (),reltol= 0 )
204
213
205
214
VectorContinuousCallback (
206
215
condition,affect!,affect_neg!,len,initialize,idxs,
207
216
rootfind,interp_points,
208
- collect (save_positions),abstol,reltol)
217
+ collect (save_positions),
218
+ dtrelax,abstol,reltol)
209
219
210
220
end
211
221
@@ -633,7 +643,7 @@ function find_callback_time(integrator,callback::ContinuousCallback,counter)
633
643
Θ = top_t
634
644
else
635
645
if integrator. event_last_time == counter &&
636
- abs (zero_func (bottom_t)) < 100 abs (integrator. last_event_error) &&
646
+ abs (zero_func (bottom_t)) <= 100 abs (integrator. last_event_error) &&
637
647
prev_sign_index == 1
638
648
639
649
# Determined that there is an event by derivative
@@ -700,7 +710,7 @@ function find_callback_time(integrator,callback::VectorContinuousCallback,counte
700
710
else
701
711
if integrator. event_last_time == counter &&
702
712
integrator. vector_event_last_time == event_idx &&
703
- abs (zero_func (bottom_t)) < 100 abs (integrator. last_event_error) &&
713
+ abs (zero_func (bottom_t)) <= 100 abs (integrator. last_event_error) &&
704
714
prev_sign_index == 1
705
715
706
716
# Determined that there is an event by derivative
@@ -754,11 +764,13 @@ function find_callback_time(integrator,callback::VectorContinuousCallback,counte
754
764
end
755
765
756
766
function apply_callback! (integrator,callback:: Union{ContinuousCallback,VectorContinuousCallback} ,cb_time,prev_sign,event_idx)
757
- if cb_time == zero (typeof (integrator. t))
758
- error (" Event repeated at the same time. Please report this error" )
759
- end
767
+
760
768
change_t_via_interpolation! (integrator,integrator. tprev+ cb_time)
761
769
770
+ if integrator. opts. adaptive
771
+ set_proposed_dt! (integrator, max (integrator. opts. dtmin+ eps (integrator. dt), callback. dtrelax * integrator. dt))
772
+ end
773
+
762
774
# handle saveat
763
775
_, savedexactly = savevalues! (integrator)
764
776
saved_in_cb = true
0 commit comments