Skip to content

Add Von Mises Metric for Structural Mechanics Applications#1491

Open
mnabian wants to merge 21 commits intoNVIDIA:mainfrom
mnabian:main
Open

Add Von Mises Metric for Structural Mechanics Applications#1491
mnabian wants to merge 21 commits intoNVIDIA:mainfrom
mnabian:main

Conversation

@mnabian
Copy link
Collaborator

@mnabian mnabian commented Mar 11, 2026

PhysicsNeMo Pull Request

Description

Add von Mises stress metric for structural mechanics. This will be used in the structural mechanics recipes.

Checklist

Dependencies

Review Process

All PRs are reviewed by the PhysicsNeMo team before merging.

Depending on which files are changed, GitHub may automatically assign a maintainer for review.

We are also testing AI-based code review tools (e.g., Greptile), which may add automated comments with a confidence score.
This score reflects the AI’s assessment of merge readiness and is not a qualitative judgment of your work, nor is
it an indication that the PR will be accepted / rejected.

AI-generated feedback should be reviewed critically for usefulness.
You are not required to respond to every AI comment, but they are intended to help both authors and reviewers.
Please react to Greptile comments with 👍 or 👎 to provide feedback on their accuracy.

@mnabian mnabian self-assigned this Mar 11, 2026
@mnabian
Copy link
Collaborator Author

mnabian commented Mar 11, 2026

/blossom-ci

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR adds a von_mises_from_stress_tensor function to physicsnemo/metrics/cae/von_mises.py that computes the von Mises equivalent stress from a symmetric 3×3 (or batched N×3×3) stress tensor, supporting both PyTorch and NumPy inputs. The implementation is mathematically correct, gradient-friendly (via torch.clamp instead of raw sqrt), and is paired with a thorough test suite.

  • Correct formula — the distortional-energy (J₂) formula is properly implemented and verified for uniaxial, hydrostatic, and pure-shear reference cases.
  • Unused parameter_validate_stress_shape accepts an is_torch: bool argument that is never read inside the function; it is dead code and should be removed.
  • Validation order inconsistency — for the numpy path, np.asarray(stress, dtype=np.float64) is called before shape validation, which may perform an unnecessary allocation for invalid inputs; the torch path validates before computing anything.
  • No 2D plane-stress support — the function is limited to full 3×3 tensors; Voigt 6-vector or 2×2 plane-stress inputs are silently rejected with a ValueError. This is acceptable for the stated scope but worth noting in the docstring.
  • Changelog and tests are both present and appropriate.

Important Files Changed

Filename Overview
physicsnemo/metrics/cae/von_mises.py New module implementing von Mises stress from 3×3 or N×3×3 stress tensors for both PyTorch and NumPy inputs. The math is correct and the gradient path is preserved. Two minor style issues: is_torch parameter in _validate_stress_shape is unused dead code, and the numpy path converts to float64 before the shape validation runs (inconsistent with the torch path).
test/metrics/test_metrics_von_mises.py Comprehensive test suite covering uniaxial tension, hydrostatic stress, pure shear, batched inputs (both torch and numpy), invalid shapes, autograd support, and asymmetric shear symmetrization. Correctly uses the device fixture from the project-wide conftest.py.
CHANGELOG.md One-line addition to the Unreleased section documenting the new von Mises metric module.

Last reviewed commit: 42c8268

mnabian and others added 2 commits March 11, 2026 16:07
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@mnabian
Copy link
Collaborator Author

mnabian commented Mar 11, 2026

/blossom-ci

@mnabian
Copy link
Collaborator Author

mnabian commented Mar 11, 2026

/blossom-ci

@mnabian mnabian enabled auto-merge March 12, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant