339
339
# the values of relevant quantities are correct after each step.
340
340
# Generally, if `Γ` has not been explicitly updated, it will be updated to acomodate new species
341
341
# values. If it has been explicitly updated, the corresponding eliminated quantity will have its
342
- # value updated to acomodate new Γ/species values (also, the eliminated species's value can not longer be changed ).
342
+ # value updated to acomodate new Γ/species values (however, we have to manually designate this by setting it to `nothing` ).
343
343
# Also checks that quantities are correctly updated in integrators and solutions derived from problems.
344
344
let
345
345
# Prepares the problem inputs and computes the conservation equation.
362
362
# - Only that species and the conservation constant have their values updated.
363
363
# The `≈` is because sometimes the computed values will not be fully exact.
364
364
for _ = 1 : 3
365
- # Updates X2, checks the values of all species and Γ, then sets which is the old problem .
365
+ # Updates X2, checks the values of all species and Γ, then resets `prob_old` .
366
366
X2_new = rand (rng, 1.0 : 10.0 )
367
367
prob_new = remake (prob_old; u0 = [:X2 => X2_new])
368
368
@test prob_old[:X1 ] ≈ prob_new[:X1 ]
371
371
@test substitute (conserved_quantity, Dict ([X1 => prob_old[X1], X2 => X2_new, X3 => prob_old[X3]])) ≈ prob_new. ps[:Γ ][1 ]
372
372
prob_old = prob_new
373
373
374
- # Updates X3, checks the values of all species and Γ, then sets which is the old problem .
374
+ # Updates X3, checks the values of all species and Γ, then resets `prob_old` .
375
375
X3_new = rand (rng, 1.0 : 10.0 )
376
376
prob_new = remake (prob_old; u0 = [:X3 => X3_new])
377
377
@test prob_old[:X1 ] ≈ prob_new[:X1 ]
@@ -398,35 +398,37 @@ let
398
398
# Similarly, but now also updates the conservation constant. Here, once Γ has been updated:
399
399
# - The conservation law constant will be kept fixed, and secondary updates are made to the
400
400
# eliminated species.
401
- # Assumes that X3 is the eliminated species.
401
+ # Assumes that X3 is the eliminated species. In most updates, designate its as `nothing` (to
402
+ # ensure that its value is updated to acommodate the new conservation law).
402
403
# The random Γ is ensured to be large enough not to generate negative values in the eliminated species.
403
404
for _ in 1 : 3
404
- # Updates Γ, checks the values of all species and Γ, then sets which is the old problem .
405
+ # Updates Γ, checks the values of all species and Γ, then resets `prob_old` .
405
406
Γ_new = substitute (conserved_quantity, Dict ([X1 => prob_old[X1], X2 => prob_old[X2], X3 => 0 ])) + rand (rng, 0.0 : 5.0 )
406
- prob_new = remake (prob_old; p = [:Γ => [Γ_new]])
407
+ prob_new = remake (prob_old; u0 = [ :X3 => nothing ], p = [:Γ => [Γ_new]])
407
408
@test prob_old[:X1 ] ≈ prob_new[:X1 ]
408
409
@test prob_old[:X2 ] ≈ prob_new[:X2 ]
409
410
@test Γ_new ≈ prob_new. ps[:Γ ][1 ]
410
411
@test substitute (conserved_quantity, Dict ([X1 => prob_old[X1], X2 => prob_old[X2], X3 => prob_new[X3]])) ≈ prob_new. ps[:Γ ][1 ]
411
412
prob_old = prob_new
412
413
413
- # Updates X1 (non-eliminated species), checks the values of all species and Γ, then sets which is the old problem .
414
- # Note that now, `X3` will have its value modified (not and `Γ` remains unchanged).
414
+ # Updates X1 (non-eliminated species), checks the values of all species and Γ, then resets `prob_old` .
415
+ # Note that now, `X3` will have its value modified (and `Γ` remains unchanged).
415
416
X1_new = rand (rng, 1.0 : 10.0 )
416
- prob_new = remake (prob_old; u0 = [:X1 => X1_new])
417
+ prob_new = remake (prob_old; u0 = [:X1 => X1_new, :X3 => nothing ])
417
418
@test X1_new ≈ prob_new[:X1 ]
418
419
@test prob_old[:X2 ] ≈ prob_new[:X2 ]
419
420
@test prob_old. ps[:Γ ][1 ] ≈ prob_new. ps[:Γ ][1 ]
420
421
@test substitute (conserved_quantity, Dict ([X1 => X1_new, X2 => prob_old[X2], X3 => prob_new[X3]])) ≈ prob_new. ps[:Γ ][1 ]
421
422
prob_old = prob_new
422
423
423
- # Updates X3 (the eliminated species). Right now, this will have no effect on `X3` (or the system).
424
+ # Updates X3 (the eliminated species). Since we reset Γ, this has its value modified to
425
+ # accommodate the new value of X3.
424
426
X3_new = rand (rng, 1.0 : 10.0 )
425
- prob_new = remake (prob_old; u0 = [:X3 => X3_new])
427
+ prob_new = remake (prob_old; u0 = [:X3 => X3_new], p = [ :Γ => nothing ] )
426
428
@test prob_old[:X1 ] ≈ prob_new[:X1 ]
427
429
@test prob_old[:X2 ] ≈ prob_new[:X2 ]
428
- @test prob_old[ :X3 ] ≈ prob_new[:X3 ]
429
- @test prob_old. ps[ :Γ ][ 1 ] ≈ prob_new. ps[:Γ ][1 ]
430
+ @test X3_new ≈ prob_new[:X3 ]
431
+ @test substitute (conserved_quantity, Dict ([X1 => prob_old[X1], X2 => prob_old[X2], X3 => X3_new])) ≈ prob_new. ps[:Γ ][1 ]
430
432
prob_old = prob_new
431
433
432
434
# Checks that integrator and solutions have identical content to problem.
0 commit comments