From efbcb2af426eb4b7a64507a4e212888a3d1c0b64 Mon Sep 17 00:00:00 2001 From: Douglas Greenshields Date: Wed, 3 Jan 2024 15:08:21 +0000 Subject: [PATCH] build hot water event schedules for corpus --- src/core/schedule.rs | 12 +++++--- src/corpus.rs | 73 +++++++++++++++++++++++++++++++++++++++++--- src/input.rs | 16 +++++----- 3 files changed, 85 insertions(+), 16 deletions(-) diff --git a/src/core/schedule.rs b/src/core/schedule.rs index 9b6bb3f..76a0730 100644 --- a/src/core/schedule.rs +++ b/src/core/schedule.rs @@ -165,8 +165,8 @@ pub fn expand_events( schedule } -impl From for ScheduleEvent { - fn from(event: WaterHeatingEvent) -> Self { +impl From<&WaterHeatingEvent> for ScheduleEvent { + fn from(event: &WaterHeatingEvent) -> Self { Self { start: event.start, duration: event.duration, @@ -176,7 +176,7 @@ impl From for ScheduleEvent { } pub fn expand_water_heating_events( - events: Vec, + events: Vec<&WaterHeatingEvent>, simulation_timestep: f64, total_timesteps: usize, ) -> Vec>> { @@ -422,7 +422,11 @@ mod test { water_events_schedule: Vec>>, ) { 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" ); diff --git a/src/corpus.rs b/src/corpus.rs index f720d3f..82f0517 100644 --- a/src/corpus.rs +++ b/src/corpus.rs @@ -5,7 +5,10 @@ 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; @@ -13,8 +16,9 @@ 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; @@ -29,6 +33,7 @@ pub struct Corpus { pub internal_gains: InternalGainsCollection, pub control: HashMap, pub wwhrs: HashMap, + pub event_schedules: HotWaterEventSchedules, } impl From for Corpus { @@ -56,10 +61,13 @@ impl From 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(), + ), } } } @@ -425,3 +433,60 @@ pub struct HotWaterEventSchedules { pub bath: HashMap, pub other: HashMap, } + +fn event_schedules_from_input( + events: WaterHeatingEvents, + simulation_time_iterator: &SimulationTimeIterator, +) -> HotWaterEventSchedules { + let mut shower_schedules: HashMap = 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 = 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 = 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) +} diff --git a/src/input.rs b/src/input.rs index 9207045..79f42d0 100644 --- a/src/input.rs +++ b/src/input.rs @@ -37,7 +37,7 @@ pub struct Input { #[serde(rename(deserialize = "Distribution"))] water_distribution: Option, #[serde(rename(deserialize = "Events"))] - water_heating_events: WaterHeatingEvents, + pub water_heating_events: WaterHeatingEvents, space_heat_system: Option, space_cool_system: Option, pub ventilation: Option, @@ -463,9 +463,9 @@ pub struct WaterDistribution { #[derive(Debug, Deserialize)] #[serde(rename_all = "PascalCase", deny_unknown_fields)] pub struct WaterHeatingEvents { - shower: Option, - bath: Option, - other: Option, + pub shower: Option, + pub bath: Option, + pub other: Option, } #[derive(Debug, Deserialize)] @@ -480,20 +480,20 @@ pub struct WaterHeatingEvent { #[serde(deny_unknown_fields)] pub struct ShowerEvents { #[serde(alias = "IES")] - ies: Vec, - mixer: Vec, + pub ies: Vec, + pub mixer: Vec, } #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] pub struct BathEvents { - medium: Vec, + pub medium: Vec, } #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] pub struct OtherWaterHeatingEvents { - other: Vec, + pub other: Vec, } pub type SpaceHeatSystem = HashMap;