Piecewise Linear Oemof


I want to create a Heat/GasLine object, similar to the electrical line. My current issue is to model the pressure loss.
The simplified pressure loss in pipes can be expressed (in case of turbulent flow and negligible changes in density):
delta_p = delta_p0*(m./m.0)^2 with delta_p0/m.0^2 = K
delta_p = K * m.^2

I already created a model using quadratic variables, but now also want to create a linear model using piece-wise linearisation.

Appended you find my quadratic code:

    def pressure_relation(block):
        for t in m.TIMESTEPS:
            for n in group:
                if O[n].slack is True:
                    self.pressure[O[n], t].value = 0
                    self.pressure[O[n], t].fix()
                    lhs = m.flow[n, O[n], t]
                    rhs = 1/(n.conv_factor[t])*(
                            self.pressure[I[n], t] -
                            self.pressure[O[n], t])*(
                            self.pressure[I[n], t] -
                            self.pressure[O[n], t])
                    raise ValueError("Error in constraint creation",
                                     "of node {}".format(n.label))
                block.pressure_flow.add((n, t), (lhs <= rhs))
                block.pressure_flow.add((n, t), (lhs >= rhs))
                block._equate_pressure_flows.add((n, t), (
                    m.flow[n, O[n], t] == m.flow[I[n], n, t]))

Has someone an idea how i can make rhs an piece-wise linear function?

I am glad for any feedback,

Hi Philipp,

there are different possibilities to model piecewise linear expressions within pyomo.

You might check the following resources:

Depending on your goal you can make a choice for your expression!


Hello Cord,
thank you for your answer. I have tried this before and I am sadly not able to make it work. The problem is that I want to use it with a variable. This variable should be the pressure difference. The aim is to get an piecewise linear expression for rhs with the pressure difference as a variable. Therefore if the pressure difference changes the piecewise linear expression should change

Kind regards,

Hi Philipp,

currently we develop a piecewise linear transformer in oemof (see this PR). I am not sure if I understand your requirements fully. Maybe this helps you already?

Best, Jann

Hello Jann,
this was exactly what I was looking for. THANK YOU!!!

Best, Philipp

Text and images licensed under CC BY 4.0Data licensed under CC0 1.0Code licensed under MITSite terms of serviceOpenmod mailing listOpenmod wiki.