Skip to content

model

ExperimentsType module-attribute

ExperimentsType = Union[
    Experiment, List[Experiment], Dict[str, Experiment], str, List[str]
]

CalibrationModel

Bases: IOModel

Calibration manager for the micromechanical model.

calibrate

calibrate(
    x0: Dict[str | CalibrationKey, float] | None = None,
    *,
    experiments: ExperimentsType | None = None,
    includes: List[str | CalibrationKey] | None = None,
    include_additions: List[str | CalibrationKey] | None = None,
    excludes: List[str | CalibrationKey] | None = None,
    experiment_specific_parameters: List[str] | None = None,
    lognormal_parameters: List[str | CalibrationKey] = None,
    fitness: Union["FitnessBase", Type["FitnessBase"], str, None] = None,
    phase_steps: Dict[str, int] | None = None,
    experiment_options: Dict[str, Dict[str, Any]] | None = None,
    experiment_weights: Dict[str, float] = None,
    experiment_includes: List[str] | None = None,
    experiment_excludes: List[str] | None = None,
    line_additions: Dict[str, Tuple[str, str]] = None,
    line_experiment_additions: (
        Dict[str, Dict[str, Tuple[str, str]]] | None
    ) = None,
    line_weights: Dict[str, float] = None,
    line_experiment_weights: Dict[str, Dict[str, float]] | None = None,
    line_includes: List[str] | None = None,
    line_experiment_includes: Dict[str, List[str]] | None = None,
    line_excludes: List[str] | None = None,
    line_experiment_excludes: Dict[str, List[str]] | None = None,
    line_xptps: Dict[str, float] | None = None,
    line_experiment_xptps: Dict[str, Dict[str, float]] | None = None,
    line_yptps: Dict[str, float] | None = None,
    line_experiment_yptps: Dict[str, Dict[str, float]] | None = None,
    line_override_xydata: (
        Dict[str, Tuple[List[float], List[float]]] | None
    ) = None,
    line_experiment_override_xydata: (
        Dict[str, Dict[str, Tuple[List[float], List[float]]]] | None
    ) = None,
    line_ensure_increasing_xdata: List[str] | None = None,
    line_experiment_ensure_increasing_xdata: Dict[str, List[str]] | None = None,
    line_clip_state_variables: Dict[str, Tuple[float, float]] | None = None,
    line_experiment_clip_state_variables: (
        Dict[str, Dict[str, Tuple[float, float]]] | None
    ) = None,
    error_fitness: float = 10000000000.0,
    similarity_method: Literal[
        "interpolate", "pcm", "area", "frechet-dist", "curve-length", "dtw"
    ] = "interpolate",
    data_get_kwargs: Dict[str, Any] | None = None,
    check_smoothness: bool = False,
    smoothness_threshold: float = 0.05,
    method: str = "PYCMA-CMAES",
    bounds: Dict[str | CalibrationKey, Tuple[float, float]] | None = None,
    stds: Dict[str | CalibrationKey, float] | None = None,
    save_to: str | None = None,
    save_to_kwargs: Dict | None = None,
    **kwargs
) -> Tuple[Dict[str, float], OptimizerResult]

Calibrate the model parameters to the experiments.

PARAMETER DESCRIPTION
x0

Initial guess for the parameters

TYPE: Dict[str | CalibrationKey, float] DEFAULT: None

experiments

Experiments to evaluate the fitness, by default None which means all experiments in the manager

TYPE: Experiment | List[Experiment] | Dict[str, Experiment] DEFAULT: None

includes

Parameters to include in the calibration, by default None which means all parameters

TYPE: List[str | CalibrationKey] DEFAULT: None

include_additions

Additional parameters to include in the calibration, by default None

TYPE: List[str | CalibrationKey] DEFAULT: None

excludes

Parameters to exclude from the calibration, by default None

TYPE: List[str | CalibrationKey] DEFAULT: None

experiment_specific_parameters

Optimization parameters that are specific to each experiment, by default None

TYPE: List[str] DEFAULT: None

lognormal_parameters

Parameters to be distributed in the lognormal space

TYPE: List[str | CalibrationKey] DEFAULT: None

fitness

Custom fitness object or class or the full name of the class, by default None

TYPE: FitnessBase | Type[FitnessBase] | str DEFAULT: None

phase_steps

Override the number of steps for each load phase, by default None

TYPE: Dict[str, int] DEFAULT: None

experiment_options

Override the options for each experiment, by default None

TYPE: Dict[str, Dict[str, Any]] DEFAULT: None

experiment_weights

Weights for the experiments, by default None

TYPE: Dict[str, float] DEFAULT: None

experiment_includes

Experiments to include in the calibration, by default None

TYPE: List[str] DEFAULT: None

experiment_excludes

Experiments to exclude in the calibration, by default None

TYPE: List[str] DEFAULT: None

line_additions

Additional lines that can be expressions of the existing lines, by default None

TYPE: Dict[str, Tuple[str, str]] DEFAULT: None

line_experiment_additions

Additional lines for each experiment, by default None

TYPE: Dict[str, Dict[str, Tuple[str, str]]] DEFAULT: None

line_weights

Weights for the lines, by default None

TYPE: Dict[str, float] DEFAULT: None

line_experiment_weights

Weights for the lines for each experiment, by default None

TYPE: Dict[str, Dict[str, float]] DEFAULT: None

line_to

Lines to to include in the calibration, by default None

line_experiment_to

Lines to to include for each experiment, by default None

line_excludes

Lines to exclude in the calibration, by default None

TYPE: List[str] DEFAULT: None

line_experiment_excludes

Lines to exclude for each experiment, by default None

TYPE: Dict[str, List[str]] DEFAULT: None

line_xptps

Point-to-point x-axis distances for the lines, by default None

TYPE: Dict[str, float] DEFAULT: None

line_experiment_xptps

Point-to-point x-axis distances for the lines for each experiment, by default None

TYPE: Dict[str, Dict[str, float]] DEFAULT: None

line_yptps

Point-to-point y-axis distances for the lines, by default None

TYPE: Dict[str, float] DEFAULT: None

line_experiment_yptps

Point-to-point y-axis distances for the lines for each experiment, by default None

TYPE: Dict[str, Dict[str, float]] DEFAULT: None

line_override_xydata

Override the experiment data, by default None

TYPE: Dict[str, Tuple[List[float], List[float]]] DEFAULT: None

line_experiment_override_xydata

Override the experiment data for each experiment, by default None

TYPE: Dict[str, Dict[str, Tuple[List[float], List[float]]]] DEFAULT: None

line_ensure_increasing_xdata

Ensure xdata is increasing by reconstructing the data with positive differences between every two points, by default None

TYPE: List[str] DEFAULT: None

line_experiment_ensure_increasing_xdata

Ensure xdata is increasing by reconstructing the data with positive differences between every two points for each experiment, by default None

TYPE: Dict[str, List[str]] DEFAULT: None

line_clip_state_variables

Clip the state variables to the given range, by default None

TYPE: Dict[str, Tuple[float, float]] DEFAULT: None

line_experiment_clip_state_variables

Clip the state variables for each experiment to the given range, by default None

TYPE: Dict[str, Dict[str, Tuple[float, float]]] DEFAULT: None

error_fitness

Fitness value to return if the simulation fails, by default 1e10

TYPE: float DEFAULT: 10000000000.0

similarity_method

Similarity method to use for the fitness calculation, by default "interpolate"

TYPE: Literal['interpolate', 'pcm', 'area', 'frechet-dist', 'curve-length', 'dtw'] DEFAULT: 'interpolate'

data_get_kwargs

Keyword arguments for the get method of the state variable exporter, by default None

TYPE: Dict[str, Any] DEFAULT: None

check_smoothness

Whether to check if the data is smooth

TYPE: bool DEFAULT: False

smoothness_threshold

Smooth threshold

TYPE: float DEFAULT: 0.05

method

Optimization method, by default "PYCMA-CMAES"

TYPE: str DEFAULT: 'PYCMA-CMAES'

bounds

Bounds for the parameters, by default None

TYPE: Dict[str | CalibrationKey, Tuple[float, float]] DEFAULT: None

stds

Standard deviations for the parameters, by default None

TYPE: Dict[str | CalibrationKey, float] DEFAULT: None

save_to

Save the calibration results to a file, by default None

TYPE: str DEFAULT: None

save_to_kwargs

Extra keyword arguments for the save_to method, by default None

TYPE: Dict DEFAULT: None

kwargs

Fitness or optimizer keyword arguments, if the fitness has attributes with the same name, the value will be set to the attribute, and other arguments will be passed to the optimizer

DEFAULT: {}

RETURNS DESCRIPTION
Tuple[Dict[str, float], OptimizerResult]

Optimized parameters and the optimization result

fitness

fitness(
    x0: Dict[str | CalibrationKey, float] | None = None,
    *,
    experiments: ExperimentsType | None = None,
    fitness: Union["FitnessBase", Type["FitnessBase"], str, None] = None,
    phase_steps: Dict[str, int] | None = None,
    experiment_options: Dict[str, Dict[str, Any]] | None = None,
    experiment_weights: Dict[str, float] = None,
    experiment_includes: List[str] | None = None,
    experiment_excludes: List[str] | None = None,
    line_additions: Dict[str, Tuple[str, str]] = None,
    line_experiment_additions: (
        Dict[str, Dict[str, Tuple[str, str]]] | None
    ) = None,
    line_weights: Dict[str, float] = None,
    line_experiment_weights: Dict[str, Dict[str, float]] | None = None,
    line_includes: List[str] | None = None,
    line_experiment_includes: Dict[str, List[str]] | None = None,
    line_excludes: List[str] | None = None,
    line_experiment_excludes: Dict[str, List[str]] | None = None,
    line_xptps: Dict[str, float] | None = None,
    line_experiment_xptps: Dict[str, Dict[str, float]] | None = None,
    line_yptps: Dict[str, float] | None = None,
    line_experiment_yptps: Dict[str, Dict[str, float]] | None = None,
    line_override_xydata: (
        Dict[str, Tuple[List[float], List[float]]] | None
    ) = None,
    line_experiment_override_xydata: (
        Dict[str, Dict[str, Tuple[List[float], List[float]]]] | None
    ) = None,
    line_ensure_increasing_xdata: List[str] | None = None,
    line_experiment_ensure_increasing_xdata: Dict[str, List[str]] | None = None,
    line_clip_state_variables: Dict[str, Tuple[float, float]] | None = None,
    line_experiment_clip_state_variables: (
        Dict[str, Dict[str, Tuple[float, float]]] | None
    ) = None,
    error_fitness: float = 10000000000.0,
    similarity_method: Literal[
        "interpolate", "pcm", "area", "frechet-dist", "curve-length", "dtw"
    ] = "interpolate",
    data_get_kwargs: Dict[str, Any] | None = None,
    check_smoothness: bool = False,
    smoothness_threshold: float = 0.05,
    lognormal_parameters: List[str | CalibrationKey] = None,
    **kwargs
) -> float

Calculate the fitness of the model to the experiments.

PARAMETER DESCRIPTION
x0

Parameters to set before calculating the fitness, by default None

TYPE: Dict[str | CalibrationKey, float] DEFAULT: None

experiments

Experiments to evaluate the fitness, by default None which means all experiments in the manager

TYPE: Experiment | List[Experiment] | Dict[str, Experiment] DEFAULT: None

fitness

Custom fitness object or class or the full name of the class, by default None

TYPE: FitnessBase | Type[FitnessBase] | str DEFAULT: None

phase_steps

