Skip to content

Commit

Permalink
code qualy+
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rieck committed Oct 18, 2024
1 parent 51206e4 commit 06d6e35
Showing 1 changed file with 53 additions and 129 deletions.
182 changes: 53 additions & 129 deletions hisim/components/heat_distribution_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,15 @@ def __init__(
)

self.theoretical_thermal_building_demand_channel: cp.ComponentInput = self.add_input(
self.component_name,
self.TheoreticalThermalBuildingDemand,
lt.LoadTypes.HEATING,
lt.Units.WATT,
True,
self.component_name, self.TheoreticalThermalBuildingDemand, lt.LoadTypes.HEATING, lt.Units.WATT, True,
)

self.water_temperature_input_channel: cp.ComponentInput = self.add_input(
self.component_name,
self.WaterTemperatureInput,
lt.LoadTypes.WATER,
lt.Units.CELSIUS,
True,
self.component_name, self.WaterTemperatureInput, lt.LoadTypes.WATER, lt.Units.CELSIUS, True,
)

self.residence_temperature_input_channel: cp.ComponentInput = self.add_input(
self.component_name,
self.ResidenceTemperatureIndoorAir,
lt.LoadTypes.TEMPERATURE,
lt.Units.CELSIUS,
True,
self.component_name, self.ResidenceTemperatureIndoorAir, lt.LoadTypes.TEMPERATURE, lt.Units.CELSIUS, True,
)

