Skip to content

Commit 7d643eb

Browse files
committed
Correcting the get_weighted_torques function to use the eigenvalues of the moment of inertia rather than the diagonal elements for weighting
1 parent f92462c commit 7d643eb

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

CodeEntropy/levels.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,9 @@ def get_weighted_torques(self, data_container, bead, rot_axes, force_partitionin
344344
# divide by moment of inertia to get weighted torques
345345
# moment of inertia is a 3x3 tensor
346346
# the weighting is done in each dimension (x,y,z) using
347-
# the diagonal elements of the moment of inertia tensor
348-
moment_of_inertia = bead.moment_of_inertia()
347+
# the sorted eigenvalues of the moment of inertia tensor
348+
eigenvalues, _ = np.linalg.eig(bead.moment_of_inertia())
349+
moments_of_inertia = sorted(eigenvalues, reverse=True)
349350

350351
for dimension in range(3):
351352
# Skip calculation if torque is already zero
@@ -354,14 +355,14 @@ def get_weighted_torques(self, data_container, bead, rot_axes, force_partitionin
354355
continue
355356

356357
# Check for zero moment of inertia
357-
if np.isclose(moment_of_inertia[dimension, dimension], 0):
358+
if np.isclose(moments_of_inertia[dimension], 0):
358359
# If moment of inertia is 0 there should be 0 torque
359360
weighted_torque[dimension] = 0
360361
logger.warning("Zero moment of inertia. Setting torque to 0")
361362
continue
362363

363364
# Check for negative moment of inertia
364-
if moment_of_inertia[dimension, dimension] < 0:
365+
if moments_of_inertia[dimension] < 0:
365366
raise ValueError(
366367
f"Negative value encountered for moment of inertia: "
367368
f"{moment_of_inertia[dimension]} "
@@ -370,7 +371,7 @@ def get_weighted_torques(self, data_container, bead, rot_axes, force_partitionin
370371

371372
# Compute weighted torque
372373
weighted_torque[dimension] = torques[dimension] / np.sqrt(
373-
moment_of_inertia[dimension, dimension]
374+
moments_of_inertia[dimension]
374375
)
375376

376377
logger.debug(f"Weighted Torque: {weighted_torque}")

0 commit comments

Comments
 (0)