Add error handling for NaN and invalid values in calculations:#53
Merged
harryswift01 merged 1 commit intomainfrom Mar 10, 2025
Merged
Add error handling for NaN and invalid values in calculations:#53harryswift01 merged 1 commit intomainfrom
harryswift01 merged 1 commit intomainfrom
Conversation
- 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.
Closed
jimboid
approved these changes
Mar 10, 2025
Member
jimboid
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:r2orx2y2is zero.Mass and Moment of Inertia Checks in Force and Torque Calculation:
get_weighted_forcesto ensure it is positive before performing calculations.get_weighted_torquesto 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:
Frequency Calculation Safety Checks:
frequency_calculationto check for negative eigenvalues, which would have caused issues in calculating frequencies.Impact