mlmc.random

Subpackage provides random field generation and GSTools library interface

Submodules

mlmc.random.correlated_field module

mlmc.random.correlated_field.kozeny_carman(porosity, m, factor, viscosity)[source]

Kozeny-Carman law. Empirical relationship between porosity and conductivity.

Parameters:
  • porosity – Porosity value.

  • m – Power. Suitable values are 1 < m < 4

  • factor – Factor [m^2]. Examples: 1e-7 , m = 3.48; juta fibers 2.2e-8 , m = 1.46; glass fibers 1.8e-13, m = 2.89; erruptive material 1e-12 , m = 2.76; erruptive material 1.8e-12, m = 1.99; basalt

  • viscosity – Fluid viscosity [Pa.s], e.g., water: 8.90e-4

Returns:

Conductivity

mlmc.random.correlated_field.positive_to_range(exp, a, b)[source]

Map a positive parameter ‘exp’ from <0, ∞) to <a, b>.

Parameters:
  • exp – Positive parameter (e.g., lognormal variable)

  • a – Lower bound of target interval

  • b – Upper bound of target interval

Returns:

Mapped value in [a, b)

class mlmc.random.correlated_field.Field(name, field=None, param_fields=[], regions=[])[source]

Bases: object

set_points(points)[source]

Set points for field evaluation.

Parameters:

points – Array of points where the field will be evaluated

sample()[source]

Generate or compute a new sample of the field.

Returns:

Sample values of the field

class mlmc.random.correlated_field.Fields(fields)[source]

Bases: object

set_outer_fields(outer)[source]

Set fields to be included in the sampled dictionary.

Parameters:

outer – List of outer field names

set_points(points, region_ids=[], region_map={})[source]

Assign evaluation points to each field.

Parameters:
  • points – Array of points for field evaluation

  • region_ids – Optional array of region ids for each point

  • region_map – Mapping from region name to region id

sample()[source]

Sample all outer fields.

Returns:

Dictionary with field names as keys and sampled arrays as values

class mlmc.random.correlated_field.RandomFieldBase(corr_exp='gauss', dim=2, corr_length=1.0, aniso_correlation=None, mu=0.0, sigma=1.0, log=False, **kwargs)[source]

Bases: object

Base class for generating spatially correlated random fields.

Random field F(x) with mean E[F(x)] = mu(x) and covariance Cov[x_i,x_j]. Stationary covariance: Cov_ij = sigma^2 * exp(-|X^T K X|^(alpha/2)), X = x_i - x_j. Supports optional non-stationary variance sigma(X).

set_points(points, mu=None, sigma=None)[source]

Set points for field evaluation.

Parameters:
  • points – Array of points (N x dim)

  • mu – Optional mean at points

  • sigma – Optional standard deviation at points

sample()[source]

Generate a realization of the random field.

Returns:

Array of field values at set points

class mlmc.random.correlated_field.SpatialCorrelatedField(corr_exp='gauss', dim=2, corr_length=1.0, aniso_correlation=None, mu=0.0, sigma=1.0, log=False, **kwargs)[source]

Bases: RandomFieldBase

Generate spatially correlated fields using covariance matrix and KL decomposition.

cov_matrix()[source]

Compute dense covariance matrix for current points.

Returns:

Covariance matrix

svd_dcmp(precision=0.01, n_terms_range=(1, inf))[source]

Perform truncated SVD for Karhunen-Loeve decomposition.

Parameters:
  • precision – Desired accuracy

  • n_terms_range – Min/max number of KL terms

Returns:

(_cov_l_factor, singular values)

class mlmc.random.correlated_field.GSToolsSpatialCorrelatedField(model, mode_no=1000, log=False, sigma=1, seed=None, mode=None, structured=False)[source]

Bases: RandomFieldBase

Spatially correlated random field generator using GSTools.

This class acts as an adapter between gstools and the MLMC random field interface (mlmc.random.random_field_base.RandomFieldBase). It supports 1D, 2D, and 3D random fields with optional logarithmic transformation, and can generate fields on both structured and unstructured grids.

change_srf(seed)[source]

Reinitialize the GSTools random field with a new random seed.

Parameters:

seed – Random seed used to reinitialize the underlying gstools.SRF instance.

Returns:

None

random_field(seed=None)[source]

Generate a raw random field realization (without scaling or transformation).

Parameters:

seed – Optional random seed for reproducibility. Default is None.

Returns:

numpy.ndarray Field values evaluated at the points defined by set_points().

sample(seed=None)[source]

Evaluate the scaled random field at the defined points.

Parameters:

seed – Optional random seed for reproducibility. Default is None.

Returns:

numpy.ndarray Field values evaluated at the defined points, scaled by sigma and shifted by mu. If log=True, returns exp(sigma * field + mu) instead.

class mlmc.random.correlated_field.FourierSpatialCorrelatedField(corr_exp='gauss', dim=2, corr_length=1.0, aniso_correlation=None, mu=0.0, sigma=1.0, log=False, **kwargs)[source]

Bases: RandomFieldBase

Deprecated: Fourier-based spatial random field generator.

Generates spatial random fields using a truncated Fourier series. Use GSToolsSpatialCorrelatedField instead.

get_normal_distr()[source]

Generate normal distributed random coefficients for Fourier modes.

Returns:

Array of shape (2, mode_no)

gau(mode_no=1000)[source]

Gaussian Fourier spectrum.

Parameters:

mode_no – Number of modes

Returns:

Array of wave vectors (dim, mode_no)

exp(mode_no=1000)[source]

Exponential Fourier spectrum.

Parameters:

mode_no – Number of modes

Returns:

Array of wave vectors (dim, mode_no)

random_field()[source]

Generate a random field using Fourier series.

Returns:

Field values at points

mlmc.random.frac_geom module

mlmc.random.gstools_wrapper module

Module contents

Subpackage provides random field generation and GSTools library interface