76
76
K, = p
77
77
return [0.1 + 5.0 * (X^ 3 )/ (X^ 3 + K^ 3 ) - 1.0 * X]
78
78
end
79
- bprob_BK = BifurcationProblem (bistable_switch_BK, [1.0 ], [2.5 ], (@lens _[1 ]); record_from_solution = (x, p) -> x[1 ])
79
+ bprob_BK = BifurcationProblem (bistable_switch_BK, [1.0 ], [2.5 ], (BifurcationKit . @optic _[1 ]); record_from_solution = (x, p; k ... ) -> x[1 ])
80
80
81
81
# Check the same function have been generated.
82
82
bprob. u0 == bprob_BK. u0
230
230
231
231
# Attempts to build a BifurcationProblem.
232
232
@test_throws Exception BifurcationProblem (rn, u0_guess, p_start, :p )
233
- end
233
+ end
234
+
235
+ # Tests the bifurcation when one of the parameters depends on another parameter, initial condition, etc.
236
+ let
237
+ rn = @reaction_network begin
238
+ @parameters k ksq = k^ 2 ratechange
239
+ (k, ksq), A <--> B
240
+ end
241
+
242
+ rn = complete (rn)
243
+ u0_guess = [:A => 1. , :B => 1. ]
244
+ p_start = [:k => 2. ]
245
+
246
+ bprob = BifurcationProblem (rn, u0_guess, p_start, :k ; plot_var = :A , u0 = [:A => 5. , :B => 3. ])
247
+ p_span = (0.1 , 6.0 )
248
+ opts_br = ContinuationPar (dsmin = 0.0001 , dsmax = 0.001 , ds = 0.0001 , max_steps = 10000 , p_min = p_span[1 ], p_max = p_span[2 ], n_inversion = 4 )
249
+ bif_dia = bifurcationdiagram (bprob, PALC (), 2 , (args... ) -> opts_br; bothside = true )
250
+ plot (bif_dia, xlabel = " k" , ylabel = " A" , xlims = (0 , 6 ), ylims= (0 ,8 ))
251
+
252
+ xs = getfield .(bif_dia. γ. branch, :x )
253
+ ks = getfield .(bif_dia. γ. branch, :param )
254
+ # @test @. 8 * (ks / (ks + ks^2)) ≈ xs
255
+
256
+ # Test that parameter updating happens correctly in ODESystem
257
+ t = default_t ()
258
+ kval = 4.
259
+ @parameters k ksq = k^ 2 tratechange = 10.
260
+ @species A (t) B (t)
261
+ rxs = [(@reaction k, A --> B), (@reaction ksq, B --> A)]
262
+ ratechange = (t == tratechange) => [k ~ kval]
263
+ u0 = [A => 5. , B => 3. ]
264
+ tspan = (0.0 , 30.0 )
265
+ p = [k => 1.0 ]
266
+
267
+ @named rs2 = ReactionSystem (rxs, t, [A, B], [k, ksq, tratechange]; discrete_events = ratechange)
268
+ rs2 = complete (rs2)
269
+
270
+ oprob = ODEProblem (rs2, u0, tspan, p)
271
+ sol = OrdinaryDiffEq. solve (oprob, Tsit5 (); tstops = 10.0 )
272
+ xval = sol. u[end ][1 ]
273
+ @test isapprox (xval, 8 * (kval / (kval + kval^ 2 )), atol= 1e-3 )
274
+ end
0 commit comments