136 lines
5.0 KiB
Python
136 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test complete ANSYS workflow with real PyMechanical
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
import json
|
|
|
|
# Add project root to path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from backend.pymechanical.session_manager import ANSYSSessionManager
|
|
|
|
def test_complete_workflow():
|
|
"""Test complete workflow from session start to geometry import"""
|
|
print("Testing Complete ANSYS Workflow...")
|
|
|
|
blade_file = Path("resource/blade.step")
|
|
if not blade_file.exists():
|
|
print("✗ Test file resource/blade.step not found")
|
|
return
|
|
|
|
try:
|
|
# Test complete workflow
|
|
print("\n=== Starting Complete Workflow Test ===")
|
|
|
|
session_manager = ANSYSSessionManager(simulation_mode=False)
|
|
|
|
# Step 1: Start session
|
|
print("\n1. Starting ANSYS session...")
|
|
success = session_manager.start_session()
|
|
if not success:
|
|
print("✗ Failed to start ANSYS session")
|
|
return
|
|
print("✓ ANSYS session started successfully")
|
|
|
|
# Step 2: Get session info
|
|
print("\n2. Getting session information...")
|
|
session_info = session_manager.get_session_info()
|
|
print(f"✓ Session active: {session_info['is_active']}")
|
|
print(f"✓ Session time: {session_info['session_time']:.2f}s")
|
|
|
|
# Step 3: Import geometry
|
|
print(f"\n3. Importing geometry from {blade_file}...")
|
|
success = session_manager.import_geometry(str(blade_file))
|
|
if not success:
|
|
print("✗ Failed to import geometry")
|
|
return
|
|
print("✓ Geometry imported successfully")
|
|
|
|
# Step 4: Validate geometry
|
|
print("\n4. Validating imported geometry...")
|
|
validation_result = session_manager.validate_geometry()
|
|
if validation_result['valid']:
|
|
print("✓ Geometry validation successful")
|
|
print(f" - Bodies: {validation_result['body_count']}")
|
|
print(f" - Surfaces: {validation_result['surface_count']}")
|
|
print(f" - Volumes: {validation_result['volume_count']}")
|
|
print(f" - Import method: {validation_result['import_method']}")
|
|
else:
|
|
print("✗ Geometry validation failed")
|
|
print(f" Error: {validation_result.get('error', 'Unknown error')}")
|
|
|
|
# Step 5: Get final session info
|
|
print("\n5. Getting final session information...")
|
|
final_session_info = session_manager.get_session_info()
|
|
print(f"✓ Has geometry: {final_session_info['has_geometry']}")
|
|
if final_session_info['geometry_info']:
|
|
print(f"✓ Geometry file: {final_session_info['geometry_info']['file_path']}")
|
|
print(f"✓ Import method: {final_session_info['geometry_info']['import_method']}")
|
|
|
|
# Step 6: Close session
|
|
print("\n6. Closing ANSYS session...")
|
|
success = session_manager.close_session()
|
|
if success:
|
|
print("✓ ANSYS session closed successfully")
|
|
else:
|
|
print("✗ Failed to close ANSYS session")
|
|
|
|
# Step 7: Cleanup
|
|
print("\n7. Cleaning up temporary files...")
|
|
success = session_manager.cleanup_temp_files()
|
|
if success:
|
|
print("✓ Cleanup completed successfully")
|
|
else:
|
|
print("✗ Cleanup failed")
|
|
|
|
print("\n=== Complete Workflow Test Completed Successfully! ===")
|
|
|
|
except Exception as e:
|
|
print(f"✗ Workflow test failed: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
def test_context_manager_workflow():
|
|
"""Test workflow using context manager"""
|
|
print("\n" + "="*60)
|
|
print("Testing Context Manager Workflow...")
|
|
|
|
blade_file = Path("resource/blade.step")
|
|
if not blade_file.exists():
|
|
print("✗ Test file resource/blade.step not found")
|
|
return
|
|
|
|
try:
|
|
with ANSYSSessionManager(simulation_mode=False) as session:
|
|
print("✓ ANSYS session started via context manager")
|
|
|
|
# Import and validate geometry
|
|
success = session.import_geometry(str(blade_file))
|
|
if success:
|
|
print("✓ Geometry imported successfully")
|
|
|
|
validation_result = session.validate_geometry()
|
|
if validation_result['valid']:
|
|
print("✓ Geometry validated successfully")
|
|
print(f" - Bodies: {validation_result['body_count']}")
|
|
else:
|
|
print("✗ Geometry validation failed")
|
|
else:
|
|
print("✗ Geometry import failed")
|
|
|
|
print("✓ Context manager workflow completed (session auto-closed)")
|
|
|
|
except Exception as e:
|
|
print(f"✗ Context manager workflow failed: {str(e)}")
|
|
|
|
if __name__ == '__main__':
|
|
print("CAE Mesh Generator Complete Workflow Test")
|
|
print("=" * 70)
|
|
|
|
test_complete_workflow()
|
|
test_context_manager_workflow()
|
|
|
|
print("\n" + "="*70)
|
|
print("✓ All workflow tests completed!") |