Skip to content

Commit 65eacb8

Browse files
committed
Use successful step in trajectory
1 parent 0c49c6d commit 65eacb8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicalSystemsBase"
22
uuid = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
33
repo = "https://github.com/JuliaDynamics/DynamicalSystemsBase.jl.git"
4-
version = "3.1.1"
4+
version = "3.1.2"
55

66
[deps]
77
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

src/core/trajectory.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ function trajectory_discrete(ds, T; Δt::Integer = 1, Ttr::Integer = 0, accessor
4343
for i in 2:L
4444
step!(ds, Δt)
4545
data[i] = SVector{X, ET}(obtain_access(current_state(ds), accessor))
46+
if !successful_step(ds)
47+
# Diverged trajectory; set final state to remaining set
48+
# and exit iteration early
49+
for j in (i+1):L
50+
data[j] = data[i]
51+
end
52+
break
53+
end
4654
end
4755
return StateSpaceSet(data), tvec
4856
end
@@ -60,6 +68,15 @@ function trajectory_continuous(ds, T; Δt = 0.1, Ttr = 0.0, accessor = nothing)
6068
step!(ds)
6169
end
6270
sol[i] = SVector{X, ET}(obtain_access(ds(t), accessor))
71+
if !successful_step(ds)
72+
# Diverged trajectory; set final state to remaining set
73+
# and exit iteration early
74+
for j in (i+1):length(tvec)
75+
sol[j] = sol[i]
76+
end
77+
break
78+
end
79+
6380
end
6481
return StateSpaceSet(sol), tvec
6582
end

0 commit comments

Comments
 (0)