## 1. Introduction

The Taylor–Goldstein (T-G) equation describes the stability of a Boussinesq stratified shear flow under inviscid and nondiffusive conditions (Taylor 1931; Goldstein 1931; Liu 2010; Smyth and Carpenter 2019). It is a second-order ordinary differential equation whose solutions exhibit singularity at critical levels (where the speed of the mean current matches the phase velocity). The singular behavior arises from the neglect of viscosity, diffusion and nonlinearity in the equations of motion (Maslowe 1986), and makes the T-G equation a challenge to solve numerically. Several well-known theorems, such as the Rayleigh inflection point criterion (Rayleigh 1880), Fjørtoft’s condition (Fjørtoft 1950), the Miles–Howard theorem (Miles 1961; Howard 1961), and Howard’s semicircle theorem (Howard 1961), allow us to predict certain aspects of instability without solving the T-G equation, but the information they give is far from complete. One alternative is to use a numerical shooting method together with asymptotic matching to cross singularities (Hazel 1972; Smyth and Peltier 1989; Rees and Monahan 2014). Another is to retain the viscous and diffusive effects. Liu et al. (2012) extended the T-G equation to include vertical and horizontal eddy coefficients of viscosity and diffusivity, allowing those coefficients to vary with height. The resulting viscous T-G (vT-G) equation set (described below) is useful for modeling naturally occurring flows. It is nonsingular, but it is higher order than the T-G equation.

The focus of this paper is numerical methods for the vT-G equations, specifically matrix-based methods. Matrix methods are slower than shooting methods for a given accuracy but are useful in practice because they do not rely on an initial guess. We will compare several commonly used methods to seek the most efficient way to get a solution with a prescribed level of accuracy.

## 2. The viscous Taylor–Goldstein problem

**k**evolving on a horizontal background flow

**U**

_{h}= {

*u*(

*z*),

*υ*(

*z*)}, mode evolution is determined solely by the component of the background flow parallel to the wave vector:

*U*(

*z*) is disturbed by the vertical velocity perturbation

*w*′ and the buoyancy perturbation

*b*′. The buoyancy is defined as

*b*=

*g*(

*ρ*

_{0}−

*ρ*)/

*ρ*

_{0}, where

*g*is the acceleration due to gravity, and

*ρ*

_{0}is a characteristic value of the density

*ρ*. We decompose the density as

*b*=

*B*(

*z*) +

*b*′, where

*b*′ = −

*gρ*′/

*ρ*

_{0}(see appendix E). The perturbations can be expressed as the normal mode

*σ*=

*σ*

_{r}+

*ισ*

_{ι}is the complex growth rate, subscripts

*r*and

*i*indicate the real and imaginary parts,

*x*is the horizontal coordinate parallel to the wave vector. We include the effects of viscosity and diffusivity, which may either be molecular in origin or result from turbulence on spatial scales much smaller than the wave scale

*k*

^{−1}. Following Liu et al. (2012), the viscosity and diffusivity have separate horizontal (

*A*

_{h},

*K*

_{h}) and vertical (

*A*

_{υ},

*K*

_{υ}) parts, and are allowed to vary in the vertical. The linearized normal-mode equations are then

*A*

_{h}=

*K*

_{h}=

*A*

_{υ}=

*K*

_{υ}= 0, the vT-G equations [Eqs. (1) and (2)] become the conventional T-G equation.

Specification of the problem is completed by the imposition of boundary conditions at the upper and lower boundaries, which may in principle be at infinity. Each boundary is assumed to be impermeable

## 3. Numerical methods

*σ*for given profiles of

*U*(

*z*),

*B*(

*z*),

*A*

_{υ}(

*z*),

*A*

_{h}(

*z*),

*K*

_{υ}(

*z*),

*K*

_{h}(

*z*), and wavenumber

*k*. We begin by defining grid points

*z*

_{i}(

*i*= 1, …,

*N*), which may or may not be evenly spaced (appendix A). We then define derivative matrices

*K*th derivative of a discretized function

*f*

_{i}=

*f*(

*z*

_{i}) is represented by

*N*× 2

*N*matrices and the eigenvector

**x**is the concatenation of the elements of the discretized structure functions

Numerical methods for determining *z*_{i} involves only a few neighboring function values *f*(*z*_{j}). We can then calculate *f* or by differentiating a local polynomial interpolant at *z*_{i} (appendix B). The result is a sparse matrix with bandwidth *J*. The larger *J* is, the higher the order of

