From 219c0330c998a7c07fd7a361703ba6d087c92ca9 Mon Sep 17 00:00:00 2001 From: "pierre-francois.duc" Date: Tue, 12 Sep 2023 16:11:13 +0200 Subject: [PATCH] WIP --- .../C0_data_processing.py | 71 ++++++++++++++----- .../D0_modelling_and_optimization.py | 7 +- .../D1_model_components.py | 23 +++++- src/multi_vector_simulator/cli.py | 4 ++ src/multi_vector_simulator/server.py | 2 +- .../utils/constants_json_strings.py | 1 + 6 files changed, 86 insertions(+), 22 deletions(-) diff --git a/src/multi_vector_simulator/C0_data_processing.py b/src/multi_vector_simulator/C0_data_processing.py index 38149a389..4d720d21f 100644 --- a/src/multi_vector_simulator/C0_data_processing.py +++ b/src/multi_vector_simulator/C0_data_processing.py @@ -727,29 +727,63 @@ def define_auxiliary_assets_of_energy_providers(dict_values, dso_name): dict_values, dso_dict, dict_availability_timeseries, ) - define_source( - dict_values=dict_values, - asset_key=dso_name + DSO_CONSUMPTION, - outflow_direction=peak_demand_bus_name(dso_dict[OUTFLOW_DIRECTION]), - price=dso_dict[ENERGY_PRICE], - energy_vector=dso_dict[ENERGY_VECTOR], - emission_factor=dso_dict[EMISSION_FACTOR], - asset_type=dso_dict.get(TYPE_ASSET), - ) + grid_availability = False + if grid_availability is False: + define_source( + dict_values=dict_values, + asset_key=dso_name + DSO_CONSUMPTION, + outflow_direction=peak_demand_bus_name(dso_dict[OUTFLOW_DIRECTION]), + price=dso_dict[ENERGY_PRICE], + energy_vector=dso_dict[ENERGY_VECTOR], + emission_factor=dso_dict[EMISSION_FACTOR], + asset_type=dso_dict.get(TYPE_ASSET), + ) + else: + pass + # in case of grid availablity the price should be 0 and and extra sink should be added + dict_feedin = change_sign_of_feedin_tariff(dso_dict[FEEDIN_TARIFF], dso_name) inflow_bus_name = peak_demand_bus_name(dso_dict[INFLOW_DIRECTION], feedin=True) # define feed-in sink of the DSO - define_sink( - dict_values=dict_values, - asset_key=dso_name + DSO_FEEDIN, - price=dict_feedin, - inflow_direction=inflow_bus_name, - specific_costs={VALUE: 0, UNIT: CURR + "/" + UNIT}, - energy_vector=dso_dict[ENERGY_VECTOR], - asset_type=dso_dict.get(TYPE_ASSET), - ) + if grid_availability is False: + define_sink( + dict_values=dict_values, + asset_key=dso_name + DSO_FEEDIN, + price=dict_feedin, + inflow_direction=inflow_bus_name, + specific_costs={VALUE: 0, UNIT: CURR + "/" + UNIT}, + energy_vector=dso_dict[ENERGY_VECTOR], + asset_type=dso_dict.get(TYPE_ASSET), + ) + else: + # def maingrid_feedin(micro_grid_system, experiment): + # logging.debug("Added to oemof model: maingrid feedin") + # bus_electricity_ng_feedin = solph.Bus(label=BUS_ELECTRICITY_NG_FEEDIN) + # micro_grid_system.add(bus_electricity_ng_feedin) + # + # # create and add demand sink to micro_grid_system - fixed + # sink_maingrid_feedin = solph.components.Sink( + # label=SINK_MAINGRID_FEEDIN, + # inputs={ + # bus_electricity_ng_feedin: solph.Flow( + # fix=experiment[GRID_AVAILABILITY], + # investment=solph.Investment(ep_costs=0), + # ) + # }, + # ) + # micro_grid_system.add(sink_maingrid_feedin) + # + # # to fill in for not really provided feed in + # source_maingrid_feedin_symbolic = solph.components.Source( + # label=SINK_MAINGRID_FEEDIN_SYMBOLIC, + # outputs={bus_electricity_ng_feedin: solph.Flow()}, + # ) + # micro_grid_system.add(source_maingrid_feedin_symbolic) + # return bus_electricity_ng_feedin + # the price should be 0 and an extra source should be added here + pass dso_dict.update( { CONNECTED_CONSUMPTION_SOURCE: dso_name + DSO_CONSUMPTION, @@ -1062,6 +1096,7 @@ def define_transformer_for_peak_demand_pricing( VALUE: 0, UNIT: CURR + "/" + dict_dso[UNIT] + "/" + UNIT_YEAR, }, + # add price here instead of in sinks DISPATCH_PRICE: {VALUE: 0, UNIT: CURR + "/" + dict_dso[UNIT] + "/" + UNIT_HOUR}, OEMOF_ASSET_TYPE: OEMOF_TRANSFORMER, ENERGY_VECTOR: dict_dso[ENERGY_VECTOR], diff --git a/src/multi_vector_simulator/D0_modelling_and_optimization.py b/src/multi_vector_simulator/D0_modelling_and_optimization.py index 332cc2d15..c44bf47cb 100644 --- a/src/multi_vector_simulator/D0_modelling_and_optimization.py +++ b/src/multi_vector_simulator/D0_modelling_and_optimization.py @@ -100,7 +100,8 @@ def run_oemof(dict_values, save_energy_system_graph=False, return_les=False): model_building.plot_networkx_graph( dict_values, model, save_energy_system_graph=save_energy_system_graph ) - + # import logging + # logging.getLogger().setLevel(logging.INFO) logging.debug("Creating oemof model based on created components and busses...") local_energy_system = solph.Model(model) logging.debug("Created oemof model based on created components and busses.") @@ -108,6 +109,10 @@ def run_oemof(dict_values, save_energy_system_graph=False, return_les=False): local_energy_system = D2.add_constraints( local_energy_system, dict_values, dict_model ) + import ipdb + + ipdb.set_trace() + model_building.store_lp_file(dict_values, local_energy_system) model, results_main, results_meta = model_building.simulating( diff --git a/src/multi_vector_simulator/D1_model_components.py b/src/multi_vector_simulator/D1_model_components.py index 2205a7cb4..9741829e2 100644 --- a/src/multi_vector_simulator/D1_model_components.py +++ b/src/multi_vector_simulator/D1_model_components.py @@ -56,6 +56,7 @@ EMISSION_FACTOR, BETA, INVESTMENT_BUS, + GRID_AVAILABILITY, ) from multi_vector_simulator.utils.helpers import get_item_if_list, get_length_if_list from multi_vector_simulator.utils.exceptions import ( @@ -324,7 +325,10 @@ def sink(model, dict_asset, **kwargs): - test_sink_dispatchable_multiple_input_busses() """ - if TIMESERIES in dict_asset: + if GRID_AVAILABILITY in dict_asset: + pass + # add the sink and symbolic source directly here for simplicity + elif TIMESERIES in dict_asset: sink_non_dispatchable(model, dict_asset, **kwargs) else: @@ -380,7 +384,11 @@ def source(model, dict_asset, **kwargs): - test_source_dispatchable_fix_normalized_timeseries() - test_source_dispatchable_fix_timeseries_not_normalized_timeseries() """ - if DISPATCHABILITY in dict_asset and dict_asset[DISPATCHABILITY] is True: + if GRID_AVAILABILITY in dict_asset: + pass + # add the source and symbolic sink directly here for simplicity + + elif DISPATCHABILITY in dict_asset and dict_asset[DISPATCHABILITY] is True: check_optimize_cap( model, dict_asset, @@ -1258,6 +1266,17 @@ def sink_non_dispatchable(model, dict_asset, **kwargs): Indirectly updated `model` and dict of asset in `kwargs` with the sink object. """ + + # sink_maingrid_feedin = solph.components.Sink( + # label=SINK_MAINGRID_FEEDIN, + # inputs={ + # bus_electricity_ng_feedin: solph.Flow( + # fix=experiment[GRID_AVAILABILITY], + # investment=solph.Investment(ep_costs=0), + # ) + # }, + # ) + # check if the sink has multiple input busses if isinstance(dict_asset[INFLOW_DIRECTION], list): inputs = {} diff --git a/src/multi_vector_simulator/cli.py b/src/multi_vector_simulator/cli.py index 340e1808c..73d914c94 100644 --- a/src/multi_vector_simulator/cli.py +++ b/src/multi_vector_simulator/cli.py @@ -175,6 +175,10 @@ def main(**kwargs): dict_values, save_energy_system_graph=save_energy_system_graph, ) + import ipdb + + ipdb.set_trace() + print("") logging.debug("Accessing script: E0_evaluation") E0.evaluate_dict(dict_values, results_main, results_meta) diff --git a/src/multi_vector_simulator/server.py b/src/multi_vector_simulator/server.py index 9ead03c78..c152d8b85 100644 --- a/src/multi_vector_simulator/server.py +++ b/src/multi_vector_simulator/server.py @@ -39,7 +39,7 @@ import tempfile from oemof.tools import logger -import oemof.solph as solph +from oemof import solph # Loading all child functions import multi_vector_simulator.B0_data_input_json as B0 diff --git a/src/multi_vector_simulator/utils/constants_json_strings.py b/src/multi_vector_simulator/utils/constants_json_strings.py index b925bd3fb..d3d82c47f 100644 --- a/src/multi_vector_simulator/utils/constants_json_strings.py +++ b/src/multi_vector_simulator/utils/constants_json_strings.py @@ -103,6 +103,7 @@ FEEDIN_TARIFF = "feedin_tariff" PEAK_DEMAND_PRICING = "peak_demand_pricing" PEAK_DEMAND_PRICING_PERIOD = "peak_demand_pricing_period" +GRID_AVAILABILITY = "grid_availability" # Asset definitions: Transformer INVESTMENT_BUS = "investment_bus"