From 06d6e35a6047d9f654cebea24c07717abaf237f2 Mon Sep 17 00:00:00 2001 From: "k.rieck" Date: Fri, 18 Oct 2024 17:52:57 +0200 Subject: [PATCH] code qualy+ --- hisim/components/heat_distribution_system.py | 182 ++++++------------- 1 file changed, 53 insertions(+), 129 deletions(-) diff --git a/hisim/components/heat_distribution_system.py b/hisim/components/heat_distribution_system.py index e31f4a874..90717e478 100644 --- a/hisim/components/heat_distribution_system.py +++ b/hisim/components/heat_distribution_system.py @@ -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 [ @@ -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 @@ -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 = [] @@ -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" @@ -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. @@ -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 @@ -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.""" @@ -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 @@ -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 @@ -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) * ( @@ -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( @@ -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 @@ -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, @@ -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 = [] @@ -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 = [] @@ -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" @@ -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( @@ -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.""" @@ -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.""" @@ -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 [] @@ -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