aurel.finitedifference

finitedifference.py

This module provides finite difference schemes for computing spatial derivatives of scalar or tensor fields on 3D grids.

It contains the following classes and functions:

  • 4th, 6th, and 8th order finite difference schemes for backward, centered, and forward differences.

  • FiniteDifference: A class that applies finite difference schemes to 3D data grids.

    • Provides Cartesian and Spherical coordinates.

    • Functions for computing the spatial derivatives of rank 0, 1, and 2 tensors along the x, y, and z axes.

    • Function for removing points affected by the boundary condition.

class aurel.finitedifference.FiniteDifference(param, boundary='no boundary', fd_order=4, verbose=True, veryverbose=False)[source]

Bases: object

This class applies the FD schemes to the entire data grid.

Parameters:
  • param (dict) –

    Dictionary containing the data grid parameters:

    ’xmin’, ‘ymin’, ‘zmin’: float, minimum x, y, and z coordinates

    ’dx’, ‘dy’, ‘dz’ : float, elementary grid size in x, y, and z direction

    ’Nx’, ‘Ny’, ‘Nz’ : int, number of data points in x, y, and z direction

  • boundary (string, default 'no boundary') – Options are: ‘periodic’, ‘symmetric’, or ‘no boundary’. If ‘periodic’ or ‘symmetric’ a centered FD scheme is used, otherwise a combination of forward + centered + backward FD schemes are used.

  • fd_order (int, default 4) – 4, 6 or 8 order of FD schemes used.

xarray, yarray, zarray

(jax.numpy.ndarray) - 1D arrays of x, y, and z coordinates.

Type:

jax.numpy.ndarray

ixcenter, iycenter, izcenter

(int) - Indexes of the x, y, and z coordinates closest to zero.

Type:

int

x, y, z

(jax.numpy.ndarray) - 3D arrays of x, y, and z coordinates.

Type:

jax.numpy.ndarray

cartesian_coords

(jax.numpy.ndarray) - 3D array of x, y, and z coordinates.

Type:

jax.numpy.ndarray

r, phi, theta

(jax.numpy.ndarray) - 3D arrays of radius, azimuth, and inclination coordinates.

Type:

jax.numpy.ndarray

spherical_coords

(jax.numpy.ndarray) - 3D array of radius, azimuth, and inclination coordinates.

Type:

jax.numpy.ndarray

mask_len

(int) - Length of the finite difference mask.

Type:

int

cutoffmask(f)[source]

Remove boundary points, for when FDs were applied once.

cutoffmask2(f)[source]

Remove boundary points, for when FDs were applied twice.

d3(f, idx, N)[source]

Apply the finite difference scheme to the data grid.

d3_rank1tensor(f)[source]

Spatial derivatives of a spatial rank 1 tensor: \(\partial_i (f_{j})\) or \(\partial_i (f^{j})\).

d3_rank2tensor(f)[source]

Spatial derivatives of a spatial rank 2 tensor: \(\partial_i (f_{kj})\) or \(\partial_i (f^{kj})\) or \(\partial_i (f^{k}_{j})\).

d3_scalar(f)[source]

Spatial derivatives of a scalar: \(\partial_i (f)\).

d3x(f)[source]

Derivative along x of a scalar: \(\partial_x (f)\).

d3x_rank2tensor(f)[source]

Spatial derivatives along x of a spatial rank 2 tensor: \(\partial_x (f_{kj})\) or \(\partial_x (f^{kj})\) or \(\partial_x (f^{k}_{j})\).

d3y(f)[source]

Derivative along y of a scalar: \(\partial_y (f)\).

d3y_rank2tensor(f)[source]

Spatial derivatives along y of a spatial rank 2 tensor: \(\partial_y (f_{kj})\) or \(\partial_y (f^{kj})\) or \(\partial_y (f^{k}_{j})\).

d3z(f)[source]

Derivative along z of a scalar: \(\partial_z (f)\).

d3z_rank2tensor(f)[source]

Spatial derivatives along z of a spatial rank 2 tensor: \(\partial_z (f_{kj})\) or \(\partial_z (f^{kj})\) or \(\partial_z (f^{k}_{j})\).

excision(finput, isingularity='find')[source]

Excision of the singularity, for when FDs were applied once.

excision2(finput, isingularity='find')[source]

Double singularity excision, for when FDs were applied twice.

reconstruct(data)[source]

If partial simulation box with symmetries, reconstruct full box

aurel.finitedifference.fd4_backward(f, i, inverse_dx)[source]

4th order backward finite difference scheme.

aurel.finitedifference.fd4_centered(f, i, inverse_dx)[source]

4th order centered finite difference scheme.

aurel.finitedifference.fd4_forward(f, i, inverse_dx)[source]

4th order forward finite difference scheme.

aurel.finitedifference.fd6_backward(f, i, inverse_dx)[source]

6th order backward finite difference scheme.

aurel.finitedifference.fd6_centered(f, i, inverse_dx)[source]

6th order centered finite difference scheme.

aurel.finitedifference.fd6_forward(f, i, inverse_dx)[source]

6th order forward finite difference scheme.

aurel.finitedifference.fd8_backward(f, i, inverse_dx)[source]

8th order backward finite difference scheme.

aurel.finitedifference.fd8_centered(f, i, inverse_dx)[source]

8th order centered finite difference scheme.

aurel.finitedifference.fd8_forward(f, i, inverse_dx)[source]

8th order forward finite difference scheme.

aurel.finitedifference.fd_map(func, farray, idx, imin, imax)[source]

Map the finite difference function over the grid.