pub struct EnergyEnvelope { /* private fields */ }Expand description
Power bounds per ISP and bounds on the stored level after each ISP, from an initial level.
Implementations§
Source§impl EnergyEnvelope
impl EnergyEnvelope
Sourcepub fn new(power: Envelope, initial: Energy) -> EnergyEnvelope
pub fn new(power: Envelope, initial: Energy) -> EnergyEnvelope
Storage behind power, holding initial at the start of the grid, with no level bound
yet. A device without storage is one with no level bound ever set.
Sourcepub fn level_after(&self, isp: u32) -> Option<Level>
pub fn level_after(&self, isp: u32) -> Option<Level>
The level bound after ISP isp; None outside the grid.
Sourcepub fn level_sources(
&self,
isp: u32,
) -> Option<(Option<&Provenance>, Option<&Provenance>)>
pub fn level_sources( &self, isp: u32, ) -> Option<(Option<&Provenance>, Option<&Provenance>)>
Who set the level bound after ISP isp on each side: (minimum, maximum).
Sourcepub fn level_at(
&self,
at: Timestamp,
level: Level,
provenance: Provenance,
) -> Result<EnergyEnvelope, Error>
pub fn level_at( &self, at: Timestamp, level: Level, provenance: Provenance, ) -> Result<EnergyEnvelope, Error>
This envelope with level in force at instant at, which must end an ISP of the grid:
a departure energy, a fill level at a deadline. On a side already bounded there, the
stricter bound is kept with its source.
§Errors
Error::NotABoundary if at does not end an ISP of the grid; Error::EmptyLevel
if, with the bounds already set there, no level is allowed.
Sourcepub fn level_always(
&self,
level: Level,
provenance: Provenance,
) -> Result<EnergyEnvelope, Error>
pub fn level_always( &self, level: Level, provenance: Provenance, ) -> Result<EnergyEnvelope, Error>
This envelope with level in force after every ISP: a capacity, a state-of-charge window.
The initial level must already be inside it.
§Errors
Error::InitialLevel if the initial level is outside level; Error::EmptyLevel if,
with the bounds already set, a boundary allows no level.
Sourcepub fn has_levels(&self) -> bool
pub fn has_levels(&self) -> bool
Whether any level bound is set.
Sourcepub fn steady_headroom(
&self,
plan: &Schedule,
window: Window,
) -> Result<Option<Headroom>, Error>
pub fn steady_headroom( &self, plan: &Schedule, window: Window, ) -> Result<Option<Headroom>, Error>
How far plan can move by one constant deviation in every ISP of window and stay inside
this envelope: the lowest and highest such deviation, None on a side nothing bounds.
The power bounds of the window’s ISPs limit it, and so does every level bound from the
window’s first ISP to the end of the grid, since the energy moved stays stored. Bounds
before the window do not move with it and are not judged. Level bounds round inward, so
every deviation in the range fits and none outside it does; the range is an interval, so
any deviation between 0 W and either end fits too, if the plan does.
Splitting a pool deviation across devices in proportion to their steady headroom keeps
every device inside its envelope; pool::check_split
confirms a split.
use flexibility::jiff::{Timestamp, tz::TimeZone};
use flexibility::*;
let grid = Grid::new(Timestamp::UNIX_EPOCH, IspDuration::FIFTEEN_MINUTES, 8, TimeZone::UTC)?;
let who = Provenance::new("agr.example", "battery-1", grid.start());
let all = Window::new(grid.start(), grid.end())?;
let power = Envelope::unbounded(grid.clone()).apply(&Limit::band(all, kw!(-5), kw!(5), who.clone())?)?;
let battery = EnergyEnvelope::new(power, kwh!(5)).level_always(Level::between(kwh!(1), kwh!(9))?, who.clone())?;
let idle = Schedule::new(Series::filled(grid.clone(), kw!(0)), who);
let hour = Window::new(grid.start(), grid.interval(4).unwrap().until())?;
let h = battery.steady_headroom(&idle, hour)?.unwrap();
assert_eq!((h.down, h.up), (Some(Deviation::from_watts(-4_000)), Some(Deviation::from_watts(4_000))));§Errors
Error::GridMismatch if plan is on another grid; Error::NotABoundary if
window does not start and end on ISP boundaries of the grid; Error::Overflow if an
end leaves the deviation range.
Sourcepub fn check(&self, plan: &Schedule) -> Result<Report, Error>
pub fn check(&self, plan: &Schedule) -> Result<Report, Error>
Every power violation of plan and every boundary whose level leaves its bounds, in ISP
order. The level starts from initial.
§Errors
Error::GridMismatch if plan is on another grid; Error::Overflow if a level
leaves the energy range.