Override the number of steps for each load phase, by default None

TYPE: Dict[str, int] DEFAULT: None

experiment_options

Override the options for each experiment, by default None

TYPE: Dict[str, Dict[str, Any]] DEFAULT: None

experiment_weights

Weights for the experiments, by default None

TYPE: Dict[str, float] DEFAULT: None

experiment_includes

Experiments to include in the calibration, by default None

TYPE: List[str] DEFAULT: None

experiment_excludes

Experiments to exclude in the calibration, by default None

TYPE: List[str] DEFAULT: None

line_additions

Additional lines that can be expressions of the existing lines, by default None

TYPE: Dict[str, Tuple[str, str]] DEFAULT: None

line_experiment_additions

Additional lines for each experiment, by default None

TYPE: Dict[str, Dict[str, Tuple[str, str]]] DEFAULT: None

line_weights

Weights for the lines, by default None

TYPE: Dict[str, float] DEFAULT: None

line_experiment_weights

Weights for the lines for each experiment, by default None

TYPE: Dict[str, Dict[str, float]] DEFAULT: None

line_to

Lines to to include in the calibration, by default None

line_experiment_to

Lines to to include for each experiment, by default None

line_excludes

Lines to exclude in the calibration, by default None

TYPE: List[str] DEFAULT: None

line_experiment_excludes

Lines to exclude for each experiment, by default None

TYPE: Dict[str, List[str]] DEFAULT: None

line_xptps

Point-to-point x-axis distances for the lines, by default None

TYPE: Dict[str, float] DEFAULT: None

line_experiment_xptps

Point-to-point x-axis distances for the lines for each experiment, by default None

TYPE: Dict[str, Dict[str, float]] DEFAULT: None

line_yptps

Point-to-point y-axis distances for the lines, by default None

TYPE: Dict[str, float] DEFAULT: None

line_experiment_yptps

Point-to-point y-axis distances for the lines for each experiment, by default None

TYPE: Dict[str, Dict[str, float]] DEFAULT: None

line_override_xydata

Override the experiment data, by default None

TYPE: Dict[str, Tuple[List[float], List[float]]] DEFAULT: None

line_experiment_override_xydata

Override the experiment data for each experiment, by default None

TYPE: Dict[str, Dict[str, Tuple[List[float], List[float]]]] DEFAULT: None

line_ensure_increasing_xdata

Ensure xdata is increasing by reconstructing the data with positive differences between every two points, by default None

TYPE: List[str] DEFAULT: None

line_experiment_ensure_increasing_xdata

Ensure xdata is increasing by reconstructing the data with positive differences between every two points for each experiment, by default None

TYPE: Dict[str, List[str]] DEFAULT: None

line_clip_state_variables

Clip the state variables to the given range, by default None

TYPE: Dict[str, Tuple[float, float]] DEFAULT: None

line_experiment_clip_state_variables

Clip the state variables for each experiment to the given range, by default None

TYPE: Dict[str, Dict[str, Tuple[float, float]]] DEFAULT: None

error_fitness

Fitness value to return if the simulation fails, by default 1e10

TYPE: float DEFAULT: 10000000000.0

similarity_method

Similarity method to use for the fitness calculation, by default "interpolate"

TYPE: Literal['interpolate', 'pcm', 'area', 'frechet-dist', 'curve-length', 'dtw'] DEFAULT: 'interpolate'

data_get_kwargs

Keyword arguments for the get method of the state variable exporter, by default None

TYPE: Dict[str, Any] DEFAULT: None

check_smoothness

Whether to check if the data is smooth

TYPE: bool DEFAULT: False

smoothness_threshold

Smooth threshold

TYPE: float DEFAULT: 0.05

lognormal_parameters

Parameters to be distributed in the lognormal space

TYPE: List[str | CalibrationKey] DEFAULT: None

kwargs

Additional keyword arguments to pass to the fitness object

DEFAULT: {}

select_parameters

select_parameters(
    x0: Dict[str | CalibrationKey, float] | None = None,
    *,
    includes: List[str | CalibrationKey] | None = None,
    include_additions: List[str | CalibrationKey] | None = None,
    excludes: List[str | CalibrationKey] | None = None,
    experiments: ExperimentsType | None = None,
    experiment_specific_parameters: List[str] | None = None,
    bounds: Dict[str | CalibrationKey, Tuple[float, float]] | None = None,
    stds: Dict[str | CalibrationKey, float] | None = None,
    lognormal_parameters: List[str | CalibrationKey] = None
) -> Tuple[List[str | CalibrationKey], Dict, Dict, Dict]

Select the parameters for the calibration.

PARAMETER DESCRIPTION
x0

Initial guess for the parameters

TYPE: Dict[str | CalibrationKey, float] DEFAULT: None

experiments

Experiments to evaluate the fitness, by default None which means all experiments in the manager

TYPE: Experiment | List[Experiment] | Dict[str, Experiment] DEFAULT: None

includes

Parameters to include in the calibration, by default None which means all parameters

TYPE: List[str | CalibrationKey] DEFAULT: None

include_additions

Additional parameters to include in the calibration, by default None

TYPE: List[str | CalibrationKey] DEFAULT: None

excludes

Parameters to exclude from the calibration, by default None

TYPE: List[str | CalibrationKey] DEFAULT: None

experiment_specific_parameters

Optimization parameters that are specific to each experiment, by default None

TYPE: List[str] DEFAULT: None

bounds

Bounds for the parameters, by default None

TYPE: Dict[str | CalibrationKey, Tuple[float, float]] DEFAULT: None

stds

Standard deviations for the parameters, by default None

TYPE: Dict[str | CalibrationKey, float] DEFAULT: None

lognormal_parameters

Parameters to be distributed in the lognormal space

TYPE: List[str | CalibrationKey] DEFAULT: None

RETURNS DESCRIPTION
Tuple[List[str | CalibrationKey], Dict, Dict, Dict]

The keys, initial values, bounds, and standard deviations of the parameters

ContactModel

Bases: ModelBase

Contact manager for the micromechanical model.

plotContactYieldSurface

plotContactYieldSurface(
    xscale: float = 1.0,
    yscale: float = 1.0,
    *,
    type: Literal["contour", "surface", "trisurf", "wireframe"] = "contour",
    experiments: ExperimentsType | None = None,
    simulate_experiment_kwargs: dict | None = None,
    xmin: float | None = None,
    xmax: float | None = None,
    xnum: int = 500,
    ymin: float | None = None,
    ymax: float | None = None,
    ynum: int = 500,
    relative: bool = False,
    no_contours_error: Literal["ignore", "warn", "raise"] = "warn",
    plot_force_state: bool = False,
    force_state_scatter_kwargs: dict | None = None,
    force_state_line_kwargs: dict | None = None,
    phase: int | slice | Iterable[int] = slice(None),
    step: int | slice | Iterable[int] = slice(None),
    idx: int | slice | Iterable[int] = slice(None),
    label: str = "Step: {step}, idx: {idx}",
    data: SVExporter | YieldFunction | None = None,
    data_get_kwargs: Dict[str, Any] | None = None,
    on: Plottable | None = None,
    same_axes: bool = False,
    ncols: int = 2,
    backend: Literal["matplotlib", "bokeh"] | str | None = None,
    subplots_kwargs: dict | None = None,
    line_kwargs: Iterable[Dict[str, Any]] | None = None,
    props: Dict[str, Any] | None = None,
    bokeh_show: bool = False,
    tight_layout: bool = True,
    **kwargs
) -> Union["MplFigure", "BkGridPlot"]

Plot yield surface for the contact law.

Notes

The following placeholders are supported for arguments label, kwargs, and line_kwargs:

  • material parameters (model.parameters)
  • {step} for the step index
  • {idx}, {beta} and {gamma} for contact variables
PARAMETER DESCRIPTION
xscale

Scale for x-axis, by default 1.0.

TYPE: float DEFAULT: 1.0

yscale

Scale for y-axis, by default 1.0.

TYPE: float DEFAULT: 1.0

type

Type of the plot, by default "contour"

TYPE: Literal['contour', 'surface', 'trisurf', 'wireframe'] DEFAULT: 'contour'

xmin

Minimum x value, by default None which means the minimum value in the data

TYPE: float DEFAULT: None

xmax

Maximum x value, by default None which means the maximum value in the data

TYPE: float DEFAULT: None

xnum

Number of x values, by default 500

TYPE: int DEFAULT: 500

ymin

Minimum y value, by default None which means the minimum value in the data

TYPE: float DEFAULT: None

ymax

Maximum y value, by default None which means the maximum value in the data

TYPE: float DEFAULT: None

ynum

Number of y values, by default 500

TYPE: int DEFAULT: 500

relative

Whether the minimum and maximum values are relative to the data, by default False

TYPE: bool DEFAULT: False

no_contours_error

Whether to raise an error if no contours are found, by default "warn"

TYPE: Literal['ignore', 'warn', 'raise'] DEFAULT: 'warn'

plot_force_state

Whether to plot the current force state with scatter, by default False

TYPE: bool DEFAULT: False

force_state_scatter_kwargs

Keyword arguments for plotting the force state scatter, by default color and edgecolors are set to the color of the corresponding yield surface

TYPE: dict DEFAULT: None

force_state_line_kwargs

Keyword arguments for plotting the force state line, by default None

TYPE: dict DEFAULT: None

phase

An integer or a slice indicates index of the phase.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

step

An integer or a slice indicates index of the step.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

idx

An integer or a slice indicates index of the integration point for contact variables.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

label

Format string for the label in the legend, by default "Step: {step}, idx: {idx}"

TYPE: str DEFAULT: 'Step: {step}, idx: {idx}'

data

State variables to plot, if not specified, the simulation will be run, by default None

TYPE: SVExporter | YieldFunction DEFAULT: None

data_get_kwargs

Extra keyword arguments for the get method of the data object, by default None

TYPE: Dict[str, Any] DEFAULT: None

on

Axes to plot on, by default None

TYPE: PlotAxes DEFAULT: None

same_axes

Whether to use the same axes for all lines, by default False

TYPE: bool DEFAULT: False

ncols

Number of columns in the figure grid, by default 2

TYPE: int DEFAULT: 2

backend

Backend to use, by default None which means the backend set in the environment variable MICROMECHANICAL_PLOTTING_BACKEND.

TYPE: Literal['matplotlib', 'bokeh'] | str DEFAULT: None

subplots_kwargs

Keyword arguments for creating the subplots, by default None

TYPE: dict DEFAULT: None

line_kwargs

Line-specific keyword arguments, by default None

TYPE: Iterable[Dict[str, Any]] DEFAULT: None

props

Properties passed to the setAxesProps method to set the axes properties, by default None

TYPE: Dict[str, Any] DEFAULT: None

bokeh_show

Whether to show the figure in the browser, by default False

TYPE: bool DEFAULT: False

tight_layout

Whether to use tight layout in the matplotlib figure, by default True

TYPE: bool DEFAULT: True

kwargs

Keyword arguments for plt.plot or bplt.line

DEFAULT: {}

RETURNS DESCRIPTION
Figure | GridPlot

The matplotlib figure or bokeh gridplot

setPlasticMethod

setPlasticMethod(method: str)

Set the plastic method for all contacts.

IOModel

Bases: IntegrationModel, LoadModel, MaterialModel, ContactModel

Simulation manager for the micromechanical model.

io property

io: ModelIO

Get the IO object for the manager.

__hash__

__hash__() -> int

Hash the model.

fromDict classmethod

fromDict(d: dict, **kwargs) -> Self

Load the model from a dictionary.

