fix: Complete stress extraction fix for NX Nastran OP2 files
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
This commit is contained in:
56
examples/test_stress_direct.py
Normal file
56
examples/test_stress_direct.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""
|
||||
Direct test of stress extraction without using cached imports.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
# Force reload
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
# Import directly from the file
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"op2_extractor",
|
||||
project_root / "optimization_engine/result_extractors/op2_extractor_example.py"
|
||||
)
|
||||
op2_extractor = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(op2_extractor)
|
||||
|
||||
if __name__ == "__main__":
|
||||
op2_path = project_root / "examples/bracket/bracket_sim1-solution_1.op2"
|
||||
|
||||
print("="*60)
|
||||
print("DIRECT STRESS EXTRACTION TEST")
|
||||
print("="*60)
|
||||
print(f"OP2 file: {op2_path}")
|
||||
print()
|
||||
|
||||
# Test stress extraction
|
||||
print("--- Testing extract_max_stress() ---")
|
||||
try:
|
||||
result = op2_extractor.extract_max_stress(op2_path, stress_type='von_mises')
|
||||
print()
|
||||
print("RESULT:")
|
||||
for key, value in result.items():
|
||||
print(f" {key}: {value}")
|
||||
|
||||
if result['max_stress'] > 100.0:
|
||||
print()
|
||||
print("SUCCESS! Stress extraction working!")
|
||||
print(f"Got: {result['max_stress']:.2f} MPa")
|
||||
elif result['max_stress'] == 0.0:
|
||||
print()
|
||||
print("FAIL: Still returning 0.0")
|
||||
else:
|
||||
print()
|
||||
print(f"Got unexpected value: {result['max_stress']:.2f} MPa")
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
print()
|
||||
print("="*60)
|
||||
Reference in New Issue
Block a user