The gradient operator is the sum of internal and boundary contributions. For boundary faces, if they are Dirichlet faces, then we use the Dirichlet value to compute the difference, otherwise the gradient is set to zero, which corresponds to a no flow condition.
We define the function that return values on faces using cells' values and upwind directions. For boundary faces when the upwind direction require to take value from the outside, if the face is a Dirichlet face, then we take the Dirichlet value otherwise we take the value of the neighboring cell.
We define the function that return values on faces defined as the average of neighboring cells. For boundary faces, we use the value of the neighboring cell if it is not a Dirichlet cell or the average of this value and the Dirichlet face value. The Dirichlet face values are specified with bc_bal.