160 lines
5.6 KiB
Python
160 lines
5.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test real ANSYS PyMechanical integration
|
|
"""
|
|
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_real_ansys():
|
|
"""Test real ANSYS PyMechanical integration"""
|
|
print("Testing Real ANSYS PyMechanical Integration...")
|
|
print("This test requires ANSYS Mechanical to be installed and licensed.")
|
|
|
|
# Test with real ANSYS (simulation_mode=False)
|
|
print("\n1. Testing real ANSYS session manager initialization...")
|
|
try:
|
|
session_manager = ANSYSSessionManager(simulation_mode=False)
|
|
print(f"✓ Real ANSYS session manager initialized")
|
|
|
|
# Test session startup
|
|
print("\n2. Testing real ANSYS session startup...")
|
|
success = session_manager.start_session(batch_mode=True)
|
|
|
|
if success:
|
|
print("✓ Real ANSYS session started successfully")
|
|
|
|
# Get session info
|
|
session_info = session_manager.get_session_info()
|
|
print(f"✓ Session info: {json.dumps(session_info, indent=2, default=str)}")
|
|
|
|
# Test geometry import
|
|
blade_file = Path("resource/blade.step")
|
|
if blade_file.exists():
|
|
print(f"\n3. Testing real geometry import with {blade_file}...")
|
|
success = session_manager.import_geometry(str(blade_file))
|
|
|
|
if success:
|
|
print("✓ Real geometry import successful")
|
|
|
|
# Validate geometry
|
|
print("\n4. Testing real geometry validation...")
|
|
validation_result = session_manager.validate_geometry()
|
|
print(f"✓ Validation result: {json.dumps(validation_result, indent=2, default=str)}")
|
|
|
|
else:
|
|
print("✗ Real geometry import failed")
|
|
else:
|
|
print("✗ Test file resource/blade.step not found")
|
|
|
|
# Close session
|
|
print("\n5. Testing real session close...")
|
|
success = session_manager.close_session()
|
|
print(f"✓ Session close: {'Success' if success else 'Failed'}")
|
|
|
|
else:
|
|
print("✗ Real ANSYS session startup failed")
|
|
print("This might be due to:")
|
|
print("- ANSYS Mechanical not installed")
|
|
print("- No valid ANSYS license")
|
|
print("- PyMechanical package not available")
|
|
print("- ANSYS environment not properly configured")
|
|
|
|
except Exception as e:
|
|
print(f"✗ Real ANSYS test failed: {str(e)}")
|
|
print("Falling back to simulation mode for development...")
|
|
|
|
# Fallback to simulation mode
|
|
print("\nFallback: Testing with simulation mode...")
|
|
session_manager = ANSYSSessionManager(simulation_mode=True)
|
|
|
|
success = session_manager.start_session()
|
|
if success:
|
|
print("✓ Simulation mode working as fallback")
|
|
session_manager.close_session()
|
|
|
|
def test_pymechanical_import():
|
|
"""Test PyMechanical package availability"""
|
|
print("\n" + "="*60)
|
|
print("Testing PyMechanical Package Availability...")
|
|
|
|
try:
|
|
import ansys.mechanical.core as pymechanical
|
|
print("✓ PyMechanical package is available")
|
|
|
|
# Try to get version info
|
|
try:
|
|
print(f"✓ PyMechanical version: {pymechanical.__version__}")
|
|
except:
|
|
print("✓ PyMechanical imported but version info not available")
|
|
|
|
return True
|
|
|
|
except ImportError as e:
|
|
print(f"✗ PyMechanical package not available: {str(e)}")
|
|
print("To install PyMechanical, run:")
|
|
print("pip install ansys-mechanical-core")
|
|
return False
|
|
|
|
def test_ansys_environment():
|
|
"""Test ANSYS environment configuration"""
|
|
print("\n" + "="*60)
|
|
print("Testing ANSYS Environment Configuration...")
|
|
|
|
import os
|
|
|
|
# Check common ANSYS environment variables
|
|
ansys_vars = [
|
|
'ANSYS_ROOT',
|
|
'AWP_ROOT242', # ANSYS 2024 R2
|
|
'AWP_ROOT241', # ANSYS 2024 R1
|
|
'AWP_ROOT232', # ANSYS 2023 R2
|
|
'ANSYSLMD_LICENSE_FILE'
|
|
]
|
|
|
|
found_vars = []
|
|
for var in ansys_vars:
|
|
value = os.environ.get(var)
|
|
if value:
|
|
found_vars.append((var, value))
|
|
print(f"✓ {var}: {value}")
|
|
|
|
if found_vars:
|
|
print(f"✓ Found {len(found_vars)} ANSYS environment variables")
|
|
else:
|
|
print("✗ No ANSYS environment variables found")
|
|
print("Make sure ANSYS is properly installed and environment is configured")
|
|
|
|
return len(found_vars) > 0
|
|
|
|
if __name__ == '__main__':
|
|
print("CAE Mesh Generator Real ANSYS Integration Test")
|
|
print("=" * 70)
|
|
|
|
# Test PyMechanical availability
|
|
pymech_available = test_pymechanical_import()
|
|
|
|
# Test ANSYS environment
|
|
env_configured = test_ansys_environment()
|
|
|
|
# Test real ANSYS integration
|
|
if pymech_available and env_configured:
|
|
test_real_ansys()
|
|
else:
|
|
print("\n" + "="*60)
|
|
print("Skipping real ANSYS tests due to missing requirements")
|
|
print("Running simulation mode test instead...")
|
|
|
|
session_manager = ANSYSSessionManager(simulation_mode=True)
|
|
success = session_manager.start_session()
|
|
if success:
|
|
print("✓ Simulation mode is working")
|
|
session_manager.close_session()
|
|
|
|
print("\n" + "="*70)
|
|
print("✓ Real ANSYS integration test completed!") |