Skip to content

Commit

Permalink
put solar thermal system within arc mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
shieldo committed Apr 19, 2024
1 parent 04b20be commit fabcfb0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
14 changes: 8 additions & 6 deletions src/core/heating_systems/storage_tank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const STORAGE_TANK_TEMP_AMB: f64 = 16.;
#[derive(Clone, Debug)]
pub enum HeatSourceWithStorageTank {
Immersion(Arc<Mutex<ImmersionHeater>>),
Solar(SolarThermalSystem),
Solar(Arc<Mutex<SolarThermalSystem>>),
}

/// An object to represent a hot water storage tank/cylinder
Expand Down Expand Up @@ -353,9 +353,11 @@ impl StorageTank {
let heat_source = &mut *(heat_source.lock());

let energy_potential = match heat_source {
HeatSource::Storage(HeatSourceWithStorageTank::Solar(ref mut solar_heat_source)) => {
HeatSource::Storage(HeatSourceWithStorageTank::Solar(ref solar_heat_source)) => {
// we are passing the storage tank object to the SolarThermal as this needs to call back the storage tank (sic from Python)
solar_heat_source.energy_output_max(self, temp_s3_n, &simulation_time)
solar_heat_source
.lock()
.energy_output_max(self, temp_s3_n, &simulation_time)
}
HeatSource::Storage(HeatSourceWithStorageTank::Immersion(immersion_heater)) => {
// no demand from heat source if the temperature of the tank at the thermostat position is below the set point
Expand Down Expand Up @@ -871,9 +873,9 @@ impl StorageTank {
HeatSource::Storage(HeatSourceWithStorageTank::Immersion(immersion)) => immersion
.lock()
.demand_energy(input_energy_adj, simulation_time_iteration),
HeatSource::Storage(HeatSourceWithStorageTank::Solar(ref mut solar)) => {
solar.demand_energy(input_energy_adj, simulation_time_iteration.index)
}
HeatSource::Storage(HeatSourceWithStorageTank::Solar(solar)) => solar
.lock()
.demand_energy(input_energy_adj, simulation_time_iteration.index),
_ => {
// TODO need to be able to call demand_energy on the other heat sources
let (primary_pipework_losses_kwh, primary_gains) =
Expand Down
46 changes: 24 additions & 22 deletions src/corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2442,9 +2442,9 @@ impl HeatSource {
HeatSourceWithStorageTank::Immersion(imm) => imm
.lock()
.demand_energy(energy_demand, simulation_time_iteration),
HeatSourceWithStorageTank::Solar(ref mut solar) => {
solar.demand_energy(energy_demand, simulation_time_iteration.index)
}
HeatSourceWithStorageTank::Solar(ref solar) => solar
.lock()
.demand_energy(energy_demand, simulation_time_iteration.index),
},
HeatSource::Wet(ref mut wet) => match wet.as_mut() {
HeatSourceWet::WaterCombi(_) => {
Expand Down Expand Up @@ -2716,25 +2716,27 @@ fn heat_source_from_input(
let energy_supply_conn = EnergySupply::connection(energy_supply.clone(), name).unwrap();

Ok((
HeatSource::Storage(HeatSourceWithStorageTank::Solar(SolarThermalSystem::new(
*solar_cell_location,
*area_module,
*modules,
*peak_collector_efficiency,
*incidence_angle_modifier,
*first_order_hlc,
*second_order_hlc,
*collector_mass_flow_rate,
*power_pump,
*power_pump_control,
energy_supply_conn,
*tilt,
*orientation,
*solar_loop_piping_hlc,
external_conditions.clone(),
simulation_time.step_in_hours(),
WATER.clone(),
))),
HeatSource::Storage(HeatSourceWithStorageTank::Solar(Arc::new(Mutex::new(
SolarThermalSystem::new(
*solar_cell_location,
*area_module,
*modules,
*peak_collector_efficiency,
*incidence_angle_modifier,
*first_order_hlc,
*second_order_hlc,
*collector_mass_flow_rate,
*power_pump,
*power_pump_control,
energy_supply_conn,
*tilt,
*orientation,
*solar_loop_piping_hlc,
external_conditions.clone(),
simulation_time.step_in_hours(),
WATER.clone(),
),
)))),
name.into(),
))
}
Expand Down

0 comments on commit fabcfb0

Please sign in to comment.