Battery

Struct Battery 

Source
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: f32

Battery capacity in kilowatt-hours

§soc: f32

State of charge as a fraction (0.0 to 1.0)

§max_charge_kw: f32

Maximum charge power in kilowatts (positive value)

§max_discharge_kw: f32

Maximum discharge power in kilowatts (positive value)

§eta_c: f32

Charging efficiency (0..1.0)

§eta_d: f32

Discharging efficiency (0..1.0)

§steps_per_day: usize

Number of time steps per day

Implementations§

Source§

impl Battery

Source

pub fn new( capacity_kwh: f32, soc: f32, max_charge_kw: f32, max_discharge_kw: f32, eta_c: f32, eta_d: f32, steps_per_day: usize, ) -> Self

Trait Implementations§

Source§

impl Clone for Battery

Source§

fn clone(&self) -> Battery

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Battery

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Device for Battery

Source§

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

Source§

fn device_type(&self) -> &'static str

Returns a human-readable type name for the device.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.