-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loss calculation for non-hourly time steps
This one first slipped through due to too many irrelevant changes in the LP files. I now added a unit test that is independent of lp files. Note that the formula is more complicated but it just changes a value in the lp file, so it will not significantly increase computational time.
- Loading branch information
Showing
3 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
import numpy as np | ||
|
||
from oemof import solph | ||
|
||
|
||
def test_relative_losses(): | ||
cases = [ | ||
{"number": 500, "interval": 2}, | ||
{"number": 1000, "interval": 1}, | ||
{"number": 2000, "interval": 0.5}, | ||
] | ||
|
||
for case in cases: | ||
es = solph.EnergySystem( | ||
timeindex=solph.create_time_index( | ||
year=2023, number=case["number"], interval=case["interval"] | ||
), | ||
infer_last_interval=True, | ||
) | ||
|
||
bus = solph.Bus("slack_bus", balanced=False) | ||
es.add(bus) | ||
|
||
storage = solph.components.GenericStorage( | ||
"storage", | ||
inputs={bus: solph.Flow(variable_costs=1)}, | ||
outputs={bus: solph.Flow(variable_costs=1)}, | ||
nominal_storage_capacity=10, | ||
initial_storage_level=1, | ||
loss_rate=0.004125876075, # half life of one week | ||
) | ||
es.add(storage) | ||
|
||
model = solph.Model(es) | ||
model.solve("cbc") | ||
|
||
result = solph.processing.results(model)[(storage, None)]["sequences"][ | ||
"storage_content" | ||
] | ||
case["result"] = np.array(result) | ||
|
||
for i in range(500): | ||
assert ( | ||
cases[0]["result"][i] | ||
== pytest.approx(cases[1]["result"][2 * i]) | ||
== pytest.approx(cases[2]["result"][4 * i]) | ||
) |