-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct dimensionality reduction for whole domain Integrals #225
Conversation
Codecov Report
@@ Coverage Diff @@
## master #225 +/- ##
==========================================
+ Coverage 77.29% 78.98% +1.68%
==========================================
Files 38 39 +1
Lines 1947 1989 +42
==========================================
+ Hits 1505 1571 +66
+ Misses 442 418 -24
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thanks! My code now runs, although isn't giving the correct answer - the PDE and the ODE should be similar (leaking mass at the upper boundary aside) - again, this is likely to be my naivete in implementing the boundary conditions properly. using DifferentialEquations
using ModelingToolkit
using MethodOfLines
using DomainSets
using OrdinaryDiffEq
using Plots
β = 0.0005
γ = 0.25
S₀ = 990.0
I₀ = 10.0
R₀ = 0.0
tmin = 0.0
tmax = 40.0
dt = 0.1
amin = 0.0
amax = 40.0
da = 0.1
@parameters t a
@variables S(..) I(..) R(..)
Dt = Differential(t)
Da = Differential(a)
Ia = Integral(a in DomainSets.ClosedInterval(amin,amax))
eqs = [Dt(S(t)) ~ -β * S(t) * Ia(I(a,t)),
Dt(I(a,t)) + Da(I(a,t)) ~ -γ*I(a,t),
Dt(R(t)) ~ γ*Ia(I(a,t))]
bcs = [
S(0) ~ S₀,
I(0,t) ~ β*S(t)*Ia(I(a,t)),
I(a,0) ~ I₀*da/(amax-amin),
R(0) ~ R₀
]
domains = [t ∈ (tmin, tmax), a ∈ (amin, amax)]
@named pde_system = PDESystem(eqs, bcs, domains, [a, t], [S(t), I(a, t), R(t)])
discretization = MOLFiniteDifference([a=>da], t)
prob = MethodOfLines.discretize(pde_system, discretization)
sol = solve(prob, saveat = dt)
Smat = sol.u[S(t)]
Imat = sol.u[I(a, t)]
Rmat = sol.u[R(t)]
plot(sol.t, vec(Smat),label="S",xlabel="Time",ylabel="Number")
plot!(sol.t, sum(Imat,dims=1)',label="I")
plot!(sol.t, vec(Rmat),label="R")
## The above should be comparable to below
function sir_ode(u,p,t)
(S, I, R) = u
(β, γ) = p
dS = -β*I*S
dI = β*I*S - γ*I
dR = γ*I
[dS, dI, dR]
end;
prob_ode = ODEProblem(sir_ode, [S₀, I₀, R₀], (tmin, tmax), [β,γ])
sol_ode = solve(prob_ode, Tsit5(), saveat=dt)
plot(sol_ode) |
fixes #221
fixes #222