Add Von Mises Metric for Structural Mechanics Applications#1491
Add Von Mises Metric for Structural Mechanics Applications#1491mnabian wants to merge 21 commits intoNVIDIA:mainfrom
Conversation
|
/blossom-ci |
Greptile SummaryThis PR adds a
Important Files Changed
Last reviewed commit: 42c8268 |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
/blossom-ci |
|
/blossom-ci |
peterdsharpe
left a comment
There was a problem hiding this comment.
A few changes requested, but overall this'll be a nice new feature when merged.
|
|
||
|
|
||
| def von_mises_from_stress_tensor( | ||
| stress: Union[torch.Tensor, np.ndarray], |
There was a problem hiding this comment.
In new code, we should always prefer modern | union types over Union. (Both here and throughout)
|
|
||
| def von_mises_from_stress_tensor( | ||
| stress: Union[torch.Tensor, np.ndarray], | ||
| ) -> Union[torch.Tensor, np.ndarray]: |
There was a problem hiding this comment.
These should all use jaxtyping to be compliant with repo rules. (Both here and throughout, on all type signatures for tensors)
| ) | ||
| return torch.sqrt(torch.clamp(vm_sq, min=0.0)) | ||
|
|
||
| _validate_stress_shape(np.shape(stress)) |
There was a problem hiding this comment.
For readability, and for better error handling, I'd recommend always prefixing switch-statement clauses with an:
elif isinstance(stress, np.ndarray):And then having an:
else:
raise TypeError("...")In other words, switch statements should always declare their switches.
| return np.sqrt(np.maximum(vm_sq, 0.0)) | ||
|
|
||
|
|
||
| def _validate_stress_shape(shape): |
There was a problem hiding this comment.
Missing type signature here
| sxz = 0.5 * (stress[..., 0, 2] + stress[..., 2, 0]) | ||
| vm_sq = 0.5 * ((sxx - syy) ** 2 + (syy - szz) ** 2 + (szz - sxx) ** 2) + 3.0 * ( | ||
| sxy**2 + syz**2 + sxz**2 | ||
| ) |
There was a problem hiding this comment.
This can be vectorized, if desired, using einsum. This may yield performance benefits if this is used downstream in performance-critical applications - up to you.
It's also possible to write this code in a way that's dimensionally-generic (e.g., works on 2x2 stress tensors for 2D problems), which could be nice down the road for reusability?
| >>> von_mises_from_stress_tensor(stress) | ||
| tensor(0.) | ||
| """ | ||
| if isinstance(stress, torch.Tensor): |
There was a problem hiding this comment.
It might be worth using the Array API standard to deduplicate the parallel numpy and torch code here? This is the official effort coordinated across NumPy/Torch/JAX/others to allow for multiple dispatch on arrays.
https://data-apis.org/array-api-compat/
I've used this in other projects - it's excellent and makes for very clean reusable implementations.
| `.to_dual_graph()` methods. These allow Mesh conversion to 0D point clouds, 1D | ||
| edge graphs, and 1D dual graphs, respectively, when connectivity information | ||
| is not needed. | ||
| - Adds von Mises stress (`physicsnemo.metrics.cae.von_mises`). |
There was a problem hiding this comment.
| - Adds von Mises stress (`physicsnemo.metrics.cae.von_mises`). | |
| - Adds von Mises stress (`physicsnemo.metrics.cae.von_mises`) as a CAE metric. |
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.