gstools.field.generator

GStools subpackage providing generators for spatial random fields.

The following classes are provided

RandMeth(model[, mode_no, seed, verbose]) Randomization method for calculating isotropic spatial random fields.
IncomprRandMeth(model[, mean_velocity, …]) RandMeth for incompressible random vector fields.
class gstools.field.generator.RandMeth(model, mode_no=1000, seed=None, verbose=False, **kwargs)[source]

Bases: object

Randomization method for calculating isotropic spatial random fields.

Parameters:
  • model (CovModel) – Covariance model
  • mode_no (int, optional) – Number of Fourier modes. Default: 1000
  • seed (int or None, optional) – The seed of the random number generator. If “None”, a random seed is used. Default: None
  • verbose (bool, optional) – Be chatty during the generation. Default: False
  • **kwargs – Placeholder for keyword-args

Notes

The Randomization method is used to generate isotropic spatial random fields characterized by a given covariance model. The calculation looks like:

u\left(x\right)=
\sqrt{\frac{\sigma^{2}}{N}}\cdot
\sum_{i=1}^{N}\left(
Z_{1,i}\cdot\cos\left(\left\langle k_{i},x\right\rangle \right)+
Z_{2,i}\cdot\sin\left(\left\langle k_{i},x\right\rangle \right)
\right)

where:

  • N : fourier mode number
  • Z_{j,i} : random samples from a normal distribution
  • k_i : samples from the spectral density distribution of the covariance model
Attributes:
mode_no

int: Number of modes in the randomization method.

model

CovModel: Covariance model of the spatial random field.

name

str: Name of the generator.

seed

int: Seed of the master RNG.

value_type

str: Type of the field values (scalar, vector).

verbose

bool: Verbosity of the generator.

Methods

__call__(self, x[, y, z, mesh_type]) Calculate the random modes for the randomization method.
reset_seed(self[, seed]) Recalculate the random amplitudes and wave numbers with the given seed.
update(self[, model, seed]) Update the model and the seed.
__call__(self, x, y=None, z=None, mesh_type='unstructured')[source]

Calculate the random modes for the randomization method.

This method calls the summate_* Cython methods, which are the heart of the randomization method.

Parameters:
Returns:

the random modes

Return type:

numpy.ndarray

reset_seed(self, seed=nan)[source]

Recalculate the random amplitudes and wave numbers with the given seed.

Parameters:seed (int or None or numpy.nan, optional) – the seed of the random number generator. If None, a random seed is used. If numpy.nan, the actual seed will be kept. Default: numpy.nan

Notes

Even if the given seed is the present one, modes will be recalculated.

update(self, model=None, seed=nan)[source]

Update the model and the seed.

If model and seed are not different, nothing will be done.

Parameters:
mode_no

Number of modes in the randomization method.

Type:int
model

Covariance model of the spatial random field.

Type:CovModel
name

Name of the generator.

Type:str
seed

Seed of the master RNG.

Notes

If a new seed is given, the setter property not only saves the new seed, but also creates new random modes with the new seed.

Type:int
value_type

Type of the field values (scalar, vector).

Type:str
verbose

Verbosity of the generator.

Type:bool
class gstools.field.generator.IncomprRandMeth(model, mean_velocity=1.0, mode_no=1000, seed=None, verbose=False, **kwargs)[source]

Bases: gstools.field.generator.RandMeth

RandMeth for incompressible random vector fields.

Parameters:
  • model (CovModel) – covariance model
  • mean_velocity (float, optional) – the mean velocity in x-direction
  • mode_no (int, optional) – number of Fourier modes. Default: 1000
  • seed (int or None, optional) – the seed of the random number generator. If “None”, a random seed is used. Default: None
  • verbose (bool, optional) – State if there should be output during the generation. Default: False
  • **kwargs – Placeholder for keyword-args

Notes

The Randomization method is used to generate isotropic spatial incompressible random vector fields characterized by a given covariance model. The equation is:

u_i\left(x\right)= \bar{u_i} \delta_{i1} +
\bar{u_i}\sqrt{\frac{\sigma^{2}}{N}}\cdot
\sum_{j=1}^{N}p_i(k_{j})\left(
Z_{1,j}\cdot\cos\left(\left\langle k_{j},x\right\rangle \right)+
Z_{2,j}\cdot\sin\left(\left\langle k_{j},x\right\rangle \right)
\right)

where:

  • \bar u : mean velocity in e_1 direction
  • N : fourier mode number
  • Z_{k,j} : random samples from a normal distribution
  • k_j : samples from the spectral density distribution of the covariance model
  • p_i(k_j) = e_1 - \frac{k_i k_1}{k^2} : the projector ensuring the incompressibility
Attributes:
mode_no

int: Number of modes in the randomization method.

model

CovModel: Covariance model of the spatial random field.

name

str: Name of the generator.

seed

int: Seed of the master RNG.

value_type

str: Type of the field values (scalar, vector).

verbose

bool: Verbosity of the generator.

Methods

__call__(self, x[, y, z, mesh_type]) Calculate the random modes for the randomization method.
reset_seed(self[, seed]) Recalculate the random amplitudes and wave numbers with the given seed.
update(self[, model, seed]) Update the model and the seed.
__call__(self, x, y=None, z=None, mesh_type='unstructured')[source]

Calculate the random modes for the randomization method.

This method calls the summate_incompr_* Cython methods, which are the heart of the randomization method. In this class the method contains a projector to ensure the incompressibility of the vector field.

Parameters:
  • x (float, numpy.ndarray) – the x components of the position tuple, the shape has to be (len(x), 1, 1) for 3d and accordingly shorter for lower dimensions
  • y (float, numpy.ndarray, optional) – the y components of the pos. tuples. Default: None
  • z (float, numpy.ndarray, optional) – the z components of the pos. tuple. Default: None
  • mesh_type (str, optional) – ‘structured’ / ‘unstructured’
Returns:

the random modes

Return type:

numpy.ndarray

reset_seed(self, seed=nan)

Recalculate the random amplitudes and wave numbers with the given seed.

Parameters:seed (int or None or numpy.nan, optional) – the seed of the random number generator. If None, a random seed is used. If numpy.nan, the actual seed will be kept. Default: numpy.nan

Notes

Even if the given seed is the present one, modes will be recalculated.

update(self, model=None, seed=nan)

Update the model and the seed.

If model and seed are not different, nothing will be done.

Parameters:
mode_no

Number of modes in the randomization method.

Type:int
model

Covariance model of the spatial random field.

Type:CovModel
name

Name of the generator.

Type:str
seed

Seed of the master RNG.

Notes

If a new seed is given, the setter property not only saves the new seed, but also creates new random modes with the new seed.

Type:int
value_type

Type of the field values (scalar, vector).

Type:str
verbose

Verbosity of the generator.

Type:bool