Hi everyone,
I’m working on a local energy system model that includes a grid connection, photovoltaic (PV) panels, residential demand, EVs, and a battery storage, using oemof solph v0.5.2. The components are connected to a system core which is defined by a AC and DC bus connected by two converters (AC/DC and DC/AC).
As bidirectional flows are modeled by two unidirectional flows I run into the following problem:
Negative energy costs from the grid force the optimizer to buy as much energy as possible and therefore waste energy, if all batteries are fully charged and the residential demand is satisfied.
Since the unidirectional flows are assigned efficiencies, the optimizer generates a circular flow to waste energy through the efficiencies.
While this may still be feasible for some components in reality, a battery cannot physically be charged and discharged at the same time.
To prevent this, I want to avoid circular flows for the storage. For this, I’m using a modified version of limit_active_flow_count()
, which can handle NonConvexFlowBlock
and InvestNonConvexFlowBlock
objects. This method seems to work well for the converter, but I’m running into issues with the battery storage if I try to additionally optimize the storage size already when creating the component without even applying my custom constraint.
self.ess = solph.components.GenericStorage(
label='ess',
inputs={self.connected_bus: solph.Flow(
variable_costs=self.opex_spec,
nonconvex=scenario.nonconvex,
)},
outputs={self.connected_bus: solph.Flow(
nonconvex=scenario.nonconvex,
)},
loss_rate=0,
balanced=True,
initial_storage_level=self.ph_init_soc,
invest_relation_input_capacity=self.chg_crate,
invest_relation_output_capacity=self.dis_crate,
inflow_conversion_factor=self.chg_eff,
outflow_conversion_factor=self.dis_eff,
investment=solph.Investment(ep_costs=self.epc))
File "C:\Users\user\AppData\Local\anaconda3\envs\oemof_env\Lib\site-packages\pyomo\core\base\indexed_component.py", line 889, in _validate_index
raise KeyError(
KeyError: 'Index \'("<oemof.solph.buses._bus.Bus: \'dc_bus\'>", "<oemof.solph.components._generic_storage.GenericStorage: \'ess\'>", 0)\' is not valid for indexed component \'InvestmentFlowBlock.total\''
For context, dc_bus
is the label for the connected bus in my model.
So here are my questions regarding this issue:
-
What would be the right way to tackle negative prices and the resulting problems? Is there a better way to ensure that the system behaves physically, avoiding simultaneous inflow and outflow from the battery storage? I’ve tried using marginal costs (variable_costs=1.00E-8), but they didn’t work for me here as the negative grid costs are higher and higher marginal costs would have an unwanted effect on the result of the optimizer. Of course, any other alternative solutions to avoid the computationally expensive binary variables would be appreciated.
-
How can I fix the error related to the
InvestNonConvexFlowBlock
? It seems like the model generator is only looking for standard investment flows (InvestmentFlowBlock
), not nonconvex flows (InvestNonConvexFlowBlock
).
Any advice or insights would be greatly appreciated. Thanks in advance for your help!
Best regards,
Brian