Skip to content

Commit 0ddae15

Browse files
committed
bug fix: missing V=0 upcrossing
in some cases, the maximum V is below 0mV, so we now detect upcrossings at V=-20mV
1 parent fd6b49f commit 0ddae15

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

mcmcSetup.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Get the period of the limit cycle.
2626
"""
2727
function get_period(lc::Vector{Float64}, prob::ODEProblem)::Number
2828
# Use callbacks to find state at start and end of a period (using upcrossings of V=0mV)
29-
condition(u, _, _) = u[1]
29+
condition(u, _, _) = u[1]+20
3030
NUM_TIMES_EFFECT_HIT::Int = 0
3131
function affect!(integrator)
3232
NUM_TIMES_EFFECT_HIT += 1
@@ -103,7 +103,7 @@ function optimiseParameters()
103103
function model_simulator(p)
104104
prob = remake(prob, p=Tools.param_map(p))::ODEProblem
105105
# Converge
106-
condition(u, _, _) = u[1]
106+
condition(u, _, _) = u[1]+20
107107
STATE::Vector{Float64} = zeros(size(Model.ic))
108108
function affect!(integrator)
109109
error = STATE .- integrator.u

mhmcmc.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Solve the ODE until convergence starting from the default initial conditions.
278278
- `lc`: The converged limit cycle.
279279
"""
280280
function odeSolverStandard(x, prob::ODEProblem, lc, xlc, paramMap::Function, verbose=1::Integer)
281-
condition(u, _, _) = u[1]
281+
condition(u, _, _) = u[1]+20
282282
STATE::Vector{Float64} = zeros(size(Model.ic))
283283
function affect!(integrator)
284284
error = STATE .- integrator.u
@@ -310,7 +310,7 @@ Solve the ODE until convergence but starting from the previous limit cycle.
310310
- `lc`: The converged limit cycle.
311311
"""
312312
function odeSolverTracking(x, prob::ODEProblem, lc, _, paramMap::Function, verbose::Integer)
313-
condition(u, _, _) = u[1]
313+
condition(u, _, _) = u[1]+20
314314
STATE::Vector{Float64} = zeros(size(Model.ic))
315315
function affect!(integrator)
316316
error = STATE .- integrator.u

simulationTimings.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ prob = ODEProblem(Model.ode!, Model.ic, (0.0, 10000.0), tmp, abstol=1e-10, relto
3131
# ODE Convergence - Standard
3232
params = [pSmall, pLarge]
3333
for i in eachindex(params)
34-
condition(u, _, _) = u[1]
34+
condition(u, _, _) = u[1]+20
3535
STATE::Vector{Float64} = zeros(size(Model.ic))
3636
function affect!(integrator)
3737
error = STATE .- integrator.u
@@ -52,7 +52,7 @@ end
5252

5353
# ODE Convergence - Tracking
5454
for i in eachindex(params)
55-
condition(u, _, _) = u[1]
55+
condition(u, _, _) = u[1]+20
5656
STATE::Vector{Float64} = zeros(size(Model.ic))
5757
function affect!(integrator)
5858
error = STATE .- integrator.u

tools.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using .Model
77
# Check all variables are converged automatically
88
function auto_converge_check(prob::ODEProblem, ic, p::NamedTuple)::Bool
99
# Use callbacks to find state at start and end of period (using upcrossings of V=0mV)
10-
condition(u, _, _) = u[1]
10+
condition(u, _, _) = u[1]+20
1111
NUM_TIMES_EFFECT_HIT::Int = 0
1212
function affect!(integrator)
1313
NUM_TIMES_EFFECT_HIT += 1
@@ -19,7 +19,14 @@ function auto_converge_check(prob::ODEProblem, ic, p::NamedTuple)::Bool
1919
save_positions = (true, false))
2020
sol = solve(prob, Tsit5(), u0=ic, p=p, tspan=(0.0, 10.0), maxiters=1e9,
2121
save_everystep=false, save_start=false, save_end=false, callback=cb)
22-
error = sol[end] - sol[1]
22+
if length(sol) < 2
23+
# Run simulation and report max and min voltage
24+
sol = solve(prob, Tsit5(), u0=ic, p=p, tspan=(0.0, 10.0), maxiters=1e9)
25+
println("Max V: ", maximum(sol[1,:]))
26+
println("Min V: ", minimum(sol[1,:]))
27+
else
28+
error = sol[end] - sol[1]
29+
end
2330
return sum(abs.(error))<1e-6
2431
end
2532

@@ -39,7 +46,7 @@ Align the limit cycle in the solution to start at the max of V and fixes the tim
3946
"""
4047
function aligned_sol(lc, prob::ODEProblem, period::Number; save_only_V::Bool = true)
4148
# Use callbacks to find state at start of period (using upcrossings of V=0mV)
42-
condition(u, _, _) = u[1]
49+
condition(u, _, _) = u[1]+20
4350
function affect!(integrator)
4451
terminate!(integrator)
4552
end

0 commit comments

Comments
 (0)