Skip to content

Commit

Permalink
correct use of simulation time with external conditions wind speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
shieldo committed Mar 13, 2024
1 parent ecd76dc commit dfd7b24
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
46 changes: 21 additions & 25 deletions src/core/space_heat_demand/ventilation_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait VentilationElementBehaviour {
&self,
zone_volume: f64,
throughput_factor: Option<f64>,
timestep_idx: Option<usize>,
simtime: Option<SimulationTimeIteration>,
external_conditions: &ExternalConditions,
) -> f64;

Expand Down Expand Up @@ -61,32 +61,32 @@ impl VentilationElementBehaviour for VentilationElement {
&self,
zone_volume: f64,
throughput_factor: Option<f64>,
timestep_idx: Option<usize>,
simtime: Option<SimulationTimeIteration>,
external_conditions: &ExternalConditions,
) -> f64 {
match self {
VentilationElement::Infiltration(el) => el.h_ve_heat_transfer_coefficient(
zone_volume,
throughput_factor,
timestep_idx,
simtime,
external_conditions,
),
VentilationElement::Mvhr(el) => el.h_ve_heat_transfer_coefficient(
zone_volume,
throughput_factor,
timestep_idx,
simtime,
external_conditions,
),
VentilationElement::Whev(el) => el.h_ve_heat_transfer_coefficient(
zone_volume,
throughput_factor,
timestep_idx,
simtime,
external_conditions,
),
VentilationElement::Natural(el) => el.h_ve_heat_transfer_coefficient(
zone_volume,
throughput_factor,
timestep_idx,
simtime,
external_conditions,
),
}
Expand Down Expand Up @@ -266,13 +266,11 @@ impl VentilationElementBehaviour for VentilationElementInfiltration {
&self,
zone_volume: f64,
_throughput_factor: Option<f64>,
timestep_idx: Option<usize>,
simtime: Option<SimulationTimeIteration>,
external_conditions: &ExternalConditions,
) -> f64 {
P_A * C_A
* (self.infiltration_rate()
* external_conditions.wind_speed_for_timestep_idx(timestep_idx.unwrap())
/ 4.0)
* (self.infiltration_rate() * external_conditions.wind_speed(&simtime.unwrap()) / 4.0)
* (zone_volume / SECONDS_PER_HOUR as f64)
}

Expand Down Expand Up @@ -479,7 +477,7 @@ impl VentilationElementBehaviour for MechanicalVentilationHeatRecovery {
&self,
zone_volume: f64,
throughput_factor: Option<f64>,
_timestep_idx: Option<usize>,
_simtime: Option<SimulationTimeIteration>,
_external_conditions: &ExternalConditions,
) -> f64 {
let throughput_factor = throughput_factor.unwrap_or(1.0);
Expand Down Expand Up @@ -603,14 +601,13 @@ impl VentilationElementBehaviour for WholeHouseExtractVentilation {
&self,
zone_volume: f64,
throughput_factor: Option<f64>,
timestep_index: Option<usize>,
simtime: Option<SimulationTimeIteration>,
external_conditions: &ExternalConditions,
) -> f64 {
let throughput_factor = throughput_factor.unwrap_or(1.0);

let infiltration_rate_adj = self.infiltration_rate
* external_conditions.wind_speed_for_timestep_idx(timestep_index.unwrap())
/ 4.0;
let infiltration_rate_adj =
self.infiltration_rate * external_conditions.wind_speed(&simtime.unwrap()) / 4.0;
let ach = self.air_change_rate(infiltration_rate_adj);
let q_v = air_change_rate_to_flow_rate(ach, zone_volume) * throughput_factor;

Expand Down Expand Up @@ -647,12 +644,11 @@ impl VentilationElementBehaviour for NaturalVentilation {
&self,
zone_volume: f64,
_throughput_factor: Option<f64>,
timestep_idx: Option<usize>,
simtime: Option<SimulationTimeIteration>,
external_conditions: &ExternalConditions,
) -> f64 {
let infiltration_rate_adj = self.infiltration_rate
* external_conditions.wind_speed_for_timestep_idx(timestep_idx.unwrap())
/ 4.0;
let infiltration_rate_adj =
self.infiltration_rate * external_conditions.wind_speed(&simtime.unwrap()) / 4.0;
let ach = self.air_change_rate(infiltration_rate_adj);
let q_v = air_change_rate_to_flow_rate(ach, zone_volume);

Expand Down Expand Up @@ -955,7 +951,7 @@ impl WindowOpeningForCooling {
simtime: SimulationTimeIteration,
external_conditions: &ExternalConditions,
) -> f64 {
let wind_speed = external_conditions.wind_speed_for_timestep_idx(simtime.index);
let wind_speed = external_conditions.wind_speed(&simtime);
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;
Expand Down Expand Up @@ -1019,7 +1015,7 @@ impl WindowOpeningForCooling {
Some(nv) => nv.h_ve_heat_transfer_coefficient(
zone_volume,
None,
Some(simtime.index),
Some(simtime),
external_conditions,
),
None => 0.0,
Expand Down Expand Up @@ -1176,7 +1172,7 @@ mod test {
infiltration_element.h_ve_heat_transfer_coefficient(
75.0,
None,
Some(simtime_step.index),
Some(simtime_step),
&external_conditions,
),
1e6,
Expand Down Expand Up @@ -1324,13 +1320,13 @@ 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!(
round_by_precision(
whole_house_extract_ventilation.h_ve_heat_transfer_coefficient(
75.0,
None,
Some(i),
Some(t_it),
&external_conditions,
),
1e6,
Expand All @@ -1344,7 +1340,7 @@ mod test {
whole_house_extract_ventilation.h_ve_heat_transfer_coefficient(
75.0,
Some(1.2),
Some(i),
Some(t_it),
&external_conditions,
),
1e6,
Expand Down
4 changes: 2 additions & 2 deletions src/core/space_heat_demand/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ fn calc_temperatures(
sum_vent_elements_h_ve += vei.h_ve_heat_transfer_coefficient(
volume,
Some(throughput_factor),
Some(simulation_time.index),
Some(*simulation_time),
external_conditions,
);
}
Expand Down Expand Up @@ -1012,7 +1012,7 @@ fn calc_temperatures(
sum_vent_elements_h_ve_times_temp_supply += vei.h_ve_heat_transfer_coefficient(
volume,
Some(throughput_factor),
Some(simulation_time.index),
Some(*simulation_time),
external_conditions,
) * vei
.temp_supply(*simulation_time, external_conditions);
Expand Down
2 changes: 1 addition & 1 deletion src/external_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl ExternalConditions {
)
}

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

Expand Down

0 comments on commit dfd7b24

Please sign in to comment.