#!/usr/bin/env python3 """ Test script for integrated mesh controls in session manager This script tests the integrated mesh control functionality through the session manager. """ import sys import os sys.path.append(os.path.dirname(os.path.abspath(__file__))) from backend.pymechanical.session_manager import ANSYSSessionManager import logging # Configure logging logging.basicConfig( level=logging.INFO, format='%(levelname)s:%(name)s:%(message)s' ) def test_integrated_mesh_controls(): """Test integrated mesh controls through session manager""" print("CAE Mesh Generator Integrated Mesh Controls Test") print("=" * 70) print("Testing Integrated Mesh Controls...") session_manager = None try: # Initialize ANSYS session session_manager = ANSYSSessionManager(simulation_mode=False) session_manager.start_session() print("✓ ANSYS session started") # Import geometry geometry_file = "resource\\blade.step" print(f"1. Importing geometry from {geometry_file}...") if session_manager.import_geometry(geometry_file): print("✓ Geometry imported successfully") else: print("✗ Geometry import failed") return # Create named selections print("\n2. Creating named selections...") selection_result = session_manager.create_named_selections() if selection_result['success']: named_selections = selection_result['selections_created'] print(f"✓ Named selections created: {named_selections}") else: print(f"✗ Named selection creation failed: {selection_result.get('error', 'Unknown error')}") return # Apply mesh controls print("\n3. Applying mesh controls...") mesh_result = session_manager.apply_mesh_controls(named_selections) if mesh_result['success']: print("✓ Mesh controls applied successfully") print(f" - Controls applied: {mesh_result['controls_applied']}") if 'mesh_parameters' in mesh_result: params = mesh_result['mesh_parameters'] print(f" - Global element size: {params.get('global_element_size', 'N/A')} mm") print(f" - Inflation layers: {params.get('inflation_layers', 'N/A')}") else: print("⚠ Some mesh controls failed") print(f" - Successful: {mesh_result.get('controls_applied', [])}") print(f" - Failed: {mesh_result.get('controls_failed', [])}") # Get mesh control summary print("\n4. Getting mesh control summary...") summary = session_manager.get_mesh_control_summary() if summary.get('success', True): print("✓ Mesh control summary retrieved") if 'mesh_parameters' in summary: params = summary['mesh_parameters'] print(f" - Global size: {params.get('global_element_size', 'N/A')} mm") print(f" - Curvature angle: {params.get('curvature_angle', 'N/A')}°") print(f" - Inflation layers: {params.get('inflation_layers', 'N/A')}") print(f" - Growth rate: {params.get('growth_rate', 'N/A')}") else: print(f"✗ Failed to get mesh control summary: {summary.get('error', 'Unknown error')}") print("\n✓ Integrated mesh controls test completed successfully") except Exception as e: print(f"\n✗ Integrated mesh controls test failed: {str(e)}") import traceback traceback.print_exc() finally: if session_manager: session_manager.close_session() def test_simulation_mode(): """Test integrated mesh controls in simulation mode""" print("\n" + "=" * 60) print("Testing Integrated Mesh Controls (Simulation Mode)...") session_manager = None try: # Initialize simulation session session_manager = ANSYSSessionManager(simulation_mode=True) session_manager.start_session() print("✓ Simulation session started") # Import geometry (simulated) session_manager.import_geometry("resource/blade.step") print("✓ Geometry imported (simulated)") # Create named selections (simulated) selection_result = session_manager.create_named_selections() print(f"✓ Named selections created (simulated): {selection_result['selections_created']}") # Apply mesh controls (simulated) mesh_result = session_manager.apply_mesh_controls() print("✓ Mesh controls applied (simulated)") print(f" - Controls: {mesh_result['controls_applied']}") # Get summary (simulated) summary = session_manager.get_mesh_control_summary() print("✓ Mesh control summary retrieved (simulated)") print("✓ Simulation mode test completed") except Exception as e: print(f"✗ Simulation test failed: {str(e)}") finally: if session_manager: session_manager.close_session() if __name__ == "__main__": test_integrated_mesh_controls() test_simulation_mode() print("\n" + "=" * 70) print("✓ All integrated mesh control tests completed!")