Skip to content

Commit

Permalink
correct use of simulation time with external conditions air temps
Browse files Browse the repository at this point in the history
  • Loading branch information
shieldo committed Mar 13, 2024
1 parent fe8f21a commit ecd76dc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/core/space_heat_demand/building_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ pub fn temp_ext_for(
- (perimeter * psi_wall_floor_junc * (temp_int_annual - temp_ext_annual)))
/ (area * u_value)
}
_ => external_conditions.air_temp_for_timestep_idx(simulation_time.index),
_ => external_conditions.air_temp(simulation_time),
}
}

Expand Down
80 changes: 50 additions & 30 deletions src/core/space_heat_demand/ventilation_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::external_conditions::ExternalConditions;
use crate::input::{
BuildingElement, InfiltrationBuildType, InfiltrationShelterType, InfiltrationTestType,
};
use crate::simulation_time::SimulationTimeIterator;
use crate::simulation_time::{SimulationTimeIteration, SimulationTimeIterator};
use std::collections::HashSet;
use std::sync::Arc;

Expand All @@ -29,7 +29,11 @@ pub trait VentilationElementBehaviour {
external_conditions: &ExternalConditions,
) -> f64;

fn temp_supply(&self, timestep_index: usize, external_conditions: &ExternalConditions) -> f64;
fn temp_supply(
&self,
simtime: SimulationTimeIteration,
external_conditions: &ExternalConditions,
) -> f64;

/// Calculate the heat transfer coefficient (h_ve), in W/K,
/// according to ISO 52016-1:2017, Section 6.5.10.1, for a constant average windspeed
Expand Down Expand Up @@ -88,14 +92,16 @@ impl VentilationElementBehaviour for VentilationElement {
}
}

fn temp_supply(&self, timestep_index: usize, external_conditions: &ExternalConditions) -> f64 {
fn temp_supply(
&self,
simtime: SimulationTimeIteration,
external_conditions: &ExternalConditions,
) -> f64 {
match self {
VentilationElement::Infiltration(el) => {
el.temp_supply(timestep_index, external_conditions)
}
VentilationElement::Mvhr(el) => el.temp_supply(timestep_index, external_conditions),
VentilationElement::Whev(el) => el.temp_supply(timestep_index, external_conditions),
VentilationElement::Natural(el) => el.temp_supply(timestep_index, external_conditions),
VentilationElement::Infiltration(el) => el.temp_supply(simtime, external_conditions),
VentilationElement::Mvhr(el) => el.temp_supply(simtime, external_conditions),
VentilationElement::Whev(el) => el.temp_supply(simtime, external_conditions),
VentilationElement::Natural(el) => el.temp_supply(simtime, external_conditions),
}
}

Expand Down Expand Up @@ -270,10 +276,14 @@ impl VentilationElementBehaviour for VentilationElementInfiltration {
* (zone_volume / SECONDS_PER_HOUR as f64)
}

fn temp_supply(&self, timestep_idx: usize, external_conditions: &ExternalConditions) -> f64 {
fn temp_supply(
&self,
simtime: SimulationTimeIteration,
external_conditions: &ExternalConditions,
) -> f64 {
// Calculate the supply temperature of the air flow element
// according to ISO 52016-1:2017, Section 6.5.10.2
external_conditions.air_temp_for_timestep_idx(timestep_idx)
external_conditions.air_temp(&simtime)
}

fn h_ve_average_heat_transfer_coefficient(
Expand Down Expand Up @@ -488,8 +498,12 @@ impl VentilationElementBehaviour for MechanicalVentilationHeatRecovery {
P_A * C_A * q_v_effective
}

fn temp_supply(&self, timestep_index: usize, external_conditions: &ExternalConditions) -> f64 {
external_conditions.air_temp_for_timestep_idx(timestep_index)
fn temp_supply(
&self,
simtime: SimulationTimeIteration,
external_conditions: &ExternalConditions,
) -> f64 {
external_conditions.air_temp(&simtime)
}

fn h_ve_average_heat_transfer_coefficient(
Expand Down Expand Up @@ -604,8 +618,12 @@ impl VentilationElementBehaviour for WholeHouseExtractVentilation {
P_A * C_A * q_v
}

fn temp_supply(&self, timestep_index: usize, external_conditions: &ExternalConditions) -> f64 {
external_conditions.air_temp_for_timestep_idx(timestep_index)
fn temp_supply(
&self,
simtime: SimulationTimeIteration,
external_conditions: &ExternalConditions,
) -> f64 {
external_conditions.air_temp(&simtime)
}

fn h_ve_average_heat_transfer_coefficient(
Expand Down Expand Up @@ -642,8 +660,12 @@ impl VentilationElementBehaviour for NaturalVentilation {
P_A * C_A * q_v
}

fn temp_supply(&self, timestep_index: usize, external_conditions: &ExternalConditions) -> f64 {
external_conditions.air_temp_for_timestep_idx(timestep_index)
fn temp_supply(
&self,
simtime: SimulationTimeIteration,
external_conditions: &ExternalConditions,
) -> f64 {
external_conditions.air_temp(&simtime)
}

fn h_ve_average_heat_transfer_coefficient(
Expand Down Expand Up @@ -930,11 +952,11 @@ impl WindowOpeningForCooling {
&self,
zone_volume: f64,
temp_int: f64,
timestep_idx: usize,
simtime: SimulationTimeIteration,
external_conditions: &ExternalConditions,
) -> f64 {
let wind_speed = external_conditions.wind_speed_for_timestep_idx(timestep_idx);
let temp_ext = external_conditions.air_temp_for_timestep_idx(timestep_idx);
let wind_speed = external_conditions.wind_speed_for_timestep_idx(simtime.index);
let temp_ext = external_conditions.air_temp(&simtime);
let temp_diff = (temp_int - temp_ext).abs();
let temp_average_c = (temp_int + temp_ext) / 2.0;
let temp_average_k = celsius_to_kelvin(temp_average_c);
Expand Down Expand Up @@ -997,7 +1019,7 @@ impl WindowOpeningForCooling {
Some(nv) => nv.h_ve_heat_transfer_coefficient(
zone_volume,
None,
Some(timestep_idx),
Some(simtime.index),
external_conditions,
),
None => 0.0,
Expand All @@ -1014,11 +1036,9 @@ impl WindowOpeningForCooling {
/// according to ISO 52016-1:2017, Section 6.5.10.2
pub fn temp_supply_for_window_opening(
window_opening: &WindowOpeningForCooling,
timestep_idx: usize,
simtime: SimulationTimeIteration,
) -> f64 {
window_opening
.external_conditions
.air_temp_for_timestep_idx(timestep_idx)
window_opening.external_conditions.air_temp(&simtime)
}

#[cfg(test)]
Expand Down Expand Up @@ -1175,7 +1195,7 @@ mod test {
) {
for simtime_step in simulation_time_iterator {
assert_eq!(
infiltration_element.temp_supply(simtime_step.index, &external_conditions),
infiltration_element.temp_supply(simtime_step, &external_conditions),
2.5 * simtime_step.index as f64,
"incorrect external temperature returned on iteration {} (1-indexed)",
simtime_step.index + 1
Expand Down Expand Up @@ -1254,9 +1274,9 @@ mod test {
simulation_time_iterator: SimulationTimeIterator,
external_conditions: ExternalConditions,
) {
for (i, _) in simulation_time_iterator.enumerate() {
for (i, t_it) in simulation_time_iterator.enumerate() {
assert_eq!(
mvhr.temp_supply(i, &external_conditions),
mvhr.temp_supply(t_it, &external_conditions),
i as f64 * 2.5,
"incorrect supply temp returned"
);
Expand Down Expand Up @@ -1356,9 +1376,9 @@ mod test {
simulation_time_iterator: SimulationTimeIterator,
external_conditions: ExternalConditions,
) {
for (i, _) in simulation_time_iterator.enumerate() {
for (i, t_it) in simulation_time_iterator.enumerate() {
assert_eq!(
whole_house_extract_ventilation.temp_supply(i, &external_conditions),
whole_house_extract_ventilation.temp_supply(t_it, &external_conditions),
i as f64 * 2.5,
"incorrect supply temp returned"
);
Expand Down
12 changes: 5 additions & 7 deletions src/core/space_heat_demand/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ pub fn space_heat_cool_demand(
let h_ve_cool_max = vent_cool_extra.as_ref().unwrap().h_ve_max(
volume,
temp_operative_free,
simulation_time.index,
*simulation_time,
external_conditions,
);
let (temp_vector_vent_max, _) = calc_temperatures(
Expand Down Expand Up @@ -612,10 +612,8 @@ pub fn space_heat_cool_demand(
);
let temp_int_air_vent_max = temp_vector_vent_max[passed_zone_idx];

let vent_cool_extra_temp_supply = temp_supply_for_window_opening(
vent_cool_extra.as_ref().unwrap(),
simulation_time.index,
);
let vent_cool_extra_temp_supply =
temp_supply_for_window_opening(vent_cool_extra.as_ref().unwrap(), *simulation_time);

// If there is cooling potential from additional ventilation
if temp_operative_vent_max < temp_operative_free
Expand Down Expand Up @@ -1007,7 +1005,7 @@ fn calc_temperatures(
vent_cool_extra.as_ref().expect(
"TODO: correct this - we are assuming there is always a window opening",
),
simulation_time.index,
*simulation_time,
);
}
for vei in vent_elements.iter() {
Expand All @@ -1017,7 +1015,7 @@ fn calc_temperatures(
Some(simulation_time.index),
external_conditions,
) * vei
.temp_supply(simulation_time.index, external_conditions);
.temp_supply(*simulation_time, external_conditions);
}
vector_b[passed_zone_idx] = (c_int / delta_t) * temp_prev[passed_zone_idx]
+ sum_vent_elements_h_ve_times_temp_supply
Expand Down
2 changes: 1 addition & 1 deletion src/corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ fn zone_from_input<'a>(
thermal_bridging_from_input(&input.thermal_bridging),
vent_elements,
vent_cool_extra,
external_conditions.air_temp_for_timestep_idx(simulation_time_iterator.current_index()),
external_conditions.air_temp(&simulation_time_iterator.current_iteration()),
input.temp_setpnt_init.unwrap(),
external_conditions.clone(),
simulation_time_iterator,
Expand Down
2 changes: 1 addition & 1 deletion src/external_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl ExternalConditions {
)
}

pub fn air_temp_for_timestep_idx(&self, timestep_idx: usize) -> f64 {
fn air_temp_for_timestep_idx(&self, timestep_idx: usize) -> f64 {
self.air_temps[timestep_idx]
}

Expand Down
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::collections::HashMap;
use crate::core::units::{SECONDS_PER_HOUR, WATTS_PER_KILOWATT};
use crate::corpus::Corpus;
use crate::external_conditions::{DaylightSavingsConfig, ExternalConditions};
use crate::simulation_time::{SimulationTime, SimulationTimeIterator};
use crate::simulation_time::{SimulationTime, SimulationTimeIteration, SimulationTimeIterator};
use std::error::Error;
use std::ffi::OsStr;
use std::ops::Deref;
Expand Down Expand Up @@ -167,7 +167,7 @@ impl Calculation {
space_cool_demand_system,
ductwork_gains,
heat_balance,
} = self.calc_space_heating(iteration.timestep, gains_internal_dhw, iteration.index);
} = self.calc_space_heating(iteration.timestep, gains_internal_dhw, iteration);
}

fn hot_water_demand(timestep_idx: usize) -> (f64, f64, u32, f64, f64, f64) {
Expand Down Expand Up @@ -202,11 +202,9 @@ impl Calculation {
&self,
delta_t_h: f64,
gains_internal_dhw: f64,
timestep_idx: usize,
simtime: SimulationTimeIteration,
) -> SpaceHeatingCalculation {
let temp_ext_air = self
.external_conditions
.air_temp_for_timestep_idx(timestep_idx);
let temp_ext_air = self.external_conditions.air_temp(&simtime);

// calculate timestep in seconds
let delta_t = delta_t_h * SECONDS_PER_HOUR as f64;
Expand Down

0 comments on commit ecd76dc

Please sign in to comment.