In global methods, computing the derivative at any point involves all the *N* nodes in the domain. Here, *N*. Details of the computation of the differentiation matrices are given in the appendixes.

It is important to recognize that higher-order finite-difference methods are designed to be more accurate *in the limit* Δ → 0, where Δ is the grid spacing defined in appendix A. In practice, we make Δ as small as we can with the available resources, but often we are interested in marginally resolved flow features, for example, a layer of strong shear that extends over just a few data points. In this case, there is no guarantee that a higher-order method will be more accurate. This failure of higher-order methods to improve accuracy has been noted previously, for example, by Putrevu and Svendsen (1992).

In some applications, our aim is to approximate the solution of the differential eigenvalue problem as accurately as possible, while in others we try to attain acceptable accuracy while minimizing processing time and memory. Therefore, we will compare methods based on two criteria:

- How quickly does the error of the growth rate (or phase speed) go to zero as
*N*→ ∞? - What is the smallest
*N*needed to achieve a predetermined accuracy, for example, a relative error of 1% in the growth rate?

## 4. Shear instabilities in idealized model flows

Our first goal in solving the vT-G equations is to identify unstable normal modes, or instabilities. We will begin with a profile that is often used in modeling geophysical flows, the hyperbolic tangent shear layer.

### a. Case 1: A homogeneous, inviscid shear layer

In the homogeneous, inviscid limit the vT-G equation reduces to the Rayleigh equation (Rayleigh 1880; Smyth and Carpenter 2019). We consider a hyperbolic tangent shear profile *U* = tanh(*z*) with boundary conditions *z* = ±*H*/2, where *H* is the domain height, chosen to be 10. Further boundary conditions are not needed since *T*_{w} and *T*_{b} drop out of Eqs. (5). For each wavenumber *k*, a matrix-based method (local or global; see appendixes B–D) using *N* grid points delivers 2*N* eigenmodes. We are concerned only with the fastest growing of these eigenmodes, that is, *σ*_{FGM}.

