Skip to content

Commit

Permalink
EC-112 Finish porting emitters logic in corpus
Browse files Browse the repository at this point in the history
Co-authored-by: Russ Penska <[email protected]>
Co-authored-by: Korinna Pinakoulaki <[email protected]>
  • Loading branch information
3 people committed Oct 11, 2024
1 parent bfb3190 commit 86b88a1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
20 changes: 20 additions & 0 deletions src/core/heating_systems/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,27 @@ impl HeatSourceWet {
pub enum SpaceHeatSystem {
Instant(InstantElecHeater),
WarmAir(HeatPumpServiceSpaceWarmAir),
WetDistribution(Emitters),
}

impl SpaceHeatSystem {
pub fn temp_setpnt(&self, simulation_time_iteration: SimulationTimeIteration) -> Option<f64> {
match self {
SpaceHeatSystem::Instant(instant) => instant.temp_setpnt(&simulation_time_iteration),
SpaceHeatSystem::WarmAir(warm_air) => warm_air.temp_setpnt(&simulation_time_iteration),
SpaceHeatSystem::WetDistribution(wet_distribution) => {
wet_distribution.temp_setpnt(&simulation_time_iteration)
}
}
}

pub fn frac_convective(&self) -> f64 {
match self {
SpaceHeatSystem::Instant(instant) => instant.frac_convective(),
SpaceHeatSystem::WarmAir(warm_air) => warm_air.frac_convective(),
SpaceHeatSystem::WetDistribution(wet_distribution) => {
wet_distribution.frac_convective()
}
}
}

Expand All @@ -125,6 +132,12 @@ impl SpaceHeatSystem {
space_heat_running_time_cumulative,
simulation_time_iteration,
),
SpaceHeatSystem::WetDistribution(wet_distribution) => wet_distribution
.running_time_throughput_factor(
energy_demand,
space_heat_running_time_cumulative,
simulation_time_iteration,
),
}
}

Expand All @@ -140,6 +153,9 @@ impl SpaceHeatSystem {
SpaceHeatSystem::WarmAir(ref mut warm_air) => {
warm_air.demand_energy(energy_demand, simulation_time_iteration)?
}
SpaceHeatSystem::WetDistribution(ref mut wet_distribution) => {
wet_distribution.demand_energy(energy_demand, simulation_time_iteration)?
}
})
}

