2026-07-10 10:38:57 +02:00

64 lines
2.3 KiB
Python

from ScEpTIC.exceptions import ConfigurationException
from ScEpTIC.emulator.energy.energy_harvester import EnergyHarvesterModel
from ScEpTIC.emulator.energy.voltage_regulator import VoltageRegulatorModel
class ChargeBoosterEnergyHarvester(EnergyHarvesterModel):
"""
Model of an energy harvester with a voltage charge booster attached to it.
"""
def __init__(self, charge_booster, equivalent_resistance=None):
"""
:param charge_booster: the voltage charge booster
:param equivalent_resistance: Equivalent resistance of the energy harvester.
"""
super().__init__(equivalent_resistance)
self.charge_booster = None
self.attach_charge_booster(charge_booster)
def attach_charge_booster(self, charge_booster):
"""
Sets the charge booster
:param charge_booster: the voltage charge booster
"""
if not isinstance(charge_booster, VoltageRegulatorModel):
raise ConfigurationException(f"{self.__class__.__name__}.attach_charge_booster() requires a VoltageRegulator but {charge_booster.__class__.__name__} was given")
self.charge_booster = charge_booster
self.get_voltage = self.charge_booster.get_voltage
if self.energy_source is not None:
self.charge_booster.attach_voltage_source(self.energy_source)
def attach_energy_source(self, energy_source):
"""
:param energy_source: an energy source model
"""
super().attach_energy_source(energy_source)
if self.charge_booster is not None:
self.charge_booster.attach_voltage_source(energy_source)
def get_voltage_intervals(self, t):
"""
Returns voltage intervals of the energy source, accounting for the voltage charge booster
:param t: elapsed time
:return: a list of (voltage, energy, elapsed_time)
"""
voltage_intervals = []
output_voltage = self.get_voltage()
# calculate new intervals
for interval in self.energy_source.get_voltage_intervals(t):
# (v, e, t)
e = self.charge_booster.get_supplied_energy(interval[1], interval[2])
boost_interval = (output_voltage, e, interval[2])
voltage_intervals.append(boost_interval)
return voltage_intervals