From 661a471971541b04df35d66863a53fb7d156d6aa Mon Sep 17 00:00:00 2001 From: Junsong Du Date: Fri, 15 May 2026 15:37:17 +0200 Subject: [PATCH] fix: prevent overwriting device result dicts --- districtgenerator/functions/opti_central.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/districtgenerator/functions/opti_central.py b/districtgenerator/functions/opti_central.py index 5881707d..f5e04728 100644 --- a/districtgenerator/functions/opti_central.py +++ b/districtgenerator/functions/opti_central.py @@ -1721,7 +1721,8 @@ def helper_func_extract_eh_results(model, results_dict, variable_type, device_se # Heat devices for n in range(nbuildings): for device in ECS_HEAT: - results_dict[n][device] = {} + if not results_dict[n].get(device): + results_dict[n][device] = {} results_dict[n][device]["Q_th"] = [] for t in time_steps: results_dict[n][device]["Q_th"].append(round(pyo.value(model.heat_dom[device, n, t]), 0)) @@ -1729,7 +1730,8 @@ def helper_func_extract_eh_results(model, results_dict, variable_type, device_se # Cooling devices for n in range(nbuildings): for device in ECS_COOL: - results_dict[n][device] = {} + if not results_dict[n].get(device): + results_dict[n][device] = {} results_dict[n][device]["Q_cool"] = [] for t in time_steps: results_dict[n][device]["Q_cool"].append(round(pyo.value(model.cool_dom[device, n, t]), 0)) @@ -1754,7 +1756,8 @@ def helper_func_extract_eh_results(model, results_dict, variable_type, device_se # Power devices for n in range(nbuildings): for device in ECS_POWER: - results_dict[n][device] = {} + if not results_dict[n].get(device): + results_dict[n][device] = {} results_dict[n][device]["P_el"] = [] for t in time_steps: results_dict[n][device]["P_el"].append(round(pyo.value(model.power_dom[device, n, t]), 0)) @@ -1762,7 +1765,8 @@ def helper_func_extract_eh_results(model, results_dict, variable_type, device_se # Storage devices for n in range(nbuildings): for device in ECS_STORAGE: - results_dict[n][device] = {} + if not results_dict[n].get(device): + results_dict[n][device] = {} for v in ("ch", "dch", "soc"): results_dict[n][device][v] = [] for t in time_steps: