134 lines
4.3 KiB
Python
134 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Direct mesh generation test using the working pattern from our successful scripts
|
|
"""
|
|
|
|
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_direct_mesh_generation():
|
|
"""Test mesh generation using the same pattern as successful geometry import"""
|
|
print("Direct Mesh Generation 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 first
|
|
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
|
|
|
|
# Apply basic mesh controls first (like we do successfully)
|
|
print("\n2. Applying basic mesh controls...")
|
|
|
|
# Use the same pattern as our successful named selection creation
|
|
mesh_setup_script = '''
|
|
# Basic mesh setup using same pattern as successful scripts
|
|
mesh = Model.Mesh
|
|
mesh.ElementSize = Quantity("3.0 [mm]")
|
|
body_count = len(Model.Geometry.GetChildren(Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body, True))
|
|
print("Mesh setup completed for " + str(body_count) + " bodies")
|
|
'''
|
|
|
|
setup_result = session_manager.mechanical.run_python_script(mesh_setup_script)
|
|
print(f"Mesh setup result: '{setup_result}'")
|
|
|
|
# Now try mesh generation using the same pattern
|
|
print("\n3. Generating mesh...")
|
|
|
|
mesh_generation_script = '''
|
|
# Generate mesh using same pattern as successful scripts
|
|
mesh = Model.Mesh
|
|
print("Starting mesh generation...")
|
|
mesh.GenerateMesh()
|
|
print("Mesh generation completed")
|
|
|
|
# Try to get mesh statistics safely
|
|
try:
|
|
elements = mesh.Elements
|
|
nodes = mesh.Nodes
|
|
print("Elements object: " + str(type(elements)))
|
|
print("Nodes object: " + str(type(nodes)))
|
|
|
|
# Try different ways to get count
|
|
try:
|
|
element_count = len(elements)
|
|
print("Element count (len): " + str(element_count))
|
|
except:
|
|
try:
|
|
element_count = elements.Count
|
|
print("Element count (Count): " + str(element_count))
|
|
except:
|
|
element_count = "unknown"
|
|
print("Element count: unknown")
|
|
|
|
try:
|
|
node_count = len(nodes)
|
|
print("Node count (len): " + str(node_count))
|
|
except:
|
|
try:
|
|
node_count = nodes.Count
|
|
print("Node count (Count): " + str(node_count))
|
|
except:
|
|
node_count = "unknown"
|
|
print("Node count: unknown")
|
|
|
|
print("Mesh generation successful")
|
|
|
|
except Exception as e:
|
|
print("Error getting mesh statistics: " + str(e))
|
|
print("But mesh generation may have succeeded")
|
|
'''
|
|
|
|
generation_result = session_manager.mechanical.run_python_script(mesh_generation_script)
|
|
print(f"Mesh generation result: '{generation_result}'")
|
|
|
|
# Test if we can get mesh info
|
|
print("\n4. Getting mesh information...")
|
|
|
|
mesh_info_script = '''
|
|
# Get mesh information
|
|
mesh = Model.Mesh
|
|
try:
|
|
element_count = len(mesh.Elements)
|
|
node_count = len(mesh.Nodes)
|
|
print("Current mesh: " + str(element_count) + " elements, " + str(node_count) + " nodes")
|
|
except Exception as e:
|
|
print("Error getting mesh info: " + str(e))
|
|
'''
|
|
|
|
info_result = session_manager.mechanical.run_python_script(mesh_info_script)
|
|
print(f"Mesh info result: '{info_result}'")
|
|
|
|
print("\n✓ Direct mesh test completed")
|
|
|
|
except Exception as e:
|
|
print(f"\n✗ Direct mesh test failed: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
finally:
|
|
if session_manager:
|
|
session_manager.close_session()
|
|
|
|
if __name__ == "__main__":
|
|
test_direct_mesh_generation() |