@@ -23,19 +23,41 @@ struct ConstantInterpolation{T1,T2} <: AbstractDiffEqInterpolation
23
23
u:: T2
24
24
end
25
25
26
+ """
27
+ $(TYPEDEF)
28
+ """
29
+ struct SensitivityInterpolation{T1,T2} <: AbstractDiffEqInterpolation
30
+ t:: T1
31
+ u:: T2
32
+ end
33
+
26
34
interp_summary (:: AbstractDiffEqInterpolation ) = " Unknown"
27
35
interp_summary (:: HermiteInterpolation ) = " 3rd order Hermite"
28
36
interp_summary (:: LinearInterpolation ) = " 1st order linear"
29
37
interp_summary (:: ConstantInterpolation ) = " Piecewise constant interpolation"
30
38
interp_summary (:: Nothing ) = " No interpolation"
39
+ interp_summary (:: SensitivityInterpolation ) = " Interpolation disabled due to sensitivity analysis"
31
40
interp_summary (sol:: DESolution ) = interp_summary (sol. interp)
32
41
42
+ const SENSITIVITY_INTERP_MESSAGE =
43
+ """
44
+ Standard interpolation is disabled due to sensitivity analysis being
45
+ used for the gradients. Only linear and constant interpolations are
46
+ compatible with non-AD sensitivity analysis calculations. Either
47
+ utilize tooling like saveat to avoid post-solution interpolation, use
48
+ the keyword argument dense=false for linear or constant interpolations,
49
+ or use the keyword argument sensealg=SensitivityADPassThrough() to revert
50
+ to AD-based derivatives.
51
+ """
52
+
33
53
(id:: HermiteInterpolation )(tvals,idxs,deriv,p,continuity:: Symbol = :left ) = interpolation (tvals,id,idxs,deriv,p,continuity)
34
54
(id:: HermiteInterpolation )(val,tvals,idxs,deriv,p,continuity:: Symbol = :left ) = interpolation! (val,tvals,id,idxs,deriv,p,continuity)
35
55
(id:: LinearInterpolation )(tvals,idxs,deriv,p,continuity:: Symbol = :left ) = interpolation (tvals,id,idxs,deriv,p,continuity)
36
56
(id:: LinearInterpolation )(val,tvals,idxs,deriv,p,continuity:: Symbol = :left ) = interpolation! (val,tvals,id,idxs,deriv,p,continuity)
37
57
(id:: ConstantInterpolation )(tvals,idxs,deriv,p,continuity:: Symbol = :left ) = interpolation (tvals,id,idxs,deriv,p,continuity)
38
58
(id:: ConstantInterpolation )(val,tvals,idxs,deriv,p,continuity:: Symbol = :left ) = interpolation! (val,tvals,id,idxs,deriv,p,continuity)
59
+ (id:: SensitivityInterpolation )(tvals,idxs,deriv,p,continuity:: Symbol = :left ) = interpolation (tvals,id,idxs,deriv,p,continuity)
60
+ (id:: SensitivityInterpolation )(val,tvals,idxs,deriv,p,continuity:: Symbol = :left ) = interpolation! (val,tvals,id,idxs,deriv,p,continuity)
39
61
40
62
@inline function interpolation (tvals,id,idxs,deriv,p,continuity:: Symbol = :left )
41
63
t = id. t; u = id. u
@@ -72,6 +94,7 @@ interp_summary(sol::DESolution) = interp_summary(sol.interp)
72
94
vals[j] = u[i- 1 ][idxs]
73
95
end
74
96
else
97
+ typeof (id) <: SensitivityInterpolation && error (SENSITIVITY_INTERP_MESSAGE)
75
98
dt = t[i] - t[i- 1 ]
76
99
Θ = (tval- t[i- 1 ])/ dt
77
100
idxs_internal = idxs
@@ -119,6 +142,7 @@ times t (sorted), with values u and derivatives ks
119
142
vals[j] = u[i- 1 ][idxs]
120
143
end
121
144
else
145
+ typeof (id) <: SensitivityInterpolation && error (SENSITIVITY_INTERP_MESSAGE)
122
146
dt = t[i] - t[i- 1 ]
123
147
Θ = (tval- t[i- 1 ])/ dt
124
148
idxs_internal = idxs
@@ -169,6 +193,7 @@ times t (sorted), with values u and derivatives ks
169
193
val = u[i- 1 ][idxs]
170
194
end
171
195
else
196
+ typeof (id) <: SensitivityInterpolation && error (SENSITIVITY_INTERP_MESSAGE)
172
197
dt = t[i] - t[i- 1 ]
173
198
Θ = (tval- t[i- 1 ])/ dt
174
199
idxs_internal = idxs
@@ -211,6 +236,7 @@ times t (sorted), with values u and derivatives ks
211
236
copy! (out,u[i- 1 ][idxs])
212
237
end
213
238
else
239
+ typeof (id) <: SensitivityInterpolation && error (SENSITIVITY_INTERP_MESSAGE)
214
240
dt = t[i] - t[i- 1 ]
215
241
Θ = (tval- t[i- 1 ])/ dt
216
242
idxs_internal = idxs
0 commit comments