def setUpClass(cls): cls.period = 24 cls.es = EnergySystem(timeindex=pandas.date_range( '2016-01-01', periods=cls.period, freq='H')) # BUSSES b_el1 = Bus(label="b_el1") b_el2 = Bus(label="b_el2") b_diesel = Bus(label='b_diesel', balanced=False) cls.es.add(b_el1, b_el2, b_diesel) # TEST DIESEL: dg = Transformer( label='diesel', inputs={b_diesel: Flow(variable_costs=2)}, outputs={ b_el1: Flow(variable_costs=1, investment=Investment(ep_costs=0.5)) }, conversion_factors={b_el1: 2}, ) batt = GenericStorage( label='storage', inputs={b_el1: Flow(variable_costs=3)}, outputs={b_el2: Flow(variable_costs=2.5)}, capacity_loss=0.00, initial_capacity=0, invest_relation_input_capacity=1 / 6, invest_relation_output_capacity=1 / 6, inflow_conversion_factor=1, outflow_conversion_factor=0.8, fixed_costs=35, investment=Investment(ep_costs=0.4), ) cls.demand_values = [100] * 8760 cls.demand_values[0] = 0.0 demand = Sink(label="demand_el", inputs={ b_el2: Flow(nominal_value=1, actual_value=cls.demand_values, fixed=True) }) cls.es.add(dg, batt, demand) cls.om = Model(cls.es) cls.om.receive_duals() cls.om.solve() cls.mod = Model(cls.es) cls.mod.solve()
def add_storages(table_collection, nodes): storages = table_collection["storages"] storages.columns = storages.columns.swaplevel() for region in storages["phes"].columns: storage_label = Label("storage", "electricity", "phes", region) bus_label = Label("bus", "electricity", "all", region) params = storages["phes"][region] nodes[storage_label] = GenericStorage( label=storage_label, inputs={nodes[bus_label]: Flow(nominal_value=params.pump)}, outputs={nodes[bus_label]: Flow(nominal_value=params.turbine)}, nominal_storage_capacity=params.energy, loss_rate=0, initial_storage_level=None, inflow_conversion_factor=params.pump_eff, outflow_conversion_factor=params.turbine_eff, )
actual_value=data['demand_el'], fixed=True) }) # power plants pp_coal = Transformer( label='pp_coal', inputs={bus_coal: Flow()}, outputs={bus_el: Flow(nominal_value=40, emission_factor=0.335)}, conversion_factors={bus_el: 0.39}) storage_el = GenericStorage(label='storage_el', nominal_storage_capacity=1000, inputs={bus_el: Flow(nominal_value=200)}, outputs={bus_el: Flow(nominal_value=200)}, loss_rate=0.01, initial_storage_level=0, max_storage_level=0.9, inflow_conversion_factor=0.9, outflow_conversion_factor=0.9) # an excess and a shortage variable can help to avoid infeasible problems excess_el = Sink(label='excess_el', inputs={bus_el: Flow()}) shortage_el = Source(label='shortage_el', outputs={bus_el: Flow(variable_costs=100000)}) # ## Add all to the energysystem energysystem.add(bus_coal, bus_gas, bus_el, source_gas, source_coal, wind, pv, demand_el, pp_coal, storage_el, excess_el, shortage_el)
t_start_warm=3, t_start_hot=1, cold_start_costs=5, warm_start_costs=4, hot_start_costs=1, minimum_downtime=1, ramp_limit_up=3, ramp_limit_down=4)) }, heat_output={bth: Flow(Q_CW_min=[30 for p in range(0, total_time_steps)])}, Beta=[0.19 for p in range(0, total_time_steps)], back_pressure=False) stor = GenericStorage(label='Storage0', nominal_storage_capacity=100, inputs={bel: Flow()}, outputs={bel: Flow()}, initial_storage_level=0, balanced=False) print(f'Time for es creation: {time()-start}') start = time() om = MultiPeriodModel(es, interval_length=48, period=24) print(f'Time for model creation: {time()-start:.6f}') # create an optimization problem and solve it start = time() om.solve(solver='cplex', solve_kwargs={'tee': True}) print(f'Time for solving: {time()-start:.6f}') if plt is not None: def plot_results(results): # plot electrical bus
excess = Sink(label='excess', inputs={bus_heat: Flow()}) heat_demand = Sink( label='heat_demand', inputs={bus_heat: Flow(nominal_value=1, fix=demand_timeseries)}) thermal_storage = GenericStorage( label='thermal_storage', inputs={bus_heat: Flow(nominal_value=maximum_heat_flow_charging)}, outputs={ bus_heat: Flow(nominal_value=maximum_heat_flow_discharging, variable_costs=0.0001) }, nominal_storage_capacity=nominal_storage_capacity, min_storage_level=input_data['min_storage_level'], max_storage_level=input_data['max_storage_level'], loss_rate=loss_rate, fixed_losses_relative=fixed_losses_relative, fixed_losses_absolute=fixed_losses_absolute, inflow_conversion_factor=1.0, outflow_conversion_factor=1.0, ) energysystem.add(bus_heat, heat_source, shortage, excess, heat_demand, thermal_storage) # Create and solve the optimization model optimization_model = Model(energysystem) optimization_model.solve(solver=solver,
heat_demand = Sink(label='heat_demand', inputs={ bus_heat: Flow(nominal_value=1, actual_value=demand_timeseries, fixed=True) }) thermal_storage = GenericStorage( label='thermal_storage', inputs={ bus_heat: Flow(nominal_value=maximum_heat_flow_charging, variable_costs=0.0001) }, outputs={bus_heat: Flow(nominal_value=maximum_heat_flow_discharging)}, min_storage_level=min_storage_level, max_storage_level=max_storage_level, loss_rate=loss_rate, fixed_losses_relative=fixed_losses_relative, fixed_losses_absolute=fixed_losses_absolute, inflow_conversion_factor=1., outflow_conversion_factor=1., investment=Investment(ep_costs=400, minimum=1)) energysystem.add(bus_heat, heat_source, shortage, excess, heat_demand, thermal_storage) # create and solve the optimization model optimization_model = Model(energysystem) optimization_model.write('storage_model.lp', io_options={'symbolic_solver_labels': True})
inputs={ thbus: Flow(nominal_value=1, actual_value=data['demand_th'], fixed=True) }) excess_el = Sink(label='excess_el', inputs={elbus: Flow(variable_costs=-0.005)}) shortage_el = Source(label='shortage_el', outputs={elbus: Flow(variable_costs=1e10)}) el_storage = GenericStorage(label='el_storage', inputs={elbus: Flow(variable_costs=0.0001)}, outputs={elbus: Flow()}, loss_rate=0.00, initial_storage_level=0.5, invest_relation_input_capacity=1 / 6, invest_relation_output_capacity=1 / 6, inflow_conversion_factor=0.9, outflow_conversion_factor=0.9, investment=Investment(ep_costs=epc_storage)) cop = 3 es.add( Transformer(label='heat_pump', inputs={elbus: Flow()}, outputs={thbus: Flow(nominal_value=10)}, conversion_factors={elbus: 1 / cop})) th_storage = GenericStorage(label='th_storage', nominal_storage_capacity=1000, inputs={thbus: Flow(nominal_value=20)},
bus_simple_thermal_storage = Bus(label='bus_simple_thermal_storage', balanced=False) energysystem.add(bus_simple_thermal_storage) storage_list.append( GenericStorage( label='simple_thermal_storage', inputs={ bus_simple_thermal_storage: Flow(nominal_value=input_data['maximum_heat_flow_charging'], variable_costs=0.0001) }, outputs={ bus_simple_thermal_storage: Flow(nominal_value=input_data['maximum_heat_flow_discharging'], variable_costs=0.0001) }, nominal_storage_capacity=nominal_storage_capacity, min_storage_level=input_data['min_storage_level'], max_storage_level=input_data['max_storage_level'], initial_storage_level=27 / nominal_storage_capacity, loss_rate=0.001, inflow_conversion_factor=1., outflow_conversion_factor=1., balanced=False)) for i, nominal_storage_capacity in enumerate([30, 65, 90]): bus_i = Bus(label=f'bus_{i}', balanced=False) energysystem.add(bus_i)
shortage = Source(label='shortage', outputs={bus_heat: Flow(variable_costs=1e6)}) excess = Sink(label='excess', inputs={bus_heat: Flow()}) heat_demand = Sink( label='heat_demand', inputs={bus_heat: Flow(nominal_value=1, fix=demand_timeseries)}) thermal_storage = GenericStorage( label='thermal_storage', inputs={bus_heat: Flow(investment=Investment(ep_costs=50))}, outputs={bus_heat: Flow(investment=Investment(), variable_costs=0.0001)}, min_storage_level=input_data['min_storage_level'], max_storage_level=input_data['max_storage_level'], loss_rate=loss_rate, fixed_losses_relative=fixed_losses_relative, fixed_losses_absolute=fixed_losses_absolute, inflow_conversion_factor=1., outflow_conversion_factor=1., invest_relation_input_output=1, investment=Investment(ep_costs=400, minimum=1)) energysystem.add(bus_heat, heat_source, shortage, excess, heat_demand, thermal_storage) # Create and solve the optimization model optimization_model = Model(energysystem) optimization_model.solve(solver=solver, solve_kwargs={ 'tee': False,
epc_pv = economics.annuity(capex=1000, n=20, wacc=0.05) epc_storage = economics.annuity(capex=1000, n=5, wacc=0.05) pv = Source(label='pv', outputs={elbus: Flow(actual_value=data['pv'], nominal_value=None, fixed=True, investment=Investment(ep_costs=epc_pv))}) demand_el = Sink(label='demand_el', inputs={elbus: Flow(nominal_value=1, actual_value=data['demand_el'], fixed=True)}) # excess_el = Sink(label='excess_el', inputs={elbus: Flow(variable_costs=0)}) # shortage_el = Source(label='shortage_el', outputs={elbus: Flow(variable_costs=1e30)}) el_storage = GenericStorage(label='el_storage', inputs={elbus: Flow(variable_costs=0.0001)}, outputs={elbus: Flow()}, loss_rate=0.00, initial_storage_level=0.6, balanced=True, invest_relation_input_capacity=1 / 6, invest_relation_output_capacity=1 / 6, inflow_conversion_factor=0.9, outflow_conversion_factor=0.9, investment=Investment(ep_costs=epc_storage)) grid = GenericStorage(label='grid', inputs={elbus: Flow(variable_costs=-0.005)}, outputs={elbus: Flow(variable_costs=1.5)}, loss_rate=0.00, nominal_storage_capacity=10000000, initial_storage_level=0.5, balanced=True, invest_relation_input_capacity=1, invest_relation_output_capacity=1, inflow_conversion_factor=1, outflow_conversion_factor=1)
actual_value=data['demand_el'], fixed=True) }) # power plants pp_coal = Transformer( label='pp_coal', inputs={bus_coal: Flow()}, outputs={bus_el: Flow(nominal_value=40, emission_factor=0.335)}, conversion_factors={bus_el: 0.39}) storage_el = GenericStorage(label='storage_el', invest=Investment(ep_cost=412), inputs={bus_el: Flow(nominal_value=200)}, outputs={bus_el: Flow(nominal_value=200)}, loss_rate=0.01, initial_storage_level=0, max_storage_level=0.9, inflow_conversion_factor=0.9, outflow_conversion_factor=0.9) # an excess and a shortage variable can help to avoid infeasible problems excess_el = Sink(label='excess_el', inputs={bus_el: Flow()}) shortage_el = Source(label='shortage_el', outputs={bus_el: Flow(variable_costs=100000)}) # ## Add all to the energysystem energysystem.add(bus_coal, bus_gas, bus_el, source_gas, source_coal, wind, pv, demand_el, pp_coal, storage_el, excess_el, shortage_el)