-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from SciML/saveat
Some automated conversions in saveat
- Loading branch information
Showing
8 changed files
with
191 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
|
||
# saveat is just a bool here: | ||
# true: ts is a vector of timestamps to read from | ||
# false: each ODE has its own timestamps, so ts is a vector to write to | ||
@kernel function ode_solve_kernel(@Const(probs), alg, _us, _ts, dt, callback, | ||
tstops, nsteps, | ||
saveat, ::Val{save_everystep}) where {save_everystep} | ||
i = @index(Global, Linear) | ||
|
||
# get the actual problem for this thread | ||
prob = @inbounds probs[i] | ||
|
||
# get the input/output arrays for this thread | ||
ts = @inbounds view(_ts, :, i) | ||
us = @inbounds view(_us, :, i) | ||
|
||
_saveat = get(prob.kwargs, :saveat, nothing) | ||
|
||
saveat = _saveat === nothing ? saveat : _saveat | ||
|
||
integ = init(alg, prob.f, false, prob.u0, prob.tspan[1], dt, prob.p, tstops, | ||
callback, save_everystep, saveat) | ||
|
||
u0 = prob.u0 | ||
tspan = prob.tspan | ||
|
||
integ.cur_t = 0 | ||
if saveat !== nothing | ||
integ.cur_t = 1 | ||
if prob.tspan[1] == saveat[1] | ||
integ.cur_t += 1 | ||
@inbounds us[1] = u0 | ||
end | ||
else | ||
@inbounds ts[integ.step_idx] = prob.tspan[1] | ||
@inbounds us[integ.step_idx] = prob.u0 | ||
end | ||
|
||
integ.step_idx += 1 | ||
# FSAL | ||
while integ.t < tspan[2] && integ.retcode != DiffEqBase.ReturnCode.Terminated | ||
saved_in_cb = step!(integ, ts, us) | ||
!saved_in_cb && savevalues!(integ, ts, us) | ||
end | ||
if integ.t > tspan[2] && saveat === nothing | ||
## Intepolate to tf | ||
@inbounds us[end] = integ(tspan[2]) | ||
@inbounds ts[end] = tspan[2] | ||
end | ||
|
||
if saveat === nothing && !save_everystep | ||
@inbounds us[2] = integ.u | ||
@inbounds ts[2] = integ.t | ||
end | ||
end | ||
|
||
@kernel function ode_asolve_kernel(@Const(probs), alg, _us, _ts, dt, callback, tstops, | ||
abstol, reltol, | ||
saveat, | ||
::Val{save_everystep}) where {save_everystep} | ||
i = @index(Global, Linear) | ||
|
||
# get the actual problem for this thread | ||
prob = @inbounds probs[i] | ||
# get the input/output arrays for this thread | ||
ts = @inbounds view(_ts, :, i) | ||
us = @inbounds view(_us, :, i) | ||
# TODO: optimize contiguous view to return a CuDeviceArray | ||
|
||
_saveat = get(prob.kwargs, :saveat, nothing) | ||
|
||
saveat = _saveat === nothing ? saveat : _saveat | ||
|
||
u0 = prob.u0 | ||
tspan = prob.tspan | ||
f = prob.f | ||
p = prob.p | ||
|
||
t = tspan[1] | ||
tf = prob.tspan[2] | ||
|
||
integ = init(alg, prob.f, false, prob.u0, prob.tspan[1], prob.tspan[2], dt, | ||
prob.p, | ||
abstol, reltol, DiffEqBase.ODE_DEFAULT_NORM, tstops, callback, | ||
saveat) | ||
|
||
integ.cur_t = 0 | ||
if saveat !== nothing | ||
integ.cur_t = 1 | ||
if tspan[1] == saveat[1] | ||
integ.cur_t += 1 | ||
@inbounds us[1] = u0 | ||
end | ||
else | ||
@inbounds ts[1] = tspan[1] | ||
@inbounds us[1] = u0 | ||
end | ||
|
||
while integ.t < tspan[2] && integ.retcode != DiffEqBase.ReturnCode.Terminated | ||
saved_in_cb = step!(integ, ts, us) | ||
!saved_in_cb && savevalues!(integ, ts, us) | ||
end | ||
|
||
if integ.t > tspan[2] && saveat === nothing | ||
## Intepolate to tf | ||
@inbounds us[end] = integ(tspan[2]) | ||
@inbounds ts[end] = tspan[2] | ||
end | ||
|
||
if saveat === nothing && !save_everystep | ||
@inbounds us[2] = integ.u | ||
@inbounds ts[2] = integ.t | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.