Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ODE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ function make_consistent_types(fn, y0, tspan, btab::Tableau)
# On container: eltype, promote_type
# On time container: eltype

Ty = typeof(y0)
Eyf = typeof(y0[1]/(tspan[end]-tspan[1]))
Ty = typeof(similar(y0, Eyf, 1))

Et = eltype(tspan)
@assert Et<:Real
Expand Down Expand Up @@ -265,7 +265,8 @@ function ode23s(F, y0, tspan; reltol = 1.0e-5, abstol = 1.0e-8,
h = tdir * min(abs(h), maxstep)

y = y0
tout = Array(typeof(t), 1)
# below promotion should maybe be replaced by using make_consistent_types
tout = Array(promote_type(typeof(t), Float64), 1)
tout[1] = t # first output time
yout = Array(typeof(y0), 1)
yout[1] = deepcopy(y) # first output solution
Expand Down
11 changes: 7 additions & 4 deletions test/interface-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ ODE.isoutofdomain(y::CompSol) = any(isnan, vcat(y.rho[:], y.x, y.p))


################################################################################

# define RHSs of differential equations
# delta, V and g are parameters
function rhs(t, y, delta, V, g)
H = [[-delta/2 V]; [V delta/2]]

rho_dot = -im*H*y.rho + im*y.rho*H
x_dot = y.p
p_dot = -y.x

return CompSol( rho_dot, x_dot, p_dot)
end

# inital conditons
rho0 = zeros(2,2);
rho0[1,1]=1.;
Expand All @@ -75,6 +75,9 @@ for solver in solvers
end
t,y2 = solver((t,y)->rhs(t, y, delta0, V0, g0), y0, linspace(0., endt, 500))
@test norm(y1[end]-y2[end])<0.1

# test that typeof(tspan)==Vector{Int} does not throw:
t,y2 = solver((t,y)->rhs(t, y, delta0, V0, g0), y0, [0,1])
end
println("ok.")

Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ for solver in solvers
t,y=solver((t,y)->2t, 0., [0:.001:1;])
@test maximum(abs(y-t.^2)) < tol

# test typeof(tspan)==Vector{Int} does not throw
t,y=solver((t,y)->2t, 0., [0,1])
if !(solver in [ODE.ode4s_s, ODE.ode4s_kr, ODE.ode23s])
# test typeof(y0)==Vector{Int} does not throw
t,y=solver((t,y)->[2t], [0], [0,1])
# test typeof(y0)==Int does not throw
t,y=solver((t,y)->2t, 0, [0,1])
end

# dy
# -- = y ==> y = y0*e.^t
Expand Down