API Reference#

This page provides an overview of the spectral package API.

Spectral Basis Classes#

Classes for spectral methods on different bases.

LegendreLobattoBasis

Legendre-Gauss-Lobatto nodal polynomial basis.

FourierEquispacedBasis

Equispaced Fourier basis on a periodic interval.

Spectral Differentiation Matrices#

Functions to construct differentiation and mass matrices.

legendre_diff_matrix

Return Legendre spectral differentiation matrix at arbitrary nodes.

legendre_mass_matrix

Return Legendre spectral mass matrix using normalized basis.

fourier_diff_matrix_cotangent

Construct Fourier differentiation matrix using cotangent identity.

fourier_diff_matrix_on_interval

Fourier differentiation matrix rescaled to periodic interval \([a, b]\).

Boundary Value Problems#

Solvers for boundary value problems (BVPs).

BvpProblem

Dense linear BVP system with convenience helpers.

solve_bvp

Solve Exercise B: Laplace's equation in polar coordinates using mixed spectral collocation.

solve_legendre_collocation

Solve Exercise A boundary value problem using Legendre-Gauss-Lobatto collocation.

solve_legendre_tau

Solve Exercise A boundary value problem using Legendre tau method.

solve_polar_bvp

Solve Exercise B: Laplace's equation in polar coordinates using mixed spectral collocation.

Time-Dependent PDEs#

Time integrators and PDE solvers.

Time Integrators#

TimeIntegrator

Base class for time integration methods.

get_time_integrator

Retrieve a time integrator by name.

RK3

3rd-order Strong Stability Preserving Runge-Kutta (SSP-RK3).

RK4

Classical 4th-order Runge-Kutta method (ERK4).

KdV Equation Solver#

KdVSolver

Korteweg-de Vries equation solver using Fourier spectral methods.

soliton

Compute KdV soliton solution.

two_soliton_initial

Initial condition for two-soliton collision simulation.

Utilities#

Helper functions for I/O, formatting, plotting, and numerical analysis.

io.ensure_output_dir

Ensure output directory exists, creating it if necessary.

io.load_simulation_data

Load simulation data with automatic fallback between parquet and pickle.

io.save_simulation_data

Save simulation data to disk.

formatting.extract_metadata

Extract metadata from a DataFrame.

formatting.format_dt_latex

Format a timestep value as LaTeX scientific notation.

formatting.format_parameter_range

Format a parameter range for display.

formatting.build_parameter_string

Build a parameter string from a dictionary.

plotting.get_repo_root

Get repository root directory, handling both local and sphinx-gallery execution.

norms.discrete_l2_norm

Approximate L2 norm using composite trapezoidal rule.

norms.discrete_l2_error

Compute discrete L2 error between exact and numerical solutions.

norms.discrete_linf_error

Compute discrete \(L^\infty\) (maximum) error.