Repository navigation
Battery Dynamics
You can find examples on the use of battery objects on this page.
If you want to find out more about flow cells consider the following sources:
- Theoretical framework >
- Battery structure and initialization >
- Battery Dynamical Models in the Dynamical Models.docx >
Let's start with a simple example.
import matplotlib.pyplot as plt
from pathlib import Path
import RFB
path = Path.cwd() / 'Battery.xlsx'
load = RFB.BatteryDataXLSX(path)
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], crossover=False)
# Constraints
battery.DynamicalModel.constraints.update({'SOC_max': 0.99, 'SOC_min': 0.01, 'U_max': 1.7, 'U_min': 0.8})
battery.DynamicalModel.rect_current_args = {'I_high': 3, 'I_low': -3, 't_high': 2600, 't_low': 2600}
dynamics = battery.Solve(t_end=5200, I='rect')
plt.plot(dynamics['I'])
plt.show()
plt.plot(dynamics['U'])
plt.show()
plt.plot(dynamics['C'])
plt.show()
The following constraints and model behavior is implemented:
- SOC_max - SOC can't be greater than this value on charge
- SOC_min - SOC can't be lower than this value on discharge
- U_max - U can't be greater than this value on charge
- U_min - U can't be lower than this value on discharge
- C_max - None of the concentrations can be greater than C_b
- C_min - None of the concentrations can be lower than 0
Constraints have default values:
- 'SOC_max': 0.99
- 'SOC_min': 0.01,
- 'U_max': 100
- 'U_min': 0
- 'C_max': [battery.Electrolyte['C_b']] * 8,
- 'C_min': [0] * 8
Although, recommended values for Vanadium Cells are the following:
- 'SOC_max': 0.9 (Due to hydrogen reduction 2H+ -> H2 )
- 'SOC_min': 0.1 (Due to concentration losses)
- 'U_max': N * 1.65 (Hydrogen reduction)
- 'U_min': 0.8 * N (Concentration losses)
Where N - number of Vanadium cells
There are several ways to set model constraints: you can pass constraints as a parameter on battery object initialization or use update method for dictionaries. The following code segments are equivalent:
con = {'SOC_max': 0.9, 'SOC_min': 0.1, 'U_max': 1.65, 'U_min': 0.8}
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], constraints=con, crossover=False)
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], crossover=False)
battery.DynamicalModel.constraints.update({'SOC_max': 0.9, 'SOC_min': 0.1, 'U_max': 1.65, 'U_min': 0.8})
Detailed information on dynamical models can be found in the original repo in the file Dynamical Models.docx >
The following code shows how to solve model for charge/discharge on constant current.
from pathlib import Path
import RFB
path = Path.cwd() / 'Battery.xlsx'
load = RFB.BatteryDataXLSX(path)
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], crossover=False)
battery.DynamicalModel.constraints.update({'SOC_max': 0.9, 'SOC_min': 0.1, 'U_max': 1.65, 'U_min': 0.8})
dynamics = battery.Solve(t_end=3000, I=3)
from pathlib import Path
import RFB
path = Path.cwd() / 'Battery.xlsx'
load = RFB.BatteryDataXLSX(path)
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], crossover=False)
battery.DynamicalModel.constraints.update({'SOC_max': 0.9, 'SOC_min': 0.1, 'U_max': 1.65, 'U_min': 0.8})
# Just for convenience. You can also set values directly in Battery.xlsx
battery.set_initial_values(battery.C_from_SOC(0.9))
dynamics = battery.Solve(t_end=3000, I=-3)
To run solver for rectangular current you shall use on of the following:
battery.Solve(t_end=5200, I='rect')
battery.Solve(t_end=5200, I='rectangular')
There are three ways to set current arguments and the following code snippets are equivalent:
args = {'I_high': 3, 'I_low': -3, 't_high': 2600, 't_low': 2600}
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], crossover=False, rect_current=args)
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], crossover=False)
battery.DynamicalModel.set_rect_args(3, -3, 2600, 2600)
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], crossover=False)
battery.DynamicalModel.rect_current_args = {'I_high': 3, 'I_low': -3, 't_high': 2600, 't_low': 2600}
You can also use any dependency I(t) in the following way:
from pathlib import Path
import RFB
import math
path = Path.cwd() / 'Battery.xlsx'
load = RFB.BatteryDataXLSX(path)
def I(t):
return 3 * math.cos(t/1500 * math.pi)
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], crossover=False)
battery.DynamicalModel.constraints.update({'SOC_max': 0.9, 'SOC_min': 0.1, 'U_max': 1.65, 'U_min': 0.8})
battery.set_initial_values(battery.C_from_SOC(0.5))
dynamics = battery.Solve(t_end=9000, I=I)
You can model performance over time with membrane crossover model. Setting crossover flag to true
battery = RFB.VanadiumBattery(load, x=[0.045, 0.4, 2.3*10**(-3)], crossover=False)
On the following image you can see capacity decrease over time. First diagram - concentrations of V2+, V3+ in the tank, second figure- concentrations of V3+ V4+ in the tank, third figure- battery capacity as a function of time.
To speed up the calculation you can set step=100 in battery.Solve()
dynamics= battery.Solve(t_end=100000, step=100)