Index
Micromechanical modeling of granular materials.
__all__
module-attribute
__all__ = [
"backends",
"config",
"Experiment",
"get_include",
"Line",
"Model",
"SVExporter",
"tr",
"trs",
"__version__",
"__semver__",
]
Experiment
Bases: HashableBaseModelIO
An experiment.
caches
class-attribute
caches: Dict[str, LRUCache] = {
"getitem": LRUCache(maxsize=128),
"__getitem__": LRUCache(maxsize=128),
}
caches for the getitem and getitem methods
data_multipliers
class-attribute
instance-attribute
Multipliers for the data, used to scale the data in the experiment
lines
class-attribute
instance-attribute
list of lines in the experiment
notes
class-attribute
instance-attribute
custom notes for the experiment, only for labelling purposes and not used in the calculation
options
class-attribute
instance-attribute
options for the micromechanical-specific model, used in :meth:micromechanical.Model.setOptions
to set the
calculation options for the model
phases
class-attribute
instance-attribute
phases: Dict[str, LoadPhaseIO] = {}
load phases of the experiment
__contains__
__getitem__
addConfinementPhase
addConfinementPhase(epsa_max: float, steps: int) -> LoadPhaseIO
Add a confinement load phase.
PARAMETER | DESCRIPTION |
---|---|
steps
|
Number of steps.
TYPE:
|
epsa_max
|
Maximum strain.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LoadPhaseIO
|
The load phase. |
addDrainedTriaxialPhase
addDrainedTriaxialPhase(
sigc: float, epsa_max: float, steps: int
) -> LoadPhaseIO
Add a drained triaxial load phase.
PARAMETER | DESCRIPTION |
---|---|
steps
|
Number of steps.
TYPE:
|
sigc
|
Confined stress.
TYPE:
|
epsa_max
|
Maximum strain.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LoadPhaseIO
|
The load phase. |
addIsotropicPhase
addIsotropicPhase(sigc: float, steps: int) -> LoadPhaseIO
Add an isotropic load phase.
PARAMETER | DESCRIPTION |
---|---|
steps
|
Number of steps.
TYPE:
|
sigc
|
Confined stress.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LoadPhaseIO
|
The load phase. |
addLoadPhase
addLoadPhase(name: str, phase: LoadPhaseIO | LoadPhase) -> LoadPhaseIO
Add a load phase.
PARAMETER | DESCRIPTION |
---|---|
name
|
Name of the load phase.
TYPE:
|
phase
|
The load phase, if not an instance of
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LoadPhaseIO
|
The load phase. |
addTrueTriaxialPhase
addTrueTriaxialPhase(
sig3: float, b: float, epsa_max: float, steps: int
) -> LoadPhaseIO
addTrueTriaxialWithConstantShearPhase
addTrueTriaxialWithConstantShearPhase(
p: float, b: float, steps: int
) -> LoadPhaseIO
addUndrainedTriaxialPhase
addUndrainedTriaxialPhase(epsa_max: float, steps: int) -> LoadPhaseIO
Add an undrained triaxial load phase.
PARAMETER | DESCRIPTION |
---|---|
steps
|
Number of steps.
TYPE:
|
epsa_max
|
Maximum strain.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LoadPhaseIO
|
The load phase. |
addUndrainedTriaxialWithoutShearPhase
addUndrainedTriaxialWithoutShearPhase(
epsa_max: float, steps: int
) -> LoadPhaseIO
Add an undrained triaxial load phase without controlling the shear strain.
PARAMETER | DESCRIPTION |
---|---|
steps
|
Number of steps.
TYPE:
|
epsa_max
|
Maximum strain.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LoadPhaseIO
|
The load phase. |
check
Check whether the experiment is valid.
PARAMETER | DESCRIPTION |
---|---|
raise_
|
Whether to raise an error if the experiment is invalid, by default True
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool | None
|
True if the experiment is valid, False if the experiment is invalid, None if the experiment is not checked. |
get
get(
x: str,
y: str | None = None,
*,
deep: bool = False,
idx: int | Iterable[int] | slice = None
) -> Tuple[ndarray, ndarray] | ndarray
Return the x-axis and y-axis data of a line.
PARAMETER | DESCRIPTION |
---|---|
x
|
Name of the x-axis of the line.
TYPE:
|
y
|
Name of the y-axis of the line. If None, only the x-axis data will be returned.
TYPE:
|
deep
|
Search for the line deeply in the experiment, by default False to avoid RecursionError.
TYPE:
|
idx
|
Index of the data to be returned, by default None to return all data. |
RETURNS | DESCRIPTION |
---|---|
Tuple[ndarray, ndarray] | ndarray
|
The x-axis and y-axis data of the line, or only the x-axis data if y is None. |
getitem
Return the x-axis and y-axis data of a line, only for exactly matching lines or expressions that can be evaluated to the x-axis and y-axis names.
PARAMETER | DESCRIPTION |
---|---|
item
|
Names of the x-axis and y-axis of the line. |
RETURNS | DESCRIPTION |
---|---|
Tuple[ndarray, ndarray]
|
The x-axis and y-axis data of the line. |
Line
Bases: HashableBaseModelIO
A line for an experiment.
x
instance-attribute
x: str
x-axis name of the line, used in :meth:micromechanical.python.micromechanical.core.StateVariables.get
to get
the x-axis data
y
instance-attribute
y: str
y-axis name of the line, used in :meth:micromechanical.python.micromechanical.core.StateVariables.get
to get
the y-axis data
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++ backendMICROMECHANICAL_BACKEND=python;NUMBA_DISABLE_JIT=1
: use the pure Python backendMICROMECHANICAL_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:
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:
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:
Evaluate the model:
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:
If two positional arguments are provided, they should be:
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:
TYPE:
|
args
|
The positional arguments for the micromechanical model if the supplied model is a class.
TYPE:
|
kwargs
|
The keyword arguments for the micromechanical model if the supplied model is a class.
TYPE:
|
no_stop
|
Whether to stop the calculation when an error occurs.
TYPE:
|
backend
|
The backend to use, default is the configured backend.
TYPE:
|
options
|
The calculation options for the micromechanical model, the contact law, or the material.
DEFAULT:
|
SVExporter
State variables exporter to handle a list of state variables. The constructor of the SVExporter
class accepts
a list of StateVariable
objects:
>>> from micromechanical.python.micromechanical.core.statevariable import StateVariable
>>> sv0, sv1 = StateVariable(37), StateVariable(37)
>>> sv0.phase, sv1.phase = 0, 1
>>> exporter = SVExporter([sv0] * 60 + [sv1] * 40)
There are three ways to get state variables:
-
Get the state variables by name, e.g.
exporter.sig
implemented bySVExporter.__getattr__
method. the state variables will be cached. This method will collect a specific state variable from all the state variables in the list, and return a numpy array with the first dimension being the step index. The returned array can be a 1D array, a 2D array or a 3D array, depending on the shape of the state variable. -
Get the state variables by name or expression of the name or name with column index, e.g.,
exporter["sig"]
, implemented bySVExporter.__getitem__
. -
Get the state variables by the above name with filters, implemented by the
SVExporter.get
method. This method is used to determine the state variables to get in visualization methods such asVisualizationModel.plot
and x/y axis of the experimentLine
.The following filters are supported:
phase
: load phase indexstep
: step indexidx
: integration point index, only valid for contact state variablescol
: column index, only valid for vector state variables
You can use the filters by the keyword arguments.
Note
The above filters are applied with the following steps:
- If
phase
is specified, the state variables will be filtered by the phase index first. - An array of the indices of the steps corresponding to the phase will be generated by the
SVExporter.indexOf
method. - An array of the state variable will be generated by the
SVExporter.__getitem__
method, and then filtered by the indices of the steps. - If the array is a 3D array, it will be filtered by the step index, integration point index and column index
in each dimension, i.e.,
array[step, idx, col]
. - If the array is a 2D array, depending on the name of the state variable, it will be filtered by the step
index and integration point index if the state variable is a contact state variable
(i.e.,
array[step, idx]
), or filtered by the step index and column index otherwise (i.e.,array[step, col]
) . - If the array is a 1D array, it will be filtered by the step index, i.e.,
array[step]
.
Note
Property fabric tensors can be obtained by the name F_{prop}
where {prop}
is the property name.
You can also export the state variables to a pandas DataFrame by the
SVExporter.toDataFrame
method.
>>> df = exporter.toDataFrame(includes=["sig", "eps"])
Saving state variables to DataFrame
>>> df.head()
eps1 eps2 eps3 eps4 eps5 eps6 sig1 sig2 sig3 sig4 sig5 sig6
...
Then it is possible to export the DataFrame to any file format supported by pandas, e.g., csv, excel, etc.
FN11
instance-attribute
FN11: ndarray
Fabric tensor of contact normal force component FN11, shape (steps,)
FN12
instance-attribute
FN12: ndarray
Fabric tensor of contact normal force component FN12, shape (steps,)
FN13
instance-attribute
FN13: ndarray
Fabric tensor of contact normal force component FN13, shape (steps,)
FN22
instance-attribute
FN22: ndarray
Fabric tensor of contact normal force component FN22, shape (steps,)
FN23
instance-attribute
FN23: ndarray
Fabric tensor of contact normal force component FN23, shape (steps,)
FN33
instance-attribute
FN33: ndarray
Fabric tensor of contact normal force component FN33, shape (steps,)
FT11
instance-attribute
FT11: ndarray
Fabric tensor of contact shear force component FT11, shape (steps,)
FT12
instance-attribute
FT12: ndarray
Fabric tensor of contact shear force component FT12, shape (steps,)
FT13
instance-attribute
FT13: ndarray
Fabric tensor of contact shear force component FT13, shape (steps,)
FT22
instance-attribute
FT22: ndarray
Fabric tensor of contact shear force component FT22, shape (steps,)
FT23
instance-attribute
FT23: ndarray
Fabric tensor of contact shear force component FT23, shape (steps,)
FT33
instance-attribute
FT33: ndarray
Fabric tensor of contact shear force component FT33, shape (steps,)
an
instance-attribute
an: ndarray
Degree of fabric anisotropy for the contact normal force, shape (steps,)
at
instance-attribute
at: ndarray
Degree of fabric anisotropy for the contact shear force, shape (steps,)
depspu
cached
property
depspu: ndarray
Plastic strain increment from displacements, shape (steps, 6)
depspua
cached
property
depspua: ndarray
Axial plastic strain increment from displacements, shape (steps,)
depspud
cached
property
depspud: ndarray
General shear plastic strain increment from displacements, shape (steps,)
depspuv
cached
property
depspuv: ndarray
Volumetric plastic strain increment from displacements, shape (steps,)
disp
instance-attribute
disp: ndarray
Displacement for every integration point, shape (steps, size, 3)
dispp
instance-attribute
dispp: ndarray
Plastic displacement for every integration point, shape (steps, size, 3)
dups
cached
property
dups: ndarray
Plastic shear displacement increment at the first direction, shape (steps, size)
dupt
cached
property
dupt: ndarray
Plastic shear displacement increment at the second direction, shape (steps, size)
dus
cached
property
dus: ndarray
Shear displacement increment at the first direction, shape (steps, size)
dut
cached
property
dut: ndarray
Shear displacement increment at the second direction, shape (steps, size)
epspq
cached
property
epspq: ndarray
Plastic strain exclude strain after the first phase, shape (steps,)
epspqa
cached
property
epspqa: ndarray
Axial plastic strain exclude strain after the first phase, shape (steps,)
epspqd
cached
property
epspqd: ndarray
General plastic shear strain exclude strain after the first phase, shape (steps,)
epspqv
cached
property
epspqv: ndarray
Volumetric plastic strain exclude strain after the first phase, shape (steps,)
epspqva
cached
property
epspqva: ndarray
Volumetric plastic strain approximation exclude strain after the first phase, shape (steps,)
epspui
cached
property
epspui: ndarray
Plastic strain from displacements after the first phase, shape (steps, 6)
epspuq
cached
property
epspuq: ndarray
Plastic strain from displacements exclude strain after the first phase, shape (steps,)
epspuqa
cached
property
epspuqa: ndarray
Axial plastic strain from displacements exclude strain after the first phase, shape (steps,)
epspuqd
cached
property
epspuqd: ndarray
General plastic shear strain from displacements exclude strain after the first phase, shape (steps,)
epspuqv
cached
property
epspuqv: ndarray
Volumetric plastic strain from displacements exclude strain after the first phase, shape (steps,)
epspuqva
cached
property
epspuqva: ndarray
Volumetric plastic strain from displacements approximation exclude strain after the first phase, shape (steps,)
epsqa
cached
property
epsqa: ndarray
Axial strain exclude strain after the first phase, shape (steps,)
epsqd
cached
property
epsqd: ndarray
General shear strain exclude strain after the first phase, shape (steps,)
epsqv
cached
property
epsqv: ndarray
Volumetric strain exclude strain after the first phase, shape (steps,)
epsqva
cached
property
epsqva: ndarray
Volumetric strain approximation exclude strain after the first phase, shape (steps,)
fs
instance-attribute
fs: ndarray
Shear force at the first direction for every integration point, shape (steps, size)
ft
instance-attribute
ft: ndarray
Shear force at the second direction for every integration point, shape (steps, size)
p0
instance-attribute
p0: ndarray
Size of the yield surface for the SaniSand model, shape (steps, size)
un
instance-attribute
un: ndarray
Normal displacement for every integration point, shape (steps, size)
upn
instance-attribute
upn: ndarray
Plastic normal displacement for every integration point, shape (steps, size)
upr
instance-attribute
upr: ndarray
Plastic shear displacement for every integration point, shape (steps, size)
ups
instance-attribute
ups: ndarray
Plastic shear displacement at the first direction for every integration point, shape (steps, size)
upt
instance-attribute
upt: ndarray
Plastic shear displacement at the second direction for every integration point, shape (steps, size)
ur
instance-attribute
ur: ndarray
Shear displacement for every integration point, shape (steps, size)
us
instance-attribute
us: ndarray
Shear displacement at the first direction for every integration point, shape (steps, size)
ut
instance-attribute
ut: ndarray
Shear displacement at the second direction for every integration point, shape (steps, size)
__getattr__
cached
__getitem__
cached
Get state variables
PARAMETER | DESCRIPTION |
---|---|
item
|
A string specifies name or an expression of the state variable parsed by
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
array
|
An array of the state variable, the shape of the array depends on the type of the state variable and the arguments specified in the name and index:
TYPE:
|
__init__
__init__(stateVars: List['StateVariable'])
Initialize state variables exporter
PARAMETER | DESCRIPTION |
---|---|
stateVars
|
State variables
TYPE:
|
abaqusStateVariableNames
classmethod
abaqusStateVariableNames(
contact_type: str, size: int = 37, reverse: bool = False
) -> dict[str, str]
The state variable names for the Abaqus subroutine, a dictionary of ("SDV{i}", name)
pairs. If reverse
is True, the dictionary is reversed to {name: "SDV{i}"}
pairs.
fromAbaqusStateVariables
classmethod
fromAbaqusStateVariables(
data: "DataFrame" | str | PathLike,
contact_type: str,
*,
size: int = 37,
phase_column: str = "Step"
) -> "SVExporter"
Create state variables exporter by a data file exported from an Abaqus output database, data is a pandas
DataFrame or a csv file with columns of names like SDV{i}
. A column with name Step
is required to
specify the load phase or any other column name specified by phase_column
, if the column is not available,
the phase will be set to 0.
get
get(
var: str,
*,
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)
) -> Union[ndarray, float]
Get state variables
PARAMETER | DESCRIPTION |
---|---|
var
|
A string specifies name or an expression of the state variable parsed by
TYPE:
|
phase
|
An integer or a slice indicates index of the phase. |
step
|
An integer or a slice indicates index of the step, noted that the step index is the relative step index
to the phase if |
idx
|
An integer or a slice indicates index of the integration point for contact variables. |
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 |
RETURNS | DESCRIPTION |
---|---|
array
|
An array or a float of the state variable |
indexOf
Get the indices of the corresponding steps belonging to a phase or phases
isContactVariable
Check if a state variable is a contact variable
toDataFrame
toDataFrame(
includes: Iterable[str] | None = None,
excludes: Iterable[str] = (),
*,
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),
set_columns: bool = False
) -> "DataFrame"
Convert state variables to a pandas DataFrame
PARAMETER | DESCRIPTION |
---|---|
includes
|
An iterable of state variable names to be included, by default None, which means only stress and strain state variables will be included. |
excludes
|
An iterable of state variable names to be excluded, by default (), which means no state variable will be excluded. |
phase
|
Filters for the state variables, see :meth: |
step
|
Filters for the state variables, see :meth: |
idx
|
Filters for the state variables, see :meth: |
col
|
Filters for the state variables, see :meth: |
set_columns
|
Set the column names of the DataFrame, by default False.
TYPE:
|
to_csv
to_csv(
filename: PathLike | str,
includes: Iterable[str] | None = None,
excludes: Iterable[str] = (),
*,
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),
set_columns: bool = False,
**kwargs
)
Save state variables to a csv file
PARAMETER | DESCRIPTION |
---|---|
filename
|
The filename to save the state variables. |
includes
|
Arguments for :meth: |
excludes
|
Arguments for :meth: |
phase
|
Arguments for :meth: |
step
|
Arguments for :meth: |
idx
|
Arguments for :meth: |
col
|
Arguments for :meth: |
set_columns
|
Set the column names of the DataFrame, by default True.
TYPE:
|
kwargs
|
Other arguments for :meth:
DEFAULT:
|