r: right hand side of Burgers equation r = -udu/dx
function rhs(nx,dx,u,r)
uL = Array{Float64}(undef, nx) # left side state
uR = Array{Float64}(undef, nx+1) # right side~state
wenoL(nx,u,uL) # compute left side state at the interface
wenoR(nx,u,uR) # compute right side state at the~interface
for i = 2:nx
if (u[i] >= 0.0)
r[i] = -u[i]*(uL[i] - uL[i-1])/dx
else
r[i] = -u[i]*(uR[i+1] - uR[i])/dx
end
end
end
```
We demonstrate two types of boundary conditions for the inviscid Burgers equation. The first one is the Dirichlet boundary condition. For Dirichlet boundary condition, we use *u*(*x* = 0) = 0 and *u*(*x* = 1) = 0. For computing numerical state at the interface, we need the information of five neighboring grid points (see Figure 7). When we compute the left side state at *i* + <sup>1</sup> <sup>2</sup> interface, we use three points on left side (i.e., *ui*−2, *ui*−1, *ui*) and two points on right side (i.e., *ui*+1, *ui*+2). Therefore, we use two ghost points on the left side of the domain and one ghost point on right side of the domain for computing left side state (i.e., *<sup>u</sup><sup>L</sup>* at *<sup>x</sup>* <sup>=</sup> 3/2 and *<sup>x</sup>* <sup>=</sup> *<sup>N</sup>* <sup>−</sup> 1/2 respectively). Similarly, we use one ghost points on the left side of the domain and two ghost point on right side of the domain for computing right side state (i.e., *<sup>u</sup><sup>R</sup>* at *<sup>x</sup>* <sup>=</sup> 3/2 and *<sup>x</sup>* <sup>=</sup> *<sup>N</sup>* <sup>−</sup> 1/2 respectively). We use linear interpolation to compute the value of discrete field *u* at ghost points. The computation of *u* at ghost points is given below

✝ ✆

$$
\mu\_{-2} = \mathfrak{A}\mathfrak{u}\_1 - 2\mathfrak{u}\_2, \qquad \mathfrak{u}\_{-1} = 2\mathfrak{u}\_1 - \mathfrak{u}\_2. \tag{41}
$$

$$
\mu\_{N+3} = 3\mu\_{N+1} - 2\mu\_{N\prime} \quad \mu\_{N+2} = 2\mu\_{N+1} - \mu\_{N\prime} \tag{42}
$$

where *u* is stored from 1 to *N* + 1 from left (*x* = 0) to right boundary (*x* = *L*) on the computational domain respectively (The default indexing in Julia for an Array starts with 1). The Julia function to select the stencil for left side state calculation is given in Listing 8. A similar function is also used for selecting the stencil for right side state calculation.

**Listing 8.** Implementation of Julia function to select the stencil for computing left side numerical state at the interface for Dirichlet boundary condition. ✞ ☎

```