160 lines
5.0 KiB
Python
160 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple mesh verification using return values
|
|
"""
|
|
|
|
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_verify():
|
|
"""Simple mesh verification using script return values"""
|
|
print("Simple Mesh Verification 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
|
|
|
|
# Set basic mesh size
|
|
print("\n2. Setting mesh size...")
|
|
mesh_size_script = '''
|
|
mesh = Model.Mesh
|
|
mesh.ElementSize = Quantity("5.0 [mm]")
|
|
"mesh_size_set"
|
|
'''
|
|
|
|
size_result = session_manager.mechanical.run_python_script(mesh_size_script)
|
|
print(f"Size setting result: '{size_result}'")
|
|
|
|
# Generate mesh and return a verification value
|
|
print("\n3. Generating mesh...")
|
|
mesh_gen_script = '''
|
|
mesh = Model.Mesh
|
|
mesh.GenerateMesh()
|
|
"mesh_generated"
|
|
'''
|
|
|
|
gen_result = session_manager.mechanical.run_python_script(mesh_gen_script)
|
|
print(f"Generation result: '{gen_result}'")
|
|
|
|
if gen_result == "mesh_generated":
|
|
print("✓ Mesh generation command executed successfully")
|
|
else:
|
|
print("⚠ Mesh generation command may have failed")
|
|
|
|
# Check if mesh has elements (return count)
|
|
print("\n4. Checking mesh elements...")
|
|
element_check_script = '''
|
|
try:
|
|
mesh = Model.Mesh
|
|
elements = mesh.Elements
|
|
len(elements)
|
|
except:
|
|
0
|
|
'''
|
|
|
|
element_result = session_manager.mechanical.run_python_script(element_check_script)
|
|
print(f"Element count result: '{element_result}'")
|
|
|
|
try:
|
|
element_count = int(element_result) if element_result else 0
|
|
if element_count > 0:
|
|
print(f"✓ Mesh has {element_count} elements - SUCCESS!")
|
|
else:
|
|
print("✗ No elements found - mesh generation failed")
|
|
except:
|
|
print("⚠ Could not parse element count")
|
|
|
|
# Check if mesh has nodes (return count)
|
|
print("\n5. Checking mesh nodes...")
|
|
node_check_script = '''
|
|
try:
|
|
mesh = Model.Mesh
|
|
nodes = mesh.Nodes
|
|
len(nodes)
|
|
except:
|
|
0
|
|
'''
|
|
|
|
node_result = session_manager.mechanical.run_python_script(node_check_script)
|
|
print(f"Node count result: '{node_result}'")
|
|
|
|
try:
|
|
node_count = int(node_result) if node_result else 0
|
|
if node_count > 0:
|
|
print(f"✓ Mesh has {node_count} nodes - SUCCESS!")
|
|
else:
|
|
print("✗ No nodes found - mesh generation failed")
|
|
except:
|
|
print("⚠ Could not parse node count")
|
|
|
|
# Final verification
|
|
print("\n6. Final mesh verification...")
|
|
final_check_script = '''
|
|
try:
|
|
mesh = Model.Mesh
|
|
elements = mesh.Elements
|
|
nodes = mesh.Nodes
|
|
element_count = len(elements)
|
|
node_count = len(nodes)
|
|
if element_count > 0 and node_count > 0:
|
|
"SUCCESS:" + str(element_count) + ":" + str(node_count)
|
|
else:
|
|
"FAILED:0:0"
|
|
except Exception as e:
|
|
"ERROR:" + str(e)
|
|
'''
|
|
|
|
final_result = session_manager.mechanical.run_python_script(final_check_script)
|
|
print(f"Final verification: '{final_result}'")
|
|
|
|
if final_result and final_result.startswith("SUCCESS:"):
|
|
parts = final_result.split(":")
|
|
if len(parts) >= 3:
|
|
print(f"🎉 MESH GENERATION SUCCESSFUL!")
|
|
print(f" Elements: {parts[1]}")
|
|
print(f" Nodes: {parts[2]}")
|
|
else:
|
|
print("✓ Mesh generation successful (details unclear)")
|
|
elif final_result and final_result.startswith("FAILED:"):
|
|
print("❌ MESH GENERATION FAILED - No elements or nodes found")
|
|
elif final_result and final_result.startswith("ERROR:"):
|
|
print(f"❌ MESH VERIFICATION ERROR: {final_result}")
|
|
else:
|
|
print("⚠ Mesh verification result unclear")
|
|
|
|
print("\n✓ Simple verification test completed")
|
|
|
|
except Exception as e:
|
|
print(f"\n✗ Simple verification test failed: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
finally:
|
|
if session_manager:
|
|
session_manager.close_session()
|
|
|
|
if __name__ == "__main__":
|
|
test_simple_verify() |