add renewable share constraint

This commit is contained in:
Philipp Glaum 2022-03-18 12:44:57 +01:00
parent a5dd712424
commit b4c31f8889

View File

@ -210,6 +210,21 @@ def add_SAFE_constraints(n, config):
rhs = peakdemand - exist_conv_caps
define_constraints(n, lhs, '>=', rhs, 'Safe', 'mintotalcap')
def add_minRenew_constraints(n, config, o):
'''
Adds the constraint to have a minimum share of renewable energy production.
As renewable carriers the renewables from the configs listed under renewable are taken.
To use this constraint simply add the wildcard RE{share} in the opts wildcard like RE0.8 for a 80% renewable share
'''
renewables=list(config["renewable"].keys())
share=float(o[2:])
gen_factor=n.generators.apply(lambda x : (1-share) if x.carrier in renewables else -share, axis=1)
snapshots=n.snapshot_weightings.generators
coef=pd.DataFrame(np.outer(snapshots,gen_factor), index= snapshots.index, columns=gen_factor.index)
lhs = linexpr((coef, get_var(n, "Generator", "p"))).sum().sum()
rhs = 0
define_constraints(n, lhs, '>=', rhs, 'Carrier', 'minrenewables')
def add_battery_constraints(n):
nodes = n.buses.index[n.buses.carrier == "battery"]
@ -239,6 +254,8 @@ def extra_functionality(n, snapshots):
for o in opts:
if "EQ" in o:
add_EQ_constraints(n, o)
if 'RE' in o:
add_minRenew_constraints(n, config, o)
add_battery_constraints(n)
@ -270,7 +287,7 @@ if __name__ == "__main__":
if 'snakemake' not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake('solve_network', network='elec', simpl='',
clusters='40', ll='v1.0', opts='Co2L-4H')
clusters='40', ll='v1.0', opts='Co2L-4H-RE0.8')
configure_logging(snakemake)
tmpdir = snakemake.config['solving'].get('tmpdir')