Skip to content

Commit

Permalink
add boiler module
Browse files Browse the repository at this point in the history
  • Loading branch information
shieldo committed Jan 12, 2024
1 parent e33bbe7 commit e4f3241
Show file tree
Hide file tree
Showing 8 changed files with 1,259 additions and 12 deletions.
95 changes: 86 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ log = "0.4.20"
nalgebra = "0.32.3"
rstest = "0.17.0"
serde = { version = "1.0.164", features = ["derive", "rc"] }
serde-enum-str = "0.4.0"
serde_json = "1.0.100"
variants-struct = "0.1.1"

Expand Down
35 changes: 35 additions & 0 deletions src/core/controls/time_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ pub enum Control {
SetpointTimeControl(SetpointTimeControl),
}

// macro so accessing individual controls through the enum isn't so repetitive
#[macro_use]
macro_rules! per_control {
($val:expr, $pattern:pat => { $res:expr }) => {
match $val {
Control::OnOffTimeControl($pattern) => $res,
Control::ToUChargeControl($pattern) => $res,
Control::OnOffMinimisingTimeControl($pattern) => $res,
Control::SetpointTimeControl($pattern) => $res,
}
};
}

impl Control {
pub fn is_on(&self, timestep_idx: usize) -> bool {
per_control!(self, c => {c.is_on_for_timestep_idx(timestep_idx)})
}
}

/// An object to model a time-only control with on/off (not modulating) operation
pub struct OnOffTimeControl {
/// list of boolean values where true means "on" (one entry per hour)
Expand All @@ -31,6 +50,10 @@ impl OnOffTimeControl {
fn is_on(&self, timestep: &SimulationTimeIteration) -> bool {
self.schedule[timestep.time_series_idx(self.start_day, self.time_series_step)]
}

pub fn is_on_for_timestep_idx(&self, timestep_idx: usize) -> bool {
self.schedule[timestep_idx]
}
}

/// An object to model a control that governs electrical charging of a heat storage device
Expand All @@ -49,6 +72,10 @@ impl ToUChargeControl {
self.schedule[iteration.time_series_idx(self.start_day, self.time_series_step)]
}

pub fn is_on_for_timestep_idx(&self, timestep_idx: usize) -> bool {
self.schedule[timestep_idx]
}

pub fn target_charge(&self, timestep: &SimulationTimeIteration) -> f64 {
self.charge_level[timestep.time_series_idx_days(self.start_day, self.time_series_step)]
}
Expand Down Expand Up @@ -114,6 +141,10 @@ impl OnOffMinimisingTimeControl {
pub fn is_on(&self, timestep: &SimulationTimeIteration) -> bool {
self.schedule[timestep.time_series_idx(self.start_day, self.time_series_step)]
}

pub fn is_on_for_timestep_idx(&self, timestep_idx: usize) -> bool {
self.schedule[timestep_idx]
}
}

#[derive(Clone)]
Expand Down Expand Up @@ -178,6 +209,10 @@ impl SetpointTimeControl {
pub fn is_on(&self, timestep: &SimulationTimeIteration) -> bool {
let schedule_idx = timestep.time_series_idx(self.start_day, self.time_series_step);

self.is_on_for_timestep_idx(schedule_idx)
}

pub fn is_on_for_timestep_idx(&self, schedule_idx: usize) -> bool {
let setpnt = self.schedule[schedule_idx];

if setpnt.is_none() {
Expand Down
Loading

0 comments on commit e4f3241

Please sign in to comment.