Skip to content

Commit a32a80c

Browse files
Merge pull request #27 from JuliaDiffEq/myb/sub
Use submodules
2 parents fb663ba + 76065be commit a32a80c

11 files changed

+124
-92
lines changed

src/DiffEqProblemLibrary.jl

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,25 @@
1-
__precompile__(false)
1+
__precompile__(true)
22

33
module DiffEqProblemLibrary
44

5-
using DiffEqBase, ParameterizedFunctions, DiffEqOperators, DiffEqBiological,
6-
LinearAlgebra
7-
8-
include("ode/ode_premade_problems.jl")
9-
include("dae_premade_problems.jl")
10-
include("dde_premade_problems.jl")
11-
include("sde_premade_problems.jl")
12-
include("jump_premade_problems.jl")
13-
14-
#ODE Example Problems
15-
export prob_ode_linear, prob_ode_bigfloatlinear, prob_ode_2Dlinear,
16-
prob_ode_large2Dlinear, prob_ode_bigfloat2Dlinear, prob_ode_rigidbody,
17-
prob_ode_2Dlinear_notinplace, prob_ode_vanderpol, prob_ode_vanderpol_stiff,
18-
prob_ode_lorenz, prob_ode_rober, prob_ode_threebody, prob_ode_mm_linear, prob_ode_pleiades,
19-
prob_ode_brusselator_1d, prob_ode_brusselator_2d, prob_ode_orego,
20-
prob_ode_hires, prob_ode_pollution, prob_ode_filament,
21-
SolverDiffEq, filament_prob
22-
23-
#SDE Example Problems
24-
export prob_sde_wave, prob_sde_linear, prob_sde_cubic, prob_sde_2Dlinear,
25-
prob_sde_lorenz, prob_sde_2Dlinear, prob_sde_additive,
26-
prob_sde_additivesystem, oval2ModelExample, prob_sde_bistable,
27-
prob_sde_bruss, prob_sde_oscilreact
5+
module ODEProblemLibrary
6+
importodeproblems() = include(joinpath(@__DIR__, "ode/ode_premade_problems.jl"))
7+
end # module
288

29-
#SDE Stratonovich Example Problems
30-
export prob_sde_linear_stratonovich, prob_sde_2Dlinear_stratonovich
9+
module DAEProblemLibrary
10+
importdaeproblems() = include(joinpath(@__DIR__, "dae_premade_problems.jl"))
11+
end # module
3112

32-
#DAE Example Problems
33-
export prob_dae_resrob
13+
module DDEProblemLibrary
14+
importddeproblems() = include(joinpath(@__DIR__, "dde_premade_problems.jl"))
15+
end # module
3416

35-
# DDE Example Problems
36-
# examples with constant delays
37-
export prob_dde_1delay, prob_dde_1delay_notinplace, prob_dde_1delay_scalar_notinplace,
38-
prob_dde_2delays, prob_dde_2delays_notinplace, prob_dde_2delays_scalar_notinplace,
39-
prob_dde_1delay_long, prob_dde_1delay_long_notinplace,
40-
prob_dde_1delay_long_scalar_notinplace, prob_dde_2delays_long,
41-
prob_dde_2delays_long_notinplace, prob_dde_2delays_long_scalar_notinplace,
42-
prob_dde_mackey, prob_dde_wheldon, prob_dde_qs,
43-
# examples with vanishing time dependent delays
44-
prob_ddde_neves1, prob_dde_neves_thompson,
45-
# examples with state dependent delays
46-
prob_dde_paul1, prob_dde_paul2, prob_dde_mahaffy1, prob_dde_mahaffy2,
47-
# examples with vanishing state dependent delays
48-
prob_neves2, prob_dde_gatica
17+
module SDEProblemLibrary
18+
importsdeproblems() = include(joinpath(@__DIR__, "sde_premade_problems.jl"))
19+
end # module
4920

