From 63ab5d0ae71b45c772cdfb7d177f835a638385c7 Mon Sep 17 00:00:00 2001 From: Eric Duminil Date: Mon, 8 Apr 2024 11:40:25 +0200 Subject: [PATCH] Cooling too --- .../04_MonthlyEnergyBalance.step/params.xml | 6 ++ .../variable_window_ratio.py | 93 ++++++++++--------- 2 files changed, 54 insertions(+), 45 deletions(-) diff --git a/python_scripts/run_simstadt_from_python/Template/99_HeatDemand.flow/04_MonthlyEnergyBalance.step/params.xml b/python_scripts/run_simstadt_from_python/Template/99_HeatDemand.flow/04_MonthlyEnergyBalance.step/params.xml index 9c25ced..602ce19 100644 --- a/python_scripts/run_simstadt_from_python/Template/99_HeatDemand.flow/04_MonthlyEnergyBalance.step/params.xml +++ b/python_scripts/run_simstadt_from_python/Template/99_HeatDemand.flow/04_MonthlyEnergyBalance.step/params.xml @@ -1,6 +1,12 @@ + + + de.hft.stuttgart.simstadt2.buildingenergymodels.MonthlyBalanceDIN18599$CalculationMode + HEATING_AND_COOLING + + Base diff --git a/python_scripts/run_simstadt_from_python/variable_window_ratio.py b/python_scripts/run_simstadt_from_python/variable_window_ratio.py index 48748ba..718b47a 100644 --- a/python_scripts/run_simstadt_from_python/variable_window_ratio.py +++ b/python_scripts/run_simstadt_from_python/variable_window_ratio.py @@ -1,59 +1,65 @@ from pathlib import Path import shutil from xml.etree import ElementTree as et -import logging import pandas as pd -import re from run_simstadt_workflow import find_simstadt, SCRIPT_DIR, run_workflow -# logging.getLogger().setLevel(logging.WARN) +import logging +logging.getLogger().setLevel(logging.WARN) +####################################################################### +# User params SIMSTADT2_GLOB = 'Desktop/SimStadt2_0.*/' REPO_PATH = Path.home() / 'git' / 'simstadt2' / 'TestRepository' PROJECT_NAME = 'Gruenbuehl' CITYGMLS = ['Gruenbuehl_LOD2_ALKIS_1010.gml'] SURFACES = ['outWalls', 'pitchedRoof'] +WINDOW_RATIOS = [0, 0.5, 1] +# Heat demand, with custom BuildingPhysics +TEMPLATE_NAME = '99_HeatDemand' +####################################################################### + +####################################################################### XML_LIB_URL = 'http://www.simstadt.eu/BuildingPhysicsLibraries' NAMESPACE = {'': XML_LIB_URL} - PROJECT_PATH = REPO_PATH / f'{PROJECT_NAME}.proj' PARAMS = 'params.xml' - BUILDING_PHYSICS_LIBRARY = 'GermanBuildingTypologyLibrary_IWU.xml' +####################################################################### -WINDOW_RATIOS = [0, 0.5, 1] - -TEMPLATE_NAME = '99_HeatDemand' -template = SCRIPT_DIR / 'Template' / f'{TEMPLATE_NAME}.flow' # Heat demand, with custom BuildingPhysics +def copy_workflow_from_template(template_name, project_path): + template = SCRIPT_DIR / 'Template' / f'{template_name}.flow' + workflow_path = project_path / f'{template_name}.flow' -workflow_path = PROJECT_PATH / f'{TEMPLATE_NAME}.flow' + shutil.copytree(template, workflow_path, dirs_exist_ok=True) -shutil.copytree(template, workflow_path, dirs_exist_ok=True) -print(workflow_path) + physics_processor_step = workflow_path / '01_Preprocessing.step/02_PhysicsPreprocessor.step' + return workflow_path, physics_processor_step -physics_processor_step = workflow_path / '01_Preprocessing.step/02_PhysicsPreprocessor.step' +def set_custom_library(physics_processor_step): + custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY -############# Specify custom lib ######################### -custom_library_path = physics_processor_step / BUILDING_PHYSICS_LIBRARY + physics_processor_params = physics_processor_step / PARAMS -physics_processor_params = physics_processor_step / PARAMS + param_tree = et.parse(physics_processor_params) + root = param_tree.getroot() -param_tree = et.parse(physics_processor_params) -root = param_tree.getroot() + lib_node = root.find( + ".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string") + lib_node.text = str(custom_library_path) + param_tree.write(physics_processor_params) + return custom_library_path -lib_node = root.find(".//object[@class='de.hft.stuttgart.simstadt2.assessment.PhysicsXmlLib']/void[@property='path']/string") -lib_node.text = str(custom_library_path) -param_tree.write(physics_processor_params) ########################################################## + def parse_library(library_path: Path) -> et.ElementTree: et.register_namespace('', XML_LIB_URL) return et.parse(library_path) -lib_tree = parse_library(custom_library_path) def set_custom_window_ratio(tree: et.ElementTree, window_ratio_node: float, export_path: Path): root = tree.getroot() @@ -65,36 +71,33 @@ def set_custom_window_ratio(tree: et.ElementTree, window_ratio_node: float, expo window_ratio_node.text = str(window_ratio) tree.write(export_path) -for window_ratio in WINDOW_RATIOS: - #################### Update lib with custom values ############################ +def parse_results(window_ratio, heat_demand_csv): + df = pd.read_csv(heat_demand_csv, + skiprows=list(range(19)) + [20], + sep=';', + decimal=',' + ) + + heat_demand_MWh = df['Yearly Heating demand'].sum() / 1000 + cool_demand_MWh = df['Yearly Cooling demand'].sum() / 1000 + print(f"Window Ratio : {window_ratio * 100} %") + print(f"Total heating demand : {heat_demand_MWh:.0f} MWh / a") + print(f"Total cooling demand : {cool_demand_MWh:.0f} MWh / a") - set_custom_window_ratio(lib_tree, window_ratio, custom_library_path) - # new_content = re.sub(r"[\w ]+", - # f"Custom Physics Library with Window Ratio : {window_ratio}", - # content, 1) - # # FIXME: Use et.parse instead. Because groundSurfaces shouldn't have any WindowRatio - # new_content = re.sub(r"[\d\.]+", - # f"{window_ratio}", - # new_content) +workflow_path, physics_processor_step = copy_workflow_from_template(TEMPLATE_NAME, PROJECT_PATH) +custom_library_path = set_custom_library(physics_processor_step) +lib_tree = parse_library(custom_library_path) - # with open(custom_library_path, 'w') as library_file: - # library_file.write(new_content) - ################################################################################# +for window_ratio in WINDOW_RATIOS: + # TODO: Status quo too + set_custom_window_ratio(lib_tree, window_ratio, custom_library_path) output_files = run_workflow(find_simstadt(SIMSTADT2_GLOB), workflow_path, CITYGMLS) - heat_demand_csv = next(file for file in output_files if 'HEATING.csv' in file.name) + heat_demand_csv = next(file for file in output_files if 'HEATING_AND_COOLING.csv' in file.name) ################### Parse heat demand ######################## - df = pd.read_csv(heat_demand_csv, - skiprows=list(range(19)) + [20], - sep=';', - decimal=',' - ) - - heat_demand_MWh = df['Yearly Heating demand'].sum() / 1000 - print(f"Window Ratio : {window_ratio * 100} %") - print(f"Total heat demand : {heat_demand_MWh:.0f} MWh / a") + parse_results(window_ratio, heat_demand_csv) -- GitLab