fromJson classmethod

fromJson(
    *, string: str | None = None, path: str | None = None, **kwargs
) -> Self

Load the model from a JSON file or a JSON string.

fromToml classmethod

fromToml(
    *, string: str | None = None, path: str | None = None, **kwargs
) -> Self

Load the model from a TOML file or a TOML string.

fromYaml classmethod

fromYaml(
    *, string: str | None = None, path: str | None = None, **kwargs
) -> Self

Load the model from a YAML file or a YAML string.

toDict

toDict(**kwargs) -> dict

Save the model to a dictionary.

toJson

toJson(path: str | None = None, **kwargs) -> str | None

Save the model to a JSON file.

toToml

toToml(path: str | None = None, **kwargs) -> str | None

Save the model to a TOML file.

toYaml

toYaml(path: str | None = None, **kwargs) -> str | None

Save the model to a YAML file.

IntegrationModel

Bases: ModelBase

Integration manager for the micromechanical model.

argbeta

argbeta(
    *, unit: Literal["rad", "deg"] = "deg", lb: float = 0.0, ub: float = 180.0
) -> ndarray

The indices of the azimuthal angles of the integration points in the y-z plane.

PARAMETER DESCRIPTION
unit

The unit of the angles, by default "deg"

TYPE: str DEFAULT: 'deg'

lb

The lower bound of the angles, by default 0.0

TYPE: float DEFAULT: 0.0

ub

The upper bound of the angles, by default 180.0

TYPE: float DEFAULT: 180.0

arggamma

arggamma(
    *, unit: Literal["rad", "deg"] = "deg", lb: float = 0.0, ub: float = 180.0
) -> ndarray

The indices of the azimuthal angles of the integration points x-axis.

PARAMETER DESCRIPTION
unit

The unit of the angles, by default "deg"

TYPE: str DEFAULT: 'deg'

lb

The lower bound of the angles, by default 0.0

TYPE: float DEFAULT: 0.0

ub

The upper bound of the angles, by default 180.0

TYPE: float DEFAULT: 180.0

beta

beta(
    *,
    unit: Literal["rad", "deg"] = "deg",
    lb: float = 0.0,
    ub: float = 180.0,
    func: Callable = None
) -> ndarray

The azimuthal angles of the integration points in the y-z plane, an array of shape (n,).

PARAMETER DESCRIPTION
unit

The unit of the angles, by default "deg"

TYPE: str DEFAULT: 'deg'

lb

The lower bound of the angles, by default 0.0

TYPE: float DEFAULT: 0.0

ub

The upper bound of the angles, by default 180.0

TYPE: float DEFAULT: 180.0

func

The function to apply to the angles, by default None

TYPE: Callable DEFAULT: None

gamma

gamma(
    *,
    unit: Literal["rad", "deg"] = "deg",
    lb: float = 0.0,
    ub: float = 180.0,
    func: Callable = None
) -> ndarray

The azimuthal angles of the integration points x-axis, an array of shape (n,).

PARAMETER DESCRIPTION
unit

The unit of the angles, by default "deg"

TYPE: str DEFAULT: 'deg'

lb

The lower bound of the angles, by default 0.0

TYPE: float DEFAULT: 0.0

ub

The upper bound of the angles, by default 180.0

TYPE: float DEFAULT: 180.0

func

The function to apply to the angles, by default None

TYPE: Callable DEFAULT: None

indexOf

indexOf(
    *,
    beta: float | ndarray | Iterable[float] = None,
    gamma: float | ndarray | Iterable[float] = None,
    beta_apply: Callable = None,
    gamma_apply: Callable = None,
    union: bool = False,
    tol: float = 0.5,
    unit: Literal["rad", "deg"] = "deg",
    sort: (
        Literal["beta", "gamma", "idx"] | List[Literal["beta", "gamma"]]
    ) = None,
    drop_duplicates: bool = False
) -> ndarray

The contact indices for the given beta and gamma.

PARAMETER DESCRIPTION
beta

The angle between the projection of the azimuth on the YZ plane and the Y axis

TYPE: float | ndarray | Iterable[float] DEFAULT: None

gamma

The angle between the azimuth and the X axis

TYPE: float | ndarray | Iterable[float] DEFAULT: None

beta_apply

The function to apply to the beta angles, by default None

TYPE: Callable DEFAULT: None

gamma_apply

The function to apply to the gamma angles, by default None

TYPE: Callable DEFAULT: None

union

If true, return the union of beta and gamma indices, else return the intersection, by default False

TYPE: bool DEFAULT: False

tol

The tolerance for the comparison of the angles, by default 0.5

TYPE: float DEFAULT: 0.5

unit

The unit of the angles, by default "deg"

TYPE: str DEFAULT: 'deg'

sort

Sort the indices by beta, gamma or idx, by default None

TYPE: str | List[str] DEFAULT: None

drop_duplicates

Drop the duplicated beta and (or) gamma, by default False

TYPE: bool DEFAULT: False

integrationplot

integrationplot(
    *, ax: Union["MplAxes3D", None] = None, **kwargs
) -> "MplAxes3D"

Plot the integration points.

setAnisotropicParameters

setAnisotropicParameters(
    type: AvailableFabricTypes = "chang1990-ext",
    evolution: AvailableFabricEvolutionTypes = "zhao2020",
    coefs: Dict[str, float] = None,
    **kwargs
)

Set the anisotropic parameters.

PARAMETER DESCRIPTION
type

The type of the anisotropic parameter.

TYPE: str DEFAULT: 'chang1990-ext'

evolution

The evolution type of the anisotropic parameter.

TYPE: str DEFAULT: 'zhao2020'

coefs

The coefficients of the anisotropic parameter.

TYPE: Dict[str, float] DEFAULT: None

kwargs

More coefficients of the anisotropic parameter.

DEFAULT: {}

setGauss37

setGauss37(full: bool = False)

Set the Gauss37 integration points.

PARAMETER DESCRIPTION
full

Full 37*2 integration points.

TYPE: bool DEFAULT: False

setGauss61

setGauss61(full: bool = False)

Set the Gauss61 integration points.

PARAMETER DESCRIPTION
full

Full 61*2 integration points.

TYPE: bool DEFAULT: False

setIntegrationParameters

setIntegrationParameters(npv: float, radius: float)

Set the parameters.

PARAMETER DESCRIPTION
npv

number of contacts per unit volume

TYPE: float

radius

particle radius

TYPE: float

setNPVFromNormalizedPackingDensity

setNPVFromNormalizedPackingDensity(rho: float)

Set the number of contacts per unit volume from the normalized packing density with the following equation:

\[ \rho=\frac{Nl^3}{V}=\frac{8Nr^3}{V} \Longrightarrow \frac{N}{V}=\frac{\rho}{8r^3} \]
PARAMETER DESCRIPTION
rho

normalized packing density

TYPE: float

setNPVFromVoidRatio

setNPVFromVoidRatio(e: float)

Set the number of contacts per unit volume from the void ratio with the following equation:

\[ \frac{N}{V}=\frac{3(13.28-8e)}{4\pi r^3(1+e)} \]
PARAMETER DESCRIPTION
e

void ratio

TYPE: float

LoadModel

Bases: ModelBase

Load manager for the micromechanical model.

addConfinementPhase

addConfinementPhase(epsa_max: float, steps: int)

Add a confinement load phase.

PARAMETER DESCRIPTION
steps

Number of steps.

TYPE: int

epsa_max

Maximum strain.

TYPE: float

addDrainedTriaxialPhase

addDrainedTriaxialPhase(sigc: float, epsa_max: float, steps: int)

Add a drained triaxial load phase.

PARAMETER DESCRIPTION
steps

Number of steps.

TYPE: int

sigc

Confined stress.

TYPE: float

epsa_max

Maximum strain.

TYPE: float

addIsotropicPhase

addIsotropicPhase(sigc: float, steps: int)

Add an isotropic load phase.

PARAMETER DESCRIPTION
steps

Number of steps.

TYPE: int

sigc

Confined stress.

TYPE: float

addLoadPhase

addLoadPhase(phase: LoadPhase)

Add a load phase.

PARAMETER DESCRIPTION
phase

The load phase.

TYPE: LoadPhase

addTrueTriaxialPhase

addTrueTriaxialPhase(sig3: float, b: float, epsa_max: float, steps: int)

Add a true triaxial load phase.

PARAMETER DESCRIPTION
sig3

Minimum principal stress.

TYPE: float

b

Intermediate stress ratio.

TYPE: float

epsa_max

Maximum strain.

TYPE: float

steps

Number of steps.

TYPE: int

addTrueTriaxialWithConstantShearPhase

addTrueTriaxialWithConstantShearPhase(p: float, b: float, steps: int)

Add a true triaxial load phase.

PARAMETER DESCRIPTION
p

Mean stress.

TYPE: float

b

Intermediate principal stress.

TYPE: float

steps

Number of steps.

TYPE: int

RETURNS DESCRIPTION
LoadPhase

The load phase.

addUndrainedTriaxialPhase

addUndrainedTriaxialPhase(epsa_max: float, steps: int)

Add an undrained triaxial load phase.

PARAMETER DESCRIPTION
steps

Number of steps.

TYPE: int

epsa_max

Maximum strain.

TYPE: float

addUndrainedTriaxialWithoutShearPhase

addUndrainedTriaxialWithoutShearPhase(epsa_max: float, steps: int)

Add an undrained triaxial load phase without controlling the shear strain.

PARAMETER DESCRIPTION
steps

Number of steps.

TYPE: int

epsa_max

Maximum strain.

TYPE: float

MaterialModel

Bases: ModelBase

Material manager for the micromechanical model.

setMaterialAnisotropicParameters

setMaterialAnisotropicParameters(
    key: str,
    type: AvailableFabricTypes = "chang1990-ext",
    evolution: AvailableFabricEvolutionTypes = "zhao2020",
    coefs: Dict[str, float] = None,
    **kwargs
)

Set the anisotropic parameters for a material property.

PARAMETER DESCRIPTION
key

The name of the material property.

TYPE: str

type

The type of the anisotropic parameter.

TYPE: str DEFAULT: 'chang1990-ext'

evolution

The evolution type of the anisotropic parameter.

TYPE: str DEFAULT: 'zhao2020'

coefs

The coefficients of the anisotropic parameter.

TYPE: Dict[str, float] DEFAULT: None

kwargs

More coefficients of the anisotropic parameter.

DEFAULT: {}

Model

Bases: VisualizationModel

A micromechanical model manager.

Notes

The main calculation of the micromechanical model is done in the model attribute, which is an instance of the pure Python/numba/C++ micromechanical model, depending on the backend. Setting the following environment variables to change the backend:

  • MICROMECHANICAL_BACKEND=cpp: use the C++ backend
  • MICROMECHANICAL_BACKEND=python;NUMBA_DISABLE_JIT=1: use the pure Python backend
  • MICROMECHANICAL_BACKEND=python;NUMBA_DISABLE_JIT=0: use the numba backend

For the cpp and numba backends, the environment variable MICROMECHANICAL_PRECISION can be set to single or double to change the precision, the default is double

Examples:

Create the micromechanical model object:

>>> from micromechanical import Model
>>> model = Model("CH-OSIMSAND")

Set up the loading phases:

>>> model.addIsotropicPhase(sigc=-100, steps=100)
>>> model.addDrainedTriaxialPhase(sigc=-100, epsa_max=-0.3, steps=100)

Set up the plastic method for the local contact law:

>>> model.setPlasticMethod("CPA")  # default is "CPA"

Set up integration points:

