From 10521ad4da05d6518697173dd81286c6e459e4ff Mon Sep 17 00:00:00 2001 From: Kai Chappell Date: Sun, 29 Jun 2025 17:33:28 +0000 Subject: [PATCH] Refactor DUTModel from Protocol to ABC for explicit interface implementation --- .../simulation/physics/models/base.py | 21 ++++++++++++------- .../simulation/physics/models/ldo.py | 6 ++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/py_dvt_ate/simulation/physics/models/base.py b/src/py_dvt_ate/simulation/physics/models/base.py index c2fed0b..9d3a875 100644 --- a/src/py_dvt_ate/simulation/physics/models/base.py +++ b/src/py_dvt_ate/simulation/physics/models/base.py @@ -1,15 +1,14 @@ -"""Base protocol for Device Under Test (DUT) models. +"""Base interface for Device Under Test (DUT) models. Defines the interface that all DUT models must implement to integrate with the physics engine. """ -from typing import Protocol, runtime_checkable +from abc import ABC, abstractmethod -@runtime_checkable -class DUTModel(Protocol): - """Protocol for DUT electrical/thermal models. +class DUTModel(ABC): + """Abstract base class for DUT electrical/thermal models. DUT models encapsulate the temperature-dependent electrical behaviour of a device, enabling realistic simulation of thermal-electrical coupling. @@ -18,8 +17,12 @@ class DUTModel(Protocol): All voltage parameters are in volts. All current parameters are in amps. All power parameters are in watts. + + Implementations must inherit from this class and implement all abstract + methods. """ + @abstractmethod def calculate_output_voltage(self, junction_temperature: float) -> float: """Calculate the output voltage at the given junction temperature. @@ -29,8 +32,9 @@ class DUTModel(Protocol): Returns: Output voltage in volts. """ - ... + pass + @abstractmethod def calculate_quiescent_current(self, junction_temperature: float) -> float: """Calculate the quiescent current at the given junction temperature. @@ -40,8 +44,9 @@ class DUTModel(Protocol): Returns: Quiescent current in amps. """ - ... + pass + @abstractmethod def calculate_power_dissipation( self, input_voltage: float, @@ -58,4 +63,4 @@ class DUTModel(Protocol): Returns: Power dissipation in watts. """ - ... + pass diff --git a/src/py_dvt_ate/simulation/physics/models/ldo.py b/src/py_dvt_ate/simulation/physics/models/ldo.py index 13ea06e..a501c84 100644 --- a/src/py_dvt_ate/simulation/physics/models/ldo.py +++ b/src/py_dvt_ate/simulation/physics/models/ldo.py @@ -7,6 +7,8 @@ and power dissipation calculations. from dataclasses import dataclass +from py_dvt_ate.simulation.physics.models.base import DUTModel + @dataclass(frozen=True) class LDOParameters: @@ -35,7 +37,7 @@ class LDOParameters: REFERENCE_TEMPERATURE_C = 25.0 -class LDOModel: +class LDOModel(DUTModel): """Temperature-dependent LDO voltage regulator model. Models the electrical behaviour of a linear voltage regulator with: @@ -44,7 +46,7 @@ class LDOModel: - Dropout voltage that increases with temperature - Power dissipation from (Vin - Vout) × Iload + Vin × Iq - This class implements the DUTModel protocol. + This class implements the DUTModel interface. """ def __init__(