339339# the values of relevant quantities are correct after each step.
340340# Generally, if `Γ` has not been explicitly updated, it will be updated to acomodate new species
341341# 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` ).
343343# Also checks that quantities are correctly updated in integrators and solutions derived from problems.
344344let
345345 # Prepares the problem inputs and computes the conservation equation.
362362 # - Only that species and the conservation constant have their values updated.
363363 # The `≈` is because sometimes the computed values will not be fully exact.
364364 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` .
366366 X2_new = rand (rng, 1.0 : 10.0 )
367367 prob_new = remake (prob_old; u0 = [:X2 => X2_new])
368368 @test prob_old[:X1 ] ≈ prob_new[:X1 ]
371371 @test substitute (conserved_quantity, Dict ([X1 => prob_old[X1], X2 => X2_new, X3 => prob_old[X3]])) ≈ prob_new. ps[:Γ ][1 ]
372372 prob_old = prob_new
373373
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` .
375375 X3_new = rand (rng, 1.0 : 10.0 )
376376 prob_new = remake (prob_old; u0 = [:X3 => X3_new])
377377 @test prob_old[:X1 ] ≈ prob_new[:X1 ]
@@ -398,35 +398,37 @@ let
398398 # Similarly, but now also updates the conservation constant. Here, once Γ has been updated:
399399 # - The conservation law constant will be kept fixed, and secondary updates are made to the
400400 # 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).
402403 # The random Γ is ensured to be large enough not to generate negative values in the eliminated species.
403404 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` .
405406 Γ_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]])
407408 @test prob_old[:X1 ] ≈ prob_new[:X1 ]
408409 @test prob_old[:X2 ] ≈ prob_new[:X2 ]
409410 @test Γ_new ≈ prob_new. ps[:Γ ][1 ]
410411 @test substitute (conserved_quantity, Dict ([X1 => prob_old[X1], X2 => prob_old[X2], X3 => prob_new[X3]])) ≈ prob_new. ps[:Γ ][1 ]
411412 prob_old = prob_new
412413
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).
415416 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 ])
417418 @test X1_new ≈ prob_new[:X1 ]
418419 @test prob_old[:X2 ] ≈ prob_new[:X2 ]
419420 @test prob_old. ps[:Γ ][1 ] ≈ prob_new. ps[:Γ ][1 ]
420421 @test substitute (conserved_quantity, Dict ([X1 => X1_new, X2 => prob_old[X2], X3 => prob_new[X3]])) ≈ prob_new. ps[:Γ ][1 ]
421422 prob_old = prob_new
422423
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.
424426 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 ] )
426428 @test prob_old[:X1 ] ≈ prob_new[:X1 ]
427429 @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 ]
430432 prob_old = prob_new
431433
432434 # Checks that integrator and solutions have identical content to problem.
0 commit comments