Skip to content

Commit

Permalink
minor corrections in modules
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoalopez committed Jul 11, 2024
1 parent 0dcf316 commit e24f81f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 47 deletions.
40 changes: 0 additions & 40 deletions src/christoffel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions src/tensor_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e24f81f

Please sign in to comment.