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
- 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
- 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:
objectBase 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).
- 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:
RandomFieldBaseGenerate spatially correlated fields using covariance matrix and KL decomposition.
- class mlmc.random.correlated_field.GSToolsSpatialCorrelatedField(model, mode_no=1000, log=False, sigma=1, seed=None, mode=None, structured=False)[source]
Bases:
RandomFieldBaseSpatially correlated random field generator using GSTools.
This class acts as an adapter between
gstoolsand 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.SRFinstance.- 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
sigmaand shifted bymu. Iflog=True, returnsexp(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:
RandomFieldBaseDeprecated: 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)
mlmc.random.frac_geom module
mlmc.random.gstools_wrapper module
Module contents
Subpackage provides random field generation and GSTools library interface