General174 commited on
Commit
6c048cb
·
1 Parent(s): a99a2db

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -140,6 +140,7 @@ y_ch = m.add_variables(coords = [t,i], name = 'y_ch', lower = 0) # Electricit
140
  l = m.add_variables(coords = [t,i], name = 'l', lower = 0) # Storage filling level
141
  w = m.add_variables(coords = [t], name = 'w', lower = 0) # RES curtailment
142
  y_curt = m.add_variables(coords = [t,i], name = 'y_curt', lower = 0)
 
143
 
144
  ## Objective function
145
  C_tot = C_op + C_inv
@@ -147,13 +148,13 @@ m.add_objective(C_tot)
147
 
148
  ## Costs terms for objective function
149
  # Operational costs minus revenue for produced hydrogen
150
- C_op_sum = m.add_constraints((y * c_fuel_i/eff_i).sum() * dt - (y_ch.sel(i = iPtG) * eff_i.sel(i = iPtG) * price_h2).sum() * dt == C_op, name = 'C_op_sum')
151
 
152
  # Investment costs
153
  C_inv_sum = m.add_constraints((K * c_inv_i).sum() == C_inv, name = 'C_inv_sum')
154
 
155
  ## Load serving
156
- loadserve_t = m.add_constraints((((y ).sum(dims = 'i') - (w ) - y_ch.sum(dims = 'i')) * dt == D_t.sel(t = t) * dt), name = 'load')
157
 
158
  ## Maximum capacity limit
159
  maxcap_i_t = m.add_constraints((y - K <= K_0_i), name = 'max_cap')
@@ -170,6 +171,9 @@ maxcha_iSto_t = m.add_constraints((y.sel(i = iSto) + y_ch.sel(i = iSto) - K.sel(
170
  ## Maximum electrolyzer capacity
171
  ptg_prod_iPtG_t = m.add_constraints((y_ch.sel(i = iPtG) - K.sel(i = iPtG) <= K_0_i.sel(i = iPtG)), name = 'max_cha_ptg')
172
 
 
 
 
173
  ## Infeed of renewables
174
  infeed_iRes_t = m.add_constraints((y.sel(i = iRes) - s_t_r_iRes.sel(i = iRes).sel(t = t) * K.sel(i = iRes) + y_curt.sel(i = iRes) == s_t_r_iRes.sel(i = iRes).sel(t = t) * K_0_i.sel(i = iRes)), name = 'infeed')
175
 
@@ -271,6 +275,13 @@ with colb1:
271
  df_charging = m.solution['y_ch'].sel(i = iSto).to_dataframe().reset_index()
272
  fig = px.area(m.solution['y_ch'].sel(i = iSto).to_dataframe().reset_index(), y='y_ch', x='t', title='Storage charging [MWh]', color='i')
273
 
 
 
 
 
 
 
 
274
  with colb2:
275
  fig
276
 
@@ -299,6 +310,7 @@ with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
299
  df_charging.to_excel(writer, sheet_name='Charging', index=False)
300
  D_t.to_dataframe().reset_index().to_excel(writer, sheet_name='Demand', index=False)
301
  df_curtailment.to_excel(writer, sheet_name='Curtailment', index=False)
 
302
 
303
  with col4:
304
  st.download_button(
 
140
  l = m.add_variables(coords = [t,i], name = 'l', lower = 0) # Storage filling level
141
  w = m.add_variables(coords = [t], name = 'w', lower = 0) # RES curtailment
142
  y_curt = m.add_variables(coords = [t,i], name = 'y_curt', lower = 0)
143
+ y_h2 = m.add_variables(coords = [t,i], name = 'y_h2', lower = 0)
144
 
145
  ## Objective function
146
  C_tot = C_op + C_inv
 
148
 
149
  ## Costs terms for objective function
150
  # Operational costs minus revenue for produced hydrogen
151
+ C_op_sum = m.add_constraints((y * c_fuel_i/eff_i).sum() * dt - (y_h2.sel(i = iPtG) * price_h2).sum() * dt == C_op, name = 'C_op_sum')
152
 
153
  # Investment costs
154
  C_inv_sum = m.add_constraints((K * c_inv_i).sum() == C_inv, name = 'C_inv_sum')
155
 
156
  ## Load serving
157
+ loadserve_t = m.add_constraints((((y ).sum(dims = 'i') - y_ch.sum(dims = 'i')) * dt == D_t.sel(t = t) * dt), name = 'load')
158
 
159
  ## Maximum capacity limit
160
  maxcap_i_t = m.add_constraints((y - K <= K_0_i), name = 'max_cap')
 
171
  ## Maximum electrolyzer capacity
172
  ptg_prod_iPtG_t = m.add_constraints((y_ch.sel(i = iPtG) - K.sel(i = iPtG) <= K_0_i.sel(i = iPtG)), name = 'max_cha_ptg')
173
 
174
+ ## PtG H2 production
175
+ h2_prod_iPtG_t = m.add_constraints(y_ch.sel(i = iPtG) * eff_i.sel(i = iPtG) == y_h2.sel(i = PtG), name = 'ptg_h2_prod')
176
+
177
  ## Infeed of renewables
178
  infeed_iRes_t = m.add_constraints((y.sel(i = iRes) - s_t_r_iRes.sel(i = iRes).sel(t = t) * K.sel(i = iRes) + y_curt.sel(i = iRes) == s_t_r_iRes.sel(i = iRes).sel(t = t) * K_0_i.sel(i = iRes)), name = 'infeed')
179
 
 
275
  df_charging = m.solution['y_ch'].sel(i = iSto).to_dataframe().reset_index()
276
  fig = px.area(m.solution['y_ch'].sel(i = iSto).to_dataframe().reset_index(), y='y_ch', x='t', title='Storage charging [MWh]', color='i')
277
 
278
+ with colb2:
279
+ fig
280
+
281
+ # %%
282
+ df_h2_prod = m.solution['y_h2'].sel(i = iPtG).to_dataframe().reset_index()
283
+ fig = px.area(m.solution['y_h2'].sel(i = iPtG).to_dataframe().reset_index(), y='y_ch', x='t', title='Hydrogen production [MWh_th]', color='i')
284
+
285
  with colb2:
286
  fig
287
 
 
310
  df_charging.to_excel(writer, sheet_name='Charging', index=False)
311
  D_t.to_dataframe().reset_index().to_excel(writer, sheet_name='Demand', index=False)
312
  df_curtailment.to_excel(writer, sheet_name='Curtailment', index=False)
313
+ df_h2_prod.to_excel(writer, sheet_name='H2 production', index=False)
314
 
315
  with col4:
316
  st.download_button(