3

The Pyomo book proposes this structure of blocks for a time-dependent problem. The electrical grid model can

There is a Pyomo Block 'Electrical Grid Model' which is repeated for every time step, means indexed by the time series.

model.T = range(120)

def electrical_grid_block(grid, t):
    <containing: bus, transmission line, generator>
model.Grid = Block(model.T,rule=electrical_grid_block)

Makes totally sense to me until I want to model blocks which have to refer to a past time step. For example a storage needs the value of its storage level from last time step. The only solution I thought of: skipping the idea of indexed blocks and passing the time series into the storage block like this:

def storage(s):
    s.storage_level = Var(model.T, bounds=(0,300))
    s.power = Var(model.T, bounds=(-2,2))

    # Constraints
    def constr_rule_speicher(s,t):
        if t >= 2:
            return s.storage_level[t] == - s.power[t] * dt + s.storage_level[t-1]
        elif t == 1:
            return s.storage_level[t] == 150.0
    s.storage_constraints = Constraint(model.T, rule=constr_rule_speicher)

model.storage = Block(rule=storage)

I don't like this solution very much because I believe the object oriented manner of problem modeling gets lost.

Any different ideas to mine?

Unfortunately the documentation around Pyomo doesn't give any example for this kind of case.

programmar
  • 594
  • 6
  • 19

1 Answers1

2

It is late, but I have found an example in some lectures on Pyomo (the materials from Pyomo workshop from 2018, but from after the question was posted). An example can be found here (slide 187 in pdf): https://software.sandia.gov/downloads/pub/pyomo/Pyomo-Workshop-Summer-2018.pdf. The idea would be something along the lines:

model.T = range(120)

def electrical_grid_block(grid, t):
    <containing: bus, transmission line, generator>
model.Grid = Block(model.T,rule=electrical_grid_block)

def past_step_rule(m, t):
    if t == m.T.first():
        return Constraint.Skip
    return m.Grid[t].storage_level == m.Grid[t].power*dt - m.Grid[t-1].storage_level
model.past_step = Constraint(model.T, rule=past_step_rule)

In brief, the constraints that require two (or more) time steps are defined outside the blocks.

scherschu
  • 21
  • 3