def __init__(self, environment, net_floor_area=None, occupancy=None): """ Parameter --------- environment : Environment object Common to all other objects. Includes time and weather instances net_floor_area : float, optional Net floor area of apartment in m^2 (default: None) occupancy : object Occupancy object of pycity (default: None) """ self.environment = environment self._kind = "apartment" self.net_floor_area = net_floor_area self.occupancy = occupancy # Create empty power curves self.power_el = ElecDemand.ElectricalDemand(environment, method=0, annualDemand=0) self.demandDomesticHotWater = DHW.DomesticHotWater(environment, tFlow=0, method=1, dailyConsumption=0, supplyTemperature=0) self.demandSpaceheating = SpaceHeat.SpaceHeating(environment, method=1, livingArea=0, specificDemand=0) self.rooms = []
def run_test(): # Generate environment timer = pycity_base.classes.Timer.Timer() weather = pycity_base.classes.Weather.Weather(timer) prices = pycity_base.classes.Prices.Prices() environment = pycity_base.classes.Environment.Environment( timer, weather, prices) # Generate heat demand object heat_demand = SpaceHeating.SpaceHeating( environment, method=1, # Standard load profile livingArea=146, specificDemand=166) # Generate electrical demand object el_demand = ElectricalDemand.ElectricalDemand( environment, method=1, # Standard load profile annualDemand=3000) # Generate hot water demand object (based on Annex 42 profiles) dhw_annex42 = DomesticHotWater.DomesticHotWater( environment, tFlow=60, thermal=True, method=1, # Annex 42 dailyConsumption=70, supplyTemperature=25) # Initialize apartment object apartment = Apartment.Apartment(environment) # Add entities to apartment object entities = [heat_demand, el_demand, dhw_annex42] apartment.addMultipleEntities(entities) print('Get all power curves of apartment (for current horizon):') print(apartment.get_power_curves()) print() print('Get space heating power curve for whole year:') print(apartment.get_space_heat_power_curve(current_values=True)) print() print('Get electrical power curve for whole year:') print(sum(apartment.get_el_power_curve(current_values=True))) print() print('Get hot water power curve for whole year:') print(apartment.get_dhw_power_curve(current_values=True)) print() print('Get water demand curve for whole year:') print( sum(apartment.get_water_demand_curve(current_values=True)) * 180 * 900) print()
def test_method0(self, create_environment): # energy comparison array load_array = np.array([10, 10, 10, 10, 20, 20, 20, 20]) el_demand_object = ED.ElectricalDemand(create_environment, method=0, loadcurve=load_array) el_load_curve = el_demand_object.get_power() # Compare arrays np.testing.assert_equal(el_load_curve, load_array)
def test_method3(self, create_environment, create_occupancy): """ Pytest method for stochastic load profiles with normalization to annual demand Parameters ---------- create_environment : object Environment object (as fixture of pytest) create_occupancy : object occupancy object """ ann_demand = 3000 # Occupancy profile occupancy_profile = create_occupancy.occupancy max_occ = np.max(occupancy_profile) el_dem_stochastic = ED.ElectricalDemand(create_environment, annualDemand=ann_demand, method=2, total_nb_occupants=max_occ, randomizeAppliances=False, lightConfiguration=10, occupancy=occupancy_profile, do_normalization=True) # Get space heating load curve (in W) per timestep (1 minute) el_load_curve = el_dem_stochastic.get_power(currentValues=False) # Convert power to energy values (W to Ws) el_en_demand_curve = create_environment.timer.timeDiscretization * \ el_load_curve # Calculate electric energy demand value in kWh el_en_demand_curve = el_en_demand_curve / (1000 * 3600) el_en_demand_value = sum(el_en_demand_curve) print('Electrical demand value for 1 person apartment for ' + 'one year in kWh/a') print(el_en_demand_value) assert ann_demand - el_en_demand_value <= 0.001 * ann_demand
def test_method1(self, create_environment): # Standard load profile # Generate electrical demand object el_demand_object = ED.ElectricalDemand(create_environment, method=1, profileType="H0", annualDemand=3000) # Get space heating load curve (in W) per timestep el_load_curve = el_demand_object.get_power(currentValues=False) # Convert power to energy values (W to Ws) el_en_demand_curve = create_environment.timer.timeDiscretization * \ el_load_curve # Calculate electric energy demand value in kWh el_en_demand_curve = el_en_demand_curve / (1000 * 3600) el_en_demand_value = np.sum(el_en_demand_curve) # Check if sum of energy demand values is (almost) equal to input assert abs(el_en_demand_value - 3000) <= 0.001 * 3000
def run_single_calc(number_of_occupants, randomize_appliances, environment, prev_heat_dev=False, app_filename=None, light_filename=None): """ Parameters ---------- number_of_occupants randomize_appliances environment prev_heat_dev : bool, optional Defines, if heating devices should be prevented within chosen appliances (default: False). If set to True, DESWH, E-INST, Electric shower, Storage heaters and Other electric space heating are set to zero. Only relevant for method == 2 app_filename : str, optional Path to Appliances file (default: None). If set to None, uses default file Appliances.csv in \inputs\stochastic_electrical_load\. Only relevant, if method == 2. light_filename : str, optional Path to Lighting configuration file (default: None). If set to None, uses default file Appliances.csv in \inputs\stochastic_electrical_load\. Only relevant, if method == 2. """ occupancy = pycity_base.classes.demand.Occupancy.Occupancy(environment, number_occupants=number_of_occupants) el_load = ED.ElectricalDemand(environment, method=2, total_nb_occupants=number_of_occupants, randomizeAppliances=randomize_appliances, lightConfiguration=10, occupancy=occupancy.occupancy, prev_heat_dev=prev_heat_dev, app_filename=app_filename, light_filename=light_filename) return el_load
def create_demands(create_environment): """ Fixture to create space heating, dhw and electrical demands (for residential buildings; with standardized load profiles (SLP)) Parameters ---------- create_environment : object Environment object (as fixture of pytest) Returns ------- create_demands : tuple (of np.arrays) Tuple with demand arrays (heat_demand, el_demand, dhw_demand) """ # Generate heating demand heat_demand = SpaceHeating.SpaceHeating(create_environment, method=1, # Standard load profile livingArea=100, specificDemand=150) el_demand = ElectricalDemand.ElectricalDemand(create_environment, method=1, # Standard load profile annualDemand=3000) daily_consumption = 70 t_flow = 70 supply_temp = 25 dhw_annex42 = DomesticHotWater.DomesticHotWater(create_environment, tFlow=t_flow, thermal=True, method=1, # Annex 42 dailyConsumption=daily_consumption, supplyTemperature=supply_temp) create_demands = (heat_demand, el_demand, dhw_annex42) return create_demands
co2capseq=co2capseq.co2capseq(environment, maxinput=10000000,maxelimination=0.8,rate=3 ) """ lines modified till here""" #Buildings #Standard demand profiles # Generate heat demand curve for space heating heat_demand = SpaceHeating.SpaceHeating(environment, method=1, # Standard load profile livingArea=146, specificDemand=166) # Generate electrical demand curve el_demand = ElectricalDemand.ElectricalDemand(environment, method=1, # Standard load profile annualDemand=3000) # Generate domestic hot water demand curve dhw_annex42 = DomesticHotWater.DomesticHotWater(environment, tFlow=60, thermal=True, method=1, # Annex 42 dailyConsumption=70, supplyTemperature=25) # Generate apartment and add demand durves apartment = Apartment.Apartment(environment) apartment.addEntity(heat_demand) apartment.addMultipleEntities([el_demand, dhw_annex42])
def run_city_generator(gen_mo=0, input_name='test_city_mixed_buildings.txt', output_name=None, use_el_slp=True, gen_dhw_profile=False): """ Function to generate and return city district object Parameters ---------- gen_mo : int, optional Generation mode number: 0 - Use data from input file (default) input_name : str, optional Name of input data file (default: 'test_city_only_buildings.txt') output_name : str, optional Name of output file (default: None) If output_name is None, no output file is generated. Else: Pickled output file is saved to output folder use_el_slp : bool, optional Boolean to define, how electrical load profile should be generated (default: True) True: Generate el. load profile via el. slp False: Use stochastic profile generator ( only valid for residential buildings!) gen_dhw_profile : bool, optional Boolean to define, if domestic hot water profile should be generated (default: False) True: Generate dhw profile (valid for residential buildings!) False: Do not generate dhw profile Returns ------- city_district : object CityDistrict object of PyCity """ # Generate timer, weather and price objects timer = pycity_base.classes.Timer.Timer() weather = pycity_base.classes.Weather.Weather(timer) prices = pycity_base.classes.Prices.Prices() # Generate environment environment = pycity_base.classes.Environment.Environment(timer, weather, prices) # Generate city district object city_district = citydis.CityDistrict(environment) # Current file path curr_path = os.path.dirname(os.path.abspath(__file__)) # Choose city district generation method if gen_mo == 0: # Load data from file import_path = os.path.join(curr_path, 'input', input_name) city_dist_pandas_dataframe = pandas.read_csv(import_path, sep='\t') for index, row in city_dist_pandas_dataframe.iterrows(): curr_name = row['name'] # Building name curr_x = row['x_coord / m'] # Building x coordinate in m curr_y = row['y_coord / m'] # Building y coordinate in m curr_area = row[ 'living_area / m2'] # Net floor area (respectively living area) in m2 curr_th_spec_demand = row[ 'specific_th_demand / kWh/m2a'] # Spec. thermal energy demand in kWh/m2a curr_el_demand = row[ 'an_el_demand / kWh/a'] # Annual electric energy demand in kWh/a curr_th_slp = row['th_slp_profile_type'] # Thermal SLP type curr_el_slp = row['el_slp_profile_type'] # Electrical SLP type curr_total_nb_occupants = row[ 'total_nb_occupants'] # Total number of occupants in building # Assert input values assert curr_area > 0 assert curr_th_spec_demand > 0 assert curr_el_demand > 0 print('Processing building', curr_name) # Check if number of occupants is nan # (for non residential buildings) if math.isnan(curr_total_nb_occupants): curr_total_nb_occupants = None # Replace nan with None else: # If number of occupants is not nan, convert value # to integer curr_total_nb_occupants = int(curr_total_nb_occupants) assert curr_total_nb_occupants >= 1 assert curr_total_nb_occupants <= 5 # Generate heat demand curve for space heating heat_demand = \ SpaceHeating.SpaceHeating(environment, method=1, # Standard load profile livingArea=curr_area, specificDemand=curr_th_spec_demand, profile_type=curr_th_slp) if use_el_slp: # Use el. SLP el_method = 1 occupancy_profile = [] # Dummy value else: # Stochastic profile generator # (only for residential buildings) el_method = 2 # Generate stochastic occupancy profile occupancy_object = \ occu.Occupancy(environment, number_occupants=curr_total_nb_occupants) occupancy_profile = occupancy_object.occupancy # Generate electrical demand curve el_demand = \ ElectricalDemand.ElectricalDemand(environment, method=el_method, annualDemand=curr_el_demand, profileType=curr_el_slp, singleFamilyHouse=True, total_nb_occupants=curr_total_nb_occupants, randomizeAppliances=True, lightConfiguration=0, occupancy=occupancy_profile) # Generate apartment and add demand durves apartment = Apartment.Apartment(environment) apartment.addMultipleEntities([heat_demand, el_demand]) if gen_dhw_profile: # Generate domestic hot water demand curve dhw_annex42 = \ DomesticHotWater.DomesticHotWater(environment, tFlow=60, thermal=True, method=1, # Annex 42 dailyConsumption=70, supplyTemperature=25) apartment.addEntity(dhw_annex42) # Generate heating curve heatingCurve = HeatingCurve.HeatingCurve(environment) # Generate building and add apartment and heating curve building = Building.Building(environment) entities = [apartment, heatingCurve] building.addMultipleEntities(entities) # Generate shapely point positions position = point.Point(curr_x, curr_y) # Add buildings to city district city_district.addEntity(entity=building, position=position, name=curr_name) print('Added building', curr_name, ' to city district.') # Save results as pickled file if output_name is not None: output_path = os.path.join(curr_path, 'output', output_name) # Pickle and dump city objects pickle.dump(city_district, open(output_path, 'wb')) print('Pickled and dumped city object') return city_district
def run_test(): timer = pycity_base.classes.Timer.Timer() weather = pycity_base.classes.Weather.Weather(timer) prices = pycity_base.classes.Prices.Prices() environment = pycity_base.classes.Environment.Environment( timer, weather, prices) heat_demand = SpaceHeating.SpaceHeating( environment, method=1, # Standard load profile livingArea=146, specificDemand=166) el_demand = ElectricalDemand.ElectricalDemand( environment, method=1, # Standard load profile annualDemand=3000) dhw_annex42 = DomesticHotWater.DomesticHotWater( environment, tFlow=60, thermal=True, method=1, # Annex 42 dailyConsumption=70, supplyTemperature=25) apartment = Apartment.Apartment(environment) apartment.addEntity(heat_demand) apartment.addMultipleEntities([el_demand, dhw_annex42]) # Heatpump data path src_path = os.path.dirname(os.path.dirname(__file__)) hp_data_path = os.path.join(src_path, 'inputs', 'heat_pumps.xlsx') heatpumpData = xlrd.open_workbook(hp_data_path) dimplex_LA12TU = heatpumpData.sheet_by_name("Dimplex_LA12TU") # Size of the worksheet number_rows = dimplex_LA12TU._dimnrows number_columns = dimplex_LA12TU._dimncols # Flow, ambient and max. temperatures tFlow = np.zeros(number_columns - 2) tAmbient = np.zeros(int((number_rows - 7) / 2)) tMax = dimplex_LA12TU.cell_value(0, 1) firstRowCOP = number_rows - len(tAmbient) qNominal = np.empty((len(tAmbient), len(tFlow))) cop = np.empty((len(tAmbient), len(tFlow))) for i in range(number_columns - 2): tFlow[i] = dimplex_LA12TU.cell_value(3, 2 + i) for col in range(len(tFlow)): for row in range(len(tAmbient)): qNominal[row, col] = dimplex_LA12TU.cell_value(int(4 + row), int(2 + col)) cop[row, col] = dimplex_LA12TU.cell_value(int(firstRowCOP + row), int(2 + col)) pNominal = qNominal / cop # Create HP lower_activation_limit = 0.5 heatpump = HeatPump.Heatpump(environment, tAmbient, tFlow, qNominal, pNominal, cop, tMax, lower_activation_limit) bes = BES.BES(environment) bes.addDevice(heatpump) heatingCurve = HeatingCurve.HeatingCurve(environment) building = Building.Building(environment) entities = [apartment, bes, heatingCurve] building.addMultipleEntities(entities) print() print(building.get_power_curves()) print() print(building.getHeatpumpNominals()) print() print(building.flowTemperature) print(building.get_space_heating_power_curve()) print(len(building.get_space_heating_power_curve())) print(building.get_electric_power_curve()) print(len(building.get_electric_power_curve())) print(building.get_dhw_power_curve()) print(len(building.get_dhw_power_curve()))
def generate_profile_pool(path=None, runs=100, timestep=60): """ Generates profile pool in subfolder profile (if no profile pool exists) (occupancy, electrical, dhw) Parameters ---------- path : str, optional Path to save profile pool to (default: None). If set to None, uses subfolder .../profiles/ to store profiles to runs : int, optional Number of loops used to generate profile pool (default: 100) timestep : int, optional Time discretization for environment in seconds (default: 60) """ if path is None: path = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(path, 'profiles') else: # path is given by user # Create path, if not existent create_path_if_not_exist(path) timestepsTotal = 365 * 24 * 3600 / timestep # Generate environment timer = pycity_base.classes.Timer.Timer(timeDiscretization=timestep, timestepsTotal=timestepsTotal) weather = pycity_base.classes.Weather.Weather(timer, useTRY=True) prices = pycity_base.classes.Prices.Prices() env = pycity_base.classes.Environment.Environment(timer, weather, prices) for occ in range(1, 6): # Loop from 1 to 5 occupants print('Number of occupants: ', occ) print('#####################################################') # Filenames (Files are going to store 3 arrays ('occ', 'app', 'lig')) file_name = str(occ) + '_person_profiles.npz' path_profile_file = os.path.join(path, file_name) occupancy_profiles = None el_profiles = None dhw_profiles = None for i in range(runs): # Loop over desired number of profiles print('Run number: ', i) # Generate occupancy object occupancy = Occ.Occupancy(environment=env, number_occupants=occ) # Get profile occ_profile = occupancy.occupancy if occupancy_profiles is None: occupancy_profiles = occ_profile else: occupancy_profiles = np.vstack( (occupancy_profiles, occ_profile)) # Generate el. load profile el_dem_stochastic = \ ED.ElectricalDemand(environment=env, method=2, total_nb_occupants=occ, randomizeAppliances=True, lightConfiguration=10, occupancy=occupancy.occupancy) # Get el. load profile el_profile = el_dem_stochastic.loadcurve if el_profiles is None: el_profiles = el_profile else: el_profiles = np.vstack((el_profiles, el_profile)) # Generate hot water profile dhw_stochastical = \ DomesticHotWater.DomesticHotWater(environment=env, tFlow=60, thermal=True, method=2, supplyTemperature=20, occupancy=occ_profile) # Get dhw curve dhw_profile = dhw_stochastical.loadcurve if dhw_profiles is None: dhw_profiles = dhw_profile else: dhw_profiles = np.vstack((dhw_profiles, dhw_profile)) # Save as npz file (3 arrays ('occ', 'el', 'dhw')) np.savez(path_profile_file, occ=occupancy_profiles, el=el_profiles, dhw=dhw_profiles) print('#####################################################') print()
def test_parse_ind_dict_to_city2(self): # Generate city object # Create extended environment of pycity_calc year = 2010 timestep = 900 # Timestep in seconds location = (51.529086, 6.944689) # (latitude, longitute) of Bottrop altitude = 55 # Altitude of Bottrop # Generate timer object timer = time.TimerExtended(timestep=timestep, year=year) # Generate weather object weather = Weather.Weather(timer, useTRY=True, location=location, altitude=altitude) # Generate market object market = germarkt.GermanMarket() # Generate co2 emissions object co2em = co2.Emissions(year=year) # Generate environment environment = env.EnvironmentExtended(timer, weather, prices=market, location=location, co2em=co2em) # Generate city object city_object = city.City(environment=environment) for i in range(7): extended_building = build_ex.BuildingExtended( environment, build_year=1990, mod_year=2003, build_type=0, roof_usabl_pv_area=30, net_floor_area=150, height_of_floors=3, nb_of_floors=2, neighbour_buildings=0, residential_layout=0, attic=0, cellar=1, construction_type='heavy', dormer=0) # Create demands (with standardized load profiles (method=1)) heat_demand = SpaceHeating.SpaceHeating(environment, method=1, profile_type='HEF', livingArea=300, specificDemand=100) el_demand = ElectricalDemand.ElectricalDemand(environment, method=1, annualDemand=3000, profileType="H0") # Create apartment apartment = Apartment.Apartment(environment) # Add demands to apartment apartment.addMultipleEntities([heat_demand, el_demand]) # Add apartment to extended building extended_building.addEntity(entity=apartment) # Add buildings to city_object city_object.add_extended_building(extended_building, position=point.Point(0, i * 10)) addbes.add_bes_to_city(city=city_object) chp_size = 10000 boi_size = 30000 tes_size = 500 pv_area = 30 dict_b1 = { 'chp': chp_size, 'boi': boi_size, 'tes': tes_size, 'eh': 0, 'hp_aw': 0, 'hp_ww': 0, 'pv': pv_area, 'bat': 0 } dict_b2 = { 'chp': chp_size, 'boi': boi_size, 'tes': tes_size, 'eh': 0, 'hp_aw': 0, 'hp_ww': 0, 'pv': pv_area, 'bat': 0 } dict_no = { 'chp': 0, 'boi': 0, 'tes': 0, 'eh': 0, 'hp_aw': 0, 'hp_ww': 0, 'pv': 0, 'bat': 0 } ind = { 1001: dict_b1, 1002: dict_no, 1003: dict_b2, 1004: copy.copy(dict_no), 1005: copy.copy(dict_no), 1006: copy.copy(dict_no), 1007: copy.copy(dict_no), 'lhn': [[1001, 1002], [1003, 1004, 1005, 1006, 1007]] } city_obj = parse_ind_to_city.parse_ind_dict_to_city(dict_ind=ind, city=city_object) assert city_obj.nodes[1001]['entity'].bes.chp.qNominal == chp_size assert city_obj.nodes[1001]['entity'].bes.boiler.qNominal == boi_size assert city_obj.nodes[1001]['entity'].bes.tes.capacity == tes_size assert city_obj.nodes[1003]['entity'].bes.chp.qNominal == chp_size assert city_obj.nodes[1003]['entity'].bes.boiler.qNominal == boi_size assert city_obj.nodes[1003]['entity'].bes.tes.capacity == tes_size assert city_obj.edges[1001, 1002]['network_type'] == 'heating' assert city_obj.edges[1003, 1004]['network_type'] == 'heating' assert city_obj.edges[1004, 1005]['network_type'] == 'heating' assert city_obj.edges[1005, 1006]['network_type'] == 'heating' assert city_obj.edges[1006, 1007]['network_type'] == 'heating' checkeb.check_eb_requirements(city=city_obj)
def run_test(): # Generate timer, weather and price objects timer = pycity_base.classes.Timer.Timer() weather = pycity_base.classes.Weather.Weather(timer) prices = pycity_base.classes.Prices.Prices() # Generate environment environment = pycity_base.classes.Environment.Environment( timer, weather, prices) print("Network Specification") print( 'Attributes of the connection mediums will be defined at initialization:' ) networksDictionary = {} networksDictionary['Electricity'] = { 'busVoltage': 1000, 'diameter': 0.2, 'spConductance': 1.68 * 10**-8 } networksDictionary['Gas'] = { 'diameter': 0.5, 'gasDensity': 0.8, 'darcyFactor': 0.03 } networksDictionary['Heat'] = {'diameter': 0.5, 'spConductance': 0.591} networksDictionary['Water'] = { 'diameter': 0.5, 'waterDensity': 1000, 'darcyFactor': 0.03 } print() print("For example: networksDictionary['ElectricCable']=[0.2,1.68*10**-8]") print('Diameters of electric cables in the district: ', networksDictionary['Electricity']['diameter'], 'm') print('Specific conductance of electric cables in the district', networksDictionary['Electricity']['spConductance'], 'ohm.m') print() print("Generate city district object") cityDistrict = CityDistrict.CityDistrict(environment, networksDictionary) # Empty dictionary for positions dict_pos = {} # Generate shapely point positions dict_pos[0] = point.Point(0, 40) #WT dict_pos[1] = point.Point(0, 35) #P2G converter dict_pos[2] = point.Point(0, 30) #P2G storage dict_pos[3] = point.Point(40, -20) #PV dict_pos[4] = point.Point(45, -20) #HE dict_pos[5] = point.Point(110, 30) #Building1 dict_pos[6] = point.Point(180, 60) #Building2 dict_pos[7] = point.Point(240, 30) #Building3 dict_pos[8] = point.Point(290, -30) #Building4 dict_pos[9] = point.Point(300, -300) #Gas Source dict_pos[10] = point.Point(500, -300) #Gas Source dict_pos[11] = point.Point(80, 30) #CHP for district heating print() print("Points on the city district object:") for no in range(len(dict_pos)): print("Position number", no, "at location", str(dict_pos[no].x) + ',' + str(dict_pos[no].y)) print() print("Generate PV farm within city district") pv = PV.PV(environment, 200, 0.15) print(pv) print('Add PV field to the city district position 3') nodePV = cityDistrict.addEntity(entity=pv, position=dict_pos[3]) print() print('Generate Hydroelectric pump storage within city district') capacity = 4 * 3600 * 1000 #4 kWh ffInit = 0.5 etaCharge = 0.96 etaDischarge = 0.95 height = 20 pump = HydroElectric.HydroElectric(environment, ffInit, capacity, height, etaCharge, etaDischarge) print(pump) print('Add HE to city district position 4') nodeHE = cityDistrict.addEntity(entity=pump, position=dict_pos[4]) print() print( 'Generate WindEnergyConverter city district from the type ENERCON E-126' ) src_path = os.path.dirname(os.path.dirname(__file__)) wind_data_path = os.path.join(src_path, 'inputs', 'wind_energy_converters.xlsx') wecDatasheets = xlrd.open_workbook(wind_data_path) ENERCON_E_126 = wecDatasheets.sheet_by_name("ENERCON_E_126") hubHeight = ENERCON_E_126.cell_value(0, 1) mapWind = [] mapPower = [] counter = 0 while ENERCON_E_126._dimnrows > 3 + counter: mapWind.append(ENERCON_E_126.cell_value(3 + counter, 0)) mapPower.append(ENERCON_E_126.cell_value(3 + counter, 1)) counter += 1 mapWind = np.array(mapWind) mapPower = np.array(mapPower) * 1000 wec = WT.WindEnergyConverter(environment, mapWind, mapPower, hubHeight) print(wec) print('Add Wind turbine field to city district position 0') nodeWT = cityDistrict.addEntity(entity=wec, position=dict_pos[0]) print() print('Create a power to gas conversion with a storage unit') maxInput = 10000 #10 kW efficiency = 0.7 #Create a storage unit ff = 0.6 capacity = 20 * 1000 * 3600 #20kWh p2g = P2G.P2G(environment, maxInput, efficiency) storage = P2GStorage.P2GStorage(environment, ff, capacity) print(p2g) print(storage) print('Add power to gas storage converter to city district position 1') print('Add power to gas storage storage unit to city district position 2') nodeP2G = cityDistrict.addEntity(entity=p2g, position=dict_pos[1]) nodeP2Gstor = cityDistrict.addEntity(entity=storage, position=dict_pos[2]) print() #Create a CHP lower_activation_limit_DH = 0.2 q_nominal_DH = 100000 t_max_DH = 90 p_nominal_DH = 60000 omega_DH = 0.9 dh_CHP = CHP.CHP(environment, p_nominal_DH, q_nominal_DH, omega_DH, t_max_DH, lower_activation_limit_DH) print('Add CHP unit for district heating') nodeCHP = cityDistrict.addEntity(entity=dh_CHP, position=dict_pos[11]) print() # Create CHPs to add to BESs 5 and 6 lower_activation_limit = 0.5 q_nominal = 10000 t_max = 90 p_nominal = 6000 omega = 0.9 heater_chp = CHP.CHP(environment, p_nominal, q_nominal, omega, t_max, lower_activation_limit) # Create a Boiler add to BES 7 lower_activation_limit = 0.5 q_nominal = 10000 t_max = 90 eta = 0.9 heater_boiler = Boiler.Boiler(environment, q_nominal, eta, t_max, lower_activation_limit) #Create a PV and Battery for BES 8 pv_Roof = PV.PV(environment, 40, 0.15) battery = Battery.Battery(environment, 0.5, 4 * 3600 * 1000) print('Generate building objects within loop') # #------------------------------------------------------------------- buildingnodes = [] buildings = [] for i in range(5, 9): # Generate heat demand curve for space heating heat_demand = SpaceHeating.SpaceHeating( environment, method=1, # Standard load profile livingArea=1460, specificDemand=166) # Generate electrical demand curve el_demand = ElectricalDemand.ElectricalDemand( environment, method=1, # Standard load profile annualDemand=30000) # Generate domestic hot water demand curve dhw_annex42 = DomesticHotWater.DomesticHotWater( environment, tFlow=60, thermal=True, method=1, # Annex 42 dailyConsumption=700, supplyTemperature=25) # Generate apartment and add demand durves apartment = Apartment.Apartment(environment) apartment.addEntity(heat_demand) apartment.addMultipleEntities([el_demand, dhw_annex42]) bes = BES.BES(environment) if i in [5, 6]: bes.addDevice(heater_chp) elif i == 7: bes.addDevice(heater_boiler) elif i == 8: bes.addDevice(pv_Roof) bes.addDevice(battery) # Generate heating curve heatingCurve = HeatingCurve.HeatingCurve(environment) # Generate building and add apartment and heating curve building = Building.Building(environment, True) entities = [apartment, heatingCurve, bes] building.addMultipleEntities(entities) # Add buildings to city district buildingnodes.append( cityDistrict.addEntity(entity=building, position=dict_pos[i])) buildings.append(building) print('Add them to the city district positons 5-8') nodeB5 = buildingnodes[0] nodeB6 = buildingnodes[1] nodeB7 = buildingnodes[2] nodeB8 = buildingnodes[3] print() print('Create a gas source object') districtGasSource = GasSource.GasSource(environment) print(districtGasSource) print('Add it to the city district position 9') nodeGS = cityDistrict.addEntity(entity=districtGasSource, position=dict_pos[9]) print() print('Create a water source object') districtWaterSource = WaterSource.WaterSource(environment) print('Add it to the city district position 10') nodeWS = cityDistrict.addEntity(entity=districtWaterSource, position=dict_pos[10]) print() print("Node and object information of the city objects") print( "-------------------------------------------------------------------") print('Number of building entities:', cityDistrict.get_nb_of_building_entities()) print('Node id list of building entities:', cityDistrict.get_list_build_entity_node_ids()) print() print('Number of PV farms:', cityDistrict.get_nb_of_entities(entity_name='pv')) print('Number of Wind farms:', cityDistrict.get_nb_of_entities(entity_name='windenergyconverter')) print('Number of Hydroelectric pump storage units:', cityDistrict.get_nb_of_entities(entity_name='heps')) print('Number of P2G converters:', cityDistrict.get_nb_of_entities(entity_name='p2gConverter')) print() print('Node information:') print('All nodes', cityDistrict.nodes()) print('Nodelists_heating:', cityDistrict.nodelists_heating) print('Nodelists_electricty:', cityDistrict.nodelists_electricity) print('Nodelists_gas:', cityDistrict.nodelists_gas) print('Nodelists_water:', cityDistrict.nodelists_water) print() print('Power supply from uncontrollable (renewable) generators') print('PV power:') print(cityDistrict.getPVPower()) print() print('Wind turbine power:') print(cityDistrict.getWindEnergyConverterPower()) print() print('Please type enter') #input() print('Aggregation of demand at consumer ends') print('Return aggregated space heating power curve:') print(cityDistrict.get_aggr_space_h_power_curve()) print() print('Return aggregated electrical power curve:') print(cityDistrict.get_aggr_el_power_curve()) print() print('Return hot water power curve:') print(cityDistrict.get_aggr_dhw_power_curve()) print() print('Return aggregated water demand curve:') print(cityDistrict.get_aggr_water_demand_power_curve()) print() print('Please type enter') #input() print('Assigning schedules to controllable objects') print() np.random.seed(0) print('Power to gas conversion: how much electric power will be supplied') conversionSchedule = -np.random.randint(90001, size=192) print(conversionSchedule) print() print('Power to gas storage: how much gas power will be supplied') storageSchedule = conversionSchedule * 0.6 print(storageSchedule) print() print( 'Hydroelectric pump storage: how much electric power will be supplied') pumpSchedule = np.random.random_integers(-3000, 101, 192) print(pumpSchedule) print() print('District heating CHP: how much electric power will be supplied') chpDH_Schedule = np.array([0.5] * 192) print(chpDH_Schedule) print() print('District Gas Source: how much gas power will be supplied') gasSupplySchedule = np.random.random_integers(0, 100000, 192) print(gasSupplySchedule) print() print('District Water Source: how much water will be supplied') waterSupplySchedule = np.random.random_integers(0, 1000, 192) print(waterSupplySchedule) print() print('Same schedule is assigned to CHPs of the buildings') chpSchedule = np.array([0.0] * 192) print(chpSchedule) print() print('Schedule assigned to gas boilers of the buildings') boilerSchedule = np.array([0.6] * 192) print(boilerSchedule) print() print('Battery schedule assigned') batterySchedule = np.random.random_integers(-3000, 3001, timer.timestepsUsedHorizon) print(batterySchedule) print() for building in buildings: if buildings.index(building) < 2: building.bes.chp.setResults(chpSchedule) elif buildings.index(building) == 2: building.bes.boiler.setResults(boilerSchedule) elif buildings.index(building) == 3: building.bes.battery.setResults(batterySchedule) dh_CHP.setResults(chpDH_Schedule) pump.setResults(pumpSchedule) p2g.setResults(conversionSchedule) storage.setResults(storageSchedule) districtGasSource.setResults(gasSupplySchedule) districtWaterSource.setResults(waterSupplySchedule)
prices = pycity_base.classes.Prices.Prices() environment = pycity_base.classes.Environment.Environment( timer, weather, prices) # Occupancy and electrical demand occupancy = pycity_base.classes.demand.Occupancy.Occupancy(environment, number_occupants=3) energy_input = 3000 el_dem_stochastic = ED.ElectricalDemand(environment, method=2, annualDemand=energy_input, total_nb_occupants=3, randomizeAppliances=True, lightConfiguration=10, occupancy=occupancy.occupancy, do_normalization=True) demand_electricity = el_dem_stochastic.loadcurve # Domestic hot water demand dhw_stochastical = DomesticHotWater.DomesticHotWater( environment, tFlow=60, thermal=True, method=2, supplyTemperature=20, occupancy=occupancy.occupancy)
def run_test(): # Generate timer, weather and price objects timer = pycity_base.classes.Timer.Timer() weather = pycity_base.classes.Weather.Weather(timer) prices = pycity_base.classes.Prices.Prices() # Generate environment environment = pycity_base.classes.Environment.Environment(timer, weather, prices) # Generate city district object cityDistrict = CityDistrict.CityDistrict(environment) # Annotations: To prevent some methods of subclasses uesgraph / nx.Graph # from failing (e.g. '.subgraph()) environment is optional input # parameter. # Empty dictionary for positions dict_pos = {} # Generate shapely point positions dict_pos[0] = point.Point(0, 0) dict_pos[1] = point.Point(0, 10) dict_pos[2] = point.Point(10, 0) dict_pos[3] = point.Point(10, 10) dict_pos[4] = point.Point(20, 20) dict_pos[5] = point.Point(30, 30) # Generate building objects within loop # #------------------------------------------------------------------- for i in range(4): # Generate heat demand curve for space heating heat_demand = SpaceHeating.SpaceHeating(environment, method=1, # Standard load profile livingArea=146, specificDemand=166) # Generate electrical demand curve el_demand = ElectricalDemand.ElectricalDemand(environment, method=1, # Standard load profile annualDemand=3000) # Generate domestic hot water demand curve dhw_annex42 = DomesticHotWater.DomesticHotWater(environment, tFlow=60, thermal=True, method=1, # Annex 42 dailyConsumption=70, supplyTemperature=25) # Generate apartment and add demand durves apartment = Apartment.Apartment(environment) apartment.addEntity(heat_demand) apartment.addMultipleEntities([el_demand, dhw_annex42]) # Generate heating curve heatingCurve = HeatingCurve.HeatingCurve(environment) # Generate building and add apartment and heating curve building = Building.Building(environment) entities = [apartment, heatingCurve] building.addMultipleEntities(entities) # Add buildings to city district cityDistrict.addEntity(entity=building, position=dict_pos[i]) # Generate PV farms within city district within loop # #------------------------------------------------------------------- for i in range(2): # Generate PV field within city district pv = PV.PV(environment, 20, 0.15) # Add PV fields to city district cityDistrict.addEntity(entity=pv, position=dict_pos[i+4]) # Add wind energy converter # #------------------------------------------------------------------- # Create Wind Energy Converter (ENERCON E-126) src_path = os.path.dirname(os.path.dirname(__file__)) wind_data_path = os.path.join(src_path, 'inputs', 'wind_energy_converters.xlsx') wecDatasheets = xlrd.open_workbook(wind_data_path) ENERCON_E_126 = wecDatasheets.sheet_by_name("ENERCON_E_126") hubHeight = ENERCON_E_126.cell_value(0, 1) mapWind = [] mapPower = [] counter = 0 while ENERCON_E_126._dimnrows > 3 + counter: mapWind.append(ENERCON_E_126.cell_value(3 + counter, 0)) mapPower.append(ENERCON_E_126.cell_value(3 + counter, 1)) counter += 1 mapWind = np.array(mapWind) mapPower = np.array(mapPower) * 1000 wec = Wind.WindEnergyConverter(environment=environment, velocity=mapWind, power=mapPower, hubHeight=hubHeight) cityDistrict.addEntity(entity=wec, position=point.Point(100, 100)) # Extract information of city object # #------------------------------------------------------------------- print('Number of building entities:') print(cityDistrict.get_nb_of_building_entities()) print('Node id list of building entities:') print(cityDistrict.get_list_build_entity_node_ids()) print('Number of PV farms:') print(cityDistrict.get_nb_of_entities(entity_name='pv')) print('Node information:') print(cityDistrict.nodes(data=True)) print('\n') print('Power curves of all building objects:') print(cityDistrict.get_power_curves()) print() print('Flow temperatures:') print(cityDistrict.getFlowTemperatures()) print() print('PV power:') print(cityDistrict.getPVPower()) print() print('Return aggregated space heating power curve:') print(cityDistrict.get_aggr_space_h_power_curve()) print() print('Return aggregated electrical power curve:') print(cityDistrict.get_aggr_el_power_curve()) print() print('Return hot water power curve:') print(cityDistrict.get_aggr_dhw_power_curve()) print() print('Get wind energy converter power:') print(cityDistrict.getWindEnergyConverterPower()) print() print('Get list of nodes of type building:') print(cityDistrict.get_list_id_of_spec_node_type(node_type='building')) print() print('Get total number of occupants within city district:') print(cityDistrict.get_nb_occupants())
def run_test(do_plot=False, run_stoch=False): print('Generate slp profile') print('########################################################') timer = pycity_base.classes.Timer.Timer() weather = pycity_base.classes.Weather.Weather(timer) # , useTRY=True) prices = pycity_base.classes.Prices.Prices() environment = pycity_base.classes.Environment.Environment( timer, weather, prices) el_demand = ED.ElectricalDemand( environment, method=1, # Standard load profile profileType="H0", annualDemand=3000) results = el_demand.loadcurve # Convert to energy_curve in kWh energy_curve = results * timer.timeDiscretization / (3600 * 1000) energy_value = sum(energy_curve) print() print("Electrical power in W: " + str(results)) print('Sum of consumed energy in kWh: ', energy_value) if do_plot: plt.plot(results[:672]) plt.show() if run_stoch: print() print('Generate stochastic, el. profile') print('########################################################') occupancy = pycity_base.classes.demand.Occupancy.Occupancy( environment, number_occupants=3) el_dem_stochastic = ED.ElectricalDemand(environment, method=2, total_nb_occupants=3, randomizeAppliances=True, lightConfiguration=10, occupancy=occupancy.occupancy, prev_heat_dev=True) results2 = el_dem_stochastic.loadcurve # Convert to energy_curve in kWh energy_curve2 = results2 * timer.timeDiscretization / (3600 * 1000) energy_value2 = sum(energy_curve2) print() print("Electrical power in W: " + str(results)) print('Sum of consumed energy in kWh: ', energy_value2) if do_plot: plt.plot(results2[:672]) plt.show() print() print('Generate normalized stochastic profile') print('########################################################') energy_input = 3000 el_dem_stochastic2 = ED.ElectricalDemand(environment, method=2, annualDemand=energy_input, total_nb_occupants=3, randomizeAppliances=True, lightConfiguration=10, occupancy=occupancy.occupancy, do_normalization=True) results3 = el_dem_stochastic2.loadcurve # Convert to energy_curve in kWh energy_curve3 = results3 * timer.timeDiscretization / (3600 * 1000) energy_value3 = sum(energy_curve3) print() print("Electrical power in W: " + str(results3)) print('Sum of consumed energy in kWh: ', energy_value3) assert energy_input - energy_value3 <= 0.001 * energy_input if do_plot: plt.plot(results3[:672]) plt.show() print('Generate el. profile based on weekly measurement data') print('########################################################') el_demand = ED.ElectricalDemand( environment, method=3, # Weekly profile do_normalization=True, annualDemand=3000, method_3_type='metal') results4 = el_demand.loadcurve # Convert to energy_curve in kWh energy_curve4 = results4 * timer.timeDiscretization / (3600 * 1000) energy_value4 = sum(energy_curve4) print() print("Electrical power in W: " + str(results4)) print('Sum of consumed energy in kWh: ', energy_value4) if do_plot: plt.plot(results4[:672]) plt.show() print('Generate el. profile based on annual measurement data') print('########################################################') el_demand = ED.ElectricalDemand( environment, method=4, # Annual measurement profiles do_normalization=True, annualDemand=5000, method_4_type='metal_2') results5 = el_demand.loadcurve # Convert to energy_curve in kWh energy_curve5 = results5 * timer.timeDiscretization / (3600 * 1000) energy_value5 = sum(energy_curve5) print() print("Electrical power in W: " + str(results5)) print('Sum of consumed energy in kWh: ', energy_value5) if do_plot: plt.plot(results5[:672]) plt.show() plt.plot(results5) plt.show()