diff --git a/peakshaving_analyzer/PSA.py b/peakshaving_analyzer/PSA.py index ee4f6e4..ef2df3b 100644 --- a/peakshaving_analyzer/PSA.py +++ b/peakshaving_analyzer/PSA.py @@ -184,7 +184,7 @@ def add_storage(self): commodity="stored_energy", locationalEligibility=pd.Series([1, 0], index=["consumption_site", "grid"]), hasCapacityVariable=True, - cyclicLifetime=10000, + cyclicLifetime=self.config.storage_cyclic_lifetime, chargeEfficiency=self.storage_charge_efficiency, dischargeEfficiency=self.storage_discharge_efficiency, capacityMax=self.max_storage_size_kwh, diff --git a/peakshaving_analyzer/input.py b/peakshaving_analyzer/input.py index 46eb34c..3e00253 100644 --- a/peakshaving_analyzer/input.py +++ b/peakshaving_analyzer/input.py @@ -51,6 +51,7 @@ class Config(IOHandler): storage_charge_efficiency: float = 0.95 storage_discharge_efficiency: float = 0.95 storage_charge_rate: float = 5 + storage_cyclic_lifetime: float = 10000 storage_discharge_rate: float = 5 inverter_efficiency: float = 0.95 max_pv_system_size_kwp: float | None = None diff --git a/tests/test_psa.py b/tests/test_psa.py index e4cf550..0a52727 100644 --- a/tests/test_psa.py +++ b/tests/test_psa.py @@ -103,3 +103,33 @@ def test_add_solar(): + results.inverter_annuity_eur + results.storage_annuity_eur ) + + +def test_storage_only(): + # 4 cheap hours, one expensive hour + # adding a storage of 1 kwh reduces cost here + config = Config( + "test_config", + consumption_timeseries=[1] * 6, + hours_per_timestep=1, + n_timesteps=6, + price_timeseries=pd.DataFrame({"grid": [0.3] * 4 + [1] + [0.3], "consumption_site": [0] * 6}), + storage_charge_rate=10, + storage_discharge_rate=10, + # cyclic lifetime must be increased, otherwise we are building much more storage + storage_cyclic_lifetime=1e5, + interest_rate=2, + storage_charge_efficiency=1, + storage_discharge_efficiency=1, + ) + psa = PeakShavingAnalyzer(config=config) + results = psa.optimize() + ts = results.timeseries_to_df() + # we need to charge in the first few hours + assert (ts["grid_usage_kw"][0:4] >= 1).all() + # but do not charge in the last hour + assert (ts["grid_usage_kw"][4] == 0).all() + + assert results.inverter_capacity_kw == 1 + results.storage_capacity_kwh + assert results.storage_capacity_kwh == 1