130 lines
5.2 KiB
Python
130 lines
5.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test named selection creation functionality
|
|
"""
|
|
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_named_selections():
|
|
"""Test named selection creation with real ANSYS"""
|
|
print("Testing Named Selection Creation...")
|
|
|
|
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")
|
|
|
|
# Step 1: Import geometry
|
|
print(f"\n1. Importing geometry from {blade_file}...")
|
|
success = session.import_geometry(str(blade_file))
|
|
if not success:
|
|
print("✗ Failed to import geometry")
|
|
return
|
|
print("✓ Geometry imported successfully")
|
|
|
|
# Step 2: Create named selections
|
|
print("\n2. Creating named selections...")
|
|
result = session.create_named_selections()
|
|
|
|
if result['success']:
|
|
print("✓ Named selections created successfully")
|
|
print(f" - Total selections: {result['total_selections']}")
|
|
print(f" - Created: {result['selections_created']}")
|
|
if result['selections_failed']:
|
|
print(f" - Failed: {result['selections_failed']}")
|
|
else:
|
|
print("✗ Named selection creation failed")
|
|
print(f" Error: {result.get('error', 'Unknown error')}")
|
|
return
|
|
|
|
# Step 3: Get named selection info
|
|
print("\n3. Getting named selection information...")
|
|
info_result = session.get_named_selections_info()
|
|
|
|
if info_result['success']:
|
|
print("✓ Named selection info retrieved")
|
|
print(f" - Total count: {info_result['total_count']}")
|
|
if 'script_result' in info_result:
|
|
print(f" - Script result: {info_result['script_result']}")
|
|
else:
|
|
print("✗ Failed to get named selection info")
|
|
print(f" Error: {info_result.get('error', 'Unknown error')}")
|
|
|
|
# Step 4: Validate named selections
|
|
print("\n4. Validating named selections...")
|
|
validation_result = session.validate_named_selections()
|
|
|
|
if validation_result['success']:
|
|
print("✓ Named selection validation completed")
|
|
if 'validation_result' in validation_result:
|
|
print(f" - Validation result: {validation_result['validation_result']}")
|
|
else:
|
|
print("✗ Named selection validation failed")
|
|
print(f" Error: {validation_result.get('error', 'Unknown error')}")
|
|
|
|
print("\n✓ Named selection test completed successfully")
|
|
|
|
except Exception as e:
|
|
print(f"✗ Named selection test failed: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
def test_simulation_mode():
|
|
"""Test named selection creation in simulation mode"""
|
|
print("\n" + "="*60)
|
|
print("Testing Named Selection Creation (Simulation Mode)...")
|
|
|
|
try:
|
|
with ANSYSSessionManager(simulation_mode=True) as session:
|
|
print("✓ Simulation session started")
|
|
|
|
# Import geometry (simulated)
|
|
success = session.import_geometry("resource/blade.step")
|
|
if success:
|
|
print("✓ Geometry imported (simulated)")
|
|
|
|
# Create named selections (simulated)
|
|
result = session.create_named_selections()
|
|
if result['success']:
|
|
print("✓ Named selections created (simulated)")
|
|
print(f" - Selections: {result['selections_created']}")
|
|
|
|
# Get info (simulated)
|
|
info_result = session.get_named_selections_info()
|
|
if info_result['success']:
|
|
print("✓ Named selection info retrieved (simulated)")
|
|
print(f" - Total: {info_result['total_count']}")
|
|
|
|
# Validate (simulated)
|
|
validation_result = session.validate_named_selections()
|
|
if validation_result['success']:
|
|
print("✓ Named selections validated (simulated)")
|
|
else:
|
|
print("✗ Simulated named selection creation failed")
|
|
else:
|
|
print("✗ Simulated geometry import failed")
|
|
|
|
print("✓ Simulation mode test completed")
|
|
|
|
except Exception as e:
|
|
print(f"✗ Simulation mode test failed: {str(e)}")
|
|
|
|
if __name__ == '__main__':
|
|
print("CAE Mesh Generator Named Selection Test")
|
|
print("=" * 70)
|
|
|
|
test_named_selections()
|
|
test_simulation_mode()
|
|
|
|
print("\n" + "="*70)
|
|
print("✓ All named selection tests completed!") |