PyGL API

PyGL banner

PyGL is a numerical library for statistical field theory in Python. The name GL corresponds to the Ginzburg–Landau theory. The library has been specifically designed to study field theories without time-reversal symmetry. The library can be used to study models of statistical physics of various symmetries and conservation laws. In particular, we allow models with mass and momentum conservations. The library constructs differentiation matrices using finite-difference and spectral methods. To study the role of momentum conservation, the library also allows computing fluid flow from the solution of the Stokes equation.

Please see installation instructions and more details in the README.md on GitHub.

API Reference

Differentiation Matrices

Differentiation matrices using finite differentiation and spectral methods

Finite Differentiation Matrices

class pygl.dms.FD

Finite Differenc (central) NxN differentiation matrix (DM)

diffmat

m-th order differentiation matrix using central differences.

diffweight

*weights of the m-th order derivative using central Difference *this can be read from the table if the code needs to be made fast *first generate the table using the code! Read more: Bengt Fornberg SIAM Review, Vol. 40, No. 3 (Sep., 1998) Calculation of Weights in Finite Difference Formulas

Fourier Spectral Matrices

class pygl.dms.FourierSpectral

Spectral method using Fourier tranform to compute differentiation matrices (DM)

dealias

dealias operator kDA: fraction of the wavectors which are not set to zero

diffmat

m-th order differentiation matrix using FourierSpectral

Stokes flow on a grid

Stokes flow on a grid in two- and three-dimensions

class pygl.solvers.Stokes

Numerical solution of Stokes equation on 2D or 3D grid.

Parameters:
  • eta (float) – Viscosity of the fluid (eta)
  • grid (dict) – Grid and its properties as a dict

Example

>>> import pygl
>>> eta    = .1
>>> grid   = {"dim":2, "Nx":32, "Ny":32}
>>> stokes = pygl.solvers.Stokes(eta, grid)
solve

Compute flow given force per unit area

self.vx, self.vy and self.vz contains the flow computed

Parameters:fk (np.array) – Fourier transform of the force per unit area on the grid

Example

>>> import pygl
>>> eta    = .1
>>> grid   = {"dim":2, "Nx":32, "Ny":32}
>>> stokes = pygl.solvers.Stokes(eta, grid)
>>> fkx    = np.random.random((32, 32))
>>> fky    = np.random.random((32, 32))
>>> stokes.solve( (fkx, fky) )

Utils

utils.azimuthalAverage()

Obtains radial distribution of field

Parameters:
  • u (A field variable to be averaged) –
  • r (Radial vector of same shape) –
  • bins (how many bins to do) –
Returns:

  • r (value of the radial component)
  • ur (the averaged field along radial direction)

utils.azimuthalAverage2()

Obtains radial distribution of field u

Parameters:u (A field defined on a grid of two-dimension) –
Returns:ur
Return type:the averaged field along radial direction
utils.bubble()
utils.droplet()
utils.ellipseDroplet()
utils.structureFactor()
  • Computes S(k) = <u(k)u(-k)> given the u(r)
  • This is computed using FFT of u to obtain u(k)
  • For a real field u, the multiplication of u(k)u(-k)

is same as (abs(u(k)))^2

Parameters:
  • u (A field on a grid in dim dimensions) –
  • dim (dimensionality) –
Returns:

Return type:

structureFactor defined (abs(u(k)))^2/N^2

utils.structureFactor()
  • Computes S(k) = <u(k)u(-k)> given the u(r)
  • This is computed using FFT of u to obtain u(k)
  • For a real field u, the multiplication of u(k)u(-k)

is same as (abs(u(k)))^2

Parameters:
  • u (A field on a grid in dim dimensions) –
  • dim (dimensionality) –
Returns:

Return type:

structureFactor defined (abs(u(k)))^2/N^2

Differentiation using loops (unlike pygl.dms)

class pygl.utils.FiniteDifference

Finite Difference using loops

diffx

computes d/dx u

diffx1

computes d/dx u

diffx2

computes d/dx u

diffy

computes d/dy u

diffy1

computes d/dy u

diffy2

computes d/dx u

lap2

computes d/dx u

laplacian

computes D^2 u