utils package
Submodules
utils.abaqus module
- utils.abaqus.get_results_from_json(fname: str) Dict[source]
Read homogenization results from json and return compliance tensors
- Parameters:
fname (str) – path to json file
- Raises:
ValueError – if json file does not contain all required data
- Returns:
dictionary with keys ‘job’, ‘name’, ‘compliance_tensors_M’
- Return type:
Dict
- utils.abaqus.write_abaqus_inp(lat: Lattice, strut_radii: Iterable, metadata: Dict[str, str], loading: List[Tuple] = [(1, 1, 1.0), (1, 2, 1.0), (1, 3, 1.0), (2, 1, 0.5), (2, 2, 0.5), (2, 3, 0.5)], fname: str | None = None, element_type: str | None = 'B31')[source]
Write abaqus input script for a specific lattice and loading
- Parameters:
lat (Lattice) – Lattice
loading (List[Tuple]) – list of 3-element tuples where first element is reference point number second is degree of freedom to which displacement is applied and third is the magnitude of displacement
fname (Optional[str], optional) – name of input script file or stream to write to
metadata (Dict[str, str]) – dictionary that will be written in header
lat – Lattice object
loading – list of 3-element tuples where first element is reference point number, second is degree of freedom to which displacement is applied and third is the magnitude of displacement
metadata – Extra information to put in the *Header section
fname – if fname is provided, output is written to file fname. Otherwise, return lines of text. Defaults to None.
- utils.abaqus.write_abaqus_inp_nopbc(lat: Lattice, strut_radii: ndarray, metadata: Dict[str, str], fname: str | None = None, element_type: str | None = 'B31', node_sets: Dict[str, Iterable] | None = None, boundary_conditions: Dict[str, Iterable] | None = None)[source]
Write abaqus input script for a specific lattice and loading
- utils.abaqus.write_abaqus_inp_normals(lat: Lattice, strut_radii: ndarray, metadata: Dict[str, str], fname: str | None = None, element_type: str | None = 'B31', loading: List[Tuple] = [(1, 1, 1.0), (1, 2, 1.0), (1, 3, 1.0), (2, 1, 0.5), (2, 2, 0.5), (2, 3, 0.5)], mesh_params: Dict[str, float | int] = {'max_length': 1, 'min_div': 3})[source]
Write abaqus input script for a specific lattice and loading
- Parameters:
lat (Lattice) – Lattice
loading (List[Tuple]) – list of 3-element tuples where first element is reference point number second is degree of freedom to which displacement is applied and third is the magnitude of displacement
fname (Optional[str], optional) – name of input script file or stream to write to
metadata (Dict[str, str]) – dictionary that will be written in header
lat – Lattice object
loading – list of 3-element tuples where first element is reference point number, second is degree of freedom to which displacement is applied and third is the magnitude of displacement
metadata – Extra information to put in the *Header section
fname – if fname is provided, output is written to file fname. Otherwise, return lines of text. Defaults to None.
utils.elasticity_func module
- utils.elasticity_func.Mandel_rot_matrix_inplace(Q: ndarray, R: ndarray) None[source]
Fill the 6x6 rotation matrix for Mandel stress/strain vector
- Parameters:
Q (Union[np.ndarray, Tensor]) – 3x3 rotation matrix
R (Union[np.ndarray, Tensor]) – 6x6 rotation matrix to be filled
- utils.elasticity_func.Mandel_rot_matrix_numpy(Q: ndarray) ndarray[source]
Generate 6x6 rotation matrix for Mandel stress/strain vector
- Parameters:
Q (np.ndarray) – 3x3 rotation matrix
- Returns:
6x6 rotation matrix for Mandel stress/strain vector
- Return type:
np.ndarray
- utils.elasticity_func.Voigt_rot_matrix_strain_inplace(Q: ndarray, R: ndarray) None[source]
Fill the 6x6 rotation matrix for Voigt strain vector
- Parameters:
Q (Union[np.ndarray, Tensor]) – 3x3 rotation matrix
R (Union[np.ndarray, Tensor]) – 6x6 rotation matrix to be filled
- utils.elasticity_func.Voigt_rot_matrix_strain_numpy(Q: ndarray) ndarray[source]
Generate 6x6 rotation matrix for Voigt strain vector
- Parameters:
Q (np.ndarray) – 3x3 rotation matrix
- Returns:
6x6 rotation matrix for Voigt strain vector
- Return type:
np.ndarray
- utils.elasticity_func.Voigt_rot_matrix_stress_inplace(Q: ndarray, R: ndarray) None[source]
Fill the 6x6 rotation matrix for Voigt stress vector
- Parameters:
Q (Union[np.ndarray, Tensor]) – 3x3 rotation matrix
R (Union[np.ndarray, Tensor]) – 6x6 rotation matrix to be filled
- utils.elasticity_func.Voigt_rot_matrix_stress_numpy(Q: ndarray) ndarray[source]
Generate 6x6 rotation matrix for Voigt stress vector
- Parameters:
Q (np.ndarray) – 3x3 rotation matrix
- Returns:
6x6 rotation matrix for Voigt stress vector
- Return type:
np.ndarray
- utils.elasticity_func.Youngs_modulus(S: ndarray, d: ndarray) ndarray[source]
Calculate Young’s modulus in a specific direction
- Parameters:
S (np.ndarray) – Compliance tensor (3,3,3,3)
d (np.ndarray) – Direction vector (…,3)
- Returns:
_description_
- Return type:
np.ndarray
- utils.elasticity_func.compliance_4th_order_to_Voigt(S: ndarray) ndarray[source]
Convert 4th order compliance tensor to Voigt notation
- Parameters:
S (np.ndarray) – 4th order compliance tensor
- Returns:
6x6 Voigt notation compliance matrix
- Return type:
np.ndarray
- utils.elasticity_func.compliance_Mandel_to_Voigt(S: ndarray) ndarray[source]
Convert Mandel notation compliance matrix to Voigt notation
- Parameters:
S (np.ndarray) – 6x6 Mandel notation compliance matrix
- Returns:
6x6 Voigt notation compliance matrix
- Return type:
np.ndarray
- utils.elasticity_func.compliance_Voigt_to_4th_order(S: ndarray) ndarray[source]
Convert Voigt notation compliance matrix to 4th order tensor
- Parameters:
S (np.ndarray) – 6x6 Voigt notation compliance matrix
- Returns:
4th order compliance tensor
- Return type:
np.ndarray
- utils.elasticity_func.compliance_Voigt_to_Mandel(S: ndarray) ndarray[source]
Convert Voigt notation compliance matrix to Mandel notation
- Parameters:
S (np.ndarray) – 6x6 Voigt notation compliance matrix
- Returns:
6x6 Mandel notation compliance matrix
- Return type:
np.ndarray
- utils.elasticity_func.numpy_Mandel_to_cart_4(C: ndarray) ndarray[source]
Convert 6x6 Mandel notation tensor to 4th order tensor
- Parameters:
C (np.ndarray) – Mandel notation tensor (…,6,6)
- Returns:
4th order tensor of shape (…,3,3,3,3)
- Return type:
np.ndarray
- utils.elasticity_func.numpy_cart_4_to_Mandel(_C: ndarray) ndarray[source]
Convert 4th order tensor to 6x6 Mandel notation
- Parameters:
_C (np.ndarray) – 4th order tensor of shape (…,3,3,3,3)
- Returns:
6x6 Mandel notation tensor
- Return type:
np.ndarray
- utils.elasticity_func.rotate_4th_order(T: ndarray, Q: ndarray) ndarray[source]
Rotate 4th order tensor to a new coordinate system
- Parameters:
T (np.ndarray) – 3x3 rotation matrix
Q (np.ndarray) – 4th order tensor
- Returns:
Rotated 4th order tensor
- Return type:
np.ndarray
- utils.elasticity_func.rotate_Voigt_compliance(S: ndarray, R: ndarray) ndarray[source]
Rotate 6x6 compliance matrix in Voigt notation
- Parameters:
S (np.ndarray) – 6x6 Voigt compliance matrix
R (np.ndarray) – 3x3 rotation matrix
- Returns:
Rotated 6x6 Voigt compliance matrix
- Return type:
np.ndarray
- utils.elasticity_func.rotate_Voigt_stiffness(C: ndarray, R: ndarray) ndarray[source]
Rotate 6x6 stiffness matrix in Voigt notation
- Parameters:
C (np.ndarray) – 6x6 Voigt stiffness matrix
R (np.ndarray) – 3x3 rotation matrix
- Returns:
Rotated 6x6 Voigt stiffness matrix
- Return type:
np.ndarray
- utils.elasticity_func.stiffness_4th_order_to_Voigt(C: ndarray) ndarray[source]
Convert 4th order stiffness tensor to Voigt notation
- Parameters:
C (np.ndarray) – 4th order stiffness tensor
- Raises:
ValueError – Wrong shape of C
- Returns:
6x6 Voigt notation stiffness matrix
- Return type:
np.ndarray
- utils.elasticity_func.stiffness_Mandel_to_Voigt(C: ndarray) ndarray[source]
Convert Mandel notation stiffness matrix to Voigt notation
- Parameters:
C (np.ndarray) – 6x6 Mandel notation stiffness matrix
- Returns:
6x6 Voigt notation stiffness matrix
- Return type:
np.ndarray
- utils.elasticity_func.stiffness_Voigt_to_4th_order(C: ndarray) ndarray[source]
Convert Voigt notation stiffness matrix to 4th order tensor
- Parameters:
C (np.ndarray) – 6x6 Voigt notation stiffness matrix
- Returns:
4th order stiffness tensor
- Return type:
np.ndarray
- utils.elasticity_func.stiffness_Voigt_to_Mandel(C: ndarray) ndarray[source]
Convert Voigt notation stiffness matrix to Mandel notation
- Parameters:
C (np.ndarray) – 6x6 Voigt notation stiffness matrix
- Returns:
6x6 Mandel notation stiffness matrix
- Return type:
np.ndarray
- utils.elasticity_func.strain_to_Voigt_inplace(e: ndarray, x: ndarray) None[source]
Fill Voigt notation vector from 2nd order strain tensor
- Parameters:
e (Union[np.ndarray, Tensor]) – 2nd order strain tensor
x (Union[np.ndarray, Tensor]) – Voigt strain vector
- utils.elasticity_func.strain_to_Voigt_numpy(e: ndarray) ndarray[source]
Convert 2nd order strain tensor to Voigt notation
- Parameters:
e (np.ndarray) – 2nd order strain tensor
- Returns:
Voigt strain vector
- Return type:
np.ndarray
- utils.elasticity_func.stress_to_Voigt_inplace(s: ndarray, x: ndarray) None[source]
Fill Voigt notation vector from 2nd order stress tensor
- Parameters:
s (Union[np.ndarray, Tensor]) – 2nd order stress tensor
x (Union[np.ndarray, Tensor]) – Voigt stress vector
- utils.elasticity_func.stress_to_Voigt_numpy(s: ndarray) ndarray[source]
Convert 2nd order stress tensor to Voigt notation
- Parameters:
s (np.ndarray) – 2nd order stress tensor
- Returns:
Voigt stress vector
- Return type:
np.ndarray
utils.plotting module
- utils.plotting.plotly_scaling_surf(C: ndarray, rel_dens: Iterable[float], title: str = '', fig: Figure | None = None, subplot: dict | None = None, resolution: int = 100j) Figure[source]
Plot the surface of scaling exponent for a given stiffness tensor
- Parameters:
C (np.ndarray) – stacked compliance tensors [n_rel_dens, 3,3,3,3]
rel_dens (Iterable[float]) – corresponding relative densities
title (str, optional) – title for plot. Defaults to ‘’.
fig (Optional[dict], go.Figure) – can pass an existing figure. Defaults to None.
subplot (Optional[dict], optional) – subplot arguments. Expect keys [‘index’,’ncol’]. Defaults to None.
- Returns:
plotly figure
- Return type:
go.Figure
- utils.plotting.plotly_tensor_projection(C: ndarray, point_func: Callable | None = None, title: str = '', fig: Figure | None = None, subplot: dict | None = None, clim: Tuple[float, float] | None = None, resolution: complex = 100j) Figure[source]
Plot a projection of 4-th order tensor using plotly
- Parameters:
C (np.ndarray) – 4-th order tensor of shape (3,3,3,3) or (1,3,3,3,3)
point_func (Optional[Callable]) – function to apply point-wise to projections.
title (str, optional) – plot title
fig (Optional[go.Figure]) – existing figure. If None, a new figure is created.
subplot (Optional[dict]) – dictionary with keys [‘index’,’ncol’] to pick the subplot
clim (Optional[Tuple[float, float]]) – limits of color scale
resolution (complex, optional) – resolution of grid on the sphere given as complex number. Defaults to 100j.
- Returns:
Resulting plotly figure
- Return type:
go.Figure
- utils.plotting.plotly_unit_cell_3d(lat: Lattice, repr: Literal['cropped', 'fundamental'] = 'cropped', coords: Literal['reduced', 'transformed'] = 'reduced', show_node_numbers: bool = False, fig: Figure | None = None, subplot: dict | None = None, highlight_nodes: Iterable | None = None, highlight_edges: Iterable | None = None, show_uc_box: bool = False) Figure[source]
Plot unit cell in 3D using plotly
- Parameters:
lat (Lattice) – Unit cell to plot
repr (Literal["cropped", "fundamental"], optional) – Representation of edges. Defaults to ‘cropped’.
coords (Literal["reduced", "transformed"], optional) – Coordinate system to use. Defaults to ‘reduced’.
show_node_numbers (bool, optional) – Whether to show node numbers. Defaults to False.
fig (Optional[go.Figure], optional) – Existing plotly figure. Defaults to None.
subplot (Optional[dict], optional) – Subplot information. Should contain keys ‘index’ and ‘ncols’. Defaults to None.
highlight_nodes (Optional[Iterable], optional) – List of node numbers that should be highlighted. Defaults to None.
highlight_edges (Optional[Iterable], optional) – List of edges that should be highlighted. Defaults to None.
show_uc_box (bool, optional) – Whether to show unit cell bounding box. Defaults to False.
- Returns:
Resulting plotly figure
- Return type:
go.Figure