Expand All @@ -154,6 +170,9 @@ impl SpaceHeatSystem {
SpaceHeatSystem::WarmAir(warm_air) => {
warm_air.in_required_period(&simulation_time_iteration)
}
SpaceHeatSystem::WetDistribution(emitters) => {
emitters.in_required_period(&simulation_time_iteration)
}
}
}
}
Expand Down Expand Up @@ -272,4 +291,5 @@ impl SpaceHeatingService {

use anyhow::Error;

use super::emitters::Emitters;
use super::heat_pump::{BufferTankEmittersData, BufferTankEmittersDataWithResult};
25 changes: 6 additions & 19 deletions src/core/heating_systems/emitters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ pub fn convert_flow_to_return_temp(flow_temp_celsius: f64) -> f64 {
(6.0 / 7.0) * flow_temp_celsius
}

#[derive(Clone)]
pub struct Emitters {
pub thermal_mass: f64,
pub c: f64,
pub n: f64,
temp_diff_emit_dsgn: f64,
_temp_diff_emit_dsgn: f64,
frac_convective: f64,
heat_source: Arc<RwLock<SpaceHeatingService>>,
temp_internal_air_fn: TempInternalAirFn,
Expand All @@ -46,7 +47,6 @@ pub struct Emitters {
max_outdoor_temp: Option<f64>,
min_flow_temp: Option<f64>,
max_flow_temp: Option<f64>,
simulation_timestep: f64,
temp_emitter_prev: f64,
target_flow_temp: Option<f64>, // In Python this is set from inside demand energy and does not exist before then
}
Expand Down Expand Up @@ -134,7 +134,6 @@ impl Emitters {
external_conditions: Arc<ExternalConditions>,
ecodesign_controller: EcoDesignController,
design_flow_temp: f64,
simulation_timestep: f64,
with_buffer_tank: bool,
) -> Self {
let ecodesign_controller_class = ecodesign_controller.ecodesign_control_class;
Expand All @@ -158,7 +157,7 @@ impl Emitters {
thermal_mass,
c,
n,
temp_diff_emit_dsgn,
_temp_diff_emit_dsgn: temp_diff_emit_dsgn,
frac_convective,
heat_source,
temp_internal_air_fn,
Expand All @@ -170,7 +169,6 @@ impl Emitters {
max_outdoor_temp,
min_flow_temp,
max_flow_temp,
simulation_timestep,
temp_emitter_prev: 20.0,
target_flow_temp: None,
}
Expand Down Expand Up @@ -391,7 +389,7 @@ impl Emitters {

let _ = stepper.integrate();

let mut temp_emitter = 0.;
let temp_emitter;
let mut time_temp_diff_max_reached: Option<f64> = None;

let y_count = stepper.y_out().len();
Expand Down Expand Up @@ -571,7 +569,7 @@ impl Emitters {
/// Demand energy from emitters and calculate how much energy can be provided
/// Arguments:
/// energy_demand -- in kWh
fn demand_energy(
pub(crate) fn demand_energy(
&mut self,
energy_demand: f64,
simulation_time: SimulationTimeIteration,
Expand Down Expand Up @@ -674,7 +672,7 @@ impl Emitters {
/// energy_demand -- in kWh
/// space_heat_running_time_cumulative
/// -- running time spent on higher-priority space heating services
fn running_time_throughput_factor(
pub(crate) fn running_time_throughput_factor(
&self,
energy_demand: f64,
space_heat_running_time_cumulative: f64,
Expand Down Expand Up @@ -723,15 +721,10 @@ mod tests {

use crate::core::controls::time_control::Control;
use crate::core::controls::time_control::OnOffTimeControl;
use crate::core::energy_supply;
use crate::core::energy_supply::energy_supply::EnergySupply;
use crate::core::energy_supply::energy_supply::EnergySupplyConnection;
use crate::core::heating_systems::boiler::Boiler;
use crate::core::heating_systems::boiler::BoilerServiceSpace;
use crate::core::heating_systems::boiler::BoilerServiceWaterRegular;
use crate::core::heating_systems::common::HeatSourceWet;
use crate::core::space_heat_demand::zone::Zone;
use crate::corpus::HeatSource;
use crate::external_conditions::DaylightSavingsConfig;
use crate::external_conditions::ShadingSegment;
use crate::input::EnergySupplyType;
Expand Down Expand Up @@ -894,7 +887,6 @@ mod tests {
pub(crate) fn emitters(
heat_source: SpaceHeatingService,
external_conditions: ExternalConditions,
simulation_time: SimulationTime,
) -> Emitters {
let thermal_mass = 0.14;
let c = 0.08;
Expand Down Expand Up @@ -924,7 +916,6 @@ mod tests {
external_conditions.into(),
ecodesign_controller,
design_flow_temp,
simulation_time.step,
with_buffer_tank,
)
}
Expand Down Expand Up @@ -1009,7 +1000,6 @@ mod tests {
external_conditions.clone().into(),
ecodesign_controller,
55.,
1.,
false,
);

Expand Down Expand Up @@ -1038,7 +1028,6 @@ mod tests {
external_conditions.into(),
ecodesign_controller,
55.,
1.,
false,
);

Expand All @@ -1059,7 +1048,6 @@ mod tests {
/// Test emitter output at given emitter and room temp
#[rstest]
fn test_power_output_emitter(
simulation_time_iterator: SimulationTimeIterator,
heat_source: SpaceHeatingService,
external_conditions: ExternalConditions,
) {
Expand All @@ -1083,7 +1071,6 @@ mod tests {
external_conditions.into(),
ecodesign_controller,
55.0,
1.,
false,
);

Expand Down
14 changes: 12 additions & 2 deletions src/corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::core::energy_supply::energy_supply::{
use crate::core::energy_supply::pv::PhotovoltaicSystem;
use crate::core::heating_systems::boiler::{Boiler, BoilerServiceWaterCombi};
use crate::core::heating_systems::common::{HeatSourceWet, SpaceHeatSystem, SpaceHeatingService};
use crate::core::heating_systems::emitters::Emitters;
use crate::core::heating_systems::heat_battery::HeatBattery;
use crate::core::heating_systems::heat_network::{HeatNetwork, HeatNetworkServiceWaterDirect};
use crate::core::heating_systems::heat_pump::{
Expand Down Expand Up @@ -348,6 +349,11 @@ impl Corpus {
&heat_system_name_for_zone,
&zones,
&heat_sources_wet_with_buffer_tank,
TempInternalAirAccessor {
zones: zones.clone(),
total_volume,
},
external_conditions.clone(),
)?)
})
.transpose()?
Expand Down Expand Up @@ -4210,6 +4216,8 @@ fn space_heat_systems_from_input(
heat_system_name_for_zone: &IndexMap<String, String>,
zones: &Arc<IndexMap<String, Zone>>,
heat_sources_wet_with_buffer_tank: &Vec<String>,
temp_internal_air_accessor: TempInternalAirAccessor,
external_conditions: Arc<ExternalConditions>,
) -> anyhow::Result<SpaceHeatSystemsWithEnergyConnections> {
let mut energy_conn_names_for_systems: IndexMap<String, String> = Default::default();
let space_heat_systems = input
Expand Down Expand Up @@ -4241,7 +4249,7 @@ fn space_heat_systems_from_input(
))
},
SpaceHeatSystemDetails::ElectricStorageHeater { .. } => unimplemented!(), // requires implementation of ElecStorageHeater, make sure to add energy supply conn name to energy_conn_names_for_systems collection
SpaceHeatSystemDetails::WetDistribution { heat_source, temp_diff_emit_dsgn, control, .. } => {
SpaceHeatSystemDetails::WetDistribution { heat_source, temp_diff_emit_dsgn, control, thermal_mass, c, n, frac_convective, ecodesign_controller, design_flow_temp, .. } => {
let heat_source_name = &heat_source.name;
let temp_flow_limit_upper = &heat_source.temp_flow_limit_upper;

Expand Down Expand Up @@ -4293,7 +4301,9 @@ fn space_heat_systems_from_input(
unimplemented!()
}
};
todo!("Currently working on Emitters")
let temp_internal_air_fn = temp_internal_air_fn(temp_internal_air_accessor.clone());
let space_heater = Emitters::new(*thermal_mass, *c, *n, *temp_diff_emit_dsgn, *frac_convective, Arc::new(RwLock::new(heat_source_service)), temp_internal_air_fn, external_conditions.clone(), *ecodesign_controller, *design_flow_temp as f64, with_buffer_tank);
SpaceHeatSystem::WetDistribution(space_heater)
}
SpaceHeatSystemDetails::WarmAir {
frac_convective,
Expand Down
4 changes: 2 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ pub struct SpaceHeatSystemHeatSource {
}

// it is unclear whether this struct should be used - see reference to the struct above
#[derive(Debug, Deserialize)]
#[derive(Clone, Copy, Debug, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[allow(dead_code)]
Expand All @@ -1479,7 +1479,7 @@ pub(crate) struct EcoDesignController {
pub(crate) min_flow_temp: Option<f64>,
}

#[derive(Debug, Deserialize_repr, PartialEq)]
#[derive(Clone, Copy, Debug, Deserialize_repr, PartialEq)]
#[repr(u8)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
Expand Down

0 comments on commit 86b88a1

Please sign in to comment.