The growth rate is purely real, and is a maximum when *k* = 0.46. As a ground truth for testing the various numerical methods, we use the Fourier–Galerkin method (appendix C) with high resolution *N* = 801 to find the corresponding growth rate *σ*_{0} = 0.184 561 95. This is used as a ground truth, or “target value” to define the relative error, |*σ* − *σ*_{0}|/*σ*_{0}, for each of the other methods tested.

Figure 1 shows the relative error in the growth rate for five methods: the second-, fourth-, and sixth-order finite-difference methods (labeled FD2, FD4 and FD6, respectively) and the Fourier and Chebyshev methods. The number of grid points *N* ranges from 11 to 265. Not surprisingly, all methods become more accurate as *N* is increased. The error in the finite-difference methods decreases according to the order of the method, giving very accurate results at high *N*. At low *N*, however, the difference vanishes. To achieve 1% accuracy in the growth rate requires *N* = 39, 21, and 19 with FD2, FD4, and FD6, respectively. The global methods become extremely accurate at large *N*, but do not perform as well at small *N* (the Chebyshev method especially). The standard of 1% accuracy requires *N* = 29 and 19 with the Chebyshev and Fourier methods, respectively. An investigator desiring <1% error in the growth rate with high efficiency might do well to choose FD6 or the Fourier method. However, FD4 is simpler while giving nearly the same accuracy.

We now show that clustering the grid points in regions of high shear using the methods described in appendix A can improve accuracy significantly, especially when the resolution is coarse (Fig. 2). In general, the clustered grid delivers greatly improved accuracy for all orders of finite-difference methods. The difference is particularly striking at low *N*, where the 1% standard is achieved even for the lowest-order method FD2c, where “c” denotes clustering (not to be confused with the phase speed of internal waves in section 6) and at the lowest resolution tested (*N* = 11).

*a*(see appendix A). This was done by maximizing an improvement index ϒ, which compares the accuracy achieved with a particular clustered grid with that using a uniform grid:

*σ*

_{FD}is the growth rate computed using a particular finite-difference method with uniform grids and

*σ*

_{FDc}is the value obtained using clustered grids.

To illustrate the method, we examine the dependence of ϒ on *a* at *N* = 113 (Fig. 3a). Using method FD2c, accuracy improves steadily as *a* is increased, reaching a maximum at *a* = 0.85. We identify this as the optimal value for FD2c. With method FD4c, the increase is faster and the maximum improvement is found at *a* = 0.60. With method FD6c, maximum improvement is also found at *a* = 0.60, but for higher values of *a*, the rate of improvement decreases approaching zero as the clustering becomes extreme.

We next examine the optimal value of *a* for a range of *N* (Fig. 3b) using second-, fourth-, and sixth-order methods. It is found that the optimal value of *a* for FD2c is constant; for FD4c and FD6c, the optimal value of *a* increases when *N* is small. These results are important because the advantage of the clustered grid method is greatest for coarsely resolved features.

While the above results might suggest using larger values of *a*, one should recall that setting *a* too large can degrade accuracy (Fig. 3a). Conservatism is especially well justified when analyzing observational data, where one may not know a priori the flow structures that the code will encounter. On that basis, we tentatively choose the lower values *a* = 0.85 for FD2c, and *a* = 0.60 for FD4c and FD6c, as in Fig. 2.

*σ*

_{0}, and the overline indicates vertical average. As shown in Figs. 4b and 4c, we normalize the solutions by scaling the maximum magnitude of the vertical velocity eigenfunction to unity. The eigenfunction is symmetric about

*z*= 0, having peaks of equal magnitude on the upper and lower edges of the shear layer. Figure 4d shows the relative error Ψ for the FD methods, the FDc methods, and the Fourier and Chebyshev methods. The FDc methods achieve higher accuracy than the FD methods and global methods, indicating that the clustered grids work for eigenfunction. The Chebyshev method performs better than the Fourier method. This is because the collocation points of the Chebyshev method is symmetric about

*z*= 0, well suitable for this case. We also note that the clustering strength needed to resolve the eigenfunction is smaller than that needed to resolve the growth rate. At

*N*= 11, FD4c method with

*a*= 0.40 can reproduce the eigenfunction (dashed line in Fig. 4c).

### b. Case 2: A stably stratified, inviscid, nondiffusive shear layer

We turn now to an inviscid, nondiffusive, stably stratified fluid for which the parallel shear flow problem reduces to the Taylor–Goldstein equation (Taylor 1931; Goldstein 1931; Smyth and Carpenter 2019). Different numerical methods were tested with a simple case of a shear layer in homogeneous fluid in the previous section. Earth’s oceans and atmosphere, however, tend to be density stratified. It is thus critical to make sure these methods also work well for stratified shear flows.

_{b}is the bulk Richardson number characterizing the strength of the stratification relative to the shear. Differentiating

*B*(

*z*), we have the squared buoyancy frequency

_{b}= 0.15 and assume that

*z*= ±

*H*/2 and

*H*= 10. The target growth rate

*σ*

_{0}is smaller than that in case 1 (Fig. 5), meaning that shear flow is stabilized by stratification.

We now repeat the calculations for which results were shown in Figs. 1–3. In this case the FDc methods are always more accurate than the FD methods. We therefore neglect the latter and compare the different order FDc methods with the Fourier and Chebyshev methods in Fig. 5. Except at high *N*, FDc methods achieve higher accuracy than the Fourier and Chebyshev methods, with the FD4c method performing best. The optimal values of *a* are similar to those found in the unstratified case, though not exactly the same (Fig. 5, legend). Once again, high-order FDc methods work best with smaller *a*.

### c. Case 3: A homogeneous, stratified shear layer with variable eddy viscosity and diffusivity

*A*

_{υ},

*A*

_{h},

*K*

_{υ}, and

*K*

_{h}. We model this scenario as

*K*

_{υ}=

*A*

_{υ},

*K*

_{h}=

*A*

_{h}). We set Re = 10 and do the same analyses as in previous cases. Boundary conditions are again

*z*= ±

*H*/2 with

*H*= 10. Use of the normal-mode formalism in viscous, diffusive fluid with arbitrary profiles

*U*(

*z*) and

*B*(

*z*) implies the assumption that the instability grows on a fast time scale in contrast with the slow diffusion of the mean profiles, the so-called frozen flow approximation. This generally requires that Re be sufficiently large (Smyth and Carpenter 2019). Here, however, we work with smaller Re to provide a rigorous test of the numerical approximations used.

Figure 6 shows the results. Again, the target growth rate is smaller than that in case 1. This reveals another stabilizing mechanism: shear instability damped by eddy viscosity and diffusion. The clustered finite-difference methods give better accuracy than the global methods at low *N*. At high *N*, the global methods converge rapidly, with the Fourier method outperforming the Chebyshev.

