Skip to content

Commit b855bc7

Browse files
committed
Update DiscreteProblem constructor and pass test
1 parent 7340bcb commit b855bc7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/systems/discrete_system/discrete_system.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ function DiffEqBase.DiscreteProblem(sys::DiscreteSystem,u0map,tspan,
115115
u = dvs
116116
p = varmap_to_vars(parammap,ps)
117117

118-
f_gen = build_function(rhss, dvs, ps, t; expression=Val{eval_expression}, expression_module=eval_module)
119-
f_oop,f_iip = (@RuntimeGeneratedFunction(eval_module, ex) for ex in f_gen)
118+
f_gen = generate_function(sys; expression=Val{eval_expression}, expression_module=eval_module)
119+
f_oop, _ = (@RuntimeGeneratedFunction(eval_module, ex) for ex in f_gen)
120120
f(u,p,t) = f_oop(u,p,t)
121121
DiscreteProblem(f,u0,tspan,p;kwargs...)
122122
end

test/discretesystem.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- https://github.com/epirecipes/sir-julia/blob/master/markdown/function_map/function_map.md
44
- https://en.wikipedia.org/wiki/Compartmental_models_in_epidemiology#Deterministic_versus_stochastic_epidemic_models
55
=#
6-
using ModelingToolkit
6+
using ModelingToolkit, Test
77

88
@inline function rate_to_proportion(r,t)
99
1-exp(-r*t)
@@ -36,16 +36,16 @@ sol_map = solve(prob_map,FunctionMap());
3636

3737
# Direct Implementation
3838

39-
function sir_map!(du,u,p,t)
39+
function sir_map!(u_new,u,p,t)
4040
(S,I,R) = u
4141
(β,c,γ,δt) = p
4242
N = S+I+R
4343
infection = rate_to_proportion*c*I/N,δt)*S
4444
recovery = rate_to_proportion(γ,δt)*I
4545
@inbounds begin
46-
du[1] = S-infection
47-
du[2] = I+infection-recovery
48-
du[3] = R+recovery
46+
u_new[1] = S-infection
47+
u_new[2] = I+infection-recovery
48+
u_new[3] = R+recovery
4949
end
5050
nothing
5151
end;

0 commit comments

Comments
 (0)