Source code for suboptimumg.vehicle.accumulator.accumulator
from ...constants import *
from ..models import VehicleModel
[docs]
class Accumulator:
def __init__(
self,
vehicle_model: VehicleModel,
):
self.vehicle_model = vehicle_model
self.params = vehicle_model.accum
# Capture the nominal mass at construction time so that mass_to_capacity
# and capacity_to_mass always use the baseline, even if the vehicle model
# mass is later mutated via modify_params.
self._nominal_mass: float = vehicle_model.mass
[docs]
def mass_to_capacity(self, mass: float) -> float:
"""
Compute the battery capacity (kWh) corresponding to a given total vehicle mass (kg),
assuming the mass difference from the current car mass is solely due to changes in battery
mass based on the energy density. Should be used when trying to check if the mass of the car
provides sufficient battery capacity.
Parameters
-----------
mass : float
Total vehicle mass (kg) for which to compute the corresponding battery capacity.
Returns
--------
float
Battery capacity (kWh)
"""
mass_delta = mass - self._nominal_mass
return self.params.capacity + mass_delta * self.params.energy_density
[docs]
def capacity_to_mass(self, capacity: float) -> float:
"""
Compute the total vehicle mass (kg) corresponding to a given battery capacity (kWh),
assuming that any extra mass can be solely used to increase battery mass. Should be used
when trying to modify the mass of the car based on a desired battery capacity.
Parameters
-----------
capacity : float
Battery capacity (kWh) for which to compute the corresponding total vehicle mass.
Returns
--------
float
Total vehicle mass (kg)
"""
cap_delta = capacity - self.params.capacity
return self._nominal_mass + cap_delta / self.params.energy_density