Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
141 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
julia 0.4 | ||
Polynomials | ||
Compat 0.9 | ||
DiffEqBase |
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,8 @@ | ||
abstract ODEJLAlgorithm <: AbstractODEAlgorithm | ||
immutable ode23 <: ODEJLAlgorithm end | ||
immutable ode45 <: ODEJLAlgorithm end | ||
immutable ode23s <: ODEJLAlgorithm end | ||
immutable ode78 <: ODEJLAlgorithm end | ||
immutable ode4 <: ODEJLAlgorithm end | ||
immutable ode4ms <: ODEJLAlgorithm end | ||
immutable ode4s <: ODEJLAlgorithm 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
function solve{uType,tType,isinplace,algType<:ODEJLAlgorithm,F}(prob::AbstractODEProblem{uType,tType,isinplace,F}, | ||
alg::algType,timeseries=[],ts=[],ks=[];dense=true,save_timeseries=true, | ||
saveat=tType[],timeseries_errors=true,reltol = 1e-5, abstol = 1e-8, | ||
dtmin = abs(prob.tspan[2]-prob.tspan[1])/1e-9, | ||
dtmax = abs(prob.tspan[2]-prob.tspan[1])/2.5, | ||
dt = 0.,norm = Base.vecnorm, | ||
kwargs...) | ||
|
||
tspan = prob.tspan | ||
|
||
if tspan[end]-tspan[1]<tType(0) | ||
error("final time must be greater than starting time. Aborting.") | ||
end | ||
|
||
u0 = prob.u0 | ||
|
||
Ts = sort(unique([tspan[1];saveat;tspan[2]])) | ||
|
||
if save_timeseries | ||
points = :all | ||
else | ||
points = :specified | ||
end | ||
|
||
sizeu = size(prob.u0) | ||
|
||
if isinplace | ||
f = (t,u) -> (du = zeros(u); prob.f(t,u,du); vec(du)) | ||
elseif uType <: AbstractArray | ||
f = (t,u) -> vec(prob.f(t,reshape(u,sizeu))) | ||
else | ||
f = prob.f | ||
end | ||
|
||
if uType <: AbstractArray | ||
u0 = vec(prob.u0) | ||
else | ||
u0 = prob.u0 | ||
end | ||
|
||
if typeof(alg) <: ode23 | ||
ts,timeseries_tmp = ODE.ode23(f,u0,Ts, | ||
norm = norm, | ||
abstol=abstol, | ||
reltol=reltol, | ||
maxstep=dtmax, | ||
minstep=dtmin, | ||
initstep=dt, | ||
points=points) | ||
elseif typeof(alg) <: ode45 | ||
ts,timeseries_tmp = ODE.ode45(f,u0,Ts, | ||
norm = norm, | ||
abstol=abstol, | ||
reltol=reltol, | ||
maxstep=dtmax, | ||
minstep=dtmin, | ||
initstep=dt, | ||
points=points) | ||
elseif typeof(alg) <: ode78 | ||
ts,timeseries_tmp = ODE.ode78(f,u0,Ts, | ||
norm = norm, | ||
abstol=abstol, | ||
reltol=reltol, | ||
maxstep=dtmax, | ||
minstep=dtmin, | ||
initstep=dt, | ||
points=points) | ||
elseif typeof(alg) <: ode23s | ||
ts,timeseries_tmp = ODE.ode23s(f,u0,Ts, | ||
norm = norm, | ||
abstol=abstol, | ||
reltol=reltol, | ||
maxstep=dtmax, | ||
minstep=dtmin, | ||
initstep=dt, | ||
points=points) | ||
elseif typeof(alg) <: ode4 | ||
ts,timeseries_tmp = ODE.ode4(f,u0,Ts) | ||
elseif typeof(alg) <: ode4ms | ||
ts,timeseries_tmp = ODE.ode4ms(f,u0,Ts) | ||
elseif typeof(alg) <: ode4s | ||
ts,timeseries_tmp = ODE.ode4s(f,u0,Ts) | ||
end | ||
|
||
# Reshape the result if needed | ||
if uType <: AbstractArray | ||
timeseries = Vector{uType}(0) | ||
for i=1:length(timeseries_tmp) | ||
push!(timeseries,reshape(timeseries_tmp[i],sizeu)) | ||
end | ||
else | ||
timeseries = timeseries_tmp | ||
end | ||
|
||
build_solution(prob,alg,ts,timeseries, | ||
timeseries_errors = timeseries_errors) | ||
end | ||
|
||
export ODEJLAlgorithm, ode23Alg, ode23sAlg, ode45Alg, ode78Alg |
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 @@ | ||
DiffEqProblemLibrary |
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,21 @@ | ||
using ODE, DiffEqBase, DiffEqProblemLibrary | ||
|
||
dt=1/2^(4) | ||
|
||
algs = [ode23(),ode45(),ode78(),ode4(),ode4ms(),ode4s()] # no ode23s | ||
|
||
# Check for errors | ||
|
||
prob = prob_ode_linear | ||
|
||
for alg in algs | ||
sol =solve(prob,alg;dt=dt,abstol=1e-6,reltol=1e-3) | ||
@test typeof(sol[2]) <: Number | ||
end | ||
|
||
prob = prob_ode_2Dlinear | ||
|
||
for alg in algs | ||
sol =solve(prob,alg;dt=dt,dtmin=eps(),abstol=1e-6,reltol=1e-3) | ||
@test size(sol[2]) == (4,2) | ||
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