Axes

Axes are the one-dimensional building blocks from which grids are constructed. Each axis defines a set of collocation points and the associated differentiation and integration rules along a single coordinate direction. Use create_axis() to build an axis of the desired type, or instantiate one of the concrete classes directly.

numgrids.create_axis(axis_type: AxisType, num_points: int, low: float, high: float, **kwargs) Axis[source]

Create an Axis object of a given type.

Parameters:
  • axis_type (AxisType) – The type of axis (equidistant, periodic, logarithmic, Chebyshev, etc.)

  • num_points (positive int) – Number of grid points along this axis.

  • low (float) – The lowest coordinate value on the axis.

  • high (float) – The highest coordinate value on the axis.

Return type:

Axis object of specified type.

class numgrids.AxisType(*values)[source]

Enumeration of available axis types.

Members

EQUIDISTANT

Uniformly spaced grid points (non-periodic).

EQUIDISTANT_PERIODIC

Uniformly spaced grid points with periodic boundary conditions.

CHEBYSHEV

Chebyshev-node spacing for spectral accuracy on non-periodic domains.

LOGARITHMIC

Logarithmically spaced grid points (requires low > 0).

class numgrids.axes.EquidistantAxis(num_points: int, low: float = 0, high: float = 1, periodic: bool = False, **kwargs)[source]

Axis with uniformly spaced grid points.

Supports both non-periodic and periodic boundary conditions. When periodic, the FFT spectral differentiation method is used; otherwise classical finite differences are employed.

For a periodic axis the last point is not included (it would coincide with the first point after wrapping).

Create an equidistant axis.

Parameters:
  • num_points (int) – Number of grid points.

  • low (float, optional) – Lower coordinate bound (default 0).

  • high (float, optional) – Upper coordinate bound (default 1).

  • periodic (bool, optional) – Whether to apply periodic boundary conditions (default False).

  • **kwargs – Additional keyword arguments forwarded to Axis (e.g. name).

create_diff_operator(grid: Grid, order: int, axis_index: int, acc: int = 4) GridDiff[source]

Create the differentiation operator for this axis.

Dispatches to FFTDiff for periodic axes and FiniteDifferenceDiff otherwise.

property spacing: float

The grid spacing.

plot() None[source]

Visualize the axis points using matplotlib.

class numgrids.axes.ChebyshevAxis(num_points: int, low: float = 0, high: float = 1, **kwargs)[source]

Axis with grid points at Chebyshev nodes.

The Chebyshev nodes are defined as

\[x_k = \cos\!\left(\frac{k\pi}{N-1}\right), \quad k = 0, \ldots, N-1\]

on the canonical interval [-1, 1], then linearly mapped to [low, high]. Points cluster near the boundaries, which avoids the Runge phenomenon and enables spectral accuracy for smooth, non-periodic functions.

Constructor

Parameters:
  • num_points (positive int) – Number of grid points

  • low (float) – Smallest coordinate value

  • high (float) – Greatest coordinate value (included).

create_diff_operator(grid: Grid, order: int, axis_index: int, acc: int = 4) GridDiff[source]

Create Chebyshev spectral differentiation operator.

Note: acc is accepted for API consistency but not used by the Chebyshev spectral method.

class numgrids.axes.LogAxis(num_points: int, low: float, high: float, **kwargs)[source]

Axis with logarithmically spaced grid points.

Internally the coordinate is transformed to a uniform grid on [ln(low), ln(high)]. Differentiation uses finite differences on the log-scale and applies the chain rule

\[\frac{df}{dx} = \frac{1}{x}\,\frac{df}{d(\ln x)}\]

This is useful for problems where fine resolution is needed near the lower boundary (e.g. radial coordinates close to zero).

low must be strictly positive.

Constructor for LogAxis

Parameters:
  • num_points (positive int) – Number of grid points (endpoint included)

  • low (float) – Lowest coordinate value

  • high (float) – Highest coordinate value

create_diff_operator(grid: Grid, order: int, axis_index: int, acc: int = 6) GridDiff[source]

Create logarithmic differentiation operator.