Class

NumCosmoMathSpectral

Description [src]

final class NumCosmoMath.Spectral : GObject.Object
{
  /* No available fields */
}

Chebyshev series of functions on an interval.

Computes the Chebyshev coefficients of a function on $[a, b]$ from its values at the Chebyshev-Lobatto nodes by a DCT-I, at a fixed order or adaptively on nested grids. Evaluates, differentiates and integrates Chebyshev series, moves them to another interval, and provides the banded ultraspherical (Gegenbauer) operators of the spectral method for linear ODEs. A function on $[a, b]$ is a series $\sum_k c^k T_k(s)$ in the Chebyshev variable $s \in [-1, 1]$, related to $x \in [a, b]$ by ncm_spectral_x_to_s(); the operator matrices and rows act on functions of $s$. See Spectral Methods for the formulas.

The adaptive expansions work on nested grids indexed by a refinement level $r$: the grid of level $r$ has $N = 2^r + 1$ Chebyshev-Lobatto nodes and gives $N$ coefficients, and each level contains the nodes of the one below. The level is an exponent: the level arguments of the adaptive functions and NcmSpectral:max-level count doublings of the grid, not coefficients.

A coefficient array passed as a pointer to a pointer is reused when it is not NULL and allocated otherwise; through bindings a new one is always returned. An instance holds the node and transform buffers of its expansions, so it must not be used by two threads at once, and a batch expansion must not be called again from inside its own callback.

Ancestors

Constructors

ncm_spectral_new

Creates a new NcmSpectral with NcmSpectral:max-level 16.

ncm_spectral_new_with_max_level
No description available.

Functions

ncm_spectral_chebT_deriv2_to_gegenbauer_alpha2

Computes the $C^{(2)}k$ coefficients of $f”(s)$ for $f(s) = \sum_n c^n T_n(s)$, $g^k = 2(k + 2)\,c^{k+2}$, from $T_n” = 2n\,C^{(2)}{n-2}$. For $N$ coefficients in c, g has $N - 2$, or one zero when $N \le 2$. The derivative is in $s$; on $[a, b]$ multiply by $(2/(b - a))^2$.

ncm_spectral_chebT_deriv_to_gegenbauer_alpha2

Computes the $C^{(2)}k$ coefficients of $f’(s)$ for $f(s) = \sum_n c^n T_n(s)$, $g^k = c^{k+1} - c^{k+3}$, from $T_n’ = n\,U{n-1}$ and $U_m = (C^{(2)}m - C^{(2)}{m-2})/(m + 1)$. For $N$ coefficients in c, g has $N - 1$, or one zero when $N \le 1$. The derivative is in $s$; on $[a, b]$ multiply by $2/(b - a)$.

ncm_spectral_chebT_to_gegenbauer_alpha1

Converts the $T_n$ coefficients c of a series to its $C^{(1)}_n = U_n$ coefficients, of the same length.

ncm_spectral_chebT_to_gegenbauer_alpha2

Converts the $T_n$ coefficients c of a series to its $C^{(2)}_k$ coefficients, of the same length.

ncm_spectral_chebyshev_deriv

Evaluates the derivative in $s$ in one backward pass that builds the coefficients of the derivative series and sums them by the Clenshaw recurrence.

ncm_spectral_chebyshev_deriv_x

Same as ncm_spectral_chebyshev_deriv() at $s$ given by ncm_spectral_x_to_s(), times $\mathrm{d}s/\mathrm{d}x = 2/(b - a)$.

ncm_spectral_chebyshev_eval

Evaluates the series by the Clenshaw recurrence for $|s| < 0.9$ and by Reinsch’s modification of it closer to the endpoints.

ncm_spectral_chebyshev_eval_x

Same as ncm_spectral_chebyshev_eval() at $s$ given by ncm_spectral_x_to_s().

ncm_spectral_chebyshev_integrate

Integrates the series over its interval, from $\int_{-1}^{1} T_k(s)\,\mathrm{d}s = 2/(1 - k^2)$ for even $k$ and zero for odd $k$. Applied to the coefficients of ncm_spectral_compute_chebyshev_coeffs() or its adaptive variants, this is Clenshaw-Curtis quadrature.

ncm_spectral_clear

