porepy.utils.array_operations module

The module contains various functions and classes useful for operations on numpy ndarrays.

class SparseNdArray(dim, value_dim=1)[source]

Bases: object

Data structure for representing N-dimensional sparse arrays.

The underlying data format is a generalization of the COO-format (in the scipy.sparse sense). The dimension is fixed upon initialization, but no bounds are set on the maximum and minimum coordinates. The coordinates are restricted to integers, thus, if the data to be stored lives a grid with non-integer ‘grid-lines’, the data should be mapped prior to feeding it to the data. To do this, it is recommended to consider the class AdaptiveInterpolationTable.

Parameters
  • dims (int) – Number of coordinate axes of the table.

  • value_dim (int) – Dimension of the values to be represented in the array. Defaults to 1.

  • dim (int) –

add(coords, values, additive=False)[source]

Add one or several new data points to the interpolation table.

Values of new coordinates are added to the array. Coordinates that were already represented in the table have their values increased or overwritten, see parameter additive.

Parameters
  • coords (list[numpy.ndarray]) – List of coordinates, each corresponding to an indivdiual data point.

  • values (ndarray) – New values. Each element corresponds to an item in the list of new coordinates.

  • additive (bool) – If True, values associated with duplicate coordinates (either between new and existing coordinates, or within the new coordinates) are added. If False, existing values will be overwritten by the new value (if there are duplicates in new coordinates the last of this coordinates are used). Defaults to False.

Returns

Permutation vector applied before the coordinates and data were

added to storage.

Return type

np.ndarray

get(coords)[source]

Retrieve values from the sparse array.

Parameters

coords (list[np.ndarray]) – List of coordinates, each corresponding to an indivdiual data point.

Raises

ValueError – If a coordinate is not present in this array.

Returns

Values associated with the items in coords.

Return type

np.ndarray

intersect_sets(a, b, tol=1e-10)[source]

Intersect two sets to find common elements up to a tolerance.

Parameters
  • a (np.ndarray, shape nd x n_pts) – The first set to be intersected. The columns of a form set members.

  • b (np.ndarray, shape nd x n_pts) – The second set to be intersected. The columns of b form set members.

  • tol (float, optional) – Tolerance used in comparison of set members. Defaults to 1e-10.

Returns

Column indices of a, so that a[:, ia] is found in

b. Information of which elements in a and b that are equal can be obtained from the return intersection.

ib (np.ndarray, dtype int): Column indices of b, so that b[:, ib] is found in

a. Information of which elements in a and b that are equal can be obtained from the return intersection.

a_in_b (np.ndarray, dtype int): Element i is true if a[:, i]

is found in b. To get the reverse, b_in_a, switch the order of the arguments.

intersection (list of list of int): The outer list has one element for each

column in a. Each element in the outer list is itself a list which contains column indices of all elements in b that corresponds to this element of a. If there is no such elements in b, the inner list is empty.

Return type

ia (np.ndarray, dtype int)