AnsysLink/CLAUDE.md

6.8 KiB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

This is AnsysLink - a CAE simulation mesh generation assistant specifically designed for turbofan engine blade processing. It's a Flask-based web application that integrates with ANSYS Mechanical through PyMechanical to automate blade model mesh generation and visualization.

Architecture

Core Components

  • Flask Web App (app.py, start.py): Main application entry point with error handling and static file serving
  • Backend API (backend/api/routes.py): RESTful API endpoints for file upload, mesh operations, and system state management
  • PyMechanical Integration (backend/pymechanical/): ANSYS Mechanical session management and automation
    • session_manager.py: Main session orchestrator with simulation mode fallback
    • mesh_controller.py: Mesh generation controls and parameter optimization
    • mesh_generator.py: Core mesh generation logic
    • named_selection_manager.py: Blade geometry feature selection
  • State Management (backend/utils/state_manager.py): Application state tracking
  • File Processing (backend/utils/file_validator.py): STEP file validation
  • Error Handling (backend/utils/error_handler.py): Centralized error management with detailed logging
  • Resource Management (backend/utils/resource_manager.py): Memory and file resource cleanup
  • Data Models (backend/models/data_models.py): Data structures for files and processing status

Key Features

  • Dual Mode Operation: Supports both real ANSYS integration and simulation mode for development
  • STEP File Processing: Handles .step and .stp CAD files up to 100MB
  • Automated Mesh Generation: Blade-specific mesh controls with curvature-based refinement
  • Named Selections: Automatically creates blade geometry selections (leading edge, trailing edge, root, surfaces)
  • Quality Control: Mesh quality validation with configurable thresholds

Development Commands

Running the Application

# Quick start with environment check (recommended)
python start.py

# Direct Flask app start
python app.py

# Using scripts (alternative methods)
python scripts/run_app.py
python scripts/demo_launcher.py

Testing

# Run all tests
pytest

# Run specific test files
pytest test/test_api_basic.py
pytest test/test_complete_workflow.py
pytest test/test_mesh_generation.py

# Run comprehensive test suite
python test/test_suite.py

# Run integration tests
python test/test_integration.py

# Run with coverage
pytest --cov=backend --cov-report=html --cov-report=term -vv

Dependencies

# Install requirements
pip install -r requirements.txt

# Core dependencies:
# - Flask==2.3.3 (web framework)
# - ansys-mechanical-core (PyMechanical integration)
# - pytest==7.4.2 (testing)
# - pytest-flask==1.2.0 (Flask testing utilities)

Configuration

ANSYS Setup (config.py)

  • ANSYS version: 241 (2024 R1)
  • Installation path: C:\Program Files\ANSYS Inc\v241
  • Batch mode enabled with 5-minute timeout
  • Executable: AnsysWBU.exe with -DSApplet -nosplash -b switches

File Upload Settings

  • Allowed formats: .step, .stp
  • Maximum file size: 100MB
  • Upload directory: frontend/uploads/
  • Temporary files: temp/
  • Results output: results/

Mesh Quality Thresholds

  • Minimum element quality: 0.2
  • Maximum aspect ratio: 20
  • Maximum skewness: 0.8
  • Minimum orthogonal quality: 0.15

API Endpoints

Key endpoints for development and testing:

  • POST /api/upload - File upload and validation
  • GET /api/files/current - Current file information
  • GET /api/mesh/status - Processing status
  • GET /api/mesh/result - Mesh generation results
  • GET /api/mesh/ready - System readiness check
  • GET /api/system/state - Complete system state
  • POST /api/system/reset - Reset system state
  • GET /api/health - Health check

Development Workflow

Project Structure

AnsysLink/
├── app.py                 # Main Flask application
├── start.py              # Quick start script with environment checks
├── config.py             # Configuration settings
├── requirements.txt      # Python dependencies
├── backend/             # Backend components
│   ├── api/            # API routes and endpoints
│   ├── models/         # Data models and structures
│   ├── utils/          # Utility functions and helpers
│   └── pymechanical/   # ANSYS Mechanical integration
├── frontend/           # Frontend assets
│   ├── index.html     # Main web interface
│   ├── static/        # CSS, JS, and other static files
│   └── uploads/       # File upload directory
├── scripts/            # Utility scripts
├── test/              # Comprehensive test suite
├── temp/              # Temporary processing files
└── results/           # Generated mesh results

Important Development Notes

Simulation Mode vs Real ANSYS

The application automatically detects if ANSYS Mechanical is available:

  • Real mode: Uses actual PyMechanical integration when ANSYS is installed
  • Simulation mode: Provides mock responses for development without ANSYS

Resource Management

  • The app includes automatic cleanup of temporary files via resource_manager
  • Long-running mesh operations are handled with progress tracking
  • Error handling includes detailed logging and user-friendly messages

Testing Strategy

The test suite includes multiple categories:

  • Unit tests: Individual component testing (test_api_basic.py, test_state_management.py)
  • Integration tests: Full workflow testing (test_complete_workflow.py, test_integration.py)
  • ANSYS-specific tests: Real ANSYS integration when available (test_real_ansys.py)
  • Comprehensive suite: All tests combined (test_suite.py)

Development Notes

Simulation Mode

The application includes a comprehensive simulation mode that doesn't require ANSYS installation. This is automatically enabled when PyMechanical is unavailable and allows full development and testing of the workflow.

Error Handling

  • File upload validation with detailed error messages
  • ANSYS session management with fallback to simulation mode
  • Comprehensive logging throughout the application via error_handler.py
  • Progress tracking for long-running operations

PyMechanical Integration

The application uses PyMechanical scripts executed within ANSYS Mechanical sessions. Scripts are dynamically generated and executed for:

  • Geometry import and validation
  • Named selection creation
  • Mesh control application
  • Mesh generation and statistics

When working with this codebase, be aware that many operations can fall back to simulation mode if ANSYS is not available, making development possible without a full ANSYS installation.