>>> model.setIntegrationParameters(npv=1e9, radius=0.65e-3)
>>> model.setAnisotropicParameters(type="chang1990-ext", evolution="wan2004", chi=0)

Set up material parameters:

>>> model.setParameters(phi=30)

Evaluate the model:

>>> sv = model.run()
Running CH-OSIMSAND model ...
Finished in ... seconds.

sv is a micromechanical.SVExporter object, which can be used to get the state variables, plot the results, and export the results to a file.

>>> sv.to_csv("data.csv")
Saving state variables to DataFrame
>>> p, q, epsa, epsv = sv.get("-p"), sv.q, 100 * sv["epsa"], sv["100 * epsv"]  # the tensile stress is positive
>>> model.plot("-p", "q", data=sv)  # if data is omitted, model.run() will be called
<Figure size ... with 1 Axes>

__init__

__init__(
    *model_types: Union[
        MicromechanicalBase,
        type,
        str | PathLike,
        AvailableModels,
        AvailableMicromechanicalModels,
        AvailableContactModels,
    ],
    args: tuple = (),
    kwargs: dict = None,
    no_stop: bool = False,
    backend: Literal["python", "cpp"] = backend,
    **options
)

Constructor for the micromechanical model manager base class.

PARAMETER DESCRIPTION
model_types

The micromechanical model to use. If no positional arguments are provided, the model will not be initialized. If one positional argument is provided, it should be:

  • a micromechanical model object
  • a micromechanical model class
  • a string of the form model_type-contact_type

If two positional arguments are provided, they should be:

  • (model_type | model_plugin_path, contact_type | contact_plugin_path)

In C++ backend, the micromechanical model type and contact law type can be a string of the file path to the compiled shared library.

For example, the following usages are valid:

  • model = Model(ChangHicherElasticModel): use the ChangHicherElasticModel class (Python)
  • model = Model(ChangHicherElasticModel()): use the ChangHicherElasticModel object (Python)
  • model = Model("CH-Elastic"): use the CH model with the Elastic contact law
  • model = Model("CH", "Elastic"): use the CH model with the Elastic contact law
  • model = Model("CH", "elastic.dll"): use the CH model with the elastic.dll shared library (C++)
  • model = Model("changhicher.dll", "Elastic"): use the changhicher.dll shared library with the Elastic contact law (C++)
  • model = Model("changhicher.dll", "elastic.dll"): use the changhicher.dll shared library with the elastic.dll shared library (C++)

TYPE: MicromechanicalBase | type | str | PossibleModels DEFAULT: ()

args

The positional arguments for the micromechanical model if the supplied model is a class.

TYPE: tuple DEFAULT: ()

kwargs

The keyword arguments for the micromechanical model if the supplied model is a class.

TYPE: dict DEFAULT: None

no_stop

Whether to stop the calculation when an error occurs.

TYPE: bool DEFAULT: False

backend

The backend to use, default is the configured backend.

TYPE: ('python', 'cpp') DEFAULT: "python"

options

The calculation options for the micromechanical model, the contact law, or the material.

DEFAULT: {}

ModelBase

Base class for micromechanical model managers.

best_fit_strain_averaging class-attribute instance-attribute

best_fit_strain_averaging: bool = property(
    fget=lambda self: best_fit_strain_averaging,
    fset=lambda self, value: setattr(
        options, "best_fit_strain_averaging", value
    ),
    doc="Whether to use the best-fit strain averaging",
)

cache class-attribute instance-attribute

cache: bool = property(
    fget=lambda self: cache,
    fset=lambda self, value: setattr(options, "cache", value),
    doc="Whether to cache contact variables",
)

cache_precision class-attribute instance-attribute

cache_precision: int = property(
    fget=lambda self: cache_precision,
    fset=lambda self, value: setattr(options, "cache_precision", value),
    doc="Cache contact variables precision",
)

caches class-attribute instance-attribute

caches: LRUCache = LRUCache(maxsize=128)

The caches.

contact property writable

The contact law.

contact_check_convergence class-attribute instance-attribute

contact_check_convergence: bool = property(
    fget=lambda self: contact_check_convergence,
    fset=lambda self, value: setattr(
        options, "contact_check_convergence", value
    ),
    doc="Check the convergence of contact",
)

contact_check_plastic_multiplier class-attribute instance-attribute

contact_check_plastic_multiplier: bool = property(
    fget=lambda self: contact_check_plastic_multiplier,
    fset=lambda self, value: setattr(
        options, "contact_check_plastic_multiplier", value
    ),
    doc="Whether to check the sign of plastic multiplier",
)

contact_ensure_force_state_on_yield_surface class-attribute instance-attribute

contact_ensure_force_state_on_yield_surface: bool = property(
    fget=lambda self: contact_ensure_force_state_on_yield_surface,
    fset=lambda self, value: setattr(
        options, "contact_ensure_force_state_on_yield_surface", value
    ),
    doc="Whether to ensure the force state is on the yield surface",
)

contact_friction_angle_combined class-attribute instance-attribute

contact_friction_angle_combined: bool = property(
    fget=lambda self: contact_friction_angle_combined,
    fset=lambda self, value: setattr(
        options, "contact_friction_angle_combined", value
    ),
    doc="Whether to combine the friction angle from different criteria",
)

contact_friction_angle_weight_mises class-attribute instance-attribute

contact_friction_angle_weight_mises: float = property(
    fget=lambda self: contact_friction_angle_weight_mises,
    fset=lambda self, value: setattr(
        options, "contact_friction_angle_weight_mises", value
    ),
    doc="Weight for Von Mises criterion in the friction angle",
)

contact_friction_angle_weight_mohr_coulomb class-attribute instance-attribute

contact_friction_angle_weight_mohr_coulomb: float = property(
    fget=lambda self: contact_friction_angle_weight_mohr_coulomb,
    fset=lambda self, value: setattr(
        options, "contact_friction_angle_weight_mohr_coulomb", value
    ),
    doc="Weight for Mohr-Coulomb criterion in the friction angle",
)

contact_friction_angle_weight_smp class-attribute instance-attribute

contact_friction_angle_weight_smp: float = property(
    fget=lambda self: contact_friction_angle_weight_smp,
    fset=lambda self, value: setattr(
        options, "contact_friction_angle_weight_smp", value
    ),
    doc="Weight for SMP criterion in the friction angle",
)

contact_friction_angle_weight_tresca class-attribute instance-attribute

contact_friction_angle_weight_tresca: float = property(
    fget=lambda self: contact_friction_angle_weight_tresca,
    fset=lambda self, value: setattr(
        options, "contact_friction_angle_weight_tresca", value
    ),
    doc="Weight for Tresca criterion in the friction angle",
)

contact_linear_critical_state_line class-attribute instance-attribute

contact_linear_critical_state_line: bool = property(
    fget=lambda self: contact_linear_critical_state_line,
    fset=lambda self, value: setattr(
        options, "contact_linear_critical_state_line", value
    ),
    doc="Whether to use linear critical state line for the OSIMSAND contact law",
)

contact_max_increment class-attribute instance-attribute

contact_max_increment: float = property(
    fget=lambda self: contact_max_increment,
    fset=lambda self, value: setattr(options, "contact_max_increment", value),
    doc="Maximum stress ratio in one increment",
)

contact_max_iterations class-attribute instance-attribute

contact_max_iterations: int = property(
    fget=lambda self: contact_max_iterations,
    fset=lambda self, value: setattr(options, "contact_max_iterations", value),
    doc="Maximum number of iterations, only for CPA or CPPM",
)

contact_min_normal_force class-attribute instance-attribute

contact_min_normal_force: float = property(
    fget=lambda self: contact_min_normal_force,
    fset=lambda self, value: setattr(
        options, "contact_min_normal_force", value
    ),
    doc="The minimum normal force",
)

contact_plastic_method_multiplier class-attribute instance-attribute

contact_plastic_method_multiplier: float = property(
    fget=lambda self: contact_plastic_method_multiplier,
    fset=lambda self, value: setattr(
        options, "contact_plastic_method_multiplier", value
    ),
    doc="Multiplier for the contact plastic method",
)

contact_sanisand_constant_hardening_parameter class-attribute instance-attribute

contact_sanisand_constant_hardening_parameter: bool = property(
    fget=lambda self: contact_sanisand_constant_hardening_parameter,
    fset=lambda self, value: setattr(
        options, "contact_sanisand_constant_hardening_parameter", value
    ),
    doc="Whether to use constant hardening parameter h for the SANISAND contact law",
)

contact_sanisand_maintain_yield_surface class-attribute instance-attribute

contact_sanisand_maintain_yield_surface: bool = property(
    fget=lambda self: contact_sanisand_maintain_yield_surface,
    fset=lambda self, value: setattr(
        options, "contact_sanisand_maintain_yield_surface", value
    ),
    doc="Whether to maintain yield surface for the SANISAND contact law",
)

contact_tolerance class-attribute instance-attribute

contact_tolerance: float = property(
    fget=lambda self: contact_tolerance,
    fset=lambda self, value: setattr(options, "contact_tolerance", value),
    doc="Contact tolerance",
)

dataset_dirs class-attribute instance-attribute

dataset_dirs: List[Path] = list(
    set([absolute() for d in dataset_dirs + [parents[1] / "datasets"]])
)

directories to search for datasets

debug class-attribute instance-attribute

debug: bool = property(
    fget=lambda self: debug,
    fset=lambda self, value: setattr(options, "debug", value),
    doc="Debug mode",
)

debugVariable property

debugVariable

The debug information.

disp_steps class-attribute instance-attribute

disp_steps: int = property(
    fget=lambda self: disp_steps,
    fset=lambda self, value: setattr(options, "disp_steps", value),
    doc="Display the information per steps",
)

experiments instance-attribute

experiments: Dict[str, Experiment] = {}

The experimental data.

fabric_coefs property writable

fabric_coefs: Dict[str, float]

The fabric coefficients.

fabric_evolution_type property writable

fabric_evolution_type: str

The fabric evolution type.

fabric_type property writable

fabric_type: str

The fabric tensor type.

ignore_distractions class-attribute instance-attribute

ignore_distractions: bool = property(
    fget=lambda self: ignore_distractions,
    fset=lambda self, value: setattr(options, "ignore_distractions", value),
    doc="Whether to ignore distractions",
)

ignore_fabric_evolution_for_isotropic_loading class-attribute instance-attribute

ignore_fabric_evolution_for_isotropic_loading: bool = property(
    fget=lambda self: ignore_fabric_evolution_for_isotropic_loading,
    fset=lambda self, value: setattr(
        options, "ignore_fabric_evolution_for_isotropic_loading", value
    ),
    doc="Whether to ignore fabric evolution for isotropic loading",
)

ignore_fabric_rotations_for_isotropic_loading class-attribute instance-attribute

ignore_fabric_rotations_for_isotropic_loading: bool = property(
    fget=lambda self: ignore_fabric_rotations_for_isotropic_loading,
    fset=lambda self, value: setattr(
        options, "ignore_fabric_rotations_for_isotropic_loading", value
    ),
    doc="Whether to ignore fabric rotations for isotropic loading",
)

increment_plastic_displacement class-attribute instance-attribute

increment_plastic_displacement: bool = property(
    fget=lambda self: increment_plastic_displacement,
    fset=lambda self, value: setattr(
        options, "increment_plastic_displacement", value
    ),
    doc="Increment plastic displacement to the total displacement",
)

integration property writable

integration: Integration

The integration points.

integration_absolute_tolerance class-attribute instance-attribute

