7. Masks
Immersed-boundary solvers keep solid cells in the field, and the integrator must leave them alone. Every kernel, and every stepper call, takes an optional mask: an array with the field's bounds and one or more components. A cell is active where the mask is negative, as with ADAM's level-set distance
fortran
! the mask has the field's bounds and one component; a cell is active (fluid) where mask < 0
allocate(mask(1:1, 0:NI+1, 0:2, 0:2, 1:NB))
mask = -1._R_P
mask(:,:,:,:,3) = 1._R_P ! block 3 is solidfortran
call st%begin_step(bx, q, mask=mask)
do k=1, st%stages()
call st%begin_stage(k, bx, dt, q, mask=mask)
r => st%rhs_register()
call fill_ghosts(q)
call residual(q, r, dx) ! computed everywhere: the stepper masks the update
call st%end_stage(k, bx, dt, q, mask=mask)
enddo
call st%finish_step(bx, dt, q, mask=mask)- Pass the same mask to all four calls.
begin_stepcopiesonly where it is active, and finish_stepupdates only there. - With several mask components,
mask_comp=picks one; the default is the last (ADAM's "all solids" summary). - The residual can be computed everywhere: whatever it holds in solid cells, the masked update ignores.
Running it
fortran
do b=1, NB
print '(A,I0,A,I2,A,I0,A)', 'block ', b, ': ', count(q(1,1:NI,1,1,b) /= q0(1,1:NI,1,1,b)), ' of ', NI, &
' cells changed'//trim(merge(' (solid)', ' ', b == 3))
enddotext
$ masks
block 1: 16 of 16 cells changed
block 2: 16 of 16 cells changed
block 3: 0 of 16 cells changed (solid)
block 4: 16 of 16 cells changedBlock 3 kept every value bit for bit.
What you learned
Masks: the sign convention, the component, and that they apply to every stepper call. Reference: Concepts: masks.
Next: 8. The flux register.