### d. Case 4: Plane Poiseuille flow in homogeneous, viscous fluid

*B*= 0) and

*A*

_{υ}=

*A*

_{h}= 1/Re. We impose rigid boundary conditions:

*z*= 0 and

*z*= 1.

The Chebyshev method with resolution *N* = 101 is used to compute the growth rate as a function of *k* and Re (Fig. 7). For Re > 10^{5}, the maximum growth rate increases with decreasing Re, that is, with increasing viscosity. This is the Tollmien–Schlichting instability (Schlichting and Gersten 2016), an example of a mode that is *destabilized* by viscosity. The growth rate maximum is found at Re = 10^{5} and *k* = 1.55. Figure 8 shows relative errors of the growth rate at the Reynolds number Re = 10^{5}. In this case, both the FDc and Chebyshev methods cluster the grid points in the boundary layers. When resolution is coarse, the strongly clustered FD methods (*a* ≥ 0.9) achieve higher accuracy than the Chebyshev method. The FD6c method performs better than the others. At large *N*, the Chebyshev method converges rapidly. (The Fourier method is omitted because it cannot represent the rigid boundary conditions in the form used here).

To summarize, the numerical methods tested in this paper (see appendixes) compute the growth rate of idealized models of shear instability with varying degrees of accuracy. The accuracy of the finite-difference methods depends on the order of the approximation. When resolution is coarse, clustering the grid in regions of strong shear can confer even higher accuracy than the global Fourier and Chebyshev methods. Most often, higher-order FD methods work best with less clustering (i.e., lower *a*). At high *N*, the Fourier and Chebyshev methods converge most rapidly. Before we make a final assessment of all these methods, tests will be carried out with an observed geophysical flows.

## 5. Shear instabilities in observed oceanic flows

We now demonstrate the application of these methods to observed geophysical flows. Observed flow profiles are considerably more complicated than the idealized models discussed above (e.g., Sun et al. 1998; Liu 2010; Smyth et al. 2011; Liu et al. 2012; Smyth et al. 2013). In what follows, we consider two cases of increasing complexity.

### a. Case 5: Clyde Sea, observed profiles with single shear maximum

*U*=

*V*= 0 at the bottom. The profiles of the squared buoyancy frequency

*N*

^{2}and diffusivity

*K*

_{υ}were obtained from a free-fall yo-yo (FLY) microstructure profiler. The diffusivity

*K*

_{υ}was estimated from the turbulent kinetic energy dissipation rate

*ε*via

*ε*can be directly estimated from FLY’s shear probes signal, and Γ is the flux coefficient, commonly approximated by the constant 0.2 (Gregg et al. 2018). As in case 3, the turbulent coefficients are assumed to be isotropic in the horizontal direction with turbulent Prandtl number unity:

*A*

_{υ}(

*z*) =

*A*

_{h}(

*z*) =

*K*

_{υ}(

*z*) =

*K*

_{h}(

*z*).

Note that the shear profile has five local maxima (excluding boundaries). Only two of these have Ri < 1/4, *z* = 16 m and *z* = 8 m. Eddy viscosity is strong at the latter, likely damping shear instability. We therefore anticipate a single dominant mode with critical level near *z* = 16 m.

**U**

_{h}= {

*u*(

*z*),

*υ*(

*z*)}, we recall that an instability is affected only by the component of the mean flow parallel to its own wave vector

**k**(section 2). Accordingly, we define the angle

*θ*as the direction of the wave vector, measured counterclockwise from due west, and loop over

*θ*= [−90°, 90°]. For each

*θ*, the velocity profile appearing in the vT-G equations is

*λ*= 2

*π*/

*k*= [1, 100] m and ultimately find the direction and wavenumber where the growth rate of the FGM is maximum (Fig. 10, black dot).

