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

How to define a switching Converter ? #1065

Open
mdonat opened this issue Apr 24, 2024 · 7 comments
Open

How to define a switching Converter ? #1065

mdonat opened this issue Apr 24, 2024 · 7 comments
Labels

Comments

@mdonat
Copy link

mdonat commented Apr 24, 2024

I would like to add a Converter which can only be on or off.
So output flow value should be 0 or nominal_value.
Is that possible?
If not, how to define for example a pump which converts electrical energy to heat, and can only be on or off?

@fwitte
Copy link
Member

fwitte commented Apr 24, 2024

Hi @mdonat,

you have to add the NonConvex on the input or output flow of the Converter, and the attribute min=1.

heat_pump = solph.components.Converter(
    "heat pump",
    inputs={b_electricity: solph.Flow()},
    outputs={
        b_heat: solph.Flow(min=1, nonconvex=solph.NonConvex(), nominal_value=10),  # e.g. 10 kW heat
    },
    conversion_factors={b_heat: COP}
)

@mdonat
Copy link
Author

mdonat commented Apr 24, 2024

I tried this, but it seems that it cannot be solved.
This is the code:

        energysystem = solph.EnergySystem(timeindex=times)
        
        bel = solph.buses.Bus(label='electricity')
        b_heat = solph.buses.Bus(label='heat')
        
        
        # create source object representing the e commodity
        energysystem.add(
                solph.components.Source(
                label="e-in",
                outputs={
                bel: solph.flows.Flow(variable_costs=50)
                },
            )
        )
        
        # create storage object for heat
        nominal_capacity = 4000
        nominal_value = 400

        heat_storage = solph.components.GenericStorage(
            nominal_storage_capacity=nominal_capacity,
            label="STORAGE_HEAT",
            inputs={b_heat: solph.flows.Flow(nominal_value=nominal_value, variable_costs=0.001)},
            outputs={
                b_heat: solph.flows.Flow(
                    nominal_value=nominal_value, variable_costs=0.001
                )
            },
            loss_rate=0.00,
            initial_storage_level=0.5,
            inflow_conversion_factor=1,
            outflow_conversion_factor=1,
        )

        energysystem.add(heat_storage)
        
        sink = solph.components.Sink(
            label="demand_th",
            inputs={b_heat: solph.Flow(nominal_value=200, fix=1)}
        )
        
        energysystem.add(solph.components.Converter(label="heatPump",
           inputs={bel: solph.flows.Flow(
           )},
           outputs={b_heat: solph.flows.Flow(nominal_value=400,
           nonconvex=solph.NonConvex(),
           min=1,
           )},
           conversion_factors={b_heat: 1}
           ))
        
        energysystem.add(bel, b_heat, sink)
        
        
        # solve problem
        om = solph.Model(energysystem)
        om.solve(solver="cbc", solve_kwargs={"tee": True})

If I uncomment "min=1" it solves with constant flow value of 200.
With "min=1" it does not solve, ...only if I set nominal_value to 200, so that the heat pump will be constantly on.

@fwitte
Copy link
Member

fwitte commented Apr 24, 2024

Your code is a incomplete, e.g. times is never defined, could you add that?

Also, the model might be infeasible, because your heat pump cannot provide 200 units of heat, only 400 or 0. Since your demand_th takes 200 units fixed at all times, nothing in your system can provide that amount of energy. The storage might be able to buffer that for up to 10 hours, but it is constrained to be cyclic by default. So depending on the number of timesteps you are running the model, it might be infeasible because the storage can never be balanced back to half way full.

To circumvent that, you could add an additional sink, which takes up any amount of heat but penalizes the model to do so (by giving the flow very high variable cost). Then you can check, why the infeasibility occurs.

@mdonat
Copy link
Author

mdonat commented Apr 24, 2024

Missing code for times:

 today = datetime.date.today()
 start_day = today - datetime.timedelta(days=1)
 times = pd.date_range(start=start_day, end=today, freq='5T')

I have added an additional sink:

energysystem.add(
    solph.components.Sink(
        label="excess_bus_heat",
        inputs={b_heat: solph.flows.Flow(variable_costs=100)},
    )
)

But it does not work.
I thought that, if the heat pump is working half the time, it provides 200 units of heat to demand_th, and 200 units to the storage. The other half, when it is switched off, the storage provides 200 units of heat to demand_th.

@fwitte
Copy link
Member

fwitte commented Apr 24, 2024

Okay, then it was a misunderstanding. I thought the problem was infeasible...

After running it, in my opinion, the issue here is, that the problem seems to have an extremely flat optimum: There is basically tons of solutions which all lead to the same objective but are very different in dispatch (the model really is indifferent on when to charge or discharge storage).

@mdonat
Copy link
Author

mdonat commented Apr 25, 2024

Ok, that's right, there is no clear optimum.
But if I set min=0.5 it is working. Should have even more possible solutions then...
Thank you for the quick support. :-)

@fwitte
Copy link
Member

fwitte commented Apr 25, 2024

But if I set min=0.5 it is working. Should have even more possible solutions then...

Due to the storage operation cost the optimum is then very easy to find: never use the storage. ;)

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

No branches or pull requests

2 participants