From b4c31f8889acef8ec738c10d73e9ff251dfb8a4b Mon Sep 17 00:00:00 2001 From: Philipp Glaum Date: Fri, 18 Mar 2022 12:44:57 +0100 Subject: [PATCH] add renewable share constraint --- scripts/solve_network.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 4bbd375d..213e4351 100755 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -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')