AnsysLink/test/test_simple_mesh.py

155 lines
4.6 KiB
Python

#!/usr/bin/env python3
"""
Simple mesh generation test to debug the issue
"""
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_simple_mesh():
"""Test simple mesh generation step by step"""
print("Simple Mesh Generation Debug Test")
print("=" * 50)
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
# Test very basic mesh generation
print("\n2. Testing basic mesh generation...")
basic_mesh_script = '''
# Very basic mesh generation test
try:
print("=== Basic Mesh Generation Test ===")
# Get mesh object
mesh = Model.Mesh
print("Mesh object obtained: " + str(mesh is not None))
# Check geometry
geometry = Model.Geometry
bodies = geometry.GetChildren(Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body, True)
print("Number of bodies: " + str(len(bodies)))
if len(bodies) > 0:
print("Body 0 name: " + str(bodies[0].Name))
# Set very basic mesh settings
try:
mesh.ElementSize = Quantity("5.0 [mm]")
print("Element size set to 5.0 mm")
except Exception as e:
print("Error setting element size: " + str(e))
# Try to generate mesh
try:
print("Attempting mesh generation...")
mesh.GenerateMesh()
print("GenerateMesh() completed")
# Check results
try:
element_count = mesh.ElementCount if hasattr(mesh, 'ElementCount') else 0
node_count = mesh.NodeCount if hasattr(mesh, 'NodeCount') else 0
print("Elements: " + str(element_count))
print("Nodes: " + str(node_count))
if element_count > 0:
print("SUCCESS: Mesh generated with elements!")
else:
print("WARNING: Mesh generated but no elements found")
except Exception as stats_error:
print("Error getting mesh statistics: " + str(stats_error))
except Exception as gen_error:
print("Mesh generation error: " + str(gen_error))
# Try to get more error details
try:
print("Checking for mesh generation messages...")
# Additional error checking could go here
except:
pass
except Exception as e:
print("Script error: " + str(e))
import traceback
traceback.print_exc()
'''
result = session_manager.mechanical.run_python_script(basic_mesh_script)
print(f"\nScript output:\n{result}")
# Test mesh statistics separately
print("\n3. Testing mesh statistics...")
stats_script = '''
try:
mesh = Model.Mesh
# Try different ways to get mesh info
print("=== Mesh Statistics ===")
try:
element_count = mesh.ElementCount
print("ElementCount: " + str(element_count))
except Exception as e:
print("Error getting ElementCount: " + str(e))
try:
node_count = mesh.NodeCount
print("NodeCount: " + str(node_count))
except Exception as e:
print("Error getting NodeCount: " + str(e))
# Check mesh state
try:
print("Mesh object type: " + str(type(mesh)))
print("Mesh attributes: " + str(dir(mesh)[:10])) # First 10 attributes
except Exception as e:
print("Error checking mesh attributes: " + str(e))
except Exception as e:
print("Statistics script error: " + str(e))
'''
stats_result = session_manager.mechanical.run_python_script(stats_script)
print(f"\nStats output:\n{stats_result}")
print("\n✓ Simple mesh test completed")
except Exception as e:
print(f"\n✗ Simple mesh test failed: {str(e)}")
import traceback
traceback.print_exc()
finally:
if session_manager:
session_manager.close_session()
if __name__ == "__main__":
test_simple_mesh()