To obtain a target value for evaluating different numerical methods, we use the Fourier method with very high resolution, *N* = 801, and thus obtain the following values for the FGM: *θ*_{0} = −54°, *λ*_{0} = 30.880 m (*k*_{0} = 2*π*/*λ*_{0} = 0.2035 m^{−1}), and *σ*_{0} = (6.295 821 + 4.879 614*ι*) × 10^{−3} s^{−1}. The critical level is located at 15.8 m, within the single maximum shear layer.

Figure 11 shows the comparison between the FD methods and the global methods (i.e., the Fourier and Chebyshev methods). At low *N*, no difference is visible between the Fourier and FD methods. The Fourier and FD6 method have higher accuracy than the others at large *N*. The Chebyshev method performs worst, even compared with FD2. This is because the Chebyshev method clusters the grid points near the boundaries, which is inefficient for this case.

We cluster the grid points in the single shear layer and compare the accuracy of the FDc methods of different orders with the FD method on a uniform grid. The FDc method achieves higher accuracy than the FD method (Fig. 12), indicating that the clustered grids work for observed flows. At large *N*, FD6c with *a* = 0.30 performs the best.

### b. Case 6: Clyde Sea, observed profiles with multiple shear maxima

Observed profiles are often more complex than the one shown above, for example, Fig. 13. Conditions for shear instability are evident at several depths; that is, shear magnitude reaches a local maximum (red curve in Fig. 13b), Ri < 1/4 (black dots), and turbulent coefficients are not too large (Fig. 13c). In this case the stability analysis at each (*k*, *θ*) may deliver two or more unstable modes with critical levels close to one of the shear maxima shown in Fig. 13b. We describe a method for dealing with this additional complexity. At each (*k*, *θ*), rather than retain only the fastest growing of the 2*N* eigenmodes, we collect all modes having positive growth rates. After scanning the *k*–*θ* plane, we are typically left with several thousand modes.

Following Smyth et al. (2013), we compute the critical level for each mode and plot a histogram of the results (Fig. 13d). For the case analyzed here, the histogram reveals eight peaks, each of which corresponds roughly to one of the shear maxima shown Fig. 13b. Local minima of the histogram (blue triangles in Fig. 13d) conveniently delineate the set of modes corresponding to each shear maximum. We call these sets *mode families*. Each mode family has its own fastest-growing mode (e.g., pentagrams in Fig. 14a) and critical level (Fig. 14c). The depth of the critical level for each family is approximately independent of wavelength. Eight depths are found and shown by horizontal lines on Fig. 14c. The shallowest critical level, located at *z* = 49 m, is denoted as mode 1. Successive mode families with critical levels at *z* = 45, 31, 23, 19, 12, 7, and 1 m are denoted as modes 2–8, respectively. These mode families represent distinct physical processes (Sun et al. 1998). For example, the uppermost mode family may represent shear at the base of the surface mixed layer, while others might represent breaking depths of the internal wave field. The growth rates of these mode families are shown on Fig. 14a. Three mode families stand out are mode 1, mode 5 and mode 6. The growth rates of their FGMs are 39.31, 39.76, and 34.21 h^{−1}, respectively, so their amplitudes grow by a factor *e* = 2.718 in about 2 min. The corresponding wavelength are 7.78, 12.04, and 25.43 m, about 7 times the thickness of their shear layer, that is, 1, 2, and 4 m.

Figure 15 shows the eigenfunctions of the three dominant modes. The solutions were normalized by scaling the maximum magnitude to unity. The vertical structure of eigenfunctions have significant magnitude at their critical-level depth, while the magnitude decreases to zero away from these layers.

We use mode 6 to test the accuracy of different numerical methods in computing the growth rate of fastest-growing mode *σ*, the wavelength *λ*, the wave vector direction *θ*, and the critical-level height *z*_{c}. All methods converge to the same values (blue arrows in Fig. 16). At large *N*, the FD4c method performs as well as the Fourier–Galerkin method and even better than the Chebyshev method. At low *N*, FD4c achieves the highest accuracy.

## 6. Internal gravity waves in inviscid, nondiffusive fluid

Internal gravity waves arise from the same Eqs. (1) and (2) that describe instabilities. The phase speed of internal gravity waves is *c* = *ισ*/*k* = *c*_{r} + *ιc*_{ι}, where *σ* is the eigenvalue of Eq. (5). Here, we look for the stable wave solutions (*c*_{ι} = 0) and test the abilities of various numerical methods to approximate the phase speed *c*_{r} in the long-wave (or hydrostatic) limit *k* → 0.

We consider a viscous stratified fluid with stratification given by (11) as in case 3 but with Ri_{b} = 1 and no background flow, *U* = 0. Eddy coefficients are uniform and equal: *A*_{υ} = *K*_{υ} = *A*_{h} = *K*_{h} = 1/Re with Re = 10^{10}.

Figure 17 shows the relative error of phase speed. The accuracy of high-order finite-difference methods and global methods is high. Unlike the behavior in Fig. 1, the Fourier method works very well at low *N*. To achieve 1% accuracy, only 12 grid points are required. The FD4, FD6, and Chebyshev methods have similar accuracy at low *N*. These methods all outperform FD2, which requires *N* > 80 to achieve 1% accuracy.

The optimal value of *a* (Fig. 18b) is generally smaller than the values computed for the homogeneous shear layer (case 1; Fig. 2). The phase speed of internal waves does not seem to require highly clustered grid points; in fact, the FD6 method gives better results with no clustering except when the resolution is very coarse (Fig. 18b; compare green and yellow diamonds). We understand this by recalling that, for shear instability, a high value of *a* ensures high resolution around the critical level, where the instability is most likely to occur. The neutral modes found here are not singular and are therefore less tightly localized than the instabilities discussed previously. The Fourier method (black curve on Fig. 17) provides reliably accurate solutions.

## 7. Summary

The conventional Taylor–Goldstein equation is extended to include effects of turbulence represented by the eddy viscosity and diffusivity. The resulting “viscous T-G” (vT-G) equation, together with appropriate boundary conditions, is a linear eigenvalue problem that can be solved using matrix-based methods. We have tested the most commonly used matrix methods including the second-, fourth-, and sixth-order finite-difference methods, the Chebyshev-collocation method, and the Fourier–Galerkin method. The accuracy of the finite-difference method is greatly improved by using adaptive grid spacing.

We have tested these methods using both idealized models and observational data. At high resolution, the global methods (i.e., the Fourier–Galerkin and Chebyshev-collocation methods) converge most rapidly. At coarse resolution, however, the finite-difference methods with optimal grid spacing can achieve higher accuracy than the global methods. The optimal value of clustering strength depends on the order of the methods. High-order finite-difference methods usually need only slight clustering. Overall, we recommend the FD4*c* method with *a* = 0.6 or the FD6*c* method with *a* = 0.4 for sheared flows. If shear is judged to be unimportant, the Fourier–Galerkin method is a reliable alternative.

## Acknowledgments

This work was supported by the National Natural Science Foundation of China (41622601, 91858201, and 41721005), the National Key R&D Program of China (2016YFC1401404), and the U.S. National Science Foundation (OCE-1537000). The project has benefited from discussions with Shuwen Tan and Larry Pratt.

Data availability statement: The codes developed in this study are available on request from W.D.S (bill.smyth@oregonstate.edu) or Z.L. (zyliu@xmu.edu.cn).

## APPENDIX A

### Creation of an Efficient Clustered Grid

Efficient solution of Eqs. (1)–(4) requires an efficient means of discretization; that is, grid spacing can vary with *z* such that the spacing is fine in regions where the solution is expected to vary most rapidly. Since instability tends to be focused in high-shear layers, it is natural to seek for a discretization with clustering in these regions.

*z*

_{B}and

*z*

_{T}:

*s*

_{min}and

*s*

_{max}, respectively. We now define the new grid increment

*a*is an adjustable constant such that 0 ≤

*a*< 1. If

*a*= 0,

*η*

_{i}= Δ; that is, the original uniform grid is recovered. As

*a*→ 1, the clustering becomes extreme. The new grid points are

## APPENDIX B

### The Finite-Difference Method

*a*= 0), the FD method is simple. The (

*i*,

*j*)th component of the derivative matrix,

