8. The flux register
On an AMR grid, a coarse cell next to a fine level is updated with the coarse flux through the shared face. The fine level computes its own, more accurate fluxes. To keep the scheme conservative, the solver accumulates the difference over the step in a flux register and corrects the coarse cell afterwards (refluxing).
With a Runge–Kutta step, "the flux over the step" is a weighted sum of the stage fluxes, and the weights are the scheme's
stage_weight(k) returns
! the flux register accumulates F_right - F_left of stage k, with the stage's effective weight
flux_w = flux_w + st%stage_weight(k) * boundary_flux(u)
flux_u = flux_u + boundary_flux(u) / st%stages() ! the wrong weights: uniform, for comparisonThe program advects a profile with inflow on the left and outflow on the right. For each stage it adds the stage's net boundary flux, once with stage_weight(k) and once with uniform weights
Running it
$ flux_register
mass change + dt sum_k stage_weight(k) flux_k: 4.50E-16
the same with uniform weights 1/s: 3.60E-06With stage_weight the identity holds to round-off. With uniform weights it misses by the size of the time error, which is how a refluxed AMR solver silently stops conserving.
What you learned
stage_weight(k) is the weight of stage k in the step's fluxes, in every form. Reference: Stepper, P4 Conservation, Cookbook: AMR.
Next: 9. On the GPU.