pub struct Battery {
pub capacity_kwh: f32,
pub soc: f32,
pub max_charge_kw: f32,
pub max_discharge_kw: f32,
pub eta_c: f32,
pub eta_d: f32,
pub steps_per_day: usize,
}Expand description
A battery energy storage system that can charge and discharge electricity.
Battery models a battery with configurable capacity, charge/discharge rates,
and efficiencies. It maintains its state of charge (SOC) and enforces operational
constraints when given power setpoints.
§Power Flow Convention
- Positive power: Discharging (supplying power to the grid)
- Negative power: Charging (consuming power from the grid)
§Examples
Note: vpp-sim currently ships as a binary-first crate; this snippet is illustrative.
use vpp_sim::devices::battery::Battery;
use vpp_sim::devices::types::{Device, DeviceContext};
// Create a 10kWh battery at 50% SOC with 5kW charge/discharge limits
let mut battery = Battery::new(
10.0, // capacity_kwh
0.5, // state of charge (50%)
5.0, // max_charge_kw
5.0, // max_discharge_kw
0.95, // charging efficiency
0.95, // discharging efficiency
96, // steps_per_day (15-min intervals)
);
// Command battery to discharge at 3kW
let context = DeviceContext::with_setpoint(0, 3.0);
let actual_kw = battery.power_kw(&context);
// Command battery to charge at 2kW
let context = DeviceContext::with_setpoint(1, -2.0);
let actual_kw = battery.power_kw(&context);Fields§
§capacity_kwh: f32Battery capacity in kilowatt-hours
soc: f32State of charge as a fraction (0.0 to 1.0)
max_charge_kw: f32Maximum charge power in kilowatts (positive value)
max_discharge_kw: f32Maximum discharge power in kilowatts (positive value)
eta_c: f32Charging efficiency (0..1.0)
eta_d: f32Discharging efficiency (0..1.0)
steps_per_day: usizeNumber of time steps per day
Implementations§
Trait Implementations§
Source§impl Device for Battery
impl Device for Battery
Source§fn power_kw(&mut self, context: &DeviceContext) -> f32
fn power_kw(&mut self, context: &DeviceContext) -> f32
Returns the actual power output given a power setpoint.
Takes a setpoint in kW and returns the actual power after accounting for battery constraints:
- Enforces charge/discharge power limits
- Prevents over-charging or over-discharging
- Updates the battery’s state of charge (SOC)
§Power Convention
- Positive: Battery is discharging (delivering power)
- Negative: Battery is charging (consuming power)
§Arguments
setpoint_kw- The requested power setpoint in kW
§Returns
The actual power output in kW after applying constraints