Skip to main content

Generalized Spectral Method Library

Project description


DISCLAIMER - this is a development version and has not been fully tested.

GSML is a Python-based software library that implements many Spectral methods which are typically used for the solution of partial differential equations. This library is mainly focused on Fourier-type spectral methods, including a recently introduced Fourier continuation (FC) method FC(Gram) [1]. The main benefit of spectral methods is that they have optimal convergence properties, so-called “exponential” convergence, for approximating functions and their derivatives.

This library is being developed to address a few key problems that face researchers when trying to solve complex differential equations:

  • High-order approximations: for many use-cases low-order approximations require unreasonably, many times infeasibly, fine spatial discretization. Access to higher-order approximations, in addition to increasing spatial refinement, is an intuitive approach to solving complex differential equations.

  • Parallel computing: parallel computing has been a key enabler of the growth of computational science, usage of the FC(Gram) method has been shown to exhibit optimal parallel scaling when solving the Navier-Stokes equation [2].

  • Heterogenous computing: Fourier spectral method and its derivatives, such as FC(Gram), utilize the Fast Fourier Transform which benefits from the presence of SIMD accelerators. Thus the combination of parallel operation and SIMD acceleration is ideal for newly emerging heterogeneous computing environments. The main focus for GSML is fused CPU/GPU architectures.

  • Ease of use: Python is used as the user interface and high-level development language for GSML with NumPy and GMPy “under the hood.”

In this current development release, the first and last of these goals have been addressed. SIMD accelerator/GPU support is planned for the next development release, followed by parallelization restricted to Cartesian domains.

[1] Bruno and Lyon (2010) J. Comp. Phys. link 1 / link 2

[2] Bruno and Albin (2011) J. Comp. Phys. link


This package uses the setuptools-enhancement of Python’s Distutils, so installation is quite simple:

  1. Check for the latest version of GSML

  2. Install GSML’s dependencies, NumPy and GMPy

  3. Once the package has been downloaded, install the package locally:

    cd gsml-0.1.0
    ./ install --user
  4. Run GSML’s tests, but these do not currently exist, so instead try one of the examples/ to determine if the library is functioning properly.

Documentation and Help

Currently no documentation beyond the docstrings exists for GSML. Several useful examples have been provided, so if these do not provide enough information to get started, you can find help here:


Many examples of GSML’s usage can be found in the examples/ directory including:

  1. Interpolation of a 1D nonperiodic function.

  2. Interpolation of a 1D periodic function.

  3. Interpolation of a 2D function on a mixed periodic and nonperiodic domain.

  4. Solution of the transient 1D diffusion equation with natural/Dirichlet boundary conditions.

  5. Solution of the transient 1D wave equation with natural/Dirichlet boundary conditions.

A simple example similar to example #1 from above is:

from numpy import *
import pylab

import gsml

# the exact function
u = lambda x: sin(x) + cos(x)

# configure the parameters of the simulation, a periodic domain with
# x=[0,2*pi) and 10 collocation points
params = {
    'shape' : (10,),        # the number of collocation points
    'scale': (2.*pi,),      # the scale of the domain
    'periodicity' : (True,), # domain is periodic => Fourier Spectral Method

# initialize GSML
grid = gsml.CartesianGrid(params)

x = grid.x

# approximate the first and third derivative of u(x)
ux = grid.dudx(u(x),1)
uxxx = grid.dudx(u(x),3)

Contributors and Contributing

If you are interested in contributing, please see GSML’s current blueprint bugs and blueprint. GSML’s Development team can be contacted through Launchpad here

GSML is currently being developed by:

  • N.M. Abukhdeir, Department of Chemical Engineering, University of Waterloo

    1. Pomorski, SHARCNET, University of Waterloo


This work was made possible by Natural Sciences and Engineering Research Council of Canada (NMA), the Shared Hierarchical Academic Research Computing Network, and Compute Canada.

Project details

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page