@@ -7,7 +7,7 @@ using .Model
77# Check all variables are converged automatically
88function 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
2431end
2532
@@ -39,7 +46,7 @@ Align the limit cycle in the solution to start at the max of V and fixes the tim
3946"""
4047function 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