from matplotlib import pyplot as plot import numpy as np class Params: def __init__(self, alpha, beta): self.alpha = alpha self.beta = beta def bas(soc: float): return 0.05, 25 def model_r(temperature: float, soc: float, p: Params): rb, tb = bas(soc) tb = 25 tb2 = tb*tb _t = temperature t2 = temperature*temperature return rb * np.exp(p.alpha*(t2 - tb2) + p.beta*(_t - tb)) temps = [0, 5, 10, 20, 25, 40] pl = 10000 il = 100 ul = 100 rl = ul/il p_ = np.linspace(0, 20000, 100) i_ = p_/ul bat_params = Params(alpha=0.0007545, beta=-0.07033) rt_ = [] for t in temps: rt_.append(model_r(t, 100, bat_params)) plot.figure() plot.plot(temps, rt_) r, t = bas(100) plot.title(f"Ri vs temperature (Base R={r}@{t}°C)") plot.xlabel("Temperature [°C]") plot.ylabel("R [Ohm]") plot.grid() titles = [ "Battery power loss vs internal battery resistance (DCR)", "Batter power consumption vs internal battery resistance (DCR)" ] for sp, name, title in zip([0, 1], ["P_loss [kW]", "P_batt [kW]"], titles): plot.figure() legs = [] plot.grid() for temp in temps: ri = model_r(temp, 100, bat_params) pi_ = (ri * i_ * i_) + sp*p_ x = p_/1000 y = pi_/1000 legs.append(f"temp={temp} °C") plot.plot(x, y) plot.xlabel("P_demand [kW]") plot.title(title) plot.legend(legs) plot.ylabel(name) plot.show()