statmechcrack.utility
A module for basic crack model utilities.
This module consist of the class BasicUtility
which contains
attributes and methods that are meant to be inherited and utilized as
basic utilities by an arbitrary crack model class.
- class BasicUtility[source]
Bases:
object
The crack model basic utilities class.
This class contains attributes and methods that are meant to be inherited and utilized as basic utilities by an arbitrary crack model class.
- minimum float
Helps avoid overflow when dividing by small numbers.
- maximum_float
Helps avoid overflow in function evaluations.
- maximum_exponent
Helps avoid overflow in exponential functions.
- inv_fun(fun, val, guess=None, **kwargs)[source]
Function to invert a mathematical function.
This function returns the argument x given a function f(x) and y, the query value of the function, i.e. y = f(x).
Note
This function is only meant for bijective f(x).
- Parameters:
fun (function) – The function f(x).
val (array_like) – The value(s) of the function y.
guess (list, optional) – A list of two initial guesses.
**kwargs – Arbitrary keyword arguments. Passed to
root_scalar
.
- Returns:
The corresponding argument(s) x.
- Return type:
numpy.ndarray
- np_array(input_)[source]
Function to return input as a numpy array.
This function essentially serves as a wrapper for
numpy.array
that returns non-array type inputs as shape (1,) numpy arrays rather than shape () numpy arrays, which is useful for indexing.- Parameters:
input (array_like) – Anything passable to
numpy.array
.- Returns:
The input as an index-able numpy array.
- Return type:
numpy.ndarray
Example
Compare attempts to index the numpy array of an integer:
>>> import numpy as np >>> from statmechcrack.utility import BasicUtility >>> try: ... np.array(8)[0] ... except IndexError: ... print('Error indexing 0-dimensional array.') ... finally: ... BasicUtility().np_array(8)[0] Error indexing 0-dimensional array. 8