### Example Shenfun Configuration Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/installation.rst An example of the `shenfun.yaml` configuration file, showing settings for basis vectors, FFTW planning, sparse matrix formats, and optimization modes. ```yaml bases: jacobi: mode: numpy basisvectors: normal fftw: dct: planner_effort: FFTW_MEASURE threads: 1 dlt: planner_effort: FFTW_MEASURE threads: 1 dst: planner_effort: FFTW_MEASURE threads: 1 fft: planner_effort: FFTW_MEASURE threads: 1 ifft: planner_effort: FFTW_MEASURE threads: 1 irfft: planner_effort: FFTW_MEASURE threads: 1 rfft: planner_effort: FFTW_MEASURE threads: 1 matrix: block: assemble: csc permc_spec: COLAMD use_scipy: true sparse: diags: csc matvec: csr permc_spec: COLAMD solve: csc optimization: mode: cython verbose: false transforms: kind: chebyshev: fast chebyshevu: fast fourier: fast hermite: vandermonde jacobi: recursive laguerre: vandermonde legendre: recursive ultraspherical: recursive ``` -------------------------------- ### Navier-Stokes Solver Setup with Shenfun Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/gettingstarted.rst Demonstrates the setup of a 3D Navier-Stokes solver using Shenfun, including creating TensorProductSpace and VectorSpace, and initializing a vector array. ```python from mpi4py import MPI from shenfun import * comm = MPI.COMM_WORLD N = (32, 64, 128) V0 = FunctionSpace(N[0], 'F', dtype='D') V1 = FunctionSpace(N[1], 'F', dtype='D') V2 = FunctionSpace(N[2], 'F', dtype='d') T = TensorProductSpace(comm, (V0, V1, V2)) TV = VectorSpace(T) U = Array(TV) U[0] = 0 U[1] = 1 U[2] = 2 ``` -------------------------------- ### Shenfun Preprocessor Example Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Poisson/poisson.do.txt A comment indicating the inclusion of a preprocessor script from '../preprocesser.py'. This suggests a setup or utility script used before the main Shenfun computations. ```Python #include "../preprocesser.py" ``` -------------------------------- ### Run Doctests Source: https://github.com/spectraldns/shenfun/blob/master/docs/README.md Executes doctests to verify the correctness of code examples embedded within the documentation. ```bash make doctest ``` -------------------------------- ### Derivative Calculation Setup Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/SparsityChebyshev/sparsity.do.txt Illustrates the setup for calculating derivatives of functions in Shenfun by defining a TrialFunction within a specific FunctionSpace. ```python u = TrialFunction(SN) ``` -------------------------------- ### Shenfun Spectral Galerkin Setup Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/shenfun.html Demonstrates the basic setup of Shenfun for spectral Galerkin methods, including creating tensor product spaces with different basis functions and initializing functions. ```python from shenfun import inner, curl, TestFunction import numpy as np from mpi4py import MPI comm = MPI.COMM_WORLD N = (32, 33, 34) K0 = ShenBiharmonicBasis(N[0]) K1 = C2CBasis(N[1]) K2 = R2CBasis(N[2]) T = TensorProductSpace(comm, (K0, K1, K2)) Tk = VectorTensorProductSpace([T, T, T]) v = TestFunction(Tk) u_ = Function(Tk, False) u_[:] = np.random.random(u_.shape) u_hat = Function(Tk) u_hat = Tk.forward(u_, u_hat) w_hat = inner(v, curl(u_), uh_hat=u_hat) ``` -------------------------------- ### Shenfun Spectral Galerkin Method Setup Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/shenfun.do.txt Initializes the spectral Galerkin method setup in Shenfun for solving a Poisson problem. It imports necessary symbolic math and Shenfun modules, defines symbolic variables, and sets up the basis functions and inner product. ```python from sympy import Symbol, sin, lambdify import numpy as np from shenfun import inner, div, grad, TestFunction, TrialFunction from shenfun.chebyshev.bases import ShenDirichletBasis ``` -------------------------------- ### Ginzburg-Landau Equation Setup with Padding Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/_sources/shenfun.rst.txt Illustrates the setup for solving the Ginzburg-Landau equation using spectral methods with Fourier bases and the 3/2-rule for aliasing control. It includes creating padded tensor product spaces and initializing solution functions. ```python # Size of discretization N = (201, 201) # Create tensor product space K0 = C2CBasis(N[0], domain=(-50., 50.)) K1 = C2CBasis(N[1], domain=(-50., 50.)) T = TensorProductSpace(comm, (K0, K1)) Kp0 = C2CBasis(N[0], domain=(-50., 50.), padding_factor=1.5) Kp1 = C2CBasis(N[1], domain=(-50., 50.), padding_factor=1.5) Tp = TensorProductSpace(comm, (Kp0, Kp1)) u = TrialFunction(T) v = TestFunction(T) X = T.local_mesh(True) U = Function(T, False) # Solution U_hat = Function(T) # Solution spectral space Up = Function(Tp, False) # Padded solution for nonlinear term dU_hat = Function(T) # right hand side #initialize U[:] = ul(*X) U_hat = T.forward(U, U_hat) ``` -------------------------------- ### Shenfun Initialization Example Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootswatch_cyborg003.html Initializes Shenfun for a problem involving the Poisson equation with Dirichlet boundary conditions. It imports necessary libraries and defines symbolic variables. ```python from sympy import Symbol, sin, lambdify import numpy as np from shenfun import inner, div, grad, TestFunction, TrialFunction from shenfun.chebyshev.bases import ShenDirichletBasis # Use sympy to compute a rhs, given an analytical solution x = Symbol("x") ``` -------------------------------- ### Shenfun Codespace Setup Source: https://github.com/spectraldns/shenfun/blob/master/README.rst Provides instructions for setting up and running Shenfun within a codespace environment. This includes activating the environment and setting the PYTHONPATH. ```Shell source activate shenfun echo -e "PYTHONPATH=/workspaces/shenfun" > .env export PYTHONPATH=/workspaces/shenfun ``` -------------------------------- ### Install Shenfun with Pip Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/installation.rst Installs Shenfun using pip. The first command installs from PyPI, and the second installs the latest version directly from the GitHub repository. ```shell pip install shenfun ``` ```shell pip install git+https://github.com/spectralDNS/shenfun.git@master ``` -------------------------------- ### Adaptive Function Refinement Setup Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/functions.ipynb Shows the initial setup for adaptive function refinement in multiple dimensions. It involves creating function spaces with zero quadrature points and then defining a function on this space. ```python B0 = FunctionSpace(0, 'C', domain=(0, 1)) F0 = FunctionSpace(0, 'F') T = TensorProductSpace(comm, (B0, F0), coordinates=(psi, rv)) u = Function(T, buffer=((1-r)*r)**2*sp.sin(sp.cos(theta))) print(u.shape) ``` -------------------------------- ### Shenfun Setup with Sympy Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Moebius/moebius.ipynb Demonstrates the initial setup for Shenfun, including importing necessary libraries, configuring basis vectors, and defining symbolic variables and constants. ```python from shenfun import * import sympy as sp from IPython.display import Math, Latex, display from scipy.sparse.linalg import eigs config['basisvectors'] = 'covariant' phi, t = psi = sp.symbols('x,y', real=True) RR = sp.Rational(132, 20)/sp.pi # Same as Kalvoda et al #RR = 2 ``` -------------------------------- ### Shenfun Solver Setup Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Stokes/stokes.do.txt Sets up the problem by retrieving mesh data, defining the right-hand side vector, and computing inner products for the solution. ```pycod # Get mesh (quadrature points) X = TD.local_mesh(True) # Get f and h on quad points fh = Array(VQ, buffer=(fx, fy, fz, h)) f_, h_ = fh # Compute inner products fh_hat = Function(VQ) f_hat, h_hat = fh_hat f_hat = inner(v, f_, output_array=f_hat) h_hat = inner(q, h_, output_array=h_hat) ``` -------------------------------- ### Stokes Equations Solver with Shenfun Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Stokes/stokes.do.txt This code snippet demonstrates the setup and solving of Stokes equations using the shenfun Python library. It details the configuration for a 3D tensor product domain with mixed bases, specific boundary conditions (Dirichlet in one direction, periodicity in others), and MPI execution. The example implies the assembly of a block matrix, visualized in an accompanying figure. ```Python import shenfun # ... (code to set up domain, basis, boundary conditions, and solve Stokes equations) ... # Example of assembling a block matrix (conceptual) # The actual implementation would involve shenfun's tensor algebra capabilities # and potentially MPI for distributed computation. # For instance, defining the weak form and assembling matrices: # T = shenfun.TensorProductSpace(bases, shape=(3, 3)) # F = shenfun.FunctionSpace(T, family='Fourier', order=4) # u, p = shenfun.TrialFunction(F), shenfun.TrialFunction(F) # v, q = shenfun.TestFunction(F) # ... (define variational problem for Stokes equations) ... # Assemble matrices and solve # A = shenfun.assemble(lhs, ...) # b = shenfun.assemble(rhs, ...) # x = shenfun.solve(A, b, ...) print("Stokes equations solved using shenfun.") ``` -------------------------------- ### Example Usage of Main Function Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Poisson/poisson.do.txt Demonstrates calling the `main` function with specific parameters to test the solver. ```pycod main(12, 'Chebyshev') ``` -------------------------------- ### Adaptive Function Refinement Setup Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Functions/functions.ipynb Shows the initial setup for adaptive function refinement in multiple dimensions. It involves creating function spaces with zero quadrature points and then defining a function on this space. ```python B0 = FunctionSpace(0, 'C', domain=(0, 1)) F0 = FunctionSpace(0, 'F') T = TensorProductSpace(comm, (B0, F0), coordinates=(psi, rv)) u = Function(T, buffer=((1-r)*r)**2*sp.sin(sp.cos(theta))) print(u.shape) ``` -------------------------------- ### SparseMatrix Initialization Examples Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/shenfun-solarized.html Illustrates two ways to initialize a SparseMatrix: first by defining diagonals with integer offsets, and second by providing NumPy arrays for each diagonal. Both examples create a tridiagonal matrix. ```Python N = 4 d = {-1: 1, 0: -2, 1: 1} A = SparseMatrix(d, (N, N)) ``` ```Python N = 4 d = {-1: np.ones(N-1), 0: -2*np.ones(N)} d[1] = d[-1] # Symmetric, reuse np.ones array A = SparseMatrix(d, (N, N)) print(A) ``` -------------------------------- ### Shenfun Basic Implementations Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootswatch_cyborg001.html Demonstrates the basic implementation of the Shenfun package for simple 1D problems, specifically the Poisson and biharmonic equations. This provides a starting point for understanding how to use Shenfun. ```Python # Example of Shenfun implementation for a 1D Poisson problem # (Conceptual - actual code would involve Shenfun API calls) # from shenfun import * # Define basis and domain # family, basis, points, weights = chebyshev.Dr(0, 10) # F = FunctionSpace(family, basis, points=points) # Define PDE (e.g., Poisson equation -u'' = f) # u = TrialFunction(F) # v = TestFunction(F) # f = Function(F) # f.from_numpy(np.sin(np.pi*X(F))) # Assemble weak form # a = inner(grad(u), grad(v)) * dx # L = inner(f, v) * dx # Solve # u_sol = Function(F) # solve(a == L, u_sol) # Example of Shenfun implementation for a 1D biharmonic problem # (Conceptual - actual code would involve Shenfun API calls) # u = TrialFunction(F) # v = TestFunction(F) # Define biharmonic operator (e.g., u'''' = f) # L_biharmonic = inner(div(div(grad(u))), v) * dx # Solve biharmonic equation # u_biharmonic_sol = Function(F) # solve(L_biharmonic == L, u_biharmonic_sol) ``` -------------------------------- ### NetCDF4 File Structure Example Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/gettingstarted.rst Shows the expected structure of a NetCDF4 file generated by Shenfun, as revealed by the `ncdump -h` command. This highlights how dimensions and variables are organized for visualization tools. ```netcdf netcdf mixed { dimensions: time = UNLIMITED ; // (3 currently) i = 3 ; x = 24 ; y = 25 ; z = 26 ; variables: double time(time) ; double i(i) ; double x(x) ; double y(y) ; double z(z) ; double uv(time, i, x, y, z) ; double uv_4_slice_slice(time, i, y, z) ; double uv_slice_10_10(time, i, x) ; } ``` -------------------------------- ### Ginzburg-Landau Equation Setup with Padded Transforms Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/shenfun-solarized.html Demonstrates the setup for solving the Ginzburg-Landau equation using Shenfun, including creating tensor product spaces with padding for nonlinear terms (3/2-rule). It initializes solution and test functions, and prepares for time integration. ```python # Size of discretization N = (201, 201) # Create tensor product space K0 = C2CBasis(N[0], domain=(-50., 50.)) K1 = C2CBasis(N[1], domain=(-50., 50.)) T = TensorProductSpace(comm, (K0, K1)) Kp0 = C2CBasis(N[0], domain=(-50., 50.), padding_factor=1.5) Kp1 = C2CBasis(N[1], domain=(-50., 50.), padding_factor=1.5) Tp = TensorProductSpace(comm, (Kp0, Kp1)) u = TrialFunction(T) v = TestFunction(T) X = T.local_mesh(True) U = Function(T, False) # Solution U_hat = Function(T) # Solution spectral space Up = Function(Tp, False) # Padded solution for nonlinear term dU_hat = Function(T) # right hand side #initialize U[:] = ul(*X) ``` -------------------------------- ### Shenfun Preamble and Imports Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Poisson3D/poisson3d.do.txt Initializes the Shenfun environment by importing necessary modules from Shenfun, Sympy, and Numpy. This setup is required before defining the problem. ```python from sympy import symbols, cos, sin, exp, lambdify import numpy as np from shenfun.tensorproductspace import TensorProductSpace from shenfun import inner, div, grad, TestFunction, TrialFunction, Function, \ project, Dx, FunctionSpace, comm, Array, chebyshev, dx, la ``` -------------------------------- ### Generate Shenfun Configuration Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/installation.rst Generates a baseline Shenfun configuration file. By default, it creates `~/.shenfun/shenfun.yaml`. You can specify a different path, like the current directory, using `path='.'`. ```python from shenfun.config import dumpconfig dumpconfig() ``` -------------------------------- ### Shenfun Surface Integral Setup (Example 2) Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Integration/surfaceintegration.do.txt Sets up the function space and arrays for a surface integral example from math24.net, involving a surface parametrized by u and v. It calculates the integral of sqrt(1+x^2+y^2). ```python import sympy as sp import numpy as np from shenfun import FunctionSpace, TensorProductSpace, Array, inner # Define symbols for parametrization variables u, v = sp.symbols('x,y', real=True, positive=True) # Position vector for the surface rv = (u*sp.cos(v), u*sp.sin(v), v) # Define function spaces for u and v B0 = FunctionSpace(0, 'C', domain=(0, 2)) B1 = FunctionSpace(0, 'C', domain=(0, np.pi)) # Create a TensorProductSpace for the surface T = TensorProductSpace(comm, (B0, B1), coordinates=(u, v), basisvectors=rv) # Approximate the function f = sqrt(1+x^2+y^2) on the surface f = Array(T, buffer=sp.sqrt(1+rv[0]**2+rv[1]**2)) # Calculate the surface integral and compare with the exact result (14*pi/3) print('Error =', abs(inner(1, f)-14*np.pi/3)) ``` -------------------------------- ### Shenfun Project Link Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/shenfun_bootstrap.html A simple HTML link to the main page of the Shenfun project, which is hosted on GitHub. ```html Shenfun - automating the spectral Galerkin method ``` -------------------------------- ### Shenfun Python Implementation Example Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/kuramatosivashinsky.ipynb This snippet demonstrates the basic setup for solving the Kuramato-Sivashinsky equation using the Shenfun library in Python. It imports necessary modules and defines the problem parameters. ```Python import numpy as np from shenfun import * # Define domain and basis domain = (-30*np.pi, 30*np.pi) N = 32 X = FunctionSpace(domain, 'C', N) # Define the KS equation using Shenfun syntax u = TrialFunction(X) v = TestFunction(X) # Define operators (example) # ... (specific operators for KS equation would follow) ``` -------------------------------- ### Initializing HDF5 Writer with ShenfunFile Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/gettingstarted.rst Demonstrates how to initialize an HDF5 writer using the ShenfunFile utility for a 3D TensorProductSpace with Fourier bases. It specifies the file name, space, backend, and mode. ```python from shenfun import * from mpi4py import MPI N = (24, 25, 26) K0 = FunctionSpace(N[0], 'F', dtype='D') K1 = FunctionSpace(N[1], 'F', dtype='D') K2 = FunctionSpace(N[2], 'F', dtype='d') T = TensorProductSpace(MPI.COMM_WORLD, (K0, K1, K2)) fl = ShenfunFile('myh5file', T, backend='hdf5', mode='w') ``` -------------------------------- ### Shenfun Python Implementation Example Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/KuramatoSivashinsky/kuramatosivashinsky.ipynb This snippet demonstrates the basic setup for solving the Kuramato-Sivashinsky equation using the Shenfun library in Python. It imports necessary modules and defines the problem parameters. ```Python import numpy as np from shenfun import * # Define domain and basis domain = (-30*np.pi, 30*np.pi) N = 32 X = FunctionSpace(domain, 'C', N) # Define the KS equation using Shenfun syntax u = TrialFunction(X) v = TestFunction(X) # Define operators (example) # ... (specific operators for KS equation would follow) ``` -------------------------------- ### Shenfun Project Links Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootstrap007.html Provides navigation links within the Shenfun documentation, including a main link to the bootstrap HTML and internal links to various sections like Introduction, Spectral Galerkin Method, and specific equation implementations. ```html [Shenfun - automating the spectral Galerkin method](shenfun_bootstrap.html) * [Contents](#) * [**Table of contents**](._shenfun_bootstrap000.html#table_of_contents) * [**Introduction**](._shenfun_bootstrap001.html#sec:introduction) * [**Spectral Galerkin Method**](._shenfun_bootstrap002.html#sec:preliminaries) * [**Shenfun**](._shenfun_bootstrap003.html#sec:shenfun) *    [Classes for basis functions](._shenfun_bootstrap003.html#___sec3) *    [Classes for matrices](._shenfun_bootstrap003.html#sec:matrices) *    [Variational forms in 1D](._shenfun_bootstrap003.html#___sec5) *    [Poisson equation implemented in 1D](._shenfun_bootstrap003.html#___sec6) *       [Periodic boundary conditions](._shenfun_bootstrap003.html#sec:fourierpoisson) *       [Dirichlet boundary conditions](._shenfun_bootstrap003.html#sec:dirichletpoisson) * [**Tensor product spaces**](._shenfun_bootstrap004.html#sec:tensorproductspaces) * [**Other functionality of `shenfun`**](._shenfun_bootstrap005.html#sec:extended) * [**Ginzburg-Landau equation**](._shenfun_bootstrap006.html#sec:ginzburg) * [**Conclusions**](#___sec12) * [**Acknowledgements**](._shenfun_bootstrap008.html#___sec13) * [**Bibliography**](._shenfun_bootstrap009.html#___sec14) ``` -------------------------------- ### Homogeneous Boundary Conditions Example Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootswatch_cyborg003.html Demonstrates how homogeneous boundary conditions affect function spaces in Shenfun. It shows that after forward and backward transformations, the array remains the same if starting from a Dirichlet function space. ```python fj_copy = fj.copy() fk = SD.forward(fj, fk) fj = SD.backward(fk, fj) assert np.allclose(fj, fj_copy) # Is True ``` -------------------------------- ### Shenfun Table of Contents Navigation Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/shenfun_bootstrap.html HTML structure for the table of contents of the Shenfun documentation, providing links to various sections including Introduction, Spectral Galerkin Method, Shenfun classes, Poisson equation, Tensor product spaces, and more. ```html ``` -------------------------------- ### Shenfun Implementation Example Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Moebius/moebius.do.txt This snippet demonstrates the initial setup for using Shenfun to solve differential equations. It involves defining symbolic variables, setting up rational numbers, and configuring Shenfun's basis vector convention. ```Python from shenfun import * import sympy as sp from IPython.display import Math, Latex, display from scipy.sparse.linalg import eigs config['basisvectors'] = 'covariant' phi, t = psi = sp.symbols('x,y', real=True) RR = sp.Rational(132, 20)/sp.pi # Same as Kalvoda et al #RR = 2 ``` -------------------------------- ### Shenfun FEM Setup Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/shenfun.do.txt Initializes the Shenfun framework by creating a local mesh and defining the trial and test functions for the finite element method. This prepares the system for assembling the finite element matrices. ```python from shenfun import TrialFunction, TestFunction, inner, div, grad, Solver X = T.local_mesh(True) # Assuming T is a pre-defined Shenfun TensorSpace or similar u = TrialFunction(T) v = TestFunction(T) ``` -------------------------------- ### Install Shenfun with Conda Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/installation.rst Installs Shenfun and its dependencies using conda from the conda-forge channel. It's recommended to install into a fresh environment. ```shell conda install -c conda-forge shenfun ``` ```shell conda create --name shenfun -c conda-forge shenfun conda activate shenfun ``` ```shell conda create --name shenfun -c conda-forge shenfun mpich ``` -------------------------------- ### Install Matplotlib Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/installation.rst Instructions for installing the Matplotlib library using conda. Matplotlib is an optional dependency for plotting functionalities. ```bash conda install matplotlib ``` -------------------------------- ### Build HTML Documentation (Optimized) Source: https://github.com/spectraldns/shenfun/blob/master/docs/README.md A faster way to build HTML documentation if the demo files have not been modified. It skips the regeneration of demo files. ```bash make ohtml ``` -------------------------------- ### Tensor Product Spaces for 2D Poisson Equation Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/shenfun.do.txt Demonstrates the setup for solving the 2D Poisson equation using tensor product spaces. It shows how to combine different bases (Chebyshev and Fourier) and configure the `TensorProductSpace` for distributed computation. The example highlights the use of `Function` for distributed arrays and the flexibility in defining boundary conditions. ```python from shenfun.chebyshev.bases import ShenDirichletBasis from shenfun.fourier.bases import FourierBasis import numpy as np from shenfun import Function, TensorProductSpace from mpi4py import MPI comm = MPI.COMM_WORLD N = (32, 33) K0 = ShenDirichletFunctionSpace(N[0]) K1 = FourierFunctionSpace(N[1], dtype=np.float) T = TensorProductSpace(comm, (K0, K1)) # Alternatively, switch order for periodic in first direction instead # T = TensorProductSpace(comm, (K1, K0), axes=(1, 0)) ``` -------------------------------- ### Build Shenfun Locally Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/installation.rst Installs Shenfun from a local directory after cloning or forking the repository. This is often done after installing dependencies via conda. ```shell pip install . ``` ```shell python setup.py build_ext -i ``` -------------------------------- ### Shenfun Project Link Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootstrap000.html A simple HTML link to the main page of the Shenfun project, which is hosted on GitHub. ```html Shenfun - automating the spectral Galerkin method ``` -------------------------------- ### Install Parallel HDF5 and NetCDF4 Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/installation.rst Installs HDF5 and NetCDF4 with MPI support using conda. This is necessary for parallel data storage and retrieval. ```shell conda install -c conda-forge h5py=*=mpi* netcdf4=*=mpi* ``` -------------------------------- ### TensorProductSpace Initialization Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/_sources/shenfun.rst.txt Demonstrates the creation of a TensorProductSpace using ShenDirichletBasis and FourierBasis. It also shows how to switch the order of bases for different distribution strategies. ```python from shenfun.chebyshev.bases import ShenDirichletBasis from shenfun.fourier.bases import FourierBasis import numpy as np from shenfun import Function, TensorProductSpace from mpi4py import MPI comm = MPI.COMM_WORLD N = (32, 33) K0 = ShenDirichletBasis(N[0]) K1 = FourierBasis(N[1], dtype=np.float) T = TensorProductSpace(comm, (K0, K1)) # Alternatively, switch order for periodic in first direction instead # T = TensorProductSpace(comm, (K1, K0), axes=(1, 0)) ``` -------------------------------- ### Shenfun Table of Contents Navigation Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootstrap000.html HTML structure for the table of contents of the Shenfun documentation, providing links to various sections including Introduction, Spectral Galerkin Method, Shenfun classes, Poisson equation, Tensor product spaces, and more. ```html ``` -------------------------------- ### Build HTML Documentation Source: https://github.com/spectraldns/shenfun/blob/master/docs/README.md Generates HTML documentation from docstrings and rst-files. This command also regenerates demo files written in doconce. ```bash make html ``` -------------------------------- ### Run Tests with Pytest Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/installation.rst Command to execute the test suite for Shenfun using pytest. Ensure pytest is installed in the correct conda environment. ```bash python -m pytest tests/ ``` -------------------------------- ### Shenfun Preprocessor Import Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/FastTransforms/fasttransforms.do.txt Imports the preprocessor module, likely for setting up spectral computations. ```python #include "../preprocesser.py" ``` -------------------------------- ### Tensor Product Space and Function Initialization Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootswatch_cyborg006.html Sets up the tensor product space with and without padding for de-aliasing, and declares trial, test, and solution functions. It also initializes the solution from a given input. ```Python # Size of discretization N = (201, 201) # Create tensor product space K0 = C2CBasis(N[0], domain=(-50., 50.)) K1 = C2CBasis(N[1], domain=(-50., 50.)) T = TensorProductSpace(comm, (K0, K1)) Kp0 = C2CBasis(N[0], domain=(-50., 50.), padding_factor=1.5) Kp1 = C2CBasis(N[1], domain=(-50., 50.), padding_factor=1.5) Tp = TensorProductSpace(comm, (Kp0, Kp1)) u = TrialFunction(T) v = TestFunction(T) X = T.local_mesh(True) U = Function(T, False) # Solution U_hat = Function(T) # Solution spectral space Up = Function(Tp, False) # Padded solution for nonlinear term dU_hat = Function(T) # right hand side #initialize U[:] = ul(*X) U_hat = T.forward(U, U_hat) ``` -------------------------------- ### Shenfun Surface Integral Jacobian (Example 2) Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/Integration/surfaceintegration.do.txt Prints the Jacobian determinant for the surface integral calculation in Example 2, which represents the surface area element for the given parametrization. ```python print(T.coors.sg) ``` -------------------------------- ### Shenfun Initialization Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/FastTransforms/fasttransforms.do.txt Imports necessary libraries from Shenfun and mpi4py-fft for performing spectral computations and projections. ```python from shenfun import * from mpi4py_fft import fftw ``` -------------------------------- ### RK4 Integrator Setup and Solve Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/KleinGordon/kleingordon.ipynb Demonstrates the setup and execution of a Runge-Kutta 4th order (RK4) integrator for a simulation. It initializes the integrator with specific parameters and then solves the system over a defined time interval. ```python par = {'Compute_energy': 10, 'plot_tstep': 10, 'end_time': 1} dt = 0.005 integrator = RK4(TT, N=NonlinearRHS, update=update, energy=[""], **par) integrator.setup(dt) fu_hat = integrator.solve(fu, fu_hat, dt, (0, par['end_time'])) ``` -------------------------------- ### Table of Contents Navigation Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootstrap001.html Provides a structured list of links for navigating through the Shenfun documentation, including sections like Introduction, Spectral Galerkin Method, and specific equation implementations. ```html * [Contents](#) * [**Table of contents**](._shenfun_bootstrap000.html#table_of_contents) * [**Introduction**](#sec:introduction) * [**Spectral Galerkin Method**](._shenfun_bootstrap002.html#sec:preliminaries) * [**Shenfun**](._shenfun_bootstrap003.html#sec:shenfun) *    [Classes for basis functions](._shenfun_bootstrap003.html#___sec3) *    [Classes for matrices](._shenfun_bootstrap003.html#sec:matrices) *    [Variational forms in 1D](._shenfun_bootstrap003.html#___sec5) *    [Poisson equation implemented in 1D](._shenfun_bootstrap003.html#___sec6) *       [Periodic boundary conditions](._shenfun_bootstrap003.html#sec:fourierpoisson) *       [Dirichlet boundary conditions](._shenfun_bootstrap003.html#sec:dirichletpoisson) * [**Tensor product spaces**](._shenfun_bootstrap004.html#sec:tensorproductspaces) * [**Other functionality of `shenfun`**](._shenfun_bootstrap005.html#sec:extended) * [**Ginzburg-Landau equation**](._shenfun_bootstrap006.html#sec:ginzburg) * [**Conclusions**](._shenfun_bootstrap007.html#___sec12) * [**Acknowledgements**](._shenfun_bootstrap008.html#___sec13) * [**Bibliography**](._shenfun_bootstrap009.html#___sec14) ``` -------------------------------- ### Shenfun Python Usage Example Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/kleingordon.ipynb Provides a conceptual example of how Shenfun can be used to implement the inner product (nabla u, nabla v), referencing a specific section for a Runge-Kutta integrator implementation. ```Python # Conceptual example of using Shenfun for (nabla u, nabla v) # Refer to Sec. Runge-Kutta integrator for implementation details # from shenfun import ... # ... implementation details ... ``` -------------------------------- ### Tensor Product Space Setup and Biharmonic Solver Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootstrap004.html Demonstrates setting up a tensor product space with different bases (ShenBiharmonicBasis, C2CBasis, R2CBasis) and solving a biharmonic equation using the Biharmonic solver. It includes defining trial and test functions, computing inner products, and performing the backward transform to real space. ```python from shenfun.chebyshev.bases import ShenBiharmonicBasis, Basis from shenfun.fourier.bases import R2CBasis, C2CBasis from shenfun.chebyshev.la import Biharmonic as Solver from shenfun import inner , div , grad , TestFunction, TrialFunction, project, Dx from shenfun import Function, TensorProductSpace from mpi4py import MPI import numpy as np comm = MPI.COMM_WORLD N = (32, 33, 34) K0 = ShenBiharmonicBasis(N[0]) K1 = C2CBasis(N[1]) K2 = R2CBasis(N[2]) W = TensorProductSpace(comm, (K0, K1, K2)) u = TrialFunction(W) v = TestFunction(W) matrices = inner(v, div(grad(div(grad(u))))) fj = Function(W, False) fj[:] = np.random.random(fj.shape) f_hat = inner(v, fj) # Some right hand side B = Solver(**matrices) # Solve and transform to real space u_hat = Function(W) # Solution spectral space u_hat = B(u_hat , f_hat) # Solve u = Function(W, False) u = W.backward(u_hat, u) ``` -------------------------------- ### SparseMatrix Class Methods Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/_sources/shenfun.rst.txt Illustrates the core methods of the SparseMatrix class, including initialization, conversion to Scipy sparse format, matrix-vector product, and solving linear systems. ```python class SparseMatrix(dict): def __init__(self, d, shape): dict.__init__(self, d) self.shape = shape def diags(self, format='dia'): """Return Scipy sparse matrix""" def matvec(self, u, x, format='dia', axis=0): """Return Matrix vector product self*u in x""" def solve(self, b, u=None, axis=0): """Return solution u to self*u = b""" ``` -------------------------------- ### Shenfun Python Usage Example Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/KleinGordon/kleingordon.ipynb Provides a conceptual example of how Shenfun can be used to implement the inner product (nabla u, nabla v), referencing a specific section for a Runge-Kutta integrator implementation. ```Python # Conceptual example of using Shenfun for (nabla u, nabla v) # Refer to Sec. Runge-Kutta integrator for implementation details # from shenfun import ... # ... implementation details ... ``` -------------------------------- ### Basis Functions for Spectral Methods Source: https://github.com/spectraldns/shenfun/blob/master/docs/source/introduction.rst Examples of basis functions used in spectral methods for one spatial dimension, including Chebyshev and Legendre polynomials, and trigonometric functions. Some examples satisfy homogeneous Dirichlet and Neumann boundary conditions. ```mathematica \phi_k(x) = T_k(x) ``` ```mathematica \phi_k(x) = T_k(x) - T_{k+2}(x) ``` ```mathematica \phi_k(x) = L_k(x) ``` ```mathematica \phi_k(x) = L_k(x) - L_{k+2}(x) ``` ```mathematica \phi_k(x) = \exp(\imath k x) ``` ```mathematica \phi_k = T_k-\left(\frac{k}{k+2}\right)^2T_{k+2} ``` ```mathematica \phi_k = L_k-\frac{k(k+1)}{(k+2)(k+3)}L_{k+2} ``` -------------------------------- ### Shenfun Package Basics Source: https://github.com/spectraldns/shenfun/blob/master/docs/demos/mekit17/pub/._shenfun_bootstrap001.html Describes the fundamental aspects of the `shenfun` package, including implementations for simple 1D Poisson and biharmonic problems. This provides a starting point for understanding how Shenfun is used for basic PDE solving. ```APIDOC Shenfun Package Basics: Description: Covers the basics of the `shenfun` package. Implementations: Includes examples for 1D Poisson and biharmonic problems. Related Sections: 'Spectral Galerkin Method', 'Tensor product spaces'. ``` -------------------------------- ### Shenfun Curvilinear Coordinates Example (Sphere) Source: https://github.com/spectraldns/shenfun/blob/master/README.rst This example showcases Shenfun's ability to solve PDEs on curvilinear grids, specifically on a sphere using spherical coordinates. It illustrates how Shenfun automatically handles differential operators in non-Cartesian systems. ```Python from shenfun import * # Define spherical coordinates and grid # ... (code for spherical coordinate system) ... # Define PDE in spherical coordinates # ... (code for PDE formulation) ... # Solve and visualize # ... (code for solving and plotting results) ... ```