Skip to content

Commit

Permalink
build hot water event schedules for corpus
Browse files Browse the repository at this point in the history
  • Loading branch information
shieldo committed Jan 3, 2024
1 parent 989aa25 commit efbcb2a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/core/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ pub fn expand_events(
schedule
}

impl From<WaterHeatingEvent> for ScheduleEvent {
fn from(event: WaterHeatingEvent) -> Self {
impl From<&WaterHeatingEvent> for ScheduleEvent {
fn from(event: &WaterHeatingEvent) -> Self {
Self {
start: event.start,
duration: event.duration,
Expand All @@ -176,7 +176,7 @@ impl From<WaterHeatingEvent> for ScheduleEvent {
}

pub fn expand_water_heating_events(
events: Vec<WaterHeatingEvent>,
events: Vec<&WaterHeatingEvent>,
simulation_timestep: f64,
total_timesteps: usize,
) -> Vec<Option<Vec<ScheduleEvent>>> {
Expand Down Expand Up @@ -422,7 +422,11 @@ mod test {
water_events_schedule: Vec<Option<Vec<ScheduleEvent>>>,
) {
assert_eq!(
expand_water_heating_events(water_heating_events, simulation_timestep, total_timesteps),
expand_water_heating_events(
water_heating_events.iter().collect(),
simulation_timestep,
total_timesteps
),
water_events_schedule,
"incorrect expansion of event list to schedule"
);
Expand Down
73 changes: 69 additions & 4 deletions src/corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ use crate::core::energy_supply::energy_supply::{EnergySupplies, EnergySupply};
use crate::core::heating_systems::wwhrs::{
WWHRSInstantaneousSystemA, WWHRSInstantaneousSystemB, WWHRSInstantaneousSystemC, Wwhrs,
};
use crate::core::schedule::{expand_boolean_schedule, expand_numeric_schedule, ScheduleEvent};
use crate::core::schedule::{
expand_boolean_schedule, expand_events, expand_numeric_schedule, expand_water_heating_events,
ScheduleEvent,
};
use crate::core::space_heat_demand::internal_gains::InternalGains;
use crate::core::space_heat_demand::ventilation_element::VentilationElementInfiltration;
use crate::core::water_heat_demand::cold_water_source::ColdWaterSource;
use crate::external_conditions::ExternalConditions;
use crate::input::{
ColdWaterSourceDetails, ColdWaterSourceInput, ColdWaterSourceType, Control as ControlInput,
ControlDetails, EnergyDiverter, EnergySupplyDetails, EnergySupplyInput, EnergySupplyType,
ExternalConditionsInput, HeatNetwork, Infiltration, Input, InternalGains as InternalGainsInput,
InternalGainsDetails, Shower, WasteWaterHeatRecovery, WasteWaterHeatRecoveryDetails, WwhrsType,
ExternalConditionsInput, Infiltration, Input, InternalGains as InternalGainsInput,
InternalGainsDetails, WasteWaterHeatRecovery, WasteWaterHeatRecoveryDetails, WaterHeatingEvent,
WaterHeatingEvents, WwhrsType,
};
use crate::simulation_time::{SimulationTime, SimulationTimeIterator};
use serde_json::Value;
Expand All @@ -29,6 +33,7 @@ pub struct Corpus {
pub internal_gains: InternalGainsCollection,
pub control: HashMap<String, Control>,
pub wwhrs: HashMap<String, Wwhrs>,
pub event_schedules: HotWaterEventSchedules,
}

impl From<Input> for Corpus {
Expand Down Expand Up @@ -56,10 +61,13 @@ impl From<Input> for Corpus {
infiltration: infiltration_from_input(input.infiltration),
cold_water_sources,
energy_supplies,
// about to do internal gains but need to add schedule code
internal_gains: internal_gains_from_input(input.internal_gains),
control: control_from_input(input.control, simulation_time_iterator.clone().as_ref()),
wwhrs,
event_schedules: event_schedules_from_input(
input.water_heating_events,
simulation_time_iterator.as_ref(),
),
}
}
}
Expand Down Expand Up @@ -425,3 +433,60 @@ pub struct HotWaterEventSchedules {
pub bath: HashMap<String, EventSchedule>,
pub other: HashMap<String, EventSchedule>,
}

fn event_schedules_from_input(
events: WaterHeatingEvents,
simulation_time_iterator: &SimulationTimeIterator,
) -> HotWaterEventSchedules {
let mut shower_schedules: HashMap<String, EventSchedule> = Default::default();
if let Some(shower_events) = events.shower {
shower_schedules.insert(
"ies".to_string(),
schedule_event_from_input(shower_events.ies.iter().collect(), simulation_time_iterator),
);
shower_schedules.insert(
"mixer".to_string(),
schedule_event_from_input(
shower_events.mixer.iter().collect(),
simulation_time_iterator,
),
);
}

let mut bath_schedules: HashMap<String, EventSchedule> = Default::default();
if let Some(bath_events) = events.bath {
bath_schedules.insert(
"medium".to_string(),
schedule_event_from_input(
bath_events.medium.iter().collect(),
simulation_time_iterator,
),
);
}

let mut other_schedules: HashMap<String, EventSchedule> = Default::default();
if let Some(other_events) = events.other {
other_schedules.insert(
"other".to_string(),
schedule_event_from_input(
other_events.other.iter().collect(),
simulation_time_iterator,
),
);
}

HotWaterEventSchedules {
shower: shower_schedules,
bath: bath_schedules,
other: other_schedules,
}
}

fn schedule_event_from_input(
events_input: Vec<&WaterHeatingEvent>,
simulation_time_iterator: &SimulationTimeIterator,
) -> EventSchedule {
let sim_timestep = simulation_time_iterator.step_in_hours();
let total_timesteps = simulation_time_iterator.total_steps();
expand_water_heating_events(events_input, sim_timestep, total_timesteps)
}
16 changes: 8 additions & 8 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Input {
#[serde(rename(deserialize = "Distribution"))]
water_distribution: Option<WaterDistribution>,
#[serde(rename(deserialize = "Events"))]
water_heating_events: WaterHeatingEvents,
pub water_heating_events: WaterHeatingEvents,
space_heat_system: Option<SpaceHeatSystem>,
space_cool_system: Option<SpaceCoolSystem>,
pub ventilation: Option<Ventilation>,
Expand Down Expand Up @@ -463,9 +463,9 @@ pub struct WaterDistribution {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase", deny_unknown_fields)]
pub struct WaterHeatingEvents {
shower: Option<ShowerEvents>,
bath: Option<BathEvents>,
other: Option<OtherWaterHeatingEvents>,
pub shower: Option<ShowerEvents>,
pub bath: Option<BathEvents>,
pub other: Option<OtherWaterHeatingEvents>,
}

#[derive(Debug, Deserialize)]
Expand All @@ -480,20 +480,20 @@ pub struct WaterHeatingEvent {
#[serde(deny_unknown_fields)]
pub struct ShowerEvents {
#[serde(alias = "IES")]
ies: Vec<WaterHeatingEvent>,
mixer: Vec<WaterHeatingEvent>,
pub ies: Vec<WaterHeatingEvent>,
pub mixer: Vec<WaterHeatingEvent>,
}

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct BathEvents {
medium: Vec<WaterHeatingEvent>,
pub medium: Vec<WaterHeatingEvent>,
}

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct OtherWaterHeatingEvents {
other: Vec<WaterHeatingEvent>,
pub other: Vec<WaterHeatingEvent>,
}

pub type SpaceHeatSystem = HashMap<String, SpaceHeatSystemDetails>;
Expand Down

0 comments on commit efbcb2a

Please sign in to comment.