*f*(

*Z*), as

*j*

_{1}and

*j*

_{2}are identify neighboring grid points around the derivative point

*i*. For example, the fourth-order central finite-difference scheme for first derivatives involves the grid points from

*j*

_{1}=

*i*− 2 to

*j*

_{2}=

*i*+ 2. The stencil width is

*J*=

*j*

_{2}−

*j*

_{1}+ 1 (5, in this case). When

*J*<

*N*, Eq. (B1) is a local method, whereas it is a global method when

*J*=

*N*. The values

*K*th derivative of

*f*(

*Z*) is then given by

**b**such that

**x**is the vector of eigenfunctions as defined in section 3. If the total number of boundary conditions is

*N*

_{bc}, then

*N*

_{bc}× 2

*N*matrix with each row specifying one boundary condition. Similarly,

**b**is an

*N*

_{bc}× 1 column vector. For example, if the boundary condition requires that the first element of

**x**vanish (a homogeneous Dirichlet condition), then the top row of

**b**is 0. If the boundary condition involves derivatives, then

**x**into

**x**

_{k}, the part of

**x**that we will keep, and

**x**

_{r}, the part that we will remove. The decomposition is chosen so that the boundary conditions become

**x**

_{r}can be expressed as a function of

**x**

_{k}:

**b**= 0) and Eq. (B5) is simply

