Skip to main content

EnergyEnvelope

Struct EnergyEnvelope 

Source
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

Source

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.

Source

pub fn power(&self) -> &Envelope

The power bounds per ISP.

Source

pub fn grid(&self) -> &Grid

The grid.

Source

pub fn initial(&self) -> Energy

The level at the start of the grid.

Source

pub fn level_after(&self, isp: u32) -> Option<Level>

The level bound after ISP isp; None outside the grid.

Source

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).

Source

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.

Source

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.

Source

pub fn has_levels(&self) -> bool

Whether any level bound is set.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for EnergyEnvelope

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EnergyEnvelope

Source§

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

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

impl Eq for EnergyEnvelope

Source§

impl Hash for EnergyEnvelope

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for EnergyEnvelope

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for EnergyEnvelope

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>, U: Sized,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.