integration_absolute_tolerance: float = property(
    fget=lambda self: integration_absolute_tolerance,
    fset=lambda self, value: setattr(
        options, "integration_absolute_tolerance", value
    ),
    doc="Absolute tolerance for macro-micro integration",
)

integration_check_absolute_convergence class-attribute instance-attribute

integration_check_absolute_convergence: bool = property(
    fget=lambda self: integration_check_absolute_convergence,
    fset=lambda self, value: setattr(
        options, "integration_check_absolute_convergence", value
    ),
    doc="Whether to check absolute contact integration error instead of the relative error",
)

integration_check_convergence class-attribute instance-attribute

integration_check_convergence: bool = property(
    fget=lambda self: integration_check_convergence,
    fset=lambda self, value: setattr(
        options, "integration_check_convergence", value
    ),
    doc="Converge the macro-micro integration algorithm when the number of iterations reaches the maximum",
)

integration_loading_ratio class-attribute instance-attribute

integration_loading_ratio: float = property(
    fget=lambda self: integration_loading_ratio,
    fset=lambda self, value: setattr(
        options, "integration_loading_ratio", value
    ),
    doc="Macro-micro integration loading ratio for the contact force and displacement",
)

integration_max_iterations class-attribute instance-attribute

integration_max_iterations: int = property(
    fget=lambda self: integration_max_iterations,
    fset=lambda self, value: setattr(
        options, "integration_max_iterations", value
    ),
    doc="Maximum number of iterations for macro-micro integration",
)

integration_max_substepping_ratio class-attribute instance-attribute

integration_max_substepping_ratio: float = property(
    fget=lambda self: integration_max_substepping_ratio,
    fset=lambda self, value: setattr(
        options, "integration_max_substepping_ratio", value
    ),
    doc="Maximum macro-micro integration substepping ratio",
)

integration_min_substepping_ratio class-attribute instance-attribute

integration_min_substepping_ratio: float = property(
    fget=lambda self: integration_min_substepping_ratio,
    fset=lambda self, value: setattr(
        options, "integration_min_substepping_ratio", value
    ),
    doc="Minimum macro-micro integration substepping ratio",
)

integration_relative_tolerance class-attribute instance-attribute

integration_relative_tolerance: float = property(
    fget=lambda self: integration_relative_tolerance,
    fset=lambda self, value: setattr(
        options, "integration_relative_tolerance", value
    ),
    doc="Relative tolerance for macro-micro integration",
)

integration_substepping_relative_to_increment class-attribute instance-attribute

integration_substepping_relative_to_increment: bool = property(
    fget=lambda self: integration_substepping_relative_to_increment,
    fset=lambda self, value: setattr(
        options, "integration_substepping_relative_to_increment", value
    ),
    doc="Whether to use the macro-micro integration substepping relative to the increment of last step",
)

integration_type property writable

integration_type

The integration points type.

kinematic_hypothesis class-attribute instance-attribute

kinematic_hypothesis: bool = property(
    fget=lambda self: kinematic_hypothesis,
    fset=lambda self, value: setattr(options, "kinematic_hypothesis", value),
    doc="Whether to use the kinematic hypothesis",
)

load property writable

load: Load

The load.

material property writable

material: Material

The material.

mixed_load_absolute_tolerance class-attribute instance-attribute

mixed_load_absolute_tolerance: float = property(
    fget=lambda self: mixed_load_absolute_tolerance,
    fset=lambda self, value: setattr(
        options, "mixed_load_absolute_tolerance", value
    ),
    doc="Absolute tolerance for mixed load control",
)

mixed_load_check_absolute_convergence class-attribute instance-attribute

mixed_load_check_absolute_convergence: bool = property(
    fget=lambda self: mixed_load_check_absolute_convergence,
    fset=lambda self, value: setattr(
        options, "mixed_load_check_absolute_convergence", value
    ),
    doc="Whether to check absolute tolerance for the mixed load",
)

mixed_load_check_convergence class-attribute instance-attribute

mixed_load_check_convergence: bool = property(
    fget=lambda self: mixed_load_check_convergence,
    fset=lambda self, value: setattr(
        options, "mixed_load_check_convergence", value
    ),
    doc="Converge the mixed load control algorithm when the number of iterations reaches the maximum",
)

mixed_load_check_strain_convergence class-attribute instance-attribute

mixed_load_check_strain_convergence: bool = property(
    fget=lambda self: mixed_load_check_strain_convergence,
    fset=lambda self, value: setattr(
        options, "mixed_load_check_strain_convergence", value
    ),
    doc="Check the convergence of mixed load strain",
)

mixed_load_max_iterations class-attribute instance-attribute

mixed_load_max_iterations: int = property(
    fget=lambda self: mixed_load_max_iterations,
    fset=lambda self, value: setattr(
        options, "mixed_load_max_iterations", value
    ),
    doc="Maximum number of iterations",
)

mixed_load_max_larger_steps class-attribute instance-attribute

mixed_load_max_larger_steps: int = property(
    fget=lambda self: mixed_load_max_larger_steps,
    fset=lambda self, value: setattr(
        options, "mixed_load_max_larger_steps", value
    ),
    doc="Allowable steps for the convergence of mixed load control and macro-micro integration",
)

mixed_load_relative_tolerance class-attribute instance-attribute

mixed_load_relative_tolerance: float = property(
    fget=lambda self: mixed_load_relative_tolerance,
    fset=lambda self, value: setattr(
        options, "mixed_load_relative_tolerance", value
    ),
    doc="Relative tolerance for mixed load control",
)

model instance-attribute

model: MicromechanicalBase | None

The micromechanical model.

no_stop instance-attribute

no_stop: bool = no_stop

No-stop mode.

npv class-attribute instance-attribute

npv: float = property(
    fget=lambda self: npv,
    fset=lambda self, value: setattr(integration, "npv", value),
    doc="Number of contacts per unit volume",
)

options property

options: Dict[str, Any]

The calculation options.

parameters property

parameters: Dict[str, float]

The model parameters.

precise_incremental_volumetric_strain class-attribute instance-attribute

precise_incremental_volumetric_strain: bool = property(
    fget=lambda self: precise_incremental_volumetric_strain,
    fset=lambda self, value: setattr(
        options, "precise_incremental_volumetric_strain", value
    ),
    doc="Whether to use the precise incremental volumetric strain to update void ratio",
)

radius class-attribute instance-attribute

radius: float = property(
    fget=lambda self: radius,
    fset=lambda self, value: setattr(integration, "radius", value),
    doc="Particle radius",
)

run_contact_integration_steps class-attribute instance-attribute

run_contact_integration_steps: int = property(
    fget=lambda self: run_contact_integration_steps,
    fset=lambda self, value: setattr(
        options, "run_contact_integration_steps", value
    ),
    doc="Number of macro-micro integration iterations to run",
)

run_mixed_load_steps class-attribute instance-attribute

run_mixed_load_steps: int = property(
    fget=lambda self: run_mixed_load_steps,
    fset=lambda self, value: setattr(options, "run_mixed_load_steps", value),
    doc="Number of mixed load iterations to run",
)

run_steps class-attribute instance-attribute

run_steps: int = property(
    fget=lambda self: run_steps,
    fset=lambda self, value: setattr(options, "run_steps", value),
    doc="Number of steps to run",
)

separate_mean_deviatoric_stress_strain class-attribute instance-attribute

separate_mean_deviatoric_stress_strain: bool = property(
    fget=lambda self: separate_mean_deviatoric_stress_strain,
    fset=lambda self, value: setattr(
        options, "separate_mean_deviatoric_stress_strain", value
    ),
    doc="Whether to apply mean stress and deviatoric stress/strain separately in the mixed load control algorithm",
)

type class-attribute instance-attribute

type: str = property(
    fget=lambda self: f"{name}-{name}",
    fset=lambda self, value: setattr(
        self, "model", MicromechanicalModel(*split("-"))
    ),
    doc="The type of the model.",
)

update_fabric_coefs class-attribute instance-attribute

update_fabric_coefs: bool = property(
    fget=lambda self: update_fabric_coefs,
    fset=lambda self, value: setattr(options, "update_fabric_coefs", value),
    doc="Whether to update fabric coefficients",
)

update_npv class-attribute instance-attribute

update_npv: bool = property(
    fget=lambda self: update_npv,
    fset=lambda self, value: setattr(options, "update_npv", value),
    doc="Whether to update npv based on the coordination number and particle radius",
)

update_void_ratio_from_after_isotropic_loading_to_before class-attribute instance-attribute

update_void_ratio_from_after_isotropic_loading_to_before: bool = property(
    fget=lambda self: update_void_ratio_from_after_isotropic_loading_to_before,
    fset=lambda self, value: setattr(
        options,
        "update_void_ratio_from_after_isotropic_loading_to_before",
        value,
    ),
    doc="Whether to update the void ratio after the isotropic loading to the void ratio before the isotropicloading, useful if the initial void ratio is given after the isotropic loading",
)

use_isotropic_fabric_tensor_in_strain_averaging class-attribute instance-attribute

use_isotropic_fabric_tensor_in_strain_averaging: bool = property(
    fget=lambda self: use_isotropic_fabric_tensor_in_strain_averaging,
    fset=lambda self, value: setattr(
        options, "use_isotropic_fabric_tensor_in_strain_averaging", value
    ),
    doc="Whether to use the isotropic fabric tensor in strain averaging",
)

use_isotropic_fabric_tensor_in_stress_localization class-attribute instance-attribute

use_isotropic_fabric_tensor_in_stress_localization: bool = property(
    fget=lambda self: use_isotropic_fabric_tensor_in_stress_localization,
    fset=lambda self, value: setattr(
        options, "use_isotropic_fabric_tensor_in_stress_localization", value
    ),
    doc="Whether to use the isotropic fabric tensor in stress localization",
)

use_plastic_strain_in_fabric_evolution class-attribute instance-attribute

use_plastic_strain_in_fabric_evolution: bool = property(
    fget=lambda self: use_plastic_strain_in_fabric_evolution,
    fset=lambda self, value: setattr(
        options, "use_plastic_strain_in_fabric_evolution", value
    ),
    doc="Whether to use plastic strain in fabric evolution",
)

verbose class-attribute instance-attribute

verbose: bool = property(
    fget=lambda self: verbose,
    fset=lambda self, value: setattr(options, "verbose", value),
    doc="Whether to print verbose information",
)

__contains__

__contains__(key: str) -> bool

Check if the option is supported.

__getitem__

__getitem__(key: str) -> Any

Get options

__init__

__init__(
    *model_types: Union[
        MicromechanicalBase,
        type,
        str | PathLike,
        AvailableModels,
        AvailableMicromechanicalModels,
        AvailableContactModels,
    ],
    args: tuple = (),
    kwargs: dict = None,
    no_stop: bool = False,
    backend: Literal["python", "cpp"] = backend,
    **options
)

Constructor for the micromechanical model manager base class.

PARAMETER DESCRIPTION
model_types

The micromechanical model to use. If no positional arguments are provided, the model will not be initialized. If one positional argument is provided, it should be:

  • a micromechanical model object
  • a micromechanical model class
  • a string of the form model_type-contact_type

If two positional arguments are provided, they should be:

  • (model_type | model_plugin_path, contact_type | contact_plugin_path)

In C++ backend, the micromechanical model type and contact law type can be a string of the file path to the compiled shared library.

