Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flixopt/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ def solution(self):
if 'time' in solution.coords:
if not solution.indexes['time'].equals(self.flow_system.timesteps_extra):
solution = solution.reindex(time=self.flow_system.timesteps_extra)
if 'cluster' in solution.dims and 'time' in solution.dims:
solution = solution.transpose('cluster', 'time', ...)
return solution

@property
Expand Down
8 changes: 3 additions & 5 deletions tests/test_math/test_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,10 @@ def test_storage_cyclic_charge_discharge_pattern(self, optimize):
discharge_fr = fs.solution['Battery(discharge)|flow_rate'].values[:, :4]
assert_allclose(discharge_fr, [[0, 50, 0, 50], [0, 50, 0, 50]], atol=1e-5)

# Charge state: dims=(time, cluster), 5 entries (incl. final)
# Cyclic: SOC wraps, starting with pre-charge from previous cycle
charge_state = fs.solution['Battery|charge_state']
assert charge_state.dims == ('time', 'cluster')
cs_c0 = charge_state.values[:5, 0]
cs_c1 = charge_state.values[:5, 1]
assert charge_state.dims == ('cluster', 'time')
cs_c0 = charge_state.isel(cluster=0).values[:5]
cs_c1 = charge_state.isel(cluster=1).values[:5]
assert_allclose(cs_c0, [50, 50, 0, 50, 0], atol=1e-5)
assert_allclose(cs_c1, [100, 100, 50, 100, 50], atol=1e-5)

Expand Down
Loading