pypi i shenfun


High performance computational platform in Python for the spectral Galerkin method

by spectralDNS

4.0.2 (see all)
pypi i shenfun


.. image:: :target: .. image:: :target: .. image:: :target: .. image:: :target: .. image:: :target: .. |binder| image:: :target:

Try it in a jupyter hub using Binder



Shenfun is a high performance computing platform for solving partial differential equations (PDEs) by the spectral Galerkin method. The user interface to shenfun is very similar to FEniCS <>, but applications are limited to multidimensional tensor product grids, using either Cartesian or curvilinear grids (e.g., but not limited to, polar, cylindrical, spherical or parabolic). The code is parallelized with MPI through the mpi4py-fft <> package.

Shenfun enables fast development of efficient and accurate PDE solvers (spectral order and accuracy), in the comfortable high-level Python language. The spectral accuracy is ensured by using high-order global orthogonal basis functions (Fourier, Legendre, Chebyshev first and second kind, Ultraspherical, Jacobi, Laguerre and Hermite), as opposed to finite element codes that are using low-order local basis functions. Efficiency is ensured through vectorization (Numpy <>), parallelization (mpi4py <>) and by moving critical routines to Cython <> or Numba <>. Shenfun has been used to run turbulence simulations (Direct Numerical Simulations) on thousands of processors on high-performance supercomputers, see the spectralDNS <>_ repository.

The demo folder contains several examples for the Poisson, Helmholtz and Biharmonic equations. For extended documentation and installation instructions see ReadTheDocs <>. For interactive demos, see the jupyter book <>. Note that shenfun currently comes with the possibility to use two non-periodic directions (see biharmonic demo <>), and equations may be solved coupled and implicit (see <>).

Note that shenfun works with curvilinear coordinates. For example, it is possible to solve equations on a sphere <> (using spherical coordinates), on the surface of a torus <>, on a Möbius strip <> or along any curved line in 2D/3D <>. Actually, any new coordinates may be defined by the user as long as the coordinates lead to a system of equations with separable coefficients. After defining new coordinates, operators like div, grad and curl work automatically with the new curvilinear coordinates. See also this notebook on the sphere <> or an illustration of the vector Laplacian <>.

.. image:: :target: :alt: The eigenvector of the 8'th smallest eigvalue on a Möbius strip .. image:: :alt: Solution of Poisson's equation on a Coil .. image:: :target: :alt: Solution of Poisson's equation on a spherical shell .. image:: :target: :alt: Solution of Poisson's equation on the surface of a torus

For a more psychedelic experience, have a look at the simulation <>_ of the Ginzburg-Landau equation on the sphere (click for Youtube-video):

.. image:: :target: :alt: Ginzburg-Landau spherical coordinates

Shenfun can also be used to approximate analytical functions with global spectral basis functions <>, and to integrate over highly complex domains, like the seashell below, see this demo <>.

.. image:: :alt: The surface of a seashell


Shenfun can be installed using either pip <> or conda <>, see installation chapter on readthedocs <>_.


* `Python <>`_ 3.3 or above. Test suits are run with Python 3.7, 3.8 and 3.9.
* A functional MPI 2.x/3.x implementation like `MPICH <>`_ or `Open MPI <>`_ built with shared/dynamic libraries.
* `FFTW <>`_ version 3, also built with shared/dynamic libraries.
* Python modules:
    * `Numpy <>`_
    * `Scipy <>`_
    * `Sympy <>`_
    * `Cython <>`_
    * `mpi4py <>`_
    * `mpi4py-fft <>`_


For comments, issues, bug-reports and requests, please use the issue tracker of the current repository, or see How to contribute? <>_ at readthedocs. Otherwise the principal author can be reached at::

Mikael Mortensen
mikaem at
Department of Mathematics
University of Oslo

GitHub Stars



5mos ago








2mos ago
4mos ago
5mos ago
5mos ago
No alternatives found
No tutorials found
Add a tutorial