From 1cb297f34416b65deeeeb66f5346f3c588efa784 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas Date: Mon, 14 Nov 2016 09:25:15 -0800 Subject: [PATCH] refactor --- src/DiffEqBase.jl | 10 ++-- src/{ => algorithms}/ode_algorithms.jl | 0 src/{ => algorithms}/ode_default_alg.jl | 0 src/algorithms/sde_algorithms.jl | 0 src/parameterized.jl | 3 -- src/{problems.jl => problems/ode_problems.jl} | 0 .../ode_solutions.jl} | 46 ------------------- .../solution_interface.jl} | 45 ++++++++++++++++++ 8 files changed, 50 insertions(+), 54 deletions(-) rename src/{ => algorithms}/ode_algorithms.jl (100%) rename src/{ => algorithms}/ode_default_alg.jl (100%) create mode 100644 src/algorithms/sde_algorithms.jl delete mode 100644 src/parameterized.jl rename src/{problems.jl => problems/ode_problems.jl} (100%) rename src/{solutions.jl => solutions/ode_solutions.jl} (66%) rename src/{plotrecipes.jl => solutions/solution_interface.jl} (60%) diff --git a/src/DiffEqBase.jl b/src/DiffEqBase.jl index 7b2d495cc..b3538421b 100644 --- a/src/DiffEqBase.jl +++ b/src/DiffEqBase.jl @@ -40,12 +40,12 @@ module DiffEqBase abstract SensitivityFunction <: ParameterizedFunction include("utils.jl") - include("solutions.jl") - include("ode_algorithms.jl") - include("ode_default_alg.jl") - include("plotrecipes.jl") + include("solutions/ode_solutions.jl") + include("algorithms/ode_algorithms.jl") + include("algorithms/ode_default_alg.jl") + include("solutions/solution_interface.jl") include("tableaus.jl") - include("problems.jl") + include("problems/ode_problems.jl") function solve end diff --git a/src/ode_algorithms.jl b/src/algorithms/ode_algorithms.jl similarity index 100% rename from src/ode_algorithms.jl rename to src/algorithms/ode_algorithms.jl diff --git a/src/ode_default_alg.jl b/src/algorithms/ode_default_alg.jl similarity index 100% rename from src/ode_default_alg.jl rename to src/algorithms/ode_default_alg.jl diff --git a/src/algorithms/sde_algorithms.jl b/src/algorithms/sde_algorithms.jl new file mode 100644 index 000000000..e69de29bb diff --git a/src/parameterized.jl b/src/parameterized.jl deleted file mode 100644 index c35388b00..000000000 --- a/src/parameterized.jl +++ /dev/null @@ -1,3 +0,0 @@ -### Basic Functionality - -getindex{s}(p::ParameterizedFunction,::Val{s}) = getfield(p,s) ## Val for type-stability diff --git a/src/problems.jl b/src/problems/ode_problems.jl similarity index 100% rename from src/problems.jl rename to src/problems/ode_problems.jl diff --git a/src/solutions.jl b/src/solutions/ode_solutions.jl similarity index 66% rename from src/solutions.jl rename to src/solutions/ode_solutions.jl index be432cba0..651d53a46 100644 --- a/src/solutions.jl +++ b/src/solutions/ode_solutions.jl @@ -1,49 +1,3 @@ -### Abstract Interface - -Base.length(sol::DESolution) = length(sol.u) # Must be on u for the test solutions! -Base.endof(sol::DESolution) = length(sol) -Base.getindex(sol::DESolution,i::Int) = sol.u[i] -Base.getindex(sol::DESolution,i::Int,I::Int...) = sol.u[i][I...] -Base.getindex(sol::DESolution,::Colon) = sol.u -Base.getindex(sol::DESolution,::Colon,i::Int...) = [sol.u[j][i...] for j in eachindex(sol)] -eachindex(sol::DESolution) = eachindex(sol.t) -tuples(sol::DESolution) = tuple.(sol.t,sol.u) - -function start(sol::DESolution) - sol.tslocation = 1 - 1 -end - -function next(sol::DESolution,state) - state += 1 - sol.tslocation = state - (sol,state) -end - -function done(sol::DESolution,state) - state >= length(sol) -end - -function eltype(sol::DESolution) - if typeof(sol[1]) <: AbstractArray - return typeof(sol[1][1]) - else - return typeof(sol[1]) - end -end - -function print(io::IO, sol::DESolution) - println(io,"$(typeof(sol))") - println(io,"u: $(sol.u)") - println(io,"t: $(sol.t)") - nothing -end - -function show(io::IO,sol::DESolution) - print(io,"$(typeof(sol))") -end - - ### Concrete Types type ODESolution{uType,tType,rateType,P,A} <: AbstractODESolution diff --git a/src/plotrecipes.jl b/src/solutions/solution_interface.jl similarity index 60% rename from src/plotrecipes.jl rename to src/solutions/solution_interface.jl index e718441d7..2036f2aa1 100644 --- a/src/plotrecipes.jl +++ b/src/solutions/solution_interface.jl @@ -1,3 +1,48 @@ +### Abstract Interface + +Base.length(sol::DESolution) = length(sol.u) # Must be on u for the test solutions! +Base.endof(sol::DESolution) = length(sol) +Base.getindex(sol::DESolution,i::Int) = sol.u[i] +Base.getindex(sol::DESolution,i::Int,I::Int...) = sol.u[i][I...] +Base.getindex(sol::DESolution,::Colon) = sol.u +Base.getindex(sol::DESolution,::Colon,i::Int...) = [sol.u[j][i...] for j in eachindex(sol)] +eachindex(sol::DESolution) = eachindex(sol.t) +tuples(sol::DESolution) = tuple.(sol.t,sol.u) + +function start(sol::DESolution) + sol.tslocation = 1 + 1 +end + +function next(sol::DESolution,state) + state += 1 + sol.tslocation = state + (sol,state) +end + +function done(sol::DESolution,state) + state >= length(sol) +end + +function eltype(sol::DESolution) + if typeof(sol[1]) <: AbstractArray + return typeof(sol[1][1]) + else + return typeof(sol[1]) + end +end + +function print(io::IO, sol::DESolution) + println(io,"$(typeof(sol))") + println(io,"u: $(sol.u)") + println(io,"t: $(sol.t)") + nothing +end + +function show(io::IO,sol::DESolution) + print(io,"$(typeof(sol))") +end + @recipe function f(sol::AbstractODESolution;sensitivity=false,plot_analytic=false,denseplot=true,plotdensity=100) plotseries = Vector{Any}(0) if typeof(sol) <: AbstractSDESolution; denseplot=false; end