Particle to Grid¶
Overview¶
The particle-to-grid routines assign particle quantities onto regular Cartesian meshes using standard particle-mesh interpolation schemes.
Supported assignment methods:
NGP: Nearest Grid PointCIC: Cloud-In-CellTSC: Triangular Shaped CloudPCS: Piecewise Cubic Spline
The density field of a cosmological simulation computed with particle-to-grid methods.
The log-density of the same density field.
Example: 2D Grid Assignment Densities¶
import numpy as np
import fiesta
np.random.seed(0)
x = np.random.uniform(0, 1, 10000)
y = np.random.uniform(0, 1, 10000)
# f here represent particle weights/masses, we will assume they are all equal.
f = np.ones_like(x)
dgrid = fiesta.part2grid2D(
x, y, f,
boxsize=1.0,
ngrid=256,
method='CIC'
)
Example: 2D Grid Assignment Fields¶
import numpy as np
import fiesta
np.random.seed(0)
x = np.random.uniform(0, 1, 10000)
y = np.random.uniform(0, 1, 10000)
# f here represent particle weights/masses, we will assume they are all equal.
f = np.ones_like(x)
dgrid = fiesta.part2grid2D(
x, y, f,
boxsize=1.0,
ngrid=256,
method='CIC'
)
# Let's assume we have velocities and we want to compute the velocity field.
v = np.random.uniform(x)
vgrid = fiesta.part2grid2D(
x, y, v,
boxsize=1.0,
ngrid=256,
method='CIC'
)
# vgrid is a momentum field since it weights the grid by the number of points
# so we must normalise to get the correct field values.
vgrid /= dgrid
Example: 3D Grid Assignment Densities¶
import numpy as np
import fiesta
np.random.seed(0)
x = np.random.uniform(0, 1, 10000)
y = np.random.uniform(0, 1, 10000)
z = np.random.uniform(0, 1, 10000)
# f here represent particle weights/masses, we will assume they are all equal.
f = np.ones_like(x)
dgrid = fiesta.part2grid3D(
x, y, z, f,
boxsize=1.0,
ngrid=256,
method='TSC'
)
Example: 3D Grid Assignment Fields¶
import numpy as np
import fiesta
np.random.seed(0)
x = np.random.uniform(0, 1, 10000)
y = np.random.uniform(0, 1, 10000)
z = np.random.uniform(0, 1, 10000)
# f here represent particle weights/masses, we will assume they are all equal.
f = np.ones_like(x)
dgrid = fiesta.part2grid3D(
x, y, z, f,
boxsize=1.0,
ngrid=256,
method='TSC'
)
# Let's assume we have velocities and we want to compute the velocity field.
v = np.random.uniform(x)
vgrid = fiesta.part2grid3D(
x, y, z, v,
boxsize=1.0,
ngrid=256,
method='TSC'
)
# vgrid is a momentum field since it weights the grid by the number of points
# so we must normalise to get the correct field values.
vgrid /= dgrid
API Reference¶
- fiesta.p2g.part2grid2D(x: ndarray, y: ndarray, f: ndarray, boxsize: float | List[float], ngrid: int | List[int], method: str = 'TSC', periodic: bool | List[bool] = True, origin: float | List[float] = 0.0) ndarray
Returns the density contrast for the nearest grid point grid assignment.
- Parameters:
x (array) – X coordinates of the particle.
y (array) – Y coordinates of the particle.
f (array) – Value of each particle to be assigned to the grid.
ngrid (int) – Grid divisions across one axis.
method (str, optional) – Grid assignment scheme, either ‘NGP’, ‘CIC’, ‘TSC’ or ‘PCS’.
periodic (bool or list, optional) – Assign particles with periodic boundaries.
- Returns:
fgrid – Grid assigned values.
- Return type:
array
- fiesta.p2g.part2grid3D(x: ndarray, y: ndarray, z: ndarray, f: ndarray, boxsize: float | List[float], ngrid: float | List[float], method: str = 'TSC', periodic: bool | List[bool] = True, origin: float | List[float] = 0.0) ndarray
Returns the density contrast for the nearest grid point grid assignment.
- Parameters:
x (array) – X coordinates of the particle.
y (array) – Y coordinates of the particle.
z (array) – Z coordinates of the particle.
f (array) – Value of each particle to be assigned to the grid.
method (str, optional) – Grid assignment scheme, either ‘NGP’, ‘CIC’, ‘TSC’ or ‘PCS’.
periodic (bool or list, optional) – Assign particles with periodic boundaries.
- Returns:
fgrid – Grid assigned values.
- Return type:
array