Modelling non-linear battery behavior with piecwise linear expressions
Modelling time dependent charging behavior of batteries is not new. The rise of global EV fleets makes it an interesting topic.
In the context of EV charging the most important charging objective is to have the car be charged to a target SOC (state of charge) at a pre-determined point in time, a.k.a. departure time.
This forms an important time constraint for the system.
The mathematical model of the charging and discharging behavior of a battery is straight forward.
All optimization strategies need to ensure, that the car is ready when needed.
It is interesting to look at different optimization objectives:
- Time Optimization: (earliest possible, latest possible charging)
- Feasibility: Car can be charged within available time
- Cost: Car will be charge at minimum cost
Batteries have non-linear charging behavior. Especially high-power charging can show interesting profiles. Here is a simplified charging and discharging profile depending on the energy in the battery (SOC). The closer the SOC gets to 100% the lower the charging power will be.
This phenomenon is also called degradation.
Step function as non-linearity
It is a well known modelling technique to approximate non-linear functions with piecewise linear functions.
Pyomo has out-of-the box support for this.
The above’s charging profile (upper boundary) can for example be modelled with this expression:
# linearize non-linear P(E) battery behavior model.pw_constraint_charging = Piecewise( block.A, block.p_plus, block.e, pw_pts=value(block.e_pw_charging), pw_constr_type='UB', # upper bound for power f_rule=value(block.p_pw_charging), pw_repn='CC', # algorithm selection )
This allows for almost arbitrary non-linear battery profiles and is limited only by the number for generated binary variables and associated solver capability.
I solve here a very simple battery model over a charging period of 50x15min time intervals. The lower bound of the blue area delineates the plugin SOC and the upper bound is the target SOC.
The red area on the P(E) diagram defines the allowed power values, depending on battery energy.
Departure time is assumed to be and we want to leave with full battery , of course.
This scenario allows discharging the battery and selling the energy to the grid operator while still having the car ready at departure time.
Under the totally unrealistic assumption that we can sell energy for twice as much as we buy it, we can see that the battery discharges twice to the allowed minimum of 30% SOC and charges up again.
However, this scenario becomes more realistic when there are time periods where charging and discharging cost do have a real spread.
Using piecewise linear functions as approximation of complex battery charging profiles can be a valid solution for modelling non-trivial charging behavior. Pyomo supports here with built-in capabilities and makes our lives as modellers bearable.