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(
                          fix=feedin["PV"],
                          
                          investment=solph.Investment(ep_costs=cost_param.loc['Annuity_per_kW','pv'], 
                          nonconvex = False, 
                          existing = 0),
                          variable_costs=Comp_param['pv']['var'],
                          re_share=0.5
                          )})

    dieselGen = solph.Transformer(label="diesel",
                       inputs={diesel_bus: solph.Flow()},
                        outputs={bel_ac:  solph.Flow(
                            
                        investment=solph.Investment(ep_costs=cost_param.loc['Annuity_per_kW','inverter'],
                                                         maximum=Peak_Demand,
                                                         minimum=0.3*Peak_Demand,
                                                         nonconvex=True),
                              variable_costs=Comp_param['diesel']['var'],
                              re_share=0.5
                             ),
                  co2_bus: solph.Flow()},
                  conversion_factors={bel_ac:  diesel_efficiency, 
                                                   co2_bus:Diesel_co2_emission_factor
                                                    })

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,expr)
    
       setattr( om,limit_name + "_constraint", 
       po.Constraint(expr=(getattr(om, limit_name) <= 0)),)
  
       return om

     RE_sh_const(model,'re_share',0.5)

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!

2 Likes