Files
Atomizer/TESTING_STRESS_FIX.md

88 lines
2.5 KiB
Markdown
Raw Normal View History

# Testing the Stress Extraction Fix
## Issue Fixed
Previously, stress extraction was returning **0.0 MPa** instead of the expected **~122.91 MPa**.
**Root Cause**: For solid elements (CHEXA, CTETRA, CPENTA), von Mises stress is at **index 9**, not the last column.
**Fix Applied**: Modified [op2_extractor_example.py](optimization_engine/result_extractors/op2_extractor_example.py#L106-L109) to check element type and use correct index.
## How to Test
### 1. Activate your test environment
```bash
conda activate test_env
```
### 2. Run the verification script
```bash
python examples/test_stress_fix.py
```
### Expected Output
```
============================================================
STRESS EXTRACTION FIX VERIFICATION
============================================================
--- Displacement (baseline test) ---
Max displacement: 0.315xxx mm
Node ID: xxx
OK Displacement extractor working
--- Stress (FIXED - should show ~122.91 MPa) ---
Max von Mises: 122.91 MPa
Element ID: 79
Element type: chexa
SUCCESS! Stress extraction fixed!
Expected: ~122.91 MPa
Got: 122.91 MPa
============================================================
```
## Alternative: Test All Extractors
```bash
python optimization_engine/result_extractors/extractors.py examples/bracket/bracket_sim1-solution_1.op2
```
## If Successful, Commit the Fix
```bash
git add optimization_engine/result_extractors/op2_extractor_example.py
git commit -m "fix: Correct von Mises stress extraction for solid elements (CHEXA)
- Use index 9 for solid elements (CHEXA, CTETRA, CPENTA)
- Keep last column for shell elements (CQUAD4, CTRIA3)
- Fixes stress extraction returning 0.0 instead of actual values (122.91 MPa)"
git push origin main
```
## Technical Details
### pyNastran OP2 Data Structure for Solid Elements
- Shape: `[itime, nnodes, 10]`
- The 10 values are:
```
[oxx, oyy, ozz, txy, tyz, txz, o1, o2, o3, von_mises]
0 1 2 3 4 5 6 7 8 9
```
- **Von Mises is at index 9**
### Code Change
```python
# BEFORE (WRONG):
stresses = stress_data.data[0, :, -1] # Last column - WRONG for CHEXA!
# AFTER (CORRECT):
if table_name in ['chexa_stress', 'ctetra_stress', 'cpenta_stress']:
# Solid elements: von Mises at index 9
stresses = stress_data.data[0, :, 9]
else:
# Shell elements: von Mises at last column
stresses = stress_data.data[0, :, -1]
```
## Files Modified
- [optimization_engine/result_extractors/op2_extractor_example.py](optimization_engine/result_extractors/op2_extractor_example.py) - Lines 103-112