For example, the following usages are valid:

  • model = Model(ChangHicherElasticModel): use the ChangHicherElasticModel class (Python)
  • model = Model(ChangHicherElasticModel()): use the ChangHicherElasticModel object (Python)
  • model = Model("CH-Elastic"): use the CH model with the Elastic contact law
  • model = Model("CH", "Elastic"): use the CH model with the Elastic contact law
  • model = Model("CH", "elastic.dll"): use the CH model with the elastic.dll shared library (C++)
  • model = Model("changhicher.dll", "Elastic"): use the changhicher.dll shared library with the Elastic contact law (C++)
  • model = Model("changhicher.dll", "elastic.dll"): use the changhicher.dll shared library with the elastic.dll shared library (C++)

TYPE: MicromechanicalBase | type | str | PossibleModels DEFAULT: ()

args

The positional arguments for the micromechanical model if the supplied model is a class.

TYPE: tuple DEFAULT: ()

kwargs

The keyword arguments for the micromechanical model if the supplied model is a class.

TYPE: dict DEFAULT: None

no_stop

Whether to stop the calculation when an error occurs.

TYPE: bool DEFAULT: False

backend

The backend to use, default is the configured backend.

TYPE: ('python', 'cpp') DEFAULT: "python"

options

The calculation options for the micromechanical model, the contact law, or the material.

DEFAULT: {}

__setitem__

__setitem__(key: str, value: Any) -> None

Set options

addDatasetDirs

addDatasetDirs(*dirs: str | PathLike)

Add directories to search for datasets.

availableDatasets

availableDatasets() -> List[str]

Get the available datasets.

clearExperiments

clearExperiments()

Clear the experiments.

defaultBounds classmethod

defaultBounds() -> Dict[str, Tuple[float, float]]

The default bounds.

defaultParameters classmethod

defaultParameters(model_type: str, contact_type: str) -> Dict[str, float]

The default parameters.

defaultStandardDeviations classmethod

defaultStandardDeviations() -> Dict[str, float]

The default standard deviations.

filterExperiments

filterExperiments(
    *args: str,
    experiments: ExperimentsType | None = None,
    method: Literal[
        "equal", "startswith", "endswith", "contains", "glob"
    ] = "glob",
    strategy: Literal["include", "exclude"] = "include",
    inplace: bool = False,
    strict: bool = True,
    **kwargs
) -> Dict[str, Experiment] | None

Filter the experiments by the name of the experiments.

PARAMETER DESCRIPTION
args

Arguments to filter the experiments by the name.

TYPE: str DEFAULT: ()

experiments

Experiments to filter, by default None which means all experiments in the manager

TYPE: Experiment | List[Experiment] | Dict[str, Experiment] | str | Iterable[str] DEFAULT: None

method

The method to filter the experiments, by default "glob"

TYPE: Literal['equal', 'startswith', 'endswith', 'contains', 'glob'] DEFAULT: 'glob'

strategy

The strategy to filter the experiments, by default "include"

TYPE: Literal['include', 'exclude'] DEFAULT: 'include'

inplace

Whether to filter the experiments in place, only used to replace the experiments in the manager, by default False

TYPE: bool DEFAULT: False

strict

If true, notes and options must match exactly with kwargs, otherwise, only items in options and notes are checked with kwargs for equality, by default True

TYPE: bool DEFAULT: True

kwargs

Additional notes or options that should be matched with the experiments

DEFAULT: {}

iterateExperiments

iterateExperiments(
    experiments: ExperimentsType | None = None,
) -> Generator[Experiment]

Iterate over the experiments.

loadCalibration

loadCalibration(filePath: str | Path)

Load parameters, options, and experiments from a calibration file.

loadExperiments

loadExperiments(
    filename: str | AvailableDatasets | PathLike,
) -> Dict[str, Experiment]

Load the experiments from a file and add them to the current experiments.

loadOptions

loadOptions(
    filePath: str | Path,
    *,
    key: str = "options",
    type: Literal["json", "toml", "yaml", "infer"] = "infer"
)

Load the calculation options from a JSON/TOML/YAML file.

loadParameters

loadParameters(
    filePath: str | Path,
    *,
    key: str = "parameters",
    type: Literal["json", "toml", "yaml", "infer"] = "infer"
)

Load the material parameters from a JSON/TOML/YAML file.

readExperiments

readExperiments(
    filename: str | AvailableDatasets | PathLike,
) -> Dict[str, Experiment]

Read the experiments from a file or from the existing datasets.

readParameters classmethod

readParameters(
    filePath: str | Path,
    *,
    key: str = "parameters",
    type: Literal["json", "toml", "yaml", "infer"] = "infer"
) -> dict[str, float]

Read the material parameters from a JSON/TOML/YAML file.

requiredParameters classmethod

requiredParameters(model_type: str, contact_type: str) -> List[str]

The required parameters.

run

run(experiment_name: str = '', **options) -> SVExporter

Run the model, return the cached state variables if the calculation is already done before with the same string representation of model exporter.

PARAMETER DESCRIPTION
experiment_name

The name of the experiment for error printing.

TYPE: str DEFAULT: ''

options

The calculation options for the micromechanical model, the contact law, or the material.

DEFAULT: {}

RETURNS DESCRIPTION
stateVar

The state variables' exporter.

TYPE: SVExporter

saveExperiments

saveExperiments(
    filename: str | PathLike,
    indent: int = 4,
    model_dump_kwargs: Dict | None = None,
    **json_dump_kwargs
)

Save the experiments to a file.

setDebug

setDebug(debug: bool = True)

Set the debug mode.

PARAMETER DESCRIPTION
debug

The debug mode.

TYPE: bool DEFAULT: True

setOptions

setOptions(opts: Dict[str, float] = None, **options)

Set the calculation options for the micromechanical model, the contact law, or the material.

PARAMETER DESCRIPTION
opts

The calculation options for the micromechanical model, the contact law, the integration, or the material.

TYPE: Dict[str, float] DEFAULT: None

options

The calculation options for the micromechanical model, the contact law, the integration, or the material.

TYPE: Dict[str, float] DEFAULT: None

setParameters

setParameters(
    params: Dict[str, float] = None, experiment_name: str = "", **kwargs: float
) -> None

Set the material parameters. Keys can be in the form of module:qualname(key1,key2) to set the specialized parameters.

PARAMETER DESCRIPTION
experiment_name

The name of the experiment for experiment-specific parameters.

TYPE: str DEFAULT: ''

params

The parameters to set.

TYPE: Dict[str, float] DEFAULT: None

kwargs

The parameters to set.

TYPE: Dict[str, float] DEFAULT: None

setupDebugVariable

setupDebugVariable(
    mixed_load_error: bool = None,
    mixed_loads: bool = None,
    sigx: bool = None,
    epsx: bool = None,
    integration_error: bool = None,
    integrations: bool = None,
    sigi: bool = None,
    sig: bool = None,
    eps: bool = None,
    dsig: bool = None,
    deps: bool = None,
    force: bool = None,
    disp: bool = None,
    yield_function: bool = None,
    dfdforce: bool = None,
    dgdforce: bool = None,
    hardening: bool = None,
    kp: bool = None,
    dlambda: bool = None,
    ddisp: bool = None,
    ddispp: bool = None,
    **kwargs
)

Setup the debug information, whether to enable debug information for specific fields.

setupModifiedModel

setupModifiedModel()

Set the model to the modified model.

setupOriginalModel

setupOriginalModel()

Set the model to the original model.

simulateExperiments

simulateExperiments(
    experiments: ExperimentsType | None = None,
    *,
    phase_steps: dict[str, int] | None = None
) -> SVExporter | Dict[str, SVExporter] | List[SVExporter]

Simulate the experiments.

PARAMETER DESCRIPTION
experiments

The experiments to simulate.

TYPE: Dict[str, Experiment] | Experiment DEFAULT: None

phase_steps

Override the number of steps for each load phase, by default None

TYPE: dict[str, int] DEFAULT: None

ParameterKey

Bases: str

A key for the model parameters in a global sense.

setup

setup(model: 'Model', value: float)

Setup the model with the value

PARAMETER DESCRIPTION
model

The model to be setup

TYPE: Model

value

The value to set

TYPE: float

VisualizationModel

Bases: CalibrationModel

Visualization manager for the micromechanical model.

fabricplot

fabricplot(
    n_theta: int = N_THETA_DEFAULT,
    n_phi: int = N_PHI_DEFAULT,
    *,
    phase: int | slice | Iterable[int] = slice(None),
    step: int | slice | Iterable[int] = slice(None),
    data: SVExporter | None = None,
    force: bool = False,
    on: Plottable | None = None,
    ncols: int = 2,
    backend: Literal["matplotlib", "bokeh"] | str | None = None,
    subplots_kwargs: dict | None = None,
    props: Dict[str, Any] | None = None,
    bokeh_show: bool = False,
    tight_layout: bool = True,
    **kwargs
) -> Union["MplFigure", "BkGridPlot"]

Plot evolution of fabric tensors.

macroplot

macroplot(
    *args: str,
    x: str | Literal["first", "auto"] = "auto",
    experiments: ExperimentsType | None = None,
    simulate_experiment_kwargs: dict | None = None,
    phase: int | slice | Iterable[int] = slice(None),
    step: int | slice | Iterable[int] = slice(None),
    idx: int | slice | Iterable[int] = slice(None),
    col: int | slice | Iterable[int] = slice(None),
    label: str = "{x} vs {y}",
    data: SVExporter | None = None,
    on: Plottable | None = None,
    ncols: int = 2,
    backend: Literal["matplotlib", "bokeh"] | str | None = None,
    subplots_kwargs: dict | None = None,
    line_kwargs: Iterable[Dict[str, Any]] | None = None,
    props: Dict[str, Any] | None = None,
    bokeh_show: bool = False,
    tight_layout: bool = True,
    **kwargs
) -> Union["MplFigure", "BkGridPlot"]

Plot macroscopic curves. Equivalent to

model.plot("100*epsa", "q", "-p", "q", "100*epsa", "100*epsva", "-p", "e", ...).

  • material parameters (model.parameters)
  • {x} and {y} for the name of the variable
See Also

microplot: Plot microscopic curves

PARAMETER DESCRIPTION
args

