f: array of numerical state at the interface between two cells
function wenoL(n,u,f)
a = Array{Float64}(undef, n)
b = Array{Float64}(undef, n)
c = Array{Float64}(undef, n)
r = Array{Float64}(undef, n)
i=1
v1 = 3.0*u[i] - 2.0*u[i+1]
v2 = 2.0*u[i] - u[i+1]
v3, v4, v5 = u[i], u[i+1], u[i+2]
f[i] = wcL(v1,v2,v3,v4,v5)
i=2
v1 = 2.0*u[i-1] - u[i]
v2, v3, v4, v5 = u[i-1], u[i], u[i+1], u[i+2]
f[i] = wcL(v1,v2,v3,v4,v5)
for i = 3:n-1
v1, v2, v3, v4, v5 = u[i-2], u[i-1], u[i], u[i+1], u[i+2]
f[i] = wcL(v1,v2,v3,v4,v5)
end
i=n
v1, v2, v3, v4 = u[i-2], u[i-1], u[i], u[i+1]
v5 = 2.0*u[i+1]-u[i]
f[i] = wcL(v1,v2,v3,v4,v5)
end
```
We also use the periodic boundary condition for the same problem. For periodic boundary condition, we do not need to use any interpolation formula to compute the variable at ghost points. The periodic boundary condition for two left and right side points outside the domain is given below

✝ ✆

$$
\mu\_{-2} = \mu\_{N-1}, \quad \mathfrak{u}\_{-1} = \mathfrak{u}\_N, \quad \mathfrak{u}\_{N+2} = \mathfrak{u}\_2, \quad \mathfrak{u}\_{N+3} = \mathfrak{u}\_3. \tag{43}
$$

where *u* is stored from 1 to *N* + 1 from left (*x* = 0) to right (*x* = *L*) boundary on the computational domain, respectively.

The evolution of shock generated from sine wave with time is shown in Figure 8 for both Dirichlet and periodic boundary conditions. We use the domain between *x* ∈ [0, 1] and divide it into 200 grids. We use the time step Δ*t* = 0.0001 and integrate the solution from *t* = 0 to *t* = 0.25. We save snapshots of the solution field at different time steps to see the evolution of the shock. It can be seen from Figure 8 that the WENO-5 scheme is able to capture the shock formed at *x* = 0.5 at final time *t* = 0.25.

**Figure 8.** Evolution of shock with time for the initial condition *u*<sup>0</sup> = sin(2*πx*) using WENO-5 scheme.

#### *3.2. Compact Reconstruction WENO-5 Scheme*

The main drawback of the WENO-5 scheme is that we have to increase the stencil size to get more accuracy. Compact reconstruction of WENO-5 scheme has been developed that uses smaller stencil without reducing the accuracy of the solution [25]. CRWENO-5 scheme uses compact stencils as their basis to calculate the left and right side state at the interface. The procedure for CRWENO-5 is similar to the WENO-5 scheme. However, its candidate stencils are implicit and hence smaller stencils can be used to get the same accuracy. The implicit system used to compute the left and right side state is given below

$$\begin{aligned} \left(\frac{2}{3}w\_1^L + \frac{1}{3}w\_2^L\right)u\_{i-\frac{1}{2}}^L + \left[\frac{1}{3}w\_1^L + \frac{2}{3}(w\_2^L + w\_3^L)\right]u\_{i+\frac{1}{2}}^L + \frac{1}{3}w\_3^L u\_{i+\frac{3}{2}}^L &= \\ \frac{w\_1^L}{6}u\_{i-1} + \frac{5(w\_1^L + w\_2^L) + w\_3^L}{6}u\_i + \frac{w\_2^L + 5w\_3^L}{6}u\_{i+1}, \\ \frac{1}{3}w\_3^R u\_{i-\frac{1}{2}}^R + \left[\frac{1}{3}w\_1^R + \frac{2}{3}(w\_2^R + w\_3^R)\right]u\_{i+\frac{1}{2}}^R + \left(\frac{2}{3}w\_1^R + \frac{1}{3}w\_2^R\right)u\_{i+\frac{3}{2}}^R &= \\ \frac{w\_1^R}{6}u\_{i-1} + \frac{5(w\_1^R + w\_2^R) + w\_3^R}{6}u\_i + \frac{w\_2^R + 5w\_3^R}{6}u\_{i+1}. \end{aligned} \tag{45}$$

where the nonlinear weights are calculated using Equations (36) and (37), in which the linear weights are given by *d<sup>L</sup>* <sup>0</sup> = 1/5, *<sup>d</sup><sup>L</sup>* <sup>1</sup> = 1/2, and *<sup>d</sup><sup>L</sup>* <sup>2</sup> = 3/10 in Equation (36), and *<sup>d</sup><sup>R</sup>* <sup>0</sup> = 3/10, *<sup>d</sup><sup>R</sup>* <sup>1</sup> = 1/2, and *<sup>d</sup><sup>R</sup>* <sup>2</sup> = 1/5 in Equation (37). The smoothness indicators are computed using Equations (38)–(40). The tridiagonal system formed using Equations (44) and (45) can be solved using the Thomas algorithm with *O*(*N*) complexity, where *N* is the total number of grid points. In our implementation of CRWENO-5 scheme, we write a function that takes *u* in the candidate stencil (i.e., *ui*−2, *ui*−1, *ui*, *ui*+1, *ui*+2) and computes all coefficients in Equations (44) and (45). The implementation of Julia function to compute the coefficients of tridiagonal system for reconstruction of left side state is given in Listing 9. A similar function can be implemented for right side state also.

**Listing 9.** Implementation of Julia function to compute coefficients used for forming the implicit system in computation of left side numerical state at the interface. ✞ ☎

```