Define a renewable energy constraint in oemof

Dear openmod community,

I’m glad to be here.

I’m trying to implement a custom constraint for the share of renewable energy in my energy system consisting of pv battery and dieselGen using oemof. The following is a part of the code, where as seen the attribute „re_share“ in the components pv and dieselGen is added

   bel_dc = solph.Bus(label = 'dc_electricity')
   bel_ac = solph.Bus(label = 'ac_electricity')
   pv = solph.Source(label='pv', outputs={bel_dc: solph.Flow(
                          nonconvex = False, 
                          existing = 0),

    dieselGen = solph.Transformer(label="diesel",
                       inputs={diesel_bus: solph.Flow()},
                        outputs={bel_ac:  solph.Flow(
                  co2_bus: solph.Flow()},
                  conversion_factors={bel_ac:  diesel_efficiency, 

I build this function based on source code for oemof.solph.constraints.integral_limit but it didn’t not work. I’ still be a beginner and not familiar that much with the constraint concept in Oemof. Maybe you might have a better idea how to realise that! I will appreciate it!

   def RE_sh_const(om,key,re_share):

       pv_gen= sum(om.flow[pv,bel_dc,:])
       fossil_gen = sum(om.flow[dieselGen,bel_ac,:])
       RE_gen= pv_gen
       total_gen = RE_gen + fossil_gen
       limit_name= key
       expr = (fossil_gen - (1 - re_share) * total_gen  )
       setattr( om,limit_name + "_constraint", 
       po.Constraint(expr=(getattr(om, limit_name) <= 0)),)
       return om


I’am grateful for any help!

A couple of pointers (but not sure how relevant they are to the original question):

Have a look here to get some ideas on how to create additional constraints:

1 Like

Following some offline traffic with @jess, I have a general suggestion for exploring these kind of queries.

A good place to start might be to write and/or sketch the basic equations for a single time‑step on a sheet of paper, rather than fight through the implementation details for a real framework like oemof or PyPSA. And then perhaps experiment with simple test cases coded up in GLPK MathProg (open source and based on the AMPL language) or GAMS (proprietary). See, for instance:

1 Like

Thanks for help every one!

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