SpECTRE  v2025.08.19
Spectral::Fourier Class Reference

A collection of helper functions for using a Fourier series. More...

#include <Fourier.hpp>

Static Public Member Functions

template<typename T >
static T basis_function_value (int k, const T &x)
 Value of the basis function \(\Phi_k(x)\). More...
 
static double basis_function_normalization_square (int k)
 The normalization square \(c_k\) of the basis function \(\Phi_k(x)\), i.e. the definite integral of its square. More...
 
static DataVector collocation_points (size_t num_points)
 Collocation points \(\{x_i\}\). More...
 
static DataVector quadrature_weights (size_t num_points)
 Quadrature weights \(\{w_i\}\). More...
 
static size_t modal_storage_index (int k)
 Storage index (offset) \(i\) into a ModalVector (representing the coefficients) of the given mode \(k\). More...
 
static int mode_at_storage_index (size_t storage_index)
 Mode \(k\) corresponding to given storage index (offset) \(i\) into a ModalVector (representing the coefficients) More...
 
static Matrix differentiation_matrix (size_t num_points)
 Matrix \(D_{i,j}\) used to obtain the first derivative. More...
 
template<typename T >
static Matrix interpolation_matrix (size_t num_points, const T &target_points)
 Matrix used to interpolate to the target_points. More...
 

Detailed Description

A collection of helper functions for using a Fourier series.

Details

The general real-valued Fourier series is given by:

\[ f(x) = a_0 + \sum_{n=1}^{\infty} a_n \cos(nx) + b_n \sin(nx) \]

where

\begin{align*} a_0 &= \frac{1}{2\pi} \int_0^{2\pi} f(x) dx \\ a_n &= \frac{1}{\pi} \int_0^{2\pi} f(x) \cos(nx) dx \\ b_n &= \frac{1}{\pi} \int_0^{2\pi} f(x) \sin(nx) dx \end{align*}

If a function is discretized at \(N\) collocation points, the modal representation will have \(N\) spectral coefficients consisting of

\begin{align*} a_n & \qquad \text{for } n = 0, \ldots, \frac{N}{2} \\ b_n & \qquad \text{for } n = 1, \ldots, \frac{N-1}{2} \end{align*}

Thus to represent all terms through the harmonic \(M\) requires \(N = 2M +1\) collocation points.

For more details about using Fourier series see e.g. [28] and [75].

Member Function Documentation

◆ basis_function_normalization_square()

static double Spectral::Fourier::basis_function_normalization_square ( int  k)
static

The normalization square \(c_k\) of the basis function \(\Phi_k(x)\), i.e. the definite integral of its square.

Details

In particular,

\begin{align*} c_k &=\begin{cases} \hfil 2 \pi \hfil & \text{if } k = 0 \\ \hfil \pi \hfil & \text{otherwise} \end{cases} \end{align*}

◆ basis_function_value()

template<typename T >
static T Spectral::Fourier::basis_function_value ( int  k,
const T &  x 
)
static

Value of the basis function \(\Phi_k(x)\).

Details

We define the basis functions as

\begin{align*} \Phi_k(x) &=\begin{cases} \hfil \cos(kx) \hfil & \text{if } k \geq 0 \\ \hfil \sin(-kx) \hfil & \text{if } k < 0 \end{cases} \end{align*}

◆ collocation_points()

static DataVector Spectral::Fourier::collocation_points ( size_t  num_points)
static

Collocation points \(\{x_i\}\).

Details

The collocation points on the interval \(0 \leq x < 2 \pi\) are given by

\[ x_i = \frac{2 \pi i}{N} \]

◆ differentiation_matrix()

static Matrix Spectral::Fourier::differentiation_matrix ( size_t  num_points)
static

Matrix \(D_{i,j}\) used to obtain the first derivative.

Details

The differentiation matrix is given by:

\begin{align*} D_{i,j} &=\begin{cases} \hfil 0 \hfil & \text{if } i = j \\ \hfil \frac{1}{2} (-1)^{i-j} \csc \left[0.5 (x_i - x_j)\right] \hfil & \text{if } i \neq j,\; N \text{ is odd} \\ \hfil \frac{1}{2} (-1)^{i-j} \cot \left[0.5 (x_i - x_j)\right] \hfil & \text{if } i \neq j,\; N \text{ is even} \end{cases} \end{align*}

◆ interpolation_matrix()

template<typename T >
static Matrix Spectral::Fourier::interpolation_matrix ( size_t  num_points,
const T &  target_points 
)
static

Matrix used to interpolate to the target_points.

Details

Each row of the matrix is given by the interpolation weights for interpolating to a particular target point \(x\). At each target point, \(x\), the interpolation weights are given by:

\begin{align*} C_j(x) &=\begin{cases} \hfil \frac{1}{N} \sin \left[0.5 N(x - x_j)\right] \csc \left[0.5 (x - x_j)\right] \hfil & \text{if } N \text{ is odd} \\ \hfil \frac{1}{N} \sin \left[0.5 N (x - x_j)\right] \cot \left[0.5 (x - x_j)\right] \hfil & \text{if } N \text{ is even} \end{cases} \end{align*}

where \(x_j\) are the collocation_points.

◆ modal_storage_index()

static size_t Spectral::Fourier::modal_storage_index ( int  k)
static

Storage index (offset) \(i\) into a ModalVector (representing the coefficients) of the given mode \(k\).

Details

The modal coefficients are stored in a ModalVector as \(\{u_0, u_1, u_{-1}, u_2, u_{-2}, \ldots, u_M, u_{-M}\}\), where \(u_{-M}\) is omitted if the number of coefficients is even. Therefore the storage index \(i\) for the mode \(u_k\) is:

\begin{align*} i &=\begin{cases} \hfil 0 \hfil & \text{if } k = 0 \\ \hfil 2k-1 \hfil & \text{if } k > 0 \\ \hfil -2k \hfil & \text{if } k < 0 \end{cases} \end{align*}

◆ mode_at_storage_index()

static int Spectral::Fourier::mode_at_storage_index ( size_t  storage_index)
static

Mode \(k\) corresponding to given storage index (offset) \(i\) into a ModalVector (representing the coefficients)

Details

The modal coefficients are stored in a ModalVector as \(\{u_0, u_1, u_{-1}, u_2, u_{-2}, \ldots, u_M, u_{-M}\}\), where \(u_{-M}\) is omitted if the number of coefficients is even. Therefore the storage index \(i\) for the mode \(u_k\) is:

\begin{align*} k &=\begin{cases} \hfil 0 \hfil & \text{if } i = 0 \\ \hfil 1 + \frac{i}{2} \hfil & \text{if } i \text{ is odd} \\ \hfil -\frac{i}{2} \hfil & \text{if } i \text{ is even} \end{cases} \end{align*}

◆ quadrature_weights()

static DataVector Spectral::Fourier::quadrature_weights ( size_t  num_points)
static

Quadrature weights \(\{w_i\}\).

Details

The quadrature weights are given by

\[ w_i = \frac{2 \pi}{N} \]


The documentation for this class was generated from the following file: