oemof / oemof-solph

A model generator for energy system modelling and optimisation (LP/MILP).
https://oemof.org
MIT License
303 stars 127 forks source link

define a renewable energy constraint in oemof #785

Open JassemKh opened 3 years ago

JassemKh commented 3 years ago

hello,

I'm trying to implement a custom constraint for the share of renewable energy in my energy system consisting of pv battery and dieselGen. this a part of the code, where a I've added in the components pv and dieselGen the attribute „re_share“.

   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 funtion 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!

simnh commented 3 years ago

Heyho,

Whats your error message? One thing first: Why do you call the function with the model and then a string: 're_share,0.5' , probably a typo -> remove the ' or rather only put them around the 're_share'.

Maybe this source code is helpful for you:

https://github.com/znes/oemof-barbados/blob/master/model.ipynb

Where I also implemented a constraint for RE (however, based on the 1- conventional share), but the logic should be similar.

simnh commented 3 years ago

Heyho,

Whats your error message? One thing first: Why do you call the function with the model and then a string: 're_share,0.5' , probably a typo -> remove the '.

Maybe this source code is helpful for you:

https://github.com/znes/oemof-barbados/blob/master/model.ipynb

Where I also implemented a constraint for RE (however, based on the 1- conventional share), but the logic should be similar.

uvchik commented 3 years ago

This is related to this forum issue.

JassemKh commented 3 years ago

@simnh , it was a mistake I meant actually RE_sh_const(model,'re_share,'0.5)! thank you for sharing your project! I'm gonna check that! best wishes!