@@ -33,7 +33,7 @@ https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/
33
33
[the return code documentation](https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes).
34
34
"""
35
35
struct RODESolution{T, N, uType, uType2, DType, tType, randType, P, A, IType, S,
36
- AC <: Union{Nothing, Vector{Int}} } < :
36
+ AC <: Union{Nothing, Vector{Int}} , V } < :
37
37
AbstractRODESolution{T, N, uType}
38
38
u:: uType
39
39
u_analytic:: uType2
@@ -49,6 +49,7 @@ struct RODESolution{T, N, uType, uType2, DType, tType, randType, P, A, IType, S,
49
49
alg_choice:: AC
50
50
retcode:: ReturnCode.T
51
51
seed:: UInt64
52
+ saved_subsystem:: V
52
53
end
53
54
54
55
function ConstructionBase. constructorof (:: Type{O} ) where {T, N, O <: RODESolution{T, N} }
@@ -63,10 +64,10 @@ function ConstructionBase.setproperties(sol::RODESolution, patch::NamedTuple)
63
64
return RODESolution{
64
65
T, N, typeof (patch. u), typeof (patch. u_analytic), typeof (patch. errors),
65
66
typeof (patch. t), typeof (patch. W), typeof (patch. prob), typeof (patch. alg), typeof (patch. interp),
66
- typeof (patch. stats), typeof (patch. alg_choice)}(
67
+ typeof (patch. stats), typeof (patch. alg_choice), typeof (patch . saved_subsystem) }(
67
68
patch. u, patch. u_analytic, patch. errors, patch. t, patch. W,
68
69
patch. prob, patch. alg, patch. interp, patch. dense, patch. tslocation, patch. stats,
69
- patch. alg_choice, patch. retcode, patch. seed)
70
+ patch. alg_choice, patch. retcode, patch. seed, patch . saved_subsystem )
70
71
end
71
72
72
73
Base. @propagate_inbounds function Base. getproperty (x:: AbstractRODESolution , s:: Symbol )
@@ -94,9 +95,14 @@ function build_solution(prob::Union{AbstractRODEProblem, AbstractSDDEProblem},
94
95
interp = LinearInterpolation (t, u),
95
96
retcode = ReturnCode. Default,
96
97
alg_choice = nothing ,
97
- seed = UInt64 (0 ), destats = missing , stats = nothing , kwargs... )
98
+ seed = UInt64 (0 ), destats = missing , stats = nothing ,
99
+ saved_subsystem = nothing , kwargs... )
98
100
T = eltype (eltype (u))
99
- N = length ((size (prob. u0)... , length (u)))
101
+ if prob. u0 === nothing
102
+ N = 2
103
+ else
104
+ N = ndims (eltype (u)) + 1
105
+ end
100
106
101
107
if prob. f isa Tuple
102
108
f = prob. f[1 ]
@@ -120,7 +126,7 @@ function build_solution(prob::Union{AbstractRODEProblem, AbstractSDDEProblem},
120
126
sol = RODESolution{T, N, typeof (u), typeof (u_analytic), typeof (errors), typeof (t),
121
127
typeof (W),
122
128
typeof (prob), typeof (alg), typeof (interp), typeof (stats),
123
- typeof (alg_choice)}(u,
129
+ typeof (alg_choice), typeof (saved_subsystem) }(u,
124
130
u_analytic,
125
131
errors,
126
132
t, W,
@@ -132,7 +138,8 @@ function build_solution(prob::Union{AbstractRODEProblem, AbstractSDDEProblem},
132
138
stats,
133
139
alg_choice,
134
140
retcode,
135
- seed)
141
+ seed,
142
+ saved_subsystem)
136
143
137
144
if calculate_error
138
145
calculate_solution_errors! (sol; timeseries_errors = timeseries_errors,
@@ -143,10 +150,11 @@ function build_solution(prob::Union{AbstractRODEProblem, AbstractSDDEProblem},
143
150
else
144
151
return RODESolution{T, N, typeof (u), Nothing, Nothing, typeof (t),
145
152
typeof (W), typeof (prob), typeof (alg), typeof (interp),
146
- typeof (stats), typeof (alg_choice)}(u, nothing , nothing , t, W,
153
+ typeof (stats), typeof (alg_choice), typeof (saved_subsystem)}(
154
+ u, nothing , nothing , t, W,
147
155
prob, alg, interp,
148
156
dense, 0 , stats,
149
- alg_choice, retcode, seed)
157
+ alg_choice, retcode, seed, saved_subsystem )
150
158
end
151
159
end
152
160
@@ -197,54 +205,24 @@ function calculate_solution_errors!(sol::AbstractRODESolution; fill_uanalytic =
197
205
end
198
206
end
199
207
200
- function build_solution (sol:: AbstractRODESolution{T, N} , u_analytic, errors) where {T, N}
201
- RODESolution{T, N, typeof (sol. u), typeof (u_analytic), typeof (errors), typeof (sol. t),
202
- typeof (sol. W), typeof (sol. prob), typeof (sol. alg), typeof (sol. interp),
203
- typeof (sol. stats), typeof (sol. alg_choice)}(sol. u, u_analytic, errors,
204
- sol. t, sol. W, sol. prob,
205
- sol. alg, sol. interp,
206
- sol. dense, sol. tslocation,
207
- sol. stats, sol. alg_choice,
208
- sol. retcode, sol. seed)
208
+ function build_solution (sol:: AbstractRODESolution , u_analytic, errors)
209
+ @reset sol. u_analytic = u_analytic
210
+ return @set sol. errors = errors
209
211
end
210
212
211
- function solution_new_retcode (sol:: AbstractRODESolution{T, N} , retcode) where {T, N}
212
- RODESolution{T, N, typeof (sol. u), typeof (sol. u_analytic), typeof (sol. errors),
213
- typeof (sol. t),
214
- typeof (sol. W), typeof (sol. prob), typeof (sol. alg), typeof (sol. interp),
215
- typeof (sol. stats), typeof (sol. alg_choice)}(sol. u, sol. u_analytic,
216
- sol. errors, sol. t, sol. W,
217
- sol. prob, sol. alg, sol. interp,
218
- sol. dense, sol. tslocation,
219
- sol. stats, sol. alg_choice,
220
- retcode, sol. seed)
213
+ function solution_new_retcode (sol:: AbstractRODESolution , retcode)
214
+ return @set sol. retcode = retcode
221
215
end
222
216
223
- function solution_new_tslocation (sol:: AbstractRODESolution{T, N} , tslocation) where {T, N}
224
- RODESolution{T, N, typeof (sol. u), typeof (sol. u_analytic), typeof (sol. errors),
225
- typeof (sol. t),
226
- typeof (sol. W), typeof (sol. prob), typeof (sol. alg), typeof (sol. interp),
227
- typeof (sol. stats), typeof (sol. alg_choice)}(sol. u, sol. u_analytic,
228
- sol. errors, sol. t, sol. W,
229
- sol. prob, sol. alg, sol. interp,
230
- sol. dense, tslocation,
231
- sol. stats, sol. alg_choice,
232
- sol. retcode, sol. seed)
217
+ function solution_new_tslocation (sol:: AbstractRODESolution , tslocation)
218
+ return @set sol. tslocation = tslocation
233
219
end
234
220
235
221
function solution_slice (sol:: AbstractRODESolution{T, N} , I) where {T, N}
236
- RODESolution{T, N, typeof (sol. u), typeof (sol. u_analytic), typeof (sol. errors),
237
- typeof (sol. t),
238
- typeof (sol. W), typeof (sol. prob), typeof (sol. alg), typeof (sol. interp),
239
- typeof (sol. stats), typeof (sol. alg_choice)}(sol. u[I],
240
- sol. u_analytic === nothing ?
241
- nothing : sol. u_analytic,
242
- sol. errors, sol. t[I],
243
- sol. W, sol. prob,
244
- sol. alg, sol. interp,
245
- false , sol. tslocation,
246
- sol. stats, sol. alg_choice,
247
- sol. retcode, sol. seed)
222
+ @reset sol. u = sol. u[I]
223
+ @reset sol. u_analytic = sol. u_analytic === nothing ? nothing : sol. u_analytic[I]
224
+ @reset sol. t = sol. t[I]
225
+ return @set sol. dense = false
248
226
end
249
227
250
228
function sensitivity_solution (sol:: AbstractRODESolution , u, t)
@@ -259,22 +237,7 @@ function sensitivity_solution(sol::AbstractRODESolution, u, t)
259
237
end
260
238
261
239
interp = enable_interpolation_sensitivitymode (sol. interp)
262
-
263
- RODESolution{T, N, typeof (u), typeof (sol. u_analytic),
264
- typeof (sol. errors), typeof (t),
265
- typeof (nothing ), typeof (sol. prob), typeof (sol. alg),
266
- typeof (sol. interp), typeof (sol. stats), typeof (sol. alg_choice)}(u,
267
- sol. u_analytic,
268
- sol. errors,
269
- t,
270
- nothing ,
271
- sol. prob,
272
- sol. alg,
273
- sol. interp,
274
- sol. dense,
275
- sol. tslocation,
276
- sol. stats,
277
- sol. alg_choice,
278
- sol. retcode,
279
- sol. seed)
240
+ @reset sol. u = u
241
+ @reset sol. t = t isa Vector ? t : collect (t)
242
+ return @set sol. interp = interp
280
243
end
0 commit comments