if self.position_hot_water_storage_in_system in [
Expand All @@ -225,11 +213,7 @@ def __init__(
]:
# just important for heating system without parallel bufferstorage
self.water_mass_flow_rate_hp_in_kg_per_second_channel: cp.ComponentInput = self.add_input(
self.component_name,
self.WaterMassFlowInput,
lt.LoadTypes.WATER,
lt.Units.KG_PER_SEC,
True,
self.component_name, self.WaterMassFlowInput, lt.LoadTypes.WATER, lt.Units.KG_PER_SEC, True,
)

# Outputs
Expand Down Expand Up @@ -275,25 +259,17 @@ def __init__(
if self.position_hot_water_storage_in_system == PositionHotWaterStorageInSystemSetup.PARALLEL:
self.add_default_connections(self.get_default_connections_from_simple_hot_water_storage())

def get_default_connections_from_heat_distribution_controller(
self,
):
def get_default_connections_from_heat_distribution_controller(self,):
"""Get heat distribution controller default connections."""

connections = []
hdsc_classname = HeatDistributionController.get_classname()
connections.append(
cp.ComponentConnection(
HeatDistribution.State,
hdsc_classname,
HeatDistributionController.State,
)
cp.ComponentConnection(HeatDistribution.State, hdsc_classname, HeatDistributionController.State,)
)
return connections

def get_default_connections_from_building(
self,
):
def get_default_connections_from_building(self,):
"""Get building default connections."""

connections = []
Expand All @@ -308,16 +284,12 @@ def get_default_connections_from_building(

connections.append(
cp.ComponentConnection(
HeatDistribution.ResidenceTemperatureIndoorAir,
building_classname,
Building.TemperatureIndoorAir,
HeatDistribution.ResidenceTemperatureIndoorAir, building_classname, Building.TemperatureIndoorAir,
)
)
return connections

def get_default_connections_from_simple_hot_water_storage(
self,
):
def get_default_connections_from_simple_hot_water_storage(self,):
"""Get simple hot water storage default connections."""
# use importlib for importing the other component in order to avoid circular-import errors
component_module_name = "hisim.components.simple_water_storage"
Expand All @@ -334,36 +306,26 @@ def get_default_connections_from_simple_hot_water_storage(
)
return connections

def get_default_connections_from_district_heating(
self,
):
"""Get distrct heating default connections."""
# use importlib for importing the other component in order to avoid circular-import errors
# for district heating as heating source no
component_module_name = "hisim.components.generic_district_heating"
component_module = importlib.import_module(name=component_module_name)
component_class = getattr(component_module, "DistrictHeating")
connections = []
classname = component_class.get_classname()
connections.append(
cp.ComponentConnection(
HeatDistribution.WaterTemperatureInput,
classname,
component_class.WaterOutputTemperature,
)
)
connections.append(
cp.ComponentConnection(
HeatDistribution.WaterMassFlowInput,
classname,
component_class.WaterMassflowOutput,
)
def get_default_connections_from_district_heating(self,):
"""Get distrct heating default connections."""
# use importlib for importing the other component in order to avoid circular-import errors
# for district heating as heating source no
component_module_name = "hisim.components.generic_district_heating"
component_module = importlib.import_module(name=component_module_name)
component_class = getattr(component_module, "DistrictHeating")
connections = []
classname = component_class.get_classname()
connections.append(
cp.ComponentConnection(
HeatDistribution.WaterTemperatureInput, classname, component_class.WaterOutputTemperature,
)
return connections
)
connections.append(
cp.ComponentConnection(HeatDistribution.WaterMassFlowInput, classname, component_class.WaterMassflowOutput,)
)
return connections

def build(
self,
) -> None:
def build(self,) -> None:
"""Build function.
The function sets important constants and parameters for the calculations.
Expand Down Expand Up @@ -467,8 +429,7 @@ def i_simulate(self, timestep: int, stsv: cp.SingleTimeStepValues, force_converg
# thermal_power_delivered_in_watt,
)
stsv.set_output_value(
self.water_mass_flow_channel,
water_mass_flow_rate_in_kg_per_second,
self.water_mass_flow_channel, water_mass_flow_rate_in_kg_per_second,
)

# write values to state
Expand All @@ -477,8 +438,7 @@ def i_simulate(self, timestep: int, stsv: cp.SingleTimeStepValues, force_converg
self.state.thermal_power_delivered_in_watt = thermal_power_delivered_in_watt

def determine_water_temperature_input_output_effective_thermal_power_without_massflow(
self,
residence_temperature_in_celsius: float,
self, residence_temperature_in_celsius: float,
) -> Any:
"""Calculate cooled or heated water temperature due to free convection after heat exchange between heat distribution system and building without massflow."""

Expand Down Expand Up @@ -552,8 +512,7 @@ def determine_water_temperature_output_after_heat_exchange_with_building_and_eff
if water_temperature_input_in_celsius > residence_temperature_in_celsius:
# prevent that water output temperature in hds gets colder than residence temperature in building when heating
water_temperature_output_in_celsius = max(
water_temperature_output_in_celsius,
residence_temperature_in_celsius,
water_temperature_output_in_celsius, residence_temperature_in_celsius,
)
thermal_power_delivered_effective_in_watt = (
self.specific_heat_capacity_of_water_in_joule_per_kilogram_per_celsius
Expand All @@ -570,8 +529,7 @@ def determine_water_temperature_output_after_heat_exchange_with_building_and_eff
if water_temperature_input_in_celsius < residence_temperature_in_celsius:
# prevent that water output temperature in hds gets hotter than residence temperature in building when cooling
water_temperature_output_in_celsius = min(
water_temperature_output_in_celsius,
residence_temperature_in_celsius,
water_temperature_output_in_celsius, residence_temperature_in_celsius,
)
thermal_power_delivered_effective_in_watt = (
self.specific_heat_capacity_of_water_in_joule_per_kilogram_per_celsius
Expand All @@ -598,7 +556,9 @@ def determine_water_temperature_output_after_heat_exchange_with_building_and_eff
)

@staticmethod
def get_cost_capex(config: HeatDistributionConfig, simulation_parameters: SimulationParameters) -> CapexCostDataClass:
def get_cost_capex(
config: HeatDistributionConfig, simulation_parameters: SimulationParameters
) -> CapexCostDataClass:
"""Returns investment cost, CO2 emissions and lifetime."""
seconds_per_year = 365 * 24 * 60 * 60
capex_per_simulated_period = (config.cost / config.lifetime) * (
Expand All @@ -614,15 +574,11 @@ def get_cost_capex(config: HeatDistributionConfig, simulation_parameters: Simula
lifetime_in_years=config.lifetime,
capex_investment_cost_for_simulated_period_in_euro=capex_per_simulated_period,
device_co2_footprint_for_simulated_period_in_kg=device_co2_footprint_per_simulated_period,
kpi_tag=KpiTagEnumClass.HEAT_DISTRIBUTION_SYSTEM
kpi_tag=KpiTagEnumClass.HEAT_DISTRIBUTION_SYSTEM,
)
return capex_cost_data_class

def get_cost_opex(
self,
all_outputs: List,
postprocessing_results: pd.DataFrame,
) -> OpexCostDataClass:
def get_cost_opex(self, all_outputs: List, postprocessing_results: pd.DataFrame,) -> OpexCostDataClass:
# pylint: disable=unused-argument
"""Calculate OPEX costs, consisting of maintenance costs for Heat Distribution System."""
opex_cost_data_class = OpexCostDataClass(
Expand All @@ -631,16 +587,12 @@ def get_cost_opex(
co2_footprint_in_kg=0,
consumption_in_kwh=0,
loadtype=lt.LoadTypes.ANY,
kpi_tag=KpiTagEnumClass.HEAT_DISTRIBUTION_SYSTEM
kpi_tag=KpiTagEnumClass.HEAT_DISTRIBUTION_SYSTEM,
)

return opex_cost_data_class

def get_component_kpi_entries(
self,
all_outputs: List,
postprocessing_results: pd.DataFrame,
) -> List[KpiEntry]:
def get_component_kpi_entries(self, all_outputs: List, postprocessing_results: pd.DataFrame,) -> List[KpiEntry]:
"""Calculates KPIs for the respective component and return all KPI entries as list."""

thermal_output_energy_in_kilowatt_hour: Optional[float] = None
Expand Down Expand Up @@ -894,18 +846,10 @@ def __init__(

# Inputs
self.theoretical_thermal_building_demand_channel: cp.ComponentInput = self.add_input(
self.component_name,
self.TheoreticalThermalBuildingDemand,
lt.LoadTypes.HEATING,
lt.Units.WATT,
True,
self.component_name, self.TheoreticalThermalBuildingDemand, lt.LoadTypes.HEATING, lt.Units.WATT, True,
)
self.daily_avg_outside_temperature_input_channel: cp.ComponentInput = self.add_input(
self.component_name,
self.DailyAverageOutsideTemperature,
lt.LoadTypes.TEMPERATURE,
lt.Units.CELSIUS,
True,
self.component_name, self.DailyAverageOutsideTemperature, lt.LoadTypes.TEMPERATURE, lt.Units.CELSIUS, True,
)
self.building_temperature_modifier_channel: cp.ComponentInput = self.add_input(
self.component_name,
Expand Down Expand Up @@ -951,9 +895,7 @@ def __init__(
self.add_default_connections(self.get_default_connections_from_weather())
self.add_default_connections(self.get_default_connections_from_energy_management_system())

def get_default_connections_from_weather(
self,
):
def get_default_connections_from_weather(self,):
"""Get weather default connections."""

connections = []
Expand All @@ -967,9 +909,7 @@ def get_default_connections_from_weather(
)
return connections

def get_default_connections_from_building(
self,
):
def get_default_connections_from_building(self,):
"""Get building default connections."""

connections = []
Expand All @@ -983,9 +923,7 @@ def get_default_connections_from_building(
)
return connections

def get_default_connections_from_energy_management_system(
self,
):
def get_default_connections_from_energy_management_system(self,):
"""Get energy management system default connections."""
# use importlib for importing the other component in order to avoid circular-import errors
component_module_name = "hisim.components.controller_l2_energy_management_system"
Expand Down Expand Up @@ -1068,10 +1006,8 @@ def i_simulate(self, timestep: int, stsv: cp.SingleTimeStepValues, force_converg
)
self.building_temperature_modifier = stsv.get_input_value(self.building_temperature_modifier_channel)

list_of_heating_distribution_system_flow_and_return_temperatures = (
self.calc_heat_distribution_flow_and_return_temperatures(
daily_avg_outside_temperature_in_celsius=daily_avg_outside_temperature_in_celsius
)
list_of_heating_distribution_system_flow_and_return_temperatures = self.calc_heat_distribution_flow_and_return_temperatures(
daily_avg_outside_temperature_in_celsius=daily_avg_outside_temperature_in_celsius
)

self.conditions_for_opening_or_shutting_heat_distribution(
Expand Down Expand Up @@ -1121,8 +1057,7 @@ def i_simulate(self, timestep: int, stsv: cp.SingleTimeStepValues, force_converg
)

def conditions_for_opening_or_shutting_heat_distribution(
self,
theoretical_thermal_building_demand_in_watt: float,
self, theoretical_thermal_building_demand_in_watt: float,
) -> None:
"""Set conditions for the valve in heat distribution."""

Expand All @@ -1143,9 +1078,7 @@ def conditions_for_opening_or_shutting_heat_distribution(
raise ValueError("unknown hds controller mode.")

def summer_heating_condition(
self,
daily_average_outside_temperature_in_celsius: float,
set_heating_threshold_temperature_in_celsius: float,
self, daily_average_outside_temperature_in_celsius: float, set_heating_threshold_temperature_in_celsius: float,
) -> str:
"""Set conditions for the valve in heat distribution."""

Expand Down Expand Up @@ -1242,26 +1175,20 @@ def calc_heat_distribution_flow_and_return_temperatures(

return list_of_heating_flow_and_return_temperature_in_celsius

def get_cost_opex(
self,
all_outputs: List,
postprocessing_results: pd.DataFrame,
) -> cp.OpexCostDataClass:
def get_cost_opex(self, all_outputs: List, postprocessing_results: pd.DataFrame,) -> cp.OpexCostDataClass:
"""Calculate OPEX costs, consisting of electricity costs and revenues."""
opex_cost_data_class = cp.OpexCostDataClass.get_default_opex_cost_data_class()
return opex_cost_data_class

@staticmethod
def get_cost_capex(config: HeatDistributionControllerConfig, simulation_parameters: SimulationParameters) -> CapexCostDataClass: # pylint: disable=unused-argument
def get_cost_capex(
config: HeatDistributionControllerConfig, simulation_parameters: SimulationParameters
) -> CapexCostDataClass: # pylint: disable=unused-argument
"""Returns investment cost, CO2 emissions and lifetime."""
capex_cost_data_class = CapexCostDataClass.get_default_capex_cost_data_class()
return capex_cost_data_class

def get_component_kpi_entries(
self,
all_outputs: List,
postprocessing_results: pd.DataFrame,
) -> List[KpiEntry]:
def get_component_kpi_entries(self, all_outputs: List, postprocessing_results: pd.DataFrame,) -> List[KpiEntry]:
"""Calculates KPIs for the respective component and return all KPI entries as list."""
return []

Expand Down Expand Up @@ -1346,10 +1273,7 @@ def prepare_calc_heating_dist_temperature(
self.max_flow_temperature_in_celsius - self.max_return_temperature_in_celsius
)

def calc_heating_distribution_system_water_mass_flow_rate(
self,
max_thermal_building_demand_in_watt: float,
) -> Any:
def calc_heating_distribution_system_water_mass_flow_rate(self, max_thermal_building_demand_in_watt: float,) -> Any:
"""Calculate water mass flow between heating distribution system and hot water storage."""
specific_heat_capacity_of_water_in_joule_per_kg_per_celsius = (
PhysicsConfig.water_specific_heat_capacity_in_joule_per_kilogram_per_kelvin
Expand Down

0 comments on commit 06d6e35

Please sign in to comment.