PHI-Arc-Engine-PHM / src /engines /base_engine.py
SM-Bello's picture
Create engines/base_engine.py
fd0efbe verified
Raw
History Blame Contribute Delete
2.88 kB
"""
PHI-Arc Engine PHM — Base Engine Class
Defines the interface for all engine types in the digital twin system.
"""
from abc import ABC, abstractmethod
from typing import Dict, List, Tuple, Any
import numpy as np
class BaseEngine(ABC):
"""Abstract base class for all engine types in PHI-Arc PHM."""
def __init__(self, name: str, engine_type: str, ata_chapters: Dict[str, str]):
self.name = name
self.engine_type = engine_type
self.ata_chapters = ata_chapters
self.fault_library = []
self.cert_standards = []
@abstractmethod
def compute_healthy_baseline(self, flight_conditions: Dict) -> Dict[str, float]:
"""Compute healthy baseline parameters for given flight conditions."""
pass
@abstractmethod
def compute_fault_signatures(self, baseline: Dict, flight_conditions: Dict) -> List[List[Dict]]:
"""Compute fault signatures for all fault modes at all severity levels."""
pass
@abstractmethod
def classify_fault(self, measured: Dict, baseline: Dict,
fault_sigs: List[List[Dict]]) -> Dict:
"""Classify fault based on measured vs baseline deviation."""
pass
@abstractmethod
def get_parameter_labels(self) -> List[str]:
"""Return list of parameter names for this engine."""
pass
@abstractmethod
def get_parameter_units(self) -> Dict[str, str]:
"""Return units for each parameter."""
pass
@abstractmethod
def get_input_fields(self) -> List[Dict]:
"""Return input field definitions for Streamlit UI."""
pass
def get_fault_actions(self, fault_id: str, severity_level: int) -> List[str]:
"""Get maintenance actions for a fault at a given severity."""
for fault in self.fault_library:
if fault["id"] == fault_id:
actions = fault.get("actions", [])
if severity_level < len(actions):
return actions[severity_level]
return actions[-1] if actions else "Consult maintenance manual"
return "Unknown fault — consult specialist"
def get_cert_requirements(self, fault_id: str) -> List[str]:
"""Get certification requirements linked to a fault."""
for fault in self.fault_library:
if fault["id"] == fault_id:
return fault.get("cert_requirements", self.cert_standards)
return self.cert_standards
def estimate_rul(self, degradation_rate: float, current_severity: float,
max_severity: float = 1.0) -> float:
"""Estimate remaining useful life in flight cycles/hours."""
if degradation_rate <= 0:
return float('inf')
remaining = (max_severity - current_severity) / degradation_rate
return max(0, remaining * 100) # Scale to approximate cycles