**x**

_{k}, since

**x**

_{r}can be recovered using Eq. (B6). Beginning with the upper part of Eq. (B7),

*σ*and

**x**

_{k}are obtained from Eq. (B8), we can recover

**x**

_{r}using Eq. (B6), and finally assemble the eigenvector

**x**.

## APPENDIX C

### The Chebyshev-Collocation Method

*T*

_{i}(

*c*) = cos[

*i*cos

^{−1}(

*c*)]. We can visualize these points as the projections on [−1, 1] of equispaced points

*z*

_{i}on the upper half of the unit circle (see Fig. 5.1 of Trefethen 2000). They are clustered at boundaries and should be very effective to analyze the boundary layer instability. Substituting Eq. (C1) into Eq. (B3), we get the Chebyshev derivative matrix

*b*

_{j}= 1/2 if

*j*= 1 or

*N*, and

*b*

_{j}= 1 otherwise. The Chebyshev points and matrices are defined on [−1, 1]; they can be extended to [

*Z*

_{B},

*Z*

_{T}] by using

*Z*

_{i}=

*Z*

_{B}+ [(

*Z*

_{T}−

*Z*

_{B})/2](

*c*

_{i}+ 1) and

^{(K)}=

^{(K)}/[(

*Z*

_{T}−

*Z*

_{B})/2]

^{K}.

We find that the collocation method is nothing other than the barycentric Lagrange interpolation based on the Chebyshev collocation points. The boundary conditions can be incorporated using the same approach discussed in the last section.

## APPENDIX D

### The Fourier–Galerkin Method

*F*

_{n}(

*Z*) automatically satisfies the frictionless boundary conditions

*Z*= 0 and

*Z*=

*H*. This choice of basis functions is natural for impermeable, frictionless, constant-buoyancy boundaries, and may be adapted for insulating boundaries by expanding

*F*

_{n}(

*Z*) is expressed by

*δ*_{m,n}is the

*N*×

*N*identity matrix. Substituting Eq. (D1) into Eqs. (1) and (2) gives

*Z*. Using the fact that

^{2}

*F*

_{n}becomes

*D*

_{n}

*F*

_{n}, where

*T*

_{w}

*F*

_{n}and

*T*

_{b}

*F*

_{n}become

*F*

_{m}and integrate, remembering Eq. (D2):

*w*

_{m}

*D*

_{m}and

*b*

_{m}, respectively. Then Eqs. (D5) and (D6) now become the algebraic eigenvalue problem;

*σ*as usual, but the eigenvector is now composed of the coefficients

*w*

_{n}and

*b*

_{n}in the expansion (D1).

## APPENDIX E

### List of Symbols

k | Wave vector |

k | Wave vector magnitude |

U | Background flow parallel to the wave vector |

B_{z} | Squared buoyancy frequency |

ρ | Density |

ρ_{0} | Characteristic value of density |

Mean density | |

ρ′ | Density perturbation |

b | Buoyancy |

b′ | Buoyancy perturbation |

w′ | Vertical velocity perturbation |

Complex vertical structure function of vertical velocity | |

Complex vertical structure function of buoyancy | |

σ | Exponential growth rate of instability |

Ri_{b} | Bulk Richardson number |

Re | Reynolds number |

## REFERENCES

Abramowitz, M., and I. A. Stegun, 1964:

*Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables*. Vol. 55. U.S. Government Printing Office, 1046 pp.Berrut, J.-P., and G. Klein, 2014: Recent advances in linear barycentric rational interpolation.

,*J. Comput. Appl. Math.***259**, 95–107, https://doi.org/10.1016/j.cam.2013.03.044.Bickley, W., 1941: Formulae for numerical differentiation.

,*Math. Gaz.***25**, 19–27, https://doi.org/10.1017/S002555720007008X.Fjørtoft, R., 1950: Application of integral theorems in deriving criteria of stability for laminar flows and for the baroclinic circular vortex.

,*Geofys. Publ.***17**(6), 1–52.Fornberg, B., and J. Zuev, 2007: The Runge phenomenon and spatially variable shape parameters in RBF interpolation.

