Source code for suboptimumg.vehicle.powertrain.powertrain
from ..subsystem_models import MotorModel
from ..vehicle_models import VehicleModel
from .motor import Motor
[docs]
class Powertrain:
"""Models the full powertrain, composed of a motor."""
def __init__(
self,
vehicle_model: VehicleModel,
) -> None:
"""
Build a powertrain model from the vehicle's powertrain parameters.
Parameters
----------
vehicle_model : VehicleModel
Full vehicle parameter model, used to access the powertrain
parameters and construct the motor.
"""
self.vehicle_model = vehicle_model
self.params = vehicle_model.pwrtn
self.motor = Motor(vehicle_model=vehicle_model)
[docs]
def swap_motor(self, new_motor: MotorModel) -> None:
"""
Replace the motor, adjusting total vehicle mass by the mass difference.
Parameters
----------
new_motor : MotorModel
Motor to install in place of the current one.
Notes
-----
Total vehicle mass is an independent parameter covering the whole car,
so swapping a component cannot re-derive it. Instead the difference
between the outgoing and incoming motor masses is applied to it,
leaving the rest of the car's mass untouched.
"""
mass_delta = new_motor.mass - self.params.motor.mass
self.params.motor = new_motor
self.vehicle_model.mass += mass_delta
self.motor = Motor(vehicle_model=self.vehicle_model)