pyrtid.utils#

pyRTID submodule providing tools and utilities for other submodules.

Working with dataclasses#

Utilities for python dataclasses.

default_field(obj)

Helper to set a default value for a dataclass field.

Regular grids#

Provide utilities to work with regular grids.

indices_to_node_number(ix[, nx, iy, ny, iz, ...])

Convert indices (ix, iy, iz) to a node-number.

node_number_to_indices(node_number[, nx, ...])

Convert a node-number to indices (ix, iy, iz) for a regular grid.

span_to_node_numbers_2d(span, nx, ny)

Convert the given span to an array of node indices.

span_to_node_numbers_3d(span, nx, ny, nz)

Convert the given span to an array of node indices.

get_array_borders_selection_2d(nx, ny)

Get a selection of the array border as a bool array.

get_array_borders_selection_3d(nx, ny, nz)

Get a selection of the array border as a bool array.

get_a_not_in_b_1d(a, b)

Return the elements of a not found in b sorted by ascending order.

get_pts_coords_regular_grid(mesh_dim, shape)

Create an array of points coordinates for regular grids.

create_selections_array_2d(polygons, ...)

Return a grid array containing the sel_ids as values.

RectilinearGrid([x0, y0, z0, dx, dy, dz, ...])

Represent a rectilinear 3D grid.

get_polygon_selection_with_dilation_2d(...)

Extend the selections using binary dilation.

get_extended_grid_shape(grid, axis, extend)

WellField#

Utilities to create wellfields.

gen_wells_coordinates(startx, starty, endx, ...)

Generate sequences of injectors and producers coordinates.

Random fields#

Provide utilities to generate random fields. This is based on the GStools package.

gen_random_ensemble(model, n_ensemble, var, ...)

Generate a (ne, nx, ny, nz) ensemble of 3D random fields.

get_normalized_mean_from_lognormal_params(...)

Get the mean of the normalized log-normal distribution.

get_normalized_std_from_lognormal_params(...)

Get the standard deviation of the normalized log-normal distribution.

get_log_normalized_mean_from_normal_params(...)

Get the mean of the log-normalized normal distribution.

get_log_normalized_std_from_normal_params(...)

Get the mean of the log-normalized normal distribution.

Working string enums#

Provide a str enum class.u

StrEnum(value[, names, module, qualname, ...])

Hashable string Enum.

Numerical approximation by finite differences#

Provide functions to compute the gradient of a function by finite difference numerical approximation.

finite_jacobian(x, fm[, fm_args, fm_kwargs, ...])

Compute the Jacobian by finite difference.

finite_gradient(x, fm[, fm_args, fm_kwargs, ...])

Compute the gradient by finite difference.

is_all_close(v1, v2[, eps])

Return whether the two vectors are approximately equal.

is_jacobian_correct(x, fm, jac[, fm_args, ...])

Check by finite difference if the Jacobian matrix is correct.

is_gradient_correct(x, fm, grad[, fm_args, ...])

Check by finite difference if the gradient is correct.

Spatial differential operators#

Provide functions for spatial differentiation.

gradient_ffd(param, dx[, axis])

Compute the gradient using the first order forward differences.

gradient_bfd(param, dx[, axis])

Compute the gradient using the first order forward differences.

hessian_cfd(param, dx[, axis])

Compute the hessian matching gradient_ffd.

Mean operators#

Provide functions to perform mean and their first derivative.

arithmetic_mean(xi, xj)

Return the arithmetic mean of xi and xj.

dxi_arithmetic_mean(xi, xj)

Return the first derivative of xi and xj arithmetic mean with respect to xi.

harmonic_mean(xi, xj)

Return the harmonic mean of xi and xj.

dxi_harmonic_mean(xi, xj)

Return the first derivative of xi and xj arithmetic mean with respect to xi.

MeanType(value[, names, module, qualname, ...])

get_mean_values_for_last_axis(arr, mean_type)

Get the mean values for the last axis of the input array.

amean_gradient(values[, weights])

Return the gradient of the weighted arithmetic mean.

gmean_gradient(values[, weights])

Return the gradient of the weighted geometric mean.

hmean_gradient(values[, weights])

Return the gradient of the harmonic arithmetic mean.

get_mean_values_gradient_for_last_axis(arr, ...)

Get the mean values for the last axis of the input array.

Filters#

Provide some spatial filters

Filter()

A gradient filter.

GaussianFilter(sigmas[, order, mode, cval, ...])

Apply gaussian filter filtering.

Others#

Other functions

object_or_object_sequence_to_list(_input)

Convert a singleton or an iterable of this object to a list of object.

get_super_ilu_preconditioner(mat, **kwargs)

Get an incomplete LU preconditioner for the given sparse matrix.

show_versions(logger)

Show the versions of all packages used by pyrtid.

check_random_state(seed)

Turn seed into a np.random.RandomState instance.

Types#

Other functions

NDArrayFloat

ndarray(shape, dtype=float, buffer=None, offset=0,

NDArrayInt

ndarray(shape, dtype=float, buffer=None, offset=0,

NDArrayBool

ndarray(shape, dtype=float, buffer=None, offset=0,

Int

alias of Union[int, ndarray[Any, dtype[int64]], Sequence[int]]

Sparse helpers#

Helpers to work with sparse matrices and sparse arrays.

sparse_cholesky(arr)

assert_allclose_sparse(A, B[, atol, rtol])

Assert that two sparse matrices or arrays are almost equal.