Files
Atomizer/generated_hooks/hook_custom_safety_factor.py
Anto01 38abb0d8d2 feat: Complete Phase 3 - pyNastran Documentation Integration
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>
2025-11-16 16:33:48 -05:00

75 lines
1.7 KiB
Python

"""
Custom Formula Hook
Auto-generated by Atomizer Phase 2.9
Calculate safety factor
Formula: safety_factor = yield_strength / max_stress
Inputs: max_stress, yield_strength
"""
import sys
import json
from pathlib import Path
def calculate_safety_factor(max_stress, yield_strength):
"""
Calculate custom metric using formula.
Args:
max_stress: float
yield_strength: float
Returns:
float: safety_factor
"""
safety_factor = yield_strength / max_stress
return safety_factor
def main():
"""Main entry point for hook execution."""
if len(sys.argv) < 2:
print("Usage: python {} <input_file.json>".format(sys.argv[0]))
sys.exit(1)
input_file = Path(sys.argv[1])
# Read inputs
with open(input_file, 'r') as f:
inputs = json.load(f)
# Extract required inputs
max_stress = inputs.get("max_stress")
if max_stress is None:
print(f"Error: Required input 'max_stress' not found")
sys.exit(1)
yield_strength = inputs.get("yield_strength")
if yield_strength is None:
print(f"Error: Required input 'yield_strength' not found")
sys.exit(1)
# Calculate result
result = calculate_safety_factor(max_stress, yield_strength)
# Write output
output_file = input_file.parent / "safety_factor_result.json"
output = {
"safety_factor": result,
"formula": "yield_strength / max_stress",
"inputs_used": {"max_stress": max_stress, "yield_strength": yield_strength}
}
with open(output_file, 'w') as f:
json.dump(output, f, indent=2)
print(f"safety_factor = {result:.6f}")
print(f"Result saved to: {output_file}")
return result
if __name__ == '__main__':
main()