50-
# Jump Example Problems
51-
export prob_jump_dnarepressor, prob_jump_constproduct, prob_jump_nonlinrxs,
52-
# examples mixing mass action and constant rate jumps
53-
prob_jump_osc_mixed_jumptypes,
54-
# examples used in published benchmarks / comparisions
55-
prob_jump_multistate, prob_jump_twentygenes, prob_jump_dnadimer_repressor,
56-
# examples approximating diffusion by continuous time random walks
57-
prob_jump_diffnetwork
21+
module JumpProblemLibrary
22+
importjumpproblems() = include(joinpath(@__DIR__, "jump_premade_problems.jl"))
23+
end # module
5824

5925
end # module

src/dae_premade_problems.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
using DiffEqBase
2+
3+
#DAE Example Problems
4+
export prob_dae_resrob
5+
16
### DAE Problems
27

38
f = function (r, yp, y, p, tres)

src/dde_premade_problems.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
using DiffEqBase
2+
# DDE Example Problems
3+
# examples with constant delays
4+
export prob_dde_1delay, prob_dde_1delay_notinplace, prob_dde_1delay_scalar_notinplace,
5+
prob_dde_2delays, prob_dde_2delays_notinplace, prob_dde_2delays_scalar_notinplace,
6+
prob_dde_1delay_long, prob_dde_1delay_long_notinplace,
7+
prob_dde_1delay_long_scalar_notinplace, prob_dde_2delays_long,
8+
prob_dde_2delays_long_notinplace, prob_dde_2delays_long_scalar_notinplace,
9+
prob_dde_mackey, prob_dde_wheldon, prob_dde_qs,
10+
# examples with vanishing time dependent delays
11+
prob_ddde_neves1, prob_dde_neves_thompson,
12+
# examples with state dependent delays
13+
prob_dde_paul1, prob_dde_paul2, prob_dde_mahaffy1, prob_dde_mahaffy2,
14+
# examples with vanishing state dependent delays
15+
prob_neves2, prob_dde_gatica
16+
17+
118
# DDE examples with analytical solution
219

320
## Single constant delay

