Storage and pools

Energy envelopes for batteries, cars and heat buffers: level bounds at every ISP boundary, steady headroom, pools that say whether they are exact, split checks.

On this page

A power envelope is a box per ISP. A car that must have 30 kWh by 07:00 is not a box: 4 kW all night fits an 11 kW charger in every ISP and still leaves the car short. Storage needs bounds on the level it reaches, as well as on power.

An energy envelope#

let charger = Envelope::unbounded(night.clone())
    .apply(&Limit::new(all, Bounds::new(Some(kw!(0)), Some(kw!(11)))?, cpo))?;
let ev = EnergyEnvelope::new(charger, kwh!(0))
    .level_at(night.local(time(7, 0, 0, 0))?, Level::at_least(kwh!(30)), departure)?;

let report = ev.check(&plan)?; // 4 kW from 00:00
assert!(report.power.is_empty());
println!("{}", report.level[0]);
after ISP 28 (06:45–07:00 +01:00): level 28 kWh below min 30 kWh set by emob.example departure
  • The level is the initial level plus the exact integral of power, consumption (charging) positive, in watt-seconds. Losses and self-discharge are not modelled.
  • level_at(instant, level, who) sets a bound after the ISP that ends at instant; an instant that does not end an ISP (07:05 on a quarter-hour grid) is refused, never moved. level_always(level, who) bounds every boundary: a battery's state-of-charge window. The initial level must already be inside it (Error::InitialLevel otherwise).
  • Two bounds on one boundary keep the stricter of each side, each naming its source (level_sources).
  • check returns a Report: every power Violation and every LevelViolation. Power is constant within an ISP, so checking the boundaries is exact.
  • kwh!(30), wh!(500), mwh!(1.2) are exact literals; a fraction of a watt-hour does not compile.

A battery at 5 kWh kept between 1 and 9 kWh, discharging 4 kW for two hours, breaks its window after the fifth ISP and every one after:

after ISP 73 (18:00–18:15 +01:00): level 0 Wh below min 1 kWh set by emob.example capacity

What can a pool offer?#

pool::aggregate(&devices, who) sums the devices' power bounds per ISP, their initial levels, and their level bounds per boundary. A side any device leaves open stays open. Guarantees are not carried over.

The result says in its type whether it is exact:

AggregateWhenMeans
Exactno device has a level boundevery pool plan inside it has a split the devices can follow, for example the same fraction of each device's power headroom
Outerany device has storageevery plan the devices can follow is inside it, but a plan inside it may have no split

The second row is not hypothetical. A car that must charge 10 kW in both ISPs of a half hour, and a 0–10 kW device beside it, aggregate to 0–20 kW with no level bound. A pool plan of 0 kW then 20 kW is inside it, and no split works: the car would need 10 kW in the first ISP while the other device draws −10 kW.

Exact holds for the envelopes as given. Stored energy is checked only as level bounds, so a battery given without them aggregates as Exact, and a split by power can still run it empty. Give a battery its state-of-charge window (level_always) and the aggregate is Outer.

How far can each device move?#

device.steady_headroom(&plan, window) is the lowest and highest constant deviation that keeps the plan inside the device's envelope in every ISP of window. It takes both power and stored energy into account, and every level bound after the window too, since the energy stays stored.

// 10 kWh, kept between 1 and 9 kWh, ±5 kW, holding 5 kWh, planned idle.
let h = battery.steady_headroom(&idle, hour)?.ok_or("no steady deviation fits")?;
assert_eq!((h.down, h.up), (Some(Deviation::from_watts(-4_000)), Some(Deviation::from_watts(4_000))));
// Over 30 minutes the inverter is the limit: -5 kW to 5 kW.
  • Level bounds round inward: every deviation in the range fits, and one watt beyond does not.
  • None means no constant deviation fits; a side that nothing bounds is None in Headroom.
  • Bounds before the window do not move with it and are not judged; check the plan for them.

The fitting deviations form an interval, so a device whose plan fits can take any share between 0 W and its steady headroom. Any pool deviation up to the sum of the devices' steady headrooms, split in proportion to them, keeps every device inside its envelope. A property test holds this on random batteries; check_split confirms each split.

Does this split work?#

Checking a split is this crate's job (finding one is not):

let split = pool::check_split(&pool_plan, &[(&anna, &plan_a), (&ben, &plan_b)])?;
for mismatch in &split.sums {
    println!("{mismatch}"); // ISP 69 (…): pool plans 10 kW, devices sum to 9.999 kW
}
for (device, report) in &split.devices {
    for v in &report.level {
        println!("device {device}: {v}");
    }
}

split.fits() is true when every ISP adds up and every device plan fits its own envelope. A property test holds that every set of device plans that each fit sums to a plan inside the aggregate; another, by brute force, that for power boxes the aggregate is exact.

The full programs are examples/charge_by_seven.rs (two cars) and examples/offer_from_a_pool.rs (three batteries: a split by power runs the smallest below its reserve, a split by steady headroom holds, and the offer leaves out the quarter hour the pool cannot hold).