THREE critical fixes applied: 1. API Access Pattern - Support dotted attribute names (e.g., 'stress.chexa_stress') - Compatible with newer pyNastran versions (NX 2412.5) - Fallback to older API formats for compatibility 2. Correct Von Mises Index - Solid elements (CHEXA, CTETRA, CPENTA): index 9 - Shell elements (CQUAD4, CTRIA3): last column - Data structure: [oxx, oyy, ozz, txy, tyz, txz, o1, o2, o3, von_mises] 3. Units Conversion (CRITICAL) - NX Nastran outputs stress in kPa, not MPa - Apply conversion: kPa / 1000 = MPa - Example: 113094.73 kPa -> 113.09 MPa Test Results: - Before: 0.00 MPa (FAIL) - After: 113.09 MPa at element 83 (SUCCESS) Files modified: - optimization_engine/result_extractors/op2_extractor_example.py Test files added: - examples/test_stress_direct.py - examples/test_stress_fix.py - examples/debug_op2_stress.py - STRESS_EXTRACTION_FIXED.md - TESTING_STRESS_FIX.md
2.5 KiB
2.5 KiB
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 to check element type and use correct index.
How to Test
1. Activate your test environment
conda activate test_env
2. Run the verification script
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
python optimization_engine/result_extractors/extractors.py examples/bracket/bracket_sim1-solution_1.op2
If Successful, Commit the Fix
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
# 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 - Lines 103-112