odatse.util.neighborlist module

class odatse.util.neighborlist.Cells(mins: ndarray, maxs: ndarray, cellsize: float)[source]

Bases: object

A class to represent a grid of cells for spatial partitioning.

Initialize the Cells object.

Parameters:
  • mins (np.ndarray) – The minimum coordinates of the grid.

  • maxs (np.ndarray) – The maximum coordinates of the grid.

  • cellsize (float) – The size of each cell.

__init__(mins: ndarray, maxs: ndarray, cellsize: float)[source]

Initialize the Cells object.

Parameters:
  • mins (np.ndarray) – The minimum coordinates of the grid.

  • maxs (np.ndarray) – The maximum coordinates of the grid.

  • cellsize (float) – The size of each cell.

cellcoord2cellindex(ns: ndarray) int[source]

Convert cell coordinates to a cell index.

Parameters:

ns (np.ndarray) – The cell coordinates to convert.

Returns:

The index of the cell.

Return type:

int

cellindex2cellcoord(index: int) ndarray[source]

Convert a cell index to cell coordinates.

Parameters:

index (int) – The index of the cell.

Returns:

The cell coordinates.

Return type:

np.ndarray

coord2cellcoord(x: ndarray) ndarray[source]

Convert coordinates to cell coordinates.

Parameters:

x (np.ndarray) – The coordinates to convert.

Returns:

The cell coordinates.

Return type:

np.ndarray

coord2cellindex(x: ndarray) int[source]

Convert coordinates to a cell index.

Parameters:

x (np.ndarray) – The coordinates to convert.

Returns:

The index of the cell.

Return type:

int

neighborcells(index: int) List[int][source]

Get the indices of neighboring cells.

Parameters:

index (int) – The index of the cell.

Returns:

The indices of the neighboring cells.

Return type:

List[int]

out_of_bound(ns: ndarray) bool[source]

Check if cell coordinates are out of bounds.

Parameters:

ns (np.ndarray) – The cell coordinates to check.

Returns:

True if out of bounds, False otherwise.

Return type:

bool

odatse.util.neighborlist.load_neighbor_list(filename: PathLike, nnodes: int = None) List[List[int]][source]

Load a neighbor list from a file.

Parameters:
  • filename (PathLike) – The path to the file containing the neighbor list.

  • nnodes (int, optional) – The number of nodes. If None, it will be determined from the file.

Returns:

The neighbor list.

Return type:

List[List[int]]

odatse.util.neighborlist.make_neighbor_list(X: ndarray, radius: float, allow_selfloop: bool = False, check_allpairs: bool = False, show_progress: bool = False, comm: Comm = None) List[List[int]][source]

Create a neighbor list for given points.

Parameters:
  • X (np.ndarray) – The coordinates of the points.

  • radius (float) – The radius within which neighbors are considered.

  • allow_selfloop (bool) – Whether to allow self-loops in the neighbor list.

  • check_allpairs (bool) – Whether to use the naive all-pairs approach.

  • show_progress (bool) – Whether to show a progress bar.

  • comm (mpi.Comm, optional) – The MPI communicator.

Returns:

The neighbor list.

Return type:

List[List[int]]

odatse.util.neighborlist.make_neighbor_list_cell(X: ndarray, radius: float, allow_selfloop: bool, show_progress: bool, comm: Comm = None) List[List[int]][source]

Create a neighbor list using cell-based spatial partitioning.

Parameters:
  • X (np.ndarray) – The coordinates of the points.

  • radius (float) – The radius within which neighbors are considered.

  • allow_selfloop (bool) – Whether to allow self-loops in the neighbor list.

  • show_progress (bool) – Whether to show a progress bar.

  • comm (mpi.Comm, optional) – The MPI communicator.

Returns:

The neighbor list.

Return type:

List[List[int]]

odatse.util.neighborlist.make_neighbor_list_naive(X: ndarray, radius: float, allow_selfloop: bool, show_progress: bool, comm: Comm = None) List[List[int]][source]

Create a neighbor list using a naive all-pairs approach.

Parameters:
  • X (np.ndarray)) – The coordinates of the points.

  • radius (float) – The radius within which neighbors are considered.

  • allow_selfloop (bool) – Whether to allow self-loops in the neighbor list.

  • show_progress (bool) – Whether to show a progress bar.

  • comm (mpi.Comm, optional) – The MPI communicator.

Returns:

The neighbor list.

Return type:

List[List[int]]

odatse.util.neighborlist.write_neighbor_list(filename: str, nnlist: List[List[int]], radius: float = None, unit: ndarray = None)[source]

Write the neighbor list to a file.

Parameters:
  • filename (str) – The path to the output file.

  • nnlist (List[List[int]]) – The neighbor list to write.

  • radius (float, optional) – The neighborhood radius. Defaults to None.

  • unit (np.ndarray, optional) – The unit for each coordinate. Defaults to None.