Afivo  0.3
Boundary conditions

Introduction

Unless a computational domain is fully periodic, there will be physical boundaries. Afivo implements boundary conditions using ghost cells, see Filling ghost cells. Currently, Dirichlet and Neumann type boundary conditions are supported. An example of how to fill boundary conditions is given in boundary_conditions_2d.f90 and boundary_conditions_3d.f90.

Writing a boundary condition routine

When filling ghost cells, see Filling ghost cells, the user has to provide a routine that will be called near physical boundaries. The interface of this routine is given by a2_types::a2_subr_bc and a3_types::a3_subr_bc. An example is shown below:

subroutine boundary_method(box, nb, iv, bc_type)
type(box2_t), intent(inout) :: box ! Box to operate on
integer, intent(in) :: nb ! Direction for the boundary condition
integer, intent(in) :: iv ! Index of variable
integer, intent(out) :: bc_type ! Type of boundary condition
integer :: nc
nc = box%n_cell
! Below the solution is specified in the approriate ghost cells
select case (nb)
case (a2_neighb_lowx) ! Lower-x direction
bc_type = af_bc_dirichlet
box%cc(0, 1:nc, iv) = 1.0_dp
case (a2_neighb_highx) ! Higher-x direction
bc_type = af_bc_neumann
box%cc(nc+1, 1:nc, iv) = 0.0_dp
case (a2_neighb_lowy) ! Lower-y direction
bc_type = af_bc_dirichlet
box%cc(1:nc, 0, iv) = 1.0_dp
case (a2_neighb_highy) ! Higher-y direction
bc_type = af_bc_neumann
box%cc(1:nc, nc+1, iv) = 0.0_dp
end select
end subroutine boundary_method

Note that the user method fills ghost cells on the sides of a box, but not corners. For example, for a boundary condition in the lower-x direction, the cells with indices (0, 1:nc) need to be filled.