,*Comput. Math. Appl.***54**, 379–398, https://doi.org/10.1016/j.camwa.2007.01.028.Goldstein, S., 1931: On the stability of superposed streams of fluids of different densities.

,*Proc. Roy. Soc. London***132A**, 524–548, https://doi.org/10.1098/rspa.1931.0116.Gregg, M., E. D’Asaro, J. Riley, and E. Kunze, 2018: Mixing efficiency in the ocean.

,*Annu. Rev. Mar. Sci.***10**, 443–473, https://doi.org/10.1146/annurev-marine-121916-063643.Hazel, P., 1972: Numerical studies of the stability of inviscid stratified shear flows.

,*J. Fluid Mech.***51**, 39–61, https://doi.org/10.1017/S0022112072001065.Howard, L. N., 1961: Note on a paper of John W. Miles.

,*J. Fluid Mech.***10**, 509–512, https://doi.org/10.1017/S0022112061000317.Klein, G., and J.-P. Berrut, 2012: Linear rational finite differences from derivatives of barycentric rational interpolants.

,*SIAM J. Numer. Anal.***50**, 643–656, https://doi.org/10.1137/110827156.Liu, Z., 2010: Instability of baroclinic tidal flow in a stratified fjord.

,*J. Phys. Oceanogr.***40**, 139–154, https://doi.org/10.1175/2009JPO4154.1.Liu, Z., S. A. Thorpe, and W. D. Smyth, 2012: Instability and hydraulics of turbulent stratified shear flows.

,*J. Fluid Mech.***695**, 235–256, https://doi.org/10.1017/jfm.2012.13.Maslowe, S. A., 1986: Critical layers in shear flows.

,*Annu. Rev. Fluid Mech.***18**, 405–432, https://doi.org/10.1146/annurev.fl.18.010186.002201.Miles, J. W., 1961: On the stability of heterogeneous shear flows.

,*J. Fluid Mech.***10**, 496–508, https://doi.org/10.1017/S0022112061000305.Putrevu, U., and I. A. Svendsen, 1992: Shear instability of longshore currents: A numerical study.

,*J. Geophys. Res.***97**, 7283–7303, https://doi.org/10.1029/91JC02988.Rayleigh, L., 1880: On the stability or instability of certain fluid motions.

*Scientific Papers*, Vol. 3, Cambridge University Press, 594–596.Rees, T., and A. Monahan, 2014: A general numerical method for analyzing the linear stability of stratified parallel shear flows.

,*J. Atmos. Oceanic Technol.***31**, 2795–2808, https://doi.org/10.1175/JTECH-D-14-00034.1.Schlichting, H., and K. Gersten, 2016:

*Boundary-Layer Theory*. Springer, 805 pp.Smyth, W. D., and W. R. Peltier, 1989: The transition between Kelvin–Helmholtz and Holmboe instability: An investigation of the overreflection hypothesis.

,*J. Atmos. Sci.***46**, 3698–3720, https://doi.org/10.1175/1520-0469(1989)046<3698:TTBKAH>2.0.CO;2.Smyth, W. D., and J. R. Carpenter, 2019:

*Instability in Geophysical Flows*. Cambridge University Press, 338 pp.Smyth, W. D., J. N. Moum, and J. D. Nash, 2011: Narrowband oscillations in the upper equatorial ocean. Part II: Properties of shear instabilities.

,*J. Phys. Oceanogr.***41**, 412–428, https://doi.org/10.1175/2010JPO4451.1.Smyth, W. D., J. N. Moum, L. Li, and S. A. Thorpe, 2013: Diurnal shear instability, the descent of the surface shear layer, and the deep cycle of equatorial turbulence.

,*J. Phys. Oceanogr.***43**, 2432–2455, https://doi.org/10.1175/JPO-D-13-089.1.Sun, C., W. Smyth, and J. Moum, 1998: Dynamic instability of stratified shear flow in the upper equatorial Pacific.

,*J. Geophys. Res.***103**, 10 323–10 337, https://doi.org/10.1029/98JC00191.Taylor, G. I., 1931: Effect of variation in density on the stability of superposed streams of fluid.

,*Proc. Roy. Soc. London***132A**, 499–523, https://doi.org/10.1098/rspa.1931.0115.Trefethen, L. N., 2000:

*Spectral Methods in MATLAB*. Society for Industrial and Applied Mathematics, 165 pp.