Skip to content

Commit

Permalink
EC-54 Begin adding edit_add_heatnetwork_heating
Browse files Browse the repository at this point in the history
Co-Authored-By: Rachel Howell <[email protected]>
  • Loading branch information
kpinakula and rachowell committed Nov 4, 2024
1 parent 39be4cc commit 694d065
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/core/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub(crate) mod input {
use serde::Deserialize;
use std::collections::HashMap;

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub(crate) struct Schedule<T: Copy> {
Expand Down Expand Up @@ -244,7 +244,7 @@ pub(crate) mod input {
}
}

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(untagged)]
Expand All @@ -255,7 +255,7 @@ pub(crate) mod input {
Reference(String),
}

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(untagged)]
Expand All @@ -264,7 +264,7 @@ pub(crate) mod input {
Single(ScheduleEntry<T>),
}

#[derive(Clone, Copy, Debug, Deserialize)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(untagged)]
Expand All @@ -273,15 +273,15 @@ pub(crate) mod input {
Value(T),
}

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub(crate) struct ScheduleRepeater<T: Copy> {
pub(crate) value: ScheduleRepeaterValue<T>,
pub(crate) repeat: usize,
}

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(untagged)]
Expand Down
14 changes: 9 additions & 5 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ pub enum WaterHeatingSchedule {

pub type HeatSourceWet = IndexMap<String, HeatSourceWetDetails>;

#[derive(Clone, Debug, Deserialize, Validate)]
#[derive(Clone, Debug, Deserialize, Validate, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -2216,7 +2216,7 @@ pub enum HeatPumpBackupControlType {
Substitute,
}

#[derive(Copy, Clone, Debug, Deserialize)]
#[derive(Copy, Clone, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -2247,7 +2247,7 @@ pub struct HeatPumpTestDatum {
pub ext_air_ratio: Option<f64>,
}

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(deny_unknown_fields)]
Expand All @@ -2268,7 +2268,7 @@ pub struct HeatPumpBoiler {
pub(crate) cost_schedule_hybrid: Option<BoilerCostScheduleHybrid>,
}

#[derive(Clone, Debug, Deserialize)]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(deny_unknown_fields)]
Expand All @@ -2279,7 +2279,7 @@ pub(crate) struct BoilerCostScheduleHybrid {
pub cost_schedule_boiler: NumericSchedule,
}

#[derive(Copy, Clone, Debug, Deserialize)]
#[derive(Copy, Clone, Debug, Deserialize, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum HeatSourceLocation {
Expand Down Expand Up @@ -3949,6 +3949,10 @@ impl InputForProcessing {
.unwrap_or(false)
}

pub(crate) fn set_heat_source_wet(&mut self, heat_source_wet: HeatSourceWet) {
self.input.heat_source_wet = Some(heat_source_wet);
}

pub(crate) fn heat_source_wet(&self) -> Option<&IndexMap<String, HeatSourceWetDetails>> {
self.input.heat_source_wet.as_ref()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,23 @@ static TABLE_R2: LazyLock<HashMap<&'static str, f64>> = LazyLock::new(|| {
])
});

fn edit_add_heatnetwork_heating() {
todo!()
/// Apply heat network settings to notional building calculation in project_dict.
fn edit_add_heatnetwork_heating(input: &mut InputForProcessing) -> anyhow::Result<()> {
let heat_network_name = "heat network";

let notional_heat_network = serde_json::from_value(json!(
{
"notionalHIU": {
"type": "HIU",
"EnergySupply": heat_network_name,
"power_max": 45,
"HIU_daily_loss": 0.8,
"building_level_distribution_losses": 62,
}
}))?;

input.set_heat_source_wet(notional_heat_network);
Ok(())
}

fn edit_add_default_space_heating_system() {
Expand Down Expand Up @@ -1100,7 +1115,8 @@ mod tests {

use super::*;
use crate::input::{
self, EnergySupplyKey, EnergySupplyType, OnSiteGeneration, WaterPipeworkSimple,
self, EnergySupplyKey, EnergySupplyType, HeatSourceWet, OnSiteGeneration,
WaterPipeworkSimple,
};
use crate::input::{
Baths, HotWaterSource, OtherWaterUses, Shower, Showers, ThermalBridging,
Expand Down Expand Up @@ -1380,6 +1396,41 @@ mod tests {
.unwrap()
}

// this test does not exist in Python HEM
#[rstest]
fn test_edit_add_heatnetwork_heating(mut test_input: InputForProcessing) {
let heat_network_name = "heat network";

let expected_heat_source_wet: HeatSourceWet = serde_json::from_value(json!({
"notionalHIU": {
"type": "HIU",
"EnergySupply": heat_network_name,
"power_max": 45,
"HIU_daily_loss": 0.8,
"building_level_distribution_losses": 62,
}
}))
.unwrap();

// let expected_hot_water_source: HotWaterSource = serde_json::from_value(json!({
// "hw cylinder": {
// "type": "HIU",
// "ColdWaterSource": "mains water",
// "HeatSourceWet": "boiler",
// }
// }))
// .unwrap();

edit_add_heatnetwork_heating(&mut test_input).unwrap();

assert_eq!(
test_input.heat_source_wet().unwrap(),
&expected_heat_source_wet
);

// assert_eq!(test_input.hot_water_source(), &expected_hot_water_source);
}

#[rstest]
fn test_edit_bath_shower_other(mut test_input: InputForProcessing) {
// this is the only cold water source type in the test input JSON file
Expand Down

0 comments on commit 694d065

Please sign in to comment.