State variables to plot. If the number of arguments is an even number, multiple curves will be plotted with every two arguments as a pair of x and y. If the number of arguments is an odd number, the x will be the step number and the y will be all the arguments. For example, the following usages are valid:

  • .plot("fn", "fr"): plot fn against fr
  • .plot("fn", "fr", "un", "ur"): plot fn against fr and un against ur
  • .plot("fn", "fs, "ft"): plot step against fn, fs and ft

if you specify x="first":

  • .plot("step", "fn", "fs, "ft", x="first"): plot step against fn, fs and ft

or any other string:

  • .plot("fn", "fs, "ft", x="step"): plot step against fn, fs and ft

If you want to use a different strategy for the x-axis, you can specify it with x. If you want to plot multiple state variables with the same x-axis, you can specify multiple y-axis variables separated by any of comma, semicolon, or pipe (or any combination of them). For example:

  • .plot("step", "fn|fs|ft"): plot step against fn, fs and ft with the same x-axis

Multiple x-axis can also be specified. If both x and y have multiple variables, the number of x-axis must be equal to the number of y-axis.

TYPE: str DEFAULT: ()

x

Variable to plot on x-axis, by default "auto".

  • "auto": the default strategy, the x variable depends on the number of arguments described above
  • "first": use the first variable as x, the rest variables in args as y
  • any other string: use the specified variable as x, all the variables in args as y

TYPE: str DEFAULT: 'auto'

experiments

The experiments to plot, only one experiment is allowed.

TYPE: Experiment | List[Experiment] | Dict[str, Experiment] DEFAULT: None

simulate_experiment_kwargs

Keyword arguments for the simulateExperiments method for the experiment, by default None

TYPE: dict DEFAULT: None

phase

An integer or a slice indicates index of the phase.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

step

An integer or a slice indicates index of the step.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

idx

An integer or a slice indicates index of the integration point for contact variables.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

col

An integer or a slice indicates index of the column for variables with multiple columns, this argument will be ignored if the variable has only one column or the column index is already specified in var.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

label

Format string for the label in the legend, by default "{x} vs {y}"

TYPE: str DEFAULT: '{x} vs {y}'

data

State variables to plot, if not specified, the simulation will be run, by default None

TYPE: SVExporter DEFAULT: None

on

Axes to plot on, by default None

TYPE: PlotAxes DEFAULT: None

ncols

Number of columns in the figure grid, by default 2

TYPE: int DEFAULT: 2

backend

Backend to use, by default None which means the backend set in the environment variable MICROMECHANICAL_PLOTTING_BACKEND.

TYPE: Literal['matplotlib', 'bokeh'] | str DEFAULT: None

subplots_kwargs

Keyword arguments for creating the subplots, by default None

TYPE: dict DEFAULT: None

line_kwargs

Line-specific keyword arguments, by default None

TYPE: Iterable[Dict[str, Any]] DEFAULT: None

props

Properties passed to the setAxesProps method to set the axes properties, by default None

TYPE: Dict[str, Any] DEFAULT: None

bokeh_show

Whether to show the figure in the browser, by default False

TYPE: bool DEFAULT: False

tight_layout

Whether to use tight layout in the matplotlib figure, by default True

TYPE: bool DEFAULT: True

kwargs

Keyword arguments for plt.plot or bplt.line

DEFAULT: {}

RETURNS DESCRIPTION
Figure | GridPlot

The matplotlib figure or bokeh grid plot of the macroscopic curves

microplot

microplot(
    *args: str,
    experiments: ExperimentsType | None = None,
    simulate_experiment_kwargs: dict | None = None,
    beta: float = None,
    gamma: float = None,
    unit: Literal["rad", "deg"] = "rad",
    smooth: bool = False,
    data: SVExporter = None,
    phase: int | slice | Iterable[int] = slice(None),
    step: int | slice | Iterable[int] = slice(None),
    idx: int | slice | Iterable[int] = slice(None),
    col: int | slice | Iterable[int] = slice(None),
    label: str = "Step {step}",
    return_handles: bool = False,
    on: Plottable | None = None,
    ncols: int = 2,
    subplots_kwargs: dict | None = None,
    props: Dict[str, Any] | None = None,
    tight_layout: bool = True,
    **kwargs
) -> Figure | Tuple[Figure, List[Line2D]]

Plot microscopic curves. Specify one (and only one) of beta or gamma to plot data of a specific azimuth, the other angle will be used for the x-axis.

Notes

The following placeholders are supported for arguments label and kwargs:

  • material parameters (model.parameters)
  • {name} for the name of the variable
  • {step} for the step index
  • {idx}, {beta} and {gamma} for contact variables
See Also

microplot: Plot microscopic curves

PARAMETER DESCRIPTION
args

Names of the variables to plot

TYPE: str DEFAULT: ()

experiments

The experiments to plot, only one experiment is allowed.

TYPE: Experiment | List[Experiment] | Dict[str, Experiment] DEFAULT: None

simulate_experiment_kwargs

Keyword arguments for the simulateExperiments method for the experiment, by default None

TYPE: dict DEFAULT: None

beta

The angle between the projection of the azimuth on the YZ plane and the Y axis

TYPE: float DEFAULT: None

gamma

The angle between the azimuth and the X axis

TYPE: float DEFAULT: None

unit

Unit of the angles, by default

TYPE: Literal['rad', 'deg'] DEFAULT: 'rad'

smooth

Whether to smooth the data, by default True

TYPE: bool DEFAULT: False

data

State variables to plot, if not specified, the simulation will be run, by default None

TYPE: SVExporter DEFAULT: None

phase

An integer or a slice indicates index of the phase.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

step

Steps to plot

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

idx

Index of the integration point to plot, by default slice(None)

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

col

An integer or a slice indicates index of the column for variables with multiple columns, this argument will be ignored if the variable has only one column or the column index is already specified in var.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

label

Label for the legend, by default "Step {step}"

TYPE: str DEFAULT: 'Step {step}'

return_handles

Whether to return the handles of the plotted lines, by default False

TYPE: bool DEFAULT: False

on

Axes to plot on, by default None

TYPE: PlotAxes DEFAULT: None

ncols

Number of columns in the figure grid, by default 2

TYPE: int DEFAULT: 2

subplots_kwargs

Keyword arguments for creating the subplots, by default None

TYPE: dict DEFAULT: None

props

Properties passed to the setAxesProps method to set the axes properties, by default None

TYPE: Dict[str, Any] DEFAULT: None

tight_layout

Whether to use tight layout in the matplotlib figure, by default True

TYPE: bool DEFAULT: True

kwargs

Keyword arguments for Axes.plot

DEFAULT: {}

RETURNS DESCRIPTION
Figure

Figure with microscopic curves

List[Line2D]

Handles of the plotted lines, only returned if return_handles is True

microplots

microplots(
    *,
    experiments: ExperimentsType | None = None,
    simulate_experiment_kwargs: dict | None = None,
    beta: float = None,
    gamma: float = None,
    unit: Literal["rad", "deg"] = "rad",
    smooth: bool = False,
    data: SVExporter = None,
    phase: int | slice | Iterable[int] = slice(None),
    step: int | slice | Iterable[int] = slice(None),
    idx: int | slice | Iterable[int] = slice(None),
    col: int | slice | Iterable[int] = slice(None),
    label: str = "Step {step}",
    on: Plottable | None = None,
    ncols: int = 2,
    subplots_kwargs: dict | None = None,
    props: Dict[str, Any] | None = None,
    tight_layout: bool = True,
    **kwargs
) -> Figure

Plot microscopic curves for normal force, shear force, normal displacement, and shear displacement.

plot

plot(
    *args: str,
    x: str | Literal["first", "auto"] = "auto",
    experiments: ExperimentsType | None = None,
    simulate_experiment_kwargs: dict | None = None,
    phase: int | slice | Iterable[int] = slice(None),
    step: int | slice | Iterable[int] = slice(None),
    idx: int | slice | Iterable[int] = slice(None),
    col: int | slice | Iterable[int] = slice(None),
    label: str = "{x} vs {y}",
    data: SVExporter | YieldFunction | None = None,
    data_get_kwargs: Dict[str, Any] | None = None,
    normalize: bool | Literal["max", "mean", "x"] | float = False,
    normalize_x: float | None = None,
    on: Plottable | None = None,
    ncols: int = 2,
    backend: Literal["matplotlib", "bokeh"] | str | None = None,
    subplots_kwargs: dict | None = None,
    line_kwargs: Iterable[Dict[str, Any]] | None = None,
    props: Dict[str, Any] | None = None,
    bokeh_show: bool = False,
    tight_layout: bool = True,
    **kwargs
) -> Union["MplFigure", "BkGridPlot"]

Plot one (or multiple) line(s) of the simulation.

Notes

The following placeholders are supported for arguments label, kwargs and line_kwargs:

  • material parameters (model.parameters)
  • {x} and {y} for the name of the variable
  • {idx}, {beta} and {gamma} for contact variables
PARAMETER DESCRIPTION
args

State variables to plot. If the number of arguments is an even number, multiple curves will be plotted with every two arguments as a pair of x and y. If the number of arguments is an odd number, the x will be the step number and the y will be all the arguments. For example, the following usages are valid:

  • .plot("fn", "fr"): plot fn against fr
  • .plot("fn", "fr", "un", "ur"): plot fn against fr and un against ur
  • .plot("fn", "fs, "ft"): plot step against fn, fs and ft

if you specify x="first":

  • .plot("step", "fn", "fs, "ft", x="first"): plot step against fn, fs and ft

or any other string:

  • .plot("fn", "fs, "ft", x="step"): plot step against fn, fs and ft

If you want to use a different strategy for the x-axis, you can specify it with x. If you want to plot multiple state variables with the same x-axis, you can specify multiple y-axis variables separated by any of comma, semicolon, or pipe (or any combination of them). For example:

  • .plot("step", "fn|fs|ft"): plot step against fn, fs and ft with the same x-axis

Multiple x-axis can also be specified. If both x and y have multiple variables, the number of x-axis must be equal to the number of y-axis.

TYPE: str DEFAULT: ()

x

Variable to plot on x-axis, by default "auto".

  • "auto": the default strategy, the x variable depends on the number of arguments described above
  • "first": use the first variable as x, the rest variables in args as y
  • any other string: use the specified variable as x, all the variables in args as y

TYPE: str DEFAULT: 'auto'

experiments

The experiments to plot, only one experiment is allowed.

TYPE: Experiment | List[Experiment] | Dict[str, Experiment] DEFAULT: None

simulate_experiment_kwargs

Keyword arguments for the simulateExperiments method for the experiment, by default None

TYPE: dict DEFAULT: None

phase

An integer or a slice indicates index of the phase.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

step

An integer or a slice indicates index of the step.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

idx

An integer or a slice indicates index of the integration point for contact variables.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

col

An integer or a slice indicates index of the column for variables with multiple columns, this argument will be ignored if the variable has only one column or the column index is already specified in var.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

label

Format string for the label in the legend, supported placeholders, by default "{x} vs {y}"

TYPE: str DEFAULT: '{x} vs {y}'

data

State variables to plot, if not specified, the simulation will be run, by default None

TYPE: SVExporter | YieldFunction DEFAULT: None

data_get_kwargs

Extra keyword arguments for the get method of the data object, by default None

TYPE: Dict[str, Any] DEFAULT: None

normalize

Whether to normalize the data variables. If True or "max", normalize by the maximum value. If "mean", normalize by the mean value, if "x", normalize by the value corresponding to this angle specified by normalize_x, if a float, normalize by the value corresponding to this angle.

TYPE: (bool, str, float) DEFAULT: False

normalize_x

The x value to normalize the yield function.

TYPE: float DEFAULT: None

on

Axes to plot on, by default None

TYPE: PlotAxes DEFAULT: None

ncols

Number of columns in the figure grid, by default 2

TYPE: int DEFAULT: 2

backend

Backend to use, by default None which means the backend set in the environment variable MICROMECHANICAL_PLOTTING_BACKEND.

TYPE: Literal['matplotlib', 'bokeh'] | str DEFAULT: None

subplots_kwargs

Keyword arguments for creating the subplots, by default None

TYPE: dict DEFAULT: None

line_kwargs

Line-specific keyword arguments, by default None

TYPE: Iterable[Dict[str, Any]] DEFAULT: None

props

Properties passed to the setAxesProps method to set the axes properties, by default None

TYPE: Dict[str, Any] DEFAULT: None

bokeh_show

Whether to show the figure in the browser, by default False

TYPE: bool DEFAULT: False

tight_layout

Whether to use tight layout in the matplotlib figure, by default True

TYPE: bool DEFAULT: True

kwargs

Keyword arguments for plt.plot or bplt.line

DEFAULT: {}

RETURNS DESCRIPTION
Figure | GridPlot

The matplotlib figure or bokeh gridplot

plotComparisons

plotComparisons(
    *args: str,
    experiment_kwargs: Dict[str, Any] | None = None,
    simulation_kwargs: Dict[str, Any] | None = None,
    x: str | Literal["first", "auto"] = "auto",
    experiments: ExperimentsType | None = None,
    phase_steps: dict[str, int] | None = None,
    phase: int | slice | Iterable[int] = slice(None),
    step: int | slice | Iterable[int] = slice(None),
    idx: int | slice | Iterable[int] = slice(None),
    col: int | slice | Iterable[int] = slice(None),
    normalize: bool | Literal["max", "mean", "x"] | float = False,
    normalize_x: float | None = None,
    label: str = "{experiment}",
    data: (
        List[SVExporter]
        | SVExporter
        | List[YieldFunction]
        | YieldFunction
        | None
    ) = None,
    data_set_experiment_options: bool = False,
    data_get_kwargs: Dict[str, Any] | None = None,
    experiment_get_kwargs: Dict[str, Any] | None = None,
    experiment_data_multipliers: Dict[str, float] | None = None,
    on: Plottable | None = None,
    ncols: int = 2,
    backend: Literal["matplotlib", "bokeh"] | str | None = None,
    subplots_kwargs: dict | None = None,
    method: Literal["plot", "scatter"] | None = None,
    line_kwargs: Iterable[Dict[str, Any]] | None = None,
    line_kwargs_each: Literal["experiment", "line"] = "experiment",
    props: Dict[str, Any] | None = None,
    bokeh_show: bool = False,
    tight_layout: bool = True,
    **kwargs
) -> Union["MplFigure", "BkGridPlot"]

Plot the comparisons between experiments and simulations.

plotExperiments

plotExperiments(
    *args: str,
    x: str | Literal["first", "auto"] = "auto",
    experiments: ExperimentsType | None = None,
    normalize: bool | Literal["max", "mean", "x"] | float = False,
    normalize_x: float | None = None,
    label: str = "{experiment}",
    experiment_get_kwargs: Dict[str, Any] | None = None,
    experiment_data_multipliers: Dict[str, float] | None = None,
    on: Plottable | None = None,
    ncols: int = 2,
    backend: Literal["matplotlib", "bokeh"] | str | None = None,
    subplots_kwargs: dict | None = None,
    method: Literal["plot", "scatter"] | None = None,
    line_kwargs: Iterable[Dict[str, Any]] | None = None,
    line_kwargs_each: Literal["experiment", "line"] = "experiment",
    props: Dict[str, Any] | None = None,
    bokeh_show: bool = False,
    tight_layout: bool = True,
    **kwargs
) -> Union["MplFigure", "BkGridPlot"]

Plot the experiments.

plotSimulations

plotSimulations(
    *args: str,
    x: str | Literal["first", "auto"] = "auto",
    experiments: ExperimentsType | None = None,
    phase_steps: dict[str, int] | None = None,
    phase: int | slice | Iterable[int] = slice(None),
    step: int | slice | Iterable[int] = slice(None),
    idx: int | slice | Iterable[int] = slice(None),
    col: int | slice | Iterable[int] = slice(None),
    normalize: bool | Literal["max", "mean", "x"] | float = False,
    normalize_x: float | None = None,
    label: str = "{experiment}",
    data: (
        List[SVExporter]
        | SVExporter
        | List[YieldFunction]
        | YieldFunction
        | None
    ) = None,
    data_set_experiment_options: bool = False,
    data_get_kwargs: Dict[str, Any] | None = None,
    experiment_get_kwargs: Dict[str, Any] | None = None,
    experiment_data_multipliers: Dict[str, float] | None = None,
    on: Plottable | None = None,
    ncols: int = 2,
    backend: Literal["matplotlib", "bokeh"] | str | None = None,
    subplots_kwargs: dict | None = None,
    method: Literal["plot", "scatter"] | None = None,
    line_kwargs: Iterable[Dict[str, Any]] | None = None,
    line_kwargs_each: Literal["experiment", "line"] = "experiment",
    props: Dict[str, Any] | None = None,
    bokeh_show: bool = False,
    tight_layout: bool = True,
    **kwargs
) -> Union["MplFigure", "BkGridPlot"]

Plot the simulations.

plotof

plotof(
    *args: str,
    x: str | Literal["first", "auto"] = "auto",
    type: Literal["experiment", "simulation"] = "experiment",
    experiments: ExperimentsType | None = None,
    phase_steps: dict[str, int] | None = None,
    phase: int | slice | Iterable[int] = slice(None),
    step: int | slice | Iterable[int] = slice(None),
    idx: int | slice | Iterable[int] = slice(None),
    col: int | slice | Iterable[int] = slice(None),
    normalize: bool | Literal["max", "mean", "x"] | float = False,
    normalize_x: float | None = None,
    label: str = "{experiment}",
    data: (
        List[SVExporter]
        | SVExporter
        | List[YieldFunction]
        | YieldFunction
        | None
    ) = None,
    data_set_experiment_options: bool = False,
    data_get_kwargs: Dict[str, Any] | None = None,
    experiment_get_kwargs: Dict[str, Any] | None = None,
    experiment_data_multipliers: Dict[str, float] | None = None,
    on: Plottable | None = None,
    ncols: int = 2,
    backend: Literal["matplotlib", "bokeh"] | str | None = None,
    subplots_kwargs: dict | None = None,
    method: Literal["plot", "scatter"] | None = None,
    line_kwargs: Iterable[Dict[str, Any]] | None = None,
    line_kwargs_each: Literal["experiment", "line"] = "experiment",
    props: Dict[str, Any] | None = None,
    bokeh_show: bool = False,
    tight_layout: bool = True,
    **kwargs
) -> Union["MplFigure", "BkGridPlot"]

Plot the experiments and/or simulations.

Notes

The following placeholders are supported for arguments label, kwargs and line_kwargs:

  • material parameters (model.parameters)
  • experiment options (experiment.options) and notes (experiment.notes)
  • {x} and {y} for the name of the variable
  • {idx}, {beta} and {gamma} for contact variables
  • {experiment} for the name of the experiment
  • {type} for the type of the data, either "experiment" or "simulation"
PARAMETER DESCRIPTION
args

State variables to plot. If the number of arguments is an even number, multiple curves will be plotted with every two arguments as a pair of x and y. If the number of arguments is an odd number, the x will be the step number and the y will be all the arguments. For example, the following usages are valid:

  • .plot("fn", "fr"): plot fn against fr
  • .plot("fn", "fr", "un", "ur"): plot fn against fr and un against ur
  • .plot("fn", "fs, "ft"): plot step against fn, fs and ft

if you specify x="first":

  • .plot("step", "fn", "fs, "ft", x="first"): plot step against fn, fs and ft

or any other string:

  • .plot("fn", "fs, "ft", x="step"): plot step against fn, fs and ft

If you want to use a different strategy for the x-axis, you can specify it with x.

TYPE: str DEFAULT: ()

x

Variable to plot on x-axis, by default "auto".

  • "auto": the default strategy, the x variable depends on the number of arguments described above
  • "first": use the first variable as x, the rest variables in args as y
  • any other string: use the specified variable as x, all the variables in args as y

TYPE: str DEFAULT: 'auto'

type

The type of the plot, by default "experiment"

TYPE: str DEFAULT: 'experiment'

experiments

The experiments to plot, by default None which means all experiments in the manager

TYPE: Experiment | List[Experiment] | Dict[str, Experiment] DEFAULT: None

phase_steps

Override the number of steps for each load phase, by default None

TYPE: dict[str, int] DEFAULT: None

phase

An integer or a slice indicates index of the phase.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

step

An integer or a slice indicates index of the step.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

idx

An integer or a slice indicates index of the integration point for contact variables.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

col

An integer or a slice indicates index of the column for variables with multiple columns, this argument will be ignored if the variable has only one column or the column index is already specified in var.

TYPE: int | slice | Iterable[int] DEFAULT: slice(None)

normalize

Whether to normalize the data variables. If True or "max", normalize by the maximum value. If "mean", normalize by the mean value, if "x", normalize by the value corresponding to this angle specified by normalize_x, if a float, normalize by the value corresponding to this angle.

TYPE: (bool, str, float) DEFAULT: False

normalize_x

The x value to normalize the yield function.

TYPE: float DEFAULT: None

label

Format string for the label in the legend, by default {experiment}

TYPE: str DEFAULT: '{experiment}'

data

State variables to plot, if not specified, the simulation will be run, by default None

TYPE: List[SVExporter] | SVExporter | List[YieldFunction] | YieldFunction DEFAULT: None

data_set_experiment_options

Whether to set the experiment options to the data, by default False

TYPE: bool DEFAULT: False

data_get_kwargs

Extra keyword arguments for the get method of the data object, the key can contain placeholders {x} and {y}, the value can be strings in the format of <expx>, <expy>, or any other variables that can be obtained from experiment.get(x) method, by default None

TYPE: Dict[str, Any] DEFAULT: None

experiment_get_kwargs

Extra keyword arguments for the get method of the experiment object, by default None

TYPE: Dict[str, Any] DEFAULT: None

experiment_data_multipliers

Multipliers for the experiment data, by default None

TYPE: Dict[str, float] DEFAULT: None

on

Axes to plot on, by default None

TYPE: PlotAxes DEFAULT: None

ncols

Number of columns in the figure grid, by default 2

TYPE: int DEFAULT: 2

backend

Backend to use, by default None which means the backend set in the environment variable MICROMECHANICAL_PLOTTING_BACKEND.

TYPE: Literal['matplotlib', 'bokeh'] | str DEFAULT: None

subplots_kwargs

Keyword arguments for creating the subplots, by default None

TYPE: dict DEFAULT: None

method

Method to use for plotting, by default plot for simulations and scatter for experiments

TYPE: Literal['plot', 'scatter'] DEFAULT: None

line_kwargs

Keyword arguments for the lines, by default None

TYPE: Iterable[Dict[str, Any]] DEFAULT: None

line_kwargs_each

Whether to use the line kwargs for each line or for each experiment, by default "experiment"

TYPE: str DEFAULT: 'experiment'

props

Properties passed to the setAxesProps method to set the axes properties, by default None

TYPE: Dict[str, Any] DEFAULT: None

bokeh_show

Whether to show the figure in the browser, by default False

TYPE: bool DEFAULT: False

tight_layout

Whether to use tight layout in the matplotlib figure, by default True

TYPE: bool DEFAULT: True

kwargs

Keyword arguments for plt.plot or bplt.line or plt.scatter or bplt.scatter

DEFAULT: {}

tensorplot classmethod

tensorplot(
    tensor: "ndarray",
    n_theta: int = N_THETA_DEFAULT,
    n_phi: int = N_PHI_DEFAULT,
    *,
    on: Plottable | None = None,
    props: Dict[str, Any] | None = None,
    **kwargs
)

Plot a fabric tensor.

_figure_postprocess

_figure_postprocess(
    axes: AxesType | List[AxesType] | List[List[AxesType | None]],
    *,
    backend: Literal["matplotlib", "bokeh"] | str | None = None,
    tight_layout: bool = True,
    ncols: int = 2,
    props: Dict[str, Any] | None = None,
    bokeh_show: bool = False
) -> Union["MplFigure", "BkGridPlot"]

_normalize_xydata

_normalize_xydata(
    xdata: ndarray,
    ydata: ndarray,
    *,
    normalize: bool | Literal["max", "mean", "x"] | float = False,
    normalize_x: float | None = None
) -> Tuple[ndarray, ndarray]

_numba_dict_merge

_numba_dict_merge(
    *data: dict | None, keytype: Type | Type, valtype: Type | Type, **kwargs
)

Merge multiple dictionaries into a numba typed dictionary, None is ignored.