def adding_assets_to_energysystem_model(dict_values, dict_model, model, **kwargs): """ Parameters ---------- dict_values: dict dict of simulation data dict_model: Updated list of assets in the oemof energy system model model: oemof.solph.network.EnergySystem Model of oemof energy system Returns ------- """ logging.info("Adding components to oemof energy system model...") # Busses have to be defined first for bus in dict_values[ENERGY_BUSSES]: D1.bus(model, dict_values[ENERGY_BUSSES][bus][LABEL], **dict_model) # Adding step by step all assets defined within the asset groups for asset_group in ACCEPTED_ASSETS_FOR_ASSET_GROUPS: if asset_group in dict_values: for asset in dict_values[asset_group]: type = dict_values[asset_group][asset][OEMOF_ASSET_TYPE] # Checking if the asset type is one accepted for the asset group (security measure) if type in ACCEPTED_ASSETS_FOR_ASSET_GROUPS[asset_group]: # if so, then the appropriate function of D1 should be called if type == OEMOF_TRANSFORMER: D1.transformer(model, dict_values[asset_group][asset], **dict_model) elif type == OEMOF_SINK: D1.sink(model, dict_values[asset_group][asset], **dict_model) elif type == OEMOF_SOURCE: D1.source(model, dict_values[asset_group][asset], **dict_model) elif type == OEMOF_GEN_STORAGE: D1.storage(model, dict_values[asset_group][asset], **dict_model) else: raise UnknownOemofAssetType( f"Asset {asset} has type {type}, " f"but this type is not a defined oemof asset type." ) else: raise WrongOemofAssetForGroupError( f"Asset {asset} has type {type}, " f"but this type is not an asset type attributed to asset group {asset_group}" f" for oemof model generation.") logging.debug("All components added.") return model
def test_bus_add_to_not_empty_dict(self): label = "Test bus 2" D1.bus(model=self.model, name=label, bus=self.busses) # self.model should contain the test bus assert self.model.entities[-1].label == label assert isinstance(self.model.entities[-1], solph.network.Bus) # self.busses should contain the test bus (key = label, value = bus object) assert label in self.busses assert isinstance(self.busses[label], solph.network.Bus)
def test_storage_optimize(self): dict_asset = self.dict_values[ENERGY_STORAGE]["storage_optimize"] dict_asset[STORAGE_CAPACITY][MAXIMUM_CAP] = {VALUE: None, UNIT: "kWh"} dict_asset[INPUT_POWER][MAXIMUM_CAP] = {VALUE: None, UNIT: "kWh"} dict_asset[OUTPUT_POWER][MAXIMUM_CAP] = {VALUE: None, UNIT: "kWh"} dict_asset[STORAGE_CAPACITY][THERM_LOSSES_REL] = { VALUE: 0.001, UNIT: "no_unit" } D1.storage( model=self.model, dict_asset=dict_asset, bus=self.busses, storage=self.storages, ) # self.storages should contain the storage (key = label, value = storage object) assert dict_asset[LABEL] in self.storages assert isinstance(self.storages[dict_asset[LABEL]], solph.components.GenericStorage) # check value of `existing`, `investment` and `nominal_value`(`nominal_storage_capacity`) input_bus = self.model.entities[-1].inputs[self.busses["Storage bus"]] output_bus = self.model.entities[-1].outputs[ self.busses["Storage bus"]] assert (input_bus.investment.existing == dict_asset[INPUT_POWER] [INSTALLED_CAP][VALUE]) assert (input_bus.investment.ep_costs == dict_asset[INPUT_POWER] [SIMULATION_ANNUITY][VALUE]) assert input_bus.nominal_value is None assert (output_bus.investment.existing == dict_asset[OUTPUT_POWER] [INSTALLED_CAP][VALUE]) assert (output_bus.investment.ep_costs == dict_asset[OUTPUT_POWER] [SIMULATION_ANNUITY][VALUE]) assert output_bus.nominal_value is None # assert self.model.entities[-1].existing == dict_asset[STORAGE_CAPACITY][INSTALLED_CAP][VALUE] # todo probably not necessary parameter assert (self.model.entities[-1].investment.ep_costs == dict_asset[STORAGE_CAPACITY][SIMULATION_ANNUITY][VALUE]) assert self.model.entities[-1].nominal_storage_capacity is None # check that invest_relation_input_capacity and invest_relation_output_capacity is added assert (self.model.entities[-1].invest_relation_input_capacity == dict_asset[INPUT_POWER][C_RATE][VALUE]) assert (self.model.entities[-1].invest_relation_output_capacity == dict_asset[OUTPUT_POWER][C_RATE][VALUE]) assert (self.model.entities[-1].fixed_losses_relative.default == dict_asset[STORAGE_CAPACITY][THERM_LOSSES_REL][VALUE]) assert (self.model.entities[-1].fixed_losses_absolute.default == dict_asset[STORAGE_CAPACITY][THERM_LOSSES_ABS][VALUE])
def test_sink_dispatchable_multiple_input_busses(self): dict_asset = self.dict_values[ENERGY_CONSUMPTION][ "dispatchable_multiple"] D1.sink_dispatchable_optimize( model=self.model, dict_asset=dict_asset, sink=self.sinks, bus=self.busses, ) self.helper_test_sink_in_model_and_dict(dispatchable=True, dict_asset=dict_asset, amount_inputs=2)
def test_sink_non_dispatchable_multiple_input_busses(self): dict_asset = self.dict_values[ENERGY_CONSUMPTION][ "non_dispatchable_multiple"] dict_asset[TIMESERIES] = self.time_series D1.sink_non_dispatchable( model=self.model, dict_asset=dict_asset, sink=self.sinks, bus=self.busses, ) self.helper_test_sink_in_model_and_dict(dispatchable=False, dict_asset=dict_asset, amount_inputs=2)
def test_check_optimize_cap_raise_error(get_json, get_model, get_busses): dict_values = get_json model = get_model busses = get_busses test_asset = dict_values[ENERGY_CONVERSION]["test_asset_for_error_raising"] test_asset[OPTIMIZE_CAP][VALUE] = "wrong value" msg = f"Input error! '{OPTIMIZE_CAP}' of asset {test_asset[LABEL]}\n should be True/False but is {test_asset[OPTIMIZE_CAP][VALUE]}." with pytest.raises(ValueError, match=msg): D1.check_optimize_cap( model=model, dict_asset=test_asset, func_constant=D1.transformer_constant_efficiency_fix, func_optimize=D1.transformer_constant_efficiency_optimize, bus=busses, transformers={}, )
def test_storage_fix(self): dict_asset = self.dict_values[ENERGY_STORAGE]["storage_fix"] D1.storage( model=self.model, dict_asset=dict_asset, bus=self.busses, storage=self.storages, ) # self.storages should contain the storage (key = label, value = storage object) assert dict_asset[LABEL] in self.storages assert isinstance(self.storages[dict_asset[LABEL]], solph.components.GenericStorage) # check value of `existing`, `investment` and `nominal_value`(`nominal_storage_capacity`) input_bus = self.model.entities[-1].inputs[self.busses["Storage bus"]] output_bus = self.model.entities[-1].outputs[ self.busses["Storage bus"]] assert hasattr(input_bus, "existing") is False assert input_bus.investment is None assert (input_bus.nominal_value == dict_asset[STORAGE_CAPACITY] [INSTALLED_CAP][VALUE]) assert hasattr(output_bus, "existing") is False assert output_bus.investment is None assert output_bus.nominal_value == dict_asset[INPUT_POWER][ INSTALLED_CAP][VALUE] assert (hasattr(self.model.entities[-1], "existing") is False ) # todo probably not necessary parameter assert self.model.entities[-1].investment is None assert (self.model.entities[-1].nominal_storage_capacity == dict_asset[OUTPUT_POWER][INSTALLED_CAP][VALUE]) # # check that invest_relation_input_capacity and invest_relation_output_capacity is not added assert self.model.entities[-1].invest_relation_input_capacity is None assert self.model.entities[-1].invest_relation_output_capacity is None assert (self.model.entities[-1].fixed_losses_relative.default == dict_asset[STORAGE_CAPACITY][THERM_LOSSES_REL][VALUE]) assert (self.model.entities[-1].fixed_losses_absolute.default == dict_asset[STORAGE_CAPACITY][THERM_LOSSES_ABS][VALUE])
def test_source_non_dispatchable_fix(self): dict_asset = self.dict_values[ENERGY_PRODUCTION][ "non_dispatchable_source_fix"] dict_asset[TIMESERIES] = self.time_series dict_asset[TIMESERIES_PEAK] = { "unit": "kWp/H", "value": self.time_series.max() } D1.source( model=self.model, dict_asset=dict_asset, source=self.sources, bus=self.busses, ) # checks done with helper function (see func for more information) self.helper_test_source_in_model_and_dict(dict_asset=dict_asset, dispatchable=False, mode="fix")
def test_transformer_fix_cap_multiple_input_busses(self, ): dict_asset = self.dict_values[ENERGY_CONVERSION][ "transformer_fix_multiple_input_busses"] D1.transformer( model=self.model, dict_asset=dict_asset, transformer=self.transformers, bus=self.busses, ) # one output bus and two input busses assert ( len([str(i) for i in self.model.entities[-1].outputs]) == 1 ), f"Amount of output busses of transformer should be one but is {len([str(i) for i in self.model.entities[-1].outputs])}." assert ( len([str(i) for i in self.model.entities[-1].inputs]) == 2 ), f"Amount of output busses of transformer should be two but is {len([str(i) for i in self.model.entities[-1].inputs])}." # checks done with helper function (see func for more information) self.helper_test_transformer_in_model_and_dict(optimize=False, dict_asset=dict_asset)
def test_storage_optimize_investment_minimum_1_abs_times_series(self): # Test if minimum value is one if absolute thermal losses are not zero (time series) dict_asset = self.dict_values[ENERGY_STORAGE]["storage_optimize"] dict_asset[STORAGE_CAPACITY][THERM_LOSSES_REL] = { VALUE: 0, UNIT: "no_unit" } dict_asset[STORAGE_CAPACITY][THERM_LOSSES_ABS] = { VALUE: [0.001, 0.001, 0.001, 0.001], UNIT: "kWh", } D1.storage( model=self.model, dict_asset=dict_asset, bus=self.busses, storage=self.storages, ) assert ( self.model.entities[-1].investment.minimum == 1 ), f"investment.minimum should be one with non-zero {THERM_LOSSES_ABS}"
def test_storage_optimize_investment_minimum_0_time_series(self): # Test if minimum value is zero if thermal losses are zero (time series) dict_asset = self.dict_values[ENERGY_STORAGE]["storage_optimize"] dict_asset[STORAGE_CAPACITY][THERM_LOSSES_REL] = { VALUE: [0, 0, 0, 0], UNIT: "no_unit", } dict_asset[STORAGE_CAPACITY][THERM_LOSSES_ABS] = { VALUE: [0, 0, 0, 0], UNIT: "kWh", } D1.storage( model=self.model, dict_asset=dict_asset, bus=self.busses, storage=self.storages, ) assert ( self.model.entities[-1].investment.minimum == 0 ), f"investment.minimum should be zero with {THERM_LOSSES_REL} and {THERM_LOSSES_ABS} that are equal to zero"
def test_source_dispatchable_fix_normalized_timeseries(self): dict_asset = self.dict_values[ENERGY_PRODUCTION][ "dispatchable_source_fix"] dict_asset[TIMESERIES_NORMALIZED] = self.time_series / max( self.time_series) dict_asset[TIMESERIES_PEAK] = { "unit": "kWp/H", "value": self.time_series.max() } D1.source( model=self.model, dict_asset=dict_asset, source=self.sources, bus=self.busses, ) # checks done with helper function (see func for more information) self.helper_test_source_in_model_and_dict( dict_asset=dict_asset, dispatchable=True, mode="fix", timeseries="normalized", )