Skip to content

Conversation

@harryswift01
Copy link
Contributor

Summary

This PR introduces error handling for invalid and edge-case values (like NaN, zero, and negative numbers), for example those in issue #7, to improve the stability and robustness of various calculation functions in the codebase. These checks ensure that invalid calculations (such as taking the square root of a negative number or dividing by zero) are caught and result in meaningful error messages, preventing runtime failures.

Changes

Error Handling for Spherical Coordinates Calculation get_sphCoord_axes:

  • Added checks for division by zero and invalid values (negative values or zero) in spherical coordinate calculations.
  • Prevented calculation of spherical coordinates when r2 or x2y2 is zero.

Mass and Moment of Inertia Checks in Force and Torque Calculation:

  • Introduced validation for mass in get_weighted_forces to ensure it is positive before performing calculations.
  • Enhanced get_weighted_torques to check for zero or invalid values in the moment of inertia tensor before performing any calculations, preventing invalid sqrt operations.

Negative Values Handling in Distance and Angle Calculations:

  • Updated the distance and angle functions to handle negative values, ensuring that invalid values don’t cause errors in square root operations.

Frequency Calculation Safety Checks:

  • Added validation to frequency_calculation to check for negative eigenvalues, which would have caused issues in calculating frequencies.

Impact

  • The codebase will be more robust, with explicit error handling for edge cases like division by zero or negative square roots.
  • The changes ensure that invalid calculations are caught early, providing meaningful error messages for debugging.
  • These updates will prevent runtime errors that could arise from edge-case data inputs and improve the stability of calculations across different functions.

- Added checks for division by zero and invalid values (negative values, zero) in spherical coordinates calculation (`get_sphCoord_axes`).
- Included validation to prevent invalid mass values (zero or negative) in `get_weighted_forces`.
- Implemented checks for zero and negative values in moment of inertia tensor to avoid invalid sqrt calculations in `get_weighted_torques`.
- Enhanced `distance` and `angle` functions to handle negative values that would cause invalid square root operations.
- Added checks for negative eigenvalues in `frequency_calculation` to prevent invalid frequency calculations.
@harryswift01 harryswift01 added the bug Something isn't working label Mar 10, 2025
@harryswift01 harryswift01 requested a review from jimboid March 10, 2025 12:18
@harryswift01 harryswift01 self-assigned this Mar 10, 2025
@harryswift01 harryswift01 linked an issue Mar 10, 2025 that may be closed by this pull request
Copy link
Member

@jimboid jimboid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct. I think a good thing to do tomorrow with Sarah F is have her pull the latest changes and quickly check it runs and gives the same numbers as before. So we can reference back to this point as being a good base.

@harryswift01 harryswift01 merged commit e7183f0 into main Mar 10, 2025
6 checks passed
@harryswift01 harryswift01 deleted the 7-nan-error-handling branch March 10, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nan Error Handling

3 participants