Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenericStorage not creating InvestmentFlows when used with invest_relation_input_output #1013

Open
lensum opened this issue Nov 15, 2023 · 5 comments

Comments

@lensum
Copy link
Contributor

lensum commented Nov 15, 2023

When using the GenericStorage with an investment optimization approach like this:

electric_storage = cmp.GenericStorage(
            label="electric_storage",
            inputs={el_bus: solph.Flow()},
            outputs={el_bus: solph.Flow()},
            loss_rate=0.01,  # based on 25kW for 2.5MW self consumption
            nominal_storage_capacity=solph.Investment(
                ep_costs=elstor_epc, existing=1200, maximum=2100
            ),
            invest_relation_input_capacity=0.9375,
            invest_relation_input_output=1,
            inflow_conversion_factor=0.9,
            outflow_conversion_factor=0.8 / 0.9,  # overall efficiency of 0.8
            initial_storage_level=0,
            balanced=False,
            ),
        )

I get KeyError: 'Index \'("<oemof.solph.components._generic_storage.GenericStorage: \'electric_storage\'>", "<oemof.solph.buses._bus.Bus: \'el_bus\'>", 0)\' is not valid for indexed component \'InvestmentFlowBlock.total\''

I assume that the error might be in the internal function _set_flows. I defined the self.invest_relation_input_capacity and self.invest_relation_input_output, but the _set_flows function only considers self.invest_relation_output_capacity for the output flows, meaning that my output flows don't get converted into InvestmentFlow objects.
If I use invest_relation_output_capacity=0.9375 instead of the invest_relation_input_output, the model starts to solve.

@p-snft
Copy link
Member

p-snft commented Nov 15, 2023

Shouldn't the Flows be created with nominal_value=Investment() to allow for investments in any case?

@lensum
Copy link
Contributor Author

lensum commented Nov 15, 2023

That might work (have to try it tomorrow) but it isn't shown like that in any of the examples. And then the _set_flows function wouldn't make much sense to me? Or is there another reason why the Investment objects in the flow should be overwritten? Maybe because of the lifetime_inflow`lifetime_outflow` attributes?

@p-snft
Copy link
Member

p-snft commented Nov 20, 2023

Maybe, it makes sense to rewrite this thing anyway. I'd consider replacing the fixed relations between the investments by a limit to the c-rate. It would be an internal property that exists independent from the nominal values of the flows.

@jokochems
Copy link
Member

Yeah, you are right about locating this to the _set_flows method, @lensum , I think.

  • The case of invest_relation_input_output is not accounted for here. In my view, a check needs to be added in _set_flows.
  • Also, for the other cases, the type of flow.investment is evaluated. I think, this needs to be flow.nominal_value instead according to the latest structural changes.

@p-snft
Copy link
Member

p-snft commented Nov 23, 2023

I see multiple problems with the current implementation. First of all, we create unexpected investment variables. (If the Flows do not have to have one, they are silently created.) Secondly, you can do confusing things. The invest_relation_input_capacity=0.1 will be typically read as "it needs 10 hours to charge the storage". However, you can set a "max" to the flows to bypass that:

electric_storage = cmp.GenericStorage(
    label="electric_storage",
    inputs={el_bus: solph.Flow(max=10)},  # will be charged in 1 hour
    outputs={el_bus: solph.Flow()},
    nominal_storage_capacity=solph.Investment(
        ep_costs=elstor_epc, existing=1200, maximum=2100
    ),
    invest_relation_input_capacity=0.1,
    invest_relation_input_output=0.1,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants