From e24f81f1ee4dba0bd189ac7df33f209bb31b3e24 Mon Sep 17 00:00:00 2001 From: "Marco A. Lopez-Sanchez" Date: Thu, 11 Jul 2024 14:08:40 +0200 Subject: [PATCH] minor corrections in modules --- src/christoffel.py | 40 ---------------------------------------- src/tensor_tools.py | 14 +++++++------- 2 files changed, 7 insertions(+), 47 deletions(-) diff --git a/src/christoffel.py b/src/christoffel.py index 97e0621..1a5e696 100644 --- a/src/christoffel.py +++ b/src/christoffel.py @@ -124,46 +124,6 @@ def christoffel_wave_speeds( pass -def _rearrange_tensor(Cij: np.ndarray) -> np.ndarray: - """Rearrange a 6x6 (rank 2, dimension 6) elastic tensor into - a 3x3x3x3 (rank 4, dimension 3) elastic tensor according to - Voigt notation. This rearranging improves tensor operations - while maintaining the original information. - - Parameters - ---------- - Cij : numpy.ndarray - The 6x6 elastic tensor in Voigt notation. - - Returns - ------- - numpy.ndarray of shape (3, 3, 3, 3). - The equivalent 3x3x3x3 elastic tensor - - Notes - ----- - The function uses a dictionary, `voigt_notation`, to map the - indices from the 6x6 tensor to the 3x3x3x3 tensor in Voigt - notation. The resulting tensor, Cijkl, is calculated by - rearranging elements from the input tensor, Cij, according to - the mapping. - """ - - voigt_notation = {0: 0, 11: 1, 22: 2, 12: 3, 21: 3, 2: 4, 20: 4, 1: 5, 10: 5} - - Cijkl = np.zeros((3, 3, 3, 3)) - - for L in range(3): - for k in range(3): - for j in range(3): - for i in range(3): - Cijkl[i, j, k, L] = Cij[ - voigt_notation[10 * i + j], voigt_notation[10 * k + L] - ] - - return Cijkl - - def _christoffel_matrix(wavevectors: np.ndarray, Cijkl: np.ndarray) -> np.ndarray: """Calculate the Christoffel matrix for a given wave vector and elastic tensor Cij. diff --git a/src/tensor_tools.py b/src/tensor_tools.py index a3b93f9..06701a8 100644 --- a/src/tensor_tools.py +++ b/src/tensor_tools.py @@ -64,10 +64,10 @@ def _symmetrise_tensor(tensor: np.ndarray) -> np.ndarray: def _rearrange_tensor(Cij: np.ndarray) -> np.ndarray: - """Rearrange a 6x6 (rank 2, dimension 6) elastic tensor into - a 3x3x3x3 (rank 4, dimension 3) elastic tensor according to - Voigt notation. This rearranging improves tensor operations - while maintaining the original information. + """Rearranges the 6x6 (rank 2, dimension 6) stiffness (elastic) + matrix in Voigt notation into a 3x3x3x3 (rank 4, dimension 3) + stiffness tensor. This rearrangement is necessary to perform + tensor operations while retaining the original information. Parameters ---------- @@ -270,7 +270,7 @@ def rotate_stiffness_tensor( rotation_axis: str = "z" ) -> tuple[np.ndarray, np.ndarray]: """Rotates a stiffness matrix (Voigt notation) or a - stiffness tensor around a specified axis. The rotation + stiffness tensor aabout a specified axis. The rotation is performed in the right-handed coordinate system taking into account the following reference frame: @@ -306,13 +306,13 @@ def rotate_stiffness_tensor( if not isinstance(rotation_axis, str): raise ValueError("rotation_axis should be a string.") - if stiffness_tensor.shape != (3, 3, 3, 3) or stiffness_tensor.shape != (6, 6): + if not (stiffness_tensor.shape == (3, 3, 3, 3) or stiffness_tensor.shape == (6, 6)): raise ValueError( "Input stiffness array must be 3x3x3x3 or 6x6 (Voigt notation)" ) # convert 6x6 to 3x3x3x3 - if stiffness_tensor.shape != (6, 6): + if stiffness_tensor.shape == (6, 6): stiffness_tensor = _rearrange_tensor(stiffness_tensor) # generate the rotation