Skip to content

Commit

Permalink
build zone out a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
shieldo committed Jul 11, 2023
1 parent 6de28e1 commit 69f179e
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 7 deletions.
14 changes: 12 additions & 2 deletions src/core/space_heat_demand/ventilation_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ fn air_change_rate_to_flow_rate(air_change_rate: f64, zone_volume: f64) -> f64 {
air_change_rate * zone_volume / SECONDS_PER_HOUR as f64
}

pub trait VentilationElement {}

pub struct VentilationElementInfiltration {
external_conditions: ExternalConditions,
volume: f64,
Expand Down Expand Up @@ -150,6 +152,8 @@ impl VentilationElementInfiltration {
}
}

impl VentilationElement for VentilationElementInfiltration {}

// # Infiltration rates for openings (m3 per hour)
const INFILTRATION_RATE_CHIMNEY_OPEN: u32 = 80;
const INFILTRATION_RATE_CHIMNEY_BLOCKED: u32 = 20;
Expand Down Expand Up @@ -363,6 +367,8 @@ impl MechanicalVentilationHeatRecovery {
}
}

impl VentilationElement for MechanicalVentilationHeatRecovery {}

pub struct WholeHouseExtractVentilation {
air_change_rate: f64,
specific_fan_power: f64,
Expand Down Expand Up @@ -478,8 +484,12 @@ impl WholeHouseExtractVentilation {
}
}

//tbc: NaturalVentilation
//tbc: WindowOpeningForCooling
impl VentilationElement for WholeHouseExtractVentilation {}

//tbc
pub struct NaturalVentilation;
//tbc:
pub struct WindowOpeningForCooling;

#[cfg(test)]
mod test {
Expand Down
128 changes: 123 additions & 5 deletions src/core/space_heat_demand/zone.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,100 @@
use crate::external_conditions::WindowShadingObject;
use crate::input::{BuildingElement, EnergySupplyType};
use crate::core::space_heat_demand::ventilation_element::{
VentilationElement, WindowOpeningForCooling,
};
use crate::input::BuildingElement;
use serde::Deserialize;
use serde_json::Value;
use std::collections::HashMap;

pub struct Zone {
area: f64,
useful_area: f64,
volume: f64,
building_elements: HashMap<String, BuildingElement>,
thermal_bridging: ThermalBridging,
vent_elements: Vec<Box<dyn VentilationElement>>,
vent_cool_extra: Option<WindowOpeningForCooling>,
tb_heat_trans_coeff: f64,
/// total area of all building elements associated with this zone, in m2
area_el_total: f64,
/// internal thermal capacity of the zone, in J / K
c_int: f64,
/// dictionary where key is building element and
/// values are 2-element tuples storing matrix row and
/// column numbers (both same) where the first element
/// of the tuple gives the position of the heat
/// balance eqn (row) and node temperature (column)
/// for the external surface and the second element
/// gives the position for the internal surface.
/// Positions in between will be for the heat balance
/// and temperature of the inside nodes of the
/// building element
element_positions: Vec<(usize, usize)>,
/// matrix row and column number (both same)
/// corresponding to heat balance eqn for zone (row)
/// and temperature of internal air (column)
zone_idx: u32,
/// number of unknown temperatures (each node in each
/// building element + 1 for internal air) to be
/// solved for
no_of_temps: u32,
/// list of temperatures (nodes and internal air) from
/// previous timestep. Positions in list defined in
/// element_positions and zone_idx
temp_prev: Vec<f64>,
}

enum ThermalBridging {
impl Zone {
/// Construct a Zone object
///
/// ## Arguments
///
/// `area` - useful floor area of the zone, in m2
/// `volume` - total volume of the zone, m3
/// `building_elements` - list of BuildingElement objects (walls, floors, windows etc.)
/// `thermal_bridging` - Either:
/// - overall heat transfer coefficient for thermal
/// bridges in the zone, in W / K
/// - list of ThermalBridge objects for this zone
/// `vent_elements` - list of ventilation elements (infiltration, mech vent etc.)
/// `vent_cool_extra` - element providing additional ventilation in response to high
/// internal temperature
/// `temp_ext_air_init` - external air temperature to use during initialisation, in Celsius
/// `temp_setpnt_init` - setpoint temperature to use during initialisation, in Celsius
pub fn new(
area: f64,
volume: f64,
building_elements: HashMap<String, BuildingElement>,
thermal_bridging: ThermalBridging,
vent_elements: Vec<Box<dyn VentilationElement>>,
vent_cool_extra: Option<WindowOpeningForCooling>,
temp_ext_air_init: f64,
temp_setpnt_init: f64,
) -> Zone {
// sample to start (unimplemented!!)
Zone {
useful_area: 0.0,
volume,
building_elements,
thermal_bridging,
vent_elements,
vent_cool_extra,
tb_heat_trans_coeff: 0.0,
area_el_total: 0.0,
c_int: 0.0,
element_positions: vec![],
zone_idx: 0,
no_of_temps: 0,
temp_prev: vec![],
}
}
}

pub enum ThermalBridging {
Number(f64),
Bridges(Vec<ThermalBridge>),
Bridges(HashMap<String, ThermalBridge>),
}

#[derive(Copy, Clone)]
pub enum ThermalBridge {
Linear {
linear_thermal_transmittance: f64,
Expand All @@ -26,6 +105,45 @@ pub enum ThermalBridge {
},
}

pub fn thermal_bridging_from_input<'a>(input: Value) -> ThermalBridging {
match input {
Value::Object(map) => {
let mut bridges = HashMap::from([]);
for (name, bridge_object) in map.clone().iter() {
bridges.insert(
(*name).clone(),
match bridge_object.get("type") {
Some(Value::String(s)) if s == &String::from("ThermalBridgeLinear") => {
ThermalBridge::Linear {
linear_thermal_transmittance: bridge_object
.get("linear_thermal_transmittance")
.unwrap()
.as_f64()
.unwrap(),
length: bridge_object.get("length").unwrap().as_f64().unwrap(),
}
}
Some(Value::String(s)) if s == &String::from("ThermalBridgePoint") => {
ThermalBridge::Point {
heat_transfer_coefficient: bridge_object
.get("heat_transfer_coeff")
.unwrap()
.as_f64()
.unwrap(),
}
}
_ => panic!("unknown type of thermal bridging sent"),
},
);
}

ThermalBridging::Bridges(bridges)
}
Value::Number(n) => ThermalBridging::Number(n.as_f64().unwrap()),
_ => panic!("thermal bridging input was not in an expected format"),
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit 69f179e

Please sign in to comment.