AMR
Reflux with stage_weight
At a face where two sides compute different fluxes (a coarse and a fine level, two solvers coupled), conservation needs one side corrected with the other's flux, summed over the step with the stage weights. Accumulate the difference inside each stage window, and apply it once after finish_step.
fortran
reg = 0._R_P ! the flux register of the shared face, zeroed per step
call st%begin_step(bx, q)
do k=1, st%stages()
call st%begin_stage(k, bx, dt, q)
u => st%stage_state() ; r => st%rhs_register()
call fill_ghosts(u)
call residual(u, r, dx) ! block 1: central flux; block 2: upwind flux at the face
reg = reg + st%stage_weight(k) * (face_flux_2(u) - face_flux_1(u)) ! fine minus coarse, weighted
call st%end_stage(k, bx, dt, q)
enddo
call st%finish_step(bx, dt, q)
drift_before = max(drift_before, abs(mass(q) - m0))
q(1,NI,1,1,1) = q(1,NI,1,1,1) - dt / dx * reg ! reflux: block 1's last cell takes block 2's flux
drift_after = max(drift_after, abs(mass(q) - m0))text
$ cookbook_amr reflux
mass drift without the correction: 5.51E-04
mass drift with it: 2.22E-16- The register is zeroed at the start of each step and accumulated with
stage_weight(k), in every Runge–Kutta form (the low-storage forms included: their weights are derived). - The correction replaces block 1's flux through the shared face with block 2's:
. - Accumulate from the stage state, in the window between
begin_stageandend_stage, after the ghost fill: the flux of stagekis the flux of the state of stagek.
Fill the ghost cells from the stage state
The ghost cells of a stage are a function of the neighbours' stage state. Filling them from the neighbours'
fortran
if (right) then
call fill_ghosts(u) ! from the neighbours' stage state: right
else
call fill_ghosts_from(u, q) ! from the neighbours' q^n: a stale exchange
endiftext
$ cookbook_amr ghosts
ghosts from the stage state: observed order 4.00
ghosts from q^n (wrong): observed order 1.14In a multi-block or MPI solver, the exchange happens inside the stage window, on the arrays stage_state() (or q, when stage_state_is_q(k)) of every block.