If $u_t+a \cdot u_x=0$ under a periodic boundary condition (to mimic an infinite domain) is solved by Discontinuous Galerkin (DG), how to implement periodic boundary condition and the other details in DG?
1 Answer
You can implement the boundary condition topologically. In pseudo-code this might look something like:
# I'm assuming 0-based indexing in 1D, adjust accordingly for 1-based indexing
for every element i:
if i == 0:
left_element = nelems - 1
else:
left_element = i - 1
if i == nelems - 1:
right_element = 0
else:
right_element = i + 1
compute_dg_update(left_element, i, right_element)
If you want to uniquely pre-compute the numerical flux instead of recomputing it in an element-based update, you would compute the numerical flux only for left faces (or only right faces, but not both). Then the numerical flux for the right face of element $\mathrm{nelems}-1$ would be the flux computed for the left face of element $0$ (vise-versa if you instead computed the flux at the right faces).
A third way to implement periodic boundary conditions is by using "ghost values". You can initialize your storage array to hold elements $[-1, \mathrm{nelems}]$, then copy the values in element $\mathrm{nelems}-1$ to element $-1$, and copy element $0$ to element $\mathrm{nelems}$. You then only update the solution for elements $[0, \mathrm{nelems}-1]$ using DG. This method generalizes well when you want to partition your domain for MPI parallelism since the periodic BC is handled almost seamlessly by the same code which handles regular sub-partition coupling.