# From Stretched String to gyre

The numerical technique demonstrated in the The Stretched String Problem section provides a powerful analog to how gyre solves the oscillation equations. The full details of gyre’s approach are laid out in Townsend & Teitler (2013); in this section we briefly summarize it, highlighting similarities and differences with the stretched-string problem.

## Separation

Similar to the stretched-string problem, gyre begins by separating variables in space and time. For the radial displacement perturbation $$\xir$$, trial solutions take the form

$\xir(r,\theta,\phi;t) = \operatorname{Re} \left[ \sqrt{4\pi} \, \txir(r) \, Y^{m}_{\ell}(\theta,\phi) \, \exp(-\ii \sigma t) \right]$

(this is taken from the Separated Equations section). In addition to the same sinusoidal time dependence as in eqn. (3), a spherical harmonic term $$Y^{m}_{\ell}$$ appears because we are separating in three (spherical) spatial coordinates rather than one.

## Discretization

As with the stretched-string problem, gyre discretizes the ODE governing $$\txir(r)$$ and related quantities on a spatial grid $$\{x_{1},x_{2},\ldots,x_{N}\}$$. However, a couple of important differences arise at this juncture. First, the oscillation equations are fourth order (sixth, in the non-adiabatic case). Rather than employing finite-difference approximations to high-order differential operators, gyre instead decomposes the problem into a system of coupled first-order equations. This system is written generically as

$x \deriv{\vty}{x} = \mA \, \vty,$

where $$\vty$$ is a vector of $$\neqn$$ dependent variables, and $$\mA$$ is a $$\neqn \times \neqn$$ Jacobian matrix. In the adiabatic case, $$\neqn=4$$; in the non-adiabatic case, $$\neqn=6$$.

Second, while the above equation system can be discretized using a simple finite-difference approximation to the left-hand side, gyre offers more-sophisticated approaches with higher orders of accuracy. These include the Magnus schemes described in Townsend & Teitler (2013), and implicit Runge-Kutta schemes mentioned in Townsend et al. (2018). The choice of scheme is set by the diff_scheme parameter of the &num namelist group. The discretization leads to difference equations of the form

$\vty_{j+1} = \mY_{j+1;j} \, \vty_{j},$

relating the dependent variable vector at adjacent grid points. The $$\neqn \times \neqn$$ fundamental solution matrix $$\mY_{j+1,j}$$ is evaluated from the value(s) of $$\mA$$ within the interval $$[x_{j},x_{j+1}]$$ using the discretization scheme.

There are $$N-1$$ of these sets of difference equations. They are augmented with the boundary conditions

$\subin{\mB} \, \vty_{1} = 0, \qquad\qquad \subout{\mB} \, \vty_{N} = 0,$

where $$\subin{\mB}$$ is a $$\nin \times \neqn$$ matrix representing the $$\nin$$ inner boundary conditions, and $$\subout{\mB}$$ is a $$\nout \times \neqn$$ matrix representing the outer boundary conditions (note that $$\nin + \nout = \neqn$$). Together, the difference equations and boundary conditions comprise a linear system of $$\neqn\,N$$ algebraic equations and $$\neqn N$$ unknowns.

## Linear System

The linear system can be written in the same form (cf. eqn. 4) as with the stretched-string problem . However, now $$\vu$$ is the vector with components

$\begin{split} \vu = \begin{pmatrix} \vty_{1} \\ \vty_{2} \\ \vdots \\ \vty_{N-1} \\ \vty_{N} \end{pmatrix}\end{split}$

and the system matrix $$\mS$$ is an $$\neq N \times \neqn N$$ block-staircase matrix with components

$\begin{split}\mS = \begin{pmatrix} \subin{\mB} & \mz & \cdots & \mz & \mz \\ -\mY_{2;1} & \mI & \cdots & \mz & \mz \\ \vdots & \vdots & \ddots & \vdots & \vdots \\ \mz & \mz & \cdots & -\mY_{N;N-1} & \mI \\ \mz & \mz & \cdots & \mz & \subout{\mB} \end{pmatrix}.\end{split}$

As before, the linear system (4) has non-trivial solutions only when the determinant of $$\mS$$ vanishes. Thus, gyre finds eigenvalues of the oscillation equation by solving the characteristic equation

$\Dfunc(\omega) \equiv \det(\mS) = 0,$

where the dimensionless frequency

$\omega \equiv \sqrt{\frac{R^{3}}{GM}} \, \sigma,$

is the product of the star’s dynamical timescale and the oscillation frequency $$\sigma$$. (Internally, gyre works extensively with such dimensionless quantities, as it improves the stability of the numerical algorithms).

## Scanning for Eigenfrequencies

In the adiabatic case, gyre searches for roots of the discriminant function $$\Dfunc$$ using the same bracketing and refinement strategies as the stretched-string problem.

In the non-adiabatic case, a complication is that the discriminant function and the dimensionless frequency are both complex quantities. Solving the characteristic equation in the complex plane is computationally challenging because there is no equivalent to bracketing and refinement. gyre implements a couple of different approaches to the problem, as discussed in the Non-Adiabatic Oscillations section.