Files
Atomizer/examples/test_stress_fix.py

66 lines
2.1 KiB
Python
Raw Normal View History

"""
Quick test to verify stress extraction fix for CHEXA elements.
Run this in test_env:
conda activate test_env
python examples/test_stress_fix.py
"""
from pathlib import Path
import sys
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
from optimization_engine.result_extractors.extractors import stress_extractor, displacement_extractor
if __name__ == "__main__":
op2_path = project_root / "examples/bracket/bracket_sim1-solution_1.op2"
print("="*60)
print("STRESS EXTRACTION FIX VERIFICATION")
print("="*60)
print(f"OP2 file: {op2_path}")
print()
# Test displacement (we know this works - 0.315 mm)
print("--- Displacement (baseline test) ---")
try:
disp_result = displacement_extractor(op2_path)
print(f"Max displacement: {disp_result['max_displacement']:.6f} mm")
print(f"Node ID: {disp_result['max_node_id']}")
print("OK Displacement extractor working")
except Exception as e:
print(f"ERROR: {e}")
print()
# Test stress (should now return 122.91 MPa, not 0.0)
print("--- Stress (FIXED - should show ~122.91 MPa) ---")
try:
stress_result = stress_extractor(op2_path)
print(f"Max von Mises: {stress_result['max_von_mises']:.2f} MPa")
print(f"Element ID: {stress_result['element_id']}")
print(f"Element type: {stress_result['element_type']}")
# Verify fix worked
if stress_result['max_von_mises'] > 100.0:
print()
print("SUCCESS! Stress extraction fixed!")
print(f"Expected: ~122.91 MPa")
print(f"Got: {stress_result['max_von_mises']:.2f} MPa")
elif stress_result['max_von_mises'] == 0.0:
print()
print("FAIL: Still returning 0.0 - fix not working")
else:
print()
print(f"WARNING: Got {stress_result['max_von_mises']:.2f} MPa - verify if correct")
except Exception as e:
print(f"ERROR: {e}")
import traceback
traceback.print_exc()
print()
print("="*60)