stem.field_generator module

class stem.field_generator.FieldGeneratorABC

Bases: ABC

Abstract class to generate fields as function of points coordinates (x, y and z). The function should implement a generate method to initialise the field and the values property to retrieve the generated field.

abstract generate(coordinates: ndarray[tuple[Any, ...], dtype[float64]])

Abstract method to generate the fields for the required coordinates. It has to set the generated_field attribute.

Args:
  • coordinates (numpy.typing.NDArray[np.float64]): Sequence of points where the field needs to be generated.

Raises:
  • Exception: abstract class of generate is called

abstract property generated_fields: List[List[Any]] | None

Abstract property of the generated field.

Raises:
  • ValueError: if field is not generated using the generate() method

Returns:
  • Optional[List[List[Any]]]: the list of generated values for the fields.

class stem.field_generator.RandomFieldGenerator(model_name: str, cov: float, v_scale_fluctuation: float, anisotropy: float | List[float], angle: float | List[float], mean_value: int | float | None = None, seed: int = 14)

Bases: FieldGeneratorABC

Class to generate random fields for a material property in the model as function of the coordinates of the centroid of the elements (x, y and z).

Inheritance:
  • FieldGeneratorABC: abstract class to generate fields as function of points coordinates (x, y and z).

Attributes:
  • __generated_field (Optional[List[float]]): The generated field values. Defaults to None.

  • model_name (str): Name of the model to be used. Options are: “Gaussian”, “Exponential”, “Matern”, “Linear”

  • n_dim (int): number of dimensions of the model (2 or 3).

  • cov (float): The coefficient of variation of the random field.

  • v_scale_fluctuation (float): The vertical scale of fluctuation of the random field.

  • anisotropy (list): The anisotropy of the random field in the other directions (per dimension).

  • angle (list): The angle of the random field (per dimension).

  • mean_value (Optional[float]): mean value of the random field. Defaults to None. In that case it should be set otherwise before running the generate method.

  • seed (int): The seed number for the random number generator.

Initialise a random generator field. The mean value is optional because it can be set at another moment. In that case it should be set before running the generate method.

Anisotropy and angle can be given as scalar, 1-D and 2-D lists. In case the model is 3D but a 1-D or scalar is provided, it is assumed the same angle and anisotropy along both horizontal direction. Because the models in STEM always have coordinates in three dimensions (x, y, and z), random fields always have a dimension (n_dim) equal to 3.

Args:
  • model_name (str): Name of the model to be used. Options are: “Gaussian”, “Exponential”, “Matern”, “Linear”

  • cov (float): The coefficient of variation of the random field.

  • v_scale_fluctuation (float): The vertical scale of fluctuation of the random field.

  • anisotropy (Union[float, List[float]]): The anisotropy of the random field in the other directions (per dimension). Either a float, or a list of float containing 1 or 2 elements is accepted.

  • angle (Union[float, List[float]]): The angle of the random field (per dimension). Either a float, or a list of float containing 1 or 2 elements is accepted.

  • mean_value (Optional[float]): mean value of the random field. Defaults to None. In that case it should be set otherwise before running the generate method.

  • seed (int): The seed number for the random number generator.

Raises:
  • ValueError: if the model_name is not a valid or implemented model.

  • ValueError: if the anisotropy has more than 2 elements.

  • ValueError: if the angle has more than 2 elements.

generate(coordinates: ndarray[tuple[Any, ...], dtype[float64]])

Generate the random field parameters at the coordinates specified. The generated values are stored in generated_field attribute.

Args:
  • coordinates (numpy.typing.NDArray[np.float64]): Sequence of points where the random field needs to be

generated.

Raises:
  • ValueError: if the mean value of the random field is undefined.

property generated_fields: List[Any] | None

Returns the value of the generated field.

Raises:
  • ValueError: if field is not generated using the generate() method

Returns:
  • Optional[List[List[Any]]]: the list of generated values for the fields.