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 #119 from JuliaDiffEq/common
add common interface bindings
- Loading branch information
Showing
10 changed files
with
115 additions
and
15 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 |
---|---|---|
|
@@ -3,7 +3,6 @@ os: | |
- osx | ||
- linux | ||
julia: | ||
- 0.4 | ||
- release | ||
- nightly | ||
matrix: | ||
|
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 | ||
julia 0.5 | ||
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
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,10 @@ | ||
abstract ODEjlAlgorithm <: AbstractODEAlgorithm | ||
# Making the ODE-solver functions into types lets us dispatch on them. | ||
# Used in the DiffEqBase interface. | ||
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,56 @@ | ||
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 | ||
|
||
u0 = prob.u0 | ||
|
||
Ts = 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 | ||
|
||
u0 = uType <: AbstractArray ? vec(prob.u0) : prob.u0 | ||
|
||
# Calling the solver, i.e. if the algorithm is ode45, | ||
# then AlgType(...) is ode45(...) | ||
ts,timeseries_tmp = AlgType(f,u0,Ts; | ||
norm = norm, | ||
abstol=abstol, | ||
reltol=reltol, | ||
maxstep=dtmax, | ||
minstep=dtmin, | ||
initstep=dt, | ||
points=points) | ||
|
||
# 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 |
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