src/jump_premade_problems.jl

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
"""
1+
using DiffEqBase, DiffEqBiological
2+
# Jump Example Problems
3+
export prob_jump_dnarepressor, prob_jump_constproduct, prob_jump_nonlinrxs,
4+
# examples mixing mass action and constant rate jumps
5+
prob_jump_osc_mixed_jumptypes,
6+
# examples used in published benchmarks / comparisions
7+
prob_jump_multistate, prob_jump_twentygenes, prob_jump_dnadimer_repressor,
8+
# examples approximating diffusion by continuous time random walks
9+
prob_jump_diffnetwork
10+
11+
"""
212
General structure to hold JumpProblem info. Needed since
3-
the JumpProblem constructor requires the algorithm, so we
13+
the JumpProblem constructor requires the algorithm, so we
414
don't create the JumpProblem here.
515
"""
6-
struct JumpProblemNetwork
16+
struct JumpProblemNetwork
717
network # DiffEqBiological network
818
rates # vector of rate constants or nothing
919
tstop # time to end simulation
@@ -28,7 +38,7 @@ Nsims = 8000
2838
expected_avg = 5.926553750000000e+02
2939
prob_data = Dict("num_sims_for_mean" => Nsims, "expected_mean" => expected_avg)
3040
"""
31-
DNA negative feedback autoregulatory model. Protein acts as repressor.
41+
DNA negative feedback autoregulatory model. Protein acts as repressor.
3242
"""
3343
prob_jump_dnarepressor = JumpProblemNetwork(dna_rs, rates, tf, u0, prob, prob_data)
3444

@@ -50,7 +60,7 @@ prob_jump_constproduct = JumpProblemNetwork(bd_rs, rates, tf, u0, prob, prob_dat
5060

5161
nonlin_rs = @reaction_network dtype begin
5262
k1, 2A --> B
53-
k2, B --> 2A
63+
k2, B --> 2A
5464
k3, A + B --> C
5565
k4, C --> A + B
5666
k5, 3C --> 3A
@@ -132,12 +142,12 @@ u0[ findfirst(rs.syms, :S3) ] = params[3]
132142
tf = 100.
133143
prob = DiscreteProblem(u0, (0., tf), rates)
134144
"""
135-
Multistate model from Gupta and Mendes,
145+
Multistate model from Gupta and Mendes,
136146
"An Overview of Network-Based and -Free Approaches for Stochastic Simulation of Biochemical Systems",
137147
Computation 2018, 6, 9; doi:10.3390/computation6010009
138148
Translated from supplementary data file: Models/Multi-state/fixed_multistate.xml
139149
"""
140-
prob_jump_multistate = JumpProblemNetwork(rs, rates, tf, u0, prob,
150+
prob_jump_multistate = JumpProblemNetwork(rs, rates, tf, u0, prob,
141151
Dict("specs_to_sym_name" => specs_sym_to_name, "rates_sym_to_idx" => rates_sym_to_idx, "params" => params))
142152

143153

@@ -162,14 +172,14 @@ genenetwork *= "end"
162172
rs = eval( parse(genenetwork) )
163173
u0 = zeros(Int, length(rs.syms))
164174
for i = 1:(2*N)
165-
u0[findfirst(rs.syms, Symbol("G$(i)"))] = 1
175+
u0[findfirst(rs.syms, Symbol("G$(i)"))] = 1
166176
end
167177
tf = 2000.0
168178
prob = DiscreteProblem(u0, (0.0, tf))
169179
"""
170-
Twenty-gene model from McCollum et al,
180+
Twenty-gene model from McCollum et al,
171181
"The sorting direct method for stochastic simulation of biochemical systems with varying reaction execution behavior"
172-
Comp. Bio. and Chem., 30, pg. 39-49 (2006).
182+
Comp. Bio. and Chem., 30, pg. 39-49 (2006).
173183
"""
174184
prob_jump_twentygenes = JumpProblemNetwork(rs, nothing, tf, u0, prob, nothing)
175185

@@ -191,11 +201,11 @@ tf = 4000.
191201
prob = DiscreteProblem(u0, (0.0, tf), rnpar)
192202
"""
193203
Negative feedback autoregulatory gene expression model. Dimer is the repressor.
194-
Taken from Marchetti, Priami and Thanh,
195-
"Simulation Algorithms for Comptuational Systems Biology",
204+
Taken from Marchetti, Priami and Thanh,
205+
"Simulation Algorithms for Comptuational Systems Biology",
196206
Springer (2017).
197207
"""
198-
prob_jump_dnadimer_repressor = JumpProblemNetwork(rn, rnpar, tf, u0, prob,
208+
prob_jump_dnadimer_repressor = JumpProblemNetwork(rn, rnpar, tf, u0, prob,
199209
Dict("specs_names" => varlabels))
200210

201211

@@ -217,7 +227,7 @@ end
217227
tf = 10.
218228
"""
219229
Continuous time random walk (i.e. diffusion approximation) example.
220-
Here the network in the JumpProblemNetwork is a function that returns a
230+
Here the network in the JumpProblemNetwork is a function that returns a
221231
network given the number of lattice sites.
222232
u0 is a similar function that returns the initial condition vector.
223233
"""

src/ode/brusselator_prob.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function brusselator_2d_loop(du, u, p, t)
1313
@inbounds begin
1414
A, B, α, xyd, dx, N = p
1515
α = α/dx^2
16-
for I in CartesianRange((N, N))
16+
for I in CartesianIndices((N, N))
1717
x = xyd[I[1]]
1818
y = xyd[I[2]]
1919
i = I[1]
@@ -25,7 +25,7 @@ function brusselator_2d_loop(du, u, p, t)
2525
du[i,j,1] = α*(u[im1,j,1] + u[ip1,j,1] + u[i,jp1,1] + u[i,jm1,1] - 4u[i,j,1]) +
2626
B + u[i,j,1]^2*u[i,j,2] - (A + 1)*u[i,j,1] + brusselator_f(x, y, t)
2727
end
28-
for I in CartesianRange((N, N))
28+
for I in CartesianIndices((N, N))
2929
i = I[1]
3030
j = I[2]
3131
ip1 = limit(i+1, N)
@@ -40,17 +40,17 @@ end
4040
function init_brusselator_2d(xyd)
4141
N = length(xyd)
4242
u = zeros(N, N, 2)
43-
for I in CartesianRange((N, N))
43+
for I in CartesianIndices((N, N))
4444
x = xyd[I[1]]
4545
y = xyd[I[2]]
4646
u[I,1] = 22*(y*(1-y))^(3/2)
4747
u[I,2] = 27*(x*(1-x))^(3/2)
4848
end
4949
u
5050
end
51-
xyd_brusselator = linspace(0,1,32)
51+
xyd_brusselator = range(0,stop=1,length=32)
5252

53-
doc"""
53+
@doc doc"""
5454
2D Brusselator
5555
5656
```math
@@ -120,15 +120,15 @@ function brusselator_1d(du, u_, p, t)
120120
end
121121
function init_brusselator_1d(N)
122122
u = zeros(N, 2)
123-
x = linspace(0, 1, N)
123+
x = range(0, stop=1, length=N)
124124
for i in 1:N
125125
u[i, 1] = 1 + sin(2pi*x[i])
126126
u[i, 2] = 3.
127127
end
128128
u
129129
end
130130

131-
doc"""
131+
@doc doc"""
132132
1D Brusselator
133133
134134
```math

src/ode/filament_prob.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ struct NoHydroProjectionCache <: AbstractInextensibilityCache
3535
J :: Matrix{T}
3636
P :: Matrix{T}
3737
J_JT :: Matrix{T}
38-
J_JT_LDLT :: Base.LinAlg.LDLt{T, SymTridiagonal{T}}
38+
J_JT_LDLT :: LinearAlgebra.LDLt{T, SymTridiagonal{T}}
3939
P0 :: Matrix{T}
4040

4141
NoHydroProjectionCache(N::Int) = new(
4242
zeros(N, 3*(N+1)), # J
4343
zeros(3*(N+1), 3*(N+1)), # P
4444
zeros(N,N), # J_JT
45-
Base.LinAlg.LDLt{T,SymTridiagonal{T}}(SymTridiagonal(zeros(N), zeros(N-1))),
45+
LinearAlgebra.LDLt{T,SymTridiagonal{T}}(SymTridiagonal(zeros(N), zeros(N-1))),
4646
zeros(N, 3*(N+1))
4747
)
4848
end
@@ -66,7 +66,7 @@ function FilamentCache(N=20; Cm=32, ω=200, Solver=SolverDiffEq)
6666
end
6767
function stiffness_matrix!(f::AbstractFilamentCache)
6868
N, μ, A = f.N, f.μ, f.A
69-
A[:] = eye(3*(N+1))
69+
A[:] = Matrix{Float64}(I, 3*(N+1), 3*(N+1))
7070
for i in 1 : 3
7171
A[i,i] = 1
7272
A[i,3+i] = -2
@@ -94,7 +94,7 @@ function stiffness_matrix!(f::AbstractFilamentCache)
9494
A[3*j+i,3*(j+2)+i] = 1
9595
end
9696
end
97-
scale!(A, -μ^4)
97+
rmul!(A, -μ^4)
9898
nothing
9999
end
100100
function update_separate_coordinates!(f::AbstractFilamentCache, r)
@@ -126,7 +126,7 @@ end
126126
function initialize!(initial_conf_type::Symbol, f::AbstractFilamentCache)
127127
N, x, y, z = f.N, f.x, f.y, f.z
128128
if initial_conf_type == :StraightX
129-
x[:] = linspace(0, 1, N+1)
129+
x[:] = range(0, stop=1, length=N+1)
130130
y[:] = 0 .* x
131131
z[:] = 0 .* x
132132
else
@@ -192,14 +192,14 @@ function projection!(f::FilamentCache)
192192
end
193193

194194
function subtract_from_identity!(A)
195-
scale!(-1, A)
195+
rmul!(-1, A)
196196
@inbounds for i in 1 : size(A,1)
197197
A[i,i] += 1
198198
end
199199
nothing
200200
end
201201

202-
function LDLt_inplace!{T<:Real}(L::Base.LinAlg.LDLt{T,SymTridiagonal{T}}, A::Matrix{T})
202+
function LDLt_inplace!(L::LinearAlgebra.LDLt{T,SymTridiagonal{T}}, A::Matrix{T}) where {T<:Real}
203203
n = size(A,1)
204204
dv, ev = L.data.dv, L.data.ev
205205
@inbounds for (i,d) in enumerate(diagind(A))

src/ode/ode_premade_problems.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
using DiffEqBase, ParameterizedFunctions, DiffEqOperators, Random, LinearAlgebra,
2+
Markdown
3+
14
srand(100)
25

6+
#ODE Example Problems
7+
export prob_ode_linear, prob_ode_bigfloatlinear, prob_ode_2Dlinear,
8+
prob_ode_large2Dlinear, prob_ode_bigfloat2Dlinear, prob_ode_rigidbody,
9+
prob_ode_2Dlinear_notinplace, prob_ode_vanderpol, prob_ode_vanderpol_stiff,
10+
prob_ode_lorenz, prob_ode_rober, prob_ode_threebody, prob_ode_mm_linear, prob_ode_pleiades,
11+
prob_ode_brusselator_1d, prob_ode_brusselator_2d, prob_ode_orego,
12+
prob_ode_hires, prob_ode_pollution, prob_ode_filament,
13+
SolverDiffEq, filament_prob
14+
315
include("ode_linear_prob.jl")
416
include("ode_simple_nonlinear_prob.jl")
517
include("brusselator_prob.jl")

src/ode/ode_simple_nonlinear_prob.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pleiades = (du,u,p,t) -> begin
175175
w = view(u,22:28) # y′
176176
du[1:7] .= v
177177
du[8:14].= w
178-
for i in 14:21
178+
for i in 14:28
179179
du[i] = zero(eltype(u))
180180
end
181181
for i=1:7,j=1:7
@@ -241,6 +241,7 @@ Usually solved from 0 to 3.
241241
prob_ode_pleiades = ODEProblem(pleiades,[3.0,3.0,-1.0,-3.0,2.0,-2.0,2.0,3.0,-3.0,2.0,0,0,-4.0,4.0,0,0,0,0,0,1.75,-1.5,0,0,0,-1.25,1,0,0],(0.0,3.0))
242242

243243

244+
244245
srand(100)
245246
const mm_A = rand(4,4)
246247
mm_linear = function (du,u,p,t)

src/ode/pollution_prob.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ u0[8] = 0.3
188188
u0[9] = 0.01
189189
u0[17] = 0.007
190190

191-
doc"""
191+
@doc doc"""
192192
[Pollution Problem](http://nbviewer.jupyter.org/github/JuliaDiffEq/DiffEqBenchmarks.jl/blob/master/StiffODE/Pollution.ipynb) (Stiff)
193193
194194
This IVP is a stiff system of 20 non-linear Ordinary Differential Equations. It is in the form of ``\\frac{dy}{dt}=f(y), \\quad y(0)=y0,`` with

0 commit comments

Comments
 (0)