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:
2nd, 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, and function to convert between them.
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:
objectThis 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) – 2, 4, 6 or 8 order of FD schemes used.
- xarray, yarray, zarray
(numpy.ndarray) - 1D arrays of x, y, and z coordinates.
- Type:
numpy.ndarray
- xmin, ymin, zmin
(float) - Minimum x, y, and z coordinates.
- Type:
float
- xmax, ymax, zmax
(float) - Maximum x, y, and z coordinates.
- Type:
float
- Nx, Ny, Nz
(int) - Number of data points in x, y, and z directions.
- Type:
int
- ixcenter, iycenter, izcenter
(int) - Indexes of the x, y, and z coordinates closest to zero.
- Type:
int
- x, y, z
(numpy.ndarray) - 3D arrays of x, y, and z coordinates.
- Type:
numpy.ndarray
- cartesian_coords
(numpy.ndarray) - 3D array of x, y, and z coordinates.
- Type:
numpy.ndarray
- r, phi, theta
(numpy.ndarray) - 3D arrays of radius, inclination/polar and azimuth coordinates.
- Type:
numpy.ndarray
- spherical_coords
(numpy.ndarray) - 3D array of radius, inclination/polar and azimuth coordinates.
- Type:
numpy.ndarray
- mask_len
(int) - Length of the finite difference mask.
- Type:
int
- cartesian_to_spherical(x, y, z)[source]
Convert Cartesian coordinates to Spherical coordinates.
- Parameters:
x (numpy.ndarray) – arrays of Cartesian coordinates.
y (numpy.ndarray) – arrays of Cartesian coordinates.
z (numpy.ndarray) – arrays of Cartesian coordinates.
- Returns:
r, theta, phi – arrays of radius, inclination/polar and azimuth coordinates.
- Return type:
numpy.ndarray
- 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})\).
- d3x_rank1tensor(f)[source]
Spatial derivatives of a spatial rank 1 tensor: \(\partial_x (f_{j})\) or \(\partial_x (f^{j})\).
- 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_rank1tensor(f)[source]
Spatial derivatives of a spatial rank 1 tensor: \(\partial_y (f_{j})\) or \(\partial_y (f^{j})\).
- 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_rank1tensor(f)[source]
Spatial derivatives of a spatial rank 1 tensor: \(\partial_z (f_{j})\) or \(\partial_z (f^{j})\).
- 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.
- spherical_to_cartesian(r, theta, phi)[source]
Convert Spherical coordinates to Cartesian coordinates.
- Parameters:
r (numpy.ndarray) – arrays of radius, inclination/polar and azimuth coordinates.
theta (numpy.ndarray) – arrays of radius, inclination/polar and azimuth coordinates.
phi (numpy.ndarray) – arrays of radius, inclination/polar and azimuth coordinates.
- Returns:
x, y, z – arrays of Cartesian coordinates.
- Return type:
numpy.ndarray
- aurel.finitedifference.fd2_backward(f, i, inverse_dx)[source]
2nd order backward finite difference scheme.
- aurel.finitedifference.fd2_centered(f, i, inverse_dx)[source]
2nd order centered finite difference scheme.
- aurel.finitedifference.fd2_forward(f, i, inverse_dx)[source]
2nd order forward finite difference scheme.
- 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.