Phase 3 implements automated OP2 extraction code generation using pyNastran documentation research. This completes the zero-manual-coding pipeline for FEA optimization workflows. Key Features: - PyNastranResearchAgent for automated OP2 code generation - Documentation research via WebFetch integration - 3 core extraction patterns (displacement, stress, force) - Knowledge base architecture for learned patterns - Successfully tested on real OP2 files Phase 2.9 Integration: - Updated HookGenerator with lifecycle hook generation - Added POST_CALCULATION hook point to hooks.py - Created post_calculation/ plugin directory - Generated hooks integrate seamlessly with HookManager New Files: - optimization_engine/pynastran_research_agent.py (600+ lines) - optimization_engine/hook_generator.py (800+ lines) - optimization_engine/inline_code_generator.py - optimization_engine/plugins/post_calculation/ - tests/test_lifecycle_hook_integration.py - docs/SESSION_SUMMARY_PHASE_3.md - docs/SESSION_SUMMARY_PHASE_2_9.md - docs/SESSION_SUMMARY_PHASE_2_8.md - docs/HOOK_ARCHITECTURE.md Modified Files: - README.md - Added Phase 3 completion status - optimization_engine/plugins/hooks.py - Added POST_CALCULATION hook Test Results: - Phase 3 research agent: PASSED - Real OP2 extraction: PASSED (max_disp=0.362mm) - Lifecycle hook integration: PASSED Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
"""
|
|
Combine normalized stress (70%) and displacement (30%)
|
|
Auto-generated lifecycle hook by Atomizer Phase 2.9
|
|
|
|
Hook Point: post_calculation
|
|
Inputs: norm_stress, norm_disp
|
|
Outputs: weighted_objective
|
|
"""
|
|
|
|
import logging
|
|
from typing import Dict, Any, Optional
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def weighted_objective_hook(context: Dict[str, Any]) -> Optional[Dict[str, Any]]:
|
|
"""
|
|
Combine normalized stress (70%) and displacement (30%)
|
|
|
|
Args:
|
|
context: Hook context containing:
|
|
- trial_number: Current optimization trial
|
|
- results: Dictionary with extracted FEA results
|
|
- calculations: Dictionary with inline calculation results
|
|
|
|
Returns:
|
|
Dictionary with calculated values to add to context
|
|
"""
|
|
logger.info(f"Executing weighted_objective_hook for trial {context.get('trial_number', 'unknown')}")
|
|
|
|
# Extract inputs from context
|
|
results = context.get('results', {})
|
|
calculations = context.get('calculations', {})
|
|
|
|
norm_stress = calculations.get('norm_stress') or results.get('norm_stress')
|
|
if norm_stress is None:
|
|
logger.error(f"Required input 'norm_stress' not found in context")
|
|
raise ValueError(f"Missing required input: norm_stress")
|
|
|
|
norm_disp = calculations.get('norm_disp') or results.get('norm_disp')
|
|
if norm_disp is None:
|
|
logger.error(f"Required input 'norm_disp' not found in context")
|
|
raise ValueError(f"Missing required input: norm_disp")
|
|
|
|
# Calculate weighted objective
|
|
result = 0.7 * norm_stress + 0.3 * norm_disp
|
|
|
|
logger.info(f"Weighted objective calculated: {result:.6f}")
|
|
|
|
return {
|
|
'weighted_objective': result,
|
|
'weighted_objective': result
|
|
}
|
|
|
|
|
|
def register_hooks(hook_manager):
|
|
"""
|
|
Register this hook with the HookManager.
|
|
|
|
This function is called automatically when the plugin is loaded.
|
|
|
|
Args:
|
|
hook_manager: The HookManager instance
|
|
"""
|
|
hook_manager.register_hook(
|
|
hook_point='post_calculation',
|
|
function=weighted_objective_hook,
|
|
description="Combine normalized stress (70%) and displacement (30%)",
|
|
name="weighted_objective_hook",
|
|
priority=100,
|
|
enabled=True
|
|
)
|
|
logger.info(f"Registered weighted_objective_hook at post_calculation")
|