# 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

(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

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

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

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

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

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

where the dimensionless frequency

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.