If spectral is not NULL, decreases its reference count by one and sets spectral to NULL.

ncm_spectral_compute_d2_row

Adds coeff times row $k$ of ncm_spectral_get_d2_matrix() to row_data. Its nonzero entries are.

ncm_spectral_compute_d_row

Adds coeff times row $k$ of ncm_spectral_get_d_matrix() to row_data. Its nonzero entries are.

ncm_spectral_compute_proj_row

Adds coeff times row $k$ of ncm_spectral_get_proj_matrix() to row_data. Its nonzero entries are.

ncm_spectral_compute_s2_d2_row

Adds coeff times row $k$ of ncm_spectral_get_s2_d2_matrix() to row_data. Its nonzero entries are.

ncm_spectral_compute_s2_row

Adds coeff times row $k$ of ncm_spectral_get_s2_matrix() to row_data. Its nonzero entries are.

ncm_spectral_compute_s_d2_row

Adds coeff times row $k$ of ncm_spectral_get_s_d2_matrix() to row_data. Its nonzero entries are.

ncm_spectral_compute_s_d_row

Adds coeff times row $k$ of ncm_spectral_get_s_d_matrix() to row_data. Its nonzero entries are.

ncm_spectral_compute_s_row

Adds coeff times row $k$ of ncm_spectral_get_s_matrix() to row_data. Its nonzero entries are.

ncm_spectral_gegenbauer_alpha1_eval

Evaluates the series by the forward recurrence of $C^{(1)}_n = U_n$, with the closed form $U_n(\pm 1) = (\pm 1)^n (n + 1)$ at the endpoints.

ncm_spectral_gegenbauer_alpha1_eval_x

Same as ncm_spectral_gegenbauer_alpha1_eval() at $s$ given by ncm_spectral_x_to_s().

ncm_spectral_gegenbauer_alpha2_eval

Evaluates the series by the forward recurrence of $C^{(2)}_n$, with the closed form $C^{(2)}_n(\pm 1) = (\pm 1)^n \binom{n+3}{3}$ at the endpoints.

ncm_spectral_gegenbauer_alpha2_eval_x

Same as ncm_spectral_gegenbauer_alpha2_eval() at $s$ given by ncm_spectral_x_to_s().

ncm_spectral_gegenbauer_alpha2_mul_affine

Multiplies $\sum_n g^n C^{(2)}n(s)$ by $\alpha s + \beta$, using $s\,C^{(2)}_n = [(n + 1)\,C^{(2)}{n+1} + (n + 3)\,C^{(2)}_{n-1}]/(2(n + 2))$. For $N$ coefficients in g, out has $N + 1$. out must not alias g.

ncm_spectral_get_d2_matrix

Builds the $N \times N$ matrix of the second derivative from the $T_n$ coefficients of $f$ to the $C^{(2)}_k$ coefficients of $f”$, truncated to the first $N$ columns.

ncm_spectral_get_d_matrix

Builds the $N \times N$ matrix of the derivative from the $T_n$ coefficients of $f$ to the $C^{(2)}_k$ coefficients of $f’$, truncated to the first $N$ columns.

ncm_spectral_get_proj_matrix

Builds the $N \times N$ matrix of the identity from the $T_n$ coefficients of $f$ to the $C^{(2)}_k$ coefficients of $f$, truncated to the first $N$ columns.

ncm_spectral_get_s2_d2_matrix

Builds the $N \times N$ matrix of $s^2\,\mathrm{d}^2/\mathrm{d}s^2$ from the $T_n$ coefficients of $f$ to the $C^{(2)}_k$ coefficients of $s^2 f”$, truncated to the first $N$ columns.

ncm_spectral_get_s2_matrix

Builds the $N \times N$ matrix of multiplication by $s^2$ from the $T_n$ coefficients of $f$ to the $C^{(2)}_k$ coefficients of $s^2 f$, truncated to the first $N$ columns.

ncm_spectral_get_s_d2_matrix

Builds the $N \times N$ matrix of $s\,\mathrm{d}^2/\mathrm{d}s^2$ from the $T_n$ coefficients of $f$ to the $C^{(2)}_k$ coefficients of $s f”$, truncated to the first $N$ columns.

ncm_spectral_get_s_d_matrix

Builds the $N \times N$ matrix of $s\,\mathrm{d}/\mathrm{d}s$ from the $T_n$ coefficients of $f$ to the $C^{(2)}_k$ coefficients of $s f’$, truncated to the first $N$ columns.

ncm_spectral_get_s_matrix

Builds the $N \times N$ matrix of multiplication by $s$ from the $T_n$ coefficients of $f$ to the $C^{(2)}_k$ coefficients of $s f$, truncated to the first $N$ columns.

ncm_spectral_s_to_x

Maps the Chebyshev variable s to $x = [(b - a)s + (a + b)]/2$, the inverse of ncm_spectral_x_to_s().

ncm_spectral_x_to_s

Maps x to the Chebyshev variable, $s = (2x - (a + b))/(b - a)$.

Instance methods

ncm_spectral_chebyshev_rebase

Expresses the same polynomial as a Chebyshev series on [a_out, b_out]. The Chebyshev variable $s_\mathrm{in}$ of [a_in, b_in] is $s_\mathrm{in} = \alpha s_\mathrm{out} + \beta$ in terms of the one of [a_out, b_out], and each $T_k(s_\mathrm{in})$ is expanded in the $T_j(s_\mathrm{out})$ by the Chebyshev recurrence, at a cost of $O(n^2)$.

ncm_spectral_compute_chebyshev_coeffs

Computes the $N$ Chebyshev coefficients of $F$ on $[a, b]$ from its values at the $N$ Chebyshev-Lobatto nodes. Aborts if $N < 2$.

ncm_spectral_compute_chebyshev_coeffs_adaptive

Computes the Chebyshev coefficients of $F$ on $[a, b]$, doubling the nested Chebyshev-Lobatto grid from level level_min until, at level $r$, the $\ell_2$ norm of the change of the first $2^{r-1} + 1$ coefficients is below tol times the norm of the level-$r$ coefficients. Each doubling evaluates $F$ only at the new nodes. Reaching NcmSpectral:max-level without converging is an error.

ncm_spectral_compute_chebyshev_coeffs_adaptive_full

As ncm_spectral_compute_chebyshev_coeffs_adaptive(), with the change compared to the larger of reltol times the norm and abstol. An abstol of 0.0 gives ncm_spectral_compute_chebyshev_coeffs_adaptive(); a positive one stops the refinement of a function known to be negligible.

ncm_spectral_compute_chebyshev_coeffs_adaptive_try

As ncm_spectral_compute_chebyshev_coeffs_adaptive_full(), stopping at the smaller of level_cap and NcmSpectral:max-level and reporting the outcome through converged instead of failing. It uses the single-function buffers, so it may be called from inside the callback of a batch expansion.

ncm_spectral_compute_chebyshev_coeffs_batch_adaptive

Computes the Chebyshev coefficients of the n_comp components of $F$ on one shared grid, as ncm_spectral_compute_chebyshev_coeffs_adaptive_full(). Each node is evaluated once for all components. Every component must converge, so the one needing the highest level sets it for all. Reaching NcmSpectral:max-level without converging is an error.

ncm_spectral_compute_chebyshev_coeffs_batch_adaptive_cap

As ncm_spectral_compute_chebyshev_coeffs_batch_adaptive(), stopping at the smaller of level_cap and NcmSpectral:max-level. When fatal is FALSE, not converging leaves coeffs unchanged and returns 0, and the last doubling is skipped when the level below predicts that it cannot converge. That suits a caller that splits its interval on failure.

ncm_spectral_free

Decreases the reference count of spectral by one.

ncm_spectral_get_max_level
No description available.

ncm_spectral_ref

Increases the reference count of spectral by one.

ncm_spectral_set_max_level

Sets NcmSpectral:max-level, reallocating the buffers when it changes.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Properties

NumCosmoMath.Spectral:max-level

Highest refinement level $r$ of the adaptive expansions, at most $2^r + 1$ nodes, from 1 to 30. Buffers of that size are allocated when it is set. It bounds memory: the adaptive expansions stop on their tolerance, and reaching this level without converging is an error, except for the variants that report it.

Signals

Signals inherited from GObject (1)
GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

Class structure

struct NumCosmoMathSpectralClass {
  GObjectClass parent_class;
  
}

No description available.

Class